| | |
| | | import { UserConfigFn } from 'vite'; |
| | | import { useGlobSetting } from '/@/hooks/setting'; |
| | | import { buildUUID } from '../../utils/uuid'; |
| | | import { DateFormat } from '../../utils/dataformat'; |
| | |
| | | EntityParams, |
| | | EntityList, |
| | | iSYS_ROLE_PROD, |
| | | pParams, |
| | | ImportEntityValidate, |
| | | ImportInput, |
| | | } from './model/systemModel'; |
| | | import { defHttp } from '/@/utils/http/axios'; |
| | | import { isArray, isDate, isNullOrEmpty, isTimeType } from '/@/utils/is'; |
| | | import { MES_ROUTE_EDGE, MES_ROUTE_NODE } from './model/router'; |
| | | 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', |
| | | ImportExcel = '/Base/ImportExcel', |
| | | BaseValidateTableImport = '/Base/ValidateTableImport', |
| | | setRoleStatus = '/system/setRoleStatus', |
| | | MenuList = '/SYS/getMenuListAll', |
| | | SaveMenu = '/SYS/SaveMenu', |
| | | SaveRole = '/SYS/SaveRole', |
| | | getSysParam = '/SYS/getSysParam', |
| | | AddEntity = '/Base/Add', |
| | | AddListEntity = '/Base/AddList', |
| | | UpdateEntity = '/Base/Update', |
| | |
| | | StartJob = '/Tsk/StartJob', |
| | | StopJob = '/Tsk/PauseJob', |
| | | AddJob = '/Tsk/AddJob', |
| | | AddTskJob = '/Tsk/AddTskJob', |
| | | ImmediateRun = '/Tsk/ImmediateRun', |
| | | RemoveTskJob = '/Tsk/RemoveTskJob', |
| | | UpdateJob = '/Tsk/UpdateJob', |
| | | SaveTskJob = '/Tsk/SaveTskJob', |
| | | urlQueryEnum = '/Base/QueryEnum', |
| | | DeleteWareHouse = '/WMS/DelWareHouseModel', |
| | | AddLocation = '/WMS/AddLoctionModel', |
| | |
| | | /* |
| | | * 生成Action |
| | | */ |
| | | export function genAction<T>(datatype: string, data: T, option?: object) { |
| | | export function genAction<T>(datatype: string, data: T, option?: object, NeedInclude?: boolean) { |
| | | const time = new Date(); |
| | | const params: ApiAction<T> = { |
| | | ID: buildUUID(), |
| | |
| | | StatusCode: 0, |
| | | Data: data, |
| | | LocaleMsg: undefined, |
| | | NeedInclude: isNullOrEmpty(NeedInclude) ? false : NeedInclude, |
| | | }; |
| | | return params; |
| | | } |
| | | |
| | | /** |
| | | * @desc 生成Action |
| | | */ |
| | | export function generateAction<T>( |
| | | datatype: string, |
| | | DataAssembly: string, |
| | | data: T, |
| | | option?: object, |
| | | NeedInclude?: boolean, |
| | | ) { |
| | | const params = genAction(datatype, data, option, NeedInclude); |
| | | params.DataAssembly = DataAssembly; |
| | | return params; |
| | | } |
| | | export function genActionjob<sting>( |
| | |
| | | return result; |
| | | } |
| | | |
| | | export function convertToTree(data: [], parentId: string, id: string, pid?: string) { |
| | | const result: any[] = []; |
| | | let temp: any[] = []; |
| | | /** |
| | | * @description: 树形表结构转树形Json |
| | | * @param {T} data |
| | | * @param {string} parentField 父字段名 |
| | | * @param {string} idField 唯一key字段名 |
| | | * @param {string} pid 父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][parentId] == null ? '' : data[i][parentId]; |
| | | const currPid = data[i][parentField] == null ? '' : data[i][parentField]; |
| | | if (currPid === _pid) { |
| | | const obj = data[i] as {}; |
| | | temp = convertToTree(data, parentId, id, data[i][id]); |
| | | const obj = data[i] as T; |
| | | temp = convertToTree(data, parentField, idField, data[i][idField]); |
| | | if (temp.length > 0) { |
| | | obj['children'] = temp; |
| | | } |
| | |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * @description: 获取父项 |
| | | * @param {any} nodes |
| | | * @param {string} childId |
| | | * @return {*} |
| | | */ |
| | | export function findParent(tree: any[], nodeId: string): any | undefined { |
| | | for (const node of tree) { |
| | | if (node.children) { |
| | | for (const child of node.children) { |
| | | if (child.tid === nodeId) { |
| | | return node; |
| | | } |
| | | // 递归查找子树 |
| | | const potentialParent = findParent(node.children, nodeId); |
| | | if (potentialParent) { |
| | | return potentialParent; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return undefined; // 没有找到对应的父亲节点 |
| | | } |
| | | |
| | | /* |
| | |
| | | * @return {*} |
| | | */ |
| | | export async function getListByPage<T>(params: T) { |
| | | const Keys = Object.getOwnPropertyNames(params); |
| | | let sqlcmd = '1=1 '; |
| | | const sqlcmd = ReturnSqlcmd(params); |
| | | let order = ''; |
| | | 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] != 'order' && |
| | | Keys[k] != 'field' && |
| | | Keys[k] != '0' && |
| | | !Keys[k].toString().endsWith('PSelect_0') |
| | | ) { |
| | | if (!isNullOrEmpty(params[Keys[k]].length) && isDate(params[Keys[k]][0])) { |
| | | sqlcmd += ` And ${Keys[k]} > '${params[Keys[k]][0]}'`; |
| | | sqlcmd += ` And ${Keys[k]} < '${params[Keys[k]][1]}'`; |
| | | } else { |
| | | sqlcmd += `And ${Keys[k]} like '%${params[Keys[k]]}%'`; |
| | | } |
| | | } |
| | | } |
| | | 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'], |
| | | }, |
| | | }); |
| | | return getListByPageAsync(rParams); |
| | | const rParams = genAction( |
| | | params['TABLE_NAME'], |
| | | !isNullOrEmpty(params['apiUrl']) |
| | | ? params |
| | | : { |
| | | QueryAble_T: '', |
| | | where: sqlcmd, |
| | | order: order, |
| | | page: { |
| | | pageAble_T: 'string', |
| | | draw: 1, |
| | | pageIndex: params['page'], |
| | | pageSize: params['pageSize'], |
| | | }, |
| | | }, |
| | | params['option'], |
| | | params['NeedInclude'], |
| | | ); |
| | | return getListByPageAsync(rParams, params['apiUrl']); //如果不想用默认的基础方法获取分页数据,可以换其他的api |
| | | } |
| | | async function getListByPageAsync(params: any) { |
| | | async function getListByPageAsync(params: any, apiUrl: string | null | undefined) { |
| | | const data = await defHttp.post( |
| | | { url: Api.QueryUrl, params }, |
| | | { url: !isNullOrEmpty(apiUrl) ? apiUrl : Api.QueryUrl, params, timeout: 50000 }, |
| | | { |
| | | isTransformResponse: false, |
| | | }, |
| | |
| | | return model; |
| | | } |
| | | |
| | | export async function SaveEntity<T>(params: T, isUpdate: boolean, entityName: string) { |
| | | /** |
| | | * @description: 根据查询条件参数拼接查询条件 |
| | | * @param {T} params |
| | | * @return {*} |
| | | */ |
| | | export function ReturnSqlcmd<T>(params: T) { |
| | | const Keys = Object.getOwnPropertyNames(params); |
| | | 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] != 'order' && |
| | | Keys[k] != 'field' && |
| | | Keys[k] != 'option' && |
| | | Keys[k] != '0' && |
| | | Keys[k] != 'apiUrl' && |
| | | Keys[k] != 'NeedInclude' && |
| | | Keys[k] != 'nolike' && |
| | | !Keys[k].toString().endsWith('PSelect_0') |
| | | ) { |
| | | if (!isNullOrEmpty(params[Keys[k]].length) && isArray(params[Keys[k]])) { |
| | | if (isTimeViaRegExp8601(params[Keys[k]][0])) { |
| | | sqlcmd += ` And ${Keys[k]} > '${params[Keys[k]][0]}'`; |
| | | sqlcmd += ` And ${Keys[k]} < '${params[Keys[k]][1]}'`; |
| | | } else { |
| | | sqlcmd += `And '${params[Keys[k]].join(',')}' like '%'+${Keys[k]}+'%'`; |
| | | } |
| | | } else if (isNumber(params[Keys[k]])) { |
| | | sqlcmd += `And ${Keys[k]} = ${params[Keys[k]]}`; |
| | | } else if(Keys[k].toString().startsWith('IFEMPTY_')){ |
| | | sqlcmd +=params[Keys[k]]=='Y'? `And (${Keys[k].split('IFEMPTY_')[1]} != '' OR ${Keys[k].split('IFEMPTY_')[1]} is not NULL)`: `And (${Keys[k].split('IFEMPTY_')[1]} = '' OR ${Keys[k].split('IFEMPTY_')[1]} is NULL)`; |
| | | } else { |
| | | sqlcmd += |
| | | params['nolike'] == 'Y' |
| | | ? `And ${Keys[k]} = '${params[Keys[k]]}'` |
| | | : `And ${Keys[k]} like '%${params[Keys[k]]}%'`; |
| | | } |
| | | } |
| | | } |
| | | return sqlcmd; |
| | | } |
| | | |
| | | export async function SaveEntity<T>(params: T, isUpdate: boolean, entityName: string, ...args) { |
| | | let data; |
| | | if (isUpdate) { |
| | | data = await defHttp.post( |
| | |
| | | }, |
| | | ); |
| | | } else { |
| | | params.ID = buildUUID(); //生成GUID |
| | | const 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) { |
| | | const data = await defHttp.post( |
| | | { url: Api.AddListEntity, params: genAction(entityName, params) }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | return data; |
| | | } |
| | | |
| | |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * @description: 先删除后添加Api |
| | | * @param {T} params |
| | | * @param {string} entityName |
| | | * @param {*} items |
| | | * @return {*} |
| | | */ |
| | | export async function AddAfterDelete(entityName: string, items: [], where: string) { |
| | | const data = await defHttp.post( |
| | | { |
| | | url: Api.AddAfterDelete, |
| | | params: genAction(entityName, { |
| | | QueryAble_T: '', |
| | | where: where, |
| | | Items: items, |
| | | }), |
| | | }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | return data; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /* 通用获取实体记录 */ |
| | | export const getEntity = async (params: { sqlcmd: string; entityName: string }) => { |
| | | export const getEntity = async (params: { sqlcmd: string; entityName: string; order: string }) => { |
| | | const usParams = genAction(params.entityName, { |
| | | QueryAble_T: '', |
| | | where: params.sqlcmd, |
| | | order: '', |
| | | order: params.order, |
| | | }); |
| | | return await defHttp.post( |
| | | { url: Api.QueryUrl, params: usParams }, |
| | |
| | | export function formatValues(values: any) { |
| | | const Keys = Object.getOwnPropertyNames(values); |
| | | for (const k in Keys) { |
| | | if(isArray(values[Keys[k]])){ |
| | | 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, |
| | | }, |
| | | ); |
| | | |
| | | /** |
| | | * @desc 导入Excel |
| | | */ |
| | | export async function ImportExcel(entityName: string, items: ImportInput) { |
| | | const data = await defHttp.post( |
| | | { |
| | | url: Api.ImportExcel, |
| | | params: genAction(entityName, items), |
| | | }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | return data; |
| | | } |
| | | |
| | | /** |
| | | * @desc 导入Excel |
| | | */ |
| | | export async function ValidateTableImport(entityName: string, items: ImportEntityValidate) { |
| | | const data = await defHttp.post( |
| | | { |
| | | url: Api.BaseValidateTableImport, |
| | | params: genAction(entityName, items), |
| | | }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | return data; |
| | | } |