Showing
1 changed file
with
63 additions
and
1 deletions
| ... | ... | @@ -17,6 +17,9 @@ |
| 17 | 17 | <view class="input-item"> |
| 18 | 18 | <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" placeholder-style="color:#aaa;" maxlength="20" /> |
| 19 | 19 | </view> |
| 20 | + <view class="remember-row"> | |
| 21 | + <uni-data-checkbox v-model="rememberVal" :localdata="rememberOptions" :multiple="true" /> | |
| 22 | + </view> | |
| 20 | 23 | <view class="input-row" v-if="captchaEnabled"> |
| 21 | 24 | <input v-model="loginForm.captcha" type="text" class="input" placeholder="请输入验证码" placeholder-style="color:#aaa;" maxlength="4" /> |
| 22 | 25 | <image :src="codeUrl" @click="getCode" class="captcha-img" /> |
| ... | ... | @@ -48,8 +51,10 @@ export default { |
| 48 | 51 | globalConfig: getApp().globalData.config, |
| 49 | 52 | codeUrl: "", |
| 50 | 53 | captchaEnabled: false, |
| 51 | - agreeVal: [], | |
| 54 | + agreeVal: ['1'], | |
| 52 | 55 | agreeOptions: [{ text: '已预览并同意', value: '1' }], |
| 56 | + rememberVal: [], | |
| 57 | + rememberOptions: [{ text: '记住密码', value: '1' }], | |
| 53 | 58 | // 用户注册开关 |
| 54 | 59 | register: false, |
| 55 | 60 | //默认登录账号和密码 |
| ... | ... | @@ -72,9 +77,53 @@ export default { |
| 72 | 77 | } |
| 73 | 78 | }, |
| 74 | 79 | created() { |
| 80 | + this.initRememberPwd() | |
| 75 | 81 | this.getCode() |
| 76 | 82 | }, |
| 77 | 83 | methods: { |
| 84 | + getAgreeChecked() { | |
| 85 | + return Array.isArray(this.agreeVal) | |
| 86 | + ? (this.agreeVal.includes('1') || this.agreeVal.length > 0) | |
| 87 | + : !!this.agreeVal | |
| 88 | + }, | |
| 89 | + getRememberChecked() { | |
| 90 | + return Array.isArray(this.rememberVal) | |
| 91 | + ? (this.rememberVal.includes('1') || this.rememberVal.length > 0) | |
| 92 | + : !!this.rememberVal | |
| 93 | + }, | |
| 94 | + initRememberPwd() { | |
| 95 | + const remember = uni.getStorageSync('login_remember_pwd') | |
| 96 | + const rememberChecked = remember === true || remember === '1' || remember === 1 | |
| 97 | + this.rememberVal = rememberChecked ? ['1'] : [] | |
| 98 | + | |
| 99 | + const username = uni.getStorageSync('login_username') | |
| 100 | + const password = uni.getStorageSync('login_password') | |
| 101 | + if (rememberChecked) { | |
| 102 | + if (username !== undefined && username !== null && username !== '') { | |
| 103 | + this.loginForm.username = username | |
| 104 | + } | |
| 105 | + if (password !== undefined && password !== null && password !== '') { | |
| 106 | + this.loginForm.password = password | |
| 107 | + } | |
| 108 | + } else { | |
| 109 | + if (username !== undefined && username !== null && username !== '') { | |
| 110 | + this.loginForm.username = username | |
| 111 | + } | |
| 112 | + } | |
| 113 | + }, | |
| 114 | + persistRememberPwd() { | |
| 115 | + const username = (this.loginForm.username || '').trim() | |
| 116 | + const password = (this.loginForm.password || '').trim() | |
| 117 | + const rememberChecked = this.getRememberChecked() | |
| 118 | + | |
| 119 | + uni.setStorageSync('login_username', username) | |
| 120 | + uni.setStorageSync('login_remember_pwd', rememberChecked) | |
| 121 | + if (rememberChecked) { | |
| 122 | + uni.setStorageSync('login_password', password) | |
| 123 | + } else { | |
| 124 | + uni.removeStorageSync('login_password') | |
| 125 | + } | |
| 126 | + }, | |
| 78 | 127 | // 用户注册 |
| 79 | 128 | handleUserRegister() { |
| 80 | 129 | this.$tab.redirectTo('/pages/register') |
| ... | ... | @@ -101,6 +150,10 @@ export default { |
| 101 | 150 | }, |
| 102 | 151 | // 登录方法 |
| 103 | 152 | async handleLogin() { |
| 153 | + if (!this.getAgreeChecked()) { | |
| 154 | + this.$modal.msgError("请先勾选已预览并同意") | |
| 155 | + return | |
| 156 | + } | |
| 104 | 157 | if (this.loginForm.username === "") { |
| 105 | 158 | this.$modal.msgError("请输入您的账号") |
| 106 | 159 | } else if (this.loginForm.password === "") { |
| ... | ... | @@ -125,6 +178,7 @@ export default { |
| 125 | 178 | }, |
| 126 | 179 | // 登录成功后,处理函数 |
| 127 | 180 | loginSuccess(result) { |
| 181 | + this.persistRememberPwd() | |
| 128 | 182 | this.$tab.reLaunch('/pages/index') |
| 129 | 183 | } |
| 130 | 184 | } |
| ... | ... | @@ -192,6 +246,14 @@ export default { |
| 192 | 246 | } |
| 193 | 247 | .captcha-img { width: 200rpx; height: 88rpx; border-left: 1px solid #e5e7eb; } |
| 194 | 248 | |
| 249 | + .remember-row { | |
| 250 | + display: flex; | |
| 251 | + align-items: center; | |
| 252 | + color: rgba(0,0,0,0.9); | |
| 253 | + margin-top: -16rpx; | |
| 254 | + font-size: 28rpx; | |
| 255 | + } | |
| 256 | + | |
| 195 | 257 | .agree-row { |
| 196 | 258 | display: flex; |
| 197 | 259 | align-items: center; | ... | ... |