张延森 5 年前
父节点
当前提交
6d3d821bc1

+ 4
- 4
config/dev.js 查看文件

5
   defineConstants: {
5
   defineConstants: {
6
 		// HOST: '"http://47.101.36.130:8085"',//测试
6
 		// HOST: '"http://47.101.36.130:8085"',//测试
7
     // WSS_HOST: '"wss://47.101.36.130:8085"',
7
     // WSS_HOST: '"wss://47.101.36.130:8085"',
8
-    // HOST: '"https://dev.jinchengjiaye.com"',//测试
9
-    // WSS_HOST: '"wss://dev.jinchengjiaye.com"',
8
+    HOST: '"https://dev.jinchengjiaye.com"',//测试
9
+    WSS_HOST: '"wss://dev.jinchengjiaye.com"',
10
     // HOST: '"https://lt.pawoma.cn"',
10
     // HOST: '"https://lt.pawoma.cn"',
11
     // WSS_HOST: '"wss://lt.pawoma.cn"',
11
     // WSS_HOST: '"wss://lt.pawoma.cn"',
12
-    HOST: '"http://127.0.0.1:8080"',
13
-    WSS_HOST: '"ws://127.0.0.1:8080"',
12
+    // HOST: '"http://127.0.0.1:8080"',
13
+    // WSS_HOST: '"ws://127.0.0.1:8080"',
14
   },
14
   },
15
   weapp: {},
15
   weapp: {},
16
   h5: {}
16
   h5: {}

+ 40
- 1
project.config.json 查看文件

23
 	"compileType": "miniprogram",
23
 	"compileType": "miniprogram",
24
 	"simulatorType": "wechat",
24
 	"simulatorType": "wechat",
25
 	"simulatorPluginLibVersion": {},
25
 	"simulatorPluginLibVersion": {},
26
-	"condition": {}
26
+	"condition": {
27
+		"search": {
28
+			"current": -1,
29
+			"list": []
30
+		},
31
+		"conversation": {
32
+			"current": -1,
33
+			"list": []
34
+		},
35
+		"plugin": {
36
+			"current": -1,
37
+			"list": []
38
+		},
39
+		"game": {
40
+			"list": []
41
+		},
42
+		"gamePlugin": {
43
+			"current": -1,
44
+			"list": []
45
+		},
46
+		"miniprogram": {
47
+			"current": -1,
48
+			"list": [
49
+				{
50
+					"id": -1,
51
+					"name": "pages/im/list/index",
52
+					"pathName": "pages/im/list/index",
53
+					"query": "",
54
+					"scene": null
55
+				},
56
+				{
57
+					"id": -1,
58
+					"name": "pages/activity/detail/assistance",
59
+					"pathName": "pages/activity/detail/assistance",
60
+					"query": "id=85",
61
+					"scene": null
62
+				}
63
+			]
64
+		}
65
+	}
27
 }
66
 }

+ 47
- 39
src/components/Poster/index.js 查看文件

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
+  static options = {
9
+    addGlobalClass: true,
10
+  }
11
+  static defaultProps = {
12
+    configs: {}
13
+  }
14
+
8
   state = {
15
   state = {
9
     images: [],
16
     images: [],
17
+    done: false,
10
     current: undefined,
18
     current: undefined,
11
-    configs: undefined,
19
+  }
20
+
21
+  static transTPLs2Configs(tpls, params) {
22
+    return tpls.map((tpl) => {
23
+      const conf = getCanvasConfig(tpl.configs, params)
24
+      return { ...conf }
25
+    })
12
   }
26
   }
13
 
27
 
14
   componentWillMount() {
28
   componentWillMount() {
15
-    if (!Array.isArray(this.props.tpls)) {
16
-      throw new Error('当前内容未维护海报信息')
29
+    if (!Array.isArray(this.props.configs)) {
30
+      throw new Error('未设置海报配置信息')
17
     }
31
     }
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
-    })
28
   }
32
   }
29
 
33
 
30
-  onScroll = inx => (e) => {
34
+  onScroll = (e) => {
35
+    const inx = e.detail.current
31
     this.setState({ current: this.state.images[inx] })
36
     this.setState({ current: this.state.images[inx] })
32
   }
37
   }
33
 
38
 
77
     })
82
     })
78
   }
