cuiqian2004
2025-03-14 00814401bba75825126baa6675e542ea3c82a5bb
pages/login/index.vue
@@ -48,7 +48,7 @@
         <!-- 输入框示例 -->
         <uni-popup ref="inputDialog" type="dialog">
            <uni-popup-dialog ref="inputClose" mode="input" :title="translateSys('set')" :value="userServer"
            :placeholder="translate('input_server')" @confirm="dialogInputConfirm"></uni-popup-dialog>
               :placeholder="translate('input_server')" @confirm="dialogInputConfirm"></uni-popup-dialog>
         </uni-popup>
         <!-- 版本升级弹窗开始 -->
         <uni-popup ref="promotion" type="center">
@@ -70,7 +70,10 @@
         </uni-popup>
         <!-- 版本升级弹窗结束 -->
      </view>
      <!-- <button @click="onClickWms">登录wms</button>
      <view class="webview">
         <web-view ref="webview" src="http://115.29.185.26:5000/mobox3/#/"></web-view>
      </view> -->
   </view>
</template>
@@ -83,6 +86,12 @@
      showLoading,
      hideLoading
   } from "@/js/Page.js"
   import {
      isMobox3Web,
      login,
      getApkVersionInfo
   } from "@/api/index.js"
   import utils from "@/js/utils.js"
   export default {
      components: {
@@ -133,113 +142,43 @@
         },
         //检测是否需要更新
         async check(version) {
            if (!this.userServer) {
               uni.showModal({
                  title: this.translateSys("tip"),
                  content: this.translate("tip_no_web_server"),
                  showCancel: false,
                  confirmText: this.translateSys('cancel')
               });
               return;
            }
            var ser = this.userServer.toLowerCase().split('/');
            var translateSyshis = this;
            var rootUrl = 'http://' + this.userServer
            if (this.userServer.includes("://")) {
               rootUrl = this.userServer
            }
            if (ser[ser.length - 1] == 'mobox3') { //判断当前网址是否是mobox3
               var url = rootUrl + '/Program/version.txt';
               console.log(url);
               uni.request({
                  url: url, // 指定JS文件的完整路径
                  method: 'GET',
                  success(res) {
                     console.log(res);
                     if (res && res.statusCode === 200) {
                        //获取当前版本号
                        var VersionName = res.data; //更新包名称
                        var versionInfo = res.data.split('_');
                        var versionNum = versionInfo[2].replace(".apk", ""); //版本编码
                        var VersionCode = versionInfo[2].replace(".apk", "").replace(".", "").replace(
                           ".", ""); //服务端版本号
                        // this.downloadUrl = resp.PdaUrl+"/"+VersionName; //app下载链接
                        translateSyshis.downloadUrl =  rootUrl+ "/Program/" +
                           VersionName; //app下载链接this.
                        var isver = translateSyshis.compare(versionNum, version);
                        if (isver) {
                           translateSyshis.$refs.promotion.open();
                        } else {
                           console.log('当前已是最新版本')
                        }
                     } else {
                        // if(res.statusCode === 404){
                        //    uni.showModal({
                        //       title: "提示",
                        //       content: '请求失败,找不到更新包版本文档:'+url,
                        //       showCancel: false,
                        //       confirmText: "取消"
                        //    });
                        // }
                     }
                  },
                  fail(err) {
                     // 错误处理逻辑
                     uni.showModal({
                        title: this.translateSys('error'),
                        content: this.translate('tip_get_file_fail_first') + "'" + url + "'" +
                           this.translate('tip_get_file_fail_last') + "\n" + err,
                        showCancel: false,
                        confirmText: this.translateSys('cancel')
                     });
                  }
               });
            } else {
               var dataInfo = {
                  server: rootUrl
               };
               this.$store.dispatch('GetApkVersionInfo', dataInfo).then(success => {
                  console.log(success);
                  if (success.code == '00000') {
                     let resp = success.data;
                     if (resp) {
                        // const obj = resp.data.filter(item => {
                        //    return item.groupName == 'version'
                        // })
                        //获取当前版本号
                        const VersionName = resp.VersionName; //更新包名称
                        const VersionCode = resp.VersionCode; //版本编码
                        const versionNum = resp.Version; //服务端版本号
                        // this.downloadUrl = resp.PdaUrl+"/"+VersionName; //app下载链接
                        translateSyshis.downloadUrl = rootUrl+
                           "/Program/" +
                           VersionName; //app下载链接this.
                        var isver = translateSyshis.compare(versionNum, version);
                        if (isver) {
                           translateSyshis.$refs.promotion.open();
                        } else {
                           console.log('当前已是最新版本')
                        }
                     }
                  } else {
                     uni.showModal({
                        title: this.translateSys('error'),
                        content: success.msg,
                        showCancel: false,
                        confirmText: this.translateSys('cancel')
                     });
                  }
               }).catch(ex => {
                  console.log(ex);
            try {
               if (!this.userServer) {
                  uni.showModal({
                     title: this.translateSys('error'),
                     content: ex.errMsg ? ex.errMsg : ex.message,
                     title: this.translateSys("tip"),
                     content: this.translate("tip_no_web_server"),
                     showCancel: false,
                     confirmText: this.translateSys('cancel')
                     confirmText: this.translateSys('close')
                  });
                  return;
               }
               // var ser = this.userServer.toLowerCase().split('/');
               const res = await getApkVersionInfo(this.userServer)
               this.downloadUrl = res.dldUrl || ""
               if (this.downloadUrl) {
                  var isver = this.compare(res.verNum || "", version);
                  if (isver) {
                     this.$refs.promotion.open();
                  } else {
                     console.log('当前已是最新版本')
                  }
               }
            } catch (ex) {
               // console.log(ex);
               let exStr = JSON.stringify(ex)
               if (exStr == "{}")
                  exStr = ex
               let tip = typeof ex.errMsg == "string" ? ex.errMsg : exStr
               uni.showModal({
                  title: this.translateSys("error"),
                  content: tip,
                  showCancel: false,
                  confirmText: this.translateSys('close')
               });
            }
         },
         compare(curV, reqV) {
            var arr1 = curV.toString().split('.');
@@ -334,7 +273,17 @@
         //    actionLogin:'login'
         // }),
         inputDialogToggle() {
            this.$refs.inputDialog.open()
            // this.$refs.inputDialog.open()
            const $this = this
            uni.navigateTo({
               url: "./set",
               events: {
                  exitSetEvent(val) {
                     $this.userServer = val;
                     $this.query(); //版本升级
                  }
               }
            })
         },
         clickSetLanguage() {
            uni.navigateTo({
@@ -387,95 +336,78 @@
         //    ((expiredays==null)?'':';expires='+exdate.toGMTString());
         // },
         logind() {
            if (!this.userServer) {
               uni.showModal({
                  title: this.translateSys('tip'),
                  content: this.translate('tip_no_web_server'),
                  showCancel: false,
                  confirmText: this.translateSys('cancel')
               });
               return;
            }
            if (!this.userName) {
               uni.showModal({
                  title: this.translateSys('tip'),
                  content: this.translate('tip_no_user_account'),
                  showCancel: false,
                  confirmText: this.translateSys('cancel')
               });
               return;
            }
            if (!this.userPwd) {
               uni.showModal({
                  title: this.translateSys('tip'),
                  content: this.translate('tip_no_user_password'),
                  showCancel: false,
                  confirmText: this.translateSys('cancel')
               });
               return;
            }
            var rootUrl = 'http://' + this.userServer
            if (this.userServer.includes("://")) {
               rootUrl = this.userServer
            }
            //检查 "登录状态/锁屏状态" 结束
            var loginInfo = {
               server:rootUrl,
               uname: this.userName,
               pwd: this.userPwd,
               cname: plus.device.model,
               type: "0"
            };
            console.log(loginInfo);
            showLoading("loading......")
            //登录
            this.$store.dispatch('login', loginInfo).then(success => {
               console.log(success);
               if (success.code == '00000' || success.err_code == 0) {
                  //登录成功后清空缓存数据
                  this.$store.commit("areaFunc", null);
                  this.$store.commit("classAttrList", null);
                  this.$store.commit("classGridStyleInfo", null);
                  this.$store.commit("dicValueInfo", null);
                  this.$store.commit("subClassAttrList", null);
                  this.$store.commit("subClassGridStyleInfo", null);
                  //设置全局参数:user-用户信息
                  utils.session.setValue('server', loginInfo.server);
                  utils.session.setValue('account', loginInfo.uname);
                  utils.session.setValue('password', loginInfo.pwd);
                  // this.mutatLogin({loginid:success});
                  this.$store.commit('login', {
                     loginid: success
                  });
                  hideLoading()
                  uni.navigateTo({
                     url: '../index/index?args=9999999999'
                  })
                  // uni.redirectTo({
                  //    url:'../index/index?args=9999999999'
                  // });
               } else {
                  hideLoading()
         async logind() {
            try {
               if (!this.userServer) {
                  uni.showModal({
                     title: this.translateSys('error'),
                     content: success.msg,
                     title: this.translateSys('tip'),
                     content: this.translate('tip_no_web_server'),
                     showCancel: false,
                     confirmText: this.translateSys('cancel')
                     confirmText: this.translateSys('close')
                  });
                  return;
               }
            }).catch(ex => {
               console.log(ex);
               if (!this.userName) {
                  uni.showModal({
                     title: this.translateSys('tip'),
                     content: this.translate('tip_no_user_account'),
                     showCancel: false,
                     confirmText: this.translateSys('close')
                  });
                  return;
               }
               if (!this.userPwd) {
                  uni.showModal({
                     title: this.translateSys('tip'),
                     content: this.translate('tip_no_user_password'),
                     showCancel: false,
                     confirmText: this.translateSys('close')
                  });
                  return;
               }
               var rootUrl = 'http://' + this.userServer
               if (this.userServer.includes("://")) {
                  rootUrl = this.userServer
               }
               showLoading("loading......")
               const res = await login(rootUrl, this.userName, this.userPwd)
               //设置全局参数:user-用户信息
               utils.session.setValue('server', rootUrl);
               utils.session.setValue('account', this.userName);
               utils.session.setValue('password', this.userPwd);
               const app = getApp()
               app.globalData.sessionId = res.session_id
               app.globalData.loginUser = {
                  id: this.userName,
                  name: res.name,
                  pwd: this.userPwd
               }
               hideLoading()
               uni.navigateTo({
                  url: '../index/index?args=9999999999'
               })
            } catch (ex) {
               hideLoading()
               let exStr = JSON.stringify(ex)
               if (exStr == "{}")
                  exStr = ex
               let tip = typeof ex.errMsg == "string" ? ex.errMsg : exStr
               uni.showModal({
                  title: this.translateSys('error'),
                  content: ex.errMsg,
                  title: this.translateSys("error"),
                  content: tip,
                  showCancel: false,
                  confirmText: this.translateSys('cancel')
                  confirmText: this.translateSys('close')
               });
            });
            }
         },
         onClickWms() {
            let otherAppSchemeURL = "testapp://pages/index/index"; // 替换为目标app的scheme URL
            plus.runtime.openURL(otherAppSchemeURL, function(error) {
               console.error('打开应用失败: ', error);
            }, "uni.TeatApp");
         },
         translate(t) {
            if (typeof this.$t == "function") return this.$t(`page.${t}`)
@@ -486,11 +418,13 @@
            else return t;
         },
      },
      onLoad() {
      onLoad(options) {
         //获取mac地址
         var url = this.$store.state.url;
         var username = this.$store.state.username;
         var userpwd = this.$store.state.userpwd;
         var url = utils.session.getValue('server');
         var username = utils.session.getValue('account');
         var userpwd = utils.session.getValue('password');
         var ischecked = false;
         if (!this.userServer)
            this.userServer = url;
@@ -517,10 +451,10 @@
            }
            deviceId += tmp;
         }
         getApp().globalData.deviceId = deviceId
         getApp().globalData.cname = plus.device.model
         //78b8d67511ca
         this.$store.commit("setDeviceId", deviceId);
         console.log('Android设备的deviceId:', deviceId);
         plus.runtime.getProperty(plus.runtime.appid, (info) => {
            // console.log(info);
            this.$data.version = info.version;