附件工具文件上传文件名称处理
continuous-integration/drone/push Build is passing Details

main
wangxiaoshuang 2025-09-08 14:18:04 +08:00
parent 33bc40d750
commit df365e97df
2 changed files with 24 additions and 20 deletions

View File

@ -27,11 +27,11 @@ async function ossGenerateSTS() {
Vue.prototype.OSSclientConfig.timeout = 10 * 60 * 1000 Vue.prototype.OSSclientConfig.timeout = 10 * 60 * 1000
let OSSclient = new OSS(Vue.prototype.OSSclientConfig) let OSSclient = new OSS(Vue.prototype.OSSclientConfig)
Vue.prototype.OSSclient = { Vue.prototype.OSSclient = {
put: function (objectName, object) { put: function (objectName, object, timestamp = true) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
let _vm = router.default.app let _vm = router.default.app
if (_vm._route.path !== '/trials/trials-panel/visit/crc-upload') { if (_vm._route.path !== '/trials/trials-panel/visit/crc-upload' && timestamp) {
var objectItem = objectName.split('/') var objectItem = objectName.split('/')
objectItem[objectItem.length - 1] = new Date().getTime() + '_' + objectItem[objectItem.length - 1] objectItem[objectItem.length - 1] = new Date().getTime() + '_' + objectItem[objectItem.length - 1]
objectName = objectItem.join('/') objectName = objectItem.join('/')
@ -56,12 +56,12 @@ async function ossGenerateSTS() {
case 'MinIO': case 'MinIO':
let minioClient = new Minio.Client(Vue.prototype.OSSclientConfig); let minioClient = new Minio.Client(Vue.prototype.OSSclientConfig);
Vue.prototype.OSSclient = { Vue.prototype.OSSclient = {
put: function (objectName, object) { put: function (objectName, object, timestamp = true) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
var name = objectName.split('/')[objectName.split('/').length - 1] var name = objectName.split('/')[objectName.split('/').length - 1]
let _vm = router.default.app let _vm = router.default.app
if (_vm._route.path !== '/trials/trials-panel/visit/crc-upload') { if (_vm._route.path !== '/trials/trials-panel/visit/crc-upload' && timestamp) {
var objectItem = objectName.split('/') var objectItem = objectName.split('/')
objectItem[objectItem.length - 1] = new Date().getTime() + '_' + objectItem[objectItem.length - 1] objectItem[objectItem.length - 1] = new Date().getTime() + '_' + objectItem[objectItem.length - 1]
objectName = objectItem.join('/') objectName = objectItem.join('/')

View File

@ -3,7 +3,7 @@
class="upload-temporary-file"> class="upload-temporary-file">
<div class="base-dialog-body"> <div class="base-dialog-body">
<el-form-item :label="$t('dictionary:attachment:label:code')" prop="Code"> <el-form-item :label="$t('dictionary:attachment:label:code')" prop="Code">
<el-input v-model="form.Code" /> <el-input v-model="form.Code" :disabled="fileList.length > 0" />
</el-form-item> </el-form-item>
<el-form-item :label="$t('dictionary:attachment:label:businessScenario')" prop="BusinessScenarioEnum"> <el-form-item :label="$t('dictionary:attachment:label:businessScenario')" prop="BusinessScenarioEnum">
<el-select v-model="form.BusinessScenarioEnum" style="width: 100%" size="small" filterable> <el-select v-model="form.BusinessScenarioEnum" style="width: 100%" size="small" filterable>
@ -16,8 +16,10 @@
<div class="upload-container"> <div class="upload-container">
<el-upload class="upload-demo" action accept="" :before-upload="beforeUpload" :http-request="handleUploadFile" <el-upload class="upload-demo" action accept="" :before-upload="beforeUpload" :http-request="handleUploadFile"
:on-preview="handlePreview" :on-remove="handleRemoveFile" :show-file-list="true" :file-list="fileList" :on-preview="handlePreview" :on-remove="handleRemoveFile" :show-file-list="true" :file-list="fileList"
:limit="1" :on-exceed="handleExceed" :disabled="(!form.FileTypeEnum && form.FileTypeEnum !== 0)"> :limit="1" :on-exceed="handleExceed"
<el-button size="small" type="primary" :disabled="(!form.FileTypeEnum && form.FileTypeEnum !== 0)" :disabled="((!form.FileTypeEnum && form.FileTypeEnum !== 0) || (!form.Code || (form.Code && !codeReg.test(form.Code))))">
<el-button size="small" type="primary"
:disabled="((!form.FileTypeEnum && form.FileTypeEnum !== 0) || (!form.Code || (form.Code && !codeReg.test(form.Code))))"
:loading="btnLoading">Select</el-button> :loading="btnLoading">Select</el-button>
<!-- <span slot="tip" style="margin-left: 10px" class="el-upload__tip"> <!-- <span slot="tip" style="margin-left: 10px" class="el-upload__tip">
(must be in xlsx/xls/doc/docx format) (must be in xlsx/xls/doc/docx format)
@ -79,9 +81,20 @@ export default {
Description: '', Description: '',
IsDeleted: false, IsDeleted: false,
}, },
codeReg: /^[a-zA-Z_]+$/,
rules: { rules: {
Code: [ Code: [
{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: ['blur'] }, { required: true, message: this.$t('common:ruleMessage:specify'), trigger: ['blur'] },
{
validator: (rule, value, callback) => {
if (value && !this.codeReg.test(value)) {
callback(new Error(this.$t('common:ruleMessage:codeRule')));
} else {
callback();
}
},
trigger: 'blur'
}
], ],
Name: [ Name: [
{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: ['blur'] }, { required: true, message: this.$t('common:ruleMessage:specify'), trigger: ['blur'] },
@ -154,7 +167,7 @@ export default {
.substring(param.file.name.lastIndexOf('.')) .substring(param.file.name.lastIndexOf('.'))
.toLocaleLowerCase() .toLocaleLowerCase()
let file = await this.fileToBlob(param.file) let file = await this.fileToBlob(param.file)
let res = await this.OSSclient.put(`/System/Tools/${this.$guid()}${extendName}`, file) let res = await this.OSSclient.put(`/System/Tools/${this.form.Code}${extendName}`, file, false)
this.form.Path = this.$getObjectName(res.url) this.form.Path = this.$getObjectName(res.url)
this.form.NameCN = param.file.name this.form.NameCN = param.file.name
this.fileList.push({ this.fileList.push({
@ -165,15 +178,6 @@ export default {
}) })
this.loading = false this.loading = false
this.btnLoading = false this.btnLoading = false
// Upload(formData, 1).then((res) => {
// this.fileList.push({
// name: param.file.name,
// path: res.Result.FilePath,
// fullPath: res.Result.FullFilePath,
// url: res.Result.FilePath,
// })
// })
}, },
fileToBlob(file) { fileToBlob(file) {
// FileReader // FileReader