Commit 07fe12483a19bb80ff9fa76dd086562dbde9a9f6
1 parent
55ee2fca
优化登陆界面,增加手机密码的登陆方式
Showing
2 changed files
with
115 additions
and
187 deletions
yudao-vue-ui/pages/auth/login.vue
| 1 | 1 | <template> |
| 2 | 2 | <view class="app"> |
| 3 | + <!-- 左下角的环 --> | |
| 3 | 4 | <view class="left-bottom-sign"></view> |
| 4 | - <view class="back-btn mix-icon icon-guanbi" @click="navBack"></view> | |
| 5 | + <!-- 右上角的折角 --> | |
| 5 | 6 | <view class="right-top-sign"></view> |
| 7 | + <!-- 左上角的 x 关闭 --> | |
| 8 | + <view class="back-btn mix-icon icon-guanbi" @click="navBack"></view> | |
| 9 | + <!-- 用户协议 --> | |
| 6 | 10 | <view class="agreement center"> |
| 7 | 11 | <text class="mix-icon icon-xuanzhong" :class="{active: agreement}" @click="checkAgreement"></text> |
| 8 | 12 | <text @click="checkAgreement">请认真阅读并同意</text> |
| 9 | - <text class="tit" @click="navToAgreementDetail(1)">《用户服务协议》</text> | |
| 10 | - <text class="tit" @click="navToAgreementDetail(2)">《隐私权政策》</text> | |
| 13 | + <text class="title" @click="navToAgreementDetail(1)">《用户服务协议》</text> | |
| 14 | + <text class="title" @click="navToAgreementDetail(2)">《隐私权政策》</text> | |
| 11 | 15 | </view> |
| 16 | + <!-- 登录表单 --> | |
| 12 | 17 | <view class="wrapper"> |
| 13 | 18 | <view class="left-top-sign">LOGIN</view> |
| 14 | - <view class="welcome"> | |
| 15 | - 欢迎回来! | |
| 16 | - </view> | |
| 19 | + <view class="welcome">手机登录/注册</view> | |
| 20 | + <!-- 手机验证码登录 --> | |
| 17 | 21 | <view class="input-content"> |
| 18 | 22 | <view class="input-item"> |
| 19 | - <text class="tit">手机号码</text> | |
| 23 | + <text class="title">手机号码</text> | |
| 20 | 24 | <view class="row"> |
| 21 | - <input | |
| 22 | - v-model="username" | |
| 23 | - type="number" | |
| 24 | - maxlength="11" | |
| 25 | - placeholder="请输入手机号码" | |
| 26 | - placeholder-style="color: #909399" | |
| 27 | - /> | |
| 25 | + <input v-model="mobile" type="number" maxlength="11" | |
| 26 | + placeholder="请输入手机号码" placeholder-style="color: #909399"/> | |
| 28 | 27 | </view> |
| 29 | 28 | </view> |
| 30 | - <view class="input-item"> | |
| 31 | - <text class="tit">验证码</text> | |
| 29 | + <!-- 判断使用验证码还是密码 --> | |
| 30 | + <view class="input-item" v-if="loginType == 'code'"> | |
| 31 | + <text class="title">验证码</text> | |
| 32 | + <view class="row"> | |
| 33 | + <input v-model="code" type="number" maxlength="6" | |
| 34 | + placeholder="请输入手机验证码" placeholder-style="color: #909399"> | |
| 35 | + <mix-code :mobile="mobile" templateCode="SMS_194050994"></mix-code> | |
| 36 | + </view> | |
| 37 | + </view> | |
| 38 | + <view class="input-item" v-else> | |
| 39 | + <text class="title">密码</text> | |
| 32 | 40 | <view class="row"> |
| 33 | - <input | |
| 34 | - v-model="code" | |
| 35 | - type="number" | |
| 36 | - maxlength="6" | |
| 37 | - placeholder="请输入手机验证码" | |
| 38 | - placeholder-style="color: #909399" | |
| 39 | - /> | |
| 40 | - <mix-code :mobile="username" templateCode="SMS_194050994"></mix-code> | |
| 41 | + <input v-model="password" type="password" maxlength="16" | |
| 42 | + placeholder="请输入密码" placeholder-style="color: #909399"/> | |
| 41 | 43 | </view> |
| 42 | 44 | </view> |
| 45 | + <mix-button ref="confirmBtn" text="立即登录" marginTop="60rpx" @onConfirm="login"></mix-button> | |
| 46 | + <!-- 切换登陆 --> | |
| 47 | + <view class="login-type" v-if="loginType == 'code'" @click="setLoginType('password')">账号密码登录</view> | |
| 48 | + <view class="login-type" v-else @click="setLoginType('code')">免密登录</view> | |
| 43 | 49 | </view> |
| 44 | - <mix-button ref="confirmBtn" text="登录" marginTop="60rpx" @onConfirm="login"></mix-button> | |
| 45 | 50 | |
| 51 | + <!-- 快捷登录 --> | |
| 46 | 52 | <!-- #ifdef APP-PLUS || MP-WEIXIN --> |
| 47 | 53 | <view class="other-wrapper"> |
| 48 | 54 | <view class="line center"> |
| 49 | - <text class="tit">快捷登录</text> | |
| 55 | + <text class="title">快捷登录</text> | |
| 50 | 56 | </view> |
| 51 | 57 | <view class="list row"> |
| 52 | 58 | <!-- #ifdef MP-WEIXIN --> |
| ... | ... | @@ -56,10 +62,6 @@ |
| 56 | 62 | <!-- #endif --> |
| 57 | 63 | |
| 58 | 64 | <!-- #ifdef APP-PLUS --> |
| 59 | - <view v-if="canUseAppleLogin && false" class="item column center" style="width: 180rpx;" @click="loginByApple"> | |
| 60 | - <image class="icon" src="/static/icon/apple.png"></image> | |
| 61 | - <text>Apple登录</text> | |
| 62 | - </view> | |
| 63 | 65 | <view class="item column center" style="width: 180rpx;" @click="loginByWxApp"> |
| 64 | 66 | <image class="icon" src="/static/icon/login-wx.png"></image> |
| 65 | 67 | <text>微信登录</text> |
| ... | ... | @@ -70,6 +72,7 @@ |
| 70 | 72 | <!-- #endif --> |
| 71 | 73 | </view> |
| 72 | 74 | |
| 75 | + <!-- Loading 框 --> | |
| 73 | 76 | <mix-loading v-if="isLoading"></mix-loading> |
| 74 | 77 | </view> |
| 75 | 78 | </template> |
| ... | ... | @@ -78,58 +81,63 @@ |
| 78 | 81 | import {checkStr} from '@/common/js/util' |
| 79 | 82 | import loginMpWx from './mixin/login-mp-wx.js' |
| 80 | 83 | import loginAppWx from './mixin/login-app-wx.js' |
| 81 | - import loginApple from './mixin/login-apple.js' | |
| 82 | 84 | export default{ |
| 83 | - mixins: [loginMpWx, loginAppWx, loginApple], | |
| 85 | + mixins: [loginMpWx, loginAppWx], | |
| 84 | 86 | data(){ |
| 85 | 87 | return { |
| 86 | - canUseAppleLogin: false, | |
| 87 | - agreement: true, | |
| 88 | - username: '', | |
| 88 | + loginType: 'code', // 登录方式,code 验证码;password 密码 | |
| 89 | + mobile: '', | |
| 89 | 90 | code: '', |
| 91 | + password: '', | |
| 92 | + agreement: true, | |
| 90 | 93 | } |
| 91 | 94 | }, |
| 92 | 95 | onLoad() { |
| 93 | - console.log(1); | |
| 94 | 96 | }, |
| 95 | 97 | methods: { |
| 96 | 98 | loginSuccessCallBack(data){ |
| 97 | - this.$util.msg('登陆成功'); | |
| 99 | + this.$util.msg('登录成功'); | |
| 98 | 100 | this.$store.commit('setToken', data); |
| 99 | 101 | setTimeout(()=>{ |
| 100 | 102 | uni.navigateBack(); |
| 101 | 103 | }, 1000) |
| 102 | 104 | }, |
| 103 | - //手机号登录 | |
| 105 | + // 手机号登录 | |
| 104 | 106 | async login(){ |
| 105 | - if(!this.agreement){ | |
| 107 | + // 参数校验 | |
| 108 | + if (!this.agreement){ | |
| 106 | 109 | this.$util.msg('请阅读并同意用户服务及隐私协议'); |
| 107 | 110 | this.$refs.confirmBtn.stop(); |
| 108 | 111 | return; |
| 109 | 112 | } |
| 110 | - const {username, code} = this; | |
| 111 | - if(!checkStr(username, 'mobile')){ | |
| 113 | + const {mobile, code, password} = this; | |
| 114 | + if (!checkStr(mobile, 'mobile')){ | |
| 112 | 115 | this.$util.msg('请输入正确的手机号码'); |
| 113 | 116 | this.$refs.confirmBtn.stop(); |
| 114 | 117 | return; |
| 115 | 118 | } |
| 116 | - if(!checkStr(code, 'mobileCode')){ | |
| 119 | + if (!checkStr(code, 'mobileCode')) { | |
| 117 | 120 | this.$util.msg('验证码错误'); |
| 118 | 121 | this.$refs.confirmBtn.stop(); |
| 119 | 122 | return; |
| 120 | 123 | } |
| 121 | - const res = await this.$request('user', 'login', {username,code}); | |
| 124 | + | |
| 125 | + // 执行登陆 | |
| 126 | + const res = await this.$request('user', 'login', {mobile,code}); | |
| 122 | 127 | this.$refs.confirmBtn.stop(); |
| 123 | 128 | |
| 124 | - if(res.status === 1){ | |
| 129 | + if (res.status === 1){ | |
| 125 | 130 | this.loginSuccessCallBack(res.data); |
| 126 | - }else{ | |
| 131 | + } else{ | |
| 127 | 132 | this.$util.msg(res.msg); |
| 128 | 133 | } |
| 129 | 134 | }, |
| 130 | 135 | navBack(){ |
| 131 | 136 | uni.navigateBack(); |
| 132 | 137 | }, |
| 138 | + setLoginType(loginType) { | |
| 139 | + this.loginType = loginType; | |
| 140 | + }, | |
| 133 | 141 | //同意协议 |
| 134 | 142 | checkAgreement(){ |
| 135 | 143 | this.agreement = !this.agreement; |
| ... | ... | @@ -154,7 +162,7 @@ |
| 154 | 162 | } |
| 155 | 163 | </style> |
| 156 | 164 | <style scoped lang='scss'> |
| 157 | - .app{ | |
| 165 | + .app { | |
| 158 | 166 | padding-top: 15vh; |
| 159 | 167 | position:relative; |
| 160 | 168 | width: 100vw; |
| ... | ... | @@ -162,12 +170,20 @@ |
| 162 | 170 | overflow: hidden; |
| 163 | 171 | background: #fff; |
| 164 | 172 | } |
| 165 | - .wrapper{ | |
| 173 | + .wrapper { | |
| 166 | 174 | position:relative; |
| 167 | 175 | z-index: 90; |
| 168 | 176 | padding-bottom: 40rpx; |
| 177 | + .welcome { | |
| 178 | + position:relative; | |
| 179 | + left: 50rpx; | |
| 180 | + top: -90rpx; | |
| 181 | + font-size: 46rpx; | |
| 182 | + color: #555; | |
| 183 | + text-shadow: 1px 0px 1px rgba(0,0,0,.3); | |
| 184 | + } | |
| 169 | 185 | } |
| 170 | - .back-btn{ | |
| 186 | + .back-btn { | |
| 171 | 187 | position:absolute; |
| 172 | 188 | left: 20rpx; |
| 173 | 189 | top: calc(var(--status-bar-height) + 20rpx); |
| ... | ... | @@ -176,18 +192,25 @@ |
| 176 | 192 | font-size: 32rpx; |
| 177 | 193 | color: #606266; |
| 178 | 194 | } |
| 179 | - .left-top-sign{ | |
| 195 | + .left-top-sign { | |
| 180 | 196 | font-size: 120rpx; |
| 181 | 197 | color: #f8f8f8; |
| 182 | 198 | position:relative; |
| 183 | 199 | left: -12rpx; |
| 184 | 200 | } |
| 185 | - .right-top-sign{ | |
| 201 | + .left-bottom-sign { | |
| 202 | + position: absolute; | |
| 203 | + left: -270rpx; | |
| 204 | + bottom: -320rpx; | |
| 205 | + border: 100rpx solid #d0d1fd; | |
| 206 | + border-radius: 50%; | |
| 207 | + padding: 180rpx; | |
| 208 | + } | |
| 209 | + .right-top-sign { | |
| 186 | 210 | position:absolute; |
| 187 | 211 | top: 80rpx; |
| 188 | 212 | right: -30rpx; |
| 189 | 213 | z-index: 95; |
| 190 | - | |
| 191 | 214 | &:before, &:after{ |
| 192 | 215 | display:block; |
| 193 | 216 | content:""; |
| ... | ... | @@ -207,56 +230,49 @@ |
| 207 | 230 | border-top-left-radius: 50px; |
| 208 | 231 | } |
| 209 | 232 | } |
| 210 | - .left-bottom-sign{ | |
| 211 | - position:absolute; | |
| 212 | - left: -270rpx; | |
| 213 | - bottom: -320rpx; | |
| 214 | - border: 100rpx solid #d0d1fd; | |
| 215 | - border-radius: 50%; | |
| 216 | - padding: 180rpx; | |
| 217 | - } | |
| 218 | - .welcome{ | |
| 219 | - position:relative; | |
| 220 | - left: 50rpx; | |
| 221 | - top: -90rpx; | |
| 222 | - font-size: 46rpx; | |
| 223 | - color: #555; | |
| 224 | - text-shadow: 1px 0px 1px rgba(0,0,0,.3); | |
| 225 | - } | |
| 226 | - .input-content{ | |
| 233 | + | |
| 234 | + /** 手机登录部分 */ | |
| 235 | + .input-content { | |
| 227 | 236 | padding: 0 60rpx; |
| 228 | - } | |
| 229 | - .input-item{ | |
| 230 | - display:flex; | |
| 231 | - flex-direction: column; | |
| 232 | - align-items:flex-start; | |
| 233 | - justify-content: center; | |
| 234 | - padding: 0 30rpx; | |
| 235 | - background: #f8f6fc; | |
| 236 | - height: 120rpx; | |
| 237 | - border-radius: 4px; | |
| 238 | - margin-bottom: 50rpx; | |
| 239 | - | |
| 240 | - &:last-child{ | |
| 241 | - margin-bottom: 0; | |
| 242 | - } | |
| 243 | - .row{ | |
| 244 | - width: 100%; | |
| 237 | + .input-item { | |
| 238 | + display:flex; | |
| 239 | + flex-direction: column; | |
| 240 | + align-items:flex-start; | |
| 241 | + justify-content: center; | |
| 242 | + padding: 0 30rpx; | |
| 243 | + background: #f8f6fc; | |
| 244 | + height: 120rpx; | |
| 245 | + border-radius: 4px; | |
| 246 | + margin-bottom: 50rpx; | |
| 247 | + &:last-child{ | |
| 248 | + margin-bottom: 0; | |
| 249 | + } | |
| 250 | + .row{ | |
| 251 | + width: 100%; | |
| 252 | + } | |
| 253 | + .title{ | |
| 254 | + height: 50rpx; | |
| 255 | + line-height: 56rpx; | |
| 256 | + font-size: 26rpx; | |
| 257 | + color: #606266; | |
| 258 | + } | |
| 259 | + input { | |
| 260 | + flex: 1; | |
| 261 | + height: 60rpx; | |
| 262 | + font-size: 30rpx; | |
| 263 | + color: #303133; | |
| 264 | + width: 100%; | |
| 265 | + } | |
| 245 | 266 | } |
| 246 | - .tit{ | |
| 247 | - height: 50rpx; | |
| 248 | - line-height: 56rpx; | |
| 249 | - font-size: 26rpx; | |
| 250 | - color: #606266; | |
| 267 | + .login-type { | |
| 268 | + display: flex; | |
| 269 | + justify-content: flex-end; | |
| 270 | + font-size: 13px; | |
| 271 | + color: #40a2ff; | |
| 272 | + margin-top: 20rpx; | |
| 251 | 273 | } |
| 252 | - input{ | |
| 253 | - flex: 1; | |
| 254 | - height: 60rpx; | |
| 255 | - font-size: 30rpx; | |
| 256 | - color: #303133; | |
| 257 | - width: 100%; | |
| 258 | - } | |
| 259 | 274 | } |
| 275 | + | |
| 260 | 276 | /* 其他登录方式 */ |
| 261 | 277 | .other-wrapper{ |
| 262 | 278 | display: flex; |
| ... | ... | @@ -264,11 +280,9 @@ |
| 264 | 280 | align-items: center; |
| 265 | 281 | padding-top: 20rpx; |
| 266 | 282 | margin-top: 80rpx; |
| 267 | - | |
| 268 | 283 | .line{ |
| 269 | 284 | margin-bottom: 40rpx; |
| 270 | - | |
| 271 | - .tit{ | |
| 285 | + .title { | |
| 272 | 286 | margin: 0 32rpx; |
| 273 | 287 | font-size: 24rpx; |
| 274 | 288 | color: #606266; |
| ... | ... | @@ -285,7 +299,6 @@ |
| 285 | 299 | color: #606266; |
| 286 | 300 | background-color: #fff; |
| 287 | 301 | border: 0; |
| 288 | - | |
| 289 | 302 | &:after{ |
| 290 | 303 | border: 0; |
| 291 | 304 | } |
| ... | ... | @@ -305,18 +318,16 @@ |
| 305 | 318 | height: 90rpx; |
| 306 | 319 | font-size: 24rpx; |
| 307 | 320 | color: #999; |
| 308 | - | |
| 309 | 321 | .mix-icon{ |
| 310 | 322 | font-size: 36rpx; |
| 311 | 323 | color: #ccc; |
| 312 | 324 | margin-right: 8rpx; |
| 313 | 325 | margin-top: 1px; |
| 314 | - | |
| 315 | 326 | &.active{ |
| 316 | 327 | color: $base-color; |
| 317 | 328 | } |
| 318 | 329 | } |
| 319 | - .tit{ | |
| 330 | + .title { | |
| 320 | 331 | color: #40a2ff; |
| 321 | 332 | } |
| 322 | 333 | } | ... | ... |
yudao-vue-ui/pages/auth/mixin/login-apple.js deleted
| 1 | -export default{ | |
| 2 | - onLoad() { | |
| 3 | - if(this.systemInfo.platform !== 'ios'){ | |
| 4 | - return; | |
| 5 | - } | |
| 6 | - const systemVersion = +this.systemInfo.system.split('.')[0]; | |
| 7 | - if(systemVersion >= 13){ | |
| 8 | - this.canUseAppleLogin = true; | |
| 9 | - } | |
| 10 | - }, | |
| 11 | - methods: { | |
| 12 | - //苹果登录 | |
| 13 | - async loginByApple(){ | |
| 14 | - /* if(!this.canUseAppleLogin){ | |
| 15 | - this.$util.msg('系统版本过低,无法使用苹果登录'); | |
| 16 | - return; | |
| 17 | - } */ | |
| 18 | - if(!this.agreement){ | |
| 19 | - this.$util.msg('请阅读并同意用户服务及隐私协议'); | |
| 20 | - this.$refs.confirmBtn.stop(); | |
| 21 | - return; | |
| 22 | - } | |
| 23 | - uni.login({ | |
| 24 | - provider: 'apple', | |
| 25 | - success: loginRes=> { | |
| 26 | - // 登录成功 | |
| 27 | - uni.getUserInfo({ | |
| 28 | - provider: 'apple', | |
| 29 | - success: async userRes=> { | |
| 30 | - console.log(userRes); | |
| 31 | - const response = await this.$request('user', 'loginByApple', { | |
| 32 | - authorizationCode: userRes.userInfo.authorizationCode, | |
| 33 | - identityToken: userRes.userInfo.identityToken | |
| 34 | - }, { | |
| 35 | - showLoading: true | |
| 36 | - }); | |
| 37 | - console.log(response); | |
| 38 | - //注销苹果登录 | |
| 39 | - this.appleLogout(); | |
| 40 | - console.log(response); | |
| 41 | - if(response.status === 0){ | |
| 42 | - this.$util.msg(response.msg); | |
| 43 | - return; | |
| 44 | - } | |
| 45 | - if(response.hasBindMobile && response.data.token){ | |
| 46 | - this.loginSuccessCallBack({ | |
| 47 | - token: response.data.token, | |
| 48 | - tokenExpired: response.data.tokenExpired | |
| 49 | - }); | |
| 50 | - }else{ | |
| 51 | - this.navTo('/pages/auth/bindMobile?type=apple&data='+JSON.stringify(response.data)) | |
| 52 | - } | |
| 53 | - } | |
| 54 | - }) | |
| 55 | - }, | |
| 56 | - fail: err=> { | |
| 57 | - console.log(err); | |
| 58 | - this.$util.msg('登录失败'); | |
| 59 | - this.appleLogout(); | |
| 60 | - } | |
| 61 | - }) | |
| 62 | - }, | |
| 63 | - appleLogout(){ | |
| 64 | - plus.oauth.getServices(oauthRes=>{ | |
| 65 | - const oIndex = oauthRes.findIndex(oItem=> oItem.id === 'apple'); | |
| 66 | - oauthRes[oIndex].logout(loRes => { | |
| 67 | - console.log('appleLogout success=> ', loRes); | |
| 68 | - }, loErr => { | |
| 69 | - console.log('appleLogout error=> ', loErr); | |
| 70 | - }) | |
| 71 | - }) | |
| 72 | - } | |
| 73 | - } | |
| 74 | -} | |
| 75 | - | |
| 76 | - | |
| 77 | - | |
| 78 | - | |
| 79 | - | |
| 80 | - | |
| 81 | - | |
| 82 | - | |
| 83 | - |