优化微信授权
This commit is contained in:
@ -7,7 +7,8 @@
|
||||
<open-data class="user-avatar" type="userAvatarUrl"></open-data>
|
||||
<open-data class="user-name" type="userNickName"></open-data>
|
||||
<view class="login-notice">为了提供更优质的服务,需要获取您的头像昵称</view>
|
||||
<button class="cu-btn author-btn" @getuserinfo="getUserInfo" open-type="getUserInfo">授权并查看</button>
|
||||
<button class="cu-btn author-btn" v-if="canIUseGetUserProfile" @tap="getUserInfoProfile">授权并查看</button>
|
||||
<button class="cu-btn author-btn" v-else @getuserinfo="getUserInfo" open-type="getUserInfo">授权并查看</button>
|
||||
<button class="cu-btn close-btn" @tap="back">暂不授权</button>
|
||||
</view>
|
||||
</view>
|
||||
@ -25,100 +26,135 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
mapState,
|
||||
mapMutations,
|
||||
mapActions
|
||||
} from "vuex";
|
||||
import {
|
||||
wxappAuth,
|
||||
getUser
|
||||
} from "@/api/user";
|
||||
import dayjs from "dayjs";
|
||||
import cookie from "@/utils/store/cookie";
|
||||
import {
|
||||
login,
|
||||
authorize
|
||||
} from "@/utils";
|
||||
import { mapState, mapMutations, mapActions } from 'vuex'
|
||||
import { wxappAuth, getUser } from '@/api/user'
|
||||
import dayjs from 'dayjs'
|
||||
import cookie from '@/utils/store/cookie'
|
||||
import { login, authorize } from '@/utils'
|
||||
|
||||
export default {
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
authorize: false,
|
||||
};
|
||||
canIUseGetUserProfile: false,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState(["isAuthorization", "$deviceType", "token"]),
|
||||
...mapState(['isAuthorization', '$deviceType', 'token']),
|
||||
},
|
||||
onShow() {
|
||||
onLoad() {
|
||||
console.log(wx.getUserProfile)
|
||||
if (wx.getUserProfile) {
|
||||
console.log(this)
|
||||
this.canIUseGetUserProfile = true
|
||||
console.log(this.canIUseGetUserProfile)
|
||||
}
|
||||
// // 先校验用户是否授权,如果没有授权,显示授权按钮
|
||||
},
|
||||
onHide() {
|
||||
this.updateAuthorizationPage(false);
|
||||
this.changeAuthorization(false);
|
||||
this.updateAuthorizationPage(false)
|
||||
this.changeAuthorization(false)
|
||||
},
|
||||
onUnload() {
|
||||
this.updateAuthorizationPage(false);
|
||||
this.changeAuthorization(false);
|
||||
this.updateAuthorizationPage(false)
|
||||
this.changeAuthorization(false)
|
||||
},
|
||||
methods: {
|
||||
...mapActions(["changeAuthorization", "setUserInfo"]),
|
||||
...mapMutations(["updateAuthorizationPage"]),
|
||||
...mapActions(['changeAuthorization', 'setUserInfo']),
|
||||
...mapMutations(['updateAuthorizationPage']),
|
||||
toLogin() {
|
||||
this.$yrouter.push({
|
||||
path: "/pages/user/Login/index",
|
||||
path: '/pages/user/Login/index',
|
||||
query: {},
|
||||
});
|
||||
})
|
||||
},
|
||||
back() {
|
||||
this.$yrouter.switchTab({
|
||||
path: "/pages/home/index",
|
||||
path: '/pages/home/index',
|
||||
query: {},
|
||||
});
|
||||
})
|
||||
},
|
||||
getUserInfo(data) {
|
||||
if (data.detail.errMsg == "getUserInfo:fail auth deny") {
|
||||
console.log(data)
|
||||
console.log('getUserInfo')
|
||||
if (data.detail.errMsg == 'getUserInfo:fail auth deny') {
|
||||
uni.showToast({
|
||||
title: "取消授权",
|
||||
icon: "none",
|
||||
title: '取消授权',
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
});
|
||||
return;
|
||||
})
|
||||
return
|
||||
}
|
||||
uni.showLoading({
|
||||
title: "登录中",
|
||||
});
|
||||
title: '登录中',
|
||||
})
|
||||
login()
|
||||
.then((res) => {
|
||||
.then(e => {
|
||||
uni.hideLoading()
|
||||
console.log('重定向')
|
||||
this.$yrouter.reLaunch({
|
||||
path: cookie.get("redirect").replace(/\ /g, '')
|
||||
});
|
||||
path: cookie.get('redirect').replace(/\ /g, ''),
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
})
|
||||
.catch(error => {
|
||||
uni.hideLoading()
|
||||
console.log(error)
|
||||
uni.showToast({
|
||||
title: error,
|
||||
icon: "none",
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
},
|
||||
getUserInfoProfile(data) {
|
||||
console.log('getUserInfoProfile')
|
||||
wx.getUserProfile({
|
||||
lang: 'zh_CN',
|
||||
desc: '需要获取您的信息用来展示',
|
||||
success: res => {
|
||||
console.log(res)
|
||||
uni.showLoading({
|
||||
title: '登录中',
|
||||
})
|
||||
login(res)
|
||||
.then(e => {
|
||||
console.log('重定向')
|
||||
this.$yrouter.reLaunch({
|
||||
path: cookie.get('redirect').replace(/\ /g, ''),
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error)
|
||||
uni.showToast({
|
||||
title: error,
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
},
|
||||
mounted() {},
|
||||
};
|
||||
mounted() {
|
||||
if (wx.getUserProfile) {
|
||||
console.log(this)
|
||||
this.canIUseGetUserProfile = true
|
||||
console.log(this.canIUseGetUserProfile)
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.container {
|
||||
.container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
position: relative;
|
||||
}
|
||||
}
|
||||
|
||||
.force-login-wrap {
|
||||
.force-login-wrap {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
@ -189,5 +225,5 @@
|
||||
color: #eb3729;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<view class="user">
|
||||
<view v-if="$store.getters.token||userInfo.uid">
|
||||
<view v-if="$store.getters.token || userInfo.uid">
|
||||
<view class="header bg-color-red acea-row row-between-wrapper">
|
||||
<view class="picTxt acea-row row-between-wrapper">
|
||||
<view class="pictrue">
|
||||
@ -15,7 +15,7 @@
|
||||
</view>
|
||||
</view>
|
||||
<view @click="goPersonalData()" class="id" v-if="userInfo.phone">
|
||||
<text>ID:{{ userInfo.uid || 0}}</text>
|
||||
<text>ID:{{ userInfo.uid || 0 }}</text>
|
||||
<text class="iconfont icon-bianji1"></text>
|
||||
</view>
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
@ -64,40 +64,35 @@
|
||||
<view @click="goMyOrder(0)" class="item">
|
||||
<view class="pictrue">
|
||||
<image src="@/static/images/dfk.png" />
|
||||
<text class="order-status-num"
|
||||
v-if="userInfo.orderStatusNum.unpaidCount > 0">{{ userInfo.orderStatusNum.unpaidCount }}</text>
|
||||
<text class="order-status-num" v-if="userInfo.orderStatusNum.unpaidCount > 0">{{ userInfo.orderStatusNum.unpaidCount }}</text>
|
||||
</view>
|
||||
<view>待付款</view>
|
||||
</view>
|
||||
<view @click="goMyOrder(1)" class="item">
|
||||
<view class="pictrue">
|
||||
<image src="@/static/images/dfh.png" />
|
||||
<text class="order-status-num"
|
||||
v-if="userInfo.orderStatusNum.unshippedCount > 0">{{ userInfo.orderStatusNum.unshippedCount }}</text>
|
||||
<text class="order-status-num" v-if="userInfo.orderStatusNum.unshippedCount > 0">{{ userInfo.orderStatusNum.unshippedCount }}</text>
|
||||
</view>
|
||||
<view>待发货</view>
|
||||
</view>
|
||||
<view @click="goMyOrder(2)" class="item">
|
||||
<view class="pictrue">
|
||||
<image src="@/static/images/dsh.png" />
|
||||
<text class="order-status-num"
|
||||
v-if="userInfo.orderStatusNum.receivedCount > 0">{{ userInfo.orderStatusNum.receivedCount }}</text>
|
||||
<text class="order-status-num" v-if="userInfo.orderStatusNum.receivedCount > 0">{{ userInfo.orderStatusNum.receivedCount }}</text>
|
||||
</view>
|
||||
<text>待收货</text>
|
||||
</view>
|
||||
<view @click="goMyOrder(3)" class="item">
|
||||
<view class="pictrue">
|
||||
<image src="@/static/images/dpj.png" />
|
||||
<text class="order-status-num"
|
||||
v-if="userInfo.orderStatusNum.evaluatedCount > 0">{{ userInfo.orderStatusNum.evaluatedCount }}</text>
|
||||
<text class="order-status-num" v-if="userInfo.orderStatusNum.evaluatedCount > 0">{{ userInfo.orderStatusNum.evaluatedCount }}</text>
|
||||
</view>
|
||||
<text>待评价</text>
|
||||
</view>
|
||||
<view @click="goReturnList()" class="item">
|
||||
<view class="pictrue">
|
||||
<image src="@/static/images/sh.png" />
|
||||
<text class="order-status-num"
|
||||
v-if="userInfo.orderStatusNum.refundCount > 0">{{ userInfo.orderStatusNum.refundCount }}</text>
|
||||
<text class="order-status-num" v-if="userInfo.orderStatusNum.refundCount > 0">{{ userInfo.orderStatusNum.refundCount }}</text>
|
||||
</view>
|
||||
<text>售后/退款</text>
|
||||
</view>
|
||||
@ -132,110 +127,97 @@
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
import {
|
||||
mapState,
|
||||
mapGetters,
|
||||
mapMutations,
|
||||
mapActions
|
||||
} from "vuex";
|
||||
import {
|
||||
getUserInfo,
|
||||
getMenuUser,
|
||||
bindingPhone
|
||||
} from "@/api/user";
|
||||
import {
|
||||
isWeixin,
|
||||
VUE_APP_RESOURCES_URL
|
||||
} from "@/utils";
|
||||
import cookie from "@/utils/store/cookie";
|
||||
import SwitchWindow from "@/components/SwitchWindow";
|
||||
import Authorization from "@/pages/authorization/index";
|
||||
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
|
||||
import { getUserInfo, getMenuUser, bindingPhone } from '@/api/user'
|
||||
import { isWeixin, VUE_APP_RESOURCES_URL } from '@/utils'
|
||||
import cookie from '@/utils/store/cookie'
|
||||
import SwitchWindow from '@/components/SwitchWindow'
|
||||
import Authorization from '@/pages/authorization/index'
|
||||
|
||||
const NAME = "User";
|
||||
const NAME = 'User'
|
||||
|
||||
export default {
|
||||
export default {
|
||||
name: NAME,
|
||||
components: {
|
||||
SwitchWindow,
|
||||
Authorization
|
||||
Authorization,
|
||||
},
|
||||
props: {},
|
||||
data: function () {
|
||||
data: function() {
|
||||
return {
|
||||
MyMenus: [],
|
||||
switchActive: false,
|
||||
isWeixin: false
|
||||
};
|
||||
isWeixin: false,
|
||||
}
|
||||
},
|
||||
computed: mapGetters(["userInfo"]),
|
||||
computed: mapGetters(['userInfo']),
|
||||
methods: {
|
||||
...mapMutations(["updateAuthorizationPage"]),
|
||||
...mapMutations(['updateAuthorizationPage']),
|
||||
goReturnList() {
|
||||
this.$yrouter.push("/pages/order/ReturnList/index");
|
||||
this.$yrouter.push('/pages/order/ReturnList/index')
|
||||
},
|
||||
goMyOrder(type) {
|
||||
this.$yrouter.push({
|
||||
path: "/pages/order/MyOrder/index",
|
||||
path: '/pages/order/MyOrder/index',
|
||||
query: {
|
||||
type
|
||||
}
|
||||
});
|
||||
type,
|
||||
},
|
||||
})
|
||||
},
|
||||
goBindPhone() {
|
||||
this.$yrouter.push({
|
||||
path: "/pages/user/BindingPhone/index",
|
||||
});
|
||||
path: '/pages/user/BindingPhone/index',
|
||||
})
|
||||
},
|
||||
goUserCoupon() {
|
||||
this.$yrouter.push("/pages/user/coupon/UserCoupon/index");
|
||||
this.$yrouter.push('/pages/user/coupon/UserCoupon/index')
|
||||
},
|
||||
goIntegral() {
|
||||
this.$yrouter.push("/pages/user/signIn/Integral/index");
|
||||
this.$yrouter.push('/pages/user/signIn/Integral/index')
|
||||
},
|
||||
goUserPromotion() {
|
||||
this.$yrouter.push("/pages/user/promotion/UserPromotion/index");
|
||||
this.$yrouter.push('/pages/user/promotion/UserPromotion/index')
|
||||
},
|
||||
goUserAccount() {
|
||||
this.$yrouter.push({
|
||||
path: "/pages/user/UserAccount/index"
|
||||
});
|
||||
path: '/pages/user/UserAccount/index',
|
||||
})
|
||||
},
|
||||
goPersonalData() {
|
||||
this.$yrouter.push("/pages/user/PersonalData/index");
|
||||
this.$yrouter.push('/pages/user/PersonalData/index')
|
||||
},
|
||||
getPhoneNumber: function (e) {
|
||||
let thit = this;
|
||||
getPhoneNumber: function(e) {
|
||||
let thit = this
|
||||
console.log(e)
|
||||
// 判断一下这里是不是小程序 如果是小程序,走获取微信手机号进行绑定
|
||||
if (e.mp.detail.errMsg == "getPhoneNumber:ok") {
|
||||
if (e.mp.detail.errMsg == 'getPhoneNumber:ok') {
|
||||
uni.showLoading({
|
||||
title: "绑定中"
|
||||
});
|
||||
bindingPhone({
|
||||
title: '绑定中',
|
||||
})
|
||||
wxappBindingPhone({
|
||||
encryptedData: e.mp.detail.encryptedData,
|
||||
iv: e.mp.detail.iv
|
||||
iv: e.mp.detail.iv,
|
||||
})
|
||||
.then(res => {
|
||||
// this.User();
|
||||
thit.$store.dispatch("userInfo", true);
|
||||
uni.hideLoading();
|
||||
thit.$store.dispatch('userInfo', true)
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: "success",
|
||||
duration: 2000
|
||||
});
|
||||
icon: 'success',
|
||||
duration: 2000,
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
uni.hideLoading();
|
||||
thit.$store.dispatch("userInfo", true);
|
||||
console.log(error);
|
||||
uni.hideLoading()
|
||||
thit.$store.dispatch('userInfo', true)
|
||||
console.log(error)
|
||||
uni.showToast({
|
||||
title: error.msg ||
|
||||
error.response.data.msg ||
|
||||
error.response.data.message,
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
});
|
||||
title: error.msg || error.response.data.msg || error.response.data.message,
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
})
|
||||
})
|
||||
// // 获取当前环境的服务商
|
||||
// uni.getProvider({
|
||||
// service: "oauth",
|
||||
@ -284,109 +266,102 @@
|
||||
// });
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: "已拒绝授权",
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
title: '已拒绝授权',
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
})
|
||||
}
|
||||
},
|
||||
changeswitch: function (data) {
|
||||
this.switchActive = data;
|
||||
changeswitch: function(data) {
|
||||
this.switchActive = data
|
||||
},
|
||||
MenuUser: function () {
|
||||
let that = this;
|
||||
MenuUser: function() {
|
||||
let that = this
|
||||
getMenuUser()
|
||||
.then(res => {
|
||||
uni.hideLoading();
|
||||
that.MyMenus = res.data.routine_my_menus;
|
||||
uni.hideLoading()
|
||||
that.MyMenus = res.data.routine_my_menus
|
||||
})
|
||||
.catch(error => {
|
||||
uni.hideLoading();
|
||||
console.log(error);
|
||||
});
|
||||
uni.hideLoading()
|
||||
console.log(error)
|
||||
})
|
||||
},
|
||||
goPages: function (index) {
|
||||
let url = this.MyMenus[index].uniapp_url;
|
||||
if (
|
||||
url === "/pages/user/promotion/UserPromotion/index" &&
|
||||
this.userInfo.statu === 1
|
||||
) {
|
||||
goPages: function(index) {
|
||||
let url = this.MyMenus[index].uniapp_url
|
||||
if (url === '/pages/user/promotion/UserPromotion/index' && this.userInfo.statu === 1) {
|
||||
if (!this.userInfo.isPromoter) {
|
||||
uni.showToast({
|
||||
title: "您还没有推广权限!!",
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
return;
|
||||
title: '您还没有推广权限!!',
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
url === "/pages/orderAdmin/OrderIndex/index" &&
|
||||
!this.userInfo.adminid
|
||||
) {
|
||||
if (url === '/pages/orderAdmin/OrderIndex/index' && !this.userInfo.adminid) {
|
||||
uni.showToast({
|
||||
title: "您还不是管理员!!",
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
return;
|
||||
title: '您还不是管理员!!',
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
})
|
||||
return
|
||||
}
|
||||
console.log(this.userInfo)
|
||||
if (url === "/pages/orderAdmin/OrderCancellation/index" && !this.userInfo.checkStatus) {
|
||||
if (url === '/pages/orderAdmin/OrderCancellation/index' && !this.userInfo.checkStatus) {
|
||||
uni.showToast({
|
||||
title: "您没有核销权限,请后台店员设置!!",
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
return;
|
||||
title: '您没有核销权限,请后台店员设置!!',
|
||||
icon: 'none',
|
||||
duration: 2000,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.$yrouter.push({
|
||||
path: this.MyMenus[index].uniapp_url
|
||||
});
|
||||
path: this.MyMenus[index].uniapp_url,
|
||||
})
|
||||
},
|
||||
goPages2: function () {
|
||||
goPages2: function() {
|
||||
this.$yrouter.push({
|
||||
path: "/pages/shop/GoodsList/index",
|
||||
path: '/pages/shop/GoodsList/index',
|
||||
query: {
|
||||
// id: 0,
|
||||
title: '积分商城',
|
||||
isIntegral: true,
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
userInfo() {
|
||||
this.MenuUser();
|
||||
}
|
||||
this.MenuUser()
|
||||
},
|
||||
},
|
||||
onShow() {
|
||||
if (this.$store.getters.token) {
|
||||
//
|
||||
uni.showLoading({
|
||||
title: "加载中"
|
||||
});
|
||||
this.$store.dispatch("getUser", true);
|
||||
this.MenuUser();
|
||||
this.isWeixin = isWeixin();
|
||||
title: '加载中',
|
||||
})
|
||||
this.$store.dispatch('getUser', true)
|
||||
this.MenuUser()
|
||||
this.isWeixin = isWeixin()
|
||||
}
|
||||
},
|
||||
onHide() {
|
||||
console.log("离开用户中心");
|
||||
this.updateAuthorizationPage(false);
|
||||
}
|
||||
};
|
||||
console.log('离开用户中心')
|
||||
this.updateAuthorizationPage(false)
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.footer-line-height {
|
||||
.footer-line-height {
|
||||
height: 1 * 100rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.order-status-num {
|
||||
.order-status-num {
|
||||
min-width: 0.33 * 100rpx;
|
||||
background-color: #fff;
|
||||
color: #eb3729;
|
||||
@ -397,17 +372,17 @@
|
||||
font-size: 0.2 * 100rpx;
|
||||
padding: 0 0.08 * 100rpx;
|
||||
border: 1px solid #eb3729;
|
||||
}
|
||||
}
|
||||
|
||||
.pictrue {
|
||||
.pictrue {
|
||||
position: relative;
|
||||
}
|
||||
}
|
||||
|
||||
.switch-h5 {
|
||||
.switch-h5 {
|
||||
margin-left: 0.2 * 100rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.binding {
|
||||
.binding {
|
||||
margin-top: 0.1 * 100rpx;
|
||||
display: inline-block;
|
||||
padding: 0.05 * 100rpx 0.2 * 100rpx;
|
||||
@ -417,15 +392,15 @@
|
||||
line-height: 1.5;
|
||||
border: 1px solid #e8695e;
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
|
||||
.by {
|
||||
.by {
|
||||
text-align: center;
|
||||
padding: 30rpx 0;
|
||||
}
|
||||
}
|
||||
|
||||
.by-text {
|
||||
.by-text {
|
||||
text-align: center;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
524
utils/index.js
524
utils/index.js
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user