添加公共方法

This commit is contained in:
zpc 2024-07-27 20:17:21 +08:00
parent d8f165b5f2
commit 47d1547858
14 changed files with 322 additions and 12 deletions

View File

@ -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

View File

@ -0,0 +1,2 @@
VUE_APP_BASE=/ #打包路径
VITE_API_URL=http://192.168.195.30:91

View File

@ -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>

View 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;

View 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 };

View 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;

View 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;

View File

@ -27,3 +27,4 @@ createApp(App)
.use(print)
.use(i18n)
.mount("#app");
console.log(import.meta.env.VITE_API_URL);

View File

@ -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}`);
}
}

View File

@ -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

View File

@ -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-->

View File

@ -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 }>();

View File

@ -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,

View File

@ -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);