wlzboy
2025-09-26 97db9d11ff425583d2dece82a842a7766bb5e7e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<template>
  <scroll-view class="normal-login-container" scroll-y="true">
    <view class="logo-content align-center justify-center flex">
      <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
      </image>
      <text class="title">民航调度系统</text>
    </view>
    <view class="login-form-content">
      <view class="input-item flex align-center">
        <view class="iconfont icon-user icon"></view>
        <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
      </view>
      <view class="input-item flex align-center">
        <view class="iconfont icon-password icon"></view>
        <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
      </view>
      <view class="input-item flex align-center captcha-container" v-if="captchaEnabled">
        <view class="iconfont icon-code icon"></view>
        <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
        <view class="login-code"> 
          <image :src="codeUrl" @click="getCode" class="login-code-img" mode="aspectFit"></image>
        </view>
      </view>
      <view class="action-btn">
        <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
      </view>
      <view class="wechat-login" @click="handleWechatLogin">
        <view class="wechat-btn">
          <image class="wechat-icon" src="/static/icons/profile.png"></image>
          <text class="wechat-text">微信一键登录</text>
        </view>
      </view>
      <view class="reg text-center" v-if="register">
        <text class="text-grey1">没有账号?</text>
        <text @click="handleUserRegister" class="text-blue">立即注册</text>
      </view>
      <view class="xieyi text-center">
        <text class="text-grey1">登录即代表同意</text>
        <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
        <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
      </view>
    </view>
  </scroll-view>
</template>
 
<script>
  import { getCodeImg } from '@/api/login'
 
  export default {
    data() {
      return {
        codeUrl: "",
        captchaEnabled: true,
        // 用户注册开关
        register: false,
        globalConfig: getApp().globalData.config,
        loginForm: {
          username: "admin",
          password: "admin123",
          code: "",
          uuid: ''
        }
      }
    },
    created() {
      this.getCode()
    },
    methods: {
      // 用户注册
      handleUserRegister() {
        this.$tab.redirectTo(`/pages/register`)
      },
      // 隐私协议
      handlePrivacy() {
        let site = this.globalConfig.appInfo.agreements[0]
        this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
      },
      // 用户协议
      handleUserAgrement() {
        let site = this.globalConfig.appInfo.agreements[1]
        this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
      },
      // 获取图形验证码
      getCode() {
        getCodeImg().then(res => {
          this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
          if (this.captchaEnabled) {
            this.codeUrl = 'data:image/gif;base64,' + res.img
            this.loginForm.uuid = res.uuid
          }
        })
      },
      // 登录方法
      async handleLogin() {
        if (this.loginForm.username === "") {
          this.$modal.msgError("请输入您的账号")
        } else if (this.loginForm.password === "") {
          this.$modal.msgError("请输入您的密码")
        } else if (this.loginForm.code === "" && this.captchaEnabled) {
          this.$modal.msgError("请输入验证码")
        } else {
          this.$modal.loading("登录中,请耐心等待...")
          this.pwdLogin()
        }
      },
      // 微信登录方法
      async handleWechatLogin() {
        // #ifdef MP-WEIXIN
        // 微信小程序登录
        uni.login({
          provider: 'weixin',
          success: (loginRes) => {
            console.log('微信登录成功', loginRes);
            // 获取用户信息
            uni.getUserInfo({
              provider: 'weixin',
              success: (infoRes) => {
                console.log('用户信息获取成功', infoRes);
                // 跳转到微信登录确认页面
                this.$tab.navigateTo(`/pages/login/wechat?userInfo=${encodeURIComponent(JSON.stringify(infoRes.userInfo))}`);
              },
              fail: (error) => {
                console.error('获取用户信息失败', error);
                this.$modal.msgError("获取微信用户信息失败");
              }
            });
          },
          fail: (error) => {
            console.error('微信登录失败', error);
            this.$modal.msgError("微信登录失败");
          }
        });
        // #endif
        
        // #ifndef MP-WEIXIN
        // H5或其他平台提示
        this.$modal.msgError("请在微信客户端中使用微信登录功能");
        // #endif
      },
      // 密码登录
      async pwdLogin() {
        this.$store.dispatch('Login', this.loginForm).then(() => {
          this.$modal.closeLoading()
          this.loginSuccess()
        }).catch(() => {
          if (this.captchaEnabled) {
            this.getCode()
          }
        })
      },
      // 登录成功后,处理函数
      loginSuccess(result) {
        // 设置用户信息
        this.$store.dispatch('GetInfo').then(res => {
          this.$tab.reLaunch('/pages/index')
        })
      }
    }
  }
</script>
 
<style lang="scss">
  page {
    background-color: #ffffff;
  }
 
  .normal-login-container {
    width: 100%;
    min-height: 100vh;
    // 隐藏滚动条但保持滚动功能
    ::-webkit-scrollbar {
      display: none;
      width: 0 !important;
      height: 0 !important;
      background: transparent;
    }
    
    // Firefox滚动条隐藏
    * {
      scrollbar-width: none; /* Firefox */
    }
    
    // IE/Edge滚动条隐藏
    * {
      -ms-overflow-style: none; /* IE 10+ */
    }
 
    .logo-content {
      width: 100%;
      font-size: 21px;
      text-align: center;
      padding-top: 15%;
 
      image {
        border-radius: 4px;
      }
 
      .title {
        margin-left: 10px;
      }
    }
 
    .login-form-content {
      text-align: center;
      margin: 20px auto;
      margin-top: 15%;
      width: 80%;
 
      .input-item {
        margin: 20px auto;
        background-color: #f5f6f7;
        height: 45px;
        border-radius: 20px;
 
        .icon {
          font-size: 38rpx;
          margin-left: 10px;
        }
 
        .input {
          margin-left: 20rpx;
          width: 100%;
          height: 45px;
          background: none;
        }
      }
 
      .captcha-container {
        width: 100%;
        margin: 20px auto;
        background-color: #f5f6f7;
        height: 45px;
        border-radius: 20px;
        padding-right: 10rpx;
        box-sizing: border-box;
 
        .icon {
          font-size: 38rpx;
          margin-left: 10px;
        }
 
        .input {
          margin-left: 20rpx;
          width: 60%;
          height: 45px;
          background: none;
        }
 
        .login-code {
          width: 30%;
          height: 45px;
          margin-left: 10rpx;
          border-left: 1px solid #e0e0e0;
          display: flex;
          align-items: center;
          justify-content: center;
 
          .login-code-img {
            max-width: 100%;
            max-height: 45px;
            object-fit: contain;
            cursor: pointer;
          }
        }
      }
 
      .action-btn {
        margin: 40rpx 0;
 
        .login-btn {
          height: 90rpx;
          font-size: 32rpx;
        }
      }
 
      .wechat-login {
        margin: 20rpx 0;
 
        .wechat-btn {
          display: flex;
          align-items: center;
          justify-content: center;
          background-color: #07c160;
          height: 90rpx;
          border-radius: 20px;
 
          .wechat-icon {
            width: 40rpx;
            height: 40rpx;
            margin-right: 10rpx;
          }
 
          .wechat-text {
            color: white;
            font-size: 32rpx;
          }
        }
      }
 
      .reg, .xieyi {
        margin: 20rpx 0;
 
        .text-grey1 {
          color: #888;
        }
 
        .text-blue {
          margin: 0 10rpx;
          color: #007AFF;
        }
      }
    }
  }
</style>