Przeglądaj źródła

fix:统一接口流程

xieyong 6 dni temu
rodzic
commit
0b8a3895b3

+ 8 - 14
src/api/attendance.js

@@ -1,4 +1,4 @@
-import { getServerConfig, getApiBaseUrl, request } from '@/utils/auth'
+import { getServerConfig, request } from '@/utils/auth'
 import { formatNow } from '@/utils/storage'
 
 // ============ 状态枚举(与后端 statusList / attendanceStatusList 一致) ============
@@ -239,12 +239,6 @@ function isServerMode() {
   return getServerConfig().mode === 'server'
 }
 
-function serverPath() {
-  const base = getApiBaseUrl()
-  if (!base) throw new Error('缺少服务器地址,请先在登录页右上角配置')
-  return base
-}
-
 // ============ 对外 API ============
 
 /**
@@ -257,7 +251,7 @@ export async function queryDailyAttendance(userId, date) {
     const vo = ensureDemoDaily(date)
     return { ...vo }
   }
-  const path = `${serverPath()}/hr/attendance/daily/${userId}/${date}`
+  const path = `/hr/attendance/daily/${userId}/${date}`
   const res = await request({ url: path, method: 'GET' })
   return res.data || null
 }
@@ -271,7 +265,7 @@ export async function queryMonthAttendance(month) {
     await new Promise((r) => setTimeout(r, 250))
     return ensureDemoMonth(month).map((x) => ({ ...x }))
   }
-  const path = `${serverPath()}/hr/ess/attendance/month`
+  const path = `/hr/ess/attendance/month`
   const res = await request({ url: path, method: 'GET', data: { month } })
   return Array.isArray(res.data) ? res.data : []
 }
@@ -286,7 +280,7 @@ export async function queryMyDayAttendance(date) {
     const vo = ensureDemoDaily(date)
     return demoDailyToSummary(date, vo)
   }
-  const path = `${serverPath()}/hr/ess/attendance/dates/${date}`
+  const path = `/hr/ess/attendance/dates/${date}`
   const res = await request({ url: path, method: 'GET' })
   return res.data || null
 }
@@ -352,7 +346,7 @@ export async function submitPunch({ method, time, lat, lng, accuracy, address, w
     return ++punchIdCounter
   }
 
-  const path = `${serverPath()}/hr/ess/punches`
+  const path = `/hr/ess/punches`
   const res = await request({ url: path, method: 'POST', data: body })
   return res.data
 }
@@ -515,7 +509,7 @@ export async function submitAttendanceApplication(payload) {
     }
   }
 
-  const path = `${serverPath()}/hr/attendance/applications`
+  const path = `/hr/attendance/applications`
   const res = await request({ url: path, method: 'POST', data: body })
   return res.data || res
 }
@@ -677,7 +671,7 @@ export async function queryAttendanceRule() {
   }
 
   try {
-    const path = `${serverPath()}/hr/ess/attendance/punch-rule`
+    const path = `/hr/ess/attendance/punch-rule`
     const res = await request({ url: path, method: 'GET' })
     const raw = res.data || null
     const rule = normalize(raw)
@@ -706,7 +700,7 @@ export async function queryShiftDetail(shiftId) {
   const cached = shiftCache.get(shiftId)
   if (cached && Date.now() - cached.fetchedAt < SHIFT_TTL) return cached.shift
 
-  const path = `${serverPath()}/hr/attendance/shifts/getShift/${shiftId}`
+  const path = `/hr/attendance/shifts/getShift/${shiftId}`
   const res = await request({ url: path, method: 'GET' })
   const shift = res.data || null
   shiftCache.set(shiftId, { shift, fetchedAt: Date.now() })

+ 8 - 14
src/api/bpm.js

@@ -1,4 +1,4 @@
-import { getApiBaseUrl, getServerConfig, request } from '@/utils/auth'
+import { getServerConfig, request } from '@/utils/auth'
 
 // ============ 模式判断 ============
 function isServerMode() {
@@ -9,12 +9,6 @@ export function isBpmServerMode() {
   return isServerMode()
 }
 
-function serverPath() {
-  const base = getApiBaseUrl()
-  if (!base) throw new Error('缺少服务器地址,请先在登录页右上角配置')
-  return base
-}
-
 // BPM 任务结果枚举(后端 bpm_task.result:1 通过 / 2 不通过 / 3 取消 / 4 退回)
 const TASK_RESULT_LABEL = {
   1: '已同意',
@@ -43,7 +37,7 @@ function compact(object = {}) {
 /** 待办任务分页 POST /bpm/task/todo-page(body 见 BpmTaskTodoPageReqVO) */
 export async function getTodoTaskPage(params = {}) {
   const res = await request({
-    url: `${serverPath()}/bpm/task/todo-page`,
+    url: `/bpm/task/todo-page`,
     method: 'POST',
     data: compact({
       pageNo: params.pageNo || 1,
@@ -59,7 +53,7 @@ export async function getTodoTaskPage(params = {}) {
 /** 已办任务分页 POST /bpm/task/done-page(body 见 BpmTaskDonePageReqVO) */
 export async function getDoneTaskPage(params = {}) {
   const res = await request({
-    url: `${serverPath()}/bpm/task/done-page`,
+    url: `/bpm/task/done-page`,
     method: 'POST',
     data: compact({
       pageNo: params.pageNo || 1,
@@ -77,7 +71,7 @@ export async function getDoneTaskPage(params = {}) {
 /** 抄送我的流程分页 GET /bpm/process-instance/cc/my-page */
 export async function getCcProcessPage(params = {}) {
   const res = await request({
-    url: `${serverPath()}/bpm/process-instance/cc/my-page`,
+    url: `/bpm/process-instance/cc/my-page`,
     method: 'GET',
     data: compact({
       pageNo: params.pageNo || 1,
@@ -93,7 +87,7 @@ export async function getCcProcessPage(params = {}) {
 export async function getProcessInstance(id) {
   if (!id) return null
   const res = await request({
-    url: `${serverPath()}/bpm/process-instance/get?id=${encodeURIComponent(id)}`,
+    url: `/bpm/process-instance/get?id=${encodeURIComponent(id)}`,
     method: 'GET',
   })
   return res.data || null
@@ -103,7 +97,7 @@ export async function getProcessInstance(id) {
 export async function getTaskListByProcessInstanceId(processInstanceId) {
   if (!processInstanceId) return []
   const res = await request({
-    url: `${serverPath()}/bpm/task/list-by-process-instance-id?processInstanceId=${encodeURIComponent(
+    url: `/bpm/task/list-by-process-instance-id?processInstanceId=${encodeURIComponent(
       processInstanceId,
     )}`,
     method: 'GET',
@@ -115,7 +109,7 @@ export async function getTaskListByProcessInstanceId(processInstanceId) {
 export async function approveTask({ id, reason = '' } = {}) {
   if (!id) throw new Error('缺少任务主键')
   const res = await request({
-    url: `${serverPath()}/bpm/task/approve`,
+    url: `/bpm/task/approve`,
     method: 'PUT',
     data: compact({ id, reason }),
   })
@@ -126,7 +120,7 @@ export async function approveTask({ id, reason = '' } = {}) {
 export async function rejectTask({ id, reason } = {}) {
   if (!id) throw new Error('缺少任务主键')
   const res = await request({
-    url: `${serverPath()}/bpm/task/reject`,
+    url: `/bpm/task/reject`,
     method: 'PUT',
     data: compact({ id, reason }),
   })

+ 2 - 9
src/api/file.js

@@ -1,20 +1,13 @@
 import {
-  getApiBaseUrl,
   getServerConfig,
   uploadFile,
 } from "@/utils/auth";
 
-// 模式判断 + 服务器路径:与 src/api/attendance.js 保持同样形态
+// 模式判断:与 src/api/attendance.js 保持同样形态
 function isServerMode() {
   return getServerConfig().mode === "server";
 }
 
-function serverPath() {
-  const base = getApiBaseUrl();
-  if (!base) throw new Error("缺少服务器地址,请先在登录页右上角配置");
-  return base;
-}
-
 // demo 模式合成一个文件主键,避免与真实 id 撞车(带 demo- 前缀)
 let demoFileIdCounter = 0;
 function nextDemoFileId() {
@@ -62,7 +55,7 @@ export async function uploadAttachment(filePath, moduleName = "hr_attendance") {
     };
   }
 
-  const url = `${serverPath()}/main/file/uploadFile?module=${encodeURIComponent(moduleName)}`;
+  const url = `/main/file/uploadFile?module=${encodeURIComponent(moduleName)}`;
   const res = await uploadFile({ url, filePath, name: "multiPartFile" });
   const data = res && res.data;
   if (!data || data.id === undefined || data.id === null) {

+ 6 - 12
src/api/onboarding.js

@@ -1,4 +1,4 @@
-import { getApiBaseUrl, getServerConfig, request } from '@/utils/auth'
+import { getServerConfig, request } from '@/utils/auth'
 import { defaultOnboardingInvitations, onboardStatus } from '@/data/mock'
 
 // ============ 模式判断 ============
@@ -6,12 +6,6 @@ function isServerMode() {
   return getServerConfig().mode === 'server'
 }
 
-function serverPath() {
-  const base = getApiBaseUrl()
-  if (!base) throw new Error('缺少服务器地址,请先在登录页右上角配置')
-  return base
-}
-
 // ============ 枚举 ============
 
 // 用工类型枚举值 → 中文标签(与后端约定一致)
@@ -187,7 +181,7 @@ export async function createOnboardingManual(payload) {
     const id = `ZY${Date.now()}${String(Math.floor(Math.random() * 1000)).padStart(3, '0')}`
     return { onboardingId: id, id, employeeNo: id }
   }
-  const path = `${serverPath()}/hr/ess/admin/onboardings/manual`
+  const path = `/hr/ess/admin/onboardings/manual`
   const res = await request({ url: path, method: 'POST', data: body })
   return res.data || {}
 }
@@ -215,7 +209,7 @@ export async function createOnboardingInvitation(payload, validDays) {
   }
   // validDays 走 query string(与后端约定一致),不放 body
   const qs = validDays != null && validDays !== '' ? `?validDays=${encodeURIComponent(Number(validDays))}` : ''
-  const path = `${serverPath()}/hr/ess/admin/onboardings/invitations${qs}`
+  const path = `/hr/ess/admin/onboardings/invitations${qs}`
   const res = await request({ url: path, method: 'POST', data: body })
   return res.data || {}
 }
@@ -231,7 +225,7 @@ export async function getOnboardingRecords() {
     await new Promise((r) => setTimeout(r, 200))
     return []
   }
-  const path = `${serverPath()}/hr/ess/admin/onboardings/records`
+  const path = `/hr/ess/admin/onboardings/records`
   const res = await request({ url: path, method: 'GET' })
   return Array.isArray(res.data) ? res.data : []
 }
@@ -247,7 +241,7 @@ export async function getOnboardingInvitationsList() {
     await new Promise((r) => setTimeout(r, 150))
     return defaultOnboardingInvitations
   }
-  const path = `${serverPath()}/hr/ess/admin/onboardings/invitations`
+  const path = `/hr/ess/admin/onboardings/invitations`
   const res = await request({ url: path, method: 'GET' })
   return Array.isArray(res.data) ? res.data : []
 }
@@ -265,7 +259,7 @@ export async function submitOnboardingRecord(onboardingId) {
     await new Promise((r) => setTimeout(r, 200))
     return { code: 0, message: '演示:已提交审批' }
   }
-  const path = `${serverPath()}/hr/ess/admin/onboardings/records/${encodeURIComponent(onboardingId)}/submit`
+  const path = `/hr/ess/admin/onboardings/records/${encodeURIComponent(onboardingId)}/submit`
   const res = await request({ url: path, method: 'POST' })
   return res
 }

+ 9 - 15
src/api/onlineDocument.js

@@ -1,4 +1,4 @@
-import { getApiBaseUrl, getServerConfig, request } from '@/utils/auth'
+import { getServerConfig, request } from '@/utils/auth'
 import {
   onlineDocumentTemplateCategories,
   onlineDocumentTemplateVersions,
@@ -19,12 +19,6 @@ function isServerMode() {
   return getServerConfig().mode === 'server'
 }
 
-function serverPath() {
-  const base = getApiBaseUrl()
-  if (!base) throw new Error('缺少服务器地址,请先在登录页右上角配置')
-  return base
-}
-
 function delay(ms = 200) {
   return new Promise((resolve) => setTimeout(resolve, ms))
 }
@@ -119,7 +113,7 @@ export function adaptOnlineTemplateVersion(raw = {}, index = 0) {
 /** 模板分页 GET /hr/online-documents/templates */
 export async function getOnlineTemplatePage(params = {}) {
   const res = await request({
-    url: `${serverPath()}/hr/online-documents/templates`,
+    url: `/hr/online-documents/templates`,
     method: 'GET',
     data: compact({
       pageNum: params.pageNum || 1,
@@ -138,7 +132,7 @@ export async function getOnlineTemplatePage(params = {}) {
 /** 模板详情 GET /hr/online-documents/templates/{id} */
 export async function getOnlineTemplateById(id) {
   const res = await request({
-    url: `${serverPath()}/hr/online-documents/templates/${id}`,
+    url: `/hr/online-documents/templates/${id}`,
     method: 'GET',
   })
   return adaptOnlineTemplate(res.data || {})
@@ -147,7 +141,7 @@ export async function getOnlineTemplateById(id) {
 /** 新增模板 POST /hr/online-documents/templates */
 export async function createOnlineTemplate(payload) {
   const res = await request({
-    url: `${serverPath()}/hr/online-documents/templates`,
+    url: `/hr/online-documents/templates`,
     method: 'POST',
     data: payload,
   })
@@ -157,7 +151,7 @@ export async function createOnlineTemplate(payload) {
 /** 修改模板草稿 PUT /hr/online-documents/templates/{id} */
 export async function updateOnlineTemplate(id, payload) {
   await request({
-    url: `${serverPath()}/hr/online-documents/templates/${id}`,
+    url: `/hr/online-documents/templates/${id}`,
     method: 'PUT',
     data: payload,
   })
@@ -167,7 +161,7 @@ export async function updateOnlineTemplate(id, payload) {
 /** 启用模板 POST /hr/online-documents/templates/{id}/enable */
 export async function enableOnlineTemplate(id) {
   await request({
-    url: `${serverPath()}/hr/online-documents/templates/${id}/enable`,
+    url: `/hr/online-documents/templates/${id}/enable`,
     method: 'POST',
   })
   return id
@@ -176,7 +170,7 @@ export async function enableOnlineTemplate(id) {
 /** 停用模板 POST /hr/online-documents/templates/{id}/disable */
 export async function disableOnlineTemplate(id) {
   await request({
-    url: `${serverPath()}/hr/online-documents/templates/${id}/disable`,
+    url: `/hr/online-documents/templates/${id}/disable`,
     method: 'POST',
   })
   return id
@@ -185,7 +179,7 @@ export async function disableOnlineTemplate(id) {
 /** 版本历史 GET /hr/online-documents/templates/{id}/versions */
 export async function getOnlineTemplateVersions(id) {
   const res = await request({
-    url: `${serverPath()}/hr/online-documents/templates/${id}/versions`,
+    url: `/hr/online-documents/templates/${id}/versions`,
     method: 'GET',
   })
   return asList(res.data).map(adaptOnlineTemplateVersion)
@@ -194,7 +188,7 @@ export async function getOnlineTemplateVersions(id) {
 /** 创建新版本 POST /hr/online-documents/templates/{id}/versions */
 export async function createOnlineTemplateVersion(id, payload = {}) {
   const res = await request({
-    url: `${serverPath()}/hr/online-documents/templates/${id}/versions`,
+    url: `/hr/online-documents/templates/${id}/versions`,
     method: 'POST',
     data: compact({
       documentContent: payload.documentContent,

+ 2 - 8
src/api/organization.js

@@ -1,4 +1,4 @@
-import { getApiBaseUrl, getServerConfig, request } from '@/utils/auth'
+import { getServerConfig, request } from '@/utils/auth'
 import { onboardingDepartments } from '@/data/mock'
 
 // ============ 模式判断 ============
@@ -6,12 +6,6 @@ function isServerMode() {
   return getServerConfig().mode === 'server'
 }
 
-function serverPath() {
-  const base = getApiBaseUrl()
-  if (!base) throw new Error('缺少服务器地址,请先在登录页右上角配置')
-  return base
-}
-
 // ============ Demo 数据 ============
 // demo 模式直接从 onboardingDepartments 全量返回;法人识别 + 部门树
 // 由调用方走 utils/organization-tree 完成,与 PC 端保持一致
@@ -37,7 +31,7 @@ export async function listOrganizations() {
     return demoListOrganizations()
   }
   try {
-    const path = `${serverPath()}/main/group/getGroupList`
+    const path = `/main/group/getGroupList`
     const res = await request({ url: path, method: 'GET' })
     return Array.isArray(res.data) ? res.data : []
   } catch (err) {

+ 3 - 9
src/api/position.js

@@ -1,4 +1,4 @@
-import { getApiBaseUrl, getServerConfig, request } from '@/utils/auth'
+import { getServerConfig, request } from '@/utils/auth'
 import { positionApplications } from '@/data/mock'
 
 // ============ 模式判断 ============
@@ -6,12 +6,6 @@ function isServerMode() {
   return getServerConfig().mode === 'server'
 }
 
-function serverPath() {
-  const base = getApiBaseUrl()
-  if (!base) throw new Error('缺少服务器地址,请先在登录页右上角配置')
-  return base
-}
-
 // ============ 枚举 ============
 
 // 岗位状态:0-停用 / 1-启用 / 2-待撤销(与后端一致)
@@ -377,7 +371,7 @@ export async function pagePosition(query = {}) {
     }
   }
 
-  const path = `${serverPath()}/hr/position/page`
+  const path = `/hr/position/page`
   const res = await request({ url: path, method: 'POST', data: body })
   return res.data || {
     count: 0,
@@ -451,7 +445,7 @@ export async function pagePositionApplication(query = {}) {
   }
 
   const res = await request({
-    url: `${serverPath()}/hr/position/apply/page`,
+    url: `/hr/position/apply/page`,
     method: 'POST',
     data: body,
   })

+ 3 - 9
src/api/positionSequence.js

@@ -1,16 +1,10 @@
-import { getApiBaseUrl, getServerConfig, request } from '@/utils/auth'
+import { getServerConfig, request } from '@/utils/auth'
 
 // ============ 模式判断 ============
 function isServerMode() {
   return getServerConfig().mode === 'server'
 }
 
-function serverPath() {
-  const base = getApiBaseUrl()
-  if (!base) throw new Error('缺少服务器地址,请先在登录页右上角配置')
-  return base
-}
-
 // ============ 枚举 ============
 
 // 岗位序列状态:1-启用 / 0-停用(与后端约定)
@@ -169,7 +163,7 @@ export async function pagePositionSequence(query = {}) {
     }
   }
 
-  const path = `${serverPath()}/hr/positionSequence/page`
+  const path = `/hr/positionSequence/page`
   const res = await request({ url: path, method: 'POST', data: body })
   return res.data || {
     count: 0,
@@ -202,7 +196,7 @@ export async function getPositionSequenceList() {
       }))
   }
 
-  const path = `${serverPath()}/hr/positionSequence/getPositionSequenceList`
+  const path = `/hr/positionSequence/getPositionSequenceList`
   const res = await request({ url: path, method: 'GET' })
   return Array.isArray(res.data) ? res.data : []
 }

+ 11 - 17
src/api/regularization.js

@@ -1,4 +1,4 @@
-import { getApiBaseUrl, getServerConfig, request } from '@/utils/auth'
+import { getServerConfig, request } from '@/utils/auth'
 import {
   probationEmployees,
   regularizationStatus,
@@ -27,12 +27,6 @@ function isServerMode() {
   return getServerConfig().mode === 'server'
 }
 
-function serverPath() {
-  const base = getApiBaseUrl()
-  if (!base) throw new Error('缺少服务器地址,请先在登录页右上角配置')
-  return base
-}
-
 function delay(ms = 200) {
   return new Promise((resolve) => setTimeout(resolve, ms))
 }
@@ -495,7 +489,7 @@ export function adaptEmployeeBrief(raw = {}) {
 /** 试用期员工分页 GET /main/user/getUserPage */
 export async function getProbationUserPage(params = {}) {
   const res = await request({
-    url: `${serverPath()}/main/user/getUserPage`,
+    url: `/main/user/getUserPage`,
     method: 'GET',
     data: compact({
       status: 5,
@@ -538,7 +532,7 @@ async function fetchEmployeeBrief(userId) {
   if (employeeCache.has(key)) return employeeCache.get(key)
   try {
     const res = await request({
-      url: `${serverPath()}/main/user/getById/${key}`,
+      url: `/main/user/getById/${key}`,
       method: 'GET',
     })
     const brief = adaptEmployeeBrief(res.data || {})
@@ -553,7 +547,7 @@ async function fetchEmployeeBrief(userId) {
 /** 新建转正草稿,返回转正单 id POST /main/regularizations */
 export async function createRegularization(payload) {
   const res = await request({
-    url: `${serverPath()}/main/regularizations`,
+    url: `/main/regularizations`,
     method: 'POST',
     data: payload,
   })
@@ -568,7 +562,7 @@ export async function createRegularization(payload) {
 /** 修改转正草稿 PUT /main/regularizations */
 export async function updateRegularization(payload) {
   await request({
-    url: `${serverPath()}/main/regularizations`,
+    url: `/main/regularizations`,
     method: 'PUT',
     data: payload,
   })
@@ -582,7 +576,7 @@ export async function updateRegularization(payload) {
 /** 查询转正单 GET /main/regularizations/{id} */
 export async function getRegularizationById(id, extras = {}) {
   const res = await request({
-    url: `${serverPath()}/main/regularizations/${id}`,
+    url: `/main/regularizations/${id}`,
     method: 'GET',
   })
   const adapted = adaptRegularization(res.data, extras)
@@ -595,7 +589,7 @@ export async function getRegularizationById(id, extras = {}) {
 /** 提交转正审批 POST /main/regularizations/{id}/submit */
 export async function submitRegularization(id) {
   const res = await request({
-    url: `${serverPath()}/main/regularizations/${id}/submit`,
+    url: `/main/regularizations/${id}/submit`,
     method: 'POST',
   })
   return res.data
@@ -604,7 +598,7 @@ export async function submitRegularization(id) {
 /** 撤回转正审批 POST /main/regularizations/{id}/withdraw */
 export async function withdrawRegularization(id, reason = '') {
   const res = await request({
-    url: `${serverPath()}/main/regularizations/${id}/withdraw`,
+    url: `/main/regularizations/${id}/withdraw`,
     method: 'POST',
     data: compact({ reason }),
   })
@@ -614,7 +608,7 @@ export async function withdrawRegularization(id, reason = '') {
 /** 取消转正单 POST /main/regularizations/{id}/cancel */
 export async function cancelRegularization(id, reason = '') {
   const res = await request({
-    url: `${serverPath()}/main/regularizations/${id}/cancel`,
+    url: `/main/regularizations/${id}/cancel`,
     method: 'POST',
     data: compact({ reason }),
   })
@@ -624,7 +618,7 @@ export async function cancelRegularization(id, reason = '') {
 /** 任职周期(计划转正日 / employmentPeriodId)GET /main/users/{userId}/employment-periods */
 export async function getEmploymentPeriods(userId) {
   const res = await request({
-    url: `${serverPath()}/main/users/${userId}/employment-periods`,
+    url: `/main/users/${userId}/employment-periods`,
     method: 'GET',
   })
   return asList(res.data)
@@ -636,7 +630,7 @@ export async function resolveRegularizationIdFromHistory(userId) {
   if (mapped) return mapped
   try {
     const res = await request({
-      url: `${serverPath()}/main/users/${userId}/history`,
+      url: `/main/users/${userId}/history`,
       method: 'GET',
     })
     const list = asList(res.data)

+ 17 - 23
src/api/resign.js

@@ -1,4 +1,4 @@
-import { getApiBaseUrl, getServerConfig, request } from '@/utils/auth'
+import { getServerConfig, request } from '@/utils/auth'
 import { resignings, resignStages } from '@/data/mock'
 import {
   addCreatedResignation,
@@ -23,12 +23,6 @@ function isServerMode() {
   return getServerConfig().mode === 'server'
 }
 
-function serverPath() {
-  const base = getApiBaseUrl()
-  if (!base) throw new Error('缺少服务器地址,请先在登录页右上角配置')
-  return base
-}
-
 // ============ 枚举 ============
 
 // 员工端申请表单(form.vue actionSheet)→ 后端 resignationType 枚举
@@ -512,7 +506,7 @@ async function fetchEmployeeBrief(userId) {
   const key = String(userId)
   if (employeeCache.has(key)) return employeeCache.get(key)
   try {
-    const res = await request({ url: `${serverPath()}/main/user/getById/${key}`, method: 'GET' })
+    const res = await request({ url: `/main/user/getById/${key}`, method: 'GET' })
     const vo = res.data || {}
     const brief = {
       name: vo.name || vo.userName || '',
@@ -544,20 +538,20 @@ function extrasOf(brief) {
 
 /** 查询离职单详情 GET /main/resignations/{id} */
 export async function getResignationById(id) {
-  const res = await request({ url: `${serverPath()}/main/resignations/${id}`, method: 'GET' })
+  const res = await request({ url: `/main/resignations/${id}`, method: 'GET' })
   return res.data
 }
 
 /** 提交离职审批 POST /main/resignations/{id}/submit */
 export async function submitResignation(id) {
-  const res = await request({ url: `${serverPath()}/main/resignations/${id}/submit`, method: 'POST' })
+  const res = await request({ url: `/main/resignations/${id}/submit`, method: 'POST' })
   return res.data
 }
 
 /** 撤回离职审批 POST /main/resignations/{id}/withdraw */
 export async function withdrawResignation(id, reason = '') {
   const res = await request({
-    url: `${serverPath()}/main/resignations/${id}/withdraw`,
+    url: `/main/resignations/${id}/withdraw`,
     method: 'POST',
     data: compact({ reason }),
   })
@@ -567,7 +561,7 @@ export async function withdrawResignation(id, reason = '') {
 /** 取消离职单 POST /main/resignations/cancel/{id}(注意:cancel 在路径中间) */
 export async function cancelResignation(id, reason = '') {
   const res = await request({
-    url: `${serverPath()}/main/resignations/cancel/${id}`,
+    url: `/main/resignations/cancel/${id}`,
     method: 'POST',
     data: compact({ reason }),
   })
@@ -576,14 +570,14 @@ export async function cancelResignation(id, reason = '') {
 
 /** 归档离职单 POST /main/resignations/{id}/archive */
 export async function archiveResignation(id) {
-  const res = await request({ url: `${serverPath()}/main/resignations/${id}/archive`, method: 'POST' })
+  const res = await request({ url: `/main/resignations/${id}/archive`, method: 'POST' })
   return res.data
 }
 
 /** 强制办结离职单 POST /main/resignations/{id}/force-complete(原因必填) */
 export async function forceCompleteResignation(id, reason) {
   const res = await request({
-    url: `${serverPath()}/main/resignations/${id}/force-complete`,
+    url: `/main/resignations/${id}/force-complete`,
     method: 'POST',
     data: { reason },
   })
@@ -593,7 +587,7 @@ export async function forceCompleteResignation(id, reason) {
 /** 生成离职交接单 POST /main/resignations/{id}/generate-handover */
 export async function generateResignationHandover(id) {
   const res = await request({
-    url: `${serverPath()}/main/resignations/${id}/generate-handover`,
+    url: `/main/resignations/${id}/generate-handover`,
     method: 'POST',
   })
   return res.data
@@ -602,7 +596,7 @@ export async function generateResignationHandover(id) {
 /** 完成离职交接事项 PUT /main/resignations/{id}/handover/items/{itemId}/complete */
 export async function completeResignationHandoverItem(resignationId, itemId, remark = '') {
   const res = await request({
-    url: `${serverPath()}/main/resignations/${resignationId}/handover/items/${itemId}/complete`,
+    url: `/main/resignations/${resignationId}/handover/items/${itemId}/complete`,
     method: 'PUT',
     data: compact({ reason: remark }),
   })
@@ -612,7 +606,7 @@ export async function completeResignationHandoverItem(resignationId, itemId, rem
 /** 分页查询离职交接单 POST /main/handovers/page */
 export async function getHandoverPage(params = {}) {
   const res = await request({
-    url: `${serverPath()}/main/handovers/page`,
+    url: `/main/handovers/page`,
     method: 'POST',
     data: compact({
       pageNum: params.pageNum,
@@ -627,20 +621,20 @@ export async function getHandoverPage(params = {}) {
 
 /** 查询离职交接单 GET /main/handovers/{id} */
 export async function getHandoverDetail(id) {
-  const res = await request({ url: `${serverPath()}/main/handovers/${id}`, method: 'GET' })
+  const res = await request({ url: `/main/handovers/${id}`, method: 'GET' })
   return res.data
 }
 
 /** 删除离职交接单 DELETE /main/handovers/{id} */
 export async function deleteHandover(id) {
-  const res = await request({ url: `${serverPath()}/main/handovers/${id}`, method: 'DELETE' })
+  const res = await request({ url: `/main/handovers/${id}`, method: 'DELETE' })
   return res.data
 }
 
 /** 回退离职交接事项 PUT /main/handovers/{id}/items/{itemId}/rollback */
 export async function rollbackHandoverItem(handoverId, itemId, reason = '') {
   const res = await request({
-    url: `${serverPath()}/main/handovers/${handoverId}/items/${itemId}/rollback`,
+    url: `/main/handovers/${handoverId}/items/${itemId}/rollback`,
     method: 'PUT',
     data: compact({ rollbackReason: reason }),
   })
@@ -650,7 +644,7 @@ export async function rollbackHandoverItem(handoverId, itemId, reason = '') {
 /** 套用离职交接模板 POST /main/handovers/{id}/templates/{templateId}/apply */
 export async function applyHandoverTemplate(handoverId, templateId) {
   const res = await request({
-    url: `${serverPath()}/main/handovers/${handoverId}/templates/${templateId}/apply`,
+    url: `/main/handovers/${handoverId}/templates/${templateId}/apply`,
     method: 'POST',
   })
   return res.data
@@ -744,7 +738,7 @@ export async function loadResignationList(params = {}) {
   let rows = []
   try {
     const res = await request({
-      url: `${serverPath()}/main/resignations/page`,
+      url: `/main/resignations/page`,
       method: 'POST',
       data: compact({ pageNum, size, resignationNo: keyword || undefined }),
     })
@@ -971,7 +965,7 @@ export async function submitResignationApplication(payload) {
     return Date.now()
   }
 
-  const path = `${serverPath()}/hr/ess/mobile/applications/resignation`
+  const path = `/hr/ess/mobile/applications/resignation`
   const res = await request({ url: path, method: 'POST', data: payload })
   const id = Number(res.data)
   return Number.isFinite(id) ? id : 0

+ 2 - 10
src/api/user.js

@@ -1,6 +1,5 @@
 import {
   fetchUserDetail,
-  getApiBaseUrl,
   getServerConfig,
   request,
 } from "@/utils/auth";
@@ -9,12 +8,6 @@ function isServerMode() {
   return getServerConfig().mode === "server";
 }
 
-function serverPath() {
-  const base = getApiBaseUrl();
-  if (!base) throw new Error("缺少服务器地址,请先在登录页右上角配置");
-  return base;
-}
-
 /**
  * 修改档案成功后,重新拉一次当前用户的 profile 接口,
  * 把最新数据落进 storage 并返回。
@@ -23,11 +16,10 @@ function serverPath() {
  */
 export async function refetchMyProfile() {
   if (!isServerMode()) return getCurrentUser();
-  const baseUrl = serverPath();
   const login = getLoginUser() || {};
   const userId = login.userId || (getCurrentUser() || {}).id;
   if (!userId && userId !== 0) throw new Error("缺少用户ID,无法刷新档案");
-  const vo = await fetchUserDetail(baseUrl, userId);
+  const vo = await fetchUserDetail(userId);
   if (vo) saveCurrentUser(vo);
   return vo;
 }
@@ -93,7 +85,7 @@ export async function saveEmployee(payload = {}) {
     return { code: 0, data: body, message: "演示模式:本地保存" };
   }
 
-  const path = `${serverPath()}/main/user/saveNew`;
+  const path = `/main/user/saveNew`;
   const res = await request({ url: path, method: "POST", data: body });
   return res;
 }

+ 11 - 17
src/api/userChange.js

@@ -1,4 +1,4 @@
-import { getApiBaseUrl, getServerConfig, request } from '@/utils/auth'
+import { getServerConfig, request } from '@/utils/auth'
 import { userChangeStatus, userChangeStages, userChanges } from '@/data/mock'
 import {
   addCreatedUserChange,
@@ -18,12 +18,6 @@ function isServerMode() {
   return getServerConfig().mode === 'server'
 }
 
-function serverPath() {
-  const base = getApiBaseUrl()
-  if (!base) throw new Error('缺少服务器地址,请先在登录页右上角配置')
-  return base
-}
-
 function delay(ms = 200) {
   return new Promise((resolve) => setTimeout(resolve, ms))
 }
@@ -361,7 +355,7 @@ async function fetchEmployeeBrief(userId) {
   const key = String(userId)
   if (employeeCache.has(key)) return employeeCache.get(key)
   try {
-    const res = await request({ url: `${serverPath()}/main/user/getById/${key}`, method: 'GET' })
+    const res = await request({ url: `/main/user/getById/${key}`, method: 'GET' })
     const vo = res.data || {}
     const brief = {
       name: vo.name || vo.userName || '',
@@ -417,7 +411,7 @@ function transferText(row = {}) {
 /** 条件查询异动单 GET /main/user-changes */
 export async function getUserChangePage(params = {}) {
   const res = await request({
-    url: `${serverPath()}/main/user-changes`,
+    url: `/main/user-changes`,
     method: 'GET',
     data: compact({
       pageNum: params.pageNum,
@@ -434,7 +428,7 @@ export async function getUserChangePage(params = {}) {
 /** 某员工的异动记录 GET /main/user-changes/users/{userId} */
 export async function getUserChangesByUserId(userId) {
   const res = await request({
-    url: `${serverPath()}/main/user-changes/users/${userId}`,
+    url: `/main/user-changes/users/${userId}`,
     method: 'GET',
   })
   return asList(res.data)
@@ -442,14 +436,14 @@ export async function getUserChangesByUserId(userId) {
 
 /** 异动单详情 GET /main/user-changes/{id} */
 export async function getUserChangeById(id) {
-  const res = await request({ url: `${serverPath()}/main/user-changes/${id}`, method: 'GET' })
+  const res = await request({ url: `/main/user-changes/${id}`, method: 'GET' })
   return res.data
 }
 
 /** 新建异动单(草稿)POST /main/user-changes */
 export async function createUserChange(payload) {
   const res = await request({
-    url: `${serverPath()}/main/user-changes`,
+    url: `/main/user-changes`,
     method: 'POST',
     data: payload,
   })
@@ -460,7 +454,7 @@ export async function createUserChange(payload) {
 
 /** 修改异动草稿 PUT /main/user-changes */
 export async function updateUserChange(payload) {
-  await request({ url: `${serverPath()}/main/user-changes`, method: 'PUT', data: payload })
+  await request({ url: `/main/user-changes`, method: 'PUT', data: payload })
   if (payload?.id != null) rememberUserChangeId(payload.id)
   return payload.id
 }
@@ -468,7 +462,7 @@ export async function updateUserChange(payload) {
 /** 异动预校验 POST /main/user-changes/{id}/validate */
 export async function validateUserChange(id) {
   const res = await request({
-    url: `${serverPath()}/main/user-changes/${id}/validate`,
+    url: `/main/user-changes/${id}/validate`,
     method: 'POST',
   })
   return res.data
@@ -477,7 +471,7 @@ export async function validateUserChange(id) {
 /** 提交异动审批 POST /main/user-changes/{id}/submit */
 export async function submitUserChange(id) {
   const res = await request({
-    url: `${serverPath()}/main/user-changes/${id}/submit`,
+    url: `/main/user-changes/${id}/submit`,
     method: 'POST',
   })
   return res.data
@@ -486,7 +480,7 @@ export async function submitUserChange(id) {
 /** 撤回异动审批 POST /main/user-changes/{id}/withdraw */
 export async function withdrawUserChange(id, reason = '') {
   const res = await request({
-    url: `${serverPath()}/main/user-changes/${id}/withdraw`,
+    url: `/main/user-changes/${id}/withdraw`,
     method: 'POST',
     data: compact({ reason }),
   })
@@ -496,7 +490,7 @@ export async function withdrawUserChange(id, reason = '') {
 /** 取消异动单 POST /main/user-changes/{id}/cancel */
 export async function cancelUserChange(id, reason = '') {
   const res = await request({
-    url: `${serverPath()}/main/user-changes/${id}/cancel`,
+    url: `/main/user-changes/${id}/cancel`,
     method: 'POST',
     data: compact({ reason }),
   })

+ 36 - 28
src/utils/auth.js

@@ -63,6 +63,15 @@ export function request({
   timeout = 15000,
 }) {
   return new Promise((resolve, reject) => {
+    if (!url) {
+      reject(new Error("请求路径不能为空"));
+      return;
+    }
+    // 相对路径由 request() 自动拼接 baseUrl;绝对 URL(http(s):// 或 //host)直通
+    const finalUrl =
+      /^https?:\/\//i.test(url) || url.startsWith("//")
+        ? url
+        : `${getApiBaseUrl()}${url}`;
     // 未显式传 token 时自动从登录态读取,登录后所有请求自动带上凭证
     let effectiveToken = token;
     let effectiveSessionId = sessionId;
@@ -81,7 +90,7 @@ export function request({
       : { "content-type": "application/json", platform: "wxapp" };
 
     uni.request({
-      url,
+      url: finalUrl,
       method,
       data,
       header,
@@ -140,6 +149,15 @@ export function uploadFile({
       reject(new Error("缺少文件路径"));
       return;
     }
+    if (!url) {
+      reject(new Error("请求路径不能为空"));
+      return;
+    }
+    // 相对路径由 uploadFile() 自动拼接 baseUrl;绝对 URL(http(s):// 或 //host)直通
+    const finalUrl =
+      /^https?:\/\//i.test(url) || url.startsWith("//")
+        ? url
+        : `${getApiBaseUrl()}${url}`;
     const { token, sessionId } = getAuthCredentials();
     const header = token
       ? {
@@ -150,7 +168,7 @@ export function uploadFile({
       : { platform: "wxapp" };
 
     uni.uploadFile({
-      url,
+      url: finalUrl,
       filePath,
       name,
       formData,
@@ -210,10 +228,8 @@ export async function testServerConnection(config) {
       .replace(/\/$/, ""),
     port: String(config.port || "").trim(),
   };
-  const baseUrl = getApiBaseUrl(normalized);
-  if (!baseUrl) throw new Error("请填写服务器地址");
   await request({
-    url: `${baseUrl}/main/connection/getConnectionTest`,
+    url: `/main/connection/getConnectionTest`,
     timeout: 5000,
   });
   return true;
@@ -231,9 +247,9 @@ function collectAuthorities(tree) {
   return authorities;
 }
 
-async function loadPermissionTree(baseUrl) {
+async function loadPermissionTree() {
   const response = await request({
-    url: `${baseUrl}/system/resources/getResourcesTreePDA`,
+    url: "/system/resources/getResourcesTreePDA",
   });
   const tree = Array.isArray(response.data) ? response.data : [];
   savePermissionData(tree, collectAuthorities(tree));
@@ -241,10 +257,9 @@ async function loadPermissionTree(baseUrl) {
 }
 
 // 拉取当前登录人的扩展资料(部门、岗位、角色等),登录后调用一次写入本地
-export async function fetchCurrentUser(baseUrl) {
-  if (!baseUrl) throw new Error("缺少 baseUrl");
+export async function fetchCurrentUser() {
   const response = await request({
-    url: `${baseUrl}/system/account/getLoginUser`,
+    url: "/system/account/getLoginUser",
   });
   return response.data || null;
 }
@@ -254,11 +269,10 @@ export async function fetchCurrentUser(baseUrl) {
 // profile 响应把用户数据放在 user 子对象里,内部摊平到顶层
 // 岗位名称不在 profile 直接返回,而是 postId(逗号分隔的 id 串),
 // 内部再调 /hr/position/page 用 id 匹配出 positionName 后回填到返回对象的 position 字段
-export async function fetchUserDetail(baseUrl, userId) {
-  if (!baseUrl) throw new Error("缺少 baseUrl");
+export async function fetchUserDetail(userId) {
   if (!userId && userId !== 0) throw new Error("缺少用户ID");
   const response = await request({
-    url: `${baseUrl}/main/users/${userId}/profile`,
+    url: `/main/users/${userId}/profile`,
   });
   const data = response.data || null;
   if (!data) return null;
@@ -268,7 +282,7 @@ export async function fetchUserDetail(baseUrl, userId) {
     ? { ...data, ...data.user }
     : data;
   try {
-    const names = await resolvePostIds(baseUrl, profile.postId);
+    const names = await resolvePostIds(profile.postId);
     if (names) profile.position = names;
   } catch (error) {
     // 岗位解析失败不影响其他字段
@@ -277,7 +291,7 @@ export async function fetchUserDetail(baseUrl, userId) {
 }
 
 // 把 profile.postId("1111,2222")解析成岗位名称字符串,用 / 拼接多个岗位
-async function resolvePostIds(baseUrl, postIdString) {
+async function resolvePostIds(postIdString) {
   if (!postIdString) return "";
   const ids = String(postIdString)
     .split(",")
@@ -285,7 +299,7 @@ async function resolvePostIds(baseUrl, postIdString) {
     .filter(Boolean);
   if (!ids.length) return "";
   const response = await request({
-    url: `${baseUrl}/hr/position/page`,
+    url: "/hr/position/page",
     method: "POST",
     data: { pageNum: 1, size: 1000, status: 1 },
   });
@@ -334,10 +348,8 @@ export async function performLogin({ account, password, rememberPassword }) {
     return data;
   }
 
-  const baseUrl = getApiBaseUrl(config);
-  if (!baseUrl) throw new Error("请先配置服务器地址");
   const response = await request({
-    url: `${baseUrl}/main/user/login`,
+    url: `/main/user/login`,
     method: "POST",
     data: { loginName, loginPwd },
   });
@@ -351,7 +363,7 @@ export async function performLogin({ account, password, rememberPassword }) {
     rememberPassword,
   });
   try {
-    await loadPermissionTree(baseUrl);
+    await loadPermissionTree();
   } catch (error) {
     savePermissionData([], []);
     uni.showToast({ title: error.message || "权限加载失败", icon: "none" });
@@ -359,8 +371,8 @@ export async function performLogin({ account, password, rememberPassword }) {
   try {
     // 部门/岗位在 getLoginUser 里没有,单独调 getById 拿,再合并
     const [basic, detail] = await Promise.allSettled([
-      fetchCurrentUser(baseUrl),
-      fetchUserDetail(baseUrl, data.userId),
+      fetchCurrentUser(),
+      fetchUserDetail(data.userId),
     ]);
     const basicData = basic.status === "fulfilled" ? basic.value : null;
     const detailData = detail.status === "fulfilled" ? detail.value : null;
@@ -383,10 +395,8 @@ export async function performLogin({ account, password, rememberPassword }) {
 
 export async function getCompanyBranding(config = getServerConfig()) {
   if (config.mode !== "server") return null;
-  const baseUrl = getApiBaseUrl(config);
-  if (!baseUrl) return null;
   const response = await request({
-    url: `${baseUrl}/pda/mes/us/indexName`,
+    url: `/pda/mes/us/indexName`,
     timeout: 5000,
   });
   return response.data || null;
@@ -396,11 +406,9 @@ export async function getCompanyBranding(config = getServerConfig()) {
 // 演示模式或未配置服务器时直接返回(不抛错),由调用方继续清理本地
 export async function serverLogout() {
   if (getServerConfig().mode !== "server") return;
-  const baseUrl = getApiBaseUrl();
-  if (!baseUrl) return;
   try {
     await request({
-      url: `${baseUrl}/main/user/logout`,
+      url: `/main/user/logout`,
       method: "POST",
       timeout: 5000,
     });