mb-table 添加 download downloadAll 快捷下载属性

This commit is contained in:
吕金泽 2022-06-24 15:37:04 +08:00
parent 8b64662664
commit a74b8009d7
4 changed files with 73 additions and 13 deletions

View File

@ -0,0 +1,26 @@
{
"properties" : { },
"id" : "f9dc93ff77d94016a771456c21774789",
"script" : null,
"groupId" : "fd3d225a1cf141bf9998c4ec4bf4a6ab",
"name" : "下载post",
"createTime" : null,
"updateTime" : 1656055977595,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/download",
"method" : "POST",
"parameters" : [ ],
"options" : [ ],
"requestBody" : "",
"headers" : [ ],
"paths" : [ ],
"responseBody" : null,
"description" : null,
"requestBodyDefinition" : null,
"responseBodyDefinition" : null
}
================================
import '@get:/system/file/download' as download;
return download();

View File

@ -31,6 +31,13 @@
</el-button>
</template>
</div>
<div v-else-if="col.type == 'download'">
<a v-for="(url, i) in scope.row[col.field].split(',')" @click="$common.downloadMore(url)" href="javascript:;">
{{ url.substring(url.lastIndexOf('/') + 1) }}
{{ i != scope.row[col.field].split(',').length - 1 ? '' : '' }}
</a>
</div>
<a v-else-if="col.type == 'downloadAll'" @click="$common.downloadMore(scope.row[col.field])" href="javascript:;">下载</a>
<el-image
v-else-if="col.type === 'image'"
:src="scope.row[col.field].startsWith('http') ? scope.row[col.field] : $global.baseApi + scope.row[col.field]"

View File

@ -62,6 +62,20 @@ const formatJson = (list, filterVal) => {
}))
}
common.$get = (url, data) => request({ url, params: data })
common.$delete = (url, data) => request({ url, method: 'delete', params: data })
common.$post = (url, data) => request.post(url, data, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
transformRequest: [data => data && Object.keys(data).map(it => encodeURIComponent(it) + '=' + encodeURIComponent(data[it] === null || data[it] === undefined ? '' : data[it])).join('&')]
})
common.$postJson = (url, data) => request.post(url, JSON.stringify(data), {
headers: {
'Content-Type': 'application/json'
}
})
common.renderWhere = (where) => {
var newWhere = {}
for(var key in where) {
@ -160,6 +174,28 @@ common.getUrl = (url, data) => {
return url
}
common.downloadMore = (urls, filename) => {
var params = {
urls: encodeURI(urls),
filename: filename || '',
token: getToken()
}
var form = document.createElement("form");
form.style.display = 'none';
form.action = global.baseApi + '/system/file/download';
form.method = 'post';
document.body.appendChild(form);
for(var key in params){
var input = document.createElement("input");
input.type = 'hidden';
input.name = key;
input.value = params[key];
form.appendChild(input);
}
form.submit();
form.remove();
}
common.download = (urls, filename) => {
location.href = common.downloadHref(urls, filename)
}

View File

@ -6,19 +6,10 @@ import treeTable from './treeTable'
const install = (app) => {
app.config.globalProperties.$request = request
app.config.globalProperties.$post = (url, data) => request.post(url, data, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
transformRequest: [data => data && Object.keys(data).map(it => encodeURIComponent(it) + '=' + encodeURIComponent(data[it] === null || data[it] === undefined ? '' : data[it])).join('&')]
})
app.config.globalProperties.$postJson = (url, data) => request.post(url, JSON.stringify(data), {
headers: {
'Content-Type': 'application/json'
}
})
app.config.globalProperties.$get = (url, data) => request({ url, params: data })
app.config.globalProperties.$delete = (url, data) => request({ url, method: 'delete', params: data })
app.config.globalProperties.$post = common.$post
app.config.globalProperties.$postJson = common.$postJson
app.config.globalProperties.$get = common.$get
app.config.globalProperties.$delete = common.$delete
app.config.globalProperties.$global = global
app.config.globalProperties.$common = common
app.config.globalProperties.$treeTable = treeTable