Skip to content

Commit 589e1e8

Browse files
committed
perf: 新增ChartScreen作为图表Demo
1 parent afd13cd commit 589e1e8

File tree

5 files changed

+464
-30
lines changed

5 files changed

+464
-30
lines changed

src/component/form-designer/src/GenerateFormItem.vue

+25-20
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,6 @@ export default class GenerateFormItem extends Vue {
425425
})
426426
readOnly!: boolean;
427427

428-
// 子表单单个组件value
429-
@Prop()
430-
value: any;
431-
432-
// 子表单单个组件初始值model
433-
@Prop()
434-
model: any;
435-
436428
// 组件校验规则
437429
@Prop()
438430
rules: any;
@@ -448,32 +440,45 @@ export default class GenerateFormItem extends Vue {
448440
normalizer: any;
449441

450442
initData() {
451-
// 如果是子表单
452-
if (this.model) {
453-
if (this.widget.options.multiple || 'cascader,checkbox'.includes(this.widget.type)) {
454-
this.dataModel = typeof this.model === 'string' ? this.model.split(',') : this.model;
455-
} else {
456-
this.dataModel = this.model;
457-
}
458-
return;
459-
}
443+
const { type, model } = this.widget;
444+
// if (this.model) {
445+
// // 多选组件需要初始化值为数组
446+
// if (this.widget.options.multiple || 'cascader,checkbox'.includes(type)) {
447+
// this.dataModel = typeof this.model === 'string' ? this.model.split(',') : this.model;
448+
// } else {
449+
// this.dataModel = this.model;
450+
// }
451+
// return;
452+
// }
460453
let normalizer;
461-
if (this.widget.type === 'treeselect') {
454+
// tree-select组件初始化
455+
if (type === 'treeselect') {
462456
const { value, label } = this.widget.options.props;
463457
normalizer = (node) => {
464458
// 去掉children=null的属性
465459
if (node.children === null || node.children === 'null') {
466460
delete node.children;
467461
}
468-
// 此处暂时写反了...暂时不做修改
469462
return {
470463
id: node[value],
471464
label: node[label],
472465
};
473466
};
467+
} else if (type.includes('chart-')) { // 图表预设option
468+
// 如果是通用图表则传入的值为option
469+
if (type === 'chart-common') {
470+
if (this.models[model]) {
471+
this.widget.options.option = this.models[model];
472+
}
473+
} else { // 指定图表默认转入data
474+
// eslint-disable-next-line no-lonely-if
475+
if (this.models[model]) {
476+
this.widget.options.data = this.models[model];
477+
}
478+
}
474479
}
475480
this.normalizer = normalizer;
476-
this.dataModel = this.models[this.widget.model];
481+
this.dataModel = this.models[model];
477482
}
478483

479484
created() {

src/component/form-designer/src/components/Charts/Echarts.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ export default {
8888
this.initEvent();
8989
// 运行配置参数
9090
this.setOption();
91-
if (this.loop) {
92-
this.initLoopFn();
93-
}
91+
// if (this.loop) {
92+
// this.initLoopFn();
93+
// }
9494
},
9595
initLoopFn() {
9696
const timer = setInterval(() => {

src/demo/App.vue

+30-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
<el-main class="content">
4343
<el-container class="container">
44-
<el-header>表格设计器(TableDesigner)</el-header>
44+
<el-header><el-tag>表格设计器(TableDesigner)</el-tag></el-header>
4545
<el-main>
4646
<TableDesigner :dictList="dictList"
4747
:formList="formList"
@@ -50,7 +50,7 @@
5050
</el-container>
5151

5252
<el-container class="container">
53-
<el-header>表单设计器(FormDesigner)</el-header>
53+
<el-header><el-tag>表单设计器(FormDesigner)</el-tag></el-header>
5454
<el-main>
5555
<FormDesigner ref="formDesigner"
5656
:getFormKey="getTableFields">
@@ -65,7 +65,7 @@
6565
</el-main>
6666
</el-container>
6767
<el-container class="container">
68-
<el-header>ProTable组件 (基于El-Table二次封装,托管分页,查询,表格。仅包含数据表格及搜索功能,增删改查封装见CrudTable)
68+
<el-header><el-tag>ProTable组件</el-tag> (基于El-Table二次封装,托管分页,查询,表格。仅包含数据表格及搜索功能,增删改查封装见CrudTable)
6969
<el-button @click="handleGenerateJson" icon="el-icon-tickets" type="warning" size="small">
7070
当前表格json
7171
</el-button>
@@ -145,7 +145,7 @@
145145
</el-main>
146146
</el-container>
147147
<el-container class="container">
148-
<el-header>CrudTable组件 基于ProTable + GenerateForm + El-Dialog 二次封装 (有批量操作按钮时会默认开启多选模式)
148+
<el-header><el-tag>CrudTable</el-tag> 基于ProTable + GenerateForm + El-Dialog 二次封装 (有批量操作按钮时会默认开启多选模式)
149149
<el-button @click="handleGenerateJson" icon="el-icon-tickets" type="warning" size="small">
150150
当前表格json
151151
</el-button>
@@ -274,6 +274,22 @@
274274
</el-col>
275275
</el-row>
276276
</el-main>
277+
</el-container>
278+
279+
<el-container class="container">
280+
<el-header>
281+
<el-tag>GenerateForm渲染图表示例</el-tag>
282+
<el-button @click="handleGenerateJson('chart')" icon="el-icon-tickets" type="warning" size="small">
283+
当前表单JSON
284+
</el-button>
285+
</el-header>
286+
<el-main class="demo-actions">
287+
<el-row :gutter="10">
288+
<el-col :span="24">
289+
<ChartScreen></ChartScreen>
290+
</el-col>
291+
</el-row>
292+
</el-main>
277293
</el-container>
278294
</el-main>
279295
<el-footer height="80px"
@@ -295,17 +311,22 @@ import {
295311
import CusDialog from '@/component/common/CusDialog.vue';
296312
import PersonCrudTable from './component/PersonCrudTable.vue';
297313
import PersonProTable from './component/PersonProTable.vue';
298-
314+
import ChartScreen from './component/ChartScreen.vue';
315+
import chartData from './component/data';
299316

300317
export default {
301318
name: 'app',
302319
methods: {
303320
getRowData(row) {
304321
this.$alert(JSON.stringify(row));
305322
},
306-
handleGenerateJson() {
323+
handleGenerateJson(type) {
307324
this.jsonVisible = true;
308-
this.jsonTemplate = JSON.stringify(this.columns, null, 2);
325+
if (type === 'chart') {
326+
this.jsonTemplate = JSON.stringify(this.chartData, null, 2);
327+
} else {
328+
this.jsonTemplate = JSON.stringify(this.columns, null, 2);
329+
}
309330

310331
this.$nextTick(() => {
311332
const editor = ace.edit('jsoneditor');
@@ -354,6 +375,7 @@ export default {
354375
},
355376
data() {
356377
return {
378+
chartData,
357379
jsonVisible: false,
358380
jsonTemplate: '',
359381
dictList: [],
@@ -395,6 +417,7 @@ export default {
395417
CusDialog,
396418
PersonCrudTable,
397419
PersonProTable,
420+
ChartScreen,
398421
},
399422
};
400423
</script>

src/demo/component/ChartScreen.vue

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--
2+
* @file: 图表展示
3+
* @author: BoBo
4+
* @copyright: BoBo
5+
* @Date: 2020年12月18日16:54:49
6+
-->
7+
8+
<template>
9+
<div class="page-container">
10+
<GenerateForm :data="data" :value="value"></GenerateForm>
11+
</div>
12+
</template>
13+
14+
<script>
15+
import { Vue, Component, Prop } from 'vue-property-decorator';
16+
import data from './data';
17+
18+
@Component({
19+
name: 'ChartScreen',
20+
})
21+
export default class ChartScreen extends Vue {
22+
data = data
23+
24+
value = {
25+
chart2: {
26+
xAxis: {
27+
type: 'category',
28+
data: ['1', '2', '3', '4', '5', '6', '7'],
29+
},
30+
yAxis: {
31+
type: 'value',
32+
},
33+
series: [
34+
{
35+
data: [150, 230, 224, 218, 135, 147, 260],
36+
type: 'line',
37+
},
38+
],
39+
},
40+
}
41+
}
42+
</script>

0 commit comments

Comments
 (0)