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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
| const $$ = require('../../utils/util');
| const app = getApp();
|
| // 获取手机号码
| function getPhoneNumber(submitData) {
| return $$.request({
| url: 'paAccount/getUserPhone',
| type: 'post',
| service: 'cust',
| submitData
| });
| }
|
| Component({
| /**
| * 组件的属性列表
| * popup: 下拉框的数据;visible:boolean 是否显示;title: string 标题;selectData: array;列数据;可拓展对象属性
| * safeBottom: iphoneX安全距离
| */
| properties: {
| popup: {
| type: Object,
| value: {
| visible: false
| }, // default: { visible: false, title: '', selectData: [] }
| },
| safeBottom: {
| type: Boolean,
| value: true,
| },
| },
|
| /**
| * 组件的初始数据
| */
| columnsDefaultIndex: 0,
| data: {
| loginVisible: false,
| popupIndex: null,
| },
|
| pageLifetimes: {
| show: function () {
| if (!app.globalData.token) {
| console.log('测试')
| if (!app.globalData.access_token) {
| $$.showModal({
| content: '抱歉您未登录,是否前往登录?',
| success: (res) => {
| if (res.confirm) {
| // wx.redirectTo({
| // url: '../../pages/login/index',
| // });
| this.handleGetUserInfo()
| } else {
| wx.navigateBack({
| delta: 1,
| });
| }
| },
| });
|
| }
| }
| if (app.globalData.token && !this.data.loginVisible) {
| this.setData({
| loginVisible: true
| });
| }
| },
| },
|
| // 登录,获取用户信息
| async handleGetUserInfo() {
| $$.showLoading();
| wx.getUserProfile({
| desc: '完善用户信息',
| complete(res) {
| if (res.errMsg === 'getUserProfile:ok') {
| wx.login({
| async success(res2) {
| if (res2.code) {
| const accountInfo = wx.getAccountInfoSync();
| const submitData = {
| appid: accountInfo.miniProgram.appId,
| code: res2.code,
| avatar: res?.userInfo.avatarUrl,
| encryptedData: res.encryptedData,
| ivStr: res.iv,
| };
| const res3 = await loginApi(submitData);
| $$.hideLoading();
| if (res3.type) {
| wx.setStorage({
| key: 'userInfo',
| data: res3.data
| });
| app.globalData.token = res3.data.token;
| $$.showToast({
| title: '登录成功',
| icon: 'success'
| });
| await $$.sleep();
| wx.reLaunch({
| url: '../../pages/homePage/index',
| });
| }
| } else {
| $$.hideLoading();
| $$.showToast('登录失败,请稍后重试');
| }
| },
| });
| } else {
| $$.hideLoading();
| $$.showToast({
| title: '抱歉!授权失败'
| });
| }
| },
| });
| },
|
| observers: {
| 'popup.visible,popup.noPicker': function (data1, data2) {
| if ((data1, data2)) {
| this.setData({
| popupIndex: this.data.popup.activeIndex
| });
| }
| },
| },
|
| /**
| * 组件的方法列表
| */
| methods: {
| // 退出登录
| loginOut() {
| this.setData({
| loginVisible: false
| });
| },
| // 获取手机号码
| async handleGetPhoneNumber(code) {
| $$.showLoading();
| const accountInfo = wx.getAccountInfoSync();
| const res = await getPhoneNumber({
| appid: accountInfo.miniProgram.appId,
| code
| });
| $$.hideLoading();
| if (res.type) {
| $$.showToast({
| title: '获取成功'
| });
| return res.data;
| }
| },
| // 下拉框底层弹出层方法
| _handleClosePopup() {
| this.triggerEvent('onClosePopup');
| },
| _handleChangePicker(e) {
| this.triggerEvent('onChangePicker', {
| dataset: e.currentTarget.dataset,
| detail: e.detail
| });
| },
| _handleConfirmPicker(e) {
| if (this.data.popup.noPicker) {
| // 当组件不是Picker时
| let index = e.currentTarget.dataset.index;
| let value = e.currentTarget.dataset.value;
| this.triggerEvent('onConfirmPicker', {
| dataset: e.currentTarget.dataset,
| detail: {
| index,
| value
| }
| });
| return;
| }
| this.triggerEvent('onConfirmPicker', {
| dataset: e.currentTarget.dataset,
| detail: e.detail
| });
| },
| },
| });
|
|