cuiqian2004
2024-07-12 effc285be3229af6b77edafcb5ec71b96a35f53a
pages/login/index.vue
@@ -1,143 +1,14 @@
<style>
   input::-webkit-input-placeholder {
      font-size: 12rpx;
   }
   #headr {
      background: #434343;
      /* width: 375px; */
      height: 250rpx;
      text-align: center;
      background-color: #438EB9;
      /* background-image: url(../../images/login/root.png) !important;
      background-size: cover !important;
      background-repeat: no-repeat !important; */
   }
   .SetServer {
      float: left;
      margin-left: 20rpx;
   }
   .check_rememberPwd {
      margin-top: 20rpx;
      margin-left: 20rpx;
   }
   .logo {
      height: 180rpx;
      width: 180rpx;
      margin-top: 170rpx;
   }
   .logo_input {
      height: 40rpx;
      width: 40rpx;
      margin-left: 40rpx;
   }
   .logo_icon {
      height: 50rpx;
      width: 50rpx;
      margin-left: 15rpx;
      margin-top: 20rpx;
   }
   .mui-content {
      height: 100%;
      padding-top: 140rpx;
      background: #FFFFFF;
      z-index: 1;
   }
   .mui-input-group .la_icon {
      width: 100rpx;
      text-align: center;
      font-family: 'Helvetica Neue', Helvetica, sans-serif;
      line-height: 1.5;
      float: left;
      padding: 7px 13px;
   }
   .mui-input-group .mui-input-row {
      height: 85rpx;
      position: relative;
      clear: left;
      overflow: hidden;
   }
   .mui-input-row:first-child {
      border-top: 1px solid #c8c7cc;
   }
   .mui-input-row:last-child {
      border-bottom: 1px solid #c8c7cc;
   }
   .mui-input-group .mui-input-row:last-child:after {
      background-color: #fff;
   }
   .mui-input-group .mui-input-row:after {
      position: absolute;
      right: 0;
      bottom: 0;
      left: 15px;
      height: 1px;
      content: '';
      transform: scaleY(.5);
      background-color: #c8c7cc;
   }
   .mui-input-row input {
      font-family: 'Helvetica Neue', Helvetica, sans-serif;
      font-size: 15px;
      width: 480rpx;
      /* float: right; */
      margin-bottom: 0;
      padding-left: 20rpx;
      /* padding-right: 10rpx; */
      /* line-height: 30rpx; */
      height: 85rpx;
      /* padding: 7px 40px 7px 0px; */
      -webkit-user-select: text;
      /* border: 0; */
      /* border-radius: 0; */
      box-shadow: none;
      outline: 0;
      background: 0 0;
      -webkit-appearance: none;
   }
   .mui-input-group label.mui-navigate-right {
      font-size: 25px;
      float: right;
      padding: 0;
      width: 80rpx;
      margin-right: 5rpx;
      margin-top: -88rpx;
      display: inline-block;
   }
   button.btn_login {
      margin-top: 50rpx;
      padding: 20rpx;
      line-height: 1.5;
      background: #27A6E1;
      border: none;
      color: #fff;
   }
</style>
<template>
   <view class="" style="width: 100vw;height: 64vh;">
   <view class="uni-page-login" style="width: 100vw;height: 64vh;">
      <div id="headr" class="mui-bar mui-bar-nav">
         <image class="logo" src="../../images/login/mobox_log_200.png"></image>
      </div>
      <div class="mui-content">
         <form id='login-form' class="mui-input-group">
            <a href="javascript:;" class="SetServer" @click="inputDialogToggle">配置</a>
            <a href="javascript:;" class="SetServer" @click="inputDialogToggle">{{translateSys('set')}}</a>
            <a href="javascript:;" class="SetServer" @click="clickSetLanguage">{{translateSys('language')}}</a>
            <!-- <div class="mui-input-row">
               <label class="la_icon"><image class="logo_input" src="../../images/login/svr_30.png"></image></label>
               <input type="text" class="mui-input" v-model="userServer" placeholder="服务器地址">
