1
|
-<script>
|
|
|
2
|
- var wx = require('jweixin-module')
|
|
|
3
|
- import {authorization,getOpenid } from '@/api/send'
|
|
|
4
|
- export default {
|
|
|
5
|
- onLaunch: function(e) {
|
|
|
6
|
- const openId = uni.getStorageSync('openId')
|
|
|
7
|
- console.log(openId);
|
|
|
8
|
- if(!openId && !e.query.code){
|
|
|
9
|
- console.log(!openId , !e.query.code);
|
|
|
10
|
- console.log(1)
|
|
|
11
|
- // getApp().authorization()
|
|
|
12
|
- }else if(e.query.code) {
|
|
|
13
|
- // getApp().getOpenid(e.query.code)
|
|
|
14
|
- console.log(2)
|
|
|
15
|
- }
|
|
|
16
|
- console.log(e.query.code);
|
|
|
17
|
- console.log('App Launch')
|
|
|
18
|
- },
|
|
|
19
|
- onShow: function() {
|
|
|
20
|
- console.log('App Show')
|
|
|
21
|
- },
|
|
|
22
|
- onHide: function() {
|
|
|
23
|
- console.log('App Hide')
|
|
|
24
|
- },
|
|
|
25
|
- methods: {
|
|
|
26
|
- // 拿code
|
|
|
27
|
- async authorization(){
|
|
|
28
|
- try {
|
|
|
29
|
- const res = await authorization(window.location.href)
|
|
|
30
|
- console.log('authorization', res)
|
|
|
31
|
- window.location.href = res.url
|
|
|
32
|
- // 保存数据
|
|
|
33
|
- } catch (err) {
|
|
|
34
|
- uni.showToast({ title:err,icon:'none' })
|
|
|
35
|
- console.log('authorization', err)
|
|
|
36
|
- }
|
|
|
37
|
- },
|
|
|
38
|
- // 获取openid
|
|
|
39
|
- async getOpenid(code){
|
|
|
40
|
- try {
|
|
|
41
|
- const res = await getOpenid(code)
|
|
|
42
|
- console.log('getOpenid', res)
|
|
|
43
|
- uni.setStorageSync('openId',res.openid)
|
|
|
44
|
- // 保存数据
|
|
|
45
|
- } catch (err) {
|
|
|
46
|
- setTimeout(()=>{
|
|
|
47
|
- uni.showToast({ title:err,icon:'none' })
|
|
|
48
|
- },300)
|
|
|
49
|
- uni.redirectTo({
|
|
|
50
|
- url:'/pages/index/index'
|
|
|
51
|
- })
|
|
|
52
|
- console.log('getOpenid', err)
|
|
|
53
|
- }
|
|
|
54
|
- },
|
|
|
55
|
- },
|
|
|
56
|
- }
|
|
|
57
|
-</script>
|
|
|
58
|
-
|
1
|
+<script>
|
|
|
2
|
+ var wx = require('jweixin-module')
|
|
|
3
|
+ import {authorization,getOpenid } from '@/api/send'
|
|
|
4
|
+ export default {
|
|
|
5
|
+ // http://localhost:8080/
|
|
|
6
|
+ onLaunch: function(e) {
|
|
|
7
|
+ const openId = uni.getStorageSync('openId')
|
|
|
8
|
+ console.log(openId);
|
|
|
9
|
+ if(!openId && !e.query.code){
|
|
|
10
|
+ getApp().authorization()
|
|
|
11
|
+ }else if(e.query.code) {
|
|
|
12
|
+ console.log(2);
|
|
|
13
|
+ getApp().getOpenid(e.query.code)
|
|
|
14
|
+ }
|
|
|
15
|
+ // else {
|
|
|
16
|
+ // uni.showModal({
|
|
|
17
|
+ // content: 'open:'+openId + 'code:'+e.query.code,
|
|
|
18
|
+ // showCancel: false
|
|
|
19
|
+ // });
|
|
|
20
|
+ // }
|
|
|
21
|
+ console.log(e.query.code);
|
|
|
22
|
+ console.log('App Launch')
|
|
|
23
|
+ },
|
|
|
24
|
+ onShow: function() {
|
|
|
25
|
+ console.log('App Show')
|
|
|
26
|
+ },
|
|
|
27
|
+ onHide: function() {
|
|
|
28
|
+ console.log('App Hide')
|
|
|
29
|
+ },
|
|
|
30
|
+ methods: {
|
|
|
31
|
+ // 拿code
|
|
|
32
|
+ async authorization(){
|
|
|
33
|
+ try {
|
|
|
34
|
+ const res = await authorization(window.location.href)
|
|
|
35
|
+ console.log('authorization', res)
|
|
|
36
|
+ window.location.href = res.url
|
|
|
37
|
+ // 保存数据
|
|
|
38
|
+ } catch (err) {
|
|
|
39
|
+ uni.showToast({ title:err,icon:'none' })
|
|
|
40
|
+ console.log('authorization', err)
|
|
|
41
|
+ }
|
|
|
42
|
+ },
|
|
|
43
|
+ // 获取openid
|
|
|
44
|
+ async getOpenid(code){
|
|
|
45
|
+ try {
|
|
|
46
|
+ const res = await getOpenid(code)
|
|
|
47
|
+ console.log('getOpenid', res)
|
|
|
48
|
+ uni.setStorageSync('openId',res.openid)
|
|
|
49
|
+ // 保存数据
|
|
|
50
|
+ } catch (err) {
|
|
|
51
|
+ setTimeout(()=>{
|
|
|
52
|
+ uni.showToast({ title:err,icon:'none' })
|
|
|
53
|
+ },300)
|
|
|
54
|
+ uni.redirectTo({
|
|
|
55
|
+ url:'/pages/index/index'
|
|
|
56
|
+ })
|
|
|
57
|
+ console.log('getOpenid', err)
|
|
|
58
|
+ }
|
|
|
59
|
+ },
|
|
|
60
|
+ },
|
|
|
61
|
+ }
|
|
|
62
|
+</script>
|
|
|
63
|
+
|
59
|
<style lang="scss">
|
64
|
<style lang="scss">
|
60
|
- /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
|
|
|
61
|
- @import "uview-ui/index.scss";
|
|
|
62
|
- uni-page-head {
|
|
|
63
|
- display:none !important;
|
|
|
64
|
- }
|
|
|
65
|
- /*每个页面公共css */
|
|
|
66
|
- .wh100 {
|
|
|
67
|
- width: 100%;
|
|
|
68
|
- height: 100%;
|
|
|
69
|
- }
|
|
|
70
|
-
|
|
|
71
|
- .flexC {
|
|
|
72
|
- display: flex;
|
|
|
73
|
- justify-content: center;
|
|
|
74
|
- align-items: center;
|
|
|
75
|
- }
|
|
|
76
|
- .flexD {
|
|
|
77
|
- display: flex;
|
|
|
78
|
- justify-content: space-between;
|
|
|
79
|
- align-items: center;
|
|
|
80
|
- }
|
|
|
81
|
-
|
|
|
82
|
- .flex {
|
|
|
83
|
- display: flex;
|
|
|
84
|
- }
|
|
|
85
|
-
|
|
|
86
|
- .flexA {
|
|
|
87
|
- display: flex;
|
|
|
88
|
- align-items: center;
|
|
|
89
|
- }
|
|
|
90
|
-
|
|
|
91
|
- .fw700 {
|
|
|
92
|
- font-weight: 700;
|
|
|
93
|
- }
|
|
|
94
|
-
|
|
|
95
|
- .flexwrap {
|
|
|
96
|
- display: flex;
|
|
|
97
|
- flex-wrap: wrap;
|
|
|
98
|
- align-items: center;
|
|
|
99
|
- }
|
|
|
100
|
-
|
|
|
101
|
- .flexcolum {
|
|
|
102
|
- display: flex;
|
|
|
103
|
- flex-direction: column;
|
|
|
104
|
- justify-content: center;
|
|
|
105
|
- align-items: center;
|
|
|
106
|
- }
|
|
|
107
|
-
|
|
|
108
|
- .serviceBtn {
|
|
|
109
|
- opacity: 0;
|
|
|
110
|
- position: absolute;
|
|
|
111
|
- left: 0;
|
|
|
112
|
- bottom: 0;
|
|
|
113
|
- width: 120rpx;
|
|
|
114
|
- height: 120rpx;
|
|
|
115
|
- }
|
|
|
116
|
-</style>
|
|
|
117
|
-<style>
|
|
|
118
|
-
|
|
|
119
|
- /*每个页面公共css */
|
65
|
+ /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
|
|
|
66
|
+ @import "uview-ui/index.scss";
|
|
|
67
|
+ uni-page-head {
|
|
|
68
|
+ display:none !important;
|
|
|
69
|
+ }
|
|
|
70
|
+ /*每个页面公共css */
|
|
|
71
|
+ .wh100 {
|
|
|
72
|
+ width: 100%;
|
|
|
73
|
+ height: 100%;
|
|
|
74
|
+ }
|
|
|
75
|
+
|
|
|
76
|
+ .flexC {
|
|
|
77
|
+ display: flex;
|
|
|
78
|
+ justify-content: center;
|
|
|
79
|
+ align-items: center;
|
|
|
80
|
+ }
|
|
|
81
|
+ .flexD {
|
|
|
82
|
+ display: flex;
|
|
|
83
|
+ justify-content: space-between;
|
|
|
84
|
+ align-items: center;
|
|
|
85
|
+ }
|
|
|
86
|
+
|
|
|
87
|
+ .flex {
|
|
|
88
|
+ display: flex;
|
|
|
89
|
+ }
|
|
|
90
|
+
|
|
|
91
|
+ .flexA {
|
|
|
92
|
+ display: flex;
|
|
|
93
|
+ align-items: center;
|
|
|
94
|
+ }
|
|
|
95
|
+
|
|
|
96
|
+ .fw700 {
|
|
|
97
|
+ font-weight: 700;
|
|
|
98
|
+ }
|
|
|
99
|
+
|
|
|
100
|
+ .flexwrap {
|
|
|
101
|
+ display: flex;
|
|
|
102
|
+ flex-wrap: wrap;
|
|
|
103
|
+ align-items: center;
|
|
|
104
|
+ }
|
|
|
105
|
+
|
|
|
106
|
+ .flexcolum {
|
|
|
107
|
+ display: flex;
|
|
|
108
|
+ flex-direction: column;
|
|
|
109
|
+ justify-content: center;
|
|
|
110
|
+ align-items: center;
|
|
|
111
|
+ }
|
|
|
112
|
+
|
|
|
113
|
+ .serviceBtn {
|
|
|
114
|
+ opacity: 0;
|
|
|
115
|
+ position: absolute;
|
|
|
116
|
+ left: 0;
|
|
|
117
|
+ bottom: 0;
|
|
|
118
|
+ width: 120rpx;
|
|
|
119
|
+ height: 120rpx;
|
|
|
120
|
+ }
|
120
|
</style>
|
121
|
</style>
|
|
|
122
|
+<style>
|
|
|
123
|
+
|
|
|
124
|
+ /*每个页面公共css */
|
|
|
125
|
+</style> |