Browse Source

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

许静 5 years ago
parent
commit
d0f0824e23

+ 76
- 22
src/components/Poster/index.js View File

1
 import Taro, { Component } from '@tarojs/taro';
1
 import Taro, { Component } from '@tarojs/taro';
2
-import { ScrollView, View } from '@tarojs/components';
2
+import { ScrollView, View, Block } from '@tarojs/components';
3
 import { TaroCanvasDrawer } from '@components/taro-plugin-canvas';
3
 import { TaroCanvasDrawer } from '@components/taro-plugin-canvas';
4
-import {} from './util';
4
+import { getCanvasConfig } from './util';
5
 import './style.scss';
5
 import './style.scss';
6
 
6
 
7
 export default class Poster extends Component {
7
 export default class Poster extends Component {
8
   state = {
8
   state = {
9
     images: [],
9
     images: [],
10
     current: undefined,
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
   onPreview = (e) => {
34
   onPreview = (e) => {
18
     e.stopPropagation()
35
     e.stopPropagation()
19
     e.preventDefault()
36
     e.preventDefault()
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
   onCreateSuccess = (inx) => (result) => {
80
   onCreateSuccess = (inx) => (result) => {
38
       Taro.hideLoading();
82
       Taro.hideLoading();
39
     }
83
     }
40
 
84
 
85
+    let images = this.state.images || []
41
     const { tempFilePath, errMsg } = result;
86
     const { tempFilePath, errMsg } = result;
42
     if (errMsg === 'canvasToTempFilePath:ok') {
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
     } else {
89
     } else {
90
+      images[inx] = undefined
50
       console.log(errMsg);
91
       console.log(errMsg);
51
     }
92
     }
52
-
93
+    this.setState({ images });
53
   }
94
   }
54
 
95
 
55
   onCreateFail = (inx) => (err) => {
96
   onCreateFail = (inx) => (err) => {
57
       Taro.hideLoading();
98
       Taro.hideLoading();
58
     }
99
     }
59
 
100
 
101
+    let images = this.state.images || []
102
+    images[inx] = undefined
103
+    this.setState({ images });
60
     console.err(err);
104
     console.err(err);
61
   }
105
   }
62
 
106
 
76
           <View className="con-body">
120
           <View className="con-body">
77
             {
121
             {
78
               images.map((img, inx) => {
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
           </View>
130
           </View>
85
           <Button className="save-btn" onClick={this.saveToAlbum}>保存海报</Button>
131
           <Button className="save-btn" onClick={this.saveToAlbum}>保存海报</Button>
86
         </View>
132
         </View>
87
         {
133
         {
88
-          configs && configs.length &&
134
+          configs &&
89
           (
135
           (
90
             configs.map((conf, inx) => {
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 View File

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 View File

3
 import Notice from '@components/Notice'
3
 import Notice from '@components/Notice'
4
 import BackHomeBtn from '@components/BackHomeBtn'
4
 import BackHomeBtn from '@components/BackHomeBtn'
5
 import AchievePhone from '@components/achievePhone'
5
 import AchievePhone from '@components/achievePhone'
6
-import Poster from './poster'
6
+import Poster from '@components/Poster'
7
 import dayjs from 'dayjs'
7
 import dayjs from 'dayjs'
8
 // import WxParse from '@components/wxParse/wxParse'
8
 // import WxParse from '@components/wxParse/wxParse'
9
 import getUserPhone from '@utils/getUserPhone'
9
 import getUserPhone from '@utils/getUserPhone'
51
     helpList: [], // 助力人员列表
51
     helpList: [], // 助力人员列表
52
     shares: [], // 分享设置
52
     shares: [], // 分享设置
53
     posters: [],  // 海报设置
53
     posters: [],  // 海报设置
54
+    posterTpls: [], // 海报模板
54
     leftTime: 0,  // 剩余时间
55
     leftTime: 0,  // 剩余时间
55
     ltTicker: undefined,  // 剩余时间计时器
56
     ltTicker: undefined,  // 剩余时间计时器
56
     actState: ActBeforeStart,  // 活动本身状态
57
     actState: ActBeforeStart,  // 活动本身状态
76
     this.clearTicker()
77
     this.clearTicker()
77
   }
78
   }
78
 
79
 
80
+  // 初始化页面数据
79
   initPageData = () => {
81
   initPageData = () => {
80
     if (!this.state.detail.helpActivityId) {
82
     if (!this.state.detail.helpActivityId) {
81
       const router = Taro.getStorageSync('router')
83
       const router = Taro.getStorageSync('router')
88
     }
90
     }
89
   }
91
   }
90
 
92
 
93
+  // 清除 ticker
91
   clearTicker() {
94
   clearTicker() {
92
     if (this.state.ltTicker) {
95
     if (this.state.ltTicker) {
93
       clearInterval(this.state.ltTicker)
96
       clearInterval(this.state.ltTicker)
117
     return true
120
     return true
118
   }
121
   }
119
 
122
 
123
+  // 打开关闭 ActionSheet 面板
120
   toggleActionVisible = () => {
124
   toggleActionVisible = () => {
121
     this.setState({
125
     this.setState({
122
       actionSheetVisible: !this.state.actionSheetVisible
126
       actionSheetVisible: !this.state.actionSheetVisible
123
     })
127
     })
124
   }
128
   }
125
 
129
 
130
+  // 打开关闭海报面板
126
   togglePosterVisible = () => {
131
   togglePosterVisible = () => {
127
     this.setState({
132
     this.setState({
128
       posterVisible: !this.state.posterVisible,
133
       posterVisible: !this.state.posterVisible,
130
     })
135
     })
131
   }
136
   }
132
 
137
 
138
+  // 计时器更新剩余时间
133
   updateLeftTime(startDate, endDate) {
139
   updateLeftTime(startDate, endDate) {
134
     const st = dayjs(startDate).valueOf()
140
     const st = dayjs(startDate).valueOf()
135
     const ed = dayjs(endDate).valueOf()
141
     const ed = dayjs(endDate).valueOf()
162
     })
168
     })
163
   }
169
   }
164
 
170
 
171
+  // 格式化剩余时间
165
   formateLeftTime = () => {
172
   formateLeftTime = () => {
166
     const nd = 1000 * 24 * 60 * 60;
173
     const nd = 1000 * 24 * 60 * 60;
167
     const nh = 1000 * 60 * 60;
174
     const nh = 1000 * 60 * 60;
176
     return `${day}天${hour}小时${min}分${sec}秒`
183
     return `${day}天${hour}小时${min}分${sec}秒`
177
   }
184
   }
178
 
185
 
186
+  // 请求详情
179
   loadDetail() {
187
   loadDetail() {
180
     const { id, initiateId } = this.state
188
     const { id, initiateId } = this.state
181
     const { userInfo } = this.props
189
     const { userInfo } = this.props
193
         helpState: initiateDetail.status === undefined ? HelpInProcess : initiateDetail.status,
201
         helpState: initiateDetail.status === undefined ? HelpInProcess : initiateDetail.status,
194
         shares: res.shareContentList || [],
202
         shares: res.shareContentList || [],
195
         posters: res.postList || [],
203
         posters: res.postList || [],
204
+        posterTpls: res.posterTemplateList || [],
196
         helpList: res.helpRecordList || [],
205
         helpList: res.helpRecordList || [],
197
         loaded: true,
206
         loaded: true,
198
         isStarter: !initiateDetail.personId || userInfo.person.personId === initiateDetail.personId,
207
         isStarter: !initiateDetail.personId || userInfo.person.personId === initiateDetail.personId,
217
   }
226
   }
218
 
227
 
219
   currentPageAndParams() {
228
   currentPageAndParams() {
220
-    const { detail, initiateDetail } = this.state
229
+    const { id, initiateId } = this.state
221
     const { userInfo: { person: { personId } } } = this.props
230
     const { userInfo: { person: { personId } } } = this.props
222
 
231
 
223
     let queryParams = [
232
     let queryParams = [
224
-      `id=${detail.helpActivityId}`,
233
+      `id=${id}`,
225
       `from=help_share`,
234
       `from=help_share`,
226
       `recommender=${personId}`
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
     const res = [
241
     const res = [
235
     ]
244
     ]
236
 
245
 
237
     console.log('--page-params->', res)
246
     console.log('--page-params->', res)
238
-
239
     return res
247
     return res
240
   }
248
   }
241
 
249
 
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
   render() {
408
   render() {
422
     const {
409
     const {
426
       loaded,
413
       loaded,
427
       actState,
414
       actState,
428
       posterVisible,
415
       posterVisible,
429
-      posterData,
430
       isStarter,
416
       isStarter,
431
       helpList,
417
       helpList,
432
       helpState,
418
       helpState,
433
       actionSheetVisible,
419
       actionSheetVisible,
434
       grantPhoneVisible,
420
       grantPhoneVisible,
421
+      posterTpls,
422
+      posters,
423
+      qrCode,
435
     } = this.state
424
     } = this.state
436
 
425
 
437
     const { userInfo } = this.props
426
     const { userInfo } = this.props
438
     const avatar = initiateId ? initiateDetail.avatarurl : userInfo.person.avatarurl
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
     return (
437
     return (
441
       <Block>
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
           grantPhoneVisible &&
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
                   <Button open-type="share" className='share__friend' onClick={this.toggleActionVisible}>分享给好友</Button>
546
                   <Button open-type="share" className='share__friend' onClick={this.toggleActionVisible}>分享给好友</Button>
550
                 </action-sheet-item>
547
                 </action-sheet-item>
551
                 <action-sheet-item>
548
                 <action-sheet-item>
552
-                  <Button className='creat__img' onClick={this.togglePosterVisible}>发送朋友圈</Button>
549
+                  <Button className='creat__img' onClick={this.shareMoments}>发送朋友圈</Button>
553
                 </action-sheet-item>
550
                 </action-sheet-item>
554
                 <action-sheet-cancel onClick={this.toggleActionVisible}>取消</action-sheet-cancel>
551
                 <action-sheet-cancel onClick={this.toggleActionVisible}>取消</action-sheet-cancel>
555
               </action-sheet>
552
               </action-sheet>