Commit c8e00ad04c87358f2fe78c2544c89e26a3c9788c
1 parent
c533f5e5
使用社交账号(微信小程序)登录
Showing
10 changed files
with
160 additions
and
163 deletions
yudao-ui-app/api/auth.js
| ... | ... | @@ -9,4 +9,5 @@ export const logout = data => http.post('/member/logout', data) |
| 9 | 9 | export const sendSmsCode = data => http.post('/member/send-sms-code', data) |
| 10 | 10 | //使用手机 + 验证码登录 |
| 11 | 11 | export const smsLogin = data => http.post('/member/sms-login', data) |
| 12 | - | |
| 12 | +//社交登录,使用 (手机号授权)code + 用户信息 | |
| 13 | +export const socialLogin = data => http.post('/member/social-login', data) | ... | ... |
yudao-ui-app/pages.json
| ... | ... | @@ -25,17 +25,17 @@ |
| 25 | 25 | } |
| 26 | 26 | }, |
| 27 | 27 | { |
| 28 | - "path": "pages/login/login", | |
| 28 | + "path": "pages/login/social", | |
| 29 | 29 | "style": { |
| 30 | - "navigationBarTitleText": "账号登录" | |
| 31 | - } | |
| 32 | - }, | |
| 33 | - { | |
| 34 | - "path": "pages/register/register", | |
| 35 | - "style": { | |
| 36 | - "navigationBarTitleText": "注册账号" | |
| 30 | + "navigationBarTitleText": "授权登录" | |
| 37 | 31 | } |
| 38 | 32 | }, |
| 33 | + { | |
| 34 | + "path": "pages/login/mobile", | |
| 35 | + "style": { | |
| 36 | + "navigationBarTitleText": "手机登录" | |
| 37 | + } | |
| 38 | + }, | |
| 39 | 39 | { |
| 40 | 40 | "path": "pages/forgot/forgot", |
| 41 | 41 | "style": { | ... | ... |
yudao-ui-app/pages/address/create.vue
yudao-ui-app/pages/address/update.vue
yudao-ui-app/pages/cart/cart.vue
| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | |
| 7 | 7 | <view v-if="!hasLogin" class="login-tips-box"> |
| 8 | 8 | <view class="login-tips"> |
| 9 | - <navigator url="/pages/login/login" open-type="navigate" hover-class="none"> | |
| 9 | + <navigator url="/pages/login/social" open-type="navigate" hover-class="none"> | |
| 10 | 10 | <text class="login-link">登录</text> |
| 11 | 11 | </navigator> |
| 12 | 12 | <text>查看购物车</text> | ... | ... |
yudao-ui-app/pages/login/login.vue renamed to yudao-ui-app/pages/login/mobile.vue
| 1 | 1 | <template> |
| 2 | 2 | <view class="container"> |
| 3 | - <view class="unp-header"> | |
| 4 | - <view class="unp-logo"> | |
| 5 | - <u-avatar size="80" icon="github-circle-fill" fontSize="80"></u-avatar> | |
| 3 | + <view class="auth-header"> | |
| 4 | + <view class="auth-logo"> | |
| 5 | + <u-avatar size="100" icon="github-circle-fill" fontSize="100"></u-avatar> | |
| 6 | 6 | </view> |
| 7 | 7 | </view> |
| 8 | 8 | |
| 9 | - <view class="unp-box"> | |
| 9 | + <view class="auth-box"> | |
| 10 | 10 | <!-- 登录方式选择 --> |
| 11 | 11 | <view class="mode-section"> |
| 12 | - <u-subsection mode="subsection" fontSize="15" :list="loginModeList" :current="currentModeIndex" @change="handleModeChange"></u-subsection> | |
| 12 | + <u-subsection class="subsection" mode="subsection" fontSize="15" :list="loginModeList" :current="currentModeIndex" @change="handleModeChange"></u-subsection> | |
| 13 | 13 | </view> |
| 14 | 14 | <u-gap height="40"></u-gap> |
| 15 | 15 | |
| ... | ... | @@ -37,10 +37,7 @@ |
| 37 | 37 | </u-form-item> |
| 38 | 38 | |
| 39 | 39 | <view class="btn-group"> |
| 40 | - <u-button type="primary" text="登录" customStyle="margin-top: 50px" @click="handleSubmit"></u-button> | |
| 41 | - | |
| 42 | - <u-gap height="20"></u-gap> | |
| 43 | - <u-button type="info" text="返回" @click="navigateBack()"></u-button> | |
| 40 | + <u-button class="auth-btn" type="primary" customStyle="margin-top: 50px" @click="handleSubmit">登录/注册</u-button> | |
| 44 | 41 | </view> |
| 45 | 42 | </u--form> |
| 46 | 43 | </view> |
| ... | ... | @@ -48,7 +45,7 @@ |
| 48 | 45 | </template> |
| 49 | 46 | |
| 50 | 47 | <script> |
| 51 | -import { passwordLogin, sendSmsCode, smsLogin } from '../../api/auth' | |
| 48 | +import { sendSmsCode } from '../../api/auth' | |
| 52 | 49 | |
| 53 | 50 | export default { |
| 54 | 51 | data() { |
| ... | ... | @@ -145,45 +142,41 @@ export default { |
| 145 | 142 | this.$store.dispatch('Login', { type: this.currentModeIndex, data: this.formData }).then(res => { |
| 146 | 143 | uni.$u.toast('登录成功') |
| 147 | 144 | setTimeout(() => { |
| 148 | - this.navigateBack() | |
| 149 | - }, 1000) | |
| 145 | + uni.switchTab({ | |
| 146 | + url: '/pages/user/user' | |
| 147 | + }) | |
| 148 | + }, 300) | |
| 150 | 149 | }) |
| 151 | 150 | }) |
| 152 | - }, | |
| 153 | - navigateBack() { | |
| 154 | - uni.navigateBack() | |
| 155 | 151 | } |
| 156 | 152 | } |
| 157 | 153 | } |
| 158 | 154 | </script> |
| 159 | 155 | |
| 160 | 156 | <style lang="scss" scoped> |
| 161 | -.unp-header { | |
| 157 | +.auth-header { | |
| 162 | 158 | height: 400rpx; |
| 163 | 159 | @include flex-center; |
| 164 | - .unp-logo { | |
| 160 | + .auth-logo { | |
| 165 | 161 | @include flex-center(column); |
| 166 | 162 | } |
| 167 | 163 | } |
| 168 | 164 | |
| 169 | -.unp-box { | |
| 165 | +.auth-box { | |
| 170 | 166 | @include flex-center(column); |
| 171 | 167 | |
| 172 | 168 | .mode-section { |
| 173 | - width: 560rpx; | |
| 169 | + width: 600rpx; | |
| 170 | + .subsection { | |
| 171 | + height: 60rpx; | |
| 172 | + } | |
| 174 | 173 | } |
| 175 | 174 | .btn-group { |
| 176 | - width: 560rpx; | |
| 175 | + width: 600rpx; | |
| 176 | + .auth-btn { | |
| 177 | + height: 90rpx; | |
| 178 | + font-size: 32rpx; | |
| 179 | + } | |
| 177 | 180 | } |
| 178 | 181 | } |
| 179 | - | |
| 180 | -.lk-group { | |
| 181 | - height: 40rpx; | |
| 182 | - margin-top: 40rpx; | |
| 183 | - @include flex-space-between; | |
| 184 | - font-size: 12rpx; | |
| 185 | - | |
| 186 | - color: $u-primary; | |
| 187 | - text-decoration: $u-primary; | |
| 188 | -} | |
| 189 | 182 | </style> | ... | ... |
yudao-ui-app/pages/login/social.vue
0 → 100644
| 1 | +<template> | |
| 2 | + <view class="container"> | |
| 3 | + <view class="auth-header"> | |
| 4 | + <view class="auth-logo"> | |
| 5 | + <u-avatar size="100" icon="github-circle-fill" fontSize="100"></u-avatar> | |
| 6 | + </view> | |
| 7 | + </view> | |
| 8 | + | |
| 9 | + <view class="auth-box"> | |
| 10 | + <view class="btn-group"> | |
| 11 | + <!-- #ifdef MP-WEIXIN --> | |
| 12 | + <u-button class="auth-btn" open-type="getPhoneNumber" type="primary" @getphonenumber="getPhoneNumber">一键登录</u-button> | |
| 13 | + <navigator class="reg-login-link" url="/pages/login/mobile" open-type="navigate" hover-class="none">手机号登录/注册 ></navigator> | |
| 14 | + <!-- #endif --> | |
| 15 | + | |
| 16 | + <!-- #ifndef MP-WEIXIN --> | |
| 17 | + <u-button type="primary" text="手机号登录/注册" @click="handleJump"></u-button> | |
| 18 | + <!-- #endif --> | |
| 19 | + </view> | |
| 20 | + <view class="auth-footer"> | |
| 21 | + <view>登录即表示同意<text class="lk-text">《用户协议》</text> 和 <text class="lk-text">《隐私政策》</text></view> | |
| 22 | + </view> | |
| 23 | + </view> | |
| 24 | + </view> | |
| 25 | +</template> | |
| 26 | + | |
| 27 | +<script> | |
| 28 | +export default { | |
| 29 | + data() { | |
| 30 | + return {} | |
| 31 | + }, | |
| 32 | + onLoad() {}, | |
| 33 | + onReady() {}, | |
| 34 | + methods: { | |
| 35 | + getPhoneNumber(e) { | |
| 36 | + let code = e.detail.code | |
| 37 | + if (!e.detail.code) { | |
| 38 | + uni.showModal({ | |
| 39 | + title: '授权失败', | |
| 40 | + content: '您已拒绝获取绑定手机号登录授权,可以使用其他手机号验证登录', | |
| 41 | + cancelText: '知道了', | |
| 42 | + confirmText: '验证登录', | |
| 43 | + confirmColor: '#3C9CFFFF', | |
| 44 | + success: res => { | |
| 45 | + if (res.confirm) { | |
| 46 | + uni.$u.route('/pages/login/mobile') | |
| 47 | + } else if (res.cancel) { | |
| 48 | + //console.log('用户点击取消') | |
| 49 | + } | |
| 50 | + } | |
| 51 | + }) | |
| 52 | + } else { | |
| 53 | + uni.getUserInfo({ | |
| 54 | + provider: 'weixin', | |
| 55 | + success: res => { | |
| 56 | + this.$store.dispatch('Login', { type: 2, data: { code: code, userData: res } }).then(res => { | |
| 57 | + uni.$u.toast('登录成功') | |
| 58 | + setTimeout(() => { | |
| 59 | + uni.switchTab({ | |
| 60 | + url: '/pages/user/user' | |
| 61 | + }) | |
| 62 | + }, 300) | |
| 63 | + }) | |
| 64 | + } | |
| 65 | + }) | |
| 66 | + } | |
| 67 | + }, | |
| 68 | + handleJump() { | |
| 69 | + uni.$u.route('/pages/login/mobile') | |
| 70 | + } | |
| 71 | + } | |
| 72 | +} | |
| 73 | +</script> | |
| 74 | + | |
| 75 | +<style lang="scss" scoped> | |
| 76 | +.container { | |
| 77 | + height: calc(100vh - 70px); | |
| 78 | + @include flex-space-between(column); | |
| 79 | +} | |
| 80 | + | |
| 81 | +.auth-header { | |
| 82 | + flex: 2; | |
| 83 | + @include flex-center; | |
| 84 | + .auth-logo { | |
| 85 | + @include flex-center(column); | |
| 86 | + } | |
| 87 | +} | |
| 88 | + | |
| 89 | +.auth-box { | |
| 90 | + @include flex-center(column); | |
| 91 | + | |
| 92 | + .btn-group { | |
| 93 | + width: 600rpx; | |
| 94 | + margin-bottom: 200rpx; | |
| 95 | + .auth-btn { | |
| 96 | + height: 90rpx; | |
| 97 | + font-size: 32rpx; | |
| 98 | + } | |
| 99 | + } | |
| 100 | + | |
| 101 | + .reg-login-link { | |
| 102 | + margin-top: 32rpx; | |
| 103 | + text-align: center; | |
| 104 | + color: #636363; | |
| 105 | + font-size: 30rpx; | |
| 106 | + } | |
| 107 | + | |
| 108 | + .auth-footer { | |
| 109 | + font-size: 26rpx; | |
| 110 | + color: #939393; | |
| 111 | + .lk-text { | |
| 112 | + color: $u-primary; | |
| 113 | + text-decoration: $u-primary; | |
| 114 | + } | |
| 115 | + } | |
| 116 | +} | |
| 117 | +</style> | ... | ... |
yudao-ui-app/pages/register/register.vue deleted
| 1 | -<template> | |
| 2 | - <view class="container"> | |
| 3 | - <view class="unp-header"> | |
| 4 | - <view class="unp-logo"> | |
| 5 | - <u-avatar size="80" icon="github-circle-fill" fontSize="80"></u-avatar> | |
| 6 | - </view> | |
| 7 | - </view> | |
| 8 | - | |
| 9 | - <view class="unp-box"> | |
| 10 | - <u--form class="unp-form" labelPosition="left" :model="formData" :rules="rules" ref="form"> | |
| 11 | - <u-form-item label="账号" prop="username" borderBottom ref="item-username"> | |
| 12 | - <u-input type="text" maxlength="20" v-model="formData.username" clearable placeholder="账号由数字和字母组成" border="none" @change="handleUsernameChange"></u-input> | |
| 13 | - </u-form-item> | |
| 14 | - | |
| 15 | - <u-gap height="20"></u-gap> | |
| 16 | - | |
| 17 | - <u-form-item label="密码" prop="password" borderBottom ref="item-password"> | |
| 18 | - <u-input :type="inputType" maxlength="20" v-model="formData.password" placeholder="密码由数字、字母和符号组成" border="none" @change="handlePasswordChange"> | |
| 19 | - <template slot="suffix"> | |
| 20 | - <u-icon v-if="inputType === 'password'" size="20" color="#666666" name="eye-fill" @click="inputType = 'text'"></u-icon> | |
| 21 | - <u-icon v-if="inputType === 'text'" size="20" color="#666666" name="eye-off" @click="inputType = 'password'"></u-icon> | |
| 22 | - </template> | |
| 23 | - </u-input> | |
| 24 | - </u-form-item> | |
| 25 | - | |
| 26 | - <view class="lk-group"> | |
| 27 | - <!-- 占位 --> | |
| 28 | - </view> | |
| 29 | - | |
| 30 | - <u-button type="success" text="注册账号" customStyle="margin-top: 50px" @click="handleSubmit"></u-button> | |
| 31 | - | |
| 32 | - <u-gap height="20"></u-gap> | |
| 33 | - <u-button type="info" text="返回" @click="navigateBack()"></u-button> | |
| 34 | - </u--form> | |
| 35 | - </view> | |
| 36 | - </view> | |
| 37 | -</template> | |
| 38 | - | |
| 39 | -<script> | |
| 40 | -export default { | |
| 41 | - data() { | |
| 42 | - return { | |
| 43 | - inputType: 'password', | |
| 44 | - formData: { | |
| 45 | - username: '', | |
| 46 | - password: '' | |
| 47 | - }, | |
| 48 | - rules: { | |
| 49 | - username: { | |
| 50 | - type: 'string', | |
| 51 | - max: 20, | |
| 52 | - required: true, | |
| 53 | - message: '请输入您的账号', | |
| 54 | - trigger: ['blur', 'change'] | |
| 55 | - }, | |
| 56 | - password: { | |
| 57 | - type: 'string', | |
| 58 | - max: 20, | |
| 59 | - required: true, | |
| 60 | - message: '请输入您的密码', | |
| 61 | - trigger: ['blur', 'change'] | |
| 62 | - } | |
| 63 | - } | |
| 64 | - } | |
| 65 | - }, | |
| 66 | - onLoad() {}, | |
| 67 | - methods: { | |
| 68 | - handleUsernameChange(e) { | |
| 69 | - let str = uni.$u.trim(e, 'all') | |
| 70 | - this.$nextTick(() => { | |
| 71 | - this.formData.username = str | |
| 72 | - }) | |
| 73 | - }, | |
| 74 | - handlePasswordChange(e) { | |
| 75 | - let str = uni.$u.trim(e, 'all') | |
| 76 | - this.$nextTick(() => { | |
| 77 | - this.formData.password = str | |
| 78 | - }) | |
| 79 | - }, | |
| 80 | - handleSubmit() { | |
| 81 | - this.$refs.form.validate().then(res => { | |
| 82 | - uni.$u.toast('点击了注册账号') | |
| 83 | - }) | |
| 84 | - }, | |
| 85 | - navigateBack() { | |
| 86 | - uni.navigateBack() | |
| 87 | - } | |
| 88 | - } | |
| 89 | -} | |
| 90 | -</script> | |
| 91 | - | |
| 92 | -<style lang="scss" scoped> | |
| 93 | -.unp-header { | |
| 94 | - height: 400rpx; | |
| 95 | - @include flex-center; | |
| 96 | - .unp-logo { | |
| 97 | - @include flex-center; | |
| 98 | - } | |
| 99 | -} | |
| 100 | - | |
| 101 | -.unp-box { | |
| 102 | - @include flex-center; | |
| 103 | - .unp-form { | |
| 104 | - width: 560rpx; | |
| 105 | - } | |
| 106 | -} | |
| 107 | - | |
| 108 | -.lk-group { | |
| 109 | - @include flex-space-between; | |
| 110 | - height: 40rpx; | |
| 111 | - margin-top: 40rpx; | |
| 112 | - font-size: 12rpx; | |
| 113 | - | |
| 114 | - color: $u-primary; | |
| 115 | - text-decoration: $u-primary; | |
| 116 | -} | |
| 117 | -</style> |
yudao-ui-app/pages/user/user.vue
yudao-ui-app/store/index.js
| ... | ... | @@ -2,7 +2,7 @@ import Vue from 'vue' |
| 2 | 2 | import Vuex from 'vuex' |
| 3 | 3 | import { logout } from '@/api/auth' |
| 4 | 4 | import { getUserInfo } from '@/api/user' |
| 5 | -import { passwordLogin, smsLogin } from '@/api/auth' | |
| 5 | +import { passwordLogin, smsLogin, socialLogin } from '@/api/auth' | |
| 6 | 6 | |
| 7 | 7 | const TokenKey = 'App-Token' |
| 8 | 8 | |
| ... | ... | @@ -56,15 +56,18 @@ const store = new Vuex.Store({ |
| 56 | 56 | actions: { |
| 57 | 57 | //账号登录 |
| 58 | 58 | Login({ state, commit }, { type, data }) { |
| 59 | - console.log(type, data) | |
| 60 | 59 | if (type === 0) { |
| 61 | 60 | return passwordLogin(data).then(res => { |
| 62 | 61 | commit('SET_TOKEN', res.data) |
| 63 | 62 | }) |
| 64 | - } else { | |
| 63 | + } else if (type === 1) { | |
| 65 | 64 | return smsLogin(data).then(res => { |
| 66 | 65 | commit('SET_TOKEN', res.data) |
| 67 | 66 | }) |
| 67 | + } else { | |
| 68 | + return socialLogin(data).then(res => { | |
| 69 | + commit('SET_TOKEN', res.data) | |
| 70 | + }) | |
| 68 | 71 | } |
| 69 | 72 | }, |
| 70 | 73 | // 退出登录 | ... | ... |