ktianc ff56a184ca 版本升级:
1. 修复(kinit-admin):页面缓存问题修复
2. 更新(kinit-api,kinit-admin):菜单管理新增是否缓存字段
3. 更新(kinit-admin):将缓存默认存储在localStorage中
4. 更新(kinit-api):将python-jose库更换为pyjwt库
5. 优化(kinit-admin,kinit-uni):退出登录方法优化
6. 优化(kinit-admin,kinit-uni):response拦截优化
7. 新增(kinit-api,kinit-admin,kinit-uni):jwt到期时间缩短,加入刷新token功能
8. (kinit-uni)切换到 vscode 开发 uniapp 项目
2023-03-13 14:34:26 +08:00

65 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 微信存储https://developers.weixin.qq.com/miniprogram/dev/framework/ability/storage.html
// 微信登录
// 微信小程序登录流程https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html
// 登录失败的原因可能是因为没将后台IP添加到白名单
import { mapGetters } from 'vuex'
import { setUserOpenid } from '@/common/request/api/login.js'
import { toast } from '@/common/utils/common'
export const wxLoginMixins = {
computed: {
...mapGetters(['isUserOpenid'])
},
data() {
return {}
},
methods: {
onGetPhoneNumber(e) {
return new Promise((resolve, reject) => {
// 获取手机号官方文档https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
if (e.detail.errMsg === 'getPhoneNumber:fail user deny') {
// 用户拒绝授权
toast('已取消授权')
reject('已取消授权')
} else if (e.detail.errMsg === 'getPhoneNumber:fail no permission') {
// 微信公众平台未认证或未使用企业认证
toast('微信公众平台未认证或未使用企业认证')
reject('微信公众平台未认证或未使用企业认证')
} else if (e.detail.errMsg === 'getPhoneNumber:ok') {
// code换取用户手机号 每个code只能使用一次code的有效期为5min
this.$store.dispatch('auth/wxLogin', e.detail.code).then((res) => {
this.setOpenid()
this.$store.dispatch('auth/GetInfo').then((result) => {
resolve(result)
})
})
} else {
toast('授权失败')
reject('授权失败')
}
})
},
setOpenid() {
let self = this
// uniapp 官方文档https://uniapp.dcloud.io/api/plugins/login.html#login
if (self.isUserOpenid) {
return
}
uni.login({
provider: 'weixin',
success: function (loginRes) {
if (loginRes.code) {
setUserOpenid(loginRes.code).then(() => {
// console.log("更新openid成功", res)
self.$store.commit('auth/SET_IS_USER_OPENID', true)
})
} else {
console.log('登录失败获取code失败' + loginRes.errMsg)
}
}
})
}
}
}