Skip to content

Commit

Permalink
perf(FormDesignerModule): some change
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed Feb 19, 2021
1 parent b9f003d commit fd1035c
Showing 1 changed file with 83 additions and 75 deletions.
158 changes: 83 additions & 75 deletions src/views/devTools/FormDesignerModule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</template>
</CrudTable>
<el-dialog v-if="visible" ref="dialog" fullscreen class="dialog" :visible.sync="visible" append-to-body>
<FormDesigner ref="formDesigner" :getFormKey="getFormKey" :allTables="allTables">
<FormDesigner ref="formDesigner" :dictType="dictType" :getFormKey="getFormKey" :allTables="allTables">
<template #custom-btn>
<el-button type="normal" size="small" @click="btnSaveOnClick" :loading="btnSaveIsLoading">保存</el-button>
</template>
Expand Down Expand Up @@ -54,90 +54,98 @@ export default class FormDesignerModule extends Vue {

formValues = {};

created() {
getTables().then((res) => {
this.allTables = res.data.map(item => ({
label: item.TABLE_NAME,
value: item.TABLE_NAME,
}));
});
}
dictType = [];

getFormKey(tablename) {
return getFormKey(tablename);
}
created() {
crud(DML.SELECT, 'ad_codelist_type').then((res) => {
this.dictType = res.data.list.map(item => ({
label: item.typeName,
value: item.id,
}));
});
getTables().then((res) => {
this.allTables = res.data.map(item => ({
label: item.TABLE_NAME,
value: item.TABLE_NAME,
}));
});
}

// 添加按钮点击事件
btnAddOnClick() {
this.formValues = {};
this.visible = true;
}
getFormKey(tablename) {
return getFormKey(tablename);
}

// 编辑按钮点击事件
btnEditOnClick(row) {
this.formValues = { ...row };
this.visible = true;
this.$nextTick(() => {
this.$refs.formDesigner.setJSON(JSON.parse(row.formJson));
// 添加按钮点击事件
btnAddOnClick() {
this.formValues = {};
this.visible = true;
}

// 编辑按钮点击事件
btnEditOnClick(row) {
this.formValues = { ...row };
this.visible = true;
this.$nextTick(() => {
this.$refs.formDesigner.setJSON(JSON.parse(row.formJson));
});
}

// 复制表单设计json
btnCopyOnClick(row) {
const r = { ...row };
r.tableName += '_复制';
delete r.id;
crud(DML.INSERT, 'form', r).then((res) => {
if (res.code !== 200) {
this.$message({
type: 'error',
message: `保存失败,原因:${res.message}`,
});
return;
}
this.$message({
type: 'success',
message: '复制成功',
});
}
this.$refs.table.tableReload();
});
}

// 复制表单设计json
btnCopyOnClick(row) {
const r = { ...row };
r.tableName += '_复制';
delete r.id;
crud(DML.INSERT, 'form', r).then((res) => {
if (res.code !== 200) {
this.$message({
type: 'error',
message: `保存失败,原因:${res.message}`,
});
return;
}
// 保存设计
btnSaveOnClick() {
const formValues = this.$refs.formDesigner.getData();
this.btnSaveIsLoading = true;
// 调用此方法验证表单数据和获取表单数据
let type;
let msg;
// 根据对话框状态判断保存或编辑
if (this.dialogStatus === STATUS.CREATE) {
type = DML.INSERT;
msg = '添加成功';
} else {
type = DML.UPDATE;
msg = '编辑成功';
}
// 如果有代理的保存方法
crud(type, 'form', {
...this.formValues,
formJson: JSON.stringify(formValues),
tableName: formValues.config.name,
position: formValues.config.position,
})
.then(() => {
this.btnSaveIsLoading = false;
this.$message({
type: 'success',
message: '复制成功',
message: msg,
});
this.visible = false;
this.$refs.table.tableReload();
});
}

// 保存设计
btnSaveOnClick() {
const formValues = this.$refs.formDesigner.getData();
this.btnSaveIsLoading = true;
// 调用此方法验证表单数据和获取表单数据
let type;
let msg;
// 根据对话框状态判断保存或编辑
if (this.dialogStatus === STATUS.CREATE) {
type = DML.INSERT;
msg = '添加成功';
} else {
type = DML.UPDATE;
msg = '编辑成功';
}
// 如果有代理的保存方法
crud(type, 'form', {
...this.formValues,
formJson: JSON.stringify(formValues),
tableName: formValues.config.name,
position: formValues.config.position,
})
.then(() => {
this.btnSaveIsLoading = false;
this.$message({
type: 'success',
message: msg,
});
this.visible = false;
this.$refs.table.tableReload();
})
.catch(() => {
this.btnSaveIsLoading = false;
});
}
.catch(() => {
this.btnSaveIsLoading = false;
});
}
}
</script>
<style lang="scss" scoped>
Expand Down

0 comments on commit fd1035c

Please sign in to comment.