From 47d1547858e7cd1d2d8f4d3990bffc8aa3a97f81 Mon Sep 17 00:00:00 2001 From: zpc Date: Sat, 27 Jul 2024 20:17:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=AC=E5=85=B1=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-client/.env | 4 +- admin-client/.env.development | 2 + .../curd/select-components/TenantSelect.vue | 19 +++ .../src/core/utils/AppDictionaryCache.ts | 21 +++ .../utils/cache/AbstractDictionaryCache.ts | 159 ++++++++++++++++++ .../utils/cache/AppDictionaryImageCache.ts | 61 +++++++ .../utils/cache/AppDictionaryTenantCache.ts | 22 +++ admin-client/src/main.ts | 1 + .../services/system/SysDictionaryService.ts | 8 + admin-client/src/utils/AppConsts.ts | 2 +- .../src/views/Apps/T_Image_Configs/Index.vue | 21 ++- .../src/views/Apps/T_Image_Configs/Info.vue | 8 +- admin-client/vite.config.ts | 2 +- .../Systems/SysDictionaryController.cs | 4 +- 14 files changed, 322 insertions(+), 12 deletions(-) create mode 100644 admin-client/.env.development create mode 100644 admin-client/src/core/components/curd/select-components/TenantSelect.vue create mode 100644 admin-client/src/core/utils/AppDictionaryCache.ts create mode 100644 admin-client/src/core/utils/cache/AbstractDictionaryCache.ts create mode 100644 admin-client/src/core/utils/cache/AppDictionaryImageCache.ts create mode 100644 admin-client/src/core/utils/cache/AppDictionaryTenantCache.ts diff --git a/admin-client/.env b/admin-client/.env index b98a346..cbba4b8 100644 --- a/admin-client/.env +++ b/admin-client/.env @@ -1,2 +1,2 @@ -VITE_BASE=/ # -VITE_BASEURL=https://adminapi.shhuanmeng.com \ No newline at end of file +VUE_APP_BASE=/ #打包路径 VUE_APP_ 开头的变量会被 webpack.DefinePlugin 静态嵌入到客户端侧的包中。你可以在应用的代码中这样访问它们 +VITE_API_URL=https://adminapi.shhuanmeng.com diff --git a/admin-client/.env.development b/admin-client/.env.development new file mode 100644 index 0000000..0996528 --- /dev/null +++ b/admin-client/.env.development @@ -0,0 +1,2 @@ +VUE_APP_BASE=/ #打包路径 +VITE_API_URL=http://192.168.195.30:91 \ No newline at end of file diff --git a/admin-client/src/core/components/curd/select-components/TenantSelect.vue b/admin-client/src/core/components/curd/select-components/TenantSelect.vue new file mode 100644 index 0000000..8827269 --- /dev/null +++ b/admin-client/src/core/components/curd/select-components/TenantSelect.vue @@ -0,0 +1,19 @@ + + + \ No newline at end of file diff --git a/admin-client/src/core/utils/AppDictionaryCache.ts b/admin-client/src/core/utils/AppDictionaryCache.ts new file mode 100644 index 0000000..9dfeaf5 --- /dev/null +++ b/admin-client/src/core/utils/AppDictionaryCache.ts @@ -0,0 +1,21 @@ + +import AppDictionaryImageCache from "./cache/AppDictionaryImageCache"; +import { AbstractDictionaryCache } from "./cache/AbstractDictionaryCache"; +import AppDictionaryTenantCache from "./cache/AppDictionaryTenantCache"; + +/** + * 基础数据缓存类 + */ +class AppDictionaryCache { + /** + * 图片类型 + */ + static appDictionaryImageCache: AbstractDictionaryCache = new AppDictionaryImageCache(); + + /** + * 多租户配置 + */ + static appDictionaryTenantCache: AbstractDictionaryCache = new AppDictionaryTenantCache(); +} + +export default AppDictionaryCache; diff --git a/admin-client/src/core/utils/cache/AbstractDictionaryCache.ts b/admin-client/src/core/utils/cache/AbstractDictionaryCache.ts new file mode 100644 index 0000000..779532b --- /dev/null +++ b/admin-client/src/core/utils/cache/AbstractDictionaryCache.ts @@ -0,0 +1,159 @@ +import SysDictionaryService from "@/services/system/SysDictionaryService"; +import { DefaultOptionType } from "ant-design-vue/es/select"; + +/** + * 常用返回的缓存类 + */ +export interface AppDictionaryModel { + /** + * 名字 + */ + name: string; + /** + * 值 + */ + value: number | string | any; + /** + * 编码 + */ + code: string; +} + +/** + * 抽象缓存类 + */ +abstract class _AbstractDictionaryCache { + /** + * 获取字典服务 + * @param code 字典标识 + * @returns Promise + */ + protected async getSysDictionaryService(code: string): Promise { + var response = await SysDictionaryService.getDictionaryByCode(code); + return response.data; + } + + /** + * 获取字典列表并转换为 AppDictionaryModel + * @param code 字典标识 + * @returns Promise + */ + protected async getSysDictionaryCacheCommonModel( + code: string + ): Promise { + //获取缓存 + const response = await this.getSysDictionaryService(code); + //映射出去 + return response.map((item: any) => { + let value: string | number | any = item.value; + const numericValue = Number(value); + + if (!isNaN(numericValue)) { + value = numericValue; + } + + return { + name: item.name, + value: value, + code: item.code, + } as AppDictionaryModel; + }); + } + + /** + * 获取图片类型列表 + * @returns Promise + */ + abstract getImageTypeList(): Promise; + + /** + * 获取图片类型下拉框 + * @returns Promise + */ + abstract getImageTypeSelect(): Promise; +} + +/** + * 抽象缓存类 + */ +abstract class AbstractDictionaryCache { + /** + * 字典名称 + */ + protected abstract code: string; + /** + * 锁 + */ + protected _lock: Promise | null = null; + /** + * 构造函数 + * @param lock 锁,需要传入一个常量过来 + */ + constructor(lock: Promise | null) { + this._lock = lock; + } + + /** + * 字典缓存 + */ + private _dataList: AppDictionaryModel[] | undefined; + /** + * 获取字典服务 + * @returns Promise + */ + protected async getSysDictionaryService(): Promise { + const response = await SysDictionaryService.getDictionaryByCode(this.code); + return response.data; + } + + /** + * 获取字典列表并转换为 AppDictionaryModel + * @returns Promise + */ + protected async getSysDictionaryCacheCommonModel(): Promise { + const response = await this.getSysDictionaryService(); + return response.map((item: any) => { + const value = isNaN(Number(item.value)) ? item.value : Number(item.value); + return { name: item.name, value, code: item.code } as AppDictionaryModel; + }); + } + + /** + * 获取数据列表 + * @returns Promise + */ + public async getDataList(): Promise { + while (this._lock) { + await this._lock; + } + //判断是否为空 + if (!this._dataList) { + //执行锁 + this._lock = (async () => { + try { + //在锁中判断是否为空 + if (this._dataList == null) { + //执行获取数据方法 + this._dataList = await this.getSysDictionaryCacheCommonModel(); + } + } finally { + this._lock = null; + } + })(); + await this._lock; + } + //最后一步判断是否为空 + if (this._dataList === undefined) { + this._dataList = []; + } + return this._dataList; + } + + /** + * 获取图片类型下拉框 + * @returns Promise + */ + abstract getDataListSelect(): Promise; +} + +export { AbstractDictionaryCache, _AbstractDictionaryCache }; diff --git a/admin-client/src/core/utils/cache/AppDictionaryImageCache.ts b/admin-client/src/core/utils/cache/AppDictionaryImageCache.ts new file mode 100644 index 0000000..f7980c0 --- /dev/null +++ b/admin-client/src/core/utils/cache/AppDictionaryImageCache.ts @@ -0,0 +1,61 @@ +import { AbstractDictionaryCache, AppDictionaryModel, _AbstractDictionaryCache } from './AbstractDictionaryCache' +import { DefaultOptionType } from "ant-design-vue/es/select"; +/** + * 实现具体的缓存服务 + */ +class _AppDictionaryImageCache extends _AbstractDictionaryCache { + /** + * 字典缓存 + */ + private static _ImageType_Cache?: AppDictionaryModel[]; + /** + * 字典名称 + */ + private image_type_name: string = "image_types"; + + /** + * 获取图片类型列表 + * @returns Promise + */ + async getImageTypeList(): Promise { + if (!AppDictionaryImageCache._ImageType_Cache) { + AppDictionaryImageCache._ImageType_Cache = await this.getSysDictionaryCacheCommonModel(this.image_type_name); + } + return AppDictionaryImageCache._ImageType_Cache; + } + + /** + * 获取图片类型下拉框 + * @returns Promise + */ + async getImageTypeSelect(): Promise { + const _data = await this.getImageTypeList(); + return _data.map((item) => { + return { + label: item.name, + value: item.value, + name: item.code, + } as DefaultOptionType; + }); + } +} + +/** + * 图片类型配置 + */ +class AppDictionaryImageCache extends AbstractDictionaryCache { + protected code: string = "image_types"; + public static _lock: Promise | null = null; + constructor() { + super(AppDictionaryImageCache._lock); + } + public async getDataListSelect(): Promise { + const _data = await this.getDataList(); + return _data.map((item) => { + return { label: item.name, value: item.value, name: item.code, } as DefaultOptionType; + }); + } + +} + +export default AppDictionaryImageCache; \ No newline at end of file diff --git a/admin-client/src/core/utils/cache/AppDictionaryTenantCache.ts b/admin-client/src/core/utils/cache/AppDictionaryTenantCache.ts new file mode 100644 index 0000000..afcb556 --- /dev/null +++ b/admin-client/src/core/utils/cache/AppDictionaryTenantCache.ts @@ -0,0 +1,22 @@ +import { AbstractDictionaryCache } from './AbstractDictionaryCache' +import { DefaultOptionType } from "ant-design-vue/es/select"; + +/** + * 多租户配置 + */ +class AppDictionaryTenantCache extends AbstractDictionaryCache { + protected code: string = "tenant"; + public static _lock: Promise | null = null; + constructor() { + super(AppDictionaryTenantCache._lock); + } + public async getDataListSelect(): Promise { + const _data = await this.getDataList(); + return _data.map((item) => { + return { label: item.name, value: item.value, name: item.code, } as DefaultOptionType; + }); + } + +} + +export default AppDictionaryTenantCache; \ No newline at end of file diff --git a/admin-client/src/main.ts b/admin-client/src/main.ts index 3315ddb..7c151ae 100644 --- a/admin-client/src/main.ts +++ b/admin-client/src/main.ts @@ -27,3 +27,4 @@ createApp(App) .use(print) .use(i18n) .mount("#app"); +console.log(import.meta.env.VITE_API_URL); diff --git a/admin-client/src/services/system/SysDictionaryService.ts b/admin-client/src/services/system/SysDictionaryService.ts index b9e652f..31e921a 100644 --- a/admin-client/src/services/system/SysDictionaryService.ts +++ b/admin-client/src/services/system/SysDictionaryService.ts @@ -53,4 +53,12 @@ export default class SysDictionaryService { static sysOrganizationTree() { return Http.post(`${this.urlPrefix}/sysOrganizationTree`); } + /** + * 获取字典集合 + * @param code 字典编码 + * @returns + */ + static getDictionaryByCode(code: string) { + return Http.get(`${this.urlPrefix}/GetDictionaryByCode/${code}`); + } } diff --git a/admin-client/src/utils/AppConsts.ts b/admin-client/src/utils/AppConsts.ts index aa0d795..b12875c 100644 --- a/admin-client/src/utils/AppConsts.ts +++ b/admin-client/src/utils/AppConsts.ts @@ -23,7 +23,7 @@ class AppConsts { /** * 后台服务api域名 */ - static domainServerApi: string ='https://adminapi.shhuanmeng.com'//import.meta.env.VITE_BASEURL// process.env.NODE_ENV == "production" ? "" : "http://localhost:5500" + static domainServerApi: string =import.meta.env.VITE_API_URL// process.env.NODE_ENV == "production" ? "" : "http://localhost:5500" /** * app 前缀 用于浏览器本地缓存 key 的前缀 diff --git a/admin-client/src/views/Apps/T_Image_Configs/Index.vue b/admin-client/src/views/Apps/T_Image_Configs/Index.vue index 4a80f34..16ed5aa 100644 --- a/admin-client/src/views/Apps/T_Image_Configs/Index.vue +++ b/admin-client/src/views/Apps/T_Image_Configs/Index.vue @@ -1,25 +1,31 @@