83
   }
79
 
84
 
80
-  onCreateSuccess = (inx) => (result) => {
81
-    if (inx + 1 === this.props.tpls.length) {
82
-      Taro.hideLoading();
83
-    }
85
+  tmpImgs = []
84
 
86
 
85
-    let images = this.state.images || []
86
-    const { tempFilePath, errMsg } = result;
87
-    if (errMsg === 'canvasToTempFilePath:ok') {
88
-      images[inx] = tempFilePath
89
-    } else {
90
-      images[inx] = undefined
91
-      console.log(errMsg);
87
+  onCreateSuccess = (inx) => {
88
+    return (result) => {
89
+      const { tempFilePath, errMsg } = result;
90
+      if (errMsg === 'canvasToTempFilePath:ok') {
91
+        this.tmpImgs[inx] = tempFilePath
92
+      } else {
93
+        this.tmpImgs[inx] = undefined
94
+        console.log(errMsg);
95
+      }
96
+
97
+      if (inx + 1 === this.props.configs.length) {
98
+        this.setState({ done: true, images: [...this.tmpImgs] });
99
+        this.tmpImgs = [];
100
+        Taro.hideLoading();
101
+      }
92
     }
102
     }
93
-    this.setState({ images });
94
   }
103
   }
95
 
104
 
96
   onCreateFail = (inx) => (err) => {
105
   onCreateFail = (inx) => (err) => {
97
-    if (inx + 1 === this.props.tpls.length) {
106
+    this.tmpImgs[inx] = undefined
107
+    if (inx + 1 === this.props.configs.length) {
108
+      this.setState({ done: true, images: [...this.tmpImgs] });
109
+      this.tmpImgs = [];
98
       Taro.hideLoading();
110
       Taro.hideLoading();
99
     }
111
     }
100
-
101
-    let images = this.state.images || []
102
-    images[inx] = undefined
103
-    this.setState({ images });
104
     console.err(err);
112
     console.err(err);
105
   }
113
   }
106
 
114
 
