mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
218 lines
7.8 KiB
Plaintext
218 lines
7.8 KiB
Plaintext
<template>
|
|
<div class="system-{{.BusinessName}}-container">
|
|
<el-dialog v-model="isShowDialog" width="769px" center>
|
|
<template #title>
|
|
<div style="font-size: large" v-drag="['.system-{{.BusinessName}}-container .el-dialog', '.system-{{.BusinessName}}-container .el-dialog__header']">{{"{{"}}title{{"}}"}}</div>
|
|
</template>
|
|
<el-form
|
|
:model="ruleForm"
|
|
:rules="ruleRules"
|
|
ref="ruleFormRef"
|
|
label-width="80px"
|
|
>
|
|
{{- range $index, $column := .Columns -}}
|
|
{{- if and (eq $column.IsInsert "1") (ne $column.IsPk "1") (ne $column.JsonField "createTime") (ne $column.JsonField "updateTime") (ne $column.JsonField "deleteTime") -}}
|
|
{{- if eq $column.HtmlType "input" }}
|
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.JsonField}}">
|
|
<el-input v-model="ruleForm.{{$column.JsonField}}" placeholder="请输入{{$column.ColumnComment}}" />
|
|
</el-form-item>
|
|
{{- else if eq $column.HtmlType "switch" }}
|
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.JsonField}}">
|
|
<el-switch v-model="ruleForm.{{$column.HtmlField}}" />
|
|
</el-form-item>
|
|
{{- else if eq $column.HtmlType "select" }}
|
|
{{if ne $column.DictType ""}}
|
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.JsonField}}">
|
|
<el-select v-model="ruleForm.{{$column.JsonField}}" placeholder="请选择{{$column.ColumnComment}}">
|
|
<el-option
|
|
v-for="dict in {{$column.JsonField}}Options"
|
|
:key="dict.dictValue"
|
|
:label="dict.dictLabel"
|
|
>{{"{{"}} dict.dictLabel {{"}}"}}</el-option>
|
|
</el-select>
|
|
</el-form-item>
|
|
{end }}
|
|
{{- else if eq $column.HtmlType "radio" }}
|
|
{{if ne $column.DictType ""}}
|
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.JsonField}}">
|
|
<el-radio-group v-model="ruleForm.{{$column.JsonField}}">
|
|
<el-radio
|
|
v-for="dict in {{$column.JsonField}}Options"
|
|
:key="dict.dictValue"
|
|
:label="dict.dictLabel"
|
|
>{{"{{"}} dict.dictLabel {{"}}"}}</el-radio>
|
|
</el-radio-group>
|
|
</el-form-item>
|
|
{{- end }}
|
|
{{- else if eq $column.HtmlType "datetime" }}
|
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.JsonField}}">
|
|
<el-date-picker clearable style="width: 200px"
|
|
v-model="ruleForm.{{$column.JsonField}}"
|
|
type="datetime"
|
|
placeholder="选择{{$column.ColumnComment}}">
|
|
</el-date-picker>
|
|
</el-form-item>
|
|
{{- else if eq $column.HtmlType "textarea" -}}
|
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.JsonField}}">
|
|
<el-input v-model="ruleForm.{{$column.HtmlField}}" type="textarea" placeholder="请输入{{$column.ColumnComment}}" />
|
|
</el-form-item>
|
|
{{- else if eq $column.HtmlType "checkbox" }}
|
|
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.ruleForm}}">
|
|
<el-checkbox-group v-model="ruleForm.{{$column.ruleForm}}">
|
|
<el-checkbox
|
|
v-for="dict in {{$column.ruleForm}}Options"
|
|
:key="dict.dictValue"
|
|
:label="dict.dictLabel"
|
|
>{{"{{"}} dict.dictLabel {{"}}"}}</el-checkbox>
|
|
</el-checkbox-group>
|
|
</el-form-item>
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end }}
|
|
</el-form>
|
|
<template #footer>
|
|
<span class="dialog-footer">
|
|
<el-button @click="onCancel">取 消</el-button>
|
|
<el-button type="primary" @click="onSubmit">编 辑</el-button>
|
|
</span>
|
|
</template>
|
|
</el-dialog>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { reactive, toRefs, ref, unref, getCurrentInstance } from "vue";
|
|
import { update{{.FunctionName}}, add{{.FunctionName}} } from "@/api/{{.PackageName}}/{{.BusinessName}}";
|
|
import { ElMessage } from "element-plus";
|
|
|
|
export default {
|
|
name: "editMenu",
|
|
props: {
|
|
// 弹窗标题
|
|
title: {
|
|
type: String,
|
|
default: () => "",
|
|
},
|
|
},
|
|
setup() {
|
|
const { proxy } = getCurrentInstance() as any;
|
|
const ruleFormRef = ref<HTMLElement | null>(null);
|
|
const state = reactive({
|
|
// 是否显示弹出层
|
|
isShowDialog: false,
|
|
loading: false,
|
|
ruleForm: {
|
|
{{- range $index, $column := .Columns -}}
|
|
{{- if or (eq $column.IsInsert "1") (eq $column.IsPk "1") }}
|
|
{{- if or (eq $column.GoType "int") (eq $column.GoType "int64")}}
|
|
{{$column.JsonField}}: 0,
|
|
{{- else if eq $column.GoType "string"}}
|
|
{{$column.JsonField}}: "",
|
|
{{- else }}
|
|
{{$column.JsonField}}: undefined,
|
|
{{- end}}
|
|
{{- end}}
|
|
{{- end}}
|
|
},
|
|
{{- range $index, $column := .Columns -}}
|
|
{{- if ne $column.DictType "" }}
|
|
// {{$column.JsonField}}Options字典数据
|
|
{{$column.JsonField}}Options: [],
|
|
{{- end -}}
|
|
{{- end }}
|
|
// 表单校验
|
|
ruleRules: {
|
|
{{- range $index, $column := .Columns -}}
|
|
{{- if eq $column.IsRequired "1" }}
|
|
{{$column.JsonField}}: [
|
|
{ required: true, message: "{{$column.ColumnComment}}不能为空", trigger: "blur" }
|
|
],
|
|
{{- end}}
|
|
{{- end}}
|
|
},
|
|
});
|
|
// 打开弹窗
|
|
const openDialog = (row: any) => {
|
|
if (row.{{.PkJsonField}} && row.{{.PkJsonField}} != undefined && row.{{.PkJsonField}} != 0) {
|
|
state.ruleForm.{{.PkJsonField}}=row.{{.PkJsonField}}; // ID
|
|
{{- range $index, $column := .Columns -}}
|
|
{{- if eq $column.IsInsert "1" }}
|
|
state.ruleForm.{{$column.JsonField}} = row.{{$column.JsonField}}
|
|
{{- end}}
|
|
{{- end}}
|
|
// 更多参数
|
|
} else {
|
|
initForm();
|
|
}
|
|
state.isShowDialog = true;
|
|
state.loading = false;
|
|
{{- range $index, $column := .Columns -}}
|
|
{{- if ne $column.DictType "" }}
|
|
proxy.getDicts("{{$column.DictType}}").then((response: any) => {
|
|
state.{{$column.JsonField}}Options = response.data;
|
|
});
|
|
{{- end -}}
|
|
{{- end}}
|
|
}
|
|
|
|
// 关闭弹窗
|
|
const closeDialog = (row?: object) => {
|
|
proxy.mittBus.emit("onEdit{{.FunctionName}}Module", row);
|
|
state.isShowDialog = false;
|
|
};
|
|
// 取消
|
|
const onCancel = () => {
|
|
closeDialog();
|
|
};
|
|
|
|
// 保存
|
|
const onSubmit = () => {
|
|
const formWrap = unref(ruleFormRef) as any;
|
|
if (!formWrap) return;
|
|
formWrap.validate((valid: boolean) => {
|
|
if (valid) {
|
|
state.loading = true;
|
|
if (state.ruleForm.{{.PkJsonField}} != undefined && state.ruleForm.{{.PkJsonField}} != 0) {
|
|
update{{.FunctionName}}(state.ruleForm).then((response) => {
|
|
ElMessage.success("修改成功");
|
|
state.loading = false;
|
|
closeDialog(state.ruleForm); // 关闭弹窗
|
|
});
|
|
} else {
|
|
add{{.FunctionName}}(state.ruleForm).then((response) => {
|
|
ElMessage.success("新增成功");
|
|
closeDialog(state.ruleForm); // 关闭弹窗
|
|
});
|
|
}
|
|
}
|
|
});
|
|
};
|
|
// 表单初始化,方法:`resetFields()` 无法使用
|
|
const initForm = () => {
|
|
state.ruleForm.{{.PkJsonField}} = 0; // ID
|
|
{{- range $index, $column := .Columns -}}
|
|
{{- if or (eq $column.IsInsert "1") (eq $column.IsPk "1") }}
|
|
{{- if or (eq $column.GoType "int") (eq $column.GoType "int64")}}
|
|
state.ruleForm.{{$column.JsonField}} = 0;
|
|
{{- else if eq $column.GoType "string"}}
|
|
state.ruleForm.{{$column.JsonField}} = "";
|
|
{{- else }}
|
|
state.ruleForm.{{$column.JsonField}} = undefined;
|
|
{{- end}}
|
|
{{- end}}
|
|
{{- end}}
|
|
};
|
|
|
|
return {
|
|
ruleFormRef,
|
|
openDialog,
|
|
closeDialog,
|
|
onCancel,
|
|
initForm,
|
|
onSubmit,
|
|
...toRefs(state),
|
|
};
|
|
},
|
|
};
|
|
</script>
|