@@ -147,25 +18,26 @@
               <label class="la_icon">
                  <image class="logo_input" src="../../images/login/person_30.png"></image>
               </label>
               <input type="text" class="mui-input" v-model="userName" placeholder="请输入账号">
               <input type="text" class="mui-input" v-model="userName" :placeholder="translateSys('input_login')">
               <!-- <label class="mui-navigate-right" id="namsel"><image class="logo_icon" src="../../images/login/user-photo.png</image></label> -->
            </div>
            <div class="mui-input-row">
               <label class="la_icon">
                  <image class="logo_input" src="../../images/login/lock_30.png"></image>
               </label>
               <input type="password" class="mui-input" v-model="userPwd" placeholder="请输入密码">
               <input type="password" class="mui-input" v-model="userPwd"
                  :placeholder="translateSys('input_password')">
            </div>
            <checkbox-group class="check_rememberPwd" @change="rememberPwd">
               <label>
                  <checkbox value="1" :checked="ischecked" />
                  <text>记住密码</text>
                  <text>{{translateSys('remember_password')}}</text>
               </label>
            </checkbox-group>
         </form>
         <button id='login' type="default" @tap="logind" class="btn_login">{{login}}</button>
         <button id='login' type="default" @tap="logind" class="btn_login">{{translateSys("start_login")}}</button>
         <p style="float:right; margin: 10px 10px;color:#c8c7cc">
            <span>版本号:</span>
            <span>{{translateSys('version')}}:</span>
            <span>{{version}}</span>
         </p>
         <div class=""
@@ -175,20 +47,20 @@
      <view>
         <!-- 输入框示例 -->
         <uni-popup ref="inputDialog" type="dialog">
            <uni-popup-dialog ref="inputClose" mode="input" title="设置" :value="userServer" placeholder="请输入内容"
               @confirm="dialogInputConfirm"></uni-popup-dialog>
            <uni-popup-dialog ref="inputClose" mode="input" :title="translateSys('set')" :value="userServer"
            :placeholder="translate('input_server')" @confirm="dialogInputConfirm"></uni-popup-dialog>
         </uni-popup>
         <!-- 版本升级弹窗开始 -->
         <uni-popup ref="promotion" type="center">
            <view class="promotion" style="width: 700rpx;padding:20rpx 40rpx; background: white;font-size: 36rpx;">
               <view class="operates" v-if="showBtns==true">
                  <view style="text-align: center;padding-top:20rpx;padding-bottom: 40rpx;">
                     系统有新版本,是否需要更新
                     {{translate('tip_app_update')}}
                  </view>
                  <text @click="cancel"
                     style="display: inline-block;color: #7cd0f8;width: 50%; text-align: center;">取消</text>
                     style="display: inline-block;color: #7cd0f8;width: 50%; text-align: center;">{{translateSys('cancel')}}</text>
                  <text @click="sure"
                     style="display: inline-block;color: #7cd0f8;width: 50%; text-align: center;">确认</text>
                     style="display: inline-block;color: #7cd0f8;width: 50%; text-align: center;">{{translateSys('confirm')}}</text>
               </view>
               <view class="operates" v-else>
                  <cmd-progress :percent="percentage" stroke-color="linear-gradient(to right, #ef32d9, #89fffd)">
