h5AuthPhone.js
2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// pages/h5AuthPhone/h5AuthPhone.js
import api from '../../api/api.js'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
import {
setConfigInfo
} from '~/store/index'
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
routeObj: {},
IMG_URL
},
/**
* 生命周期函数--监听页面加载
*/
onShow(options) {
// this.init()
// console.log(options);
},
onLoad(options) {
console.log(options, '-------');
this.setData({
routeObj: options
})
this.login()
},
async jumpH5(target) {
const { routeObj } = this.data
routeObj.authphone = target.phone
let str = ''
Object.keys(routeObj).forEach((item, index) => {
if (!['page', 'h5Page'].includes(item)) {
str = str + (str ? '&' : '?') + item + '=' + routeObj[item]
}
})
// 获取配置服务数据
let baseConfigData = await setConfigInfo(app.globalData)
const url = (baseConfigData.jumpBIUrl || 'https://scrm.glsx.com.cn/glsx-bi-report/#/') + routeObj.h5Page + str
console.log(url, 'url')
wx.navigateTo({
url: `/pages/webView/webView?url=${encodeURIComponent(url)}`
})
},
login() {
wx.$util.showLoading()
let _this = this
wx.login({
success({
code
}) {
if (code) {
api
.wxLogin({
code,
appId: wx.getAccountInfoSync().miniProgram.appId
})
.then(res => {
wx.$util.hideLoading()
if (res.code == '0') {
_this.setData({
loginToken: res.data
})
}
})
} else {
wx.$util.showToast('登录失败')
}
}
})
},
/**
* 获取授权手机号
*/
getPhoneNumber(e) {
let {
loginToken
} = this.data
let {
encryptedData,
iv
} = e.detail
if (!encryptedData) return
wx.$util.showLoading('加载中...')
api
.authPhone({
encryptedData,
loginToken,
iv,
noSignIn: false
})
.then(({
code,
data,
message
}) => {
wx.hideLoading()
console.log(data, 'data---')
if (code == 0) {
let {
loginUserInfoList,
sessionId,
noSignInUuid,
needSelectAccount
} = data
if (loginUserInfoList.length) {
this.jumpH5(loginUserInfoList[0])
} else {
wx.$router.reLaunch('pages.nothing')
}
} else {
wx.hideLoading()
wx.showModal({
title: '温馨提示',
content: message,
showCancel: false,
confirmText: '知道了',
confirmColor: '#2C66F7'
})
}
})
},
})