Refresh to lose other tags, front-end page optimization
-
In the index.vue directory in the layout/components/TagsView file, add the following method to the methods method:
tagsViewCache() { window. addEventListener("beforeunload", () => { let tabViews = this.visitedViews.map(item => { return { fullPath: item.fullPath, hash: item.hash, meta: { ...item.meta }, name: item.name, params: { ...item. params }, path: item.path, query: { ...item. query }, title: item.title }; }); sessionStorage.setItem("tabViews", JSON.stringify(tabViews)); });
-
Call the tagsViewCache() method in the mounted() method, the content is as follows
this. tagsViewCache();
-
Delete all tagviews when logging out, so you need to add the following to async logout() in the methods method of Navbar.vue in the layout/components file:
// Delete all tagviews when logging out await this. $store. dispatch('tagsView/delAllViews') sessionStorage. removeItem('tabViews') Modify the path to: this.$router.push("/login")
Integrate Swagger
-
Add dependencies to the pom.xml file
<!--Swagger Documentation Tool--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency>
-
Configure a swagger configuration class MySwaggerConfig.java, the content is as follows
package com.zz.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.oas.annotations.EnableOpenApi; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; /** * ClassName: MySwaggerConfig * Package:com.zz.config * Description: description information * * @date:2023/5/18 9:27 * @author:ZZ */ @Configuration @EnableOpenApi @EnableWebMvc public class MySwaggerConfig {<!-- --> @Bean public Docket api() {<!-- --> return new Docket(DocumentationType.OAS_30) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.zz"))//Here is the package name .paths(PathSelectors. any()) .build(); } private ApiInfo apiInfo() {<!-- --> return new ApiInfoBuilder() .title("XXXX Management System Interface Document") .description("The simplest SpringBoot + Vue front-end and back-end separation project in the whole network") .version("1.0") .contact(new Contact("qqcn", "http://www.qqcn.cn", "[email protected]")) .build(); } }
-
The controller adds swagger annotations as needed
-
Test swagger address: http://localhost:9999/swagger-ui/index.html
-
Add an @ApiOperation(“xxx”) to each method, which can be described in swagger.
-
Improve the swagger configuration file so that the token value can be carried.
package com.zz.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.oas.annotations.EnableOpenApi; import springfox.documentation.service.*; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; import java.util.Collections; import java.util.List; /** * ClassName: MySwaggerConfig * Package:com.zz.config * Description: description information * * @date:2023/5/18 9:27 * @author:ZZ */ @Configuration @EnableOpenApi @EnableWebMvc public class MySwaggerConfig {<!-- --> @Bean public Docket api() {<!-- --> return new Docket(DocumentationType.OAS_30) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.zz"))//Here is the package name .paths(PathSelectors. any()) .build() .securitySchemes(Collections. singletonList(securityScheme())) .securityContexts(Collections. singletonList(securityContext())); } private SecurityScheme securityScheme() {<!-- --> //return new ApiKey("Authorization", "Authorization", "header"); return new ApiKey("X-Token", "X-Token", "header"); } private SecurityContext securityContext() {<!-- --> return SecurityContext. builder() .securityReferences(defaultAuth()) .forPaths(PathSelectors.regex("^(?!auth).*$")) .build(); } private List<SecurityReference> defaultAuth() {<!-- --> AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; authorizationScopes[0] = authorizationScope; return Collections. singletonList( new SecurityReference("X-Token", authorizationScopes)); } private ApiInfo apiInfo() {<!-- --> return new ApiInfoBuilder() .title("XXXX Management System Interface Document") .description("The simplest SpringBoot + Vue front-end and back-end separation project in the whole network") .version("1.0") .contact(new Contact("qqcn", "http://www.qqcn.cn", "[email protected]")) .build(); } }