张延森 5 年之前
父節點
當前提交
1038ff5f30

+ 0
- 15
src/components/Poster/index.js 查看文件

1
 import Taro, { Component } from '@tarojs/taro';
1
 import Taro, { Component } from '@tarojs/taro';
2
 import { ScrollView, View, Block } 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 { getCanvasConfig } from './util';
5
 import './style.scss';
4
 import './style.scss';
6
 
5
 
7
 export default class Poster extends Component {
6
 export default class Poster extends Component {
8
-  static options = {
9
-    addGlobalClass: true,
10
-  }
11
-  static defaultProps = {
12
-    configs: {}
13
-  }
14
-
15
   state = {
7
   state = {
16
     images: [],
8
     images: [],
17
     done: false,
9
     done: false,
18
     current: undefined,
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
   componentWillMount() {
13
   componentWillMount() {
29
     if (!Array.isArray(this.props.configs)) {
14
     if (!Array.isArray(this.props.configs)) {
30
       throw new Error('未设置海报配置信息')
15
       throw new Error('未设置海报配置信息')

+ 0
- 42
src/components/Poster/util.js 查看文件

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 查看文件

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'
10
 import ready from '@utils/ready'
10
 import ready from '@utils/ready'
11
-import { getDownloadURL, times, formateLeftTime } from '@utils/tools'
11
+import { getDownloadURL, times, formateLeftTime, getCanvasConfig } from '@utils/tools'
12
 import {
12
 import {
13
   getGroupDetail,
13
   getGroupDetail,
14
   createGroupActivity,
14
   createGroupActivity,
444
       this.togglePosterVisible()
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
   render() {
456
   render() {
449
     const {
457
     const {
480
 
488
 
481
     const joinedNum = detail.groupBuyPeople - (recordDetail.recordId ? 1 : 0) - memberList.length
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
     console.log('------posterConfigs------', posterConfigs)
493
     console.log('------posterConfigs------', posterConfigs)
486
     return (
494
     return (

+ 9
- 2
src/pages/activity/detail/assistance.js 查看文件

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'
10
 import ready from '@utils/ready'
10
 import ready from '@utils/ready'
11
-import { getDownloadURL, times, formateLeftTime } from '@utils/tools'
11
+import { getDownloadURL, times, formateLeftTime, getCanvasConfig } from '@utils/tools'
12
 import {
12
 import {
13
   getHelpDetail,
13
   getHelpDetail,
14
   createHelpActivity,
14
   createHelpActivity,
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
   render() {
456
   render() {
450
     const {
457
     const {
451
       initiateId,
458
       initiateId,
477
       avatarurl: getDownloadURL(userInfo.person.avatarurl, 'avatar') || '',
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
     console.log('------posterConfigs------', posterConfigs)
489
     console.log('------posterConfigs------', posterConfigs)
483
     const isJoin = helpList.filter(x => x.personId === userInfo.person.personId)[0] || isStarter
490
     const isJoin = helpList.filter(x => x.personId === userInfo.person.personId)[0] || isStarter

+ 48
- 1
src/utils/tools.js 查看文件

413
 export const isEmail = function (value) {
413
 export const isEmail = function (value) {
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,}))$/;
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
   return re.test(value);
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
+}