张延森 5 years ago
parent
commit
1038ff5f30

+ 0
- 15
src/components/Poster/index.js View File

@@ -1,30 +1,15 @@
1 1
 import Taro, { Component } from '@tarojs/taro';
2 2
 import { ScrollView, View, Block } from '@tarojs/components';
3 3
 import { TaroCanvasDrawer } from '@components/taro-plugin-canvas';
4
-import { getCanvasConfig } from './util';
5 4
 import './style.scss';
6 5
 
7 6
 export default class Poster extends Component {
8
-  static options = {
9
-    addGlobalClass: true,
10
-  }
11
-  static defaultProps = {
12
-    configs: {}
13
-  }
14
-
15 7
   state = {
16 8
     images: [],
17 9
     done: false,
18 10
     current: undefined,
19 11
   }
20 12
 
21
-  static transTPLs2Configs(tpls, params) {
22
-    return tpls.map((tpl) => {
23
-      const conf = getCanvasConfig(tpl.configs, params)
24
-      return { ...conf }
25
-    })
26
-  }
27
-
28 13
   componentWillMount() {
29 14
     if (!Array.isArray(this.props.configs)) {
30 15
       throw new Error('未设置海报配置信息')

+ 0
- 42
src/components/Poster/util.js View File

@@ -1,42 +0,0 @@
1
-
2
-export function getCanvasConfig(config, params) {
3
-  if (!config || !params) {
4
-    throw new Error('转换海报配置出错: config 或 params 不能为空')
5
-  }
6
-
7
-  const { basic, items } = typeof config === 'string' ? JSON.parse(config) : config
8
-
9
-  const itemConf = items.reduce((conf, item) => {
10
-    const { type, remark, value, variable, ...others } = item
11
-    const settingOfType = conf[type] || []
12
-    let val = variable ? params[variable] : value
13
-
14
-    let mainVal = {}
15
-    switch (type) {
16
-      case 'texts':
17
-        mainVal = { text: val }
18
-        break;
19
-      case 'images':
20
-        mainVal = { url: val }
21
-        break;
22
-      default:
23
-        val = true
24
-        break;
25
-    }
26
-
27
-    if (val) {
28
-      settingOfType.push({
29
-        ...mainVal,
30
-        ...others,
31
-      })
32
-      conf[type] = settingOfType
33
-    }
34
-    
35
-    return conf
36
-  }, {})
37
-
38
-  return {
39
-    ...basic,
40
-    ...itemConf,
41
-  }
42
-}

+ 10
- 2
src/pages/activity/detail/assemble.js View File

@@ -8,7 +8,7 @@ import dayjs from 'dayjs'
8 8
 // import WxParse from '@components/wxParse/wxParse'
9 9
 // import getUserPhone from '@utils/getUserPhone'
10 10
 import ready from '@utils/ready'
11
-import { getDownloadURL, times, formateLeftTime } from '@utils/tools'
11
+import { getDownloadURL, times, formateLeftTime, getCanvasConfig } from '@utils/tools'
12 12
 import {
13 13
   getGroupDetail,
14 14
   createGroupActivity,
@@ -444,6 +444,14 @@ export default class Detail extends Component {
444 444
       this.togglePosterVisible()
445 445
     })
446 446
   }
447
+  
448
+  transTPLs2Configs(tpls, params) {
449
+    return tpls.map((tpl) => {
450
+      const conf = getCanvasConfig(tpl.configs, params)
451
+      return { ...conf }
452
+    })
453
+  }
454
+
447 455
 
448 456
   render() {
449 457
     const {
@@ -480,7 +488,7 @@ export default class Detail extends Component {
480 488
 
481 489
     const joinedNum = detail.groupBuyPeople - (recordDetail.recordId ? 1 : 0) - memberList.length
482 490
 
483
-    const posterConfigs = Poster.transTPLs2Configs(posterTpls, posterData)
491
+    const posterConfigs = this.transTPLs2Configs(posterTpls, posterData)
484 492
 
485 493
     console.log('------posterConfigs------', posterConfigs)
486 494
     return (

+ 9
- 2
src/pages/activity/detail/assistance.js View File

@@ -8,7 +8,7 @@ import dayjs from 'dayjs'
8 8
 // import WxParse from '@components/wxParse/wxParse'
9 9
 // import getUserPhone from '@utils/getUserPhone'
10 10
 import ready from '@utils/ready'
11
-import { getDownloadURL, times, formateLeftTime } from '@utils/tools'
11
+import { getDownloadURL, times, formateLeftTime, getCanvasConfig } from '@utils/tools'
12 12
 import {
13 13
   getHelpDetail,
14 14
   createHelpActivity,
@@ -446,6 +446,13 @@ export default class Detail extends Component {
446 446
     })
447 447
   }
448 448
 
449
+  transTPLs2Configs(tpls, params) {
450
+    return tpls.map((tpl) => {
451
+      const conf = getCanvasConfig(tpl.configs, params)
452
+      return { ...conf }
453
+    })
454
+  }
455
+
449 456
   render() {
450 457
     const {
451 458
       initiateId,
@@ -477,7 +484,7 @@ export default class Detail extends Component {
477 484
       avatarurl: getDownloadURL(userInfo.person.avatarurl, 'avatar') || '',
478 485
     }
479 486
 
480
-    const posterConfigs = Poster.transTPLs2Configs(posterTpls, posterData)
487
+    const posterConfigs = this.transTPLs2Configs(posterTpls, posterData)
481 488
 
482 489
     console.log('------posterConfigs------', posterConfigs)
483 490
     const isJoin = helpList.filter(x => x.personId === userInfo.person.personId)[0] || isStarter

+ 48
- 1
src/utils/tools.js View File

@@ -413,4 +413,51 @@ export const isChineseMobilePhoneNumber = function (phoneNumber, strict) {
413 413
 export const isEmail = function (value) {
414 414
   var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
415 415
   return re.test(value);
416
-}
416
+}
417
+
418
+/**
419
+ * 转换海报的数据库配置为可用配置
420
+ * @param {*} config 
421
+ * @param {*} params 
422
+ */
423
+export function getCanvasConfig(config, params) {
424
+  if (!config || !params) {
425
+    throw new Error('转换海报配置出错: config 或 params 不能为空')
426
+  }
427
+
428
+  const { basic, items } = typeof config === 'string' ? JSON.parse(config) : config
429
+
430
+  const itemConf = items.reduce((conf, item) => {
431
+    const { type, remark, value, variable, ...others } = item
432
+    const settingOfType = conf[type] || []
433
+    let val = variable ? params[variable] : value
434
+
435
+    let mainVal = {}
436
+    switch (type) {
437
+      case 'texts':
438
+        mainVal = { text: val }
439
+        break;
440
+      case 'images':
441
+        mainVal = { url: val }
442
+        break;
443
+      default:
444
+        val = true
445
+        break;
446
+    }
447
+
448
+    if (val) {
449
+      settingOfType.push({
450
+        ...mainVal,
451
+        ...others,
452
+      })
453
+      conf[type] = settingOfType
454
+    }
455
+    
456
+    return conf
457
+  }, {})
458
+
459
+  return {
460
+    ...basic,
461
+    ...itemConf,
462
+  }
463
+}