tianheng-ui 0.1.12 → 0.1.14

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.
@@ -1,189 +1,94 @@
1
1
  <template>
2
- <div class="th-table-making">
3
- <el-container>
4
- <el-container>
5
- <el-header>
6
- <div class="client">
7
- <el-button
8
- :class="{ active: client === 'monitor' }"
9
- type="text"
10
- size="medium"
11
- icon="el-icon-monitor"
12
- @click="client = 'monitor'"
13
- >
14
- 桌面端
15
- </el-button>
16
- <!-- <el-button
17
- :class="{ active: client === 'mobile' }"
18
- type="text"
19
- size="medium"
20
- icon="el-icon-mobile"
21
- @click="client = 'mobile'"
22
- >
23
- 移动端
24
- </el-button> -->
25
- </div>
26
- <slot name="action"></slot>
27
- </el-header>
28
- <el-main>
29
- <widget-table
30
- :searchFields="searchFields"
31
- :tableFields="tableFields"
32
- @move="handleMoveChange"
33
- ></widget-table>
34
- </el-main>
35
- </el-container>
36
- <el-aside width="300px">
37
- <widget-config
38
- :fields="fields"
39
- ref="configRef"
40
- @fields-change="handleFieldsChange"
41
- ></widget-config>
42
- </el-aside>
43
- </el-container>
2
+ <div class="th-table-making th-flex_box">
3
+ <div class="th-fiex_content">
4
+ <widget-tools
5
+ :config="config"
6
+ :client="client"
7
+ :permissions="permissions"
8
+ @click="handleToolsClick"
9
+ >
10
+ <slot name="action"></slot>
11
+ </widget-tools>
12
+ <widget-table
13
+ style="height:calc(100% - 45px)"
14
+ :config="config"
15
+ ></widget-table>
16
+ </div>
17
+ <div class="th-flex_aside th-is_border_left" style="width:300px">
18
+ <widget-config
19
+ :config="config"
20
+ :fields.sync="fields"
21
+ :formOptions="formOptions"
22
+ :apiOptions="apiOptions"
23
+ ref="configRef"
24
+ ></widget-config>
25
+ </div>
44
26
  </div>
45
27
  </template>
46
28
 
47
29
  <script>
30
+ import WidgetTools from "./WidgetTools.vue";
48
31
  import WidgetTable from "./widgetTable.vue";
49
32
  import WidgetConfig from "./widgetConfig.vue";
