App.vue
2.3 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
<script>
var wx = require('jweixin-module')
import {authorization,getOpenid } from '@/api/send'
export default {
onLaunch: function(e) {
const openId = uni.getStorageSync('openId')
console.log(openId);
if(!openId && !e.query.code){
console.log(!openId , !e.query.code);
console.log(1)
// getApp().authorization()
}else if(e.query.code) {
// getApp().getOpenid(e.query.code)
console.log(2)
}
console.log(e.query.code);
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
},
methods: {
// 拿code
async authorization(){
try {
const res = await authorization(window.location.href)
console.log('authorization', res)
window.location.href = res.url
// 保存数据
} catch (err) {
uni.showToast({ title:err,icon:'none' })
console.log('authorization', err)
}
},
// 获取openid
async getOpenid(code){
try {
const res = await getOpenid(code)
console.log('getOpenid', res)
uni.setStorageSync('openId',res.openid)
// 保存数据
} catch (err) {
setTimeout(()=>{
uni.showToast({ title:err,icon:'none' })
},300)
uni.redirectTo({
url:'/pages/index/index'
})
console.log('getOpenid', err)
}
},
},
}
</script>
<style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
uni-page-head {
display:none !important;
}
/*每个页面公共css */
.wh100 {
width: 100%;
height: 100%;
}
.flexC {
display: flex;
justify-content: center;
align-items: center;
}
.flexD {
display: flex;
justify-content: space-between;
align-items: center;
}
.flex {
display: flex;
}
.flexA {
display: flex;
align-items: center;
}
.fw700 {
font-weight: 700;
}
.flexwrap {
display: flex;
flex-wrap: wrap;
align-items: center;
}
.flexcolum {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.serviceBtn {
opacity: 0;
position: absolute;
left: 0;
bottom: 0;
width: 120rpx;
height: 120rpx;
}
</style>
<style>
/*每个页面公共css */
</style>