CMVR-IOT-UI/src/views/is/func/FunctionTable/FunctionDialog.vue

116 lines
2.5 KiB
Vue
Raw Normal View History

2025-11-24 14:37:40 +08:00
<template>
<el-dialog
v-model="visible"
:title="title"
width="500px"
destroy-on-close
>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="80px"
>
2025-11-25 10:34:51 +08:00
<el-form-item label="功能选择" prop="funcKey">
<el-select v-model="formData.funcKey">
<el-option
v-for="dict in ti_function_config"
:key="dict.value"
:label="dict.label"
2025-11-26 14:03:19 +08:00
:value="dict.value"
2025-11-25 10:34:51 +08:00
/>
2025-11-24 14:37:40 +08:00
</el-select>
</el-form-item>
<el-form-item label="上传图片">
2025-11-25 10:34:51 +08:00
<FileUpload v-model="imgUrl" :limit="1" :fileSize="5" :fileType="['png', 'jpg', 'jpeg']" />
2025-11-24 14:37:40 +08:00
</el-form-item>
2025-11-25 10:34:51 +08:00
<el-form-item label="描述" prop="remark">
2025-11-24 14:37:40 +08:00
<el-input
2025-11-25 10:34:51 +08:00
v-model="formData.remark"
2025-11-24 14:37:40 +08:00
type="textarea"
:rows="3"
placeholder="请输入描述"
/>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="handleCancel">取消</el-button>
<el-button type="primary" @click="handleConfirm">确认</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup>
import { ref, watch } from 'vue'
import FileUpload from '@/components/FileUpload/index'
2025-11-25 10:34:51 +08:00
import { useDict } from '@/utils/dict'
2025-11-24 14:37:40 +08:00
const props = defineProps({
visible: {
type: Boolean,
default: false
},
title: {
type: String,
default: ''
},
formData: {
type: Object,
default: () => {}
}
})
const emit = defineEmits(['update:visible', 'confirm'])
2025-11-25 10:34:51 +08:00
const { ti_function_config } = useDict("ti_function_config");
2025-11-24 14:37:40 +08:00
const formRef = ref()
// 表单验证规则
const formRules = {
2025-11-25 10:34:51 +08:00
funcKey: [
2025-11-24 14:37:40 +08:00
{ required: true, message: '请输入功能名称', trigger: 'blur' }
]
}
const visible = ref(props.visible)
const imgUrl = ref('')
watch(() => props.visible, (newVal) => {
visible.value = newVal
2025-11-25 10:34:51 +08:00
if (props.formData.iconUrl) {
imgUrl.value = props.formData.iconUrl
}
2025-11-24 14:37:40 +08:00
})
watch(visible, (newVal) => {
emit('update:visible', newVal)
})
function handleConfirm() {
if (!formRef.value) return
formRef.value.validate((valid) => {
2025-11-25 10:34:51 +08:00
const obj = { ...props.formData }
if (imgUrl.value && imgUrl.value.length > 0) {
obj.iconUrl = imgUrl.value
}
emit('confirm', valid, { ...obj })
2025-11-24 14:37:40 +08:00
})
}
function handleCancel() {
visible.value = false
}
</script>
<style scoped>
.dialog-footer {
display: flex;
justify-content: flex-end;
gap: 12px;
}
</style>