refactor: 重构项目配置和布局

- 移除了 OpenController 中的 @CheckOpenApi 注解
- 更新了 Layout 组件中的标题和 logo 属性
- 修改了路由配置,使用 __APP_INFO.moduleName 替代 __APP_ENV.VITE_APP_MODULE_NAME
- 更新了全局类型定义,增加了 __APP_INFO 对象
- 调整了 Vite 环境变量配置,移除了 VITE_APP_MODULE_NAME
- 更新了项目名称和版本号
This commit is contained in:
luozhun 2024-11-21 10:06:30 +08:00
parent 372d7e12cf
commit a2819042df
13 changed files with 23 additions and 102 deletions

View File

@ -1,17 +0,0 @@
package com.changhu.common.annotation;
import com.changhu.common.enums.OpenApiType;
import java.lang.annotation.*;
/**
* @author 20252
* @createTime 2024/10/9 下午5:14
* @desc 检查openApi
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CheckOpenApi {
OpenApiType value();
}

View File

@ -1,22 +0,0 @@
package com.changhu.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
/**
* @author 20252
* @createTime 2024/10/9 下午5:10
* @desc OpenApiType...
*/
@Getter
@AllArgsConstructor
public enum OpenApiType {
Information_on_enterprises_and_institutions("获取企事业单位信息", Arrays.asList("1fe0aaf3-45a4-4be3-a989-75e914a3f36e", "1fe0aaf3-45a4-a989-75e914a3f36e")),
data_view("数据总览", List.of("8da74bbf-c686-4393-b4ec-692091e6d381"));
private final String desc;
private final List<String> openApiKeys;
}

View File