@@ -205,37 +77,24 @@
<script>
   import cmdProgress from "@/components/cmd-progress/cmd-progress.vue"
   // import {
   //    mapState,
   //    mapMutations,
   //    mapActions ,
   // } from 'vuex'
   import {
      showModal,
      showToast,
      showLoading,
      hideLoading
   } from "@/js/Page.js"
   import utils from "@/js/utils.js"
   export default {
      components: {
         cmdProgress
      },
      data() {
         //获取全局参数:url-服务器地址
         var server = uni.getStorageSync('server');
         var account = uni.getStorageSync('account');
         var password = uni.getStorageSync('password');
         var url = this.$store.state.url;
         var username = this.$store.state.username;
         var userpwd = this.$store.state.userpwd;
         var ischecked = false;
         if (!server)
            server = url;
         if (!account)
            account = username;
         if (account && password)
            ischecked = true;
         // console.log(url);
         return {
            login: "开始登录",
            userServer: server,
            userName: account,
            userPwd: password,
            ischecked: ischecked,
            userServer: utils.session.getValue('server'),
            userName: utils.session.getValue('account'),
            userPwd: utils.session.getValue('password'),
            ischecked: false,
            version: "1.0.0",
            downloadUrl: "", //安卓app下载链接
            percentage: 0, //下载进度
@@ -276,18 +135,22 @@
         async check(version) {
            if (!this.userServer) {
               uni.showModal({
                  title: "提示",
                  content: "未输入网站地址,请重新配置输入!",
                  title: this.translateSys("tip"),
                  content: this.translate("tip_no_web_server"),
                  showCancel: false,
                  confirmText: "取消"
                  confirmText: this.translateSys('cancel')
               });
               return;
            }
            var ser = this.userServer.split('/');
            var $this = this;
            if(ser[1] == 'mobox3'){ //判断当前网址是否是mobox3
               var url = 'http://'+this.userServer+'/Program/version.txt';
               // console.log(url);
            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',
@@ -298,12 +161,15 @@
                        var VersionName = res.data; //更新包名称
                        var versionInfo = res.data.split('_');
                        var versionNum = versionInfo[2].replace(".apk", ""); //版本编码
                        var VersionCode = versionInfo[2].replace(".apk", "").replace(".", "").replace(".", ""); //服务端版本号
                        var VersionCode = versionInfo[2].replace(".apk", "").replace(".", "").replace(
                           ".", ""); //服务端版本号
                        // this.downloadUrl = resp.PdaUrl+"/"+VersionName; //app下载链接
                        $this.downloadUrl = "http://" + $this.userServer + "/Program/" + VersionName; //app下载链接this.
                        var isver = $this.compare(versionNum,version);
                        translateSyshis.downloadUrl =  rootUrl+ "/Program/" +
                           VersionName; //app下载链接this.
                        var isver = translateSyshis.compare(versionNum, version);
                        if (isver) {
                           $this.$refs.promotion.open();
                           translateSyshis.$refs.promotion.open();
                        } else {
                           console.log('当前已是最新版本')
                        }
@@ -321,16 +187,17 @@
                  fail(err) {
                     // 错误处理逻辑
                     uni.showModal({
                        title: "错误",
                        content: '获取'+url+'文件失败:'+ err,
                        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: "取消"
                        confirmText: this.translateSys('cancel')
                     });
                  }
               });
            }else{
            } else {
               var dataInfo = {
                  server: this.userServer
                  server: rootUrl
               };
               this.$store.dispatch('GetApkVersionInfo', dataInfo).then(success => {
                  console.log(success);
@@ -345,56 +212,58 @@
                        const VersionCode = resp.VersionCode; //版本编码
                        const versionNum = resp.Version; //服务端版本号
                        // this.downloadUrl = resp.PdaUrl+"/"+VersionName; //app下载链接
                        $this.downloadUrl = "http://" + $this.userServer + "/Program/" + VersionName; //app下载链接this.
                        var isver = $this.compare(versionNum,version);
                        translateSyshis.downloadUrl = rootUrl+
                           "/Program/" +
                           VersionName; //app下载链接this.
                        var isver = translateSyshis.compare(versionNum, version);
                        if (isver) {
                           $this.$refs.promotion.open();
                           translateSyshis.$refs.promotion.open();
                        } else {
                           console.log('当前已是最新版本')
                        }
                     }
                  } else {
                     uni.showModal({
                        title: "错误",
                        title: this.translateSys('error'),
                        content: success.msg,
                        showCancel: false,
                        confirmText: "取消"
                        confirmText: this.translateSys('cancel')
                     });
                  }
               }).catch(ex => {
                  console.log(ex);
                  uni.showModal({
                     title: "错误",
                     title: this.translateSys('error'),
                     content: ex.errMsg ? ex.errMsg : ex.message,
                     showCancel: false,
                     confirmText: "取消"
                     confirmText: this.translateSys('cancel')
                  });
               });
            }
         },
         compare(curV, reqV) {
            var arr1 = curV.toString().split('.');
             var arr2 = reqV.toString().split('.');
             //将两个版本号拆成数字
             var minL = Math.min(arr1.length, arr2.length);
             var pos = 0; //当前比较位
             var diff = 0; //当前为位比较是否相等
             var flag = false;
             //逐个比较如果当前位相等则继续比较下一位
             while (pos < minL) {
                 diff = parseInt(arr1[pos]) - parseInt(arr2[pos]);
                 if (diff == 0) {
                     pos++;
                     continue;
                 } else if (diff > 0) {
                     flag = true;
                     break;
                 } else {
                     flag = false;
                     break;
                 }
             }
             return flag;
            var arr2 = reqV.toString().split('.');
            //将两个版本号拆成数字
            var minL = Math.min(arr1.length, arr2.length);
            var pos = 0; //当前比较位
            var diff = 0; //当前为位比较是否相等
            var flag = false;
            //逐个比较如果当前位相等则继续比较下一位
            while (pos < minL) {
               diff = parseInt(arr1[pos]) - parseInt(arr2[pos]);
               if (diff == 0) {
                  pos++;
                  continue;
               } else if (diff > 0) {
                  flag = true;
                  break;
               } else {
                  flag = false;
                  break;
               }
            }
            return flag;
         },
         //确认更新
         sure() {
@@ -433,7 +302,7 @@
                  plus.runtime.openFile(d.filename); //选择软件打开文件
                  uni.showToast({
                     icon: 'none',
                     title: '更新成功'
                     title: this.translate('update_success')
                  });
                  _this.$refs.promotion.close();
               } else {
@@ -441,7 +310,7 @@
                  plus.downloader.clear(); //清除下载任务
                  uni.showToast({
                     icon: 'none',
                     title: '更新失败'
                     title: this.translate('update_fail')
                  });
                  _this.showBtns = false;
               }
