Bladeren bron

Merge branch 'v4' of http://git.ycjcjy.com/zhiyuxing/miniapp-v3 into v4

许静 5 jaren geleden
bovenliggende
commit
d0f0824e23
3 gewijzigde bestanden met toevoegingen van 141 en 152 verwijderingen
  1. 76
    22
      src/components/Poster/index.js
  2. 0
    62
      src/components/Poster/index.scss
  3. 65
    68
      src/pages/activity/detail/assistance.js

+ 76
- 22
src/components/Poster/index.js Bestand weergeven

@@ -1,19 +1,36 @@
1 1
 import Taro, { Component } from '@tarojs/taro';
2
-import { ScrollView, View } from '@tarojs/components';
2
+import { ScrollView, View, Block } from '@tarojs/components';
3 3
 import { TaroCanvasDrawer } from '@components/taro-plugin-canvas';
4
-import {} from './util';
4
+import { getCanvasConfig } from './util';
5 5
 import './style.scss';
6 6
 
7 7
 export default class Poster extends Component {
8 8
   state = {
9 9
     images: [],
10 10
     current: undefined,
11
+    configs: undefined,
11 12
   }
12 13
 
13
-  onScroll = (e) => {
14
-    console.log('---onScroll-->', e)
14
+  componentWillMount() {
15
+    if (!Array.isArray(this.props.tpls)) {
16
+      throw new Error('当前内容未维护海报信息')
17
+    }
18
+
19
+    let configs = this.state.configs || []
20
+    this.props.tpls.forEach((tpl, inx) => {
21
+      const conf = getCanvasConfig(tpl.configs, this.props.params)
22
+      configs.push(conf)
23
+
24
+      if (inx === this.props.tpls.length - 1) {
25
+        this.setState({ configs })
26
+      }
27
+    })
15 28
   }
16
-  
29
+
30
+  onScroll = inx => (e) => {
31
+    this.setState({ current: this.state.images[inx] })
32
+  }
33
+
17 34
   onPreview = (e) => {
18 35
     e.stopPropagation()
19 36
     e.preventDefault()
@@ -29,8 +46,35 @@ export default class Poster extends Component {
29 46
     }
30 47
   }
31 48
 
32
-  saveToAlbum = () => {
49
+  saveToAlbum = (e) => {
50
+    e.stopPropagation()
51
+    e.preventDefault()
52
+
53
+    if (!this.state.current) {
54
+      return
55
+    }
33 56
 
57
+    Taro.authorize({ scope: "scope.writePhotosAlbum" }).then(res => {
58
+      Taro.saveImageToPhotosAlbum({
59
+        filePath: this.state.current,
60
+      }).then(res => {
61
+        if (typeof this.props.onFinish === 'function') {
62
+          this.props.onFinish()
63
+        }
64
+
65
+        Taro.showToast({
66
+          title: '保存图片成功',
67
+          icon: 'success',
68
+          duration: 2000,
69
+        });
70
+      })
71
+    }).catch(err => {
72
+      console.log('err:', err)
73
+      Taro.showToast({
74
+        title: '未开启相册权限',
75
+        icon: 'none'
76
+      })
77
+    })
34 78
   }
35 79
 
36 80
   onCreateSuccess = (inx) => (result) => {
@@ -38,18 +82,15 @@ export default class Poster extends Component {
38 82
       Taro.hideLoading();
39 83
     }
40 84
 
85
+    let images = this.state.images || []
41 86
     const { tempFilePath, errMsg } = result;
42 87
     if (errMsg === 'canvasToTempFilePath:ok') {
43
-      this.setState({
44
-        shareImage: tempFilePath,
45
-        canvasStatus: false,
46
-        config: null,
47
-        visible: true
48
-      });
88
+      images[inx] = tempFilePath
49 89
     } else {
90
+      images[inx] = undefined
50 91
       console.log(errMsg);
51 92
     }
52
-
93
+    this.setState({ images });
53 94
   }
54 95
 
55 96
   onCreateFail = (inx) => (err) => {
@@ -57,6 +98,9 @@ export default class Poster extends Component {
57 98
       Taro.hideLoading();
58 99
     }
59 100
 
101
+    let images = this.state.images || []
102
+    images[inx] = undefined
103
+    this.setState({ images });
60 104
     console.err(err);
61 105
   }
62 106
 
@@ -76,23 +120,33 @@ export default class Poster extends Component {
76 120
           <View className="con-body">
77 121
             {
78 122
               images.map((img, inx) => {
79
-                <ScrollView scrollX scrollWithAnimation onScroll={this.onScroll} style="width: 100%" key={`img-${inx}`}>
80
-                  <Image className="result-img" mode="aspectFit" lazy-load src={img} onClick={this.onPreview}></Image>
81
-                </ScrollView>
123
+                return (
124
+                  <ScrollView scrollX scrollWithAnimation onScroll={this.onScroll(inx)} style="width: 100%" key={`img-${inx}`}>
125
+                    <Image className="result-img" mode="aspectFit" lazy-load src={img} onClick={this.onPreview}></Image>
126
+                  </ScrollView>
127
+                )
82 128
               })
83 129
             }
84 130
           </View>
85 131
           <Button className="save-btn" onClick={this.saveToAlbum}>保存海报</Button>
86 132
         </View>
87 133
         {
88
-          configs && configs.length &&
134
+          configs &&
89 135
           (
90 136
             configs.map((conf, inx) => {
91
-              <TaroCanvasDrawer
92
-                config={conf}
93
-                onCreateSuccess={this.onCreateSuccess(inx)}
94
-                onCreateFail={this.onCreateFail(inx)}
95
-              />
137
+              return (
138
+                <Block key={`cvs-${inx}`}>
139
+                  {
140
+                    !images[inx] && (
141
+                      <TaroCanvasDrawer
142
+                        config={conf}
143
+                        onCreateSuccess={this.onCreateSuccess(inx)}
144
+                        onCreateFail={this.onCreateFail(inx)}
145
+                      />
146
+                    )
147
+                  }
148
+                </Block>
149
+              )
96 150
             })
97 151
           )
98 152
         }

+ 0
- 62
src/components/Poster/index.scss Bestand weergeven

@@ -1,62 +0,0 @@
1
-.poster {
2
-  position: fixed;
3
-  width: 100vw;
4
-  height: 100vh;
5
-  background: rgba(0, 0, 0, 0.6);
6
-  z-index: 999;
7
-  justify-content: space-around;
8
-  display: flex;
9
-  align-items: center;
10
-  flex-direction: column;
11
-  top: 0;
12
-
13
-  .con {
14
-    position: absolute;
15
-    bottom: 0;
16
-    width: 100%;
17
-    padding: 0 60px;
18
-    background: white;
19
-    margin: 0 auto;
20
-    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
21
-    border-top-left-radius: 20px;
22
-    border-top-right-radius: 20px;
23
-
24
-    &-head {
25
-      display: flex;
26
-      justify-content: space-between;
27
-      align-items: center;
28
-      padding: 20px 0;
29
-      font-size: 32px;
30
-      font-weight: bold;
31
-
32
-      .iconfont {
33
-        font-size: 40px;
34
-        color: #545454;
35
-        font-weight: normal;
36
-      }
37
-    }
38
-
39
-    &-body {
40
-      width: 100%;
41
-      // background: #EAEAEA;
42
-      border-radius: 10px;
43
-      padding: 40px 0;
44
-
45
-      .result-img {
46
-        height: 60vh;
47
-        display: block;
48
-        margin: 0 auto;
49
-      }
50
-    }
51
-  }
52
-
53
-  .save-btn {
54
-    margin: 0 auto;
55
-    color: white;
56
-    border: none;
57
-    font-size: 36px;
58
-    background: linear-gradient(90deg, rgba(255, 199, 12, 1) 0%, rgba(255, 65, 65, 1) 100%);
59
-    border-radius: 12px;
60
-    margin: 20px 0;
61
-  }
62
-}

+ 65
- 68
src/pages/activity/detail/assistance.js Bestand weergeven

@@ -3,7 +3,7 @@ import './index.scss'
3 3
 import Notice from '@components/Notice'
4 4
 import BackHomeBtn from '@components/BackHomeBtn'
5 5
 import AchievePhone from '@components/achievePhone'
6
-import Poster from './poster'
6
+import Poster from '@components/Poster'
7 7
 import dayjs from 'dayjs'
8 8
 // import WxParse from '@components/wxParse/wxParse'
9 9
 import getUserPhone from '@utils/getUserPhone'
@@ -51,6 +51,7 @@ export default class Detail extends Component {
51 51
     helpList: [], // 助力人员列表
52 52
     shares: [], // 分享设置
53 53
     posters: [],  // 海报设置
54
+    posterTpls: [], // 海报模板
54 55
     leftTime: 0,  // 剩余时间
55 56
     ltTicker: undefined,  // 剩余时间计时器
56 57
     actState: ActBeforeStart,  // 活动本身状态
@@ -76,6 +77,7 @@ export default class Detail extends Component {
76 77
     this.clearTicker()
77 78
   }
78 79
 
80
+  // 初始化页面数据
79 81
   initPageData = () => {
80 82
     if (!this.state.detail.helpActivityId) {
81 83
       const router = Taro.getStorageSync('router')
@@ -88,6 +90,7 @@ export default class Detail extends Component {
88 90
     }
89 91
   }
90 92
 
93
+  // 清除 ticker
91 94
   clearTicker() {
92 95
     if (this.state.ltTicker) {
93 96
       clearInterval(this.state.ltTicker)
@@ -117,12 +120,14 @@ export default class Detail extends Component {
117 120
     return true
118 121
   }
119 122
 
123
+  // 打开关闭 ActionSheet 面板
120 124
   toggleActionVisible = () => {
121 125
     this.setState({
122 126
       actionSheetVisible: !this.state.actionSheetVisible
123 127
     })
124 128
   }
125 129
 
130
+  // 打开关闭海报面板
126 131
   togglePosterVisible = () => {
127 132
     this.setState({
128 133
       posterVisible: !this.state.posterVisible,
@@ -130,6 +135,7 @@ export default class Detail extends Component {
130 135
     })
131 136
   }
132 137
 
138
+  // 计时器更新剩余时间
133 139
   updateLeftTime(startDate, endDate) {
134 140
     const st = dayjs(startDate).valueOf()
135 141
     const ed = dayjs(endDate).valueOf()
@@ -162,6 +168,7 @@ export default class Detail extends Component {
162 168
     })
163 169
   }
164 170
 
171
+  // 格式化剩余时间
165 172
   formateLeftTime = () => {
166 173
     const nd = 1000 * 24 * 60 * 60;
167 174
     const nh = 1000 * 60 * 60;
@@ -176,6 +183,7 @@ export default class Detail extends Component {
176 183
     return `${day}天${hour}小时${min}分${sec}秒`
177 184
   }
178 185
 
186
+  // 请求详情
179 187
   loadDetail() {
180 188
     const { id, initiateId } = this.state
181 189
     const { userInfo } = this.props
@@ -193,6 +201,7 @@ export default class Detail extends Component {
193 201
         helpState: initiateDetail.status === undefined ? HelpInProcess : initiateDetail.status,
194 202
         shares: res.shareContentList || [],
195 203
         posters: res.postList || [],
204
+        posterTpls: res.posterTemplateList || [],
196 205
         helpList: res.helpRecordList || [],
197 206
         loaded: true,
198 207
         isStarter: !initiateDetail.personId || userInfo.person.personId === initiateDetail.personId,
@@ -217,16 +226,16 @@ export default class Detail extends Component {
217 226
   }
218 227
 
219 228
   currentPageAndParams() {
220
-    const { detail, initiateDetail } = this.state
229
+    const { id, initiateId } = this.state
221 230
     const { userInfo: { person: { personId } } } = this.props
222 231
 
223 232
     let queryParams = [
224
-      `id=${detail.helpActivityId}`,
233
+      `id=${id}`,
225 234
       `from=help_share`,
226 235
       `recommender=${personId}`
227 236
     ]
228
-    if (initiateDetail.helpRecordInitiateId) {
229
-      queryParams.push(`initiateId=${initiateDetail.helpRecordInitiateId}`)
237
+    if (initiateId) {
238
+      queryParams.push(`initiateId=${initiateId}`)
230 239
     }
231 240
 
232 241
     const res = [
@@ -235,7 +244,6 @@ export default class Detail extends Component {
235 244
     ]
236 245
 
237 246
     console.log('--page-params->', res)
238
-
239 247
     return res
240 248
   }
241 249
 
@@ -355,68 +363,47 @@ export default class Detail extends Component {
355 363
     }
356 364
   }
357 365
 
358
-  handleFavor() {
359
-  }
360
-
361
-  getPosterData = () => {
362
-    return new Promise(resolve => {
363
-      const { posterData } = this.state
364
-      if (posterData.qrcode) {
365
-        resolve(posterData)
366
-        return
367
-      }
368
-
369
-      const { userInfo: { person } } = this.props
370
-      const { avatarurl, nickname } = person
371
-      const { detail: { posters, createDate } } = this.state
372
-      const [page, scene] = this.currentPageAndParams()
373
-      const payload = { page, scene }
374
-
375
-      const _avatarurl = getDownloadURL(avatarurl, 'avatar');
376
-      getMiniQrcode(payload).then(qrcode => {
377
-        let data = {
378
-          qrcode,//小程序二维码
379
-          nickname,//访问者名字
380
-          avatarurl: _avatarurl,//访问者头像
381
-          poster: posters[0].posterImg,
382
-          title: posters[0].posterTitle,//海报标题
383
-          createDate: createDate,//时间
384
-        }
385
-        resolve(data)
386
-      })
366
+  getQRCode() {
367
+    const [page, scene] = this.currentPageAndParams()
368
+    const payload = { page, scene }
369
+  
370
+    getMiniQrcode(payload).then(qrCode => {
371
+      this.setState({ qrCode, posterVisible: true })
387 372
     })
388 373
   }
389 374
 
390
-  // 开始生成海报
391
-  togglePosterStatus = (flag) => {
392
-    if (flag) {
393
-      this.getPosterData().then(posterData => {
394
-        this.setState({
395
-          posterVisible: !!flag,
396
-          posterData
397
-        })
398
-      })
399
-      // App.zhuge.track('生成助力详情海报')
400
-    } else {
401
-      this.setState({
402
-        posterVisible: !!flag
403
-      })
404
-    }
405
-    savePoint({
406
-      event: 'poster',
407
-      eventType: 'help',
408
-      propertyName: '生成助力详情海报',
409
-      data: '{}'
410
-    }).then(res => {
411
-      console.log('生成助力详情海报')
412
-    })
375
+  // 发送朋友圈
376
+  shareMoments = () => {
377
+    this.getQRCode().then(() => {
378
+      this.togglePosterVisible()
379
+    })    
413 380
   }
414 381
 
415
-  hideModal() {
416
-    this.setState({
417
-      canChoose: 'none'
418
-    })
419
-  }
382
+  // // 开始生成海报
383
+  // togglePosterStatus = (flag) => {
384
+  //   if (flag) {
385
+  //     this.getPosterData().then(posterData => {
386
+  //       this.setState({
387
+  //         posterVisible: !!flag,
388
+  //         posterData
389
+  //       })
390
+  //     })
391
+  //     // App.zhuge.track('生成助力详情海报')
392
+  //   } else {
393
+  //     this.setState({
394
+  //       posterVisible: !!flag
395
+  //     })
396
+  //   }
397
+
398
+  //   savePoint({
399
+  //     event: 'poster',
400
+  //     eventType: 'help',
401
+  //     propertyName: '生成助力详情海报',
402
+  //     data: '{}',
403
+  //   }).then(res => {
404
+  //     console.log('生成助力详情海报')
405
+  //   })
406
+  // }
420 407
 
421 408
   render() {
422 409
     const {
@@ -426,25 +413,35 @@ export default class Detail extends Component {
426 413
       loaded,
427 414
       actState,
428 415
       posterVisible,
429
-      posterData,
430 416
       isStarter,
431 417
       helpList,
432 418
       helpState,
433 419
       actionSheetVisible,
434 420
       grantPhoneVisible,
421
+      posterTpls,
422
+      posters,
423
+      qrCode,
435 424
     } = this.state
436 425
 
437 426
     const { userInfo } = this.props
438 427
     const avatar = initiateId ? initiateDetail.avatarurl : userInfo.person.avatarurl
428
+    const posterData = {
429
+      title: posters[0] ? posters[0].posterTitle : '',
430
+      desc: posters[0] ? posters[0].posterDescription : '',
431
+      poster: posters[0] ? posters[0].posterImg : '',
432
+      name: userInfo.person.name || userInfo.person.nickname,
433
+      qrcode: qrCode,
434
+      avatarurl: getDownloadURL(userInfo.person.avatarurl, 'avatar') || '',
435
+    }
439 436
 
440 437
     return (
441 438
       <Block>
442 439
         {/* 生成海报 */}
443
-        {posterVisible && (<Poster data={posterData} toggle={this.togglePosterStatus}></Poster>)}
444
-
440
+        {posterVisible && (<Poster tpls={posterTpls} params={posterData} onCancel={this.togglePosterVisible} onFinish={this.togglePosterVisible}></Poster>)}
441
+        
445 442
         {
446 443
           grantPhoneVisible &&
447
-          <AchievePhone user={this.props.userInfo.person} onSuccess={this.initPageData}></AchievePhone>
444
+          <AchievePhone user={userInfo.person} onSuccess={this.initPageData}></AchievePhone>
448 445
         }
449 446
 
450 447
         {
@@ -549,7 +546,7 @@ export default class Detail extends Component {
549 546
                   <Button open-type="share" className='share__friend' onClick={this.toggleActionVisible}>分享给好友</Button>
550 547
                 </action-sheet-item>
551 548
                 <action-sheet-item>
552
-                  <Button className='creat__img' onClick={this.togglePosterVisible}>发送朋友圈</Button>
549
+                  <Button className='creat__img' onClick={this.shareMoments}>发送朋友圈</Button>
553 550
                 </action-sheet-item>
554 551
                 <action-sheet-cancel onClick={this.toggleActionVisible}>取消</action-sheet-cancel>
555 552
               </action-sheet>