@ -1,8 +1,6 @@
package com.changhu.controller; package com.changhu.controller;
import com.changhu.common.annotation.CheckOpenApi;
import com.changhu.common.annotation.JsonBody; import com.changhu.common.annotation.JsonBody;
import com.changhu.common.enums.OpenApiType;
import com.changhu.common.pojo.vo.SelectNodeVo; import com.changhu.common.pojo.vo.SelectNodeVo;
import com.changhu.pojo.dto.DataViewDTO; import com.changhu.pojo.dto.DataViewDTO;
import com.changhu.pojo.dto.EnterprisesUnitDetailDTO; import com.changhu.pojo.dto.EnterprisesUnitDetailDTO;
@ -33,7 +31,6 @@ public class OpenController {
private OpenApiService openApiService; private OpenApiService openApiService;
@Operation(summary = "获取企事业单位列表") @Operation(summary = "获取企事业单位列表")
@CheckOpenApi(value = OpenApiType.Information_on_enterprises_and_institutions)
@GetMapping("/getEnterprisesUnit") @GetMapping("/getEnterprisesUnit")
public List<SelectNodeVo<Long>> getEnterprisesUnit(@Schema(description = "代码") @RequestParam String code, public List<SelectNodeVo<Long>> getEnterprisesUnit(@Schema(description = "代码") @RequestParam String code,
@Schema(description = "等级") @RequestParam Integer level) { @Schema(description = "等级") @RequestParam Integer level) {
@ -41,21 +38,18 @@ public class OpenController {
} }
@Operation(summary = "企事业单位详情") @Operation(summary = "企事业单位详情")
@CheckOpenApi(value = OpenApiType.Information_on_enterprises_and_institutions)
@GetMapping("/enterprisesUnitDetailById") @GetMapping("/enterprisesUnitDetailById")
public EnterprisesUnitDetailDTO enterprisesUnitDetailById(@Schema(description = "企事业单位id") @RequestParam Long enterprisesUnitId) { public EnterprisesUnitDetailDTO enterprisesUnitDetailById(@Schema(description = "企事业单位id") @RequestParam Long enterprisesUnitId) {
return openApiService.enterprisesUnitDetailById(enterprisesUnitId); return openApiService.enterprisesUnitDetailById(enterprisesUnitId);
} }
@Operation(summary = "数据总览") @Operation(summary = "数据总览")
@CheckOpenApi(value = OpenApiType.data_view)
@GetMapping("/dataView") @GetMapping("/dataView")
public DataViewDTO dataView() { public DataViewDTO dataView() {
return openApiService.dataView(); return openApiService.dataView();
} }
@Operation(summary = "保安单位使用情况统计") @Operation(summary = "保安单位使用情况统计")
@CheckOpenApi(value = OpenApiType.Information_on_enterprises_and_institutions)
@GetMapping("/securityUnitUseStatistics") @GetMapping("/securityUnitUseStatistics")
public List<SecurityUnitUseStatisticsDTO> securityUnitUseStatistics(@Schema(description = "代码") @RequestParam String code, public List<SecurityUnitUseStatisticsDTO> securityUnitUseStatistics(@Schema(description = "代码") @RequestParam String code,
@Schema(description = "等级") @RequestParam Integer level) { @Schema(description = "等级") @RequestParam Integer level) {
@ -63,7 +57,6 @@ public class OpenController {
} }
@Operation(summary = "服务项目安保人员花名册") @Operation(summary = "服务项目安保人员花名册")
@CheckOpenApi(value = OpenApiType.Information_on_enterprises_and_institutions)
@GetMapping("/serviceProjectUserRoster") @GetMapping("/serviceProjectUserRoster")
public List<ServiceProjectSecurityUserRosterDTO> serviceProjectUserRoster(@Schema(description = "服务项目id") Long serviceProjectId) { public List<ServiceProjectSecurityUserRosterDTO> serviceProjectUserRoster(@Schema(description = "服务项目id") Long serviceProjectId) {
return openApiService.serviceProjectUserRoster(serviceProjectId); return openApiService.serviceProjectUserRoster(serviceProjectId);

View File

@ -1,42 +0,0 @@
package com.changhu.support.interceptor;
import cn.hutool.core.util.StrUtil;
import com.changhu.common.annotation.CheckOpenApi;
import com.changhu.common.exception.MessageException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author 20252
* @createTime 2024/10/9 下午5:05
* @desc OpenApiInterceptor...
*/
@Slf4j
public class OpenApiInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) {
if (handler instanceof HandlerMethod handlerMethod) {
String header = request.getHeader("X-API-KEY");
if (StrUtil.isBlank(header)) {
throw new MessageException("请求头缺失");
}
log.info("apiKey:{} {} 请求:{}", header, LocalDateTime.now(), request.getRequestURI());
CheckOpenApi methodAnnotation = handlerMethod.getMethodAnnotation(CheckOpenApi.class);
if (methodAnnotation != null) {
List<String> openApiKeys = methodAnnotation.value().getOpenApiKeys();
if (!openApiKeys.contains(header)) {
throw new MessageException("openApiKey error!");
}
}
}
return true;
}
}

View File

@ -1,8 +1,7 @@
VITE_APP_NAME=超级后台 VITE_APP_NAME=保安管理
VITE_APP_ENV=development VITE_APP_ENV=development
VITE_APP_PORT=1000 VITE_APP_PORT=1000
VITE_DROP_CONSOLE=false VITE_DROP_CONSOLE=false
VITE_APP_MODULE_NAME=superManagement
# axios # axios
VITE_APP_BASE_API=/api VITE_APP_BASE_API=/api

View File

@ -1,8 +1,7 @@
VITE_APP_NAME=超级后台 VITE_APP_NAME=保安管理
VITE_APP_ENV=production VITE_APP_ENV=production
VITE_APP_PORT=1001 VITE_APP_PORT=1001
VITE_DROP_CONSOLE=true VITE_DROP_CONSOLE=true
VITE_APP_MODULE_NAME=superManagement
# axios # axios
VITE_APP_BASE_API=/api VITE_APP_BASE_API=/api

View File

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script type="module" src="/src/assets/iconfont/iconfont.js"></script> <script type="module" src="/src/assets/iconfont/iconfont.js"></script>
<title>超级后台</title> <title>保安管理</title>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

View File

@ -1,6 +1,6 @@
{ {
"name": "supermanagement", "name": "super_management",
"appName": "超级后台", "appName": "保安管理",
"private": true, "private": true,
"version": "1.0.0", "version": "1.0.0",
"type": "module", "type": "module",

View File

@ -7,10 +7,10 @@
collapsible collapsible
> >
<div v-if="!collapsed" class="title flex-center"> <div v-if="!collapsed" class="title flex-center">
<div>超级后台</div> <div>{{ appInfo.appName }}</div>
</div> </div>
<div v-else class="logo flex-center"> <div v-else class="logo flex-center">
<img src="@/assets/vue.svg" title="超级后台" alt="xx"> <img src="@/assets/vue.svg" :title="appInfo.appName" alt="xx">
</div> </div>
<SystemMenus/> <SystemMenus/>
</a-layout-sider> </a-layout-sider>
@ -40,6 +40,8 @@ import {ref} from "vue";
import LayoutHeader from "@/components/layout/header/LayoutHeader.vue"; import LayoutHeader from "@/components/layout/header/LayoutHeader.vue";
import SystemMenus from "@/components/layout/SystemMenus.vue"; import SystemMenus from "@/components/layout/SystemMenus.vue";
const appInfo = __APP_INFO
const collapsed = ref<boolean>(false); const collapsed = ref<boolean>(false);
const keepAliveNames = ref<string[]>([]) const keepAliveNames = ref<string[]>([])

View File

@ -1,4 +1,9 @@
declare const __APP_ENV: ImportMetaEnv; declare const __APP_ENV: ImportMetaEnv;
declare const __APP_INFO: {
moduleName: string,
appName: string,
version: string
}
/** /**
* *

View File

@ -10,7 +10,7 @@ import {ROUTER_WHITE_LIST} from "@/config";
* createWebHashHistory: 路径带# URL SEO * createWebHashHistory: 路径带# URL SEO
*/ */
const router = createRouter({ const router = createRouter({
history: createWebHistory(__APP_ENV.VITE_APP_MODULE_NAME), history: createWebHistory(__APP_INFO.moduleName),
routes: [...staticRouter], routes: [...staticRouter],
strict: false, strict: false,
scrollBehavior: () => ({left: 0, top: 0}), scrollBehavior: () => ({left: 0, top: 0}),

View File

@ -6,8 +6,6 @@ interface ImportMetaEnv {
readonly VITE_APP_ENV: 'development' | 'production'; readonly VITE_APP_ENV: 'development' | 'production';
// 启动端口 // 启动端口
readonly VITE_APP_PORT: number; readonly VITE_APP_PORT: number;
// 模块名称
readonly VITE_APP_MODULE_NAME: string;
// axios // axios
readonly VITE_APP_BASE_API: string; readonly VITE_APP_BASE_API: string;

View File

@ -4,6 +4,7 @@ import Components from 'unplugin-vue-components/vite';
import {AntDesignVueResolver} from 'unplugin-vue-components/resolvers'; import {AntDesignVueResolver} from 'unplugin-vue-components/resolvers';
import * as path from "node:path"; import * as path from "node:path";
import vueJsx from '@vitejs/plugin-vue-jsx' import vueJsx from '@vitejs/plugin-vue-jsx'
import {appName, version, name} from './package.json'
const pathSrc = path.resolve(__dirname, 'src'); const pathSrc = path.resolve(__dirname, 'src');
@ -12,9 +13,14 @@ export default defineConfig(({mode}) => {
const env: Record<string, string> = loadEnv(mode, process.cwd(), '') const env: Record<string, string> = loadEnv(mode, process.cwd(), '')
return { return {
define: { define: {
__APP_ENV: JSON.stringify(env) __APP_ENV: JSON.stringify(env),
__APP_INFO: JSON.stringify({
moduleName: name,
appName,
version
})
}, },
base: `/${env['VITE_APP_MODULE_NAME']}/`, base: `/${name}/`,
plugins: [ plugins: [
vue(), vue(),
vueJsx(), vueJsx(),