DESKTOP-8FESTBI\Administrator 7 ay önce
ebeveyn
işleme
12c571b3ec
1 değiştirilmiş dosya ile 182 ekleme ve 116 silme
  1. 182
    116
      RuoYi-App/pages/login.vue

+ 182
- 116
RuoYi-App/pages/login.vue Dosyayı Görüntüle

@@ -1,7 +1,6 @@
1 1
 <template>
2 2
   <view class="normal-login-container">
3 3
     <view class="logo-content align-center justify-center flex">
4
-<!--      <image :src="globalConfig.appInfo.logo" class="logo" /> -->
5 4
       <text class="title">哎呀免费小说登录</text>
6 5
     </view>
7 6
     <view class="login-form-content">
@@ -45,132 +44,203 @@
45 44
 </template>
46 45
 
47 46
 <script>
48
-  //import { getCodeImg } from '@/api/login'
49
-  //import { getToken } from '@/utils/auth'
50
-
51
-  export default {
52
-    data() {
53
-      return {
54
-        codeUrl: "",
55
-        captchaEnabled: true,
56
-        // 用户注册开关
57
-        register: false,
58
-        globalConfig: getApp().globalData.config,
59
-        loginForm: {
60
-          username: "admin",
61
-          password: "admin123",
62
-          code: "",
63
-          uuid: ""
47
+export default {
48
+  data() {
49
+    return {
50
+      codeUrl: "",
51
+      captchaEnabled: false, // 默认不开启验证码
52
+      register: false,
53
+      // 安全的全局配置访问方式
54
+      globalConfig: {
55
+        appInfo: {
56
+          logo: "",
57
+          agreements: []
58
+        }
59
+      },
60
+      loginForm: {
61
+        username: "",
62
+        password: "",
63
+        code: "",
64
+        uuid: ""
65
+      }
66
+    }
67
+  },
68
+  created() {
69
+    // 安全地获取全局配置
70
+    this.safeInit();
71
+  },
72
+  onLoad() {
73
+    // 如果全局配置已设置,则使用全局配置
74
+    if (this.$config) {
75
+      this.globalConfig = this.$config;
76
+    }
77
+  },
78
+  methods: {
79
+    // 安全的初始化方法
80
+    safeInit() {
81
+      try {
82
+        // 安全地获取全局配置
83
+        if (typeof getApp === 'function') {
84
+          const app = getApp();
85
+          if (app && app.globalData && app.globalData.config) {
86
+            this.globalConfig = app.globalData.config;
87
+          }
88
+        }
89
+        
90
+        // 尝试获取验证码
91
+        this.getCodeSafe();
92
+      } catch (error) {
93
+        console.error('初始化失败:', error);
94
+      }
95
+    },
96
+    
97
+    // 安全的获取验证码方法
98
+    async getCodeSafe() {
99
+      try {
100
+        await this.getCode();
101
+      } catch (error) {
102
+        console.error('获取验证码失败:', error);
103
+        // 可以设置默认行为,比如不显示验证码
104
+        this.captchaEnabled = false;
105
+      }
106
+    },
107
+    
108
+    // 获取验证码
109
+    async getCode() {
110
+      // 确保$http对象可用
111
+      if (!this.$http || typeof this.$http.get !== 'function') {
112
+        console.warn('$http未定义或不可用');
113
+        return;
114
+      }
115
+      
116
+      try {
117
+        const res = await this.$http.get('/captchaImage');
118
+        if (res.code === 200) {
119
+          this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
120
+          if (this.captchaEnabled) {
121
+            this.codeUrl = 'data:image/png;base64,' + res.data.img;
122
+            this.loginForm.uuid = res.data.uuid;
123
+          }
124
+        } else {
125
+          console.error('验证码获取失败:', res.msg);
64 126
         }
127
+      } catch (error) {
128
+        console.error('验证码请求失败:', error);
129
+        throw error;
65 130
       }
66 131
     },
67
-    created() {
68
-      this.getCode()
132
+    
133
+    // 用户注册
134
+    handleUserRegister() {
135
+      this.$router.push('/pages/register');
69 136
     },
70
-    onLoad() {
71
-		// 如果全局配置已设置,则使用全局配置
72
-		    if (this.$config) {
73
-		      this.globalConfig = this.$config
74
-		    }
75
-      //#ifdef H5
76
-      if (getToken()) {
77
-        this.$tab.reLaunch('/pages/index')
78
-      }
79
-      //#endif
137
+    
138
+    // 隐私协议
139
+    handlePrivacy() {
140
+      // 简化处理,直接跳转到webview页面
141
+      this.$router.push('/pages/common/webview?title=隐私协议&url=https://example.com/privacy');
80 142
     },
81
-    methods: {
82
-      // 用户注册
83
-      handleUserRegister() {
84
-        this.$tab.redirectTo(`/pages/register`)
85
-      },
86
-      // 隐私协议
87
-      // handlePrivacy() {
88
-      //   let site = this.globalConfig.appInfo.agreements[0]
89
-      //   this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
90
-      // },
91
-      // 用户协议
92
-      // handleUserAgrement() {
93
-      //   let site = this.globalConfig.appInfo.agreements[1]
94
-      //   this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
95
-      // },
96
-      // 获取图形验证码
97
-      // getCode() {
98
-      //   getCodeImg().then(res => {
99
-      //     this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
100
-      //     if (this.captchaEnabled) {
101
-      //       this.codeUrl = 'data:image/gif;base64,' + res.img
102
-      //       this.loginForm.uuid = res.uuid
103
-      //     }
104
-      //   })
105
-      // },
106
-	  // 获取验证码
107
-	  getCode() {
108
-	    this.$axios.get('/captchaImage').then(res => {
109
-	      this.codeUrl = 'data:image/png;base64,' + res.data.img;
110
-	      this.loginForm.uuid = res.data.uuid;
111
-	    }).catch(() => {
112
-	      this.$message.error("验证码获取失败");
113
-	    });
114
-	  },
115
-      // 登录方法
116
-      async handleLogin() {
117
-        if (this.loginForm.username === "") {
118
-          this.$modal.msgError("请输入账号")
119
-        } else if (this.loginForm.password === "") {
120
-          this.$modal.msgError("请输入密码")
121
-        } else if (this.loginForm.code === "" && this.captchaEnabled) {
122
-          this.$modal.msgError("请输入验证码")
143
+    
144
+    // 用户协议
145
+    handleUserAgrement() {
146
+      // 简化处理,直接跳转到webview页面
147
+      this.$router.push('/pages/common/webview?title=用户协议&url=https://example.com/agreement');
148
+    },
149
+    
150
+    // 登录方法
151
+    async handleLogin() {
152
+      if (!this.loginForm.username) {
153
+        this.$modal.msgError("请输入账号");
154
+        return;
155
+      }
156
+      
157
+      if (!this.loginForm.password) {
158
+        this.$modal.msgError("请输入密码");
159
+        return;
160
+      }
161
+      
162
+      if (this.captchaEnabled && !this.loginForm.code) {
163
+        this.$modal.msgError("请输入验证码");
164
+        return;
165
+      }
166
+      
167
+      this.$modal.loading("登录中,请耐心等待...");
168
+      
169
+      try {
170
+        await this.pwdLogin();
171
+      } catch (error) {
172
+        this.$modal.closeLoading();
173
+        this.$modal.msgError(error.message || '登录失败');
174
+        
175
+        // 刷新验证码
176
+        if (this.captchaEnabled) {
177
+          this.getCodeSafe();
178
+        }
179
+      }
180
+    },
181
+    
182
+    // 密码登录
183
+    async pwdLogin() {
184
+      try {
185
+        // 使用安全的API调用方式
186
+        if (this.$store && this.$store.dispatch) {
187
+          await this.$store.dispatch('Login', this.loginForm);
188
+          this.$modal.closeLoading();
189
+          this.loginSuccess();
123 190
         } else {
124
-          this.$modal.loading("登录中,请耐心等待...")
125
-          this.pwdLogin()
191
+          throw new Error('存储系统不可用');
126 192
         }
127
-      },
128
-      // 密码登录
129
-      async pwdLogin() {
130
-        this.$store.dispatch('Login', this.loginForm).then(() => {
131
-          this.$modal.closeLoading()
132
-          this.loginSuccess()
133
-        }).catch(() => {
134
-          if (this.captchaEnabled) {
135
-            this.getCode()
136
-          }
137
-        })
138
-      },
139
-      // 登录成功后,处理函数
140
-      loginSuccess(result) {
141
-        // 设置用户信息
142
-        this.$store.dispatch('GetInfo').then(res => {
143
-          this.$tab.reLaunch('/pages/index')
144
-        })
193
+      } catch (error) {
194
+        console.error('登录失败:', error);
195
+        throw error;
196
+      }
197
+    },
198
+    
199
+    // 登录成功后,处理函数
200
+    loginSuccess() {
201
+      // 设置用户信息
202
+      if (this.$store && this.$store.dispatch) {
203
+        this.$store.dispatch('GetInfo').then(() => {
204
+          this.$router.replace('/pages/index');
205
+        }).catch(error => {
206
+          console.error('获取用户信息失败:', error);
207
+          this.$router.replace('/pages/index');
208
+        });
209
+      } else {
210
+        this.$router.replace('/pages/index');
145 211
       }
146 212
     }
147 213
   }
214
+}
148 215
 </script>
149 216
 
150 217
 <style lang="scss" scoped>
218
+  /* 保持原有样式不变 */
151 219
   page {
152 220
     background-color: #ffffff;
153 221
   }
154
-.reading-tips {
155
-  margin-top: 40rpx;
156
-  padding: 20rpx;
157
-  background-color: #f9f9f9;
158
-  border-radius: 10rpx;
159
-}
160
-
161
-.tip-text {
162
-  font-size: 32rpx;
163
-  font-weight: bold;
164
-  display: block;
165
-  margin-bottom: 20rpx;
166
-}
167
-
168
-.benefits text {
169
-  display: block;
170
-  font-size: 28rpx;
171
-  margin: 10rpx 0;
172
-  color: #2c3e50;
173
-}
222
+  
223
+  .reading-tips {
224
+    margin-top: 40rpx;
225
+    padding: 20rpx;
226
+    background-color: #f9f9f9;
227
+    border-radius: 10rpx;
228
+  }
229
+  
230
+  .tip-text {
231
+    font-size: 32rpx;
232
+    font-weight: bold;
233
+    display: block;
234
+    margin-bottom: 20rpx;
235
+  }
236
+  
237
+  .benefits text {
238
+    display: block;
239
+    font-size: 28rpx;
240
+    margin: 10rpx 0;
241
+    color: #2c3e50;
242
+  }
243
+  
174 244
   .normal-login-container {
175 245
     width: 100%;
176 246
 
@@ -179,11 +249,7 @@
179 249
       font-size: 21px;
180 250
       text-align: center;
181 251
       padding-top: 15%;
182
-
183
-      image {
184
-        border-radius: 4px;
185
-      }
186
-
252
+      
187 253
       .title {
188 254
         margin-left: 10px;
189 255
       }

Loading…
İptal
Kaydet