|
@@ -42,33 +42,29 @@ export default defineComponent({
|
|
|
if (!browser().weixin) {
|
|
|
this.showPopup = true
|
|
|
}
|
|
|
- // if (browser().weixin) {
|
|
|
- // 微信公众号支付
|
|
|
- //授权
|
|
|
- // const code = getUrlCode()
|
|
|
- // console.log('login mounted code: ' + code)
|
|
|
- // if (!code) {
|
|
|
- // this.getAppIdAndCode()
|
|
|
- // } else {
|
|
|
- // this.code = code
|
|
|
- // }
|
|
|
- // this.getAppIdAndCode()
|
|
|
- // } else {
|
|
|
- // this.showPopup = true
|
|
|
- // }
|
|
|
},
|
|
|
methods: {
|
|
|
- // async getAppIdAndCode() {
|
|
|
- // try {
|
|
|
- // const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
|
|
|
- // // 判断是否有微信appId
|
|
|
- // if (data) {
|
|
|
- // this.wxAppId = data
|
|
|
- // }
|
|
|
- // } catch {
|
|
|
- // //
|
|
|
- // }
|
|
|
- // },
|
|
|
+ async getAppIdAndCode(url?: string) {
|
|
|
+ try {
|
|
|
+ const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
|
|
|
+ // 判断是否有微信appId
|
|
|
+ if (data) {
|
|
|
+ this.goAuth(data, url)
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ },
|
|
|
+ goAuth(wxAppId: string, urlString?: string) {
|
|
|
+ // 用户授权
|
|
|
+ console.log(urlString || window.location.href, 'urlString || window.location.href')
|
|
|
+ const urlNow = encodeURIComponent(urlString || window.location.href)
|
|
|
+ console.log(urlNow, 'urlNow')
|
|
|
+ const scope = 'snsapi_base' //snsapi_userinfo //静默授权 用户无感知
|
|
|
+ const appid = wxAppId || 'wx8654c671631cfade'
|
|
|
+ const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
|
|
|
+ window.location.replace(url)
|
|
|
+ },
|
|
|
directNext() {
|
|
|
if (state.user.status === 'login' || state.user.status === 'error') {
|
|
|
const { returnUrl, isRegister, ...rest } = this.$route.query
|
|
@@ -80,15 +76,6 @@ export default defineComponent({
|
|
|
'jump pre registration'
|
|
|
)
|
|
|
|
|
|
- // this.goAuth(data)
|
|
|
- // console.log(returnUrl, isRegister, { ...rest })
|
|
|
- // this.$router.replace({
|
|
|
- // path: returnUrl as any,
|
|
|
- // query: {
|
|
|
- // ...rest,
|
|
|
- // code: this.code
|
|
|
- // }
|
|
|
- // })
|
|
|
const newUrl =
|
|
|
window.location.origin +
|
|
|
window.location.pathname +
|
|
@@ -97,9 +84,10 @@ export default defineComponent({
|
|
|
'?' +
|
|
|
qs.stringify({
|
|
|
...rest
|
|
|
- // wxAppId: this.wxAppId
|
|
|
})
|
|
|
- this.locationReplace(newUrl)
|
|
|
+ // 直接跳转到授权页面
|
|
|
+ this.getAppIdAndCode(newUrl)
|
|
|
+ // this.locationReplace(newUrl)
|
|
|
}
|
|
|
},
|
|
|
locationReplace(url: any) {
|