添加公共方法
This commit is contained in:
parent
d8f165b5f2
commit
47d1547858
|
|
@ -1,2 +1,2 @@
|
|||
VITE_BASE=/ #
|
||||
VITE_BASEURL=https://adminapi.shhuanmeng.com
|
||||
VUE_APP_BASE=/ #打包路径 VUE_APP_ 开头的变量会被 webpack.DefinePlugin 静态嵌入到客户端侧的包中。你可以在应用的代码中这样访问它们
|
||||
VITE_API_URL=https://adminapi.shhuanmeng.com
|
||||
|
|
|
|||
2
admin-client/.env.development
Normal file
2
admin-client/.env.development
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
VUE_APP_BASE=/ #打包路径
|
||||
VITE_API_URL=http://192.168.195.30:91
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<script lang="ts" setup>
|
||||
import { computed, reactive, ref } from "vue";
|
||||
import type { UploadProps, SelectProps } from 'ant-design-vue';
|
||||
import AppDictionaryCache from "@/core/utils/AppDictionaryCache";
|
||||
const options = ref<SelectProps['options']>([
|
||||
// { value: 0, label: '默认' },
|
||||
]);
|
||||
const props = defineProps<{ onSuccess: () => void }>();
|
||||
AppDictionaryCache.appDictionaryTenantCache.getDataListSelect().then(data => {
|
||||
console.log(data);
|
||||
options.value?.push(...data);
|
||||
});
|
||||
|
||||
</script>
|
||||
<template>
|
||||
<a-select :options="options">
|
||||
</a-select>
|
||||
</template>
|
||||
<style lang="less"></style>
|
||||
21
admin-client/src/core/utils/AppDictionaryCache.ts
Normal file
21
admin-client/src/core/utils/AppDictionaryCache.ts
Normal file
|
|
@ -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;
|
||||
159
admin-client/src/core/utils/cache/AbstractDictionaryCache.ts
vendored
Normal file
159
admin-client/src/core/utils/cache/AbstractDictionaryCache.ts
vendored
Normal file
|
|
@ -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<any>
|
||||
*/
|
||||
protected async getSysDictionaryService(code: string): Promise<any> {
|
||||
var response = await SysDictionaryService.getDictionaryByCode(code);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典列表并转换为 AppDictionaryModel
|
||||
* @param code 字典标识
|
||||
* @returns Promise<AppDictionaryModel[]>
|
||||
*/
|
||||
protected async getSysDictionaryCacheCommonModel(
|
||||
code: string
|
||||
): Promise<AppDictionaryModel[]> {
|
||||
//获取缓存
|
||||
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<AppDictionaryModel[]>
|
||||
*/
|
||||
abstract getImageTypeList(): Promise<AppDictionaryModel[]>;
|
||||
|
||||
/**
|
||||
* 获取图片类型下拉框
|
||||
* @returns Promise<DefaultOptionType[]>
|
||||
*/
|
||||
abstract getImageTypeSelect(): Promise<DefaultOptionType[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽象缓存类
|
||||
*/
|
||||
abstract class AbstractDictionaryCache {
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
protected abstract code: string;
|
||||
/**
|
||||
* 锁
|
||||
*/
|
||||
protected _lock: Promise<void> | null = null;
|
||||
/**
|
||||
* 构造函数
|
||||
* @param lock 锁,需要传入一个常量过来
|
||||
*/
|
||||
constructor(lock: Promise<void> | null) {
|
||||
this._lock = lock;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典缓存
|
||||
*/
|
||||
private _dataList: AppDictionaryModel[] | undefined;
|
||||
/**
|
||||
* 获取字典服务
|
||||
* @returns Promise<any>
|
||||
*/
|
||||
protected async getSysDictionaryService(): Promise<any> {
|
||||
const response = await SysDictionaryService.getDictionaryByCode(this.code);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典列表并转换为 AppDictionaryModel
|
||||
* @returns Promise<AppDictionaryModel[]>
|
||||
*/
|
||||
protected async getSysDictionaryCacheCommonModel(): Promise<AppDictionaryModel[]> {
|
||||
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<AppDictionaryModel[]>
|
||||
*/
|
||||
public async getDataList(): Promise<AppDictionaryModel[]> {
|
||||
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<DefaultOptionType[]>
|
||||
*/
|
||||
abstract getDataListSelect(): Promise<DefaultOptionType[]>;
|
||||
}
|
||||
|
||||
export { AbstractDictionaryCache, _AbstractDictionaryCache };
|
||||
61
admin-client/src/core/utils/cache/AppDictionaryImageCache.ts
vendored
Normal file
61
admin-client/src/core/utils/cache/AppDictionaryImageCache.ts
vendored
Normal file
|
|
@ -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<AppDictionaryModel[]>
|
||||
*/
|
||||
async getImageTypeList(): Promise<AppDictionaryModel[]> {
|
||||
if (!AppDictionaryImageCache._ImageType_Cache) {
|
||||
AppDictionaryImageCache._ImageType_Cache = await this.getSysDictionaryCacheCommonModel(this.image_type_name);
|
||||
}
|
||||
return AppDictionaryImageCache._ImageType_Cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片类型下拉框
|
||||
* @returns Promise<DefaultOptionType[]>
|
||||
*/
|
||||
async getImageTypeSelect(): Promise<DefaultOptionType[]> {
|
||||
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<void> | null = null;
|
||||
constructor() {
|
||||
super(AppDictionaryImageCache._lock);
|
||||
}
|
||||
public async getDataListSelect(): Promise<DefaultOptionType[]> {
|
||||
const _data = await this.getDataList();
|
||||
return _data.map((item) => {
|
||||
return { label: item.name, value: item.value, name: item.code, } as DefaultOptionType;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default AppDictionaryImageCache;
|
||||
22
admin-client/src/core/utils/cache/AppDictionaryTenantCache.ts
vendored
Normal file
22
admin-client/src/core/utils/cache/AppDictionaryTenantCache.ts
vendored
Normal file
|
|
@ -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<void> | null = null;
|
||||
constructor() {
|
||||
super(AppDictionaryTenantCache._lock);
|
||||
}
|
||||
public async getDataListSelect(): Promise<DefaultOptionType[]> {
|
||||
const _data = await this.getDataList();
|
||||
return _data.map((item) => {
|
||||
return { label: item.name, value: item.value, name: item.code, } as DefaultOptionType;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default AppDictionaryTenantCache;
|
||||
|
|
@ -27,3 +27,4 @@ createApp(App)
|
|||
.use(print)
|
||||
.use(i18n)
|
||||
.mount("#app");
|
||||
console.log(import.meta.env.VITE_API_URL);
|
||||
|
|
|
|||
|
|
@ -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}`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 的前缀
|
||||
|
|
|
|||
|
|
@ -1,25 +1,31 @@
|
|||
<script lang="ts" setup>
|
||||
import { reactive, ref, onMounted } from "vue";
|
||||
import { FormInstance,SelectProps } from "ant-design-vue";
|
||||
import { FormInstance, SelectProps } from "ant-design-vue";
|
||||
import { useAuthority } from "@/utils/Authority";
|
||||
import AppIcon from "@/core/components/AppIcon.vue";
|
||||
import Info from "./Info.vue";
|
||||
import Tools from "@/core/utils/Tools";
|
||||
import AppDictionaryCache from "@/core/utils/AppDictionaryCache";
|
||||
import PageContainer from "@/core/components/PageContainer.vue";
|
||||
import TableCurd from "@/core/components/curd/TableCurd.vue";
|
||||
import TImageConfigService from "@/services/Apps/T_Image_Configs/TImageConfigService";
|
||||
|
||||
defineOptions({ name: "tImageConfigIndex" });
|
||||
|
||||
const options = ref<SelectProps['options']>([
|
||||
{ value: -1, label: '全部' },
|
||||
{ value: 0, label: '默认' },
|
||||
]);
|
||||
AppDictionaryCache.appDictionaryImageCache.getDataListSelect().then(data => {
|
||||
console.log(data);
|
||||
options.value?.push(...data) ;
|
||||
});
|
||||
|
||||
const state = reactive({
|
||||
search: {
|
||||
state: false,
|
||||
vm: {
|
||||
name: undefined,
|
||||
imageType:undefined,
|
||||
imageType: undefined,
|
||||
},
|
||||
sort: [] as any[],
|
||||
},
|
||||
|
|
@ -209,10 +215,13 @@ async function imageUpdate(image: any) {
|
|||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
|
||||
<a-form-item class="mb-0" name="name" label="名称">
|
||||
<a-select v-model:value="state.search.vm.imageType" :options="options">
|
||||
<a-form-item class="mb-0" name="name" label="文件类型">
|
||||
<TenantSelect>
|
||||
|
||||
</TenantSelect>
|
||||
<!-- <a-select v-model:value="state.search.vm.imageType" :options="options">
|
||||
|
||||
</a-select>
|
||||
</a-select> -->
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<!--button-->
|
||||
|
|
|
|||
|
|
@ -2,14 +2,20 @@
|
|||
import { reactive, ref } from "vue";
|
||||
import { FormInstance } from "ant-design-vue";
|
||||
import Tools from "@/core/utils/Tools";
|
||||
import AppDictionaryCache from "@/core/utils/AppDictionaryCache";
|
||||
import TImageConfigService from "@/services/Apps/T_Image_Configs/TImageConfigService";
|
||||
import { UploadOutlined } from '@ant-design/icons-vue';
|
||||
import { message } from 'ant-design-vue';
|
||||
import type { UploadProps, SelectProps } from 'ant-design-vue';
|
||||
|
||||
const options = ref<SelectProps['options']>([
|
||||
{ value: 0, label: '默认' },
|
||||
// { value: 0, label: '默认' },
|
||||
]);
|
||||
AppDictionaryCache.appDictionaryImageCache.getDataListSelect().then(data => {
|
||||
console.log(data);
|
||||
options.value?.push(...data) ;
|
||||
});
|
||||
|
||||
//定义组件事件
|
||||
const props = defineProps<{ onSuccess: () => void }>();
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default defineConfig({
|
|||
* 生产环境默认:client 文件夹包起来
|
||||
* 开发环境默认:/
|
||||
*/
|
||||
base: process.env.VITE_BASE, // process.env.NODE_ENV == "production" ? "/client/" : "/",
|
||||
base:process.env.VUE_APP_BASE, // process.env.NODE_ENV == "production" ? "/client/" : "/",
|
||||
server: {
|
||||
port: 5501,
|
||||
host: true,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ namespace MiaoYu.Api.Admin.Controllers.Systems;
|
|||
/// <summary>
|
||||
/// 数据字典控制器
|
||||
/// </summary>
|
||||
[ControllerDescriptor(MenuId = "23", DisplayName = "数据字典")]
|
||||
[ControllerDescriptor(MenuId = "", DisplayName = "数据字典")]
|
||||
public class SysDictionaryController : AdminControllerBase<SysDictionaryService>
|
||||
{
|
||||
public SysDictionaryController(SysDictionaryService defaultService) : base(defaultService)
|
||||
|
|
@ -82,6 +82,7 @@ public class SysDictionaryController : AdminControllerBase<SysDictionaryService>
|
|||
/// <returns></returns>
|
||||
[ActionDescriptor(DisplayName = "获取字典树")]
|
||||
[HttpGet()]
|
||||
[AllowAnonymous]
|
||||
public async Task<List<SysDictionaryDto>> GetDictionaryTreeAsync()
|
||||
{
|
||||
return await _defaultService.GetDictionaryTreeAsync();
|
||||
|
|
@ -93,6 +94,7 @@ public class SysDictionaryController : AdminControllerBase<SysDictionaryService>
|
|||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{code}")]
|
||||
[AllowAnonymous]
|
||||
public Task<List<SysDictionaryDto>> GetDictionaryByCodeAsync([FromRoute] string code)
|
||||
{
|
||||
return _defaultService.GetDictionaryByCodeAsync(code);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user