79 lines
3.0 KiB
Twig
79 lines
3.0 KiB
Twig
<template>
|
|
<el-dialog :title="titleMap[mode]" v-model="visible" :width="800" destroy-on-close @closed="$emit('closed')">
|
|
<el-form :model="{{ config.model }}" :rules="{{ config.rules }}" :disabled="mode==='show'" ref="{{ config.ref }}"
|
|
label-width="{{ config.labelWidth }}" label-position="{{ config.labelPosition }}" size="{{ config.size }}">
|
|
{% for field in fields %}
|
|
<el-form-item label="{{ field.title }}" prop="{{ field.field_name }}">
|
|
{% if field.name == 'text' %}
|
|
<el-input v-model="{{ config.model }}.{{ field.field_name }}"{% if field.props.placeholder %} placeholder="{{ field.props.placeholder }}"{% endif %}
|
|
{% if field.props.minlength %} :minlength="{{ field.props.minlength }}"{% endif %}{% if field.props.maxlength %} :maxlength="{{ field.props.maxlength }}"{% endif %}
|
|
{% if field.props.showWordLimit %} showWordLimit{% endif %}{% if field.props.prefixIcon %} prefixIcon="{{ field.props.prefixIcon }}"{% endif %}
|
|
{% if field.props.suffixIcon %} suffixIcon="{{ field.props.suffixIcon }}"{% endif %}{% if field.props.clearable %} clearable{% endif %}
|
|
{% if field.props.readonly %} readonly{% endif %}{% if field.props.disabled %} disabled{% endif %}{% if field.width %} style="width: {{ field.width }}"{% endif %}/>
|
|
{% endif %}
|
|
</el-form-item>
|
|
{% endfor %}
|
|
</el-form>
|
|
<template #footer>
|
|
<el-button @click="visible=false">取 消</el-button>
|
|
<el-button v-if="mode!=='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
|
|
</template>
|
|
</el-dialog>
|
|
</template>
|
|
|
|
<script setup>
|
|
import {getCurrentInstance, ref} from 'vue'
|
|
import api from "@/api/index"
|
|
|
|
defineExpose({
|
|
open
|
|
})
|
|
const emit = defineEmits(['success', 'closed'])
|
|
const formRef = ref(null)
|
|
const {proxy} = getCurrentInstance()
|
|
|
|
let mode = ref('add')
|
|
let titleMap = ref({
|
|
add: '新增',
|
|
edit: '编辑',
|
|
show: '查看'
|
|
})
|
|
let visible = ref(false)
|
|
let isSaveing = ref(false)
|
|
let form = ref({
|
|
dict_id: null,
|
|
dict_name: null,
|
|
dict_type: null,
|
|
remark: null
|
|
})
|
|
const rules = ref({
|
|
dict_name: [
|
|
{required: true, message: '请填写字典名称'}
|
|
],
|
|
dict_type: [
|
|
{required: true, message: '请填写字典类型'}
|
|
]
|
|
})
|
|
|
|
function open(m = 'add', data = null) {
|
|
mode.value = m
|
|
visible.value = true
|
|
Object.assign(form.value, data)
|
|
}
|
|
|
|
async function submit() {
|
|
// 校验登录
|
|
const validate = await formRef.value.validate().catch(() => {
|
|
});
|
|
if (!validate) {
|
|
return false
|
|
}
|
|
isSaveing.value = true;
|
|
const res = form.value.dict_id ? await api.system.dict.edit(form.value) : await api.system.dict.add(form.value);
|
|
isSaveing.value = false;
|
|
emit('success')
|
|
visible.value = false;
|
|
proxy.$message.success(res.msg)
|
|
}
|
|
</script>
|