材料上传

pg_adapter
dshclm 6 months ago
parent 7f4af28066
commit 8e9fd70eea

@ -188,6 +188,7 @@
:on-error="handleUploadError" :on-error="handleUploadError"
:on-exceed="handleExceed" :on-exceed="handleExceed"
:on-remove="handleRemove(scope.row)" :on-remove="handleRemove(scope.row)"
:on-preview="handlePreview"
> >
<el-button slot="trigger" disabled size="small" type="primary">上传文件</el-button> <el-button slot="trigger" disabled size="small" type="primary">上传文件</el-button>
</el-upload> </el-upload>
@ -346,6 +347,36 @@
handleExceed(){ handleExceed(){
$.modal.msgWarning('超出个数限制,最多只能上传一个文件!'); $.modal.msgWarning('超出个数限制,最多只能上传一个文件!');
}, },
handlePreview(file){
$.ajax({
url: '/common/download/resource?resource=' + file.url,
type: 'GET',
xhrFields: {
responseType: 'blob'
},
success: function (data, status, xhr) {
let contentType = xhr.getResponseHeader('Content-Type');
let filename = file.name;
if (navigator.msSaveBlob) {
// 兼容 IE
navigator.msSaveBlob(data, filename);
} else {
let blob = new Blob([data], { type: contentType });
let url = URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
},
error: function (xhr, status, error) {
console.error('下载文件失败:', error);
}
});
},
validateEndTime(rule, value, callback) { validateEndTime(rule, value, callback) {
// if (value && this.postForm.checkStartTime && new Date(value).getTime() < new Date(this.postForm.checkStartTime).getTime()) { // if (value && this.postForm.checkStartTime && new Date(value).getTime() < new Date(this.postForm.checkStartTime).getTime()) {
// callback(new Error('结束日期不能早于开始日期')); // callback(new Error('结束日期不能早于开始日期'));

@ -185,6 +185,7 @@
:on-error="handleUploadError" :on-error="handleUploadError"
:on-exceed="handleExceed" :on-exceed="handleExceed"
:on-remove="handleRemove(scope.row)" :on-remove="handleRemove(scope.row)"
:on-preview="handlePreview"
> >
<el-button slot="trigger" :disabled="scope.row.ifstarts" size="small" type="primary">上传文件</el-button> <el-button slot="trigger" :disabled="scope.row.ifstarts" size="small" type="primary">上传文件</el-button>
</el-upload> </el-upload>
@ -357,6 +358,36 @@
handleExceed(){ handleExceed(){
$.modal.msgWarning('超出个数限制,最多只能上传一个文件!'); $.modal.msgWarning('超出个数限制,最多只能上传一个文件!');
}, },
handlePreview(file){
$.ajax({
url: '/common/download/resource?resource=' + file.url,
type: 'GET',
xhrFields: {
responseType: 'blob'
},
success: function (data, status, xhr) {
let contentType = xhr.getResponseHeader('Content-Type');
let filename = file.name;
if (navigator.msSaveBlob) {
// 兼容 IE
navigator.msSaveBlob(data, filename);
} else {
let blob = new Blob([data], { type: contentType });
let url = URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
},
error: function (xhr, status, error) {
console.error('下载文件失败:', error);
}
});
},
validateEndTime(rule, value, callback) { validateEndTime(rule, value, callback) {
// if (value && this.postForm.checkStartTime && new Date(value).getTime() < new Date(this.postForm.checkStartTime).getTime()) { // if (value && this.postForm.checkStartTime && new Date(value).getTime() < new Date(this.postForm.checkStartTime).getTime()) {
// callback(new Error('结束日期不能早于开始日期')); // callback(new Error('结束日期不能早于开始日期'));

Loading…
Cancel
Save