| | |
| | | import { UserConfigFn } from 'vite'; |
| | | import { useGlobSetting } from '/@/hooks/setting'; |
| | | import { buildUUID } from '../../utils/uuid'; |
| | | import { DateFormat } from '../../utils/dataformat'; |
| | | import { ApiAction, ApiActionJob, ApiActionPage } from '../model/baseModel'; |
| | |
| | | LoginLogPageListGetResultModel, |
| | | iSYS_ROLE_ORG, |
| | | iSYS_ROLE_WH, |
| | | EntityParams, |
| | | EntityList, |
| | | } from './model/systemModel'; |
| | | import { defHttp } from '/@/utils/http/axios'; |
| | | import { isNullOrEmpty } from '/@/utils/is'; |
| | | |
| | | export enum Api { |
| | | QueryUrl = '/Base/Query', |
| | |
| | | //导入 |
| | | ValidateTableImport = '/SMT/ValidateTableImport', |
| | | SaveValidateTableImport = '/SMT/SaveValidateTableImport', |
| | | GetEntityNameList = '/System/Entitys/Get', |
| | | } |
| | | |
| | | const globSetting = useGlobSetting(); |
| | | |
| | | /** |
| | | * 生成apiaction,带分页 |
| | |
| | | return model; |
| | | } |
| | | |
| | | /* |
| | | *通用方法======================================================== |
| | | */ |
| | | |
| | | export const GetEnum = async (enumName: { name: string }) => { |
| | | const usParams = genAction(enumName.name, ''); |
| | | return await defHttp.post( |
| | |
| | | }, |
| | | ); |
| | | }; |
| | | |
| | | /* 通用查询分页 */ |
| | | export async function getListByPage<T>(params: T) { |
| | | const Keys = Object.getOwnPropertyNames(params); |
| | | let sqlcmd = ''; |
| | | for (const k in Keys) { |
| | | console.log(`${k}:${Keys[k]}`); |
| | | if ( |
| | | !isNullOrEmpty(params[Keys[k]]) && |
| | | Keys[k] != 'page' && |
| | | Keys[k] != 'pageSize' && |
| | | Keys[k] != 'TABLE_NAME' |
| | | ) { |
| | | sqlcmd += `And ${Keys[k]} like '%${params[Keys[k]]}%'`; |
| | | } |
| | | } |
| | | const rParams = genActionPage(params['TABLE_NAME'], sqlcmd, params['page'], params['pageSize']); |
| | | return getListByPageAsync(rParams); |
| | | } |
| | | async function getListByPageAsync(params: ApiActionPage) { |
| | | const data = await defHttp.post<ApiActionPage>( |
| | | { url: Api.EntityPageList, params }, |
| | | { |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | const model = { |
| | | items: data.Data.data, |
| | | total: data.Data.totals, |
| | | }; |
| | | return model; |
| | | } |
| | | |
| | | export async function SaveEntity<T>(params: T, isUpdate: boolean, entityName: string) { |
| | | let data; |
| | | if (isUpdate) { |
| | | data = await defHttp.post( |
| | | { url: Api.UpdateEntity, params: genAction(entityName, params) }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | } else { |
| | | params.ID = buildUUID(); //生成GUID |
| | | data = await defHttp.post( |
| | | { url: Api.AddEntity, params: genAction(entityName, params) }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | } |
| | | return data; |
| | | } |
| | | |
| | | export async function DeleteEntity<T>(params: T, entityName: string) { |
| | | const usParams = genAction(entityName, [params]); |
| | | return await defHttp.post( |
| | | { url: Api.DeleteList, params: usParams }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | } |
| | | |
| | | //获取服务器Json文件返回Json数据 |
| | | export async function fetchJson(url: string) { |
| | | try { |
| | | const response = await fetch(url); |
| | | return await response.json(); |
| | | } catch (error) { |
| | | console.error('Error fetching columns:', error); |
| | | } |
| | | } |
| | | |
| | | // 泛型函数,获取类的名称 |
| | | export function getClassName<T>(ctor: new () => T): string { |
| | | return ctor.name; |
| | | } |
| | | |
| | | export const getEntityList = (params?: EntityParams) => |
| | | defHttp.get<EntityList>( |
| | | { url: Api.GetEntityNameList, params }, |
| | | { |
| | | isTransformResponse: false, |
| | | apiUrl: globSetting.sysApiUrl, |
| | | }, |
| | | ); |
| | | |
| | | export async function getEntityNameList(params?: EntityParams) { |
| | | const data = await defHttp.get<EntityList>( |
| | | { url: Api.GetEntityNameList, params }, |
| | | { |
| | | isTransformResponse: false, |
| | | apiUrl: globSetting.sysApiUrl, |
| | | }, |
| | | ); |
| | | const model = { |
| | | items: data.Data, |
| | | total: data.Total, |
| | | }; |
| | | return model; |
| | | } |
| | | |
| | | export async function getEntityPropertieList(params?: EntityParams) { |
| | | const data = await defHttp.get<EntityList>( |
| | | { url: Api.GetEntityNameList, params }, |
| | | { |
| | | isTransformResponse: false, |
| | | apiUrl: globSetting.sysApiUrl, |
| | | }, |
| | | ); |
| | | const model = { |
| | | items: data.Data.filter((x) => x.Name == params?.StartWith)[0].Properties, |
| | | total: data.Total, |
| | | }; |
| | | return model; |
| | | } |
| | | |
| | | /* 通用获取实体记录 */ |
| | | export const getEntity = async (params: { sqlcmd: string; entityName: string }) => { |
| | | const usParams = genAction(params.entityName, { |
| | | QueryAble_T: '', |
| | | where: params.sqlcmd, |
| | | order: '', |
| | | }); |
| | | return await defHttp.post( |
| | | { url: Api.QueryUrl, params: usParams }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | }; |