ServiceKQ.vue
4.09 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
131
132
133
134
135
136
<template>
<service-basekq :centerNo="centerNo" v-if="centerNo"></service-basekq>
</template>
<script>
import ServiceBasekq from './ServiceBaseKQ.vue'
export default {
name: 'ServiceKQ',
data () {
return {
centerNo: '',
}
},
mounted () {
console.log('xst mounted')
this.checkAuth()
},
activated () {
console.log('KQ activated')
this.checkAuth()
},
methods: {
checkAuth () {
let centerNo = localStorage.getItem('centerNo');
let ticket = this.common.getUrlParam('ticket');
if (centerNo) {
this.centerNo = centerNo
localStorage.setItem('centerNo', centerNo);
this.getUserInfo()
} else if (ticket) {
this.getCenterByTicket(ticket)
} else {
const sUserAgent = window.navigator.userAgent.toLowerCase()
const dtdreamweb = sUserAgent.indexOf("dtdreamweb") > -1
const miniprogram = sUserAgent.indexOf("miniprogram") > -1 && sUserAgent.indexOf("alipay") > -1
if (dtdreamweb) {
// alert('浙里办')
window.location.href = `https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=hswsy`;
}
else if (miniprogram) {
// alert('支付宝')
window.location.href = `https://puser.zjzwfw.gov.cn/sso/alipay.do?action=ssoLogin&servicecode=hswsy`;
}
else {
alert('非浙里办渠道访问,显示测试用户数据')
console.log('非浙里办渠道访问,显示测试用户数据')
this.centerNo = '20210930160466993660'
localStorage.setItem('centerNo', '20210930160466993660');
this.getUserInfo()
}
}
},
// 通过ticket获取centerNo
getCenterByTicket (ticket) {
this.mgop({
api: 'mgop.sz.hswsy.getCenterNo', // 必须
host: 'https://mapi.zjzwfw.gov.cn/',
dataType: 'JSON',
type: 'POST',
appKey: 'fuxgnukl+2001895516+edccpx', // 必须
headers: {
// 'isTestUrl': '1'
},
data: {
"ticket": ticket,
},
onSuccess: res => {
console.log('通过ticket获取centerNo成功', res)
if (res.data.code == 200) {
this.centerNo = res.data.message
localStorage.setItem('centerNo', res.data.message);
} else {
this.reLoad()
}
},
onFail: err => {
console.log('通过ticket获取centerNo成功失败', err)
this.reLoad()
}
})
},
reLoad () {
console.log('reload')
ZWJSBridge.confirm({
"title": "警告",
"buttonLabels": [
"重新载入"
],
"message": "用户身份验证失败,请重新加载"
}).then(res => {
const sUserAgent = window.navigator.userAgent.toLowerCase()
const dtdreamweb = sUserAgent.indexOf("dtdreamweb") > -1
const miniprogram = sUserAgent.indexOf("miniprogram") > -1 && sUserAgent.indexOf("alipay") > -1
if (dtdreamweb) {
// alert('浙里办')
window.location.href = `https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=hswsy`;
}
else if (miniprogram) {
// alert('支付宝')
window.location.href = `https://puser.zjzwfw.gov.cn/sso/alipay.do?action=ssoLogin&servicecode=hswsy`;
}
})
},
// 获取用户信息
getUserInfo: function () {
this.mgop({
api: 'mgop.sz.hswsy.getPortalUserByNum', // 必须
// host: 'https://mapi.zjzwfw.gov.cn/',
// dataType: 'JSON',
// type: 'GET',
appKey: 'fuxgnukl+2001895516+edccpx', // 必须
headers: {
// 'isTestUrl': '1'
},
data: {
"userNum": this.centerNo
},
onSuccess: res => {
console.log('getUserInfo', res)
if (res.data.code == 200) {
localStorage.setItem('userInfo', JSON.stringify(res.data.data.userInfo))
}
},
onFail: err => {
console.log('err', err)
}
});
},
},
components: {
ServiceBasekq
}
}
</script>