From 1d66f43353524889999bbd9ac0b331c557ff98f7 Mon Sep 17 00:00:00 2001 From: zhouwx <1175765986@qq.com> Date: 星期一, 30 六月 2025 17:29:22 +0800 Subject: [PATCH] 修改 --- src/views/build/conpanyFunctionConsult/qualityManage/rangeManage/range/components/recordDialog.vue | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 205 insertions(+), 0 deletions(-) diff --git a/src/views/build/conpanyFunctionConsult/qualityManage/rangeManage/range/components/recordDialog.vue b/src/views/build/conpanyFunctionConsult/qualityManage/rangeManage/range/components/recordDialog.vue new file mode 100644 index 0000000..ca300d2 --- /dev/null +++ b/src/views/build/conpanyFunctionConsult/qualityManage/rangeManage/range/components/recordDialog.vue @@ -0,0 +1,205 @@ +<template> + <div class="notice"> + <el-dialog + v-model="dialogVisible" + :title="state.title" + width="600px" + :before-close="handleClose" + :close-on-press-escape="false" + :close-on-click-modal="false" + > + <el-form :model="state.form" size="default" ref="superRef" :rules="state.formRules" label-width="150px" > + <el-form-item label="记录名称:" prop="templateName"> + <el-input v-model.trim="state.form.templateName" :disabled="state.title =='查看'" placeholder="材料名称"></el-input> + </el-form-item> + <el-form-item label="模板文件:" prop="filePath"> + <el-upload accept=".doc,.docx" :action="state.uploadUrl" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile)" :on-exceed="showTip" :limit='state.fileLimit' v-model:file-list="state.fileList" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles)" > + <el-button type="primary">点击上传</el-button> + <template #tip> + <div class="el-upload__tip">支持上传.doc、.docx格式文档,尺寸小于5M,最多可上传1张</div> + </template> + </el-upload> + </el-form-item> + </el-form> + <template #footer v-if="state.title !='查看'"> + <span class="dialog-footer"> + <el-button @click="handleClose" size="default">取 消</el-button> + <el-button type="primary" @click="onSubmit" size="default" v-preReClick>确认</el-button> + </span> + </template> + </el-dialog> + </div> +</template> +<script setup> +import {reactive, ref, toRefs, defineEmits, nextTick, onMounted} from 'vue' +import {ElMessage} from "element-plus"; +import {addUser, editUser, getUserById, resetPwd} from "@/api/onlineEducation/user" +import {Base64} from "js-base64" +import {getCompany} from "@/api/onlineEducation/company"; +import {addIndustryTemp, updateIndustryTemp, updateInfoPlatforms} from "@/api/staffManage/staff"; +import {getToken} from "@/utils/auth"; +import {delPic} from "@/api/onlineEducation/banner"; + +const emit = defineEmits(["getList"]); +const dialogVisible = ref(false) +const superRef = ref() +const state = reactive({ + title: '', + form: { + id: null, + templateName: '', + filePath: '', + format: '', + companyId: null + }, + formRules:{ + templateName: [{ required: true, message: '请输入材料名称', trigger: 'blur' }], + }, + isAdmin: false, + companyList: [], + industryList: [], + uploadUrl: import.meta.env.VITE_APP_BASE_API + '/system/common/uploadFile', + header: { + Authorization: getToken() + }, + fileLimit: 1, + fileList: [] +}) +onMounted(() => { + +}); + +const openDialog = async (type, value,companyId, isAdmin, companyList) => { + state.isAdmin = isAdmin + if(isAdmin){ + state.companyList = companyList + } + state.title = type === 'add' ? '新增' : type ==='edit' ? '编辑' : '查看' + state.form.companyId = companyId + if(state.title == '编辑'||state.title == '查看'){ + Object.keys(state.form).forEach(key => { + if (key in value) { + state.form[key] = value[key] + } + }) + if(value.filePath) { + const obj = { + url: value.filePath, + name: '模板文件' + } + state.fileList = [obj] + } + } + dialogVisible.value = true +} + + +const onSubmit = async () => { + const valid = await superRef.value.validate(); + if(valid){ + if(state.title == '新增'){ + const {id,...data} = state.form + const res = await addIndustryTemp(data) + if(res.code == 200){ + ElMessage.success(res.message) + emit('getList') + handleClose() + dialogVisible.value = false; + }else{ + ElMessage.warning(res.message) + } + }else{ + const res = await updateIndustryTemp(state.form) + if(res.code == 200){ + ElMessage.success(res.message) + emit('getList') + handleClose() + dialogVisible.value = false; + }else{ + ElMessage.warning(res.message) + } + } + } +} + +const handleAvatarSuccess = (res, uploadFile) => { + if(res.code == 200){ + state.form.filePath = res.data.path + state.form.format = '.' + res.data.filename.split('.')[1] + }else{ + state.fileList = [] + ElMessage({ + type: 'warning', + message: '文件上传失败' + }) + } +} + +const showTip =()=>{ + ElMessage({ + type: 'warning', + message: '超出文件上传数量' + }); +} +const picSize = async (rawFile) => { + if(rawFile.size / 1024 / 1024 > 5){ + ElMessage({ + type: 'warning', + message: '文件大小不能超过5M' + }); + return false + } +}; +const handleRemove = async (file, uploadFiles) => { + let path = state.form.filePath; + await delPic({path: path}).then(res => { + if(res.code == 200){ + // ElMessage({ + // type: 'success', + // message: '文件已删除' + // }) + state.form.filePath = '' + state.form.format = '' + }else{ + ElMessage({ + type: 'warning', + message: res.message + }) + } + }).catch(() => { + state.form.imgUrl = '' + }); +} + +const handleClose = () => { + state.form = { + id: null, + templateName: '', + industryType: '', + filePath: '', + format: '', + companyId: null + } + superRef.value.clearValidate(); + superRef.value.resetFields() + dialogVisible.value = false; +} + +defineExpose({ + openDialog +}); + +</script> + +<style scoped lang="scss"> +.notice{ + :deep(.el-form .el-form-item__label) { + font-size: 15px; + } + .file { + display: flex; + flex-direction: column; + align-items: flex-start; + } +} +</style> -- Gitblit v1.9.2