mirror of
https://gitee.com/xiangheng/x_admin.git
synced 2026-04-22 22:57:15 +08:00
138 lines
3.9 KiB
Vue
138 lines
3.9 KiB
Vue
<template>
|
|
<div class="edit-popup">
|
|
<popup
|
|
ref="popupRef"
|
|
:title="popupTitle"
|
|
:async="true"
|
|
width="900px"
|
|
:clickModalClose="true"
|
|
@confirm="handleSubmit"
|
|
@close="handleClose"
|
|
>
|
|
<el-form ref="formRef" :model="formData" label-width="110px" :rules="formRules">
|
|
<el-form-item label="标识" prop="Tag" borderBottom>
|
|
<el-input v-model="formData.Tag" placeholder="请输入标识" />
|
|
</el-form-item>
|
|
<el-form-item label="版本" prop="Version" borderBottom>
|
|
<el-input v-model="formData.Version" type="number" placeholder="请输入版本" />
|
|
</el-form-item>
|
|
<el-form-item label="标题" prop="Title">
|
|
<el-input v-model="formData.Title" placeholder="请输入标题" />
|
|
</el-form-item>
|
|
<el-form-item label="协议内容" prop="Content">
|
|
<editor v-model="formData.Content" :height="500" />
|
|
</el-form-item>
|
|
</el-form>
|
|
</popup>
|
|
</div>
|
|
</template>
|
|
<script lang="ts" setup>
|
|
import { ref, computed, reactive, useTemplateRef } from 'vue'
|
|
import type { FormInstance } from 'element-plus'
|
|
import { user_protocol_edit, user_protocol_add, user_protocol_detail } from '@/api/user/protocol'
|
|
import Popup from '@/components/popup/index.vue'
|
|
import feedback from '@/utils/feedback'
|
|
import type { PropType } from 'vue'
|
|
defineProps({
|
|
dictData: {
|
|
type: Object as PropType<Record<string, any[]>>,
|
|
default: () => ({})
|
|
},
|
|
listAllData: {
|
|
type: Object as PropType<Record<string, any[]>>,
|
|
default: () => ({})
|
|
}
|
|
})
|
|
const emit = defineEmits(['success', 'close'])
|
|
const formRef = useTemplateRef<FormInstance>('formRef')
|
|
const popupRef = useTemplateRef<InstanceType<typeof Popup>>('popupRef')
|
|
const mode = ref('add')
|
|
const popupTitle = computed(() => {
|
|
return mode.value == 'edit' ? '编辑用户协议' : '新增用户协议'
|
|
})
|
|
|
|
const formData = reactive({
|
|
Tag: null,
|
|
Version: null,
|
|
Id: null,
|
|
Title: null,
|
|
Content: null
|
|
})
|
|
|
|
const formRules = {
|
|
// Id: [
|
|
// {
|
|
// required: true,
|
|
// message: '请输入',
|
|
// trigger: ['blur']
|
|
// }
|
|
// ]
|
|
// Title: [
|
|
// {
|
|
// required: true,
|
|
// message: '请输入标题',
|
|
// trigger: ['blur']
|
|
// }
|
|
// ],
|
|
// Content: [
|
|
// {
|
|
// required: true,
|
|
// message: '请输入协议内容',
|
|
// trigger: ['blur']
|
|
// }
|
|
// ]
|
|
// Sort: [
|
|
// {
|
|
// required: true,
|
|
// message: '请输入排序',
|
|
// trigger: ['blur']
|
|
// }
|
|
// ]
|
|
}
|
|
|
|
const handleSubmit = async () => {
|
|
try {
|
|
await formRef.value?.validate()
|
|
const data: any = { ...formData }
|
|
// delete data.Title
|
|
data.Version = data.Version ? Number(data.Version) : null
|
|
// data.Version = null
|
|
mode.value == 'edit' ? await user_protocol_edit(data) : await user_protocol_add(data)
|
|
popupRef.value?.close()
|
|
feedback.msgSuccess('操作成功')
|
|
emit('success')
|
|
} catch (error) {}
|
|
}
|
|
|
|
const open = (type = 'add') => {
|
|
mode.value = type
|
|
popupRef.value?.open()
|
|
}
|
|
|
|
const setFormData = async (data: Record<string, any>) => {
|
|
for (const key in formData) {
|
|
if (data[key] != null && data[key] != undefined) {
|
|
//@ts-ignore
|
|
formData[key] = data[key]
|
|
}
|
|
}
|
|
}
|
|
|
|
const getDetail = async (row: Record<string, any>) => {
|
|
try {
|
|
const data = await user_protocol_detail(row.Id)
|
|
setFormData(data)
|
|
} catch (error) {}
|
|
}
|
|
|
|
const handleClose = () => {
|
|
emit('close')
|
|
}
|
|
|
|
defineExpose({
|
|
open,
|
|
setFormData,
|
|
getDetail
|
|
})
|
|
</script>
|