@cloudbase/lowcode-builder 1.9.13 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/builder/config/dependencies.js +3 -3
- package/lib/builder/core/index.js +8 -3
- package/lib/builder/h5/generate.js +1 -6
- package/lib/builder/mp/util.js +10 -4
- package/lib/builder/mp/wxml.js +10 -1
- package/lib/builder.web.js +7 -7
- package/package.json +2 -2
- package/template/html/index.html.ejs +4 -4
- package/template/mp/common/info/index.json +3 -2
- package/template/mp/common/util.js +34 -16
- package/template/mp/datasources/config.js.tpl +1 -1
- package/template/mp/packages/$wd_system/pages/login/index.js +544 -279
- package/template/mp/packages/$wd_system/pages/login/index.wxml +89 -61
- package/template/mp/packages/$wd_system/pages/login/index.wxss +82 -22
- package/template/mp/packages/$wd_system/pages/login/methods/loginByOpenId.js +24 -0
- package/template/mp/packages/$wd_system/pages/login/methods/loginByUnionId.js +24 -0
|
@@ -1,293 +1,558 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
app,
|
|
3
|
+
$app
|
|
4
|
+
} from '../../../../app/weapps-api';
|
|
2
5
|
import loginByPassword from './methods/loginByPassword';
|
|
3
6
|
import loginByWXPhone from './methods/loginByWXPhone';
|
|
4
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
parseSmsError
|
|
9
|
+
} from './methods/errorHandler';
|
|
5
10
|
import loginBySms from './methods/loginBySms';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
11
|
+
import loginByOpenId from './methods/loginByOpenId';
|
|
12
|
+
import loginByUnionId from './methods/loginByUnionId';
|
|
13
|
+
import {
|
|
14
|
+
getLoginConfig
|
|
15
|
+
} from '../../../../common/util';
|
|
16
|
+
import {
|
|
17
|
+
phoneNumberPattern,
|
|
18
|
+
phoneVerifyInfoKey,
|
|
19
|
+
verifyDelay,
|
|
20
|
+
loginOnly
|
|
21
|
+
} from './methods/contants';
|
|
22
|
+
import loginSuccessCallBack from './methods/loginSuccessCallBack'
|
|
23
|
+
|
|
24
|
+
const AUTO_LOGIN_TYPE = ['openid_login', 'unionid_login']
|
|
25
|
+
const AUTO_LOGIN_METHOD = {
|
|
26
|
+
'openid_login': loginByOpenId,
|
|
27
|
+
'unionid_login': loginByUnionId
|
|
28
|
+
}
|
|
8
29
|
|
|
9
30
|
function decodePageQuery(query) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
31
|
+
return Object.keys(query).reduce((decoded, key) => {
|
|
32
|
+
decoded[key] = decodeURIComponent(query[key]);
|
|
33
|
+
return decoded;
|
|
34
|
+
}, {});
|
|
14
35
|
}
|
|
15
36
|
|
|
16
37
|
const BUTTON_CLASSNAME = 'weda-ui weda-button weui-btn weui-btn_primary wd-event-tap';
|
|
17
38
|
|
|
18
39
|
function setStorage(data) {
|
|
19
|
-
|
|
20
|
-
|
|
40
|
+
const current = wx.getStorageSync(phoneVerifyInfoKey);
|
|
41
|
+
wx.setStorageSync(phoneVerifyInfoKey, {
|
|
42
|
+
...current,
|
|
43
|
+
...data
|
|
44
|
+
});
|
|
21
45
|
}
|
|
22
46
|
|
|
23
47
|
Component({
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
48
|
+
data: {
|
|
49
|
+
params: {},
|
|
50
|
+
initing: true,
|
|
51
|
+
error: null,
|
|
52
|
+
settingData: {
|
|
53
|
+
logo: '',
|
|
54
|
+
agreement: {
|
|
55
|
+
items: [],
|
|
56
|
+
enable: false,
|
|
57
|
+
},
|
|
58
|
+
miniprogram: [],
|
|
59
|
+
},
|
|
60
|
+
pageStyle: '',
|
|
61
|
+
agreement: false,
|
|
62
|
+
wxLoginStatus: '',
|
|
63
|
+
passwordVisible: false,
|
|
64
|
+
enablePassword: false,
|
|
65
|
+
enableMpPhone: false,
|
|
66
|
+
enbaleSms: false,
|
|
67
|
+
disableLoginSubmit: false,
|
|
68
|
+
loginButtonClass: BUTTON_CLASSNAME,
|
|
69
|
+
phoneValidateMessage: '手机号为空',
|
|
70
|
+
phoneNum: '',
|
|
71
|
+
defaultPhoneNumber: '',
|
|
72
|
+
smsVerificationInfo: {
|
|
73
|
+
id: '',
|
|
74
|
+
isUser: false,
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
currentLoginType: '',
|
|
78
|
+
currentLoginList: [],
|
|
79
|
+
baseInfoShow: false,
|
|
80
|
+
avatarUrl: '',
|
|
81
|
+
avatarRealUrl: '',
|
|
82
|
+
nickName: '',
|
|
83
|
+
},
|
|
84
|
+
methods: {
|
|
85
|
+
async getPhoneCodeNumber(e) {
|
|
86
|
+
const agree = this.checkAgreement();
|
|
87
|
+
if (!agree) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (e?.detail?.errMsg?.includes('fail') || e?.detail?.errno || !e?.detail?.code) {
|
|
91
|
+
console.warn('获取手机号授权令牌失败:', !e?.detail.code ? {
|
|
92
|
+
errMsg: '可能基础库版本过低'
|
|
93
|
+
} : e.detail);
|
|
94
|
+
|
|
95
|
+
$app.showModal({
|
|
96
|
+
cancelColor: '#000000',
|
|
97
|
+
cancelText: '取消',
|
|
98
|
+
confirmColor: '#576B95',
|
|
99
|
+
confirmText: '确认',
|
|
100
|
+
showCancel: true,
|
|
101
|
+
title: '获取手机号授权令牌失败',
|
|
102
|
+
content: `获取手机号授权令牌失败: ${e.detail.errno || e.detail?.errMsg || '可能基础库版本过低'}`,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return loginByWXPhone(this, {
|
|
109
|
+
event: e
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
async onLoad(options) {
|
|
113
|
+
try {
|
|
114
|
+
const cache = wx.getStorageSync(phoneVerifyInfoKey);
|
|
115
|
+
if (cache.phoneNum) {
|
|
116
|
+
this.setData({
|
|
117
|
+
defaultPhoneNumber: cache.phoneNum,
|
|
118
|
+
phoneNum: cache.phoneNum,
|
|
119
|
+
phoneValidateMessage: ''
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const config = await getLoginConfig().catch(() => {
|
|
124
|
+
return getLoginConfig();
|
|
125
|
+
});
|
|
126
|
+
const query = decodePageQuery(options || {});
|
|
127
|
+
let settingData = {
|
|
128
|
+
logo: app.__internal__.resolveStaticResourceUrl(config.logo) ||
|
|
129
|
+
'https://sso-1303824488.cos.ap-shanghai.myqcloud.com/logo.svg',
|
|
130
|
+
agreement: {
|
|
131
|
+
items: [],
|
|
132
|
+
enable: false,
|
|
133
|
+
...config.agreement,
|
|
134
|
+
},
|
|
135
|
+
miniprogram: (config.miniprogram || []).map(v => ({
|
|
136
|
+
...v,
|
|
137
|
+
label: v.label?.replace(/^微信小程序/, '')
|
|
138
|
+
})),
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const enableSms = this._getEnableSms(settingData);
|
|
142
|
+
const smsDelay =
|
|
143
|
+
enableSms && !cache.phoneNum ? Math.max(0, Math.ceil(((cache?.smsDelay || 0) - +new Date()) / 1000)) : 0;
|
|
144
|
+
const baseInfoShow = query.baseInfoShow === 'true'
|
|
145
|
+
const currentLoginType = query.currentLoginType || settingData.miniprogram.filter(v => !AUTO_LOGIN_TYPE.includes(v.type))?.[0]?.type || settingData.miniprogram[0]?.type;
|
|
146
|
+
const currentLoginList = query.currentLoginType ? [] : settingData.miniprogram.filter(v => v.type !== currentLoginType)
|
|
147
|
+
|
|
148
|
+
const {
|
|
149
|
+
avatarUrl,
|
|
150
|
+
nickName
|
|
151
|
+
} = app.auth.currentUser
|
|
152
|
+
const avatarRealUrl = await this.getAvatarUrl(avatarUrl)
|
|
153
|
+
|
|
154
|
+
this.setData({
|
|
155
|
+
params: query,
|
|
156
|
+
settingData,
|
|
157
|
+
enablePassword: this._getEnablePassword(settingData),
|
|
158
|
+
enableMpPhone: this._getEnableMpPhone(settingData),
|
|
159
|
+
enableSms,
|
|
160
|
+
smsDelay,
|
|
161
|
+
smsVerificationInfo: cache,
|
|
162
|
+
pageStyle: `${this.data.pageStyle}; background-color: ${config.backgroundColor || '#fff'};`,
|
|
163
|
+
initing: false,
|
|
164
|
+
currentLoginType,
|
|
165
|
+
currentLoginList,
|
|
166
|
+
baseInfoShow,
|
|
167
|
+
avatarRealUrl,
|
|
168
|
+
avatarUrl,
|
|
169
|
+
nickName,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
if (smsDelay > 0) {
|
|
173
|
+
this._intervalSender(smsDelay);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (settingData.miniprogram.length === 1 && AUTO_LOGIN_TYPE.includes(currentLoginType) && !baseInfoShow) {
|
|
177
|
+
await this.dealOpenIdOrUnionIdLogin(currentLoginType);
|
|
178
|
+
}
|
|
179
|
+
} catch (e) {
|
|
180
|
+
console.error('获取登录配置失败:', e);
|
|
181
|
+
this.setData({
|
|
182
|
+
initing: false,
|
|
183
|
+
error: {
|
|
184
|
+
message: '获取登录配置失败,' + (e.message || ''),
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
togglePasswordVisible() {
|
|
190
|
+
this.setData({
|
|
191
|
+
passwordVisible: !this.data.passwordVisible,
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
loginByPassword(e) {
|
|
195
|
+
if (!this.checkAgreement()) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const values = e.detail.value;
|
|
200
|
+
|
|
201
|
+
return loginByPassword(this, {
|
|
202
|
+
phone: values?.username?.value,
|
|
203
|
+
sms: values?.password?.value,
|
|
204
|
+
});
|
|
205
|
+
},
|
|
206
|
+
loginBySms(e) {
|
|
207
|
+
if (!this.checkAgreement()) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const values = e.detail.value;
|
|
212
|
+
|
|
213
|
+
return loginBySms(this, {
|
|
214
|
+
phoneNum: values?.phoneNum,
|
|
215
|
+
verificationCode: values?.verificationCode,
|
|
216
|
+
verificationInfo: this.data.smsVerificationInfo,
|
|
217
|
+
callback: (err, data) => {
|
|
218
|
+
if (err) {
|
|
219
|
+
const {
|
|
220
|
+
usedCount = 0
|
|
221
|
+
} = wx.getStorageSync(phoneVerifyInfoKey) || {};
|
|
222
|
+
setStorage({
|
|
223
|
+
usedCount: usedCount + 1
|
|
224
|
+
});
|
|
225
|
+
} else {
|
|
226
|
+
setStorage({
|
|
227
|
+
usedCount: 0,
|
|
228
|
+
smsDelay: 0
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
showAgreement(e) {
|
|
235
|
+
const index = e.currentTarget?.dataset?.index;
|
|
236
|
+
const agreementContent = this.data.settingData.agreement.items[index]?.value;
|
|
237
|
+
this.setData({
|
|
238
|
+
agreementContent,
|
|
239
|
+
isShowAgreement: !!agreementContent,
|
|
240
|
+
});
|
|
241
|
+
},
|
|
242
|
+
checkAgreement() {
|
|
243
|
+
if (this.data.settingData?.agreement?.enable && !this.data.agreement) {
|
|
244
|
+
app.showToast({
|
|
245
|
+
title: '请阅读勾选协议',
|
|
246
|
+
icon: 'error',
|
|
247
|
+
duartion: 1500,
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
return true;
|
|
253
|
+
},
|
|
254
|
+
onAgreementChange(e) {
|
|
255
|
+
this.setData({
|
|
256
|
+
agreement: e.detail.value.length > 0,
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
onPhoneChange(e) {
|
|
260
|
+
const {
|
|
261
|
+
value
|
|
262
|
+
} = e.detail;
|
|
263
|
+
if (!phoneNumberPattern.test(value)) {
|
|
264
|
+
this.setData({
|
|
265
|
+
phoneValidateMessage: '手机号格式非法',
|
|
266
|
+
phoneNum: value
|
|
267
|
+
});
|
|
268
|
+
} else {
|
|
269
|
+
this.setData({
|
|
270
|
+
phoneValidateMessage: '',
|
|
271
|
+
phoneNum: value
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
getCaptcha(e) {
|
|
276
|
+
if (this.data.phoneValidateMessage) {
|
|
277
|
+
wx.showToast({
|
|
278
|
+
icon: 'error',
|
|
279
|
+
title: this.data.phoneValidateMessage,
|
|
280
|
+
});
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (this.data.smsDelay > 0) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
this._intervalSender(verifyDelay);
|
|
287
|
+
const target = loginOnly ? 'USER' : 'ANY';
|
|
288
|
+
const phoneNum = this.data.phoneNum;
|
|
289
|
+
app.cloud
|
|
290
|
+
.getCloudInstance()
|
|
291
|
+
.then((cloudbase) => {
|
|
292
|
+
return cloudbase.authInstance || cloudbase.auth;
|
|
293
|
+
})
|
|
294
|
+
.then((auth) => {
|
|
295
|
+
setStorage({
|
|
296
|
+
phoneNum
|
|
297
|
+
});
|
|
298
|
+
return auth.getVerification({
|
|
299
|
+
target,
|
|
300
|
+
phone_number: `+86 ${phoneNum}`,
|
|
301
|
+
});
|
|
302
|
+
})
|
|
303
|
+
.then((data) => {
|
|
304
|
+
const verifyInfo = {
|
|
305
|
+
id: data.verification_id,
|
|
306
|
+
isUser: data.is_user,
|
|
307
|
+
};
|
|
308
|
+
this.setData({
|
|
309
|
+
smsVerificationInfo: verifyInfo,
|
|
310
|
+
});
|
|
311
|
+
setStorage({
|
|
312
|
+
...verifyInfo,
|
|
313
|
+
usedCount: 0
|
|
314
|
+
});
|
|
315
|
+
wx.showToast({
|
|
316
|
+
title: '验证码已发送',
|
|
317
|
+
});
|
|
318
|
+
})
|
|
319
|
+
.catch((e) => {
|
|
320
|
+
wx.hideLoading()
|
|
321
|
+
clearInterval(this.timerInterval);
|
|
322
|
+
this.setData({
|
|
323
|
+
smsDelay: 0
|
|
324
|
+
});
|
|
325
|
+
setStorage({
|
|
326
|
+
smsDelay: 0
|
|
327
|
+
});
|
|
328
|
+
wx.showModal({
|
|
329
|
+
title: '获取验证码失败',
|
|
330
|
+
content: parseSmsError(e, target, loginOnly),
|
|
331
|
+
showCancel: false,
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
},
|
|
335
|
+
_getEnablePassword(settingData) {
|
|
336
|
+
const config = settingData || this.data.settingData;
|
|
337
|
+
return config.miniprogram?.find?.((item) => item.type === 'password')?.enable ?? false;
|
|
338
|
+
},
|
|
339
|
+
_getEnableMpPhone(settingData) {
|
|
340
|
+
const config = settingData || this.data.settingData;
|
|
341
|
+
return !!config.miniprogram.find(function (item) {
|
|
342
|
+
return item.type === 'miniprogram_phone';
|
|
343
|
+
})?.enable;
|
|
344
|
+
},
|
|
345
|
+
_getEnableSms(settingData) {
|
|
346
|
+
const config = settingData || this.data.settingData;
|
|
347
|
+
return !!config.miniprogram.find(function (item) {
|
|
348
|
+
return item.type === 'sms';
|
|
349
|
+
})?.enable;
|
|
350
|
+
},
|
|
351
|
+
_intervalSender(delay) {
|
|
352
|
+
this.setData({
|
|
353
|
+
smsDelay: delay
|
|
354
|
+
});
|
|
355
|
+
const timerInterval = setInterval(() => {
|
|
356
|
+
delay = delay - 1;
|
|
357
|
+
if (delay <= 0) {
|
|
358
|
+
clearInterval(timerInterval);
|
|
359
|
+
}
|
|
360
|
+
this.setData({
|
|
361
|
+
smsDelay: delay
|
|
362
|
+
});
|
|
363
|
+
setStorage({
|
|
364
|
+
smsDelay: +new Date() + delay * 1000
|
|
365
|
+
});
|
|
366
|
+
}, 1000);
|
|
367
|
+
this.timerInterval = timerInterval;
|
|
368
|
+
},
|
|
369
|
+
compareVersion(version1, version2) {
|
|
370
|
+
// 将版本号字符串分割成数组
|
|
371
|
+
const v1 = version1.split('.');
|
|
372
|
+
const v2 = version2.split('.');
|
|
373
|
+
|
|
374
|
+
// 获取两个版本号数组的最大长度
|
|
375
|
+
const maxLength = Math.max(v1.length, v2.length);
|
|
376
|
+
|
|
377
|
+
// 遍历版本号数组并比较每个部分
|
|
378
|
+
for (let i = 0; i < maxLength; i++) {
|
|
379
|
+
// 如果某个版本号的长度较短,则将其补0
|
|
380
|
+
const num1 = parseInt(v1[i] || 0, 10);
|
|
381
|
+
const num2 = parseInt(v2[i] || 0, 10);
|
|
382
|
+
|
|
383
|
+
// 比较当前位置的数字大小
|
|
384
|
+
if (num1 > num2) {
|
|
385
|
+
return 1;
|
|
386
|
+
} else if (num1 < num2) {
|
|
387
|
+
return -1;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// 如果所有位置的数字都相同,则两个版本号相等
|
|
392
|
+
return 0;
|
|
393
|
+
},
|
|
394
|
+
async getAvatarUrl(avatarUrl) {
|
|
395
|
+
let avatarRealUrl = avatarUrl
|
|
396
|
+
if (avatarUrl.startsWith('cloud://')) {
|
|
397
|
+
const tcb = await app.cloud.getCloudInstance()
|
|
398
|
+
const pic = await tcb.getTempFileURL({
|
|
399
|
+
fileList: [avatarUrl]
|
|
400
|
+
})
|
|
401
|
+
avatarRealUrl = pic?.fileList?.[0]?.tempFileURL || ''
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return avatarRealUrl;
|
|
405
|
+
},
|
|
406
|
+
async dealOpenIdOrUnionIdLogin(type) {
|
|
407
|
+
try {
|
|
408
|
+
const res = await (AUTO_LOGIN_METHOD[type])(this);
|
|
409
|
+
if (res) {
|
|
410
|
+
const {
|
|
411
|
+
avatarUrl,
|
|
412
|
+
nickName
|
|
413
|
+
} = app.auth.currentUser
|
|
414
|
+
const {
|
|
415
|
+
SDKVersion
|
|
416
|
+
} = wx.getSystemInfoSync();
|
|
417
|
+
// 2.21.2以下版本不支持获取用户头像/昵称,暂时跳过
|
|
418
|
+
if ((!avatarUrl || !nickName) && this.compareVersion(SDKVersion, '2.21.2') >= 0) {
|
|
419
|
+
const avatarRealUrl = await this.getAvatarUrl(avatarUrl)
|
|
420
|
+
this.setData({
|
|
421
|
+
avatarRealUrl,
|
|
422
|
+
avatarUrl,
|
|
423
|
+
nickName,
|
|
424
|
+
baseInfoShow: true
|
|
425
|
+
})
|
|
426
|
+
} else {
|
|
427
|
+
loginSuccessCallBack(this);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
} catch (error) {
|
|
431
|
+
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
jumpBaseInfoConfig() {
|
|
435
|
+
loginSuccessCallBack(this);
|
|
436
|
+
},
|
|
437
|
+
methodClick(e) {
|
|
438
|
+
const {
|
|
439
|
+
type
|
|
440
|
+
} = e.currentTarget.dataset.item || {};
|
|
441
|
+
|
|
442
|
+
const currentLoginType = type || this.data.currentLoginType;
|
|
443
|
+
|
|
444
|
+
this.setData({
|
|
445
|
+
currentLoginType,
|
|
446
|
+
currentLoginList: this.data.settingData.miniprogram.filter(v => v.type !== currentLoginType)
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
if (AUTO_LOGIN_TYPE.includes(currentLoginType)) {
|
|
450
|
+
if (this.data.disableLoginSubmit) {
|
|
451
|
+
wx.showToast({
|
|
452
|
+
title: '请先阅读并同意协议',
|
|
453
|
+
icon: 'none'
|
|
454
|
+
})
|
|
455
|
+
return;
|
|
456
|
+
};
|
|
457
|
+
this.dealOpenIdOrUnionIdLogin(currentLoginType)
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
onChooseAvatar(e) {
|
|
462
|
+
this.setData({
|
|
463
|
+
avatarUrl: e.detail.avatarUrl,
|
|
464
|
+
avatarRealUrl: '',
|
|
465
|
+
})
|
|
466
|
+
},
|
|
467
|
+
nickNameChange(e) {
|
|
468
|
+
this.setData({
|
|
469
|
+
nickName: e.detail.value
|
|
470
|
+
})
|
|
471
|
+
},
|
|
472
|
+
randomStr(len = 32) {
|
|
473
|
+
const s = [];
|
|
474
|
+
const hexDigits = '0123456789abcdef';
|
|
475
|
+
const dictLen = hexDigits.length;
|
|
476
|
+
for (var i = 0; i < len; i++) {
|
|
477
|
+
const index = Math.floor(Math.random() * dictLen);
|
|
478
|
+
s[i] = hexDigits[index];
|
|
479
|
+
}
|
|
480
|
+
const result = s.join('');
|
|
481
|
+
return result;
|
|
482
|
+
},
|
|
483
|
+
async uploadFile(file) {
|
|
484
|
+
return new Promise(async (resolve) => {
|
|
485
|
+
const uploadPath = 'weda-uploader';
|
|
486
|
+
const fileType = file.split('.')?.slice(-1)?.[0];
|
|
487
|
+
const cloudPath = `${uploadPath}/${this.randomStr()}-${Date.now()}.${fileType}`;
|
|
488
|
+
try {
|
|
489
|
+
const tcb = await app.cloud.getCloudInstance();
|
|
490
|
+
const res = await tcb.uploadFile({
|
|
491
|
+
cloudPath: cloudPath,
|
|
492
|
+
filePath: file,
|
|
493
|
+
});
|
|
494
|
+
if (res.fileID) {
|
|
495
|
+
resolve(res)
|
|
496
|
+
} else {
|
|
497
|
+
throw res
|
|
498
|
+
}
|
|
499
|
+
} catch (e) {
|
|
500
|
+
wx.showModal({
|
|
501
|
+
title: '上传失败,请重试',
|
|
502
|
+
content: e.message,
|
|
503
|
+
showCancel: false,
|
|
504
|
+
});
|
|
505
|
+
resolve({});;
|
|
506
|
+
}
|
|
507
|
+
})
|
|
508
|
+
},
|
|
509
|
+
async baseInfoConfirm() {
|
|
510
|
+
let {
|
|
511
|
+
avatarUrl,
|
|
512
|
+
nickName,
|
|
513
|
+
currentLoginType,
|
|
514
|
+
} = this.data
|
|
515
|
+
|
|
516
|
+
wx.showLoading()
|
|
517
|
+
|
|
518
|
+
if (avatarUrl && !avatarUrl.startsWith('cloud://')) {
|
|
519
|
+
const res = await this.uploadFile(avatarUrl)
|
|
520
|
+
avatarUrl = res.fileID || ''
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
try {
|
|
524
|
+
const tcb = await app.cloud.getCloudInstance();
|
|
525
|
+
await tcb.auth.updateUserBasicInfo({
|
|
526
|
+
avatar_url: avatarUrl,
|
|
527
|
+
nickname: nickName,
|
|
528
|
+
user_id: app.auth.currentUser.userId
|
|
529
|
+
});
|
|
530
|
+
await (AUTO_LOGIN_METHOD[currentLoginType])(this);
|
|
531
|
+
loginSuccessCallBack(this);
|
|
532
|
+
} catch (error) {
|
|
533
|
+
wx.showModal({
|
|
534
|
+
title: '更新用户信息出错',
|
|
535
|
+
content: error.message,
|
|
536
|
+
showCancel: false,
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
wx.hideLoading()
|
|
541
|
+
}
|
|
542
|
+
},
|
|
543
|
+
observers: {
|
|
544
|
+
'settingData,agreement': function (settingData, agreement) {
|
|
545
|
+
const disabled = settingData?.agreement?.enable && !agreement;
|
|
546
|
+
if (!!this.data.disableLoginSubmit !== disabled) {
|
|
547
|
+
this.setData({
|
|
548
|
+
disableLoginSubmit: disabled
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
},
|
|
552
|
+
disableLoginSubmit: function (disableLoginSubmit) {
|
|
553
|
+
this.setData({
|
|
554
|
+
loginButtonClass: `${BUTTON_CLASSNAME} ${disableLoginSubmit ? 'is-disabled' : ''}`,
|
|
555
|
+
});
|
|
556
|
+
},
|
|
557
|
+
},
|
|
293
558
|
});
|