Skip to content

Commit

Permalink
feat(@0.9.0): 布局组件新增禁止嵌套提醒,子表单仅支持拖拽表单组件提醒
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed Mar 10, 2021
1 parent 0d615ab commit ee72394
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "element-pro-crud",
"version": "0.8.9",
"version": "0.9.0",
"author": "BoBo<[email protected]>",
"main": "lib/ProCrud.umd.min.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/component/form-designer/src/FormDesigner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
</div>
</el-header>
<el-main class="config-content">
<WidgetConfig v-show="configTab == 'widget'" v-if="Object.keys(widgetFormSelect).length > 0" :dictType="dictType" :elementConfig="widgetFormSelect"></WidgetConfig>
<WidgetConfig v-show="configTab == 'widget'" v-if="widgetFormSelect && Object.keys(widgetFormSelect).length > 0" :dictType="dictType" :elementConfig="widgetFormSelect"></WidgetConfig>
<FormConfig v-show="configTab == 'form'" :data="widgetForm.config"></FormConfig>
</el-main>
</el-container>
Expand Down
10 changes: 7 additions & 3 deletions src/component/form-designer/src/WidgetForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,15 @@ export default {
},
handleWidgetTdAdd($event, col) {
const { newIndex, oldIndex, item } = $event;
const newItem = col.list[newIndex];
// 防止布局元素的嵌套拖拽
if (item.className.indexOf('data-grid') >= 0) {
col.list[newIndex].splice(newIndex, 1);
if (['tabs', 'grid', 'grid-table'].includes(newItem.type)) {
col.list.splice(newIndex, 1);
this.$message.warning('布局元素暂不支持嵌套');
return false;
}
this.selectWidget = col.list[newIndex];
this.selectWidget = newItem;
return null;
},
handleWidgetColAdd($event, row, colIndex) {
Expand All @@ -364,6 +367,7 @@ export default {
this.data.list.splice(oldIndex, 0, row.columns[colIndex].list[newIndex]);
}
row.columns[colIndex].list.splice(newIndex, 1);
this.$message.warning('布局元素暂不支持嵌套');
return false;
}
this.selectWidget = row.columns[colIndex].list[newIndex];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
Component, Vue, Prop, Watch,
} from 'vue-property-decorator';
import Draggable from 'vuedraggable';
import { formElement } from '../../componentsConfig';

@Component({
name: 'WidgetSubForm',
Expand Down Expand Up @@ -114,13 +115,23 @@ export default class WidgetSubForm extends Vue {

selectWidget = this.select;

formElement = formElement

handleSelectWidget(index) {
this.selectWidget = this.element.tableColumns[index];
}

handleWidgetAdd(evt) {
const { newIndex } = evt;
const { model, type } = this.element.tableColumns[newIndex];

// 防止布局元素的嵌套拖拽
if (!formElement.includes(type)) {
this.element.tableColumns.splice(newIndex, 1);
this.$message.warning('仅支持拖拽表单组件');
return false;
}

// 为拖拽到容器的元素添加唯一 key
const key = model || `${type}_${Math.ceil(Math.random() * 99999)}`;
this.$set(this.element.tableColumns, newIndex, {
Expand Down Expand Up @@ -153,6 +164,7 @@ export default class WidgetSubForm extends Vue {
}
console.log(this.element.tableColumns[newIndex]);
this.selectWidget = this.element.tableColumns[newIndex];
return null;
}

handleWidgetDelete(index) {
Expand Down
28 changes: 19 additions & 9 deletions src/component/form-designer/src/components/Tabs/WidgetTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
:gutter="element.options.gutter ? element.options.gutter : 0"
:justify="element.options.justify"
:align="element.options.align"
@click.native="handleSelectWidget(index)"
@click.native.stop="handleSelectWidget(element)"
>
<el-col v-for="(col, colIndex) in element.columns" :key="colIndex" :span="col.span ? col.span : 0">
<Draggable
Expand All @@ -57,7 +57,7 @@
:element="el"
:select.sync="selectWidget"
:index="i"
@click.native="handleSelectWidget(i)"
@click.native="handleSelectWidget(el)"
:data="col"
></WidgetFormItem>
</transition-group>
Expand Down Expand Up @@ -86,7 +86,7 @@
:select.sync="selectWidget"
:index="index"
:data="data"
@click.native="handleSelectWidget(index)"
@click.native="handleSelectWidget(element)"
></WidgetFormItem>
</template>
</transition-group>
Expand All @@ -96,6 +96,9 @@
<div class="widget-view-drag widget-col-drag" v-if="selectWidget.key == element.key">
<i class="drag-widget el-icon el-icon-rank"></i>
</div>
<div class="widget-view-action" v-if="selectWidget.key == element.key">
<i class="el-icon el-icon-delete-solid" @click.stop="handleWidgetDelete()"></i>
</div>
</div>
</template>

Expand Down Expand Up @@ -135,19 +138,25 @@ export default class WidgetTabs extends Vue {
})
data!: any

@Prop({
type: Number,
default: null,
})
index!: number

activeName = '标签页1'

selectWidget = this.select

handleSelectWidget(index) {
const currentTab = this.element.items.find(_ => _.name === this.activeName);
this.selectWidget = currentTab.list[index];
handleSelectWidget(element) {
this.selectWidget = element;
}

handleWidgetColAdd($event, row, colIndex) {
const { newIndex } = $event;
const { oldIndex } = $event;
const { item } = $event;
console.log(item.className);
// 防止布局元素的嵌套拖拽
if (item.className.indexOf('data-grid') >= 0) {
// 如果是列表中拖拽的元素需要还原到原来位置
Expand All @@ -174,7 +183,7 @@ export default class WidgetTabs extends Vue {
});
}

handleWidgetDelete(index) {
handleWidgetDelete(index = this.index) {
if (this.data.list.length - 1 === index) {
if (index === 0) {
this.selectWidget = {};
Expand Down Expand Up @@ -214,9 +223,10 @@ export default class WidgetTabs extends Vue {
const { newIndex, item, oldIndex } = evt;
const { list } = currentTab;
const newItem = list[newIndex];
// 防止tab布局元素的嵌套拖拽
if (newItem.type === 'tabs') {
// 防止布局元素的嵌套拖拽
if (['tabs', 'grid-table'].includes(newItem.type)) {
list.splice(newIndex, 1);
this.$message.warning('布局元素暂不支持嵌套');
return false;
}
this.selectWidget = newItem;
Expand Down
2 changes: 1 addition & 1 deletion src/component/form-designer/src/componentsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export const layoutComponents = [
{
type: 'grid-table',
name: '表格布局',
icon: 'th',
icon: 'table',
options: {
borderWidth: 1,
borderColor: '#999',
Expand Down
1 change: 1 addition & 0 deletions src/component/form-designer/src/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ import 'vue-awesome/icons/file-word';
import 'vue-awesome/icons/chart-bar';
import 'vue-awesome/icons/tags';
import 'vue-awesome/icons/user';
import 'vue-awesome/icons/table';

0 comments on commit ee72394

Please sign in to comment.