zhuguifei
2025-07-25 85a15646ffe20ed2bbb2042ec500df8c850a69cc
pages/login/login.vue
@@ -2,7 +2,7 @@
<template>
   <view class="contaier">
      <view class="top-bg">
         <view class="text-white text-bold text-xxxl">智能中草药干燥设备配套系统</view>
         <view class="text-white text-bold text-xxxl">兰浦<text @longpress="showModal">智能</text>干燥</view>
         <view class="margin-top-xs text-white">欢迎使用,请先登录</view>
      </view>
      <u-form labelPosition="left" :model="model" ref="form">
@@ -22,20 +22,30 @@
         <view class="padding margin-top-xs">
            <button @click="submit" class="cu-btn block round bg-login-zl margin-tb-sm lg">立即登录</button>
            <view class="text-gray flex justify-between padding-lr-sm">
               <text>注册账号</text>
               <text>忘记密码</text>
               <!-- <text @click="switchMode">局域网模式</text> -->
               <!-- <text>忘记密码</text> -->
            </view>
         </view>
      </u-form>
      <u-modal :show="show" title="提示" @confirm="handleSwitchMode">
         <view class="slot-content">
            <u-input v-model="pass" style="width: 100%;" placeholder="请输入管理员密码" border="surround" password
               clearable></u-input>
         </view>
      </u-modal>
   </view>
</template>
<script>
   export default {
      data() {
         return {
            show: false,
            pass: "",
            model: {
               username: "tongjitang",
               password: "123456"
               username: "",
               password: ""
            },
            rules: {
               'username': {
@@ -51,31 +61,57 @@
                  trigger: ['blur', 'change']
               },
            },
         };
      },
      onLoad() {
         const account = uni.getStorageSync('account');
         if (account) {
            this.model = account
         }
      },
      mounted() {
         setTimeout(() => {
            //this.model.username = this.clientPushId
         }, 1000)
      },
      computed: {
         clientPushId() {
            return this.$store.getters.getClientPushId;
      methods: {
         forget() {
         },
      },
      methods: {
         showModal() {
            this.pass = ""
            this.show = true
         },
         handleSwitchMode() {
            this.show = false
            if (this.pass === 'lanbaoit') {
               this.switchMode()
            }
         },
         switchMode() {
            uni.navigateTo({
               url: "/pages/tabBar/demo"
               url: "/packageA/pages/login/switchMode"
            })
         },
         submit() {
            if (this.model.username.startsWith("http")) {
               uni.setStorageSync('baseurl', this.model.username);
               this.model.username = null
               uni.$u.toast('配置baseUrl成功,请退出程序重新启动~')
               return false;
         forget() {
         },
         submit() {
            const mode = uni.getStorageSync('mode');
            //首次登录没有配置,默认为云服务模式
            if (!mode) {
               uni.setStorageSync('mode', 'cloud');
            }
            const curMode = uni.getStorageSync('mode');
            getApp().globalData.mode = curMode;
            this.$refs.form.validate().then(res => {
               this.login()
@@ -86,20 +122,16 @@
         },
         login() {
            this.$api.login(this.model).then((res) => {
               if (res.success) {
                  console.log('request success', res)
               if (res.success) {
                  uni.showToast({
                     title: '登录成功',
                     icon: 'success',
                     mask: true
                  });
                  //缓存信息
                  uni.setStorageSync('account', this.model);
                  uni.setStorageSync('userinfo', res.result.userInfo);
                  uni.setStorageSync('token', res.result.token);
                  uni.setStorageSync('token', res.result.token);
                  uni.switchTab({
                     url: '/pages/tabBar/general'
@@ -118,9 +150,7 @@
               console.log('request fail', err);
            })
         },
         onReset(e) {
            console.log(e)
         }
      },
      onReady() {
         //onReady 为uni-app支持的生命周期之一