From bcac70b2abaf61ee3429cfcd8ed0b0d5b3c656b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Sun, 26 Sep 2021 17:02:08 +0800 Subject: [PATCH 01/10] =?UTF-8?q?update=20=E6=89=A9=E5=B1=95=20security=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-admin/src/main/resources/application.yml | 5 +++++ .../com/ruoyi/framework/config/SecurityConfig.java | 3 ++- .../config/properties/SecurityProperties.java | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 9f649edb0..6a7b7d007 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -108,6 +108,9 @@ token: # security配置 security: + # 登出路径 + logout-url: /logout + # 匿名路径 anonymous: - /login - /register @@ -122,6 +125,8 @@ security: # actuator 监控配置 - /actuator - /actuator/** + # 用户放行 + permit-all: # 重复提交 repeat-submit: diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 855be657c..229704f1b 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -109,11 +109,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter "/**/*.js" ).permitAll() .antMatchers(securityProperties.getAnonymous()).anonymous() + .antMatchers(securityProperties.getPermitAll()).permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated() .and() .headers().frameOptions().disable(); - httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); + httpSecurity.logout().logoutUrl(securityProperties.getLogoutUrl()).logoutSuccessHandler(logoutSuccessHandler); // 添加JWT filter httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); // 添加CORS filter diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SecurityProperties.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SecurityProperties.java index 33414cedb..c83ffccbe 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SecurityProperties.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SecurityProperties.java @@ -14,9 +14,19 @@ import org.springframework.stereotype.Component; @ConfigurationProperties(prefix = "security") public class SecurityProperties { + /** + * 退出登录url + */ + private String logoutUrl; + /** * 匿名放行路径 */ private String[] anonymous; + /** + * 用户任意访问放行路径 + */ + private String[] permitAll; + } From 3434610349c93037e9fc565600b151e0aed1672e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Sun, 26 Sep 2021 17:02:28 +0800 Subject: [PATCH 02/10] =?UTF-8?q?update=20=E6=8E=A5=E5=8F=A3=E6=96=87?= =?UTF-8?q?=E6=A1=A3=20=E6=94=AF=E6=8C=81=E5=88=86=E7=BB=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 5 + .../ruoyi/framework/config/SwaggerConfig.java | 162 ++++++++++-------- .../config/properties/SwaggerProperties.java | 33 +++- 3 files changed, 121 insertions(+), 79 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 6a7b7d007..48464f1a6 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -243,6 +243,11 @@ swagger: name: Lion Li email: crazylionli@163.com url: https://gitee.com/JavaLionLi/RuoYi-Vue-Plus + groups: + - name: 演示案例 + basePackage: com.ruoyi.demo + - name: 系统模块 + basePackage: com.ruoyi.admin # 防止XSS攻击 xss: diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java index 2c65ac69d..4da3b9949 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java @@ -1,11 +1,12 @@ package com.ruoyi.framework.config; import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; +import com.ruoyi.common.properties.TokenProperties; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.framework.config.properties.SwaggerProperties; -import io.swagger.annotations.ApiOperation; import io.swagger.models.auth.In; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; @@ -15,6 +16,7 @@ import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; +import javax.annotation.PostConstruct; import java.util.ArrayList; import java.util.List; @@ -27,82 +29,92 @@ import java.util.List; @EnableKnife4j public class SwaggerConfig { - @Autowired - private SwaggerProperties swaggerProperties; + @Autowired + private SwaggerProperties swaggerProperties; - /** - * 创建API - */ - @Bean - public Docket createRestApi() { - return new Docket(DocumentationType.OAS_30) - .enable(swaggerProperties.getEnabled()) - // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) - .apiInfo(apiInfo()) - // 设置哪些接口暴露给Swagger展示 - .select() - // 扫描所有有注解的api,用这种方式更灵活 - .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) - // 扫描指定包中的swagger注解 - // .apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger")) - // 扫描所有 .apis(RequestHandlerSelectors.any()) - .paths(PathSelectors.any()) - .build() - /* 设置安全模式,swagger可以设置访问token */ - .securitySchemes(securitySchemes()) - .securityContexts(securityContexts()) - .pathMapping(swaggerProperties.getPathMapping()); - } + @Autowired + private TokenProperties tokenProperties; - /** - * 安全模式,这里指定token通过Authorization头请求头传递 - */ - private List securitySchemes() { - List apiKeyList = new ArrayList(); - apiKeyList.add(new ApiKey("Authorization", "Authorization", In.HEADER.toValue())); - return apiKeyList; - } + /** + * 创建API + */ + @PostConstruct + public void createRestApi() { + for (SwaggerProperties.Groups group : swaggerProperties.getGroups()) { + String basePackage = group.getBasePackage(); + Docket docket = new Docket(DocumentationType.OAS_30) + .enable(swaggerProperties.getEnabled()) + // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) + .apiInfo(apiInfo()) + // 设置哪些接口暴露给Swagger展示 + .select() + // 扫描所有有注解的api,用这种方式更灵活 + //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) + // 扫描指定包中的swagger注解 + .apis(RequestHandlerSelectors.basePackage(basePackage)) + // 扫描所有 .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build() + .groupName(group.getName()) + // 设置安全模式,swagger可以设置访问token + .securitySchemes(securitySchemes()) + .securityContexts(securityContexts()) + .pathMapping(swaggerProperties.getPathMapping()); + String beanName = StringUtils.substringAfterLast(basePackage, ".") + "Docket"; + SpringUtils.registerBean(beanName, docket); + } + } - /** - * 安全上下文 - */ - private List securityContexts() { - List securityContexts = new ArrayList<>(); - securityContexts.add( - SecurityContext.builder() - .securityReferences(defaultAuth()) - .operationSelector(o -> o.requestMappingPattern().matches("/.*")) - .build()); - return securityContexts; - } + /** + * 安全模式,这里指定token通过Authorization头请求头传递 + */ + private List securitySchemes() { + List apiKeyList = new ArrayList(); + String header = tokenProperties.getHeader(); + apiKeyList.add(new ApiKey(header, header, In.HEADER.toValue())); + return apiKeyList; + } - /** - * 默认的安全上引用 - */ - private List defaultAuth() { - AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); - AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; - authorizationScopes[0] = authorizationScope; - List securityReferences = new ArrayList<>(); - securityReferences.add(new SecurityReference("Authorization", authorizationScopes)); - return securityReferences; - } + /** + * 安全上下文 + */ + private List securityContexts() { + List securityContexts = new ArrayList<>(); + securityContexts.add( + SecurityContext.builder() + .securityReferences(defaultAuth()) + .operationSelector(o -> o.requestMappingPattern().matches("/.*")) + .build()); + return securityContexts; + } - /** - * 添加摘要信息 - */ - private ApiInfo apiInfo() { - // 用ApiInfoBuilder进行定制 - SwaggerProperties.Contact contact = swaggerProperties.getContact(); - return new ApiInfoBuilder() - // 设置标题 - .title(swaggerProperties.getTitle()) - // 描述 - .description(swaggerProperties.getDescription()) - // 作者信息 - .contact(new Contact(contact.getName(), contact.getUrl(), contact.getEmail())) - // 版本 - .version(swaggerProperties.getVersion()) - .build(); - } + /** + * 默认的安全上引用 + */ + private List defaultAuth() { + AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); + AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; + authorizationScopes[0] = authorizationScope; + List securityReferences = new ArrayList<>(); + securityReferences.add(new SecurityReference(tokenProperties.getHeader(), authorizationScopes)); + return securityReferences; + } + + /** + * 添加摘要信息 + */ + private ApiInfo apiInfo() { + // 用ApiInfoBuilder进行定制 + SwaggerProperties.Contact contact = swaggerProperties.getContact(); + return new ApiInfoBuilder() + // 设置标题 + .title(swaggerProperties.getTitle()) + // 描述 + .description(swaggerProperties.getDescription()) + // 作者信息 + .contact(new Contact(contact.getName(), contact.getUrl(), contact.getEmail())) + // 版本 + .version(swaggerProperties.getVersion()) + .build(); + } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java index ece75efef..9c4cd238c 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java @@ -5,6 +5,8 @@ import lombok.NoArgsConstructor; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.List; + /** * swagger 配置属性 * @@ -41,23 +43,46 @@ public class SwaggerProperties { */ private Contact contact; + /** + * 组配置 + */ + private List groups; + @Data @NoArgsConstructor - public static class Contact{ + public static class Contact { /** * 联系人 - **/ + */ private String name; + /** * 联系人url - **/ + */ private String url; + /** * 联系人email - **/ + */ private String email; } + @Data + @NoArgsConstructor + public static class Groups { + + /** + * 组名 + */ + private String name; + + /** + * 基础包路径 + */ + private String basePackage; + + } + } From 2a6d2d733e947a41eb139369a23576530c81b9d5 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Mon, 27 Sep 2021 10:32:03 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E5=8D=87=E7=BA=A7dart-sass=E5=88=B0?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=89=88=E6=9C=AC1.42.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index 9048f5a4d..b96cd65de 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -71,7 +71,7 @@ "eslint-plugin-vue": "7.2.0", "lint-staged": "10.5.3", "runjs": "4.4.2", - "sass": "1.32.0", + "sass": "1.42.1", "sass-loader": "10.1.0", "script-ext-html-webpack-plugin": "2.1.5", "svg-sprite-loader": "5.1.1", From 02b95f95a8abd602d2c21ed3e4c736070f2e4d1c Mon Sep 17 00:00:00 2001 From: RuoYi Date: Mon, 27 Sep 2021 10:36:43 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E5=8D=87=E7=BA=A7file-saver=E5=88=B0?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=89=88=E6=9C=AC2.0.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index b96cd65de..ee68b26a3 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -42,7 +42,7 @@ "core-js": "3.8.1", "echarts": "4.9.0", "element-ui": "2.15.5", - "file-saver": "2.0.4", + "file-saver": "2.0.5", "fuse.js": "6.4.3", "highlight.js": "9.18.5", "js-beautify": "1.13.0", From ded99502ae2d7824d9584b5c69f4dfcf7bdb6759 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Mon, 27 Sep 2021 10:38:29 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=AE=80=E5=8C=96=E4=B8=8B=E8=BD=BD=E4=BD=BF?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/utils/file/FileUtils.java | 1 + .../framework/config/SecurityConfig.java | 2 - .../src/main/resources/vm/vue/index.vue.vm | 2 +- ruoyi-ui/src/main.js | 3 +- ruoyi-ui/src/plugins/download.js | 48 +++++++++++++++++++ ruoyi-ui/src/plugins/index.js | 3 ++ ruoyi-ui/src/utils/ruoyi.js | 7 --- ruoyi-ui/src/utils/zipdownload.js | 42 ---------------- ruoyi-ui/src/views/monitor/job/index.vue | 2 +- ruoyi-ui/src/views/monitor/job/log.vue | 2 +- .../src/views/monitor/logininfor/index.vue | 2 +- ruoyi-ui/src/views/monitor/operlog/index.vue | 2 +- ruoyi-ui/src/views/system/config/index.vue | 2 +- ruoyi-ui/src/views/system/dict/data.vue | 2 +- ruoyi-ui/src/views/system/dict/index.vue | 2 +- ruoyi-ui/src/views/system/post/index.vue | 2 +- ruoyi-ui/src/views/system/role/index.vue | 2 +- ruoyi-ui/src/views/system/user/index.vue | 4 +- ruoyi-ui/src/views/tool/build/index.vue | 19 ++------ ruoyi-ui/src/views/tool/gen/index.vue | 3 +- 20 files changed, 70 insertions(+), 82 deletions(-) create mode 100644 ruoyi-ui/src/plugins/download.js delete mode 100644 ruoyi-ui/src/utils/zipdownload.js diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java index 04ae9b1db..8d8f5a6a3 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java @@ -211,6 +211,7 @@ public class FileUtils .append(percentEncodedFileName); response.setHeader("Content-disposition", contentDispositionValue.toString()); + response.setHeader("download-filename", percentEncodedFileName); } /** diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index bd3622901..58dd02ad0 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -107,8 +107,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter "/**/*.js", "/profile/**" ).permitAll() - .antMatchers("/common/download**").anonymous() - .antMatchers("/common/download/resource**").anonymous() .antMatchers("/swagger-ui.html").anonymous() .antMatchers("/swagger-resources/**").anonymous() .antMatchers("/webjars/**").anonymous() diff --git a/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm b/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm index a55550373..867225aba 100644 --- a/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm +++ b/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm @@ -567,7 +567,7 @@ export default { this.exportLoading = true; return export${BusinessName}(queryParams); }).then(response => { - this.download(response.msg); + this.#[[$download]]#.name(response.msg); this.exportLoading = false; }).catch(() => {}); } diff --git a/ruoyi-ui/src/main.js b/ruoyi-ui/src/main.js index 79a2ab4bf..489600aa4 100644 --- a/ruoyi-ui/src/main.js +++ b/ruoyi-ui/src/main.js @@ -17,7 +17,7 @@ import './assets/icons' // icon import './permission' // permission control import { getDicts } from "@/api/system/dict/data"; import { getConfigKey } from "@/api/system/config"; -import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, download, handleTree } from "@/utils/ruoyi"; +import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi"; // 分页组件 import Pagination from "@/components/Pagination"; // 自定义表格工具组件 @@ -43,7 +43,6 @@ Vue.prototype.resetForm = resetForm Vue.prototype.addDateRange = addDateRange Vue.prototype.selectDictLabel = selectDictLabel Vue.prototype.selectDictLabels = selectDictLabels -Vue.prototype.download = download Vue.prototype.handleTree = handleTree // 全局组件挂载 diff --git a/ruoyi-ui/src/plugins/download.js b/ruoyi-ui/src/plugins/download.js new file mode 100644 index 000000000..cb10ab0e4 --- /dev/null +++ b/ruoyi-ui/src/plugins/download.js @@ -0,0 +1,48 @@ +import { saveAs } from 'file-saver' +import axios from 'axios' +import { getToken } from '@/utils/auth' + +const baseURL = process.env.VUE_APP_BASE_API + +export default { + name(name, isDelete = true) { + var url = baseURL + "/common/download?fileName=" + encodeURI(name) + "&delete=" + isDelete + axios({ + method: 'get', + url: url, + responseType: 'blob', + headers: { 'Authorization': 'Bearer ' + getToken() } + }).then(res => { + const blob = new Blob([res.data]) + this.saveAs(blob, decodeURI(res.headers['download-filename'])) + }) + }, + resource(resource) { + var url = baseURL + "/common/download/resource?resource=" + encodeURI(resource); + axios({ + method: 'get', + url: url, + responseType: 'blob', + headers: { 'Authorization': 'Bearer ' + getToken() } + }).then(res => { + const blob = new Blob([res.data]) + this.saveAs(blob, decodeURI(res.headers['download-filename'])) + }) + }, + zip(url, name) { + var url = baseURL + url + axios({ + method: 'get', + url: url, + responseType: 'blob', + headers: { 'Authorization': 'Bearer ' + getToken() } + }).then(res => { + const blob = new Blob([res.data], { type: 'application/zip' }) + this.saveAs(blob, name) + }) + }, + saveAs(text, name, opts) { + saveAs(text, name, opts); + } +} + diff --git a/ruoyi-ui/src/plugins/index.js b/ruoyi-ui/src/plugins/index.js index 15d829b18..a138e6d6f 100644 --- a/ruoyi-ui/src/plugins/index.js +++ b/ruoyi-ui/src/plugins/index.js @@ -1,5 +1,6 @@ import cache from './cache' import modal from './modal' +import download from './download' export default { install(Vue) { @@ -7,5 +8,7 @@ export default { Vue.prototype.$cache = cache // 模态框对象 Vue.prototype.$modal = modal + // 下载文件 + Vue.prototype.$download = download } } diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js index 5669a4347..63bd379b7 100644 --- a/ruoyi-ui/src/utils/ruoyi.js +++ b/ruoyi-ui/src/utils/ruoyi.js @@ -3,8 +3,6 @@ * Copyright (c) 2019 ruoyi */ -const baseURL = process.env.VUE_APP_BASE_API - // 日期格式化 export function parseTime(time, pattern) { if (arguments.length === 0 || !time) { @@ -95,11 +93,6 @@ export function selectDictLabels(datas, value, separator) { return actions.join('').substring(0, actions.join('').length - 1); } -// 通用下载方法 -export function download(fileName) { - window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true; -} - // 字符串格式化(%s ) export function sprintf(str) { var args = arguments, flag = true, i = 1; diff --git a/ruoyi-ui/src/utils/zipdownload.js b/ruoyi-ui/src/utils/zipdownload.js deleted file mode 100644 index 8a1b81983..000000000 --- a/ruoyi-ui/src/utils/zipdownload.js +++ /dev/null @@ -1,42 +0,0 @@ -import axios from 'axios' -import { getToken } from '@/utils/auth' - -const mimeMap = { - xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - zip: 'application/zip' -} - -const baseUrl = process.env.VUE_APP_BASE_API -export function downLoadZip(str, filename) { - var url = baseUrl + str - axios({ - method: 'get', - url: url, - responseType: 'blob', - headers: { 'Authorization': 'Bearer ' + getToken() } - }).then(res => { - resolveBlob(res, mimeMap.zip) - }) -} -/** - * 解析blob响应内容并下载 - * @param {*} res blob响应内容 - * @param {String} mimeType MIME类型 - */ -export function resolveBlob(res, mimeType) { - const aLink = document.createElement('a') - var blob = new Blob([res.data], { type: mimeType }) - // //从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名; - var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*') - var contentDisposition = decodeURI(res.headers['content-disposition']) - var result = patt.exec(contentDisposition) - var fileName = result[1] - fileName = fileName.replace(/\"/g, '') - aLink.style.display = 'none' - aLink.href = URL.createObjectURL(blob) - aLink.setAttribute('download', fileName) // 设置下载文件名称 - document.body.appendChild(aLink) - aLink.click() - URL.revokeObjectURL(aLink.href);//清除引用 - document.body.removeChild(aLink); -} diff --git a/ruoyi-ui/src/views/monitor/job/index.vue b/ruoyi-ui/src/views/monitor/job/index.vue index 528c98bf9..06b939d85 100644 --- a/ruoyi-ui/src/views/monitor/job/index.vue +++ b/ruoyi-ui/src/views/monitor/job/index.vue @@ -515,7 +515,7 @@ export default { this.exportLoading = true; return exportJob(queryParams); }).then(response => { - this.download(response.msg); + this.$download.name(response.msg); this.exportLoading = false; }).catch(() => {}); } diff --git a/ruoyi-ui/src/views/monitor/job/log.vue b/ruoyi-ui/src/views/monitor/job/log.vue index f8b3a5016..44efe5f1e 100644 --- a/ruoyi-ui/src/views/monitor/job/log.vue +++ b/ruoyi-ui/src/views/monitor/job/log.vue @@ -298,7 +298,7 @@ export default { this.exportLoading = true; return exportJobLog(queryParams); }).then(response => { - this.download(response.msg); + this.$download.name(response.msg); this.exportLoading = false; }).catch(() => {}); } diff --git a/ruoyi-ui/src/views/monitor/logininfor/index.vue b/ruoyi-ui/src/views/monitor/logininfor/index.vue index b4a498e96..634141997 100644 --- a/ruoyi-ui/src/views/monitor/logininfor/index.vue +++ b/ruoyi-ui/src/views/monitor/logininfor/index.vue @@ -221,7 +221,7 @@ export default { this.exportLoading = true; return exportLogininfor(queryParams); }).then(response => { - this.download(response.msg); + this.$download.name(response.msg); this.exportLoading = false; }).catch(() => {}); } diff --git a/ruoyi-ui/src/views/monitor/operlog/index.vue b/ruoyi-ui/src/views/monitor/operlog/index.vue index 243451ae0..0aee4a6a5 100644 --- a/ruoyi-ui/src/views/monitor/operlog/index.vue +++ b/ruoyi-ui/src/views/monitor/operlog/index.vue @@ -308,7 +308,7 @@ export default { this.exportLoading = true; return exportOperlog(queryParams); }).then(response => { - this.download(response.msg); + this.$download.name(response.msg); this.exportLoading = false; }).catch(() => {}); } diff --git a/ruoyi-ui/src/views/system/config/index.vue b/ruoyi-ui/src/views/system/config/index.vue index c1bb728d2..efb69615b 100644 --- a/ruoyi-ui/src/views/system/config/index.vue +++ b/ruoyi-ui/src/views/system/config/index.vue @@ -339,7 +339,7 @@ export default { this.exportLoading = true; return exportConfig(queryParams); }).then(response => { - this.download(response.msg); + this.$download.name(response.msg); this.exportLoading = false; }).catch(() => {}); }, diff --git a/ruoyi-ui/src/views/system/dict/data.vue b/ruoyi-ui/src/views/system/dict/data.vue index 6ff517bf7..36eb6afdb 100644 --- a/ruoyi-ui/src/views/system/dict/data.vue +++ b/ruoyi-ui/src/views/system/dict/data.vue @@ -385,7 +385,7 @@ export default { this.exportLoading = true; return exportData(queryParams); }).then(response => { - this.download(response.msg); + this.$download.name(response.msg); this.exportLoading = false; }).catch(() => {}); } diff --git a/ruoyi-ui/src/views/system/dict/index.vue b/ruoyi-ui/src/views/system/dict/index.vue index a0e553986..37de40f3f 100644 --- a/ruoyi-ui/src/views/system/dict/index.vue +++ b/ruoyi-ui/src/views/system/dict/index.vue @@ -343,7 +343,7 @@ export default { this.exportLoading = true; return exportType(queryParams); }).then(response => { - this.download(response.msg); + this.$download.name(response.msg); this.exportLoading = false; }).catch(() => {}); }, diff --git a/ruoyi-ui/src/views/system/post/index.vue b/ruoyi-ui/src/views/system/post/index.vue index b0039eb91..e2069687d 100644 --- a/ruoyi-ui/src/views/system/post/index.vue +++ b/ruoyi-ui/src/views/system/post/index.vue @@ -310,7 +310,7 @@ export default { this.exportLoading = true; return exportPost(queryParams); }).then(response => { - this.download(response.msg); + this.$download.name(response.msg); this.exportLoading = false; }).catch(() => {}); } diff --git a/ruoyi-ui/src/views/system/role/index.vue b/ruoyi-ui/src/views/system/role/index.vue index b58b26ff3..6e5855863 100644 --- a/ruoyi-ui/src/views/system/role/index.vue +++ b/ruoyi-ui/src/views/system/role/index.vue @@ -618,7 +618,7 @@ export default { this.exportLoading = true; return exportRole(queryParams); }).then(response => { - this.download(response.msg); + this.$download.name(response.msg); this.exportLoading = false; }).catch(() => {}); } diff --git a/ruoyi-ui/src/views/system/user/index.vue b/ruoyi-ui/src/views/system/user/index.vue index fe431f167..4f20b0872 100644 --- a/ruoyi-ui/src/views/system/user/index.vue +++ b/ruoyi-ui/src/views/system/user/index.vue @@ -648,7 +648,7 @@ export default { this.exportLoading = true; return exportUser(queryParams); }).then(response => { - this.download(response.msg); + this.$download.name(response.msg); this.exportLoading = false; }).catch(() => {}); }, @@ -660,7 +660,7 @@ export default { /** 下载模板操作 */ importTemplate() { importTemplate().then(response => { - this.download(response.msg); + this.$download.name(response.msg); }); }, // 文件上传中处理 diff --git a/ruoyi-ui/src/views/tool/build/index.vue b/ruoyi-ui/src/views/tool/build/index.vue index 0281d18df..e51140875 100644 --- a/ruoyi-ui/src/views/tool/build/index.vue +++ b/ruoyi-ui/src/views/tool/build/index.vue @@ -137,23 +137,13 @@