#
whycq
2023-11-01 fb73be20fcdc285c46f1a350960e69c894361709
pages/LoginDemo/LoginDemo.vue
@@ -22,7 +22,7 @@
         <!-- <view class="button" @click="login" :loading="load.loading">
            {{load.btnText}} 
         </view> -->
         <button class="button" @click="onLogin()" :loading="load.loading">{{load.btnText}}</button>
         <button class="button" @click="login()" :loading="load.loading">{{load.btnText}}</button>
      </view>
      <!-- 设置弹窗区域 -->
      <uni-popup ref="settings" type="dialog">
@@ -67,6 +67,7 @@
      mapState
   } from 'vuex' //引入mapState
   import md5 from '../../static/js/md5.js'
   import common from '../api/common/common.js'
   export default {
      data() {
         return {
@@ -112,9 +113,9 @@
         }
         // 手机端版本号
         // #ifdef APP-PLUS
         var that = this
         var _this = this
         plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
            that.version = wgtinfo.version
            _this.version = wgtinfo.version
         });
         // #endif
      },
@@ -135,55 +136,51 @@
            uni.setStorageSync('Network', this.network);
            this.$refs.settings.close()
         },
         onLogin() {
            let _this = this,
               path = 'demo',
               network = uni.getStorageSync('Network');
            if (!network) {
         async login() {
            if (!uni.getStorageSync('Network')) {
               uni.showToast({ icon: 'error', title: '请配置网络信息' })
               return
            }
            if (!this.user.username ) {
               uni.showToast({ icon: 'none', title: '请输入账号' })
               return
            }
            if (!this.user.password ) {
               uni.showToast({ icon: 'none', title: '请输入密码' })
               return
            }
            this.load.loading = true;
            this.load.btnText = '登录中';
            uni.setStorageSync('user', this.user);
            let res = await common.onLogin(this.user)
            if (res.code === 200) {
               setTimeout(() => {
                  uni.showToast({
                     title: '登录成功'
                  })
                  setTimeout(() => {
                     uni.reLaunch({
                        url: `/pages/home/home`,
                     });
                  }, 300)
               }, 700)
            } else if (res.code === 0) {
               this.load.loading = false;
               this.load.btnText = '登录';
               uni.showToast({
                  icon: 'error',
                  title: '请配置网络信息'
                  icon: 'none',
                  title: '连接失败,请检查网络'
               })
            } else {
               this.load.loading = false;
               this.load.btnText = '登录';
               uni.showToast({
                  icon: 'none',
                  title: `${this.user.username} ${res.msg}`
               })
            }
            // path = network[0].address
            // path = path.substring(0, path.length - 3);
            path = _this.project.name
            let baseUrl = `http://${network[0].ip}:${network[0].port}/${network[0].address}`
            _this.load.loading = true;
            _this.load.btnText = '登录中';
            uni.setStorageSync('user', _this.user);
            uni.request({
               url: `${baseUrl}/login.action`,
               data: {
                  username: _this.user.username,
                  password: md5.hex_md5(_this.user.password)
               },
               success(res) {
                  res = res.data
                  if (res.code === 200) {
                     uni.setStorageSync('token', res.data.token);
                     _this.load.btnText = '登录中';
                     setTimeout(() => {
                        uni.showToast({
                           title: '登录成功'
                        })
                        setTimeout(() => {
                           uni.reLaunch({
                              url: `/pages/home/home`,
                           });
                        }, 300)
                     }, 700)
                  }
                  // uni.navigateTo({
                  //    url: `/pages/project/${path}/home/home`,
                  //    fail(res) {
                  //       console.log(`没有${path}项目,请联系管理元`);
                  //    }
                  // })
               }
            })
         }
         },
         // end
      }
   }
</script>