| | |
| | | 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, |
| | | iSYS_ROLE_PROD, |
| | | pParams, |
| | | } from './model/systemModel'; |
| | | import { defHttp } from '/@/utils/http/axios'; |
| | | import { isNullOrEmpty } from '/@/utils/is'; |
| | | import { isArray, isNullOrEmpty, isTimeViaRegExp8601 } from '/@/utils/is'; |
| | | import { isNumber } from 'xe-utils'; |
| | | |
| | | export enum Api { |
| | | QueryUrl = '/Base/Query', |
| | |
| | | EntitySqlList = '/Base/QuerySQL', |
| | | EntityPageList = '/Base/QueryCustomPage', |
| | | IsAccountExist = '/Base/IsExist', |
| | | AddAfterDelete = '/Base/AddAfterDelete', |
| | | setRoleStatus = '/system/setRoleStatus', |
| | | MenuList = '/SYS/getMenuListAll', |
| | | SaveMenu = '/SYS/SaveMenu', |
| | | SaveRole = '/SYS/SaveRole', |
| | | getSysParam = '/SYS/getSysParam', |
| | | AddEntity = '/Base/Add', |
| | | AddListEntity = '/Base/AddList', |
| | | UpdateEntity = '/Base/Update', |
| | |
| | | DeleteList = '/Base/DeleteList', |
| | | DeleteWhere = '/Base/DeleteWhere', |
| | | GetOrgTreeList = '/SYS/getOrgTreeList', |
| | | GetProdTreeList = '/SYS/getProdTreeList', |
| | | GetHouseTreeList = '/WMS/GetHouseModel', |
| | | GetHouseOrgTreeList = '/WMS/GetHouseModelOrg', |
| | | GetCreateBillCode = '/WMS/CreateBillCode', |
| | |
| | | //导入 |
| | | ValidateTableImport = '/SMT/ValidateTableImport', |
| | | SaveValidateTableImport = '/SMT/SaveValidateTableImport', |
| | | GetEntityNameList = '/System/Entitys/Get', |
| | | } |
| | | |
| | | const globSetting = useGlobSetting(); |
| | | |
| | | /** |
| | | * 生成apiaction,带分页 |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * @description: 树形表结构转树形Json |
| | | * @param {T} data |
| | | * @param {string} parentField 父字段名 |
| | | * @param {string} idField 唯一key字段名 |
| | | * @param {string} pid_val 父id值 |
| | | * @return {*} |
| | | */ |
| | | export function convertToTree<T>(data: T[], parentField: string, idField: string, pid?: string) { |
| | | const result: T[] = []; |
| | | let temp: T[] = []; |
| | | const _pid = isNullOrEmpty(pid) ? '' : pid; |
| | | for (let i = 0; i < data.length; i++) { |
| | | const currPid = data[i][parentField] == null ? '' : data[i][parentField]; |
| | | if (currPid === _pid) { |
| | | const obj = data[i] as T; |
| | | temp = convertToTree(data, parentField, idField, data[i][idField]); |
| | | if (temp.length > 0) { |
| | | obj['children'] = temp; |
| | | } |
| | | result.push(obj); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /* |
| | | * 保存参数 |
| | | */ |
| | |
| | | } |
| | | async function getRoleOrg(params: ApiAction<string>) { |
| | | const data = await defHttp.post<ApiAction<iSYS_ROLE_ORG[]>>( |
| | | { |
| | | url: Api.EntityList, |
| | | params, |
| | | }, |
| | | { |
| | | errorMessageMode: 'modal', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | return data.Data; |
| | | } |
| | | |
| | | export function getProdList(params: string) { |
| | | const rmParams = genAction('SYS_ROLE_PROD', " ROLE_CODE = '" + params + "'"); |
| | | return getRoleProd(rmParams); |
| | | } |
| | | async function getRoleProd(params: ApiAction<string>) { |
| | | const data = await defHttp.post<ApiAction<iSYS_ROLE_PROD[]>>( |
| | | { |
| | | url: Api.EntityList, |
| | | params, |
| | |
| | | ); |
| | | }; |
| | | |
| | | /* 通用查询分页 */ |
| | | /** |
| | | * @description: 通用查询分页 |
| | | * @param {T} params |
| | | * @return {*} |
| | | */ |
| | | export async function getListByPage<T>(params: T) { |
| | | const sqlcmd = ReturnSqlcmd(params); |
| | | let order = ''; |
| | | if (!isNullOrEmpty(params['order'])) { |
| | | order = params['order'] == 'descend' ? params['field'] + ' desc' : params['field']; |
| | | } |
| | | const rParams = genAction( |
| | | params['TABLE_NAME'], |
| | | { |
| | | QueryAble_T: '', |
| | | where: sqlcmd, |
| | | order: order, |
| | | page: { |
| | | pageAble_T: 'string', |
| | | draw: 1, |
| | | pageIndex: params['page'], |
| | | pageSize: params['pageSize'], |
| | | }, |
| | | }, |
| | | params['option'], |
| | | ); |
| | | return getListByPageAsync(rParams); |
| | | } |
| | | async function getListByPageAsync(params: any) { |
| | | const data = await defHttp.post( |
| | | { url: Api.QueryUrl, params, timeout: 50000 }, |
| | | { |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | const model = { |
| | | items: data.Data.page.data, |
| | | total: data.Data.page.totals, |
| | | }; |
| | | return model; |
| | | } |
| | | |
| | | /** |
| | | * @description: 根据查询条件参数拼接查询条件 |
| | | * @param {T} params |
| | | * @return {*} |
| | | */ |
| | | export function ReturnSqlcmd<T>(params: T) { |
| | | const Keys = Object.getOwnPropertyNames(params); |
| | | let sqlcmd = ''; |
| | | let sqlcmd = '1=1 '; |
| | | 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' |
| | | Keys[k] != 'TABLE_NAME' && |
| | | Keys[k] != 'order' && |
| | | Keys[k] != 'field' && |
| | | Keys[k] != 'option' && |
| | | Keys[k] != '0' && |
| | | !Keys[k].toString().endsWith('PSelect_0') |
| | | ) { |
| | | sqlcmd += `And ${Keys[k]} like '%${params[Keys[k]]}%'`; |
| | | if (!isNullOrEmpty(params[Keys[k]].length) && isTimeViaRegExp8601(params[Keys[k]][0])) { |
| | | sqlcmd += ` And ${Keys[k]} > '${params[Keys[k]][0]}'`; |
| | | sqlcmd += ` And ${Keys[k]} < '${params[Keys[k]][1]}'`; |
| | | } else if (isNumber(params[Keys[k]])) { |
| | | sqlcmd += `And ${Keys[k]} = ${params[Keys[k]]}`; |
| | | } else { |
| | | 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; |
| | | return sqlcmd; |
| | | } |
| | | |
| | | export async function SaveEntity<T>(params: T, isUpdate: boolean, entityName: string) { |
| | | export async function SaveEntity<T>(params: T, isUpdate: boolean, entityName: string, ...args) { |
| | | let data; |
| | | /* 针对模板地址做替换,特殊处理 */ |
| | | if(params['TEMP_PATH']){ |
| | | params['TEMP_PATH'] = params['TEMP_PATH'].toString().replace('/','//'); |
| | | } |
| | | if (isUpdate) { |
| | | data = await defHttp.post( |
| | | { url: Api.UpdateEntity, params: genAction(entityName, params) }, |
| | |
| | | }, |
| | | ); |
| | | } else { |
| | | params.ID = buildUUID(); //生成GUID |
| | | var check = await isExist(genAction(entityName, args[0])); |
| | | if (check.Data) { |
| | | check.IsSuccessed = false; |
| | | check.Message = '记录已经存在,不能新增!'; |
| | | return check; |
| | | } |
| | | params['ID'] = args[1] == true ? params['ID'] : buildUUID(); //生成GUID |
| | | data = await defHttp.post( |
| | | { url: Api.AddEntity, params: genAction(entityName, params) }, |
| | | { |
| | |
| | | }, |
| | | ); |
| | | } |
| | | return data; |
| | | } |
| | | |
| | | export async function AddListEntity<T>(params: T, entityName: string) { |
| | | let data = await defHttp.post( |
| | | { url: Api.AddListEntity, params: genAction(entityName, params) }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | return data; |
| | | } |
| | | |
| | |
| | | ); |
| | | } |
| | | |
| | | //获取服务器Json文件返回Json数据 |
| | | /** |
| | | * @description: 先删除后添加Api |
| | | * @param {T} params |
| | | * @param {string} entityName |
| | | * @param {*} items |
| | | * @return {*} |
| | | */ |
| | | export async function AddAfterDelete(entityName: string, items: [], where: string) { |
| | | let data = await defHttp.post( |
| | | { |
| | | url: Api.AddAfterDelete, |
| | | params: genAction(entityName, { |
| | | QueryAble_T: '', |
| | | where: where, |
| | | Items: items, |
| | | }), |
| | | }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | return data; |
| | | } |
| | | |
| | | /** |
| | | * @description: 根据条件删除 |
| | | * @param {string} sqlcmd |
| | | * @param {string} entityName |
| | | * @return {*} |
| | | */ |
| | | export const DeleteWhere = async (sqlcmd: string, entityName: string) => { |
| | | const usParams = genAction(entityName, sqlcmd); |
| | | return await defHttp.post( |
| | | { url: Api.DeleteWhere, params: usParams }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | }; |
| | | |
| | | /** |
| | | * @description: 获取服务器Json文件返回Json数据 |
| | | * @param {string} url |
| | | * @return {*} |
| | | */ |
| | | export async function fetchJson(url: string) { |
| | | try { |
| | | const response = await fetch(url); |
| | |
| | | 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; order: string }) => { |
| | | const usParams = genAction(params.entityName, { |
| | | QueryAble_T: '', |
| | | where: params.sqlcmd, |
| | | order: params.order, |
| | | }); |
| | | return await defHttp.post( |
| | | { url: Api.QueryUrl, params: usParams }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | }; |
| | | |
| | | /** |
| | | * @description: 判断保存的值如果是[]数组的,就直接取[0]第一个值,一般针对上传模板的地址 |
| | | * @param {any} values |
| | | * @return {*} |
| | | */ |
| | | export function formatValues(values: any) { |
| | | const Keys = Object.getOwnPropertyNames(values); |
| | | for (const k in Keys) { |
| | | if (isArray(values[Keys[k]])) { |
| | | values[Keys[k]] = values[Keys[k]][0]; |
| | | } |
| | | } |
| | | return values; |
| | | } |
| | | |
| | | /** |
| | | * @description: 获取参数 |
| | | * @param {pParams} params |
| | | * @return {*} |
| | | */ |
| | | export const getSysParam = (params?: pParams) => |
| | | defHttp.get<ApiAction<treeParamsListItem[]>>( |
| | | { url: Api.getSysParam, params }, |
| | | { |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |