| | |
| | | :close-on-click-modal="false" |
| | | > |
| | | <el-form :model="state.form" size="default" ref="superRef" :rules="state.formRules" label-width="150px" > |
| | | <el-form-item v-if="state.isAdmin" label="单位:" prop="companyId"> |
| | | <el-select v-model="state.form.companyId" placeholder="请选择" clearable> |
| | | <el-option |
| | | v-for="item in state.companyList" |
| | | :key="item.id" |
| | | :label="item.name" |
| | | :value="item.id"> |
| | | </el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="信息平台名称:" prop="platformName"> |
| | | <el-input v-model.trim="state.form.platformName" :disabled="state.title =='查看'" placeholder="信息平台名称"></el-input> |
| | | </el-form-item> |
| | |
| | | value-format="YYYY-MM-DD" |
| | | placeholder="请选择创建时间" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="平台链接:" prop="platformAddress"> |
| | | <el-input v-model.trim="state.form.platformAddress" :disabled="state.title =='查看'" placeholder="平台链接"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="系统图标" prop="platformPic"> |
| | | <el-upload accept="image/*" :action="state.uploadUrl" :disabled="state.title =='查看'" list-type="picture-card" :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-icon><Plus /></el-icon> |
| | | <template #tip> |
| | | <div class="el-upload__tip">支持上传图片格式,尺寸小于5M,最多可上传1份</div> |
| | | </template> |
| | | </el-upload> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer v-if="state.title !='查看'"> |
| | |
| | | import {Base64} from "js-base64" |
| | | import {getCompany} from "@/api/onlineEducation/company"; |
| | | import {updateInfoPlatforms} from "@/api/staffManage/staff"; |
| | | import {delPic} from "@/api/onlineEducation/banner"; |
| | | import {getToken} from "@/utils/auth"; |
| | | |
| | | const emit = defineEmits(["getList"]); |
| | | const dialogVisible = ref(false) |
| | | const superRef = ref() |
| | | const checkFiles = (rule, value, callback) => { |
| | | if (state.fileList.length == 0) { |
| | | callback(new Error('请上传系统图标')) |
| | | } else { |
| | | callback() |
| | | } |
| | | } |
| | | const state = reactive({ |
| | | title: '', |
| | | form: { |
| | | id: null, |
| | | platformName: '', |
| | | buildDate: '', |
| | | companyId: null |
| | | companyId: null, |
| | | platformAddress: '', |
| | | platformPic: '' |
| | | }, |
| | | formRules:{ |
| | | companyId: [{ required: true, message: '请选择企业', trigger: 'blur' }], |
| | | platformName: [{ required: true, message: '请输入信息平台名称', trigger: 'blur' }], |
| | | buildDate: [{ required: true, message: '请选择平台创建时间', trigger: 'blur' }] |
| | | } |
| | | buildDate: [{ required: true, message: '请选择平台创建时间', trigger: 'blur' }], |
| | | platformAddress: [{ required: true, message: '请填写平台链接', trigger: 'blur' }], |
| | | platformPic: [{ required: true, validator: checkFiles, trigger: 'blur' }] |
| | | }, |
| | | isAdmin: false, |
| | | companyList: [], |
| | | uploadUrl: import.meta.env.VITE_APP_BASE_API + '/system/common/uploadFile', |
| | | header: { |
| | | Authorization: getToken() |
| | | }, |
| | | fileLimit: 1, |
| | | fileList: [] |
| | | }) |
| | | onMounted(() => { |
| | | |
| | | }); |
| | | |
| | | const openDialog = async (type, value,companyId) => { |
| | | 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 == '查看'){ |
| | |
| | | state.form[key] = value[key] |
| | | } |
| | | }) |
| | | if(value.platformPic) { |
| | | const obj = { |
| | | url: import.meta.env.VITE_APP_BASE_API + '/' + value.platformPic, |
| | | name: value.platformName |
| | | } |
| | | state.fileList = [obj] |
| | | } |
| | | } |
| | | dialogVisible.value = true |
| | | } |
| | | |
| | | const handleAvatarSuccess = (res, uploadFile) => { |
| | | if(res.code == 200){ |
| | | state.form.platformPic = res.data.path |
| | | }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.platformPic |
| | | await delPic({path: path}).then(res => { |
| | | if(res.code == 200){ |
| | | // ElMessage({ |
| | | // type: 'success', |
| | | // message: '文件已删除' |
| | | // }) |
| | | state.form.platformPic = '' |
| | | }else{ |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: res.message |
| | | }) |
| | | } |
| | | }).catch(() => { |
| | | state.form.platformPic = '' |
| | | }); |
| | | } |
| | | |
| | | const onSubmit = async () => { |
| | | const valid = await superRef.value.validate(); |
| | |
| | | data = { |
| | | platformName: state.form.platformName, |
| | | buildDate: state.form.buildDate, |
| | | companyId: state.form.companyId |
| | | companyId: state.form.companyId, |
| | | platformAddress: state.form.platformAddress, |
| | | platformPic: state.form.platformPic |
| | | } |
| | | }else{ |
| | | data = state.form |
| | |
| | | id: null, |
| | | platformName: '', |
| | | buildDate: '', |
| | | companyId: null |
| | | companyId: null, |
| | | platformAddress: '', |
| | | platformPic: '' |
| | | } |
| | | state.fileList = [] |
| | | superRef.value.clearValidate(); |
| | | superRef.value.resetFields() |
| | | dialogVisible.value = false; |