张延森 5 년 전
부모
커밋
e0ab54ca0f
2개의 변경된 파일35개의 추가작업 그리고 0개의 파일을 삭제
  1. 0
    0
      src/components/Poster/index.js
  2. 35
    0
      src/components/Poster/util.js

+ 0
- 0
src/components/Poster/index.js 파일 보기


+ 35
- 0
src/components/Poster/util.js 파일 보기

@@ -0,0 +1,35 @@
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
+    
13
+    let mainVal = {}
14
+    switch (type) {
15
+      case 'text':
16
+        mainVal = { text: variable ? params[variable] : value }
17
+        break;
18
+      case 'image':
19
+        mainVal = { url: variable ? params[variable] : value }
20
+        break;
21
+      default:
22
+        break;
23
+    }
24
+
25
+    settingOfType.push({
26
+      ...mainVal,
27
+      ...others,
28
+    })
29
+  }, {})
30
+
31
+  return {
32
+    ...basic,
33
+    ...itemConf,
34
+  }
35
+}