update SmallDialog

This commit is contained in:
lb 2023-02-03 15:14:07 +08:00
parent 0c1252467e
commit 70243b527f
3 changed files with 173 additions and 210 deletions

View File

@ -205,9 +205,6 @@ export default {
}, },
}, },
methods: { methods: {
k() {
console.log("[DialogWithMenu] closed");
},
/** utitilities */ /** utitilities */
showButton(operate) { showButton(operate) {
const notDetailMode = !this.detailMode; const notDetailMode = !this.detailMode;

View File

@ -15,28 +15,10 @@
<!-- :append-to-body="appendToBody"> --> <!-- :append-to-body="appendToBody"> -->
<div> <div>
<el-form ref="dataForm" :model="dataForm"> <el-form ref="dataForm" :model="dataForm">
<el-row <el-row v-for="(row, rowIndex) in configs.rows" :key="'row_' + rowIndex" :gutter="20">
v-for="(row, rowIndex) in configs.rows" <el-col v-for="(col, colIndex) in row" :key="colIndex" :span="col.span ?? 24 / row.length">
:key="'row_' + rowIndex" <el-form-item :prop="col.prop" :rules="col.rules || null" :label="col.label">
:gutter="20" <el-input v-if="col.input" v-model="dataForm[col.prop]" clearable :disabled="detailMode" v-bind="col.elparams" />
>
<el-col
v-for="(col, colIndex) in row"
:key="colIndex"
:span="col.span ?? 24 / row.length"
>
<el-form-item
:prop="col.prop"
:rules="col.rules || null"
:label="col.label"
>
<el-input
v-if="col.input"
v-model="dataForm[col.prop]"
clearable
:disabled="detailMode"
v-bind="col.elparams"
/>
<el-select <el-select
v-if="col.select" v-if="col.select"
v-model="dataForm[col.prop]" v-model="dataForm[col.prop]"
@ -45,12 +27,7 @@
v-bind="col.elparams" v-bind="col.elparams"
@change="handleSelectChange(col, $event)" @change="handleSelectChange(col, $event)"
> >
<el-option <el-option v-for="(opt, optIdx) in col.options" :key="'option_' + optIdx" :label="opt.label" :value="opt.value" />
v-for="(opt, optIdx) in col.options"
:key="'option_' + optIdx"
:label="opt.label"
:value="opt.value"
/>
</el-select> </el-select>
<el-switch <el-switch
v-if="col.switch" v-if="col.switch"
@ -60,13 +37,7 @@
@change="handleSwitchChange" @change="handleSwitchChange"
:disabled="detailMode" :disabled="detailMode"
/> />
<el-input <el-input v-if="col.textarea" type="textarea" v-model="dataForm[col.prop]" :disabled="detailMode" v-bind="col.elparams" />
v-if="col.textarea"
type="textarea"
v-model="dataForm[col.prop]"
:disabled="detailMode"
v-bind="col.elparams"
/>
<!-- add more... --> <!-- add more... -->
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -77,13 +48,9 @@
<!-- footer --> <!-- footer -->
<div slot="footer"> <div slot="footer">
<template v-for="(operate, index) in configs.operations"> <template v-for="(operate, index) in configs.operations">
<el-button <el-button v-if="showButton(operate)" :key="'operation_' + index" :type="operate.type" @click="handleBtnClick(operate)">{{
v-if="showButton(operate)" operate.label
:key="'operation_' + index" }}</el-button>
:type="operate.type"
@click="handleBtnClick(operate)"
>{{ operate.label }}</el-button
>
</template> </template>
<el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button> <el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button>
</div> </div>
@ -134,12 +101,8 @@ export default {
const showAlways = operate.showAlways ?? false; const showAlways = operate.showAlways ?? false;
const editMode = operate.showOnEdit && this.dataForm.id; const editMode = operate.showOnEdit && this.dataForm.id;
const addMode = !operate.showOnEdit && !this.dataForm.id; const addMode = !operate.showOnEdit && !this.dataForm.id;
const permission = operate.permission const permission = operate.permission ? this.$hasPermission(operate.permission) : true;
? this.$hasPermission(operate.permission) return notDetailMode && (showAlways || ((editMode || addMode) && permission));
: true;
return (
notDetailMode && (showAlways || ((editMode || addMode) && permission))
);
}, },
resetForm(excludeId = false) { resetForm(excludeId = false) {
setTimeout(() => { setTimeout(() => {
@ -156,7 +119,7 @@ export default {
console.log("[small dialog] init", id, isdetail); console.log("[small dialog] init", id, isdetail);
this.detailMode = isdetail; this.detailMode = isdetail;
if (this.$refs.dataForm) this.$refs.dataForm.clearValidate() if (this.$refs.dataForm) this.$refs.dataForm.clearValidate();
this.$nextTick(() => { this.$nextTick(() => {
// this.$refs['dataForm'].resetFields(); // this.$refs['dataForm'].resetFields();
@ -164,9 +127,7 @@ export default {
if (this.dataForm.id) { if (this.dataForm.id) {
// //
this.$http this.$http.get(this.urls.subase + `/${this.dataForm.id}`).then(({ data: res }) => {
.get(this.urls.subase + `/${this.dataForm.id}`)
.then(({ data: res }) => {
if (res && res.code === 0) { if (res && res.code === 0) {
const dataFormKeys = Object.keys(this.dataForm); const dataFormKeys = Object.keys(this.dataForm);
this.dataForm = __pick(res.data, dataFormKeys); this.dataForm = __pick(res.data, dataFormKeys);
@ -175,7 +136,7 @@ export default {
}); });
} else { } else {
// //
this.visible = true this.visible = true;
} }
}); });
}, },
@ -193,20 +154,24 @@ export default {
break; break;
case "add": case "add":
case "update": { case "update": {
console.log('update extraParam: ', this.configs.extraParam) console.log("update extraParam: ", this.configs.extraParam);
const method = payload.name === "add" ? "POST" : "PUT"; const method = payload.name === "add" ? "POST" : "PUT";
const fields = {};
fields[this.configs.extraParam] = this.relatedId;
// [this.configs.extraParam]: this.relatedId, // this.configs.extraParam
if (this.configs.forceAttachCode) fields["code"] = "";
this.$http({ this.$http({
url: this.urls.subase, url: this.urls.subase,
method, method,
data: { data: {
...this.dataForm, ...this.dataForm,
[this.configs.extraParam]: this.relatedId, // this.configs.extraParam ...fields
}, },
}).then(({ data: res }) => { }).then(({ data: res }) => {
console.log("[add&update] res is: ", res); console.log("[add&update] res is: ", res);
this.$message.success( this.$message.success(payload.name === "add" ? "添加成功" : "更新成功");
payload.name === "add" ? "添加成功" : "更新成功"
);
this.$emit("refreshDataList"); this.$emit("refreshDataList");
this.handleClose(); this.handleClose();
}); });

View File

@ -117,6 +117,7 @@ export default function () {
subDialog: { subDialog: {
extraParam: 'productId', extraParam: 'productId',
forceAttachCode: true, // 产品属性新增必填 code 字段......
rows: [ rows: [
[ [
{ input: true, label: '属性名称', prop: 'name', rules: { required: true, message: 'not empty', trigger: 'blur' }, elparams: { placeholder: '请输入属性名称' } }, { input: true, label: '属性名称', prop: 'name', rules: { required: true, message: 'not empty', trigger: 'blur' }, elparams: { placeholder: '请输入属性名称' } },