下载文件
This commit is contained in:
parent
b18f274121
commit
85900682b8
@ -18,6 +18,33 @@ export function downLoadZip(str, filename) {
|
||||
resolveBlob(res, mimeMap.zip)
|
||||
})
|
||||
}
|
||||
export function downLoadUrl(str, item) {
|
||||
var url = baseUrl + str
|
||||
axios({
|
||||
method: 'get',
|
||||
url: url,
|
||||
params: { name: item.fileurl },
|
||||
responseType: 'blob',
|
||||
headers: { 'Authorization': 'Bearer ' + getToken() },
|
||||
}).then(res => {
|
||||
console.log(res);
|
||||
downloadFileFun(res, item)
|
||||
})
|
||||
}
|
||||
|
||||
export function downloadFileFun(data, item) {
|
||||
if (!data) {
|
||||
return
|
||||
}
|
||||
let url = window.URL.createObjectURL(new Blob([data]))
|
||||
let link = document.createElement('a')
|
||||
link.style.display = 'none'
|
||||
link.href = url
|
||||
link.setAttribute('download', item.name)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析blob响应内容并下载
|
||||
* @param {*} res blob响应内容
|
||||
|
@ -12,13 +12,18 @@
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row> -->
|
||||
<ul class="infinite-list" v-infinite-scroll="load" style="overflow:auto">
|
||||
<li v-for="(ele, i) in filesList" :key="i" class="flex align-center justify-between infinite-list-item">
|
||||
<ul class="infinite-list" v-infinite-scroll="load" style="overflow: auto">
|
||||
<li
|
||||
v-for="(ele, i) in filesList"
|
||||
:key="i"
|
||||
class="flex align-center justify-between infinite-list-item"
|
||||
>
|
||||
<div class="left">
|
||||
<span>{{i + 1}}.</span>
|
||||
<i class="el-icon-document icon"></i>{{ele.name}}
|
||||
<span>{{ i + 1 }}.</span>
|
||||
<i class="el-icon-document icon"></i>{{ ele.name }}
|
||||
</div>
|
||||
<a class="right" :href="apiurl + ele.fileurl">下载</a>
|
||||
<!-- <a class="right" :href="apiurl + ele.fileurl">下载</a> -->
|
||||
<a class="right" @click="down(ele)">下载</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -26,6 +31,7 @@
|
||||
|
||||
<script>
|
||||
import { listFiles, getFiles } from "@/api/benyi/files";
|
||||
import { downLoadUrl } from "@/utils/zipdownload";
|
||||
|
||||
export default {
|
||||
name: "childFiles",
|
||||
@ -43,8 +49,8 @@ export default {
|
||||
filetype: undefined,
|
||||
type: "1", //代表幼儿入园系列文件
|
||||
fileurl: undefined,
|
||||
createuserid: undefined
|
||||
}
|
||||
createuserid: undefined,
|
||||
},
|
||||
};
|
||||
},
|
||||
created() {
|
||||
@ -54,15 +60,16 @@ export default {
|
||||
/** 查询文件管理列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listFiles(this.queryParams).then(response => {
|
||||
listFiles(this.queryParams).then((response) => {
|
||||
this.filesList = response.rows;
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
load() {
|
||||
|
||||
}
|
||||
}
|
||||
load() {},
|
||||
down(row) {
|
||||
downLoadUrl('/common/download/resource',row);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
|
@ -94,9 +94,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
"/**/*.css",
|
||||
"/**/*.js"
|
||||
).permitAll()
|
||||
.antMatchers("/profile/**").anonymous()
|
||||
.antMatchers("/common/download**").anonymous()
|
||||
.antMatchers("/common/download/resource**").anonymous()
|
||||
// .antMatchers("/profile/**").anonymous()
|
||||
// .antMatchers("/common/download**").anonymous()
|
||||
// .antMatchers("/common/download/resource**").anonymous()
|
||||
.antMatchers("/swagger-ui.html").anonymous()
|
||||
.antMatchers("/swagger-resources/**").anonymous()
|
||||
.antMatchers("/webjars/**").anonymous()
|
||||
|
@ -140,6 +140,10 @@ public class CommonController {
|
||||
return ajax;
|
||||
}
|
||||
|
||||
/**
|
||||
*获取七牛资源地址
|
||||
*@param URL 上传的资源名称
|
||||
*/
|
||||
public String privateDownloadUrl(String URL) {
|
||||
|
||||
Auth auth = Auth.create(constantQiniu.getAccessKey(), constantQiniu.getSecretKey());
|
||||
@ -156,8 +160,10 @@ public class CommonController {
|
||||
public void resourceDownload(String name, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
// 本地资源路径
|
||||
String localPath = RuoYiConfig.getProfile();
|
||||
// System.out.println("localPath:"+localPath);
|
||||
// 数据库资源地址
|
||||
String downloadPath = localPath + StringUtils.substringAfter(name, Constants.RESOURCE_PREFIX);
|
||||
// System.out.println("downloadPath:"+downloadPath);
|
||||
// 下载名称
|
||||
String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
|
Loading…
x
Reference in New Issue
Block a user