107
   render() {
115
   render() {
108
-    const {
109
-      images,
110
-      configs
111
-    } = this.state
116
+    const { images, done } = this.state
117
+    const { configs } = this.props
112
 
118
 
113
     return (
119
     return (
114
       <View className="poster">
120
       <View className="poster">
118
             <Text className="iconfont icon-buoumaotubiao20" onClick={this.onCancel}></Text>
124
             <Text className="iconfont icon-buoumaotubiao20" onClick={this.onCancel}></Text>
119
           </View>
125
           </View>
120
           <View className="con-body">
126
           <View className="con-body">
127
+            <Swiper className="preview-box" onChange={this.onScroll} >
121
             {
128
             {
122
-              images.map((img, inx) => {
129
+              done && images.map((img, inx) => {
123
                 return (
130
                 return (
124
-                  <ScrollView scrollX scrollWithAnimation onScroll={this.onScroll(inx)} style="width: 100%" key={`img-${inx}`}>
131
+                  <SwiperItem key={`img-${inx}`}>
125
                     <Image className="result-img" mode="aspectFit" lazy-load src={img} onClick={this.onPreview}></Image>
132
                     <Image className="result-img" mode="aspectFit" lazy-load src={img} onClick={this.onPreview}></Image>
126
-                  </ScrollView>
133
+                  </SwiperItem>
127
                 )
134
                 )
128
               })
135
               })
129
             }
136
             }
137
+            </Swiper>
130
           </View>
138
           </View>
131
           <Button className="save-btn" onClick={this.saveToAlbum}>保存海报</Button>
139
           <Button className="save-btn" onClick={this.saveToAlbum}>保存海报</Button>
132
         </View>
140
         </View>
133
         {
141
         {
134
-          configs &&
142
+          !done && configs && configs.length &&
135
           (
143
           (
136
             configs.map((conf, inx) => {
144
             configs.map((conf, inx) => {
137
               return (
145
               return (

+ 7
- 2
src/components/Poster/style.scss 查看文件

43
       border-radius: 10px;
43
       border-radius: 10px;
44
       padding: 40px 0;
44
       padding: 40px 0;
45
 
45
 
46
-      .result-img {
46
+      .preview-box {
47
+        width: 100%;
47
         height: 60vh;
48
         height: 60vh;
48
-        display: block;
49
+      }
50
+
51
+      .result-img {
52
+        height: 100%;
49
         margin: 0 auto;
53
         margin: 0 auto;
54
+        display: inline-block;
50
       }
55
       }
51
     }
56
     }
52
   }
57
   }

+ 16
- 9
src/components/Poster/util.js 查看文件

9
   const itemConf = items.reduce((conf, item) => {
9
   const itemConf = items.reduce((conf, item) => {
10
     const { type, remark, value, variable, ...others } = item
10
     const { type, remark, value, variable, ...others } = item
11
     const settingOfType = conf[type] || []
11
     const settingOfType = conf[type] || []
12
-    
12
+    let val = variable ? params[variable] : value
13
+
13
     let mainVal = {}
14
     let mainVal = {}
14
     switch (type) {
15
     switch (type) {
15
-      case 'text':
16
-        mainVal = { text: variable ? params[variable] : value }
16
+      case 'texts':
17
+        mainVal = { text: val }
17
         break;
18
         break;
18
-      case 'image':
19
-        mainVal = { url: variable ? params[variable] : value }
19
+      case 'images':
20
+        mainVal = { url: val }
20
         break;
21
         break;
21
       default:
22
       default:
23
+        val = true
22
         break;
24
         break;
23
     }
25
     }
24
 
26
 
25
-    settingOfType.push({
26
-      ...mainVal,
27
-      ...others,
28
-    })
27
+    if (val) {
28
+      settingOfType.push({
29
+        ...mainVal,
30
+        ...others,
31
+      })
32
+      conf[type] = settingOfType
33
+    }
34
+    
35
+    return conf
29
   }, {})
36
   }, {})
30
 
37
 
31
   return {
38
   return {

+ 25
- 7
src/components/taro-plugin-canvas/index.js 查看文件

40
   }
40
   }
41
 
41
 
42
   componentDidMount() {
42
   componentDidMount() {
43
-    const sysInfo = Taro.getSystemInfoSync();
44
-    const screenWidth = sysInfo.screenWidth;
45
-    this.setState({
46
-      factor: screenWidth / 750
47
-    })
48
-    this.onCreate();
43
+    setTimeout(() => {
44
+      const sysInfo = Taro.getSystemInfoSync();
45
+      const screenWidth = sysInfo.screenWidth;
46
+      this.setState({
47
+        factor: screenWidth / 750
48
+      })
49
+      this.onCreate();
50
+    }, 0)
49
   }
51
   }
50
 
52
 
51
   componentWillUnmount() { }
53
   componentWillUnmount() { }
139
    */
141
    */
140
   initCanvas = (w, h, debug) => {
142
   initCanvas = (w, h, debug) => {
141
     return new Promise((resolve) => {
143
     return new Promise((resolve) => {
144
+      console.debug('-----------start to init canvas state------------')
142
       this.setState({
145
       this.setState({
143
         pxWidth: this.toPx(w),
146
         pxWidth: this.toPx(w),
144
         pxHeight: this.toPx(h),
147
         pxHeight: this.toPx(h),
145
         debug,
148
         debug,
146
-      }, resolve);
149
+      }, () => {
150
+        console.debug('-----------finish init canvas state------------')
151
+        resolve()
152
+      });
147
     });
153
     });
148
   }
154
   }
149
   /**
155
   /**
152
   onCreate = () => {
158
   onCreate = () => {
153
     const { onCreateFail, config } = this.props;
159
     const { onCreateFail, config } = this.props;
154
     Taro.showLoading({ mask: true, title: '生成中...' });
160
     Taro.showLoading({ mask: true, title: '生成中...' });
161
+    console.debug('-----start to download images---')
155
       return this.downloadResourceTransit()
162
       return this.downloadResourceTransit()
156
       .then(() => {
163
       .then(() => {
164
+        console.debug('-----finish download images---')
157
         this.create(config);
165
         this.create(config);
158
       })
166
       })
159
       .catch((err) => {
167
       .catch((err) => {
171
    * @param  { object } config
179
    * @param  { object } config
172
    */
180
    */
173
   create = (config) => {
181
   create = (config) => {
182
+    console.debug('-----create canvas---', this.canvasId, this.$scope)
174
     this.ctx = Taro.createCanvasContext(this.canvasId, this.$scope);
183
     this.ctx = Taro.createCanvasContext(this.canvasId, this.$scope);
184
+    console.debug('-----finish create canvas---')
175
     const height = getHeight(config);
185
     const height = getHeight(config);
186
+    console.debug('-----ready to init canvas---')
176
     this.initCanvas(config.width, height, config.debug)
187
     this.initCanvas(config.width, height, config.debug)
177
       .then(() => {
188
       .then(() => {
189
+        console.debug('-----finish init canvas---')
178
         // 设置画布底色
190
         // 设置画布底色
179
         if (config.backgroundColor) {
191
         if (config.backgroundColor) {
180
           this.ctx.save();
192
           this.ctx.save();
231
           // 在安卓平台,经测试发现如果海报过于复杂在转换时需要做延时,要不然样式会错乱
243
           // 在安卓平台,经测试发现如果海报过于复杂在转换时需要做延时,要不然样式会错乱
232
           time = 300;
244
           time = 300;
233
         }
245
         }
246
+        console.debug('-----start to draw---')
234
         this.ctx.draw(false, () => {
247
         this.ctx.draw(false, () => {
248
+          console.debug('-----finish draw---')
235
           setTimeout(() => {
249
           setTimeout(() => {
250
+            console.debug('-----ready to read file---')
236
             this.getTempFile();
251
             this.getTempFile();
237
           }, time);
252
           }, time);
238
         });
253
         });
248
     Taro.canvasToTempFilePath({
263
     Taro.canvasToTempFilePath({
249
       canvasId: this.canvasId,
264
       canvasId: this.canvasId,
250
       success: (result) => {
265
       success: (result) => {
266
+        console.debug('-----read file success---')
251
         if (!onCreateSuccess) {
267
         if (!onCreateSuccess) {
252
           console.warn('您必须实现 taro-plugin-canvas 组件的 onCreateSuccess 方法,详见文档 https://github.com/chuyun/taro-plugin-canvas#success');
268
           console.warn('您必须实现 taro-plugin-canvas 组件的 onCreateSuccess 方法,详见文档 https://github.com/chuyun/taro-plugin-canvas#success');
253
         }
269
         }
272
   }
288
   }
273
 
289
 
274
   render() {
290
   render() {
291
+    console.log('------render canvas----')
292
+
275
     const { pxWidth, pxHeight, debug } = this.state;
293
     const { pxWidth, pxHeight, debug } = this.state;
276
     if(pxWidth && pxHeight){
294
     if(pxWidth && pxHeight){
277
       return (
295
       return (

+ 86
- 26
src/pages/activity/detail/assemble.js 查看文件

52
     recordDetail: {}, // 发团记录
52
     recordDetail: {}, // 发团记录
53
     memberList: [], // 团员记录
53
     memberList: [], // 团员记录
54
     shares: [], // 分享设置
54
     shares: [], // 分享设置
55
-    posters: [], // 海报模板
55
+    posters: [],  // 海报设置
56
+    posterTpls: [], // 海报模板
56
     leftTime: 0,  // 剩余时间
57
     leftTime: 0,  // 剩余时间
57
     ltTicker: undefined,  // 剩余时间计时器
58
     ltTicker: undefined,  // 剩余时间计时器
58
     actState: ActBeforeStart,  // 活动本身状态
59
     actState: ActBeforeStart,  // 活动本身状态
76
   }
77
   }
77
 
78
 
78
   componentWillUnmount() {
79
   componentWillUnmount() {
79
-    this.clearTicker()
80
+    this.stopTicker()
80
     this.state.pointRecordId && updatePoint(pointRecordId)
81
     this.state.pointRecordId && updatePoint(pointRecordId)
81
   }
82
   }
82
 
83
 
84
+  componentDidShow() {
85
+    this.startTicker()
86
+  }
87
+  
88
+  componentDidHide() {
89
+    this.stopTicker()
90
+  }
91
+
83
   // 初始化页面数据
92
   // 初始化页面数据
84
   initPageData = () => {
93
   initPageData = () => {
85
     if (!this.state.detail.groupActivityId) {
94
     if (!this.state.detail.groupActivityId) {
98
     }
107
     }
99
   }
108
   }
100
 
109
 
110
+  // 启动 ticker
111
+  startTicker() {
112
+    if (this.state.ltTicker && !this.state.ltTicker.processing) {
113
+      this.state.ltTicker.start()
114
+    }
115
+  }
116
+
101
   // 清除 ticker
117
   // 清除 ticker
102
-  clearTicker() {
118
+  stopTicker() {
103
     if (this.state.ltTicker) {
119
     if (this.state.ltTicker) {
104
-      clearInterval(this.state.ltTicker)
105
-      this.setState({ ltTicker: undefined })
120
+      this.state.ltTicker.stop()
106
     }
121
     }
107
   }
122
   }
108
 
123
 
130
 
145
 
131
   // 打开关闭 ActionSheet 面板
146
   // 打开关闭 ActionSheet 面板
132
   toggleActionVisible = () => {
147
   toggleActionVisible = () => {
148
+    debugger
149
+    const { actionSheetVisible } = this.state
150
+
151
+    if (this.state.ltTicker) {
152
+      actionSheetVisible ? this.startTicker() : this.stopTicker()
153
+    }
154
+
133
     this.setState({
155
     this.setState({
134
-      actionSheetVisible: !this.state.actionSheetVisible
156
+      actionSheetVisible: !actionSheetVisible
135
     })
157
     })
136
   }
158
   }
137
 
159
 
138
   // 打开关闭海报面板
160
   // 打开关闭海报面板
139
   togglePosterVisible = () => {
161
   togglePosterVisible = () => {
162
+    const { posterVisible, posters } = this.state
163
+
164
+    if (!posters || !posters.length) {
165
+      Taro.showToast({
166
+        title: '未设置海报模板',
167
+        icon: 'none'
168
+      })
169
+      return
170
+    }
171
+
140
     this.setState({
172
     this.setState({
141
-      posterVisible: !this.state.posterVisible,
173
+      posterVisible: !posterVisible,
142
       actionSheetVisible: false
174
       actionSheetVisible: false
143
     })
175
     })
144
   }
176
   }
161
   }
193
   }
162
 
194
 
163
   // 计时器更新剩余时间
195
   // 计时器更新剩余时间
164
-  updateLeftTime(startDate, endDate) {
165
-    this.setState({
166
-      ltTicker: setInterval(() => {
167
-        const [actState, leftTime] = this.compActState(startDate, endDate)
168
-        this.setState({ actState, leftTime })
196
+  getLeftTimeTicker(startDate, endDate) {
197
+    let processing = false
198
+    let ticker = undefined
169
 
199
 
170
-        if (actState === ActFinished) {
171
-          this.clearTicker()
172
-        }
173
-      }, 1000)
174
-    })
200
+    const stop = () => {
201
+      ticker && clearInterval(ticker)
202
+      processing = false
203
+    }
204
+
205
+    const fn = () => {
206
+      const [actState, leftTime] = this.compActState(startDate, endDate)
207
+      this.setState({ actState, leftTime })
208
+
209
+      if (actState === ActFinished) {
210
+        stop()
211
+      }
212
+    }
213
+
214
+    const start = () => {
215
+      ticker = setInterval(fn, 1000)
216
+      processing = true
217
+    }
218
+
219
+    return {
220
+      start,
221
+      stop,
222
+      processing,
223
+    }
175
   }
224
   }
176
 
225
 
177
   loadDetail() {
226
   loadDetail() {
178
-    const { id, recordId } = this.state
227
+    let { id, recordId, ltTicker } = this.state
179
     const { userInfo } = this.props
228
     const { userInfo } = this.props
180
 
229
 
181
     Taro.showLoading()
230
     Taro.showLoading()
189
         actState = ActFinished
238
         actState = ActFinished
190
       }
239
       }
191
 
240
 
241
+      if (actState != ActFinished) {
242
+        ltTicker = this.getLeftTimeTicker(res.taShareActivity.startTime, res.taShareActivity.endTime)
243
+      }
244
+
192
       Taro.hideLoading()
245
       Taro.hideLoading()
193
       this.setState({
246
       this.setState({
194
         detail: res.taShareActivity,
247
         detail: res.taShareActivity,
203
         isStarter: !recordDetail.personId || userInfo.person.personId === recordDetail.personId,
256
         isStarter: !recordDetail.personId || userInfo.person.personId === recordDetail.personId,
204
         actState,
257
         actState,
205
         leftTime,
258
         leftTime,
206
-      })
207
-
208
-      if (actState != ActFinished) {
209
-        this.updateLeftTime(res.taShareActivity.startTime, res.taShareActivity.endTime)
210
-      }
259
+        ltTicker
260
+      }, () => this.startTicker())
211
 
261
 
212
       // Taro.setNavigationBarTitle({ title: res.taShareActivity.activityName })
262
       // Taro.setNavigationBarTitle({ title: res.taShareActivity.activityName })
213
 
263
 
378
     const [page, scene] = this.currentPageAndParams()
428
     const [page, scene] = this.currentPageAndParams()
379
     const payload = { page, scene }
429
     const payload = { page, scene }
380
 
430
 
381
-    getMiniQrcode(payload).then(qrCode => {
382
-      this.setState({ qrCode, posterVisible: true })
431
+    return new Promise((resolve) => {
432
+      getMiniQrcode(payload).then(qrCode => {
433
+        this.setState({ qrCode, posterVisible: true }, resolve)
434
+      })
383
     })
435
     })
384
   }
436
   }
385
 
437
 
407
       posters,
459
       posters,
408
       qrCode,
460
       qrCode,
409
       leftTime,
461
       leftTime,
462
+      ltTicker,
410
     } = this.state
463
     } = this.state
411
 
464
 
412
     const { userInfo } = this.props
465
     const { userInfo } = this.props
424
 
477
 
425
     const joinedNum = detail.groupBuyPeople - (recordDetail.recordId ? 1 : 0) - memberList.length
478
     const joinedNum = detail.groupBuyPeople - (recordDetail.recordId ? 1 : 0) - memberList.length
426
 
479
 
480
+    const posterConfigs = Poster.transTPLs2Configs(posterTpls, posterData)
481
+
482
+    console.log('------posterConfigs------', posterConfigs)
427
     return (
483
     return (
428
       <Block>
484
       <Block>
429
         {/* 生成海报 */}
485
         {/* 生成海报 */}
430
-        {posterVisible && (<Poster tpls={posterTpls} params={posterData} onCancel={this.togglePosterVisible} onFinish={this.togglePosterVisible}></Poster>)}
486
+        { posterVisible && !ltTicker.processing &&
487
+          (
488
+            <Poster configs={posterConfigs} onCancel={this.togglePosterVisible} onFinish={this.togglePosterVisible}></Poster>
489
+          )
490
+        }
431
 
491
 
432
         {
492
         {
433
           grantPhoneVisible &&
493
           grantPhoneVisible &&

+ 90
- 32
src/pages/activity/detail/assistance.js 查看文件

64
     handleHelpBtn: true, // 立即助力好友
64
     handleHelpBtn: true, // 立即助力好友
65
     pointRecordId: undefined, // 埋点ID
65
     pointRecordId: undefined, // 埋点ID
66
   }
66
   }
67
-
67
+  
68
   componentWillMount() {
68
   componentWillMount() {
69
     ready.queue(() => {
69
     ready.queue(() => {
70
       // 必须先授权电话
70
       // 必须先授权电话
75
   }
75
   }
76
 
76
 
77
   componentWillUnmount() {
77
   componentWillUnmount() {
78
-    this.clearTicker()
78
+    this.stopTicker()
79
     this.state.pointRecordId && updatePoint(pointRecordId)
79
     this.state.pointRecordId && updatePoint(pointRecordId)
80
   }
80
   }
81
 
81
 
82
+  componentDidShow() {
83
+    this.startTicker()
84
+  }
85
+  
86
+  componentDidHide() {
87
+    this.stopTicker()
88
+  }
89
+
82
   // 初始化页面数据
90
   // 初始化页面数据
83
   initPageData = () => {
91
   initPageData = () => {
84
     if (!this.state.detail.helpActivityId) {
92
     if (!this.state.detail.helpActivityId) {
97
     }
105
     }
98
   }
106
   }
99
 
107
 
108
+  // 启动 ticker
109
+  startTicker() {
110
+    if (this.state.ltTicker && !this.state.ltTicker.processing) {
111
+      this.state.ltTicker.start()
112
+    }
113
+  }
114
+
100
   // 清除 ticker
115
   // 清除 ticker
101
-  clearTicker() {
116
+  stopTicker() {
102
     if (this.state.ltTicker) {
117
     if (this.state.ltTicker) {
103
-      clearInterval(this.state.ltTicker)
104
-      this.setState({ ltTicker: undefined })
118
+      this.state.ltTicker.stop()
105
     }
119
     }
106
   }
120
   }
107
 
121
 
129
 
143
 
130
   // 打开关闭 ActionSheet 面板
144
   // 打开关闭 ActionSheet 面板
131
   toggleActionVisible = () => {
145
   toggleActionVisible = () => {
146
+    debugger
147
+    const { actionSheetVisible } = this.state
148
+
149
+    if (this.state.ltTicker) {
150
+      actionSheetVisible ? this.startTicker() : this.stopTicker()
151
+    }
152
+
132
     this.setState({
153
     this.setState({
133
-      actionSheetVisible: !this.state.actionSheetVisible
154
+      actionSheetVisible: !actionSheetVisible
134
     })
155
     })
135
   }
156
   }
136
 
157
 
137
   // 打开关闭海报面板
158
   // 打开关闭海报面板
138
   togglePosterVisible = () => {
159
   togglePosterVisible = () => {
160
+    const { posterVisible, posters } = this.state
161
+    
162
+    if (!posters || !posters.length) {
163
+      Taro.showToast({
164
+        title: '未设置海报模板',
165
+        icon: 'none'
166
+      })
167
+      return
168
+    }
169
+
139
     this.setState({
170
     this.setState({
140
-      posterVisible: !this.state.posterVisible,
171
+      posterVisible: !posterVisible,
141
       actionSheetVisible: false
172
       actionSheetVisible: false
142
     })
173
     })
143
   }
174
   }
160
   }
191
   }
161
 
192
 
162
   // 计时器更新剩余时间
193
   // 计时器更新剩余时间
163
-  updateLeftTime(startDate, endDate) {
164
-    this.setState({
165
-      ltTicker: setInterval(() => {
166
-        const [actState, leftTime] = this.compActState(startDate, endDate)
167
-        this.setState({ actState, leftTime })
194
+  getLeftTimeTicker(startDate, endDate) {
195
+    let processing = false
196
+    let ticker = undefined
168
 
197
 
169
-        if (actState === ActFinished) {
170
-          this.clearTicker()
171
-        }
172
-      }, 1000)
173
-    })
198
+    const stop = () => {
199
+      ticker && clearInterval(ticker)
200
+      processing = false
201
+    }
202
+
203
+    const fn = () => {
204
+      const [actState, leftTime] = this.compActState(startDate, endDate)
205
+      this.setState({ actState, leftTime })
206
+
207
+      if (actState === ActFinished) {
208
+        stop()
209
+      }
210
+    }
211
+
212
+    const start = () => {
213
+      ticker = setInterval(fn, 1000)
214
+      processing = true
215
+    }
216
+
217
+    return {
218
+      start,
219
+      stop,
220
+      processing,
221
+    }
174
   }
222
   }
175
 
223
 
176
   // 请求详情
224
   // 请求详情
177
   loadDetail() {
225
   loadDetail() {
178
-    // debugger
179
-    const { id, initiateId } = this.state
226
+    let { id, initiateId, ltTicker } = this.state
180
     const { userInfo } = this.props
227
     const { userInfo } = this.props
181
 
228
 
182
     Taro.showLoading()
229
     Taro.showLoading()
183
     getHelpDetail(id, initiateId).then(res => {
230
     getHelpDetail(id, initiateId).then(res => {
184
-      this.clearTicker()
231
+      this.stopTicker()
185
 
232
 
186
       const initiateDetail = res.helpInitiateRecord || {}
233
       const initiateDetail = res.helpInitiateRecord || {}
187
       let [actState, leftTime] = this.compActState(res.helpActivity.startDate, res.helpActivity.endDate)
234
       let [actState, leftTime] = this.compActState(res.helpActivity.startDate, res.helpActivity.endDate)
190
         actState = ActFinished
237
         actState = ActFinished
191
       }
238
       }
192
 
239
 
240
+      if (actState != ActFinished) {
241
+        ltTicker = this.getLeftTimeTicker(res.helpActivity.startDate, res.helpActivity.endDate)
242
+      }
243
+
193
       Taro.hideLoading()
244
       Taro.hideLoading()
194
       this.setState({
245
       this.setState({
195
         detail: res.helpActivity,
246
         detail: res.helpActivity,
204
         isStarter: !initiateDetail.personId || userInfo.person.personId === initiateDetail.personId,
255
         isStarter: !initiateDetail.personId || userInfo.person.personId === initiateDetail.personId,
205
         actState,
256
         actState,
206
         leftTime,
257
         leftTime,
207
-        isJoin: res.isJoin
208
-      })
209
-
210
-      if (actState != ActFinished) {
211
-        this.updateLeftTime(res.helpActivity.startDate, res.helpActivity.endDate)
212
-      }
258
+        isJoin: res.isJoin,
259
+        ltTicker
260
+      }, () => this.startTicker())
213
 
261
 
214
       // Taro.setNavigationBarTitle({ title: res.helpActivity.title })
262
       // Taro.setNavigationBarTitle({ title: res.helpActivity.title })
215
 
263
 
366
     // 必须授权头像
414
     // 必须授权头像
367
     if (this.toggleGrantAvatar()) {
415
     if (this.toggleGrantAvatar()) {
368
       const initiateDetail = this.state.initiateDetail
416
       const initiateDetail = this.state.initiateDetail
369
-      // debugger
370
       if (!initiateDetail.helpRecordInitiateId) {
417
       if (!initiateDetail.helpRecordInitiateId) {
371
         // 如果是未发起的助力, 先以当前人身份发起
418
         // 如果是未发起的助力, 先以当前人身份发起
372
         this.startMine().then(() => {
419
         this.startMine().then(() => {
382
     const [page, scene] = this.currentPageAndParams()
429
     const [page, scene] = this.currentPageAndParams()
383
     const payload = { page, scene }
430
     const payload = { page, scene }
384
 
431
 
385
-    getMiniQrcode(payload).then(qrCode => {
386
-      this.setState({ qrCode, posterVisible: true })
432
+    return new Promise((resolve) => {
433
+      getMiniQrcode(payload).then(qrCode => {
434
+        this.setState({ qrCode }, resolve)
435
+      })
387
     })
436
     })
388
   }
437
   }
389
 
438
 
411
       posters,
460
       posters,
412
       qrCode,
461
       qrCode,
413
       leftTime,
462
       leftTime,
463
+      ltTicker,
414
     } = this.state
464
     } = this.state
415
 
465
 
416
     const { userInfo } = this.props
466
     const { userInfo } = this.props
424
       avatarurl: getDownloadURL(userInfo.person.avatarurl, 'avatar') || '',
474
       avatarurl: getDownloadURL(userInfo.person.avatarurl, 'avatar') || '',
425
     }
475
     }
426
 
476
 
477
+    const posterConfigs = Poster.transTPLs2Configs(posterTpls, posterData)
478
+
479
+    console.log('------posterConfigs------', posterConfigs)
480
+
427
     return (
481
     return (
428
-      <Block>
482
+      <View>
429
         {/* 生成海报 */}
483
         {/* 生成海报 */}
430
-        {posterVisible && (<Poster tpls={posterTpls} params={posterData} onCancel={this.togglePosterVisible} onFinish={this.togglePosterVisible}></Poster>)}
484
+        { posterVisible && !ltTicker.processing &&
485
+          (
486
+            <Poster configs={posterConfigs} onCancel={this.togglePosterVisible} onFinish={this.togglePosterVisible}></Poster>
487
+          )
488
+        }
431
 
489
 
432
         {
490
         {
433
           grantPhoneVisible &&
491
           grantPhoneVisible &&
553
             </View>
611
             </View>
554
           )
612
           )
555
         }
613
         }
556
-      </Block>
614
+      </View>
557
     )
615
     )
558
   }
616
   }
559
 }
617
 }

+ 1
- 0
src/pages/project/detail/poster.js 查看文件

27
     }
27
     }
28
   }
28
   }
29
   componentWillMount() {
29
   componentWillMount() {
30
+    debugger
30
     this.initConfig()
31
     this.initConfig()
31
     Taro.showLoading({
32
     Taro.showLoading({
32
       title: '生成中...',
33
       title: '生成中...',