@@ -467,6 +336,12 @@
         inputDialogToggle() {
            this.$refs.inputDialog.open()
         },
         clickSetLanguage() {
            uni.navigateTo({
               url: './language'
            });
         },
         dialogInputConfirm(val) {
            // console.log(val);
            // uni.showLoading({
@@ -475,7 +350,7 @@
            // setTimeout(() => {
            // uni.hideLoading();
            this.userServer = val;
            uni.setStorageSync('server', val);
            utils.session.setValue('server', val);
            // this.value = val
            // 关闭窗口后,恢复默认内容
            this.$refs.inputDialog.close();
@@ -486,11 +361,11 @@
         },
         rememberPwd(e) { //记住密码
            console.log(e.target);
            uni.setStorageSync('account', '');
            uni.setStorageSync('password', '');
            utils.session.setValue('account', '');
            utils.session.setValue('password', '');
            if (e.target.value[0] == '1') {
               uni.setStorageSync('account', this.userName);
               uni.setStorageSync('password', this.userPwd);
               utils.session.setValue('account', this.userName);
               utils.session.setValue('password', this.userPwd);
            }
         },
         // getCookie(key){
@@ -515,46 +390,49 @@
         logind() {
            if (!this.userServer) {
               uni.showModal({
                  title: "提示",
                  content: "未输入网站地址,请重新配置输入!",
                  title: this.translateSys('tip'),
                  content: this.translate('tip_no_web_server'),
                  showCancel: false,
                  confirmText: "取消"
                  confirmText: this.translateSys('cancel')
               });
               return;
            }
            if (!this.userName) {
               uni.showModal({
                  title: "提示",
                  content: "未输入用户名,请重新输入!",
                  title: this.translateSys('tip'),
                  content: this.translate('tip_no_user_account'),
                  showCancel: false,
                  confirmText: "取消"
                  confirmText: this.translateSys('cancel')
               });
               return;
            }
            if (!this.userPwd) {
               uni.showModal({
                  title: "提示",
                  content: "未输入密码,请重新输入!",
                  title: this.translateSys('tip'),
                  content: this.translate('tip_no_user_password'),
                  showCancel: false,
                  confirmText: "取消"
                  confirmText: this.translateSys('cancel')
               });
               return;
            }
            var rootUrl = 'http://' + this.userServer
            if (this.userServer.includes("://")) {
               rootUrl = this.userServer
            }
            //检查 "登录状态/锁屏状态" 结束
            var loginInfo = {
               server: this.userServer,
               server:rootUrl,
               uname: this.userName,
               pwd: this.userPwd,
               cname: plus.device.model,
               type: "0"
            };
            console.log(loginInfo);
            this.$data.login = "loading......";
            showLoading("loading......")
            //登录
            this.$store.dispatch('login', loginInfo).then(success => {
               console.log(success);
               if (success.code == '00000' || success.err_code==0) {
               if (success.code == '00000' || success.err_code == 0) {
                  //登录成功后清空缓存数据
                  this.$store.commit("areaFunc", null);
                  this.$store.commit("classAttrList", null);
@@ -563,43 +441,86 @@
                  this.$store.commit("subClassAttrList", null);
                  this.$store.commit("subClassGridStyleInfo", null);
                  //设置全局参数:user-用户信息
                  uni.setStorageSync('server', loginInfo.server);
                  uni.setStorageSync('account', loginInfo.uname);
                  uni.setStorageSync('password', loginInfo.pwd);
                  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'
                  // });
                  this.login = "开始登录";
               } else {
                  hideLoading()
                  uni.showModal({
                     title: "错误",
                     title: this.translateSys('error'),
                     content: success.msg,
                     showCancel: false,
                     confirmText: "取消"
                     confirmText: this.translateSys('cancel')
                  });
                  this.login = "开始登录";
               }
            }).catch(ex => {
               console.log(ex);
               hideLoading()
               uni.showModal({
                  title: "错误",
                  title: this.translateSys('error'),
                  content: ex.errMsg,
                  showCancel: false,
                  confirmText: "取消"
                  confirmText: this.translateSys('cancel')
               });
               this.login = "开始登录";
            });
         }
         },
         translate(t) {
            if (typeof this.$t == "function") return this.$t(`page.${t}`)
            else return t;
         },
         translateSys(t) {
            if (typeof this.$t == "function") return this.$t(`sys.${t}`)
            else return t;
         },
      },
      onLoad() {
         //获取mac地址
         var url = this.$store.state.url;
         var username = this.$store.state.username;
         var userpwd = this.$store.state.userpwd;
         var ischecked = false;
         if (!this.userServer)
            this.userServer = url;
         if (!this.userName)
            this.userName = username;
         if (this.userName && this.userPwd)
            ischecked = true;
         this.ischecked = ischecked
         var net = plus.android.importClass("java.net.NetworkInterface");
         var wl0 = net.getByName('wlan0');
         var macByte = wl0.getHardwareAddress();
         var deviceId = ''
         //下面这段代码来自网络
         for (var i = 0; i < macByte.length; i++) {
            var tmp = "";
            var num = macByte[i];
            if (num < 0) {
               tmp = (255 + num + 1).toString(16);
            } else {
               tmp = num.toString(16);
            }
            if (tmp.length == 1) {
               tmp = "0" + tmp;
            }
            deviceId += tmp;
         }
         //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;
@@ -607,3 +528,135 @@
      }
   }
