blessing.js
13.6 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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
import {
getBindtapData,
checkAuth
} from '../../utils/util';
import Dialog from '../../ui/vant-weapp/dialog/dialog';
const back = wx.getBackgroundAudioManager();
let app = getApp();
Page({
data: {
isOverShare: true,
authorizeVisible: false,
total: 0,
page: 1,
size: 10,
productList: [], // 产品列表
indexInfo: {},
userInfo: {},
options: {},
detailData: {},
ownerMember: {}, // 房主
memberList: [], // 用户信息
blessContent: [], // 祝福内容
isAuth: false, // 是否授权
// type: 0, // 0单人 1组队
// 个人信息修改
updateUserInfoDialogVisible: false,
updateUserInfo: {}, // 需要更新的用户数据
files: [], // 上传文件列表
// 房间信息信息修改
updateRoomDialogVisible: false,
updateRoomInfo: {}, // 需要更新的房间数据
// 加入房间
joinRoomDialogVisible: false,
isJoin: false, // 是否能加入状态
isPlayingBgm: false,
isMore: false,
// shortcutPics:["red-package2","more-bless"]
},
onShareAppMessage(res) {
let shareType = ""
if (res.from === 'button') {
// 来自页面内转发按钮
// shareType == join 分享给家人,能加入 组队模式
shareType = res.target.dataset.data || "";
console.log("shareType:", shareType);
} else {}
let {
detailData
} = this.data;
let memberCode = app.store.getItem("memberCode");
let title = "";
let path = `pages/blessing/blessing?c=${detailData.blessCode}&m=${memberCode}&t=${shareType}`;
console.log("share path:", path);
// let imageUrl = detailData && detailData.thumbnail || "";
return {
// title,
path,
// imageUrl
}
},
showAuth() {
this.setData({
authorizeVisible: true
})
},
onLoad(options) {
this.setData({
options
});
checkAuth().then((result) => {
this.setData({
isAuth: result
})
this.initData();
this.queryBlessDetail().then((result) => {
this.playBgm();
let {
detailData,
ownerMember,
memberList
} = this.data;
// 判断memberList里面是否有自己
let joined = false;
memberList.forEach(element => {
if (element.mySelf == 1) {
joined = true;
}
});
/**
* 显示加入房间条件
* 1.已定制
* 2.类型为组队类型
* 3.非房主
* 4.shareType为join t="join"
* 5.未加入过 判断memberList里面是否有自己
*/
console.log("---- 判断是否显示加入 Start ----");
console.log("已定制:", detailData.customMade == 1);
console.log("类型为组队类型:", detailData.type == 1);
console.log("非房主:", ownerMember.mySelf == 0);
console.log("shareType为join:", options);
console.log("是否加入过:", joined);
if (detailData.customMade == 1 && detailData.type == 1 && ownerMember.mySelf == 0 && options.t == "join" && !joined) {
this.setData({
joinRoomDialogVisible: true,
isJoin: true
})
}
});
console.log("memberCode:", app.store.getItem("memberCode"));
}).catch((err) => {});
},
/**
* 基础方法
* 授权完毕重拉数据用
*/
initData() {},
playBgm() {
return;
let _this = this;
let {
detailData
} = this.data;
this.setData({
isPlayingBgm: true,
})
back.title = "背景音乐";
back.src = detailData.musicUrl;
back.onEnded(() => {
_this.playBgm();
})
},
pauseBgm() {
wx.pauseBackgroundAudio()
this.setData({
isPlayingBgm: false,
})
},
onShowMoreHandler() {
this.setData({
isMore: true
})
},
showTips(evt) {
let tips = getBindtapData(evt);
wx.showModal({
content: tips,
success(res) {}
})
},
/**
* 赞赏祝福
* 跳转到赞赏页
*/
toReward() {
app.router.push({
path: "reward"
})
},
/**
* 选择更多祝福模版
*/
onMoreTemplateHandler() {
let pages = getCurrentPages();
if (pages.length > 1) {
// 如果能返回上一级
app.router.push({
openType: "back"
});
} else {
app.router.push({
openType: "redirect",
path: "index"
});
}
},
/**
* 分享图片祝福
* 生成海报
*/
onPosterHandler(){
},
// 显示更新用户信息
showUpdateUserInfoDialog() {
this.setData({
updateUserInfoDialogVisible: true,
updateUserInfo: {},
files: []
})
},
// 房主名字
onUpdateUserInfoBindInput(e) {
this.setData({
updateUserInfo: {
memberName: e.detail.value
}
})
},
// 显示更新用户信息
showUpdateRoomDialog() {
this.setData({
updateRoomDialogVisible: true,
updateRoomInfo: {},
})
},
// 家庭名称
onUpdateFamilyNameBindInput(e) {
this.setData({
"updateRoomInfo.familyName": e.detail.value
})
},
// 祝福语
onUpdateSentenceBindInput(e) {
this.setData({
"updateRoomInfo.sentence": e.detail.value
})
},
/**
* 更新房间信息
*/
onUpdateRoomHander() {
let {
detailData,
ownerMember,
updateRoomInfo
} = this.data;
console.log("updateRoomInfo:", updateRoomInfo);
app.post({
url: app.api.blessUpdateRoom,
data: {
blessCode: detailData.blessCode,
// ownerMemberCode: app.store.getItem("memberCode"),
familyName: updateRoomInfo.familyName || "",
sentence: updateRoomInfo.sentence || "",
}
}).then((result) => {
console.log("result:", result);
this.queryBlessDetail();
}).catch((err) => {});
},
/**
* 上传头像
*/
onUploadHandler() {
let _this = this;
wx.chooseImage({
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
count: 1,
success(res) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFiles = res.tempFiles
let files = tempFiles;
console.log("chooseImage files:", files);
_this.setData({
files
});
}
})
},
/**
* 更新拜年页用户信息
*/
onUpdateUserInfoHander() {
let {
detailData,
ownerMember,
updateUserInfo,
files
} = this.data;
let pics = [];
files.forEach(element => {
pics.push(element.path)
});
this.uploadToCustomService(pics).then((picRes) => {
console.log("picRes:", picRes);
console.log("updateUserInfo:", updateUserInfo);
app.post({
url: app.api.blessUpdateUserInfo,
data: {
blessCode: detailData.blessCode,
ownerMemberCode: this.data.options.m ? this.data.options.m : app.store.getItem("memberCode") ? app.store.getItem("memberCode") : "",
memberName: updateUserInfo.memberName || "",
memberHead: picRes[0] || "",
}
}).then((result) => {
console.log("result:", result);
this.queryBlessDetail();
}).catch((err) => {});
})
},
/**
* 上传到自定义服务器
* urlList 需要上传的图片地址
*/
uploadToCustomService(urlList) {
let _this = this;
return new Promise((resolve, reject) => {
// promise列表
let p = [];
// 用promise上传音频
urlList.forEach(element => {
let myPromise = new Promise((resolve2, reject2) => {
_this.uploadfileMultiple(element).then((result2) => {
resolve2(result2)
}).catch((err) => {
reject2();
});
});
p.push(myPromise);
});
Promise.all(p).then(uploadFiles => {
resolve(uploadFiles)
}, reason => {
reject();
});
});
},
/**
* 多文件上传
* @param {*} filePath
*/
uploadfileMultiple(filePath) {
let _this = this;
return new Promise((resolve, reject) => {
wx.uploadFile({
url: app.config.NET_CONFIG.commonApi + app.api.uploadFile,
filePath: filePath,
name: 'file',
// header: {}, // 设置请求的 header
header: {
'content-type': 'multipart/form-data'
},
formData: {
path: '/weapp/jyes/avatar/'
},
// HTTP 请求中其他额外的 form data
success(res) {
let result = JSON.parse(res.data).content;
resolve(result);
},
fail() {
reject()
},
complete: function () {}
})
});
},
/**
* 视频详情
*/
queryBlessDetail() {
return new Promise((resolve, reject) => {
app.post({
url: app.api.blessDetail,
data: {
blessCode: this.data.options.c,
ownerMemberCode: this.data.options.m ? this.data.options.m : app.store.getItem("memberCode") ? app.store.getItem("memberCode") : "",
}
}).then((result) => {
let blessContent = [];
try {
blessContent = JSON.parse(result.blessContent) || [];
} catch (error) {}
let memberList = result.memberList;
// hardcode数据
// for (let index = 0; index < 18; index++) {
// memberList.push({
// blessCode: "4144feba2b904ba89585d90e8618a863",
// blessMemberCode: "747e8e314d0e46679be17fb495975439",
// count: 2,
// customMade: 0,
// familyName: "祝福团体称呼",
// memberCode: "9af835ad57234cf2826b770dcc8a9897",
// memberHead: "https://wx.qlogo.cn/mmopen/vi_32/v4XnMftVxCzkFD8ibLicDjxicFhzugVt4vUWsHmup9ZeunwZhQ21H9ugELpgyTicsVyNCXenqIlUHBIkZ2aEP2qPpw/132",
// memberName: "ee",
// mySelf: 1,
// owner: 0,
// sentence: "定义"
// })
// }
this.setData({
detailData: result,
ownerMember: result.ownerMember,
memberList: memberList,
blessContent: blessContent,
});
console.log("detailData:", result);
console.log("blessContent:", this.data.blessContent);
console.log("类型 type => ", result.type == 1 ? "组队" : "单人");
console.log("是否已定制 customMade => ", result.customMade == 1 ? "已经定制" : "未定制");
console.log("是否自己房间 mySelf => ", result.ownerMember.mySelf == 1 ? "是" : "否");
console.log("房主信息 ownerMember => ", result.ownerMember);
console.log("是否授权 isAuth =>", this.data.isAuth);
console.log("房主信息 =>", result.ownerMember);
console.log("祝福内容 =>", result.blessContent);
resolve(result);
}).catch((err) => {
reject(err);
});
});
},
/**
* 标记定制祝福
*/
onBlessMakeHandler() {
let {
detailData,
isAuth
} = this.data;
console.log("isAuth:", isAuth);
if (isAuth) {
// 已授权
app.post({
url: app.api.blessMade,
data: {
blessCode: detailData.blessCode,
}
}).then((result) => {
this.queryBlessDetail().then((result) => {
wx.showModal({
title: '定制祝福成功!',
content: '马上为亲朋好友送上祝福吧~',
success(res) {}
})
});
}).catch((err) => {});
} else {
// 未授权
}
},
/**
* 加入房间
*/
onBlessJoinHandler(e) {
let {
options,
detailData
} = this.data;
app.post({
url: app.api.blessJoin,
data: {
ownerMemberCode: options.m,
blessCode: detailData.blessCode
}
}).then((result) => {
this.setData({
isJoin: false
})
this.queryBlessDetail().then((result) => {
wx.showModal({
content: '加入成功',
success(res) {}
})
});
}).catch((err) => {
});
},
// 点击确认授权按钮
bindGetUserInfo(e) {
let _this = this;
wx.showLoading();
wx.login({
success(res) {
app.store.setItem('wxcode', res.code);
_this.getUserInfo(e.detail);
}
});
},
// 授权操作
getUserInfo(e) {
let _this = this;
if (e.encryptedData && e.iv) {
// 同意授权
app.post({
url: app.api.register,
sid: false,
data: {
encryptedData: e.encryptedData,
iv: e.iv,
code: app.store.getItem("wxcode"),
tlMemberCode: app.globalData.tlMemberCode
}
}).then((res2) => {
wx.hideLoading();
if (res2 && res2.sessionId) {
app.store.setItem('sessionId', res2.sessionId);
}
wx.showModal({
content: '授权成功',
success(res) {}
})
checkAuth().then((result) => {
_this.setData({
isAuth: result
});
}).catch((err) => {});
}).catch((err) => {
wx.hideLoading();
console.log("授权成功 err:", err);
})
} else {
// 取消授权
wx.hideLoading();
console.log("取消授权");
}
},
/**
* 隐藏蒙层
*/
hideMask() {
this.setData({
productDetailVisible: false,
authorizeVisible: false,
})
},
/**
* 子组件事件
* @param {*} evt
*/
evtcomp(evt) {
let {
name,
data
} = evt.detail;
switch (name) {
// 隐藏蒙层
case "_evt_hide_mask":
this.hideMask();
break;
/**
* 重拉数据已在
*/
case "_evt_auth_complete":
// this.initData();
this.hideMask();
break;
default:
break;
}
},
})