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="上传图片">
|
2026-02-04 11:44:17 +08:00
|
|
|
|
<el-upload
|
|
|
|
|
|
v-model:file-list="uploadFileList"
|
|
|
|
|
|
:action="`${data.baseUrl}/system/file/upload`"
|
|
|
|
|
|
:before-upload="beforeAvatarUpload"
|
|
|
|
|
|
:data="{fileType:uploadFileType}"
|
|
|
|
|
|
:headers="{
|
|
|
|
|
|
'authorization': getToken()
|
|
|
|
|
|
}"
|
|
|
|
|
|
:limit="1"
|
|
|
|
|
|
:on-error="uploadError"
|
|
|
|
|
|
:on-success="uploadSuccess"
|
|
|
|
|
|
class="file-uploader"
|
|
|
|
|
|
:on-preview="handlePictureCardPreview"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-button type="primary">选取文件</el-button>
|
|
|
|
|
|
<template #tip>
|
|
|
|
|
|
<div class="el-upload__tip">
|
|
|
|
|
|
支持格式:'png', 'jpg', 'jpeg',大小不超过5MB
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-upload>
|
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>
|
2026-02-04 11:44:17 +08:00
|
|
|
|
|
2026-02-04 13:54:52 +08:00
|
|
|
|
<el-dialog :width="800" v-model="dialogVisible">
|
|
|
|
|
|
<img width="770" :src="dialogImageUrl" alt="Preview Image" />
|
2026-02-04 11:44:17 +08:00
|
|
|
|
</el-dialog>
|
2025-11-24 14:37:40 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
|
import { ref, watch } from 'vue'
|
2025-11-25 10:34:51 +08:00
|
|
|
|
import { useDict } from '@/utils/dict'
|
2026-02-04 11:44:17 +08:00
|
|
|
|
import {getToken} from "@/utils/auth.js";
|
|
|
|
|
|
import {supportType} from "@/enum/index.js";
|
|
|
|
|
|
import { ElMessage } from 'element-plus';
|
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('')
|
|
|
|
|
|
|
2026-02-04 11:44:17 +08:00
|
|
|
|
const uploadFileList = ref([])
|
|
|
|
|
|
const uploadFileType = ref(null)
|
|
|
|
|
|
const data = {
|
|
|
|
|
|
baseUrl: import.meta.env.VITE_APP_BASE_API
|
|
|
|
|
|
}
|
|
|
|
|
|
const beforeAvatarUpload = (rawFile) => {
|
|
|
|
|
|
const fileName = rawFile.name.split('.');
|
|
|
|
|
|
const fileExt = fileName[fileName.length - 1];
|
|
|
|
|
|
const isTypeOk = ['png', 'jpg', 'jpeg'].indexOf(fileExt) >= 0;
|
|
|
|
|
|
if (!isTypeOk) {
|
|
|
|
|
|
proxy.$modal.msgError(`文件格式不正确,请上传${['png', 'jpg', 'jpeg'].join("/")}格式文件!`);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
const {label = undefined, value = undefined} = supportType?.find(item => item.label === rawFile.type)
|
|
|
|
|
|
if (label) {
|
|
|
|
|
|
uploadFileType.value = value
|
|
|
|
|
|
}
|
|
|
|
|
|
// 校检文件大小
|
|
|
|
|
|
|
|
|
|
|
|
const isLt = rawFile.size / 1024 / 1024 < 5;
|
|
|
|
|
|
if (!isLt) {
|
|
|
|
|
|
ElMessage.error(`上传文件大小不能超过 ${5} MB!`);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const uploadSuccess = (e) => {
|
|
|
|
|
|
imgUrl.value = e.msg
|
|
|
|
|
|
ElMessage.success('上传成功')
|
|
|
|
|
|
}
|
|
|
|
|
|
const uploadError = (e) => {
|
|
|
|
|
|
console.log("uploadError", e)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const dialogImageUrl = ref('')
|
|
|
|
|
|
const dialogVisible = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
const handlePictureCardPreview = (uploadFile) => {
|
|
|
|
|
|
dialogImageUrl.value = uploadFile.response.msg
|
|
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-24 14:37:40 +08:00
|
|
|
|
watch(() => props.visible, (newVal) => {
|
|
|
|
|
|
visible.value = newVal
|
2025-11-25 10:34:51 +08:00
|
|
|
|
if (props.formData.iconUrl) {
|
|
|
|
|
|
imgUrl.value = props.formData.iconUrl
|
2026-02-04 13:54:52 +08:00
|
|
|
|
uploadFileList.value = [{
|
|
|
|
|
|
name: 'image',
|
|
|
|
|
|
url: props.formData.iconUrl,
|
|
|
|
|
|
response: {
|
|
|
|
|
|
msg: props.formData.iconUrl
|
|
|
|
|
|
}
|
|
|
|
|
|
}]
|
2025-11-25 10:34:51 +08:00
|
|
|
|
}
|
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
|
|
|
|
|
|
}
|
2026-02-04 13:54:52 +08:00
|
|
|
|
uploadFileList.value = []
|
2025-11-25 10:34:51 +08:00
|
|
|
|
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>
|