</script>
<style lang="scss">
   .uni-page-login {
      input::-webkit-input-placeholder {
         font-size: 12rpx;
      }
      #headr {
         background: #434343;
         /* width: 375px; */
         height: 250rpx;
         text-align: center;
         background-color: #438EB9;
         /* background-image: url(../../images/login/root.png) !important;
      background-size: cover !important;
      background-repeat: no-repeat !important; */
      }
      .SetServer {
         float: left;
         margin-left: 20rpx;
      }
      .check_rememberPwd {
         margin-top: 20rpx;
         margin-left: 20rpx;
      }
      .logo {
         height: 180rpx;
         width: 180rpx;
         margin-top: 170rpx;
      }
      .logo_input {
         height: 40rpx;
         width: 40rpx;
         margin-left: 40rpx;
      }
      .logo_icon {
         height: 50rpx;
         width: 50rpx;
         margin-left: 15rpx;
         margin-top: 20rpx;
      }
      .mui-content {
         height: 100%;
         padding-top: 140rpx;
         background: #FFFFFF;
         z-index: 1;
      }
      .mui-input-group .la_icon {
         width: 100rpx;
         text-align: center;
         font-family: 'Helvetica Neue', Helvetica, sans-serif;
         line-height: 1.5;
         float: left;
         padding: 7px 13px;
      }
      .mui-input-group .mui-input-row {
         height: 85rpx;
         position: relative;
         clear: left;
         overflow: hidden;
      }
      .mui-input-row:first-child {
         border-top: 1px solid #c8c7cc;
      }
      .mui-input-row:last-child {
         border-bottom: 1px solid #c8c7cc;
      }
      .mui-input-group .mui-input-row:last-child:after {
         background-color: #fff;
      }
      .mui-input-group .mui-input-row:after {
         position: absolute;
         right: 0;
         bottom: 0;
         left: 15px;
         height: 1px;
         content: '';
         transform: scaleY(.5);
         background-color: #c8c7cc;
      }
      .mui-input-row input {
         font-family: 'Helvetica Neue', Helvetica, sans-serif;
         font-size: 15px;
         width: 480rpx;
         /* float: right; */
         margin-bottom: 0;
         padding-left: 20rpx;
         /* padding-right: 10rpx; */
         /* line-height: 30rpx; */
         height: 85rpx;
         /* padding: 7px 40px 7px 0px; */
         -webkit-user-select: text;
         /* border: 0; */
         /* border-radius: 0; */
         box-shadow: none;
         outline: 0;
         background: 0 0;
         -webkit-appearance: none;
      }
      .mui-input-group label.mui-navigate-right {
         font-size: 25px;
         float: right;
         padding: 0;
         width: 80rpx;
         margin-right: 5rpx;
         margin-top: -88rpx;
         display: inline-block;
      }
      button.btn_login {
         margin-top: 50rpx;
         padding: 20rpx;
         line-height: 1.5;
         background: #27A6E1;
         border: none;
         color: #fff;
      }
   }
</style>