Commit e4e6beef authored by Facius's avatar Facius

feat: 登录改造

parent 6df338bc
Pipeline #6606 canceled with stages
......@@ -2,7 +2,10 @@
<script>
import { getLatestVersionNumber } from '@/api/common/index.js';
import { version } from '@/utils/config.js';
import { checkToken } from '@/utils/common.js';
import {
platform,
} from '@/utils/platform'
export default {
onLaunch: function() {
// setToken("eyJ0eXAiOiJKc29uV2ViVG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJ1bmlvbklkIjoib1gtVEs2VmVTWmNVbUx0cWhodk15NU1mYk9IMCIsIm9wZW5JZCI6Im9aZk5VNUVhSEF3bGdrbm8yQno3Y1Q0X0JRVUUiLCJuYW1lIjoi6Ze7562gIiwibW9iaWxlIjoiMTM0MjM4MzExOTEiLCJ0b2tlbl90eXBlIjoidG9rZW4iLCJ1c2VyaWQiOiIxNTUyNDg2NzEyMzY4NjkzMjQ4IiwiYWNjb3VudCI6IjEzNDIzODMxMTkxIiwiaWF0IjoxNjYwNzA4MzYyLCJuYmYiOjE2NjA3MDgzNjIsImV4cCI6MTY2MjAwNDM2Mn0.9hBVwqmYDxL4Q0S05JXQqteOWI9kda_UXxX5-eNO1LY")
......@@ -23,11 +26,25 @@ import { version } from '@/utils/config.js';
},
onShow: function() {
console.log('App Show')
this.autoLogin()
},
onHide: function() {
console.log('App Hide')
},
methods:{
autoLogin() {
if (platform != '1' || checkToken()) {
return
}
this.$store
.dispatch('Auto_login')
.then(res => {
console.log('登录成功', res);
})
.catch(err => {
console.log('登录失败', err);
});
},
/* 版本更新 */
updateApp() {
if (uni.canIUse('getUpdateManager')) {
......
......@@ -2,7 +2,7 @@ import request from "@/utils/request.js"
export function userAuthLogin(data) {
return request({
url: `/app/unify/authorization`,
url: `/app/unify/v2/authorization`,
method: 'POST',
data,
noLoading:true
......@@ -16,3 +16,11 @@ export function sendCode(data) {
data
})
}
export function userBindMobile(data) {
return request({
url: `/app/unify/v2/bindMobile`,
method: 'POST',
data,
noLoading:true
})
}
<template>
<button :style="[customStyle]" v-if="userInfo.id && !userInfo.mobile" class="bind-phone-button" :open-type="platform == '1' ? 'getPhoneNumber' : ''"
@getphonenumber="handleClickBindPhone" @click.stop="$u.throttle(handleToBind, 500)">
<view v-if="$slots.content" class="slot-view">
<slot name="content" />
</view>
<view v-else class="bind-phone-view" hover-class="u-hover-class">
<view class="left-view">若您是会员,请绑定手机号恢复权限</view>
<view class="right-view">
<view class="bind-view">立即绑定</view>
<u-icon name="arrow-right" color="#3383FE" :size="28" />
</view>
</view>
</button>
</template>
<script>
import { mapGetters } from 'vuex';
import { wxBindPhone } from '@/utils/bind-mobile.js';
export default {
props: {
customStyle: {
type: Object,
default () {
return {
'background-color': '#ffffff',
padding: '0 28rpx'
}
}
}
},
data () {
return {
show: false,
}
},
computed: {
...mapGetters(['platform', 'userInfo']),
},
watch: {
},
methods: {
handleClickBindPhone (e) {
wxBindPhone(e, () => {
this.getUserInfo();
});
},
handleToBind () {
console.log('-------------', this.platform)
if (this.platform == '4' || this.platform == '3' || this.platform == 'alipay') {
uni.navigateTo({
url: '/pages/login/binding-phone/binding-phone?type=phone'
});
}
},
async getUserInfo () {
try {
await this.$store.dispatch('Get_UserInfo');
this.$emit('bind', this.userInfo)
} catch (e) {
//TODO handle the exception
}
},
},
}
</script>
<style lang="scss" scoped>
.bind-phone-button::after {
border: none;
}
.bind-phone-button {
background-color: #ffffff;
.bind-phone-view {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 24rpx;
border-radius: 16rpx;
min-height: 72rpx;
height: 100%;
.left-view {
font-weight: bold;
color: #333333;
}
.right-view {
color: #3383fe;
display: flex;
align-items: center;
.bind-view {
margin-right: 8rpx;
}
.arrow-right {}
}
}
}
</style>
<template>
<u-popup v-model="show" safe-area-inset-bottom border-radius="24" mode="bottom" :closeable="true" @close="handleClose"
:zoom="false">
<view class="pop-bind-phone">
<view class="title-view">绑定提示</view>
<view class="content-view">享受完整会员权益,请您先绑定手机号码</view>
<button class="bind-phone" open-type="getPhoneNumber" @getphonenumber="handleClickBindPhone">
<view class="buttons-view">
<view class="left-view">
<image class="image-view" :src="imageUrl"></image>
</view>
<view class="right-view">绑定手机号</view>
</view>
</button>
</view>
</u-popup>
</template>
<script>
import { wxBindPhone } from '@/utils/bind-mobile.js';
export default {
props: {
visible: {
type: Boolean,
default: false,
},
},
data () {
return {
show: false,
}
},
watch: {
visible (val) {
this.show = val
},
},
computed: {
baseUrl(){
return process.uniEnv.qn_base_url
},
imageUrl(){
return this.baseUrl+'weixinbangding@3x.png'
},
},
created () { },
methods: {
changeVisibleValue (val) {
this.show = val
this.$emit('update:visible', val)
},
handleClickBindPhone (e) {
wxBindPhone(e, () => {
this.getUserInfo();
this.changeVisibleValue(false)
});
},
handleClose () {
this.changeVisibleValue(false)
},
async getUserInfo () {
try {
await this.$store.dispatch('Get_UserInfo');
this.$emit('bind', this.userInfo)
} catch (e) {
//TODO handle the exception
}
},
},
}
</script>
<style lang="scss" scoped>
.pop-bind-phone {
text-align: center;
padding: 24rpx 32rpx;
background-image: linear-gradient(to bottom, #E9F3FF 0%, #ffffff 50%);
.title-view {
color: #9EA5BB;
font-weight: bold;
font-size: 40rpx;
margin: 32rpx 0 24rpx 0;
}
.content-view {
display: flex;
align-items: center;
justify-content: center;
margin-top: 32rpx;
margin-bottom: 48rpx;
color: #333333;
}
.bind-phone {
background-color: #00C802;
box-shadow: 0 12rpx 24rpx rgba(0, 200, 2, 0.32);
height: 104rpx;
width: 520rpx;
border-radius: 52rpx;
margin-bottom: 32rpx;
padding: 0;
.buttons-view {
display: flex;
justify-content: center;
align-items: center;
height: 104rpx;
.left-view {
margin-right: 16rpx;
display: flex;
justify-content: center;
align-items: center;
.image-view {
width: 38rpx;
height: 32rpx;
}
}
.right-view {
color: #FFFFFF;
font-size: 32rpx;
font-weight: bold;
}
}
}
}
</style>
......@@ -32,6 +32,9 @@
</view>
<slot v-else />
</view>
<view v-if="isShare" class="bottom-tip">
<view class="tip-view">{{ bottomTip }}</view>
</view>
<view class="buttons-view">
<view v-if="showCancel" class="left-view">
<u-button
......@@ -61,11 +64,8 @@
</u-button>
</view>
</view>
<view v-if="isShare" class="bottom-tip">
<view class="tip-view">{{ bottomTip }}</view>
</view>
<view
v-else-if="bottomTip"
v-if="bottomTip && !isShare"
:class="['bottom-tip', { select: select }]"
:hover-class="isSelect ? 'u-hover-class' : ''"
@click="$u.throttle(handleSelect, 500)"
......@@ -80,12 +80,18 @@
</view>
<view class="tip-view">{{ bottomTip }}</view>
</view>
<BindPhone :customStyle="{'background-color': '#f4fffc',margin: '0 -32rpx -24rpx -24rpx',height: '104rpx'}" @bind="changeStatusDisplay"/>
</view>
</u-popup>
</template>
<script>
import BindPhone from '@/components/bind-phone';
export default {
components: {
BindPhone
},
props: {
title: {
type: String,
......@@ -213,6 +219,9 @@ export default {
handleSelect() {
this.select = !this.select
},
changeStatusDisplay() {
this.changeVisibleValue(false)
}
},
}
</script>
......@@ -279,6 +288,7 @@ export default {
display: flex;
align-items: center;
font-size: 28rpx;
margin-bottom: 24rpx;
&.select {
margin-top: 16rpx;
}
......
......@@ -95,6 +95,7 @@ export default {
width: 100%;
display: flex;
align-items: center;
margin-bottom: 32upx;;
.user-profile {
width: 160upx;
height: 160upx;
......
......@@ -44,7 +44,7 @@ export default {
<style lang="scss" scoped>
.content{
margin-top: 56upx;
margin-top: 24upx;
.my-package{
width: 100%;
height: 112upx;
......
......@@ -2,6 +2,7 @@
<view class="content">
<view class="mine">
<user-header :vipStatus="vipStatus" :vipStatusText="vipStatusText"></user-header>
<BindPhone @bind="changeStatusDisplay"/>
<!-- 购买会员入口 -->
<vip-center v-if="showPayEntrance"></vip-center>
<view v-else class="invite-view" hover-class="u-hover-class" @click="$u.throttle(handleClickInvite, 500)">
......@@ -21,6 +22,7 @@ import VipCenter from './components/vip-center.vue';
import MyPackage from './components/my-package.vue';
import UserTotal from './components/user-total.vue';
import MidPopup from '@/components/mid-popup/mid-popup.vue';
import BindPhone from '@/components/bind-phone';
import { usedOptions } from '@/utils/options/mine/index.js';
import { checkToken } from '@/utils/common.js';
import { tabbar } from '@/utils/settings.js';
......@@ -36,7 +38,8 @@ export default {
UserHeader,
VipCenter,
MyPackage,
UserTotal
UserTotal,
BindPhone
},
data() {
return {
......@@ -312,5 +315,35 @@ export default {
border-radius: 8upx;
overflow: hidden;
}
.bind-phone-button {
background-color: transparent;
padding: 0;
}
.bind-phone-view {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 24rpx;
background-color: #f4f9ff;
border-radius: 16rpx;
padding: 0 32rpx;
margin: 0 24rpx;
height: 72rpx;
.left-view {
font-weight: bold;
color: #333333;
}
.right-view {
color: #3383fe;
display: flex;
align-items: center;
.bind-view {
margin-right: 8rpx;
}
.arrow-right {
}
}
}
}
</style>
<template>
<view class="binding-phone-view">
<view class="title-view">绑定手机</view>
<view class="text-view">首次登录的用户需绑定手机</view>
<view class="text-view">{{ isPhone ? '绑定手机,多平台登录' : '首次登录的用户需绑定手机' }}</view>
<view class="phone-view">
<view class="left-view">+86</view>
<view class="middle-view"></view>
......@@ -24,6 +24,8 @@
<script>
import { sendCode } from '@/api/login/index.js';
import { bindPhone } from '@/utils/bind-mobile.js';
export default {
data() {
return {
......@@ -42,12 +44,16 @@ export default {
height: '104rpx',
backgroundColor: '#02A074',
color: 'transparent'
}
},
type: 'login'
};
},
computed: {
disabled() {
return this.code && this.phone ? false : true;
},
isPhone() {
return this.type == 'phone';
}
},
onReady() {
......@@ -55,7 +61,9 @@ export default {
},
onLoad(options) {
console.log('-----options----', options);
if (options && options.type) {
this.type = options.type;
}
if (options) {
let { unionId } = options;
if (unionId) {
......@@ -142,7 +150,71 @@ export default {
}
},
handleClickSave() {
this.signup();
var reg = /^[1][3456789][0-9]{9}$/;
if (!reg.test(this.phone)) {
uni.showToast({
icon: 'none',
title: '请输入正确的手机号'
});
return false;
}
if (this.isPhone) {
this.handleBindPhone();
} else {
this.onAppLogin();
}
},
handleBindPhone() {
bindPhone({
password: this.code,
account: this.phone
})
.then(res => {
console.log('------绑定手机接口:-------', res);
uni.showToast({
title: '绑定成功',
icon: 'none'
});
this.getUserInfo();
})
.catch(err => {
console.log('------绑定手机接口失败:-------', err);
uni.showToast({
title: '绑定手机失败',
icon: 'none'
});
});
},
async getUserInfo () {
try {
await this.$store.dispatch('Get_UserInfo');
this.goBackPage();
} catch (e) {
//TODO handle the exception
}
},
goBackPage() {
console.log('---------绑定成功跳转------');
let pages = getCurrentPages();
let len = pages.length;
if (len && len - 1) {
let prevPage = pages[len - 1]; //上一个页面
if (prevPage && prevPage.$vm) {
prevPage.$vm.isRefresh = true;
}
uni.navigateBack({
delta: 1
});
} else {
uni.switchTab({
url: '/pages/index/index'
});
}
},
signup() {
this.loading = true;
......@@ -228,7 +300,7 @@ export default {
});
} else if (data.code === -1) {
uni.redirectTo({
url: '/pages/login/binding-phone'
url: '/pages/login/binding-phone/binding-phone'
});
} else {
uni.showToast({
......
......@@ -238,7 +238,7 @@ export default {
} else {
// 临时解决方案
that.$u.route({
url: 'pages/login/binding-phone',
url: 'pages/login/binding-phone/binding-phone',
params: {
encryptedData: that.params.encryptedData,
iv: that.params.iv
......
......@@ -12,7 +12,8 @@
<view class="auth-tip">我们需要取得您的手机号,以关联您的扳手记账账号</view>
<view class="quick-center-buttons">
<button class="login-refuse" @tap="refuseAuth">拒绝</button>
<button class="login-refuse login-accept" open-type="getPhoneNumber" lang="zh_CN" @getphonenumber="signup">立即登录</button>
<!-- <button class="login-refuse login-accept" open-type="getPhoneNumber" lang="zh_CN" @getphonenumber="signup">立即登录</button> -->
<button class="login-refuse login-accept" lang="zh_CN" @click="newLoginup">立即登录</button>
</view>
</view>
</view>
......@@ -224,7 +225,51 @@ export default {
}
});
},
newLoginup() {
uni.getUserProfile({
desc: '用于授权登录',
success: res => {
console.log('授权成功', res);
const userInfo = {
nickname: res.userInfo.nickName,
avatar: res.userInfo.avatarUrl
};
getApp().globalData.wxUserInfo = userInfo;
console.log('授权成功', JSON.stringify(userInfo));
uni.showLoading({
title: '授权中..',
mask: true
});
console.log('--------------', res);
this.$store
.dispatch('Auto_login',userInfo)
.then(res => {
console.log('登录成功', res);
setTimeout(() => {
if (this.returnUrl) { // 需要跳转到特定页面
var isSwitchTab = this.returnUrl.indexOf('pages/index/') != -1
this.$u.route({
url: this.returnUrl,
type: isSwitchTab ? 'switchTab' : 'redirectTo',
})
}else {
uni.switchTab({
url: '/pages/index/index'
});
}
}, 1000);
})
.catch(err => {
showToast('登录失败');
console.log('登录失败', err);
});
},
fail: function(res) {
console.log('授权失败', res);
return;
}
});
},
signup(e) {
log.setFilterMsg('getPhoneNumber');
let self = this;
......
......@@ -46,6 +46,7 @@
<u-mask :show="messageFlag"></u-mask>
<!-- <view class="mask" v-if="messageFlag"></view> -->
<!-- 底部 -->
<PopBindPhone :visible.sync="showBind" @confirm="handleClickConfirm" />
</view>
</template>
......@@ -54,8 +55,13 @@ const log = require('@/utils/log.js');
import { mineBaseUrl } from '@/utils/config.js';
import { getList, checkCode, useCode } from '@/api/mine/cd-key.js';
import PopBindPhone from '@/components/pop-bind-phone/index.vue';
import { mapGetters } from 'vuex';
export default {
components: {
PopBindPhone
},
data() {
return {
cdKey: '',
......@@ -140,10 +146,13 @@ export default {
day: 7,
endDate: '',
uid: '',
list: []
list: [],
showBind: false
};
},
computed: {
...mapGetters(['userInfo']),
noList() {
return !this.list || this.list.length == 0;
}
......@@ -207,6 +216,25 @@ export default {
submitKey() {
log.setFilterMsg(this.uid);
if (!this.userInfo.mobile) {
if (uni.$u.platform == '4' || uni.$u.platform == '3'|| uni.$u.platform == 'alipay') {
this.$refs.uToast.show({
title: '请绑定手机号',
type: 'warning',
duration: 1500,
callback: () => {
uni.navigateTo({
url: '/pages/login/binding-phone/binding-phone?type=phone'
});
}
});
} else {
this.showBind = true
}
return
}
if (!this.cdKey) {
uni.showToast({
title: '请输入兑换码',
......@@ -347,6 +375,9 @@ export default {
animationType:'pop-in',
url: '../mine/service/service'
});
},
handleClickConfirm() {
// this.userInfo = this.$store.getters.user_info;
}
}
};
......
......@@ -93,19 +93,22 @@
</view>
<view v-if="!hidePay" class="bottom-view"><button class="buy-button" @tap="$u.throttle(handleClickBuy, 500)">立即购买</button></view>
<BottomPay :visible.sync="showPayBottom" @buy="handleClickBottom" />
<PopBindPhone :visible.sync="showBind" @bind="handleClickConfirm" />
</view>
</template>
<script>
import log from '@/utils/log.js';
import BottomPay from '@/components/bottom-pay/index.vue';
import PopBindPhone from '@/components/pop-bind-phone/index.vue';
import { mineBaseUrl } from '@/utils/config.js';
import { introOptions } from '@/utils/options/mine/pay.js';
import { getGoodsList, getOrderInfo, systemExchange } from '@/api/mine/pay.js';
import { mapGetters } from 'vuex';
export default {
components: {
BottomPay
BottomPay,
PopBindPhone
},
data() {
return {
......@@ -118,7 +121,8 @@ export default {
showPayBottom: false,
current: 0,
iap: '',
showCDKey: false
showCDKey: false,
showBind: false
};
},
computed: {
......@@ -212,6 +216,24 @@ export default {
},
handleClickBuy() {
if (!this.userInfo.mobile) {
if (uni.$u.platform == '4' || uni.$u.platform == '3'|| uni.$u.platform == 'alipay') {
this.$refs.uToast.show({
title: '请绑定手机号',
type: 'warning',
duration: 1500,
callback: () => {
uni.navigateTo({
url: '/pages/login/binding-phone/binding-phone?type=phone'
});
}
});
} else {
this.showBind = true;
}
return;
}
if (this.platform == '4') {
if (this.isIOS) {
this.getProvider();
......@@ -707,6 +729,9 @@ export default {
animationType:'pop-in',
url: '/pages/mine/cd-key/cd-key'
});
},
handleClickConfirm() {
// this.userInfo = this.$store.getters.user_info;
}
}
};
......
......@@ -6,9 +6,24 @@
<u-avatar slot="right-icon" class="avatar-iamge" :src="userInfo.avatar ? userInfo.avatar : avatar" size="120"></u-avatar>
<u-icon slot="right-icon" color="#D8D8D8" size="24" name="play-right-fill"></u-icon>
</u-cell-item>
<u-cell-item title="昵称" :value="userInfo.nickname" @click="handleClickChangeName" :border-bottom="false" :title-style="titleStyle" :value-style="valueStyle" :arrow="false">
<u-cell-item title="昵称" :value="userInfo.nickname" @click="handleClickChangeName" :title-style="titleStyle" :value-style="valueStyle" :arrow="false">
<u-icon slot="right-icon" color="#D8D8D8" size="24" name="play-right-fill"></u-icon>
</u-cell-item>
<u-cell-item title="手机号" :border-bottom="false" :title-style="titleStyle" :value-style="valueStyle" :arrow="false">
<!-- <u-icon slot="right-icon" color="#D8D8D8" size="24" name="play-right-fill"></u-icon> -->
<view slot="right-icon">
<BindPhone v-if="!userInfo.mobile" :customStyle="{padding: '0'}" @bind="handleClickConfirm">
<view slot="content" class="bind-phone-view" hover-class="u-hover-class">
<view class="bind-view">立即绑定</view>
<u-icon name="play-right-fill" color="#D8D8D8" :size="24" />
</view>
</BindPhone>
<view v-else class="bind-phone-button">
<view class="mobile-view">{{userInfo.mobile}}</view>
<u-icon name="play-right-fill" color="#D8D8D8" :size="24" />
</view>
</view>
</u-cell-item>
</u-cell-group>
</view>
<view class="push-setting-view" v-if="platform == '4'">
......@@ -34,6 +49,7 @@
</template>
<script>
import BindPhone from '@/components/bind-phone';
import upload from '@/utils/upload';
import { mineBaseUrl,UPLOAD_FILE_HOST } from '@/utils/config.js';
import { mapGetters } from 'vuex';
......@@ -41,6 +57,9 @@ import { getQiNiuToken } from '@/api/common/index.js'
import { update } from '@/api/user/index.js';
import permision from "@/js_sdk/wa-permission/permission.js"
export default {
components: {
BindPhone,
},
data() {
return {
form:{
......@@ -166,6 +185,9 @@ export default {
}
}
});
},
handleClickConfirm() {
}
}
};
......@@ -184,6 +206,28 @@ export default {
background-color: #f6f7fa;
border-radius: 50%;
}
.bind-phone-button {
background-color: transparent;
padding: 0;
display: flex;
justify-content: flex-end;
align-items: center;
border: none;
}
.bind-phone-view {
display: flex;
justify-content: flex-end;
align-items: center;
font-size: 28rpx;
height: 54rpx;
.bind-view {
margin-right: 16rpx;
color: #8d8d8d;
}
}
.push-setting-view {
background-color: #ffffff;
margin-top: 24rpx;
......
......@@ -166,8 +166,8 @@ const actions = {
break;
}
try {
let code=""
if(params&&!params.account){
let code = ''
if(!params || params&&!params.account){
code=await wxLogin()
}
let info = {
......
import {
setUserinfo,
getUserinfo,
getChannel,
setToken
} from "@/utils/common.js"
import {
userBindMobile,
} from "@/api/login/index.js";
export function bindPhone(data) {
return new Promise(function(resolve, reject) {
var channel = getChannel()
userBindMobile({
...data,
loginChannel: channel.loginChannel, // 登录渠道
authType: channel.authType, // 授权渠道
}).then((res)=> {
if (res && res.data) {
setToken(res.data.token)
resolve(res);
} else {
reject(res);
}
}).catch((err)=> {
reject(err);
})
});
}
export function wxBindPhone(e, block = ()=>{}) {
console.log('-------e--------', e);
if (e.detail.errMsg.indexOf('user deny') > -1) {
uni.showModal({
title: '提示',
showCancel: false,
content: '未授权不能完成该操作',
success: function(res) {}
});
} else {
console.log('用户同意', e.detail);
var detail = e.detail
// 低版本没有 detail.code
if (detail && (detail.code || detail.encryptedData)) {
wxLogin()
.then(result => {
console.log('绑定手机之后微信登录成功', result);
var channel = getChannel()
userBindMobile({
encryptedData: detail.encryptedData,
iv: detail.iv,
code: result.code,
mobileCode: detail.code,
authType: 'WX',
loginChannel: channel.loginChannel, // 登录渠道
}).then((res)=> {
console.log('------绑定手机接口:-------', res)
if (res.data) {
setToken(res.data.token)
block();
} else {
uni.showToast({
title: '绑定手机号失败',
icon: 'none'
});
}
}).catch((err)=> {
uni.showToast({
title: detail.errMsg || '获取手机号code失败',
icon: 'none'
});
})
})
} else {
uni.showModal({
title: '提示',
showCancel: false,
content: '获取手机信息失败',
success: function(res) {}
});
}
}
}
function wxLogin() {
return new Promise(function(resolve, reject) {
uni.login({
success: (res) => {
console.log('-----wxLogin success-----', res)
if (!res.code) {
uni.hideLoading();
uni.showModal({
content: res.errMsg,
showCancel: false
});
}
resolve(res);
},
fail(e) {
console.log('-----wxLogin fail-----', e)
uni.hideLoading();
uni.showModal({
content: '登录失败',
showCancel: false
});
reject();
}
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment