|
@@ -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
|
+}
|