33
+ import { deepClone, deepMerge } from "./util/index";
34
+ import { tableConfig } from "./custom/config";
50
35
  export default {
51
36
  name: "ThTableMaking",
52
- components: { WidgetTable, WidgetConfig },
37
+ components: { WidgetTools, WidgetTable, WidgetConfig },
53
38
  props: {
54
- fields: {
55
- type: Array,
56
- default: () => {
57
- return [];
58
- }
59
- },
60
- config: {
39
+ data: {
61
40
  type: Object,
62
41
  default: () => {
63
- return {};
42
+ return deepClone(tableConfig);
64
43
  }
44
+ },
45
+ fields: Array,
46
+ formOptions: Array,
47
+ apiOptions: Array,
48
+ permissions: {
49
+ type: Array,
50
+ default: () => [
51
+ "monitor",
52
+ "mobile",
53
+ "upload",
54
+ "clearable",
55
+ "preview",
56
+ "generateCode",
57
+ "generateJson"
58
+ ]
65
59
  }
66
60
  },
67
61
  data() {
68
62
  return {
69
- searchFields: [],
70
- tableFields: [],
63
+ config: this.data,
71
64
  client: "monitor"
72
65
  };
73
66
  },
74
67
  watch: {
75
- fields: {
76
- handler(val, oldVal) {
77
- if (oldVal.length === 0) {
78
- this.initConfig();
79
- }
80
- },
81
- deep: true
68
+ config: {
69
+ deep: true,
70
+ handler: function(val) {
71
+ this.$emit("update:data", val);
72
+ }
82
73
  },
83
- config(val) {
84
- this.initConfig();
74
+ data(val) {
75
+ this.config = val;
85
76
  }
86
77
  },
87
- mounted() {
88
- this.initConfig();
89
- },
78
+ mounted() {},
90
79
  methods: {
91
- initConfig() {
92
- if (!this.config || Object.keys(this.config).length === 0) return;
80
+ handleToolsClick(action, data) {
81
+ switch (action) {
82
+ case "import-json":
83
+ this.config = data;
84
+ break;
93
85
 
94
- this.$refs.configRef.tableConfig = this.config;
95
-
96
- const searchFields = [];
97
- const searchFieldsIndexs = [];
98
- if (this.config.search) {
99
- const searchOptions = this.config.search.options;
100
- for (const item of searchOptions) {
101
- for (let i = 0; i < this.fields.length; i++) {
102
- const element = this.fields[i];
103
- if (element.prop === item.prop) {
104
- searchFields.push(item);
105
- searchFieldsIndexs.push(i);
106
- }
107
- }
108
- }
109
- this.searchFields = searchFields;
110
- this.$refs.configRef.search = {
111
- fields: searchFieldsIndexs,
112
- isCheckAll: searchFieldsIndexs.length === this.fields.length,
113
- isIndeterminate:
114
- searchFieldsIndexs.length > 0 &&
115
- searchFieldsIndexs.length < this.fields.length
116
- };
117
- }
118
-
119
- const tableFields = [];
120
- const tableFieldsIndexs = [];
121
- if (this.config.table) {
122
- const tableOptions = this.config.table.options;
123
- for (const item of tableOptions) {
124
- for (let i = 0; i < this.fields.length; i++) {
125
- const element = this.fields[i];
126
- if (element.prop === item.prop) {
127
- tableFields.push(item);
128
- tableFieldsIndexs.push(i);
129
- }
130
- }
131
- }
132
- this.tableFields = tableFields;
133
- this.$refs.configRef.table = {
134
- fields: tableFieldsIndexs,
135
- isCheckAll: tableFieldsIndexs.length === this.fields.length,
136
- isIndeterminate:
137
- tableFieldsIndexs.length > 0 &&
138
- tableFieldsIndexs.length < this.fields.length
139
- };
140
- }
141
- },
142
- handleFieldsChange(val) {
143
- const type = val.type;
144
- const data = val.data;
145
- const list = [];
146
- data.forEach(i => {
147
- list.push(this.fields[i]);
148
- });
149
- if (type === 0) {
150
- this.searchFields = list;
151
- } else {
152
- this.tableFields = list;
153
- }
154
- },
155
- handleMoveChange(val) {
156
- const newIndex = val.data.newIndex;
157
- const oldIndex = val.data.oldIndex;
158
- if (val.type === "search") {
159
- let list = this.$refs.configRef.search.fields;
160
- list = this.handleMobile(list, oldIndex, newIndex);
161
- this.$refs.configRef.search.fields = list;
162
- this.searchFields = this.handleMobile(this.searchFields, oldIndex, newIndex);
163
- } else {
164
- let list = this.$refs.configRef.table.fields;
165
- list = this.handleMobile(list, oldIndex, newIndex);
166
- this.$refs.configRef.table.fields = list;
167
- this.tableFields = this.handleMobile(this.tableFields, oldIndex, newIndex);
168
- }
169
- },
170
- handleMobile(list, oldIndex, newIndex) {
171
- const item = JSON.parse(JSON.stringify(list[oldIndex]));
172
- if (oldIndex < newIndex) {
173
- list.splice(newIndex + 1, 0, item);
174
- list.splice(oldIndex, 1);
175
- }
176
- if (oldIndex > newIndex) {
177
- list.splice(newIndex, 0, item);
178
- list.splice(oldIndex + 1, 1);
86
+ default:
87
+ break;
179
88
  }
180
- return list;
181
89
  },
182
90
  getJson() {
183
- const tableConfig = this.$refs.configRef.getJson();
184
- tableConfig.search.options = this.searchFields;
185
- tableConfig.table.options = this.tableFields;
186
- return tableConfig;
91
+ return this.config;
187
92
  }
188
93
  }
189
94
  };
@@ -425,9 +425,62 @@ const tableConfig = {
425
425
  }
426
426
  }
427
427
  }
428
- };
428
+ };
429
429
 
430
430
  export const tableItemConfig = key => {
431
431
  const config = tableConfig[key] || null;
432
432
  return JSON.parse(JSON.stringify(config));
433
433
  };
434
+
435
+ export const deepClone = (obj, clone) => {
436
+ //判断拷贝的要进行深拷贝的是数组还是对象,是数组的话进行数组拷贝,对象的话进行对象拷贝
437
+ const toString = Object.prototype.toString;
438
+ toString.call(obj) === "[object Array]"
439
+ ? (clone = clone || [])
440
+ : (clone = clone || {});
441
+ for (const i in obj) {
442
+ if (typeof obj[i] === "object" && obj[i] !== null) {
443
+ // 要考虑深复制问题了
444
+ if (Array.isArray(obj[i])) {
445
+ // 这是数组
446
+ clone[i] = [];
447
+ } else {
448
+ // 这是对象
449
+ clone[i] = {};
450
+ }
451
+ deepClone(obj[i], clone[i]);
452
+ } else {
453
+ clone[i] = obj[i];
454
+ }
455
+ }
456
+ return clone;
457
+ };
458
+
459
+ export const deepMerge = (target, other) => {
460
+ const targetToString = Object.prototype.toString.call(target);
461
+ const otherToString = Object.prototype.toString.call(target);
462
+ if (
463
+ targetToString === "[object Object]" &&
464
+ otherToString === "[object Object]"
465
+ ) {
466
+ for (let [key, val] of Object.entries(other)) {
467
+ if (!target[key]) {
468
+ target[key] = val;
469
+ } else {
470
+ target[key] = deepMerge(target[key], val);
471
+ }
472
+ }
473
+ } else if (
474
+ targetToString === "[object Array]" &&
475
+ otherToString === "[object Array]"
476
+ ) {
477
+ for (let [key, val] of Object.entries(other)) {
478
+ if (target[key]) {
479
+ target[key] = deepMerge(target[key], val);
480
+ } else {
481
+ target.push(val);
482
+ }
483
+ }
484
+ }
485
+ return target;
486
+ };