优化文件存储

This commit is contained in:
不做码农 2022-07-12 21:14:49 +08:00
parent c61bc792f2
commit 7a483d4a51
2 changed files with 44 additions and 18 deletions

View File

@ -33,7 +33,7 @@
<template v-if="fileSize">
大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b>
</template>
<template v-if="fileType">
<template v-if="fileType && fileType.length > 0">
格式为 <b style="color: #f56c6c">{{ fileType.join('/') }}</b>
</template>
的文件

View File

@ -107,6 +107,15 @@
</el-form-item>
</el-col>
<el-col :lg="24">
<el-form-item label="文件名规则" prop="fileNameType">
<el-radio-group v-model="form.fileNameType" placeholder="请选择文件名存储类型">
<el-radio v-for="item in fileNameTypeOptions" :key="item.dictValue" :label="parseInt(item.dictValue)">
{{ item.dictLabel }}
</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :lg="24" v-if="form.fileNameType == 2">
<el-form-item label="自定文件名" prop="fileName">
<el-input v-model="form.fileName" placeholder="请输入文件名" clearable="" />
</el-form-item>
@ -116,8 +125,7 @@
ref="uploadRef"
v-model="form.accessUrl"
:fileType="[]"
:limit="1"
:fileSize="15"
:fileSize="100"
:drag="true"
:data="uploadData"
:autoUpload="false"
@ -213,9 +221,14 @@ const dateRangeAddTime = ref([])
//
const storeTypeOptions = ref([
{ dictLabel: '本地存储', dictValue: 1 },
{ dictLabel: '阿里云存储', dictValue: 2 },
{ dictLabel: '阿里云存储', dictValue: 2 }
])
//
const fileNameTypeOptions = ref([
{ dictLabel: '原文件名', dictValue: 1 },
{ dictLabel: '自定义', dictValue: 2 },
{ dictLabel: '自动生成', dictValue: 3 }
])
//
const dataList = ref([])
//
@ -223,30 +236,37 @@ const total = ref(0)
const state = reactive({
form: {
storeType: 1,
storeType: 1
},
rules: {
accessUrl: [
{
required: true,
message: '上传文件不能为空',
trigger: 'blur',
},
trigger: 'blur'
}
],
storeType: [
{
required: true,
message: '存储类型不能为空',
trigger: 'blur',
},
trigger: 'blur'
}
],
fileName: [
{
required: true,
message: '文件名不能为空',
trigger: 'blur'
}
]
},
queryParams: {
pageNum: 1,
pageSize: 20,
storeType: 1, // 1 2
fileId: undefined,
},
fileId: undefined
}
})
const { queryParams, form, rules } = toRefs(state)
const { proxy } = getCurrentInstance()
@ -278,6 +298,7 @@ function reset() {
fileExt: '',
storeType: 1,
accessUrl: '',
fileNameType: 3
}
proxy.resetForm('formRef')
}
@ -339,13 +360,18 @@ function handleUploadSuccess(filelist) {
}
//
function submitUpload() {
proxy.$refs['formRef'].validate((valid) => {
if (valid) {
uploadData.value = {
fileDir: form.value.storePath,
fileName: form.value.fileName,
storeType: form.value.storeType,
fileNameType: form.value.fileNameType
}
proxy.$refs.uploadRef.submitUpload()
}
})
}
const { copy, isSupported } = useClipboard()
const copyText = async (val) => {