tianheng-ui 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/theme-chalk/styles/reset.scss +0 -2
- package/lib/tianheng-ui.js +13 -14
- package/package.json +1 -1
- package/packages/FormMaking/GenerateForm.vue +16 -11
- package/packages/FormMaking/GenerateFormItem.vue +73 -581
- package/packages/FormMaking/GenerateFormItemH5.vue +6 -6
- package/packages/FormMaking/Upload/index.vue +0 -1
- package/packages/FormMaking/WidgetConfig.vue +100 -77
- package/packages/FormMaking/WidgetForm.vue +7 -48
- package/packages/FormMaking/WidgetFormItem.vue +41 -65
- package/packages/FormMaking/WidgetSelect.vue +160 -0
- package/packages/FormMaking/WidgetTools.vue +538 -0
- package/packages/FormMaking/config/index.js +6 -0
- package/packages/FormMaking/custom/config.js +119 -87
- package/packages/FormMaking/custom/configs/button.vue +24 -25
- package/packages/FormMaking/custom/configs/cascader.vue +7 -7
- package/packages/FormMaking/custom/configs/checkbox.vue +23 -22
- package/packages/FormMaking/custom/configs/color.vue +3 -3
- package/packages/FormMaking/custom/configs/date.vue +3 -3
- package/packages/FormMaking/custom/configs/grid.vue +4 -4
- package/packages/FormMaking/custom/configs/input.vue +138 -31
- package/packages/FormMaking/custom/configs/number.vue +5 -5
- package/packages/FormMaking/custom/configs/radio.vue +23 -19
- package/packages/FormMaking/custom/configs/rate.vue +3 -3
- package/packages/FormMaking/custom/configs/select.vue +25 -20
- package/packages/FormMaking/custom/configs/slider.vue +3 -3
- package/packages/FormMaking/custom/configs/switch.vue +3 -3
- package/packages/FormMaking/custom/configs/table.vue +2 -2
- package/packages/FormMaking/custom/configs/{table_h5.vue → tableH5.vue} +2 -2
- package/packages/FormMaking/custom/configs/tabs.vue +18 -23
- package/packages/FormMaking/custom/configs/textarea.vue +124 -22
- package/packages/FormMaking/custom/configs/time.vue +3 -3
- package/packages/FormMaking/custom/configs/upload.vue +5 -5
- package/packages/FormMaking/custom/index.js +2 -4
- package/packages/FormMaking/custom/items/alliance.vue +30 -29
- package/packages/FormMaking/custom/items/blank_pro.vue +14 -0
- package/packages/FormMaking/custom/items/button.vue +36 -1
- package/packages/FormMaking/custom/items/cascader.vue +6 -2
- package/packages/FormMaking/custom/items/cell.vue +0 -2
- package/packages/FormMaking/custom/items/checkbox.vue +18 -8
- package/packages/FormMaking/custom/items/color.vue +1 -1
- package/packages/FormMaking/custom/items/date.vue +1 -1
- package/packages/FormMaking/custom/items/editor.vue +1 -1
- package/packages/FormMaking/custom/items/{grid.vue → grid_dev.vue} +16 -47
- package/packages/FormMaking/custom/items/grid_pro.vue +45 -0
- package/packages/FormMaking/custom/items/image.vue +0 -28
- package/packages/FormMaking/custom/items/input.vue +15 -9
- package/packages/FormMaking/custom/items/number.vue +4 -4
- package/packages/FormMaking/custom/items/radio.vue +17 -7
- package/packages/FormMaking/custom/items/rate.vue +1 -1
- package/packages/FormMaking/custom/items/select.vue +12 -6
- package/packages/FormMaking/custom/items/slider.vue +1 -1
- package/packages/FormMaking/custom/items/switch.vue +1 -1
- package/packages/FormMaking/custom/items/{table_h5.vue → tableH5_dev.vue} +44 -49
- package/packages/FormMaking/custom/items/tableH5_pro.vue +113 -0
- package/packages/FormMaking/custom/items/{table.vue → table_dev.vue} +21 -41
- package/packages/FormMaking/custom/items/table_pro.vue +114 -0
- package/packages/FormMaking/custom/items/tabs_dev.vue +101 -0
- package/packages/FormMaking/custom/items/tabs_pro.vue +50 -0
- package/packages/FormMaking/custom/items/text.vue +1 -1
- package/packages/FormMaking/custom/items/textarea.vue +4 -13
- package/packages/FormMaking/custom/items/time.vue +3 -3
- package/packages/FormMaking/custom/items/upload.vue +15 -14
- package/packages/FormMaking/custom/mixins/index.js +28 -6
- package/packages/FormMaking/custom/register.js +22 -11
- package/packages/FormMaking/index.vue +95 -468
- package/packages/FormMaking/styles/index.scss +235 -242
- package/packages/FormMaking/util/generateCode.js +3 -3
- package/packages/FormMaking/util/index.js +33 -23
- package/packages/FormMaking/util/request.js +9 -12
- package/packages/FormMaking/custom/items/tabs.vue +0 -145
- /package/packages/FormMaking/custom/items/{blank.vue → blank_dev.vue} +0 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
<template>
|
2
|
+
<div
|
3
|
+
v-if="selectWidget.model == widget.model"
|
4
|
+
class="widget-actions"
|
5
|
+
:class="{
|
6
|
+
'widget-actions_layout': [
|
7
|
+
'grid',
|
8
|
+
'tabs',
|
9
|
+
'table',
|
10
|
+
'tableH5',
|
11
|
+
'alliance'
|
12
|
+
].includes(widget.type)
|
13
|
+
}"
|
14
|
+
>
|
15
|
+
<div class="actions">
|
16
|
+
<i class="iconfont icon-icon_clone" @click.stop="handleWidgetClone"></i>
|
17
|
+
<i class="iconfont icon-trash" @click.stop="handleWidgetDelete"></i>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div class="drag">
|
21
|
+
<i class="iconfont icon-drag drag-widget"></i>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
</template>
|
25
|
+
|
26
|
+
<script>
|
27
|
+
export default {
|
28
|
+
props: ["widgetArray", "widgetIndex", "widget", "select"],
|
29
|
+
data() {
|
30
|
+
return {
|
31
|
+
selectWidget: this.select
|
32
|
+
};
|
33
|
+
},
|
34
|
+
watch: {
|
35
|
+
select(val) {
|
36
|
+
this.selectWidget = val;
|
37
|
+
},
|
38
|
+
selectWidget: {
|
39
|
+
handler(val) {
|
40
|
+
this.$emit("update:select", val);
|
41
|
+
},
|
42
|
+
deep: true
|
43
|
+
}
|
44
|
+
},
|
45
|
+
created() {},
|
46
|
+
mounted() {},
|
47
|
+
methods: {
|
48
|
+
handleWidgetDelete() {
|
49
|
+
if (this.widgetArray.length - 1 === this.widgetIndex) {
|
50
|
+
if (this.widgetIndex === 0) {
|
51
|
+
this.selectWidget = {};
|
52
|
+
} else {
|
53
|
+
this.selectWidget = this.widgetArray[this.widgetIndex - 1];
|
54
|
+
}
|
55
|
+
} else {
|
56
|
+
this.selectWidget = this.widgetArray[this.widgetIndex + 1];
|
57
|
+
}
|
58
|
+
|
59
|
+
this.$nextTick(() => {
|
60
|
+
this.widgetArray.splice(this.widgetIndex, 1);
|
61
|
+
});
|
62
|
+
},
|
63
|
+
|
64
|
+
handleWidgetClone() {
|
65
|
+
const data = JSON.parse(
|
66
|
+
JSON.stringify(this.widgetArray[this.widgetIndex])
|
67
|
+
);
|
68
|
+
|
69
|
+
const initKey = item => {
|
70
|
+
const key = `${Date.parse(new Date().toString())}_${Math.ceil(
|
71
|
+
Math.random() * 99999
|
72
|
+
)}`;
|
73
|
+
|
74
|
+
item.key = key;
|
75
|
+
item.options.remoteFunc = `func__${key}`;
|
76
|
+
item.model = `${item.type}_${key}`;
|
77
|
+
|
78
|
+
if (["table", "tableH5"].includes(item.type)) {
|
79
|
+
item.list.forEach(element => {
|
80
|
+
initKey(element);
|
81
|
+
});
|
82
|
+
}
|
83
|
+
if (["tabs"].includes(item.type)) {
|
84
|
+
item.options.columns.forEach(tab => {
|
85
|
+
tab.forEach(element => {
|
86
|
+
initKey(element);
|
87
|
+
});
|
88
|
+
});
|
89
|
+
}
|
90
|
+
if (["grid"].includes(item.type)) {
|
91
|
+
item.options.columns.forEach(column => {
|
92
|
+
column.list.forEach(element => {
|
93
|
+
initKey(element);
|
94
|
+
});
|
95
|
+
});
|
96
|
+
}
|
97
|
+
};
|
98
|
+
initKey(data);
|
99
|
+
|
100
|
+
this.widgetArray.splice(this.widgetIndex, 0, data);
|
101
|
+
this.selectWidget = data;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
};
|
105
|
+
</script>
|
106
|
+
|
107
|
+
<style lang="scss" scoped>
|
108
|
+
$primary-color: #409eff;
|
109
|
+
$primary-background-color: #ecf5ff;
|
110
|
+
.widget-actions {
|
111
|
+
position: absolute;
|
112
|
+
left: 0;
|
113
|
+
top: 0;
|
114
|
+
width: 100%;
|
115
|
+
height: 100%;
|
116
|
+
.actions {
|
117
|
+
position: absolute;
|
118
|
+
right: 0;
|
119
|
+
bottom: 0;
|
120
|
+
height: 28px;
|
121
|
+
line-height: 28px;
|
122
|
+
background: $primary-color;
|
123
|
+
z-index: 9;
|
124
|
+
|
125
|
+
i {
|
126
|
+
font-size: 14px;
|
127
|
+
color: #fff;
|
128
|
+
margin: 0 5px;
|
129
|
+
cursor: pointer;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
.drag {
|
134
|
+
position: absolute;
|
135
|
+
left: -2px;
|
136
|
+
bottom: -2px;
|
137
|
+
height: 28px;
|
138
|
+
line-height: 28px;
|
139
|
+
background: $primary-color;
|
140
|
+
z-index: 9;
|
141
|
+
|
142
|
+
i {
|
143
|
+
font-size: 14px;
|
144
|
+
color: #fff;
|
145
|
+
margin: 0 5px;
|
146
|
+
cursor: move;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
.widget-actions_layout {
|
152
|
+
.actions {
|
153
|
+
background: #e6a23c;
|
154
|
+
}
|
155
|
+
|
156
|
+
.drag {
|
157
|
+
background: #e6a23c;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
</style>
|
@@ -0,0 +1,538 @@
|
|
1
|
+
<template>
|
2
|
+
<div class="widgetTools">
|
3
|
+
<div class="left">
|
4
|
+
<el-button
|
5
|
+
v-if="permissions.includes('monitor')"
|
6
|
+
:class="{ active: client === 'monitor' }"
|
7
|
+
type="text"
|
8
|
+
size="medium"
|
9
|
+
icon="el-icon-monitor"
|
10
|
+
@click="handleClick('monitor')"
|
11
|
+
>
|
12
|
+
</el-button>
|
13
|
+
<el-button
|
14
|
+
v-if="permissions.includes('mobile')"
|
15
|
+
:class="{ active: client === 'mobile' }"
|
16
|
+
type="text"
|
17
|
+
size="medium"
|
18
|
+
icon="el-icon-mobile"
|
19
|
+
@click="handleClick('mobile')"
|
20
|
+
>
|
21
|
+
</el-button>
|
22
|
+
</div>
|
23
|
+
<div class="right">
|
24
|
+
<slot> </slot>
|
25
|
+
|
26
|
+
<el-button
|
27
|
+
v-if="permissions.includes('clearable')"
|
28
|
+
style="margin-left:10px;"
|
29
|
+
type="text"
|
30
|
+
size="medium"
|
31
|
+
icon="el-icon-delete"
|
32
|
+
@click="handleClick('clear')"
|
33
|
+
>清空
|
34
|
+
</el-button>
|
35
|
+
<el-button
|
36
|
+
v-if="permissions.includes('preview')"
|
37
|
+
type="text"
|
38
|
+
size="medium"
|
39
|
+
icon="el-icon-view"
|
40
|
+
@click="dialog.preview.visible = true"
|
41
|
+
>预览
|
42
|
+
</el-button>
|
43
|
+
<el-popover style="margin-left:10px;" placement="bottom" trigger="hover">
|
44
|
+
<el-button
|
45
|
+
v-if="permissions.includes('upload')"
|
46
|
+
type="text"
|
47
|
+
size="medium"
|
48
|
+
icon="el-icon-upload2"
|
49
|
+
slot="reference"
|
50
|
+
>导入</el-button
|
51
|
+
>
|
52
|
+
<div>
|
53
|
+
<div>
|
54
|
+
<el-button
|
55
|
+
type="text"
|
56
|
+
size="medium"
|
57
|
+
@click="dialog.import.visible = true"
|
58
|
+
>导入JSON
|
59
|
+
</el-button>
|
60
|
+
</div>
|
61
|
+
<div>
|
62
|
+
<el-upload
|
63
|
+
action
|
64
|
+
accept=".xlsx, .xls"
|
65
|
+
:auto-upload="false"
|
66
|
+
:show-file-list="false"
|
67
|
+
:on-change="onExcelFileChange"
|
68
|
+
>
|
69
|
+
<el-button type="text" size="medium">导入EXCEL</el-button>
|
70
|
+
</el-upload>
|
71
|
+
</div>
|
72
|
+
<div>
|
73
|
+
<el-button
|
74
|
+
type="text"
|
75
|
+
size="medium"
|
76
|
+
@click="dialog.template.visible = true"
|
77
|
+
>导入模板
|
78
|
+
</el-button>
|
79
|
+
</div>
|
80
|
+
</div>
|
81
|
+
</el-popover>
|
82
|
+
<el-popover style="margin-left:10px;" placement="bottom" trigger="hover">
|
83
|
+
<el-button
|
84
|
+
v-if="
|
85
|
+
permissions.includes('generateJson') ||
|
86
|
+
permissions.includes('generateCode')
|
87
|
+
"
|
88
|
+
type="text"
|
89
|
+
size="medium"
|
90
|
+
icon="el-icon-document"
|
91
|
+
slot="reference"
|
92
|
+
>生成</el-button
|
93
|
+
>
|
94
|
+
<div>
|
95
|
+
<div>
|
96
|
+
<el-button
|
97
|
+
v-if="permissions.includes('generateJson')"
|
98
|
+
type="text"
|
99
|
+
size="medium"
|
100
|
+
@click="handleGenerateJson"
|
101
|
+
>
|
102
|
+
生成JSON
|
103
|
+
</el-button>
|
104
|
+
</div>
|
105
|
+
<div>
|
106
|
+
<el-button
|
107
|
+
v-if="permissions.includes('generateCode')"
|
108
|
+
type="text"
|
109
|
+
size="medium"
|
110
|
+
@click="handleGenerateCode"
|
111
|
+
>
|
112
|
+
生成代码
|
113
|
+
</el-button>
|
114
|
+
</div>
|
115
|
+
</div>
|
116
|
+
</el-popover>
|
117
|
+
</div>
|
118
|
+
|
119
|
+
<!-- 导入JSON -->
|
120
|
+
<th-dialog
|
121
|
+
title="导入JSON"
|
122
|
+
:visible="dialog.import.visible"
|
123
|
+
:modal-append-to-body="false"
|
124
|
+
@on-close="dialog.import.visible = false"
|
125
|
+
@on-affirm="handleImportJson"
|
126
|
+
@on-fullscreen="$refs.valueCodeEditor.resize()"
|
127
|
+
>
|
128
|
+
<el-alert
|
129
|
+
type="info"
|
130
|
+
title="JSON格式如下,直接复制生成的json覆盖此处代码点击确定即可"
|
131
|
+
></el-alert>
|
132
|
+
<th-code-editor
|
133
|
+
v-model="dialog.import.value"
|
134
|
+
ref="valueCodeEditor"
|
135
|
+
></th-code-editor>
|
136
|
+
</th-dialog>
|
137
|
+
|
138
|
+
<!-- 导入模板 -->
|
139
|
+
<th-dialog
|
140
|
+
title="导入模板"
|
141
|
+
:visible="dialog.template.visible"
|
142
|
+
:modal-append-to-body="false"
|
143
|
+
@on-close="dialog.template.visible = false"
|
144
|
+
@on-affirm="handleImportTemplate"
|
145
|
+
>
|
146
|
+
|
147
|
+
</th-dialog>
|
148
|
+
|
149
|
+
<!-- 预览 -->
|
150
|
+
<th-dialog
|
151
|
+
title="预览"
|
152
|
+
v-model="dialog.preview.visible"
|
153
|
+
:modal-append-to-body="false"
|
154
|
+
@on-close="dialog.preview.visible = false"
|
155
|
+
>
|
156
|
+
<generate-form
|
157
|
+
v-if="dialog.preview.visible"
|
158
|
+
:data="formData"
|
159
|
+
:value="formValue"
|
160
|
+
:oauthConfig="oauthConfig"
|
161
|
+
:remote="remoteData"
|
162
|
+
:slotKeys="slotKeys"
|
163
|
+
:client="client"
|
164
|
+
insite="true"
|
165
|
+
@on-change="handleDataChange"
|
166
|
+
@button-submit="handleButtonSubmit"
|
167
|
+
ref="generateForm"
|
168
|
+
>
|
169
|
+
<template v-for="name in slotKeys" :slot="name">
|
170
|
+
<slot :name="name" />
|
171
|
+
</template>
|
172
|
+
</generate-form>
|
173
|
+
|
174
|
+
<template slot="footer">
|
175
|
+
<el-button type="primary" @click="handleGetData">获取数据</el-button>
|
176
|
+
<el-button @click="handleReset">重置</el-button>
|
177
|
+
</template>
|
178
|
+
</th-dialog>
|
179
|
+
|
180
|
+
<!-- 获取数据 -->
|
181
|
+
<th-dialog
|
182
|
+
title="获取数据"
|
183
|
+
:visible="dialog.data.visible"
|
184
|
+
:modal-append-to-body="false"
|
185
|
+
@on-close="dialog.data.visible = false"
|
186
|
+
@on-fullscreen="$refs.dataCodeEditor.resize()"
|
187
|
+
>
|
188
|
+
<th-code-editor
|
189
|
+
v-model="dialog.data.value"
|
190
|
+
ref="dataCodeEditor"
|
191
|
+
></th-code-editor>
|
192
|
+
|
193
|
+
<template slot="footer">
|
194
|
+
<el-button
|
195
|
+
type="primary"
|
196
|
+
class="json-btn"
|
197
|
+
:data-clipboard-text="dialog.data.valueCopy"
|
198
|
+
>复制数据</el-button
|
199
|
+
>
|
200
|
+
</template>
|
201
|
+
</th-dialog>
|
202
|
+
|
203
|
+
<!-- 生成json -->
|
204
|
+
<th-dialog
|
205
|
+
title="生成JSON"
|
206
|
+
:visible="dialog.config.visible"
|
207
|
+
:modal-append-to-body="false"
|
208
|
+
@on-close="dialog.config.visible = false"
|
209
|
+
@on-fullscreen="$refs.jsonCodeEditor.resize()"
|
210
|
+
>
|
211
|
+
<th-code-editor
|
212
|
+
v-model="dialog.config.value"
|
213
|
+
ref="jsonCodeEditor"
|
214
|
+
></th-code-editor>
|
215
|
+
|
216
|
+
<template slot="footer">
|
217
|
+
<el-button
|
218
|
+
type="primary"
|
219
|
+
class="json-btn"
|
220
|
+
:data-clipboard-text="dialog.config.valueCopy"
|
221
|
+
>复制数据</el-button
|
222
|
+
>
|
223
|
+
</template>
|
224
|
+
</th-dialog>
|
225
|
+
|
226
|
+
<!-- 生成代码 -->
|
227
|
+
<th-dialog
|
228
|
+
class="codeDialog"
|
229
|
+
title="生成代码"
|
230
|
+
:visible="dialog.code.visible"
|
231
|
+
:showFooter="false"
|
232
|
+
:modal-append-to-body="false"
|
233
|
+
@on-close="dialog.code.visible = false"
|
234
|
+
@on-fullscreen="handleDialogFullscreen"
|
235
|
+
>
|
236
|
+
<el-tabs
|
237
|
+
type="border-card"
|
238
|
+
style="box-shadow: none;"
|
239
|
+
v-model="dialog.code.type"
|
240
|
+
>
|
241
|
+
<el-tab-pane label="Vue Component" name="vue">
|
242
|
+
<th-code-editor
|
243
|
+
v-model="dialog.code.valueVue"
|
244
|
+
language="html"
|
245
|
+
readonly
|
246
|
+
ref="vueCodeEditor"
|
247
|
+
></th-code-editor>
|
248
|
+
</el-tab-pane>
|
249
|
+
<el-tab-pane label="HTML" name="html">
|
250
|
+
<th-code-editor
|
251
|
+
v-model="dialog.code.valueHtml"
|
252
|
+
language="html"
|
253
|
+
readonly
|
254
|
+
ref="htmlCodeEditor"
|
255
|
+
></th-code-editor>
|
256
|
+
</el-tab-pane>
|
257
|
+
</el-tabs>
|
258
|
+
</th-dialog>
|
259
|
+
</div>
|
260
|
+
</template>
|
261
|
+
|
262
|
+
<script>
|
263
|
+
import * as XLSX from "xlsx/xlsx.mjs";
|
264
|
+
import request from "./util/request";
|
265
|
+
import Clipboard from "clipboard";
|
266
|
+
import generateCode from "./util/generateCode.js";
|
267
|
+
import GenerateForm from "./GenerateForm";
|
268
|
+
export default {
|
269
|
+
props: {
|
270
|
+
baseConfig: Object,
|
271
|
+
permissions: Array,
|
272
|
+
client: String,
|
273
|
+
basicComponents: Array,
|
274
|
+
layoutComponents: Array,
|
275
|
+
formData: Object,
|
276
|
+
formValue: Object,
|
277
|
+
oauthConfig: Object,
|
278
|
+
slotKeys: Array
|
279
|
+
},
|
280
|
+
components: { GenerateForm },
|
281
|
+
data() {
|
282
|
+
return {
|
283
|
+
dialog: {
|
284
|
+
import: { visible: false, value: "" },
|
285
|
+
template: { visible: false, value: "" },
|
286
|
+
preview: { visible: false, value: "" },
|
287
|
+
data: { visible: false, value: "", valueCopy: "" },
|
288
|
+
config: { visible: false, value: "", valueCopy: "" },
|
289
|
+
code: { visible: false, valueHtml: "", valueVue: "", type: "vue" }
|
290
|
+
},
|
291
|
+
remoteData: {
|
292
|
+
func_test(resolve) {
|
293
|
+
setTimeout(() => {
|
294
|
+
const options = [
|
295
|
+
{ id: "1", name: "1111" },
|
296
|
+
{ id: "2", name: "2222" },
|
297
|
+
{ id: "3", name: "3333" }
|
298
|
+
];
|
299
|
+
|
300
|
+
resolve(options);
|
301
|
+
}, 2000);
|
302
|
+
},
|
303
|
+
funcGetToken(resolve) {
|
304
|
+
request
|
305
|
+
.get("http://tools-server.making.link/api/uptoken")
|
306
|
+
.then(res => {
|
307
|
+
resolve(res.uptoken);
|
308
|
+
});
|
309
|
+
},
|
310
|
+
upload_callback(response, file, fileList) {
|
311
|
+
console.log("callback", response, file, fileList);
|
312
|
+
}
|
313
|
+
},
|
314
|
+
jsonClipboard: null
|
315
|
+
};
|
316
|
+
},
|
317
|
+
created() {},
|
318
|
+
mounted() {},
|
319
|
+
methods: {
|
320
|
+
handleClick(val, data) {
|
321
|
+
this.$emit("click", val, data);
|
322
|
+
},
|
323
|
+
// excel 文件上传 改变监听
|
324
|
+
async onExcelFileChange(ev) {
|
325
|
+
let file = ev.raw;
|
326
|
+
if (!file) {
|
327
|
+
console.log("文件打开失败");
|
328
|
+
return;
|
329
|
+
} else {
|
330
|
+
let data = await this.readExcelFile(file);
|
331
|
+
//XLSX 文档 https://www.npmjs.com/package/xlsx
|
332
|
+
let workbook = XLSX.read(data, { type: "binary" }); //解析二进制格式数据
|
333
|
+
let worksheet = workbook.Sheets[workbook.SheetNames[0]]; //获取第一个Sheet
|
334
|
+
|
335
|
+
// console.log("XLSX.read => \n", workbook);
|
336
|
+
// console.log("sheet_to_json => \n", XLSX.utils.sheet_to_json(worksheet));
|
337
|
+
// console.log("sheet_to_csv => \n", XLSX.utils.sheet_to_csv(worksheet));
|
338
|
+
// console.log("sheet_to_txt => \n", XLSX.utils.sheet_to_txt(worksheet));
|
339
|
+
const xlsxDom = this.parseDom(XLSX.utils.sheet_to_html(worksheet));
|
340
|
+
// console.log("sheet_to_html => \n", xlsxDom);
|
341
|
+
const rowsDom = xlsxDom.getElementsByTagName("tr");
|
342
|
+
let rowSpan = 0;
|
343
|
+
for (let i = 0; i < rowsDom[0].childNodes.length; i++) {
|
344
|
+
const col = rowsDom[0].childNodes[i];
|
345
|
+
rowSpan += col.colSpan || 1;
|
346
|
+
}
|
347
|
+
const colSpan = 24 / rowSpan;
|
348
|
+
|
349
|
+
let config = {
|
350
|
+
list: [],
|
351
|
+
config: this.baseConfig
|
352
|
+
};
|
353
|
+
|
354
|
+
for (const row of rowsDom) {
|
355
|
+
const key =
|
356
|
+
Date.parse(new Date()) + "_" + Math.ceil(Math.random() * 99999);
|
357
|
+
let grid = this.getComponentsConfig("grid");
|
358
|
+
grid.options.columns = [];
|
359
|
+
grid.key = key;
|
360
|
+
grid.model = "grid_" + key;
|
361
|
+
|
362
|
+
const colsDom = row.childNodes;
|
363
|
+
let span = 0;
|
364
|
+
for (let i = 0; i < colsDom.length; i++) {
|
365
|
+
if (i % 2 === 0) span = 0;
|
366
|
+
else continue;
|
367
|
+
|
368
|
+
const colKey =
|
369
|
+
Date.parse(new Date()) + "_" + Math.ceil(Math.random() * 99999);
|
370
|
+
const titleDom = colsDom[i];
|
371
|
+
const valueDom = colsDom[i + 1];
|
372
|
+
if (!titleDom.innerText && !valueDom.innerText) continue;
|
373
|
+
|
374
|
+
if (valueDom) {
|
375
|
+
span =
|
376
|
+
((titleDom.colSpan || 1) + (valueDom.colSpan || 1)) * colSpan;
|
377
|
+
|
378
|
+
const data = this.getComponentsConfig("input");
|
379
|
+
let name = titleDom.innerText;
|
380
|
+
if (name.charAt(0) === "*") {
|
381
|
+
name = name.slice(1);
|
382
|
+
data.options.required = true;
|
383
|
+
data.rules = data.rules || [];
|
384
|
+
data.rules.push({
|
385
|
+
required: true,
|
386
|
+
message: "单行文本必须填写"
|
387
|
+
});
|
388
|
+
}
|
389
|
+
data.name = name;
|
390
|
+
data.options.defaultValue = valueDom.innerText;
|
391
|
+
data.key = colKey;
|
392
|
+
data.model = "input_" + colKey;
|
393
|
+
grid.options.columns.push({ span: span, list: [data] });
|
394
|
+
} else {
|
395
|
+
span = titleDom.colSpan * colSpan;
|
396
|
+
|
397
|
+
const data = this.getComponentsConfig("text");
|
398
|
+
data.name = titleDom.innerText;
|
399
|
+
data.options.defaultValue = titleDom.innerText;
|
400
|
+
data.options.hideLabel = true;
|
401
|
+
data.key = colKey;
|
402
|
+
data.model = "text_" + colKey;
|
403
|
+
grid.options.columns.push({ span: span, list: [data] });
|
404
|
+
}
|
405
|
+
}
|
406
|
+
if (grid.options.columns.length) {
|
407
|
+
config.list.push(grid);
|
408
|
+
} else {
|
409
|
+
const data = this.getComponentsConfig("filler");
|
410
|
+
data.name = "";
|
411
|
+
data.key = key;
|
412
|
+
data.model = "filler_" + key;
|
413
|
+
config.list.push(data);
|
414
|
+
}
|
415
|
+
}
|
416
|
+
this.handleClick("import-excel", config);
|
417
|
+
}
|
418
|
+
},
|
419
|
+
// 读取excel file
|
420
|
+
readExcelFile(file) {
|
421
|
+
//文件读取
|
422
|
+
return new Promise(resolve => {
|
423
|
+
let reader = new FileReader();
|
424
|
+
reader.readAsBinaryString(file); //以二进制的方式读取
|
425
|
+
reader.onload = ev => {
|
426
|
+
resolve(ev.target.result);
|
427
|
+
};
|
428
|
+
});
|
429
|
+
},
|
430
|
+
parseDom(arg) {
|
431
|
+
var objE = document.createElement("div");
|
432
|
+
objE.innerHTML = arg;
|
433
|
+
return objE.childNodes[2];
|
434
|
+
},
|
435
|
+
getComponentsConfig(type) {
|
436
|
+
let data = null;
|
437
|
+
for (const item of this.basicComponents) {
|
438
|
+
if (type === item.type) {
|
439
|
+
data = JSON.parse(JSON.stringify(item));
|
440
|
+
return data;
|
441
|
+
}
|
442
|
+
}
|
443
|
+
for (const item of this.layoutComponents) {
|
444
|
+
if (type === item.type) {
|
445
|
+
data = JSON.parse(JSON.stringify(item));
|
446
|
+
return data;
|
447
|
+
}
|
448
|
+
}
|
449
|
+
return data;
|
450
|
+
},
|
451
|
+
handleImportJson() {
|
452
|
+
this.dialog.import.visible = false;
|
453
|
+
this.handleClick("import-json", JSON.parse(this.dialog.import.value));
|
454
|
+
},
|
455
|
+
handleImportTemplate() {
|
456
|
+
this.dialog.template.visible = false;
|
457
|
+
},
|
458
|
+
handleDataChange(field, value, data) {
|
459
|
+
// console.log('handleDataChange =>',field, value, data);
|
460
|
+
},
|
461
|
+
handleButtonSubmit(val) {
|
462
|
+
// console.log("handleButtonSubmit =>", val);
|
463
|
+
},
|
464
|
+
handleGetData() {
|
465
|
+
this.$refs.generateForm.getData().then(data => {
|
466
|
+
this.dialog.data = {
|
467
|
+
visible: true,
|
468
|
+
value: JSON.stringify(data, null, 2),
|
469
|
+
valueCopy: JSON.stringify(data, null, 2)
|
470
|
+
};
|
471
|
+
this.$nextTick(() => {
|
472
|
+
this.initClipboard();
|
473
|
+
});
|
474
|
+
});
|
475
|
+
},
|
476
|
+
handleReset() {
|
477
|
+
this.$refs.generateForm.reset();
|
478
|
+
},
|
479
|
+
handleGenerateJson() {
|
480
|
+
this.dialog.config = {
|
481
|
+
visible: true,
|
482
|
+
value: JSON.stringify(this.formData, null, 2),
|
483
|
+
valueCopy: JSON.stringify(this.formData, null, 2)
|
484
|
+
};
|
485
|
+
this.$nextTick(() => {
|
486
|
+
this.initClipboard();
|
487
|
+
});
|
488
|
+
},
|
489
|
+
initClipboard() {
|
490
|
+
if (!this.jsonClipboard) {
|
491
|
+
this.jsonClipboard = new Clipboard(".json-btn");
|
492
|
+
this.jsonClipboard.on("success", e => {
|
493
|
+
this.$message.success("复制成功");
|
494
|
+
});
|
495
|
+
}
|
496
|
+
},
|
497
|
+
handleGenerateCode() {
|
498
|
+
this.dialog.code = {
|
499
|
+
visible: true,
|
500
|
+
valueHtml: generateCode(JSON.stringify(this.formData), "html"),
|
501
|
+
valueVue: generateCode(JSON.stringify(this.formData), "vue"),
|
502
|
+
type: "vue"
|
503
|
+
};
|
504
|
+
},
|
505
|
+
handleDialogFullscreen() {
|
506
|
+
this.$refs.vueCodeEditor.resize();
|
507
|
+
this.$refs.htmlCodeEditor.resize();
|
508
|
+
}
|
509
|
+
}
|
510
|
+
};
|
511
|
+
</script>
|
512
|
+
|
513
|
+
<style lang="scss" scoped>
|
514
|
+
.widgetTools {
|
515
|
+
display: flex;
|
516
|
+
align-items: center;
|
517
|
+
width: 100%;
|
518
|
+
height: 45px;
|
519
|
+
padding: 0 15px;
|
520
|
+
border-bottom: solid 2px #e4e7ed;
|
521
|
+
|
522
|
+
.left {
|
523
|
+
min-width: 60px;
|
524
|
+
.el-button {
|
525
|
+
color: #333;
|
526
|
+
}
|
527
|
+
.active {
|
528
|
+
color: #409eff;
|
529
|
+
}
|
530
|
+
}
|
531
|
+
.right {
|
532
|
+
flex: 1;
|
533
|
+
display: flex;
|
534
|
+
align-items: center;
|
535
|
+
justify-content: right;
|
536
|
+
}
|
537
|
+
}
|
538
|
+
</style>
|