如洲 陈
3 天以前 900e4776223c2a42d8859fc8cd635c13ffcfb3b5
pages/BasePages/main.vue
@@ -18,11 +18,11 @@
                     <navigator navigateTo class="grid-item-box" hover-class="none" :url="`../${item.path}`">
                        <image v-if="item.icoimg" class="imgMenu" :src="`${item.icoimg}`"></image>
                        <image v-else class="imgMenu" src="/static/img/imgMenu/APP01.png"></image>
                        <uni-notice-bar v-if="item.pagE_VIEW.length>6" :speed="30"
               <uni-notice-bar v-if="item.pagE_VIEW && item.pagE_VIEW.length>6" :speed="30"
                           style="padding:0;margin-bottom:0;font-weight: 900;" textSize="13px"
                           background-color="#ffffff" color="#000000" :scrollable="item.pagE_VIEW.length>6"
                           :single="true" :text="item.pagE_VIEW" />
                        <text v-else class="text">{{ item.pagE_VIEW }}</text>
                        background-color="#ffffff" color="#000000" :scrollable="item.pagE_VIEW && item.pagE_VIEW.length>6"
                        :single="true" :text="item.pagE_VIEW || ''" />
                        <text v-else class="text">{{ item.pagE_VIEW || '' }}</text>
                     </navigator>
                  </uni-grid-item>
               </uni-grid>
@@ -53,6 +53,8 @@
               "../../static/img/SN-GG1.png"
            ],
            col: 4, //菜单列数
            updateChecked: false,
            msg: "",
         };
      },
      methods: {
@@ -100,15 +102,21 @@
            })
         },
         checkForUpdate() {
            if (this.updateChecked) return;
            if (!this.$post || typeof this.$post !== 'function') return;
            this.$post({
               url: "/Login/getAppUpgradeInfo",
               data: {}
            }).then(res => {
               let newVersion = res.data.version;
               let currentVersion = uni.getSystemInfoSync(); // 获取当前 APK 版本号
               if (newVersion > currentVersion.appVersion) {
               const newVersion = res && res.data ? res.data.version : null;
               const sysInfo = uni.getSystemInfoSync();
               const currentVersion = sysInfo && sysInfo.appVersion ? sysInfo.appVersion : null;
               if (!newVersion || !currentVersion) {
                  this.updateChecked = true;
                  return; // 非 APP 端或缺少版本信息时跳过
               }
               // 简单比较,不处理复杂语义版本
               if (String(newVersion) !== String(currentVersion)) {
                  uni.showModal({
                     title: "发现新版本",
                     content: "是否下载最新版本?",
@@ -118,50 +126,57 @@
                        }
                     }
                  });
                  //this.downloadNewApk(res.data.apkUrl);
                  this.updateChecked = true; // 标记更新已检查过
                  //      // 如果有新版本,开始下载
                  //download(res.data.apkUrl);
                  this.updateChecked = true;
               }
            }).catch(err => {
               console.error('getAppUpgradeInfo error:', err);
               this.updateChecked = true;
            })
         },
         downloadNewApk(apkUrl) {
            uni.showToast({
               title: "开始下载更新...",
               icon: "none",
               duration: 2000
            });
            uni.downloadFile({
               url: apkUrl,
               success: (res) => {
                  if (res.statusCode === 200) {
                     plus.runtime.install(res.tempFilePath, {
                        force: true
                     }, function() {
                        console.log("安装成功,重启应用");
                        //plus.runtime.restart();
                        //plus.runtime.quit();
                        // uni.navigateBack()
                     }, function(e) {
                        console.error("安装失败:", e);
                  downloadNewApk(apkUrl) {
                     if (typeof plus === "undefined" || !plus.runtime) {
                        uni.showToast({
                           title: "仅支持在APP内更新",
                           icon: "none",
                           duration: 2000
                        });
                        return;
                     }
                     uni.showToast({
                        title: "开始下载更新...",
                        icon: "none",
                        duration: 2000
                     });
                     uni.downloadFile({
                        url: apkUrl,
                        success: (res) => {
                           if (res.statusCode === 200) {
                              plus.runtime.install(res.tempFilePath, {
                                 force: true
                              }, function() {
                                 console.log("安装成功,重启应用");
                                 //plus.runtime.restart();
                                 //plus.runtime.quit();
                                 // uni.navigateBack()
                              }, function(e) {
                                 console.error("安装失败:", e);
                              });
                           }
                        },
                        fail: (err) => {
                           console.error("下载失败:", err);
                           uni.showToast({
                              title: "下载失败,请检查网络",
                              icon: "none",
                              duration: 2000
                           });
                        }
                     });
                  }
               },
               fail: (err) => {
                  console.error("下载失败:", err);
                  uni.showToast({
                     title: "下载失败,请检查网络",
                     icon: "none",
                     duration: 2000
                  });
               }
            });
         }
      },
      onLoad() {
         if (!this.loginInfo.hasLogin) {
@@ -191,12 +206,21 @@
            });
         } else {
            this.getMenu(true);
            // 检查应用更新(仅 APP 端)
            if (typeof plus !== "undefined") {
               this.checkForUpdate();
            }
         }
      },
      onPullDownRefresh() {
         if (this.loginInfo.hasLogin)
         if (this.loginInfo.hasLogin) {
            this.getMenu(true);
            // 下拉刷新时也检查更新(仅 APP 端)
            if (typeof plus !== "undefined") {
               this.checkForUpdate();
            }
         }
      },
   }