Files
yunzerwebsiteallinone/backend/src/api/organization.js
T
2026-11-16 17:22:50 +08:00

195 lines
5.5 KiB
JavaScript

import request from '@/utils/request';
const MODULES = ['erp', 'oa'];
function normalizeModule(module) {
const value = String(module || '').toLowerCase();
return MODULES.includes(value) ? value : 'erp';
}
export function createOrganizationApi(module) {
const base = `/backend/${normalizeModule(module)}`;
return {
module: normalizeModule(module),
getOrganizationList(params) {
return request({ url: `${base}/getOrganization`, method: 'get', params });
},
getOrganizationTree(params) {
return request({ url: `${base}/getOrganizationTree`, method: 'get', params });
},
getOrganizationDetail(id) {
return request({ url: `${base}/getOrganizationDetail/${id}`, method: 'get' });
},
createOrganization(data) {
return request({ url: `${base}/createOrganization`, method: 'post', data });
},
updateOrganization(id, data) {
return request({ url: `${base}/editOrganization/${id}`, method: 'post', data });
},
deleteOrganization(id) {
return request({ url: `${base}/deleteOrganization/${id}`, method: 'delete' });
},
getCompanyList(params) {
return request({ url: `${base}/getCompanys`, method: 'get', params });
},
getDepartmentList(parentId) {
return request({
url: `${base}/getDepartments`,
method: 'get',
params: parentId ? { parent_id: parentId } : {},
});
},
searchOrganizations(keyword) {
return request({ url: `${base}/searchOrganizations`, method: 'get', params: { keyword } });
},
getOrganizationHierarchy(orgId) {
return request({ url: `${base}/getOrganizationHierarchy/${orgId}`, method: 'get' });
},
getOrganizationStats() {
return request({ url: `${base}/getOrganizationStats`, method: 'get' });
},
moveOrganization(orgId, parentId, sort) {
const data = { org_id: orgId, parent_id: parentId || 0 };
if (sort !== undefined && sort !== null) {
data.sort = sort;
}
return request({ url: `${base}/moveOrganization`, method: 'post', data });
},
batchOrganizeOrganizations(ids, action) {
return request({
url: `${base}/batchOrganizeOrganizations`,
method: 'post',
data: { ids, action },
});
},
checkOrgCodeUnique(orgCode, excludeId) {
return request({
url: `${base}/checkOrgCodeUnique`,
method: 'get',
params: { org_code: orgCode, exclude_id: excludeId || '' },
});
},
getEmployeeList(params) {
return request({ url: `${base}/getEmployee`, method: 'get', params });
},
getEmployeeDetail(id) {
return request({ url: `${base}/getEmployeeDetail/${id}`, method: 'get' });
},
createEmployee(data) {
return request({ url: `${base}/createEmployee`, method: 'post', data });
},
updateEmployee(id, data) {
return request({ url: `${base}/editEmployee/${id}`, method: 'post', data });
},
deleteEmployee(id) {
return request({ url: `${base}/deleteEmployee/${id}`, method: 'delete' });
},
getOrganizationEmployees(orgId) {
return request({ url: `${base}/getOrganizationEmployees/${orgId}`, method: 'get' });
},
moveEmployeeToOrg(employeeIds, orgId, position) {
const ids = Array.isArray(employeeIds) ? employeeIds : [employeeIds];
const data = { employee_ids: ids, org_id: orgId };
if (position !== undefined && position !== null) {
data.position = position;
}
return request({ url: `${base}/moveEmployeeToOrg`, method: 'post', data });
},
checkEmployeeAccountUnique(account, excludeId) {
return request({
url: `${base}/checkEmployeeAccountUnique`,
method: 'get',
params: { account, exclude_id: excludeId || '' },
});
},
getPositionList(params) {
return request({ url: `${base}/getPosition`, method: 'get', params });
},
getPositionDetail(id) {
return request({ url: `${base}/getPositionDetail/${id}`, method: 'get' });
},
createPosition(data) {
return request({ url: `${base}/createPosition`, method: 'post', data });
},
updatePosition(id, data) {
return request({ url: `${base}/editPosition/${id}`, method: 'post', data });
},
deletePosition(id) {
return request({ url: `${base}/deletePosition/${id}`, method: 'delete' });
},
checkPositionCodeUnique(positionCode, excludeId) {
return request({
url: `${base}/checkPositionCodeUnique`,
method: 'get',
params: { position_code: positionCode, exclude_id: excludeId || '' },
});
},
getOrgSettings() {
return request({ url: `${base}/getOrgSettings`, method: 'get' });
},
saveOrgSettings(data) {
return request({ url: `${base}/saveOrgSettings`, method: 'post', data });
},
exportOrganization() {
return request({ url: `${base}/exportOrganization`, method: 'get', responseType: 'blob' });
},
downloadImportTemplate() {
return request({
url: `${base}/organizationImportTemplate`,
method: 'get',
responseType: 'blob',
});
},
importOrganization(file) {
const data = new FormData();
data.append('file', file);
return request({
url: `${base}/importOrganization`,
method: 'post',
data,
headers: { 'Content-Type': 'multipart/form-data' },
});
},
};
}
export const erpOrganizationApi = createOrganizationApi('erp');
export const oaOrganizationApi = createOrganizationApi('oa');
export default erpOrganizationApi;