tianheng-ui 0.0.44 → 0.0.47

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,268 +1,268 @@
1
- <template>
2
- <div class="widget-form-container">
3
- <div v-if="data.list.length == 0" class="form-empty">
4
- 从左侧拖拽来添加字段
5
- </div>
6
- <el-form
7
- :size="data.config.size"
8
- label-suffix=":"
9
- :label-position="data.config.labelPosition"
10
- :label-width="data.config.labelWidth + 'px'"
11
- >
12
- <draggable
13
- class=""
14
- v-model="data.list"
15
- v-bind="{
16
- group: 'people',
17
- ghostClass: 'ghost',
18
- animation: 200,
19
- handle: '.drag-widget'
20
- }"
21
- @end="handleMoveEnd"
22
- @add="handleWidgetAdd"
23
- >
24
- <transition-group name="fade" tag="div" class="widget-form-list">
25
- <template v-for="(element, index) in data.list">
26
- <template v-if="element.type == 'grid'">
27
- <el-row
28
- class="widget-col widget-view"
29
- v-if="element && element.key"
30
- :key="element.key"
31
- type="flex"
32
- :class="{ active: selectWidget.key == element.key }"
33
- :gutter="element.options.gutter ? element.options.gutter : 0"
34
- :justify="element.options.justify"
35
- :align="element.options.align"
36
- @click.native="handleSelectWidget(index)"
37
- >
38
- <el-col
39
- v-for="(col, colIndex) in element.columns"
40
- :key="colIndex"
41
- :span="col.span ? col.span : 0"
42
- >
43
- <draggable
44
- v-model="col.list"
45
- :no-transition-on-drag="true"
46
- v-bind="{
47
- group: 'people',
48
- ghostClass: 'ghost',
49
- animation: 200,
50
- handle: '.drag-widget'
51
- }"
52
- @end="handleMoveEnd"
53
- @add="handleWidgetColAdd($event, element, colIndex)"
54
- >
55
- <transition-group
56
- name="fade"
57
- tag="div"
58
- class="widget-col-list"
59
- >
60
- <template v-for="(el, i) in col.list">
61
- <widget-form-item
62
- :key="el.key"
63
- v-if="el.key"
64
- :element="el"
65
- :select.sync="selectWidget"
66
- :index="i"
67
- :data="col"
68
- >
69
- </widget-form-item>
70
- </template>
71
- </transition-group>
72
- </draggable>
73
- </el-col>
74
- <div
75
- class="widget-view-action widget-col-action"
76
- v-if="selectWidget.key == element.key"
77
- >
78
- <i
79
- class="iconfont icon-trash"
80
- @click.stop="handleWidgetDelete(index)"
81
- ></i>
82
- </div>
83
-
84
- <div
85
- class="widget-view-drag widget-col-drag"
86
- v-if="selectWidget.key == element.key"
87
- >
88
- <i class="iconfont icon-drag drag-widget"></i>
89
- </div>
90
- </el-row>
91
- </template>
92
- <template v-else>
93
- <widget-form-item
94
- v-if="element && element.key"
95
- :key="element.key"
96
- :element="element"
97
- :select.sync="selectWidget"
98
- :index="index"
99
- :data="data"
100
- ></widget-form-item>
101
- </template>
102
- </template>
103
- </transition-group>
104
- </draggable>
105
- </el-form>
106
- </div>
107
- </template>
108
-
109
- <script>
110
- import Draggable from "vuedraggable";
111
- import WidgetFormItem from "./WidgetFormItem";
112
-
113
- export default {
114
- components: {
115
- Draggable,
116
- WidgetFormItem
117
- },
118
- props: ["data", "select"],
119
- data() {
120
- return {
121
- selectWidget: this.select
122
- };
123
- },
124
- mounted() {
125
- document.body.ondrop = function(event) {
126
- let isFirefox = navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
127
- if (isFirefox) {
128
- event.preventDefault();
129
- event.stopPropagation();
130
- }
131
- };
132
- },
133
- methods: {
134
- handleMoveEnd({ newIndex, oldIndex }) {},
135
- handleSelectWidget(index) {
136
- this.selectWidget = this.data.list[index];
137
- },
138
- handleWidgetAdd(evt) {
139
- const newIndex = evt.newIndex;
140
- const to = evt.to;
141
-
142
- //为拖拽到容器的元素添加唯一 key
143
- const key =
144
- Date.parse(new Date()) + "_" + Math.ceil(Math.random() * 99999);
145
- this.$set(this.data.list, newIndex, {
146
- ...this.data.list[newIndex],
147
- options: {
148
- ...this.data.list[newIndex].options,
149
- remoteFunc: "func_" + key
150
- },
151
- key,
152
- // 绑定键值
153
- model: this.data.list[newIndex].type + "_" + key,
154
- rules: []
155
- });
156
-
157
- if (
158
- this.data.list[newIndex].type === "radio" ||
159
- this.data.list[newIndex].type === "checkbox" ||
160
- this.data.list[newIndex].type === "select"
161
- ) {
162
- this.$set(this.data.list, newIndex, {
163
- ...this.data.list[newIndex],
164
- options: {
165
- ...this.data.list[newIndex].options,
166
- options: this.data.list[newIndex].options.options.map(item => ({
167
- ...item
168
- }))
169
- }
170
- });
171
- }
172
-
173
- if (this.data.list[newIndex].type === "grid") {
174
- this.$set(this.data.list, newIndex, {
175
- ...this.data.list[newIndex],
176
- columns: this.data.list[newIndex].columns.map(item => ({ ...item }))
177
- });
178
- }
179
-
180
- this.selectWidget = this.data.list[newIndex];
181
- },
182
- handleWidgetColAdd($event, row, colIndex) {
183
- console.log("coladd", $event, row, colIndex);
184
- const newIndex = $event.newIndex;
185
- const oldIndex = $event.oldIndex;
186
- const item = $event.item;
187
-
188
- // 防止布局元素的嵌套拖拽
189
- if (item.className.indexOf("data-grid") >= 0) {
190
- // 如果是列表中拖拽的元素需要还原到原来位置
191
- item.tagName === "DIV" &&
192
- this.data.list.splice(
193
- oldIndex,
194
- 0,
195
- row.columns[colIndex].list[newIndex]
196
- );
197
-
198
- row.columns[colIndex].list.splice(newIndex, 1);
199
-
200
- return false;
201
- }
202
-
203
- console.log("from", item);
204
-
205
- const key =
206
- Date.parse(new Date()) + "_" + Math.ceil(Math.random() * 99999);
207
-
208
- this.$set(row.columns[colIndex].list, newIndex, {
209
- ...row.columns[colIndex].list[newIndex],
210
- options: {
211
- ...row.columns[colIndex].list[newIndex].options,
212
- remoteFunc: "func_" + key
213
- },
214
- key,
215
- // 绑定键值
216
- model: row.columns[colIndex].list[newIndex].type + "_" + key,
217
- rules: []
218
- });
219
-
220
- if (
221
- row.columns[colIndex].list[newIndex].type === "radio" ||
222
- row.columns[colIndex].list[newIndex].type === "checkbox" ||
223
- row.columns[colIndex].list[newIndex].type === "select"
224
- ) {
225
- this.$set(row.columns[colIndex].list, newIndex, {
226
- ...row.columns[colIndex].list[newIndex],
227
- options: {
228
- ...row.columns[colIndex].list[newIndex].options,
229
- options: row.columns[colIndex].list[newIndex].options.options.map(
230
- item => ({
231
- ...item
232
- })
233
- )
234
- }
235
- });
236
- }
237
-
238
- this.selectWidget = row.columns[colIndex].list[newIndex];
239
- },
240
- handleWidgetDelete(index) {
241
- if (this.data.list.length - 1 === index) {
242
- if (index === 0) {
243
- this.selectWidget = {};
244
- } else {
245
- this.selectWidget = this.data.list[index - 1];
246
- }
247
- } else {
248
- this.selectWidget = this.data.list[index + 1];
249
- }
250
-
251
- this.$nextTick(() => {
252
- this.data.list.splice(index, 1);
253
- });
254
- }
255
- },
256
- watch: {
257
- select(val) {
258
- this.selectWidget = val;
259
- },
260
- selectWidget: {
261
- handler(val) {
262
- this.$emit("update:select", val);
263
- },
264
- deep: true
265
- }
266
- }
267
- };
268
- </script>
1
+ <template>
2
+ <div class="widget-form-container">
3
+ <div v-if="data.list.length == 0" class="form-empty">
4
+ 从左侧拖拽来添加字段
5
+ </div>
6
+ <el-form
7
+ :size="data.config.size"
8
+ label-suffix=":"
9
+ :label-position="data.config.labelPosition"
10
+ :label-width="data.config.labelWidth + 'px'"
11
+ >
12
+ <draggable
13
+ class=""
14
+ v-model="data.list"
15
+ v-bind="{
16
+ group: 'people',
17
+ ghostClass: 'ghost',
18
+ animation: 200,
19
+ handle: '.drag-widget'
20
+ }"
21
+ @end="handleMoveEnd"
22
+ @add="handleWidgetAdd"
23
+ >
24
+ <transition-group name="fade" tag="div" class="widget-form-list">
25
+ <template v-for="(element, index) in data.list">
26
+ <template v-if="element.type == 'grid'">
27
+ <el-row
28
+ class="widget-col widget-view"
29
+ v-if="element && element.key"
30
+ :key="element.key"
31
+ type="flex"
32
+ :class="{ active: selectWidget.key == element.key }"
33
+ :gutter="element.options.gutter ? element.options.gutter : 0"
34
+ :justify="element.options.justify"
35
+ :align="element.options.align"
36
+ @click.native="handleSelectWidget(index)"
37
+ >
38
+ <el-col
39
+ v-for="(col, colIndex) in element.columns"
40
+ :key="colIndex"
41
+ :span="col.span ? col.span : 0"
42
+ >
43
+ <draggable
44
+ v-model="col.list"
45
+ :no-transition-on-drag="true"
46
+ v-bind="{
47
+ group: 'people',
48
+ ghostClass: 'ghost',
49
+ animation: 200,
50
+ handle: '.drag-widget'
51
+ }"
52
+ @end="handleMoveEnd"
53
+ @add="handleWidgetColAdd($event, element, colIndex)"
54
+ >
55
+ <transition-group
56
+ name="fade"
57
+ tag="div"
58
+ class="widget-col-list"
59
+ >
60
+ <template v-for="(el, i) in col.list">
61
+ <widget-form-item
62
+ :key="el.key"
63
+ v-if="el.key"
64
+ :element="el"
65
+ :select.sync="selectWidget"
66
+ :index="i"
67
+ :data="col"
68
+ >
69
+ </widget-form-item>
70
+ </template>
71
+ </transition-group>
72
+ </draggable>
73
+ </el-col>
74
+ <div
75
+ class="widget-view-action widget-col-action"
76
+ v-if="selectWidget.key == element.key"
77
+ >
78
+ <i
79
+ class="iconfont icon-trash"
80
+ @click.stop="handleWidgetDelete(index)"
81
+ ></i>
82
+ </div>
83
+
84
+ <div
85
+ class="widget-view-drag widget-col-drag"
86
+ v-if="selectWidget.key == element.key"
87
+ >
88
+ <i class="iconfont icon-drag drag-widget"></i>
89
+ </div>
90
+ </el-row>
91
+ </template>
92
+ <template v-else>
93
+ <widget-form-item
94
+ v-if="element && element.key"
95
+ :key="element.key"
96
+ :element="element"
97
+ :select.sync="selectWidget"
98
+ :index="index"
99
+ :data="data"
100
+ ></widget-form-item>
101
+ </template>
102
+ </template>
103
+ </transition-group>
104
+ </draggable>
105
+ </el-form>
106
+ </div>
107
+ </template>
108
+
109
+ <script>
110
+ import Draggable from "vuedraggable";
111
+ import WidgetFormItem from "./WidgetFormItem";
112
+
113
+ export default {
114
+ components: {
115
+ Draggable,
116
+ WidgetFormItem
117
+ },
118
+ props: ["data", "select"],
119
+ data() {
120
+ return {
121
+ selectWidget: this.select
122
+ };
123
+ },
124
+ mounted() {
125
+ document.body.ondrop = function(event) {
126
+ let isFirefox = navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
127
+ if (isFirefox) {
128
+ event.preventDefault();
129
+ event.stopPropagation();
130
+ }
131
+ };
132
+ },
133
+ methods: {
134
+ handleMoveEnd({ newIndex, oldIndex }) {},
135
+ handleSelectWidget(index) {
136
+ this.selectWidget = this.data.list[index];
137
+ },
138
+ handleWidgetAdd(evt) {
139
+ const newIndex = evt.newIndex;
140
+ const to = evt.to;
141
+
142
+ //为拖拽到容器的元素添加唯一 key
143
+ const key =
144
+ Date.parse(new Date()) + "_" + Math.ceil(Math.random() * 99999);
145
+ this.$set(this.data.list, newIndex, {
146
+ ...this.data.list[newIndex],
147
+ options: {
148
+ ...this.data.list[newIndex].options,
149
+ // remoteFunc: "func_" + key
150
+ },
151
+ key,
152
+ // 绑定键值
153
+ model: this.data.list[newIndex].type + "_" + key,
154
+ rules: []
155
+ });
156
+
157
+ if (
158
+ this.data.list[newIndex].type === "radio" ||
159
+ this.data.list[newIndex].type === "checkbox" ||
160
+ this.data.list[newIndex].type === "select"
161
+ ) {
162
+ this.$set(this.data.list, newIndex, {
163
+ ...this.data.list[newIndex],
164
+ options: {
165
+ ...this.data.list[newIndex].options,
166
+ options: this.data.list[newIndex].options.options.map(item => ({
167
+ ...item
168
+ }))
169
+ }
170
+ });
171
+ }
172
+
173
+ if (this.data.list[newIndex].type === "grid") {
174
+ this.$set(this.data.list, newIndex, {
175
+ ...this.data.list[newIndex],
176
+ columns: this.data.list[newIndex].columns.map(item => ({ ...item }))
177
+ });
178
+ }
179
+
180
+ this.selectWidget = this.data.list[newIndex];
181
+ },
182
+ handleWidgetColAdd($event, row, colIndex) {
183
+ console.log("coladd", $event, row, colIndex);
184
+ const newIndex = $event.newIndex;
185
+ const oldIndex = $event.oldIndex;
186
+ const item = $event.item;
187
+
188
+ // 防止布局元素的嵌套拖拽
189
+ if (item.className.indexOf("data-grid") >= 0) {
190
+ // 如果是列表中拖拽的元素需要还原到原来位置
191
+ item.tagName === "DIV" &&
192
+ this.data.list.splice(
193
+ oldIndex,
194
+ 0,
195
+ row.columns[colIndex].list[newIndex]
196
+ );
197
+
198
+ row.columns[colIndex].list.splice(newIndex, 1);
199
+
200
+ return false;
201
+ }
202
+
203
+ console.log("from", item);
204
+
205
+ const key =
206
+ Date.parse(new Date()) + "_" + Math.ceil(Math.random() * 99999);
207
+
208
+ this.$set(row.columns[colIndex].list, newIndex, {
209
+ ...row.columns[colIndex].list[newIndex],
210
+ options: {
211
+ ...row.columns[colIndex].list[newIndex].options,
212
+ // remoteFunc: "func_" + key
213
+ },
214
+ key,
215
+ // 绑定键值
216
+ model: row.columns[colIndex].list[newIndex].type + "_" + key,
217
+ rules: []
218
+ });
219
+
220
+ if (
221
+ row.columns[colIndex].list[newIndex].type === "radio" ||
222
+ row.columns[colIndex].list[newIndex].type === "checkbox" ||
223
+ row.columns[colIndex].list[newIndex].type === "select"
224
+ ) {
225
+ this.$set(row.columns[colIndex].list, newIndex, {
226
+ ...row.columns[colIndex].list[newIndex],
227
+ options: {
228
+ ...row.columns[colIndex].list[newIndex].options,
229
+ options: row.columns[colIndex].list[newIndex].options.options.map(
230
+ item => ({
231
+ ...item
232
+ })
233
+ )
234
+ }
235
+ });
236
+ }
237
+
238
+ this.selectWidget = row.columns[colIndex].list[newIndex];
239
+ },
240
+ handleWidgetDelete(index) {
241
+ if (this.data.list.length - 1 === index) {
242
+ if (index === 0) {
243
+ this.selectWidget = {};
244
+ } else {
245
+ this.selectWidget = this.data.list[index - 1];
246
+ }
247
+ } else {
248
+ this.selectWidget = this.data.list[index + 1];
249
+ }
250
+
251
+ this.$nextTick(() => {
252
+ this.data.list.splice(index, 1);
253
+ });
254
+ }
255
+ },
256
+ watch: {
257
+ select(val) {
258
+ this.selectWidget = val;
259
+ },
260
+ selectWidget: {
261
+ handler(val) {
262
+ this.$emit("update:select", val);
263
+ },
264
+ deep: true
265
+ }
266
+ }
267
+ };
268
+ </script>