|
@@ -1,21 +1,26 @@
|
|
<template>
|
|
<template>
|
|
<el-form-item
|
|
<el-form-item
|
|
v-if="element && element.key"
|
|
v-if="element && element.key"
|
|
- :label-width="isLabel || !element.options.labelWidthStatus?'0px': elementLabelWidth + 'px'"
|
|
|
|
- class="widget-view "
|
|
|
|
- :class="{active: selectWidget.key === element.key, 'is_req': element.options.required}"
|
|
|
|
- :label="isLabel || element.type==='divider' || !element.options.labelWidthStatus?'':element.name"
|
|
|
|
|
|
+ :label-width="
|
|
|
|
+ isLabel || !element.options.labelWidthStatus
|
|
|
|
+ ? '0px'
|
|
|
|
+ : elementLabelWidth + 'px'
|
|
|
|
+ "
|
|
|
|
+ class="widget-view"
|
|
|
|
+ :class="{
|
|
|
|
+ active: selectWidget.key === element.key,
|
|
|
|
+ is_req: element.options.required,
|
|
|
|
+ }"
|
|
|
|
+ :label="
|
|
|
|
+ isLabel || element.type === 'divider' || !element.options.labelWidthStatus
|
|
|
|
+ ? ''
|
|
|
|
+ : element.name
|
|
|
|
+ "
|
|
@click.native.stop="handleSelectWidget(index)"
|
|
@click.native.stop="handleSelectWidget(index)"
|
|
>
|
|
>
|
|
-
|
|
|
|
<div v-if="isTable">
|
|
<div v-if="isTable">
|
|
- <el-table
|
|
|
|
- :data="[element]"
|
|
|
|
- border
|
|
|
|
- >
|
|
|
|
- <el-table-column
|
|
|
|
- :label="element.name"
|
|
|
|
- >
|
|
|
|
|
|
+ <el-table :data="[element]" border>
|
|
|
|
+ <el-table-column :label="element.name">
|
|
<WidgetFormFields :element="element" />
|
|
<WidgetFormFields :element="element" />
|
|
</el-table-column>
|
|
</el-table-column>
|
|
</el-table>
|
|
</el-table>
|
|
@@ -25,111 +30,149 @@
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div v-if="selectWidget.key == element.key" class="widget-view-action">
|
|
<div v-if="selectWidget.key == element.key" class="widget-view-action">
|
|
- <i class="iconfont icon-icon_clone" @click.stop="handleWidgetClone(index)" />
|
|
|
|
- <i class="iconfont icon-trash" @click.stop="handleWidgetDelete(index)" />
|
|
|
|
|
|
+ <i
|
|
|
|
+ class="iconfont icon-icon_clone"
|
|
|
|
+ @click.stop="handleWidgetClone(index)"
|
|
|
|
+ />
|
|
|
|
+ <i
|
|
|
|
+ class="iconfont icon-trash"
|
|
|
|
+ @click.stop="handleWidgetDelete(index, element)"
|
|
|
|
+ />
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div v-if="selectWidget.key == element.key" class="widget-view-drag">
|
|
<div v-if="selectWidget.key == element.key" class="widget-view-drag">
|
|
<i class="iconfont icon-drag drag-widget" />
|
|
<i class="iconfont icon-drag drag-widget" />
|
|
</div>
|
|
</div>
|
|
-
|
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
-import WidgetFormFields from './WidgetFormFields'
|
|
|
|
|
|
+import WidgetFormFields from "./WidgetFormFields";
|
|
export default {
|
|
export default {
|
|
components: {
|
|
components: {
|
|
- WidgetFormFields
|
|
|
|
|
|
+ WidgetFormFields,
|
|
},
|
|
},
|
|
/* eslint-disable */
|
|
/* eslint-disable */
|
|
- props: ['element', 'select', 'index', 'data', 'dataConfig', 'isLabel', 'isTable'],
|
|
|
|
|
|
+ props: [
|
|
|
|
+ "element",
|
|
|
|
+ "select",
|
|
|
|
+ "index",
|
|
|
|
+ "data",
|
|
|
|
+ "dataConfig",
|
|
|
|
+ "isLabel",
|
|
|
|
+ "isTable",
|
|
|
|
+ ],
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- elementLabelWidth: '',
|
|
|
|
- selectWidget: this.select
|
|
|
|
- }
|
|
|
|
|
|
+ elementLabelWidth: "",
|
|
|
|
+ selectWidget: this.select,
|
|
|
|
+ };
|
|
},
|
|
},
|
|
watch: {
|
|
watch: {
|
|
select(val) {
|
|
select(val) {
|
|
- this.selectWidget = val
|
|
|
|
|
|
+ this.selectWidget = val;
|
|
},
|
|
},
|
|
selectWidget: {
|
|
selectWidget: {
|
|
handler(val) {
|
|
handler(val) {
|
|
- this.$emit('update:select', val)
|
|
|
|
|
|
+ this.$emit("update:select", val);
|
|
},
|
|
},
|
|
- deep: true
|
|
|
|
|
|
+ deep: true,
|
|
},
|
|
},
|
|
- 'element.options.labelWidth': function (val) {
|
|
|
|
- this.elementLabelWidth = val
|
|
|
|
|
|
+ "element.options.labelWidth": function (val) {
|
|
|
|
+ this.elementLabelWidth = val;
|
|
},
|
|
},
|
|
- 'element.options.labelWidthDisabled': function (val) {
|
|
|
|
- this.setLabelWidth(val)
|
|
|
|
|
|
+ "element.options.labelWidthDisabled": function (val) {
|
|
|
|
+ this.setLabelWidth(val);
|
|
},
|
|
},
|
|
- 'dataConfig.config.labelWidth': function (val) {
|
|
|
|
- if (!this.element.options.labelWidthDisabled && this.element.type!=='divider') {
|
|
|
|
- this.elementLabelWidth = val
|
|
|
|
|
|
+ "dataConfig.config.labelWidth": function (val) {
|
|
|
|
+ if (
|
|
|
|
+ !this.element.options.labelWidthDisabled &&
|
|
|
|
+ this.element.type !== "divider"
|
|
|
|
+ ) {
|
|
|
|
+ this.elementLabelWidth = val;
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ },
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
- this.setLabelWidth()
|
|
|
|
|
|
+ this.setLabelWidth();
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
setLabelWidth(status) {
|
|
setLabelWidth(status) {
|
|
if (status === undefined) {
|
|
if (status === undefined) {
|
|
- status = this.element.options.labelWidthDisabled
|
|
|
|
|
|
+ status = this.element.options.labelWidthDisabled;
|
|
}
|
|
}
|
|
if (status) {
|
|
if (status) {
|
|
- this.elementLabelWidth = this.element.options.labelWidth
|
|
|
|
- } else if (this.element.type==='divider') {
|
|
|
|
- this.elementLabelWidth = 0
|
|
|
|
|
|
+ this.elementLabelWidth = this.element.options.labelWidth;
|
|
|
|
+ } else if (this.element.type === "divider") {
|
|
|
|
+ this.elementLabelWidth = 0;
|
|
} else {
|
|
} else {
|
|
// 全局
|
|
// 全局
|
|
- this.elementLabelWidth = this.dataConfig.config.labelWidth
|
|
|
|
|
|
+ this.elementLabelWidth = this.dataConfig.config.labelWidth;
|
|
}
|
|
}
|
|
},
|
|
},
|
|
handleSelectWidget(index) {
|
|
handleSelectWidget(index) {
|
|
- this.selectWidget = this.data.list[index]
|
|
|
|
|
|
+ this.selectWidget = this.data.list[index];
|
|
},
|
|
},
|
|
- handleWidgetDelete(index) {
|
|
|
|
|
|
+ handleWidgetDelete(index, element) {
|
|
|
|
+ console.log(index, element, this.data);
|
|
if (this.data.list.length - 1 === index) {
|
|
if (this.data.list.length - 1 === index) {
|
|
if (index === 0) {
|
|
if (index === 0) {
|
|
- this.selectWidget = {}
|
|
|
|
|
|
+ this.selectWidget = {};
|
|
} else {
|
|
} else {
|
|
- this.selectWidget = this.data.list[index - 1]
|
|
|
|
|
|
+ this.selectWidget = this.data.list[index - 1];
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- this.selectWidget = this.data.list[index + 1]
|
|
|
|
|
|
+ this.selectWidget = this.data.list[index + 1];
|
|
}
|
|
}
|
|
|
|
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
- this.data.list.splice(index, 1)
|
|
|
|
- })
|
|
|
|
|
|
+ // 判断当前组件是否有关联,如果有关联则删除
|
|
|
|
+ const list = this.data.list || [];
|
|
|
|
+ list.forEach((item) => {
|
|
|
|
+ // 判断是否是下拉组件,是否设置了选项关联
|
|
|
|
+ if (item.type == "select" && item.options.relationStatus) {
|
|
|
|
+ const options = item.options.options || [];
|
|
|
|
+ options.forEach((option) => {
|
|
|
|
+ const relationOptions = option.relationOptions || [];
|
|
|
|
+ const index =
|
|
|
|
+ relationOptions.findIndex((r) => r == element.model) || -1;
|
|
|
|
+ if (index > -1) {
|
|
|
|
+ option.relationOptions.splice(index, 1);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ // 删除组件
|
|
|
|
+ this.data.list.splice(index, 1);
|
|
|
|
+ });
|
|
},
|
|
},
|
|
handleWidgetClone(index) {
|
|
handleWidgetClone(index) {
|
|
let cloneData = {
|
|
let cloneData = {
|
|
...this.data.list[index],
|
|
...this.data.list[index],
|
|
options: { ...this.data.list[index].options },
|
|
options: { ...this.data.list[index].options },
|
|
- key: Date.parse(new Date()) + '_' + Math.ceil(Math.random() * 99999)
|
|
|
|
- }
|
|
|
|
- cloneData.model = cloneData.type + '_' + cloneData.key
|
|
|
|
- if (this.data.list[index].type === 'radio' || this.data.list[index].type === 'checkbox' || this.data.list[index].type === 'select') {
|
|
|
|
|
|
+ key: Date.parse(new Date()) + "_" + Math.ceil(Math.random() * 99999),
|
|
|
|
+ };
|
|
|
|
+ cloneData.model = cloneData.type + "_" + cloneData.key;
|
|
|
|
+ if (
|
|
|
|
+ this.data.list[index].type === "radio" ||
|
|
|
|
+ this.data.list[index].type === "checkbox" ||
|
|
|
|
+ this.data.list[index].type === "select"
|
|
|
|
+ ) {
|
|
cloneData = {
|
|
cloneData = {
|
|
...cloneData,
|
|
...cloneData,
|
|
options: {
|
|
options: {
|
|
...cloneData.options,
|
|
...cloneData.options,
|
|
- options: cloneData.options.options.map(item => ({ ...item }))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ options: cloneData.options.options.map((item) => ({ ...item })),
|
|
|
|
+ },
|
|
|
|
+ };
|
|
}
|
|
}
|
|
|
|
|
|
- this.data.list.splice(index, 0, cloneData)
|
|
|
|
|
|
+ this.data.list.splice(index, 0, cloneData);
|
|
|
|
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
- this.selectWidget = this.data.list[index + 1]
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ this.selectWidget = this.data.list[index + 1];
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+};
|
|
</script>
|
|
</script>
|