oaApproval.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. import request from '@/utils/http'
  2. const BASE = '/web/admin/oa-approval'
  3. // ---------------------------------------------------------------------------
  4. // 收款账户
  5. // ---------------------------------------------------------------------------
  6. export function fetchOaReceiveAccountList(params?: {
  7. keyword?: string
  8. accountType?: string
  9. page?: number
  10. pageSize?: number
  11. }) {
  12. return request.get<{ list: any[]; total: number }>({
  13. url: `${BASE}/receive-accounts`,
  14. params
  15. })
  16. }
  17. export function fetchOaReceiveAccountOptions() {
  18. return request.get<{ list: any[] }>({ url: `${BASE}/receive-accounts/options` })
  19. }
  20. export function fetchOaReceiveAccountDetail(id: string) {
  21. return request.get<any>({ url: `${BASE}/receive-accounts/${id}` })
  22. }
  23. export function fetchCreateOaReceiveAccount(data: Record<string, unknown>) {
  24. return request.post({ url: `${BASE}/receive-accounts`, data, showSuccessMessage: true })
  25. }
  26. export function fetchUpdateOaReceiveAccount(id: string, data: Record<string, unknown>) {
  27. return request.put({ url: `${BASE}/receive-accounts/${id}`, data, showSuccessMessage: true })
  28. }
  29. export function fetchDeleteOaReceiveAccount(id: string) {
  30. return request.del({ url: `${BASE}/receive-accounts/${id}`, showSuccessMessage: true })
  31. }
  32. export function fetchBatchDeleteOaReceiveAccounts(ids: string[]) {
  33. return request.post({
  34. url: `${BASE}/receive-accounts/batch-delete`,
  35. data: { ids },
  36. showSuccessMessage: true
  37. })
  38. }
  39. // ---------------------------------------------------------------------------
  40. // 分组 / 应用 / 草稿 / 发布
  41. // ---------------------------------------------------------------------------
  42. export function fetchOaGroupList() {
  43. return request.get<{ list: any[] }>({ url: `${BASE}/groups` })
  44. }
  45. export function fetchCreateOaGroup(data: {
  46. groupName: string
  47. orderNum?: number
  48. remark?: string
  49. }) {
  50. return request.post({
  51. url: `${BASE}/groups`,
  52. data,
  53. showSuccessMessage: true
  54. })
  55. }
  56. export function fetchUpdateOaGroup(
  57. id: string,
  58. data: Partial<{ groupName: string; orderNum: number; remark: string }>
  59. ) {
  60. return request.put({
  61. url: `${BASE}/groups/${id}`,
  62. data,
  63. showSuccessMessage: true
  64. })
  65. }
  66. export function fetchDeleteOaGroup(id: string) {
  67. return request.del({
  68. url: `${BASE}/groups/${id}`,
  69. showSuccessMessage: true
  70. })
  71. }
  72. export function fetchOaAppList(params?: {
  73. groupId?: string
  74. keyword?: string
  75. status?: string
  76. }) {
  77. return request.get<{ list: any[] }>({
  78. url: `${BASE}/apps`,
  79. params
  80. })
  81. }
  82. export function fetchCreateOaApp(data: Record<string, any>) {
  83. return request.post({
  84. url: `${BASE}/apps`,
  85. data,
  86. showSuccessMessage: true
  87. })
  88. }
  89. export function fetchUpdateOaApp(id: string, data: Record<string, any>) {
  90. return request.put({
  91. url: `${BASE}/apps/${id}`,
  92. data,
  93. showSuccessMessage: true
  94. })
  95. }
  96. export function fetchDeleteOaApp(id: string) {
  97. return request.del({
  98. url: `${BASE}/apps/${id}`,
  99. showSuccessMessage: true
  100. })
  101. }
  102. export function fetchCopyOaApp(id: string) {
  103. return request.post({
  104. url: `${BASE}/apps/${id}/copy`,
  105. showSuccessMessage: true
  106. })
  107. }
  108. export function fetchOaAppDraft(appId: string) {
  109. return request.get<any>({ url: `${BASE}/apps/${appId}/draft` })
  110. }
  111. export function fetchSaveOaAppDraft(
  112. appId: string,
  113. data: {
  114. basic?: Record<string, any>
  115. formSchemaJson?: any
  116. flowTreeJson?: any
  117. advancedSettingsJson?: any
  118. }
  119. ) {
  120. return request.put({
  121. url: `${BASE}/apps/${appId}/draft`,
  122. data,
  123. showSuccessMessage: true
  124. })
  125. }
  126. export function fetchPublishOaApp(appId: string) {
  127. return request.post({
  128. url: `${BASE}/apps/${appId}/publish`,
  129. showSuccessMessage: true
  130. })
  131. }
  132. // ---------------------------------------------------------------------------
  133. // 运行时
  134. // ---------------------------------------------------------------------------
  135. export function fetchOaTemplates() {
  136. return request.get<{ list: any[] }>({ url: `${BASE}/templates` })
  137. }
  138. export function fetchOaTemplateDetail(appId: string) {
  139. return request.get<any>({ url: `${BASE}/templates/${appId}` })
  140. }
  141. /** 发起前审批流预览(条件齐后返回最终路径) */
  142. export function fetchOaFlowPreview(
  143. appId: string,
  144. opts?: { formData?: Record<string, any>; initiatorSelectByNode?: Record<string, string[]> }
  145. ) {
  146. return request.post<{
  147. resolved: boolean
  148. message?: string
  149. steps: OaFlowPreviewStep[]
  150. }>({
  151. url: `${BASE}/templates/${appId}/flow-preview`,
  152. data: {
  153. formData: opts?.formData || {},
  154. initiatorSelectByNode: opts?.initiatorSelectByNode || undefined
  155. },
  156. showSuccessMessage: false
  157. })
  158. }
  159. export type OaFlowPreviewStep = {
  160. id: string
  161. type: 'start' | 'approval' | 'cc' | 'branch' | 'end' | string
  162. name: string
  163. signMode?: string
  164. assigneeType?: string
  165. assigneeTypes?: string[]
  166. meta?: string
  167. people?: Array<{ id: string; nickName: string }>
  168. resolveError?: string
  169. }
  170. export function fetchStartOaInstance(data: {
  171. appId: string
  172. formData?: Record<string, any>
  173. title?: string
  174. initiatorDeptId?: string
  175. initiatorSelectByNode?: Record<string, string[]>
  176. relatedInstanceIds?: string[]
  177. }) {
  178. return request.post({
  179. url: `${BASE}/instances`,
  180. data,
  181. showSuccessMessage: true
  182. })
  183. }
  184. // ---------------------------------------------------------------------------
  185. // 发起审批草稿箱
  186. // ---------------------------------------------------------------------------
  187. export function fetchOaInstanceDraftList(params?: {
  188. keyword?: string
  189. groupId?: string
  190. updateTimeFrom?: string
  191. updateTimeTo?: string
  192. page?: number
  193. pageSize?: number
  194. }) {
  195. return request.get<{ list: any[]; total: number }>({
  196. url: `${BASE}/drafts`,
  197. params
  198. })
  199. }
  200. export function fetchOaInstanceDraftCount() {
  201. return request.get<{ count: number }>({ url: `${BASE}/drafts/count` })
  202. }
  203. export function fetchOaInstanceDraftDetail(id: string) {
  204. return request.get<any>({ url: `${BASE}/drafts/${id}` })
  205. }
  206. export function fetchCreateOaInstanceDraft(data: {
  207. appId: string
  208. formData?: Record<string, any>
  209. title?: string
  210. initiatorDeptId?: string
  211. initiatorSelectByNode?: Record<string, string[]>
  212. }) {
  213. return request.post({
  214. url: `${BASE}/drafts`,
  215. data,
  216. showSuccessMessage: true
  217. })
  218. }
  219. export function fetchUpdateOaInstanceDraft(
  220. id: string,
  221. data: {
  222. formData?: Record<string, any>
  223. title?: string
  224. initiatorDeptId?: string
  225. initiatorSelectByNode?: Record<string, string[]>
  226. }
  227. ) {
  228. return request.put({
  229. url: `${BASE}/drafts/${id}`,
  230. data,
  231. showSuccessMessage: true
  232. })
  233. }
  234. export function fetchDeleteOaInstanceDraft(id: string) {
  235. return request.del({
  236. url: `${BASE}/drafts/${id}`,
  237. showSuccessMessage: true
  238. })
  239. }
  240. export function fetchBatchDeleteOaInstanceDrafts(ids: string[]) {
  241. return request.post({
  242. url: `${BASE}/drafts/batch-delete`,
  243. data: { ids },
  244. showSuccessMessage: true
  245. })
  246. }
  247. export function fetchSubmitOaInstanceDraft(
  248. id: string,
  249. data?: {
  250. formData?: Record<string, any>
  251. title?: string
  252. initiatorDeptId?: string
  253. initiatorSelectByNode?: Record<string, string[]>
  254. }
  255. ) {
  256. return request.post({
  257. url: `${BASE}/drafts/${id}/submit`,
  258. data: data || {},
  259. showSuccessMessage: true
  260. })
  261. }
  262. /** 详情审批进度投影项(后端 build_progress_items) */
  263. export interface OaProgressPerson {
  264. id?: string
  265. nickName?: string
  266. status?: string
  267. timestamp?: string
  268. commentText?: string
  269. taskId?: string
  270. transferToUserId?: string
  271. transferToUserName?: string
  272. }
  273. export interface OaProgressItem {
  274. kind: 'submit' | 'task' | 'pending_node' | 'terminal' | string
  275. roundNo?: number
  276. title?: string
  277. status?: string
  278. assigneeUserId?: string
  279. assigneeUserName?: string
  280. timestamp?: string
  281. commentText?: string
  282. nodeKey?: string
  283. taskType?: string
  284. resolveSource?: string
  285. taskId?: string
  286. people?: OaProgressPerson[]
  287. }
  288. export function fetchOaInstanceDetail(id: string) {
  289. return request.get<{ progress?: OaProgressItem[]; tasks?: any[] } & Record<string, any>>({
  290. url: `${BASE}/instances/${id}`
  291. })
  292. }
  293. export type OaCommentAttachmentRef = {
  294. source?: 'form' | 'upload' | string
  295. fieldKey?: string
  296. fieldLabel?: string
  297. url: string
  298. fileName: string
  299. }
  300. export type OaCommentMention = {
  301. userId: string
  302. userName: string
  303. }
  304. export type OaInstanceComment = {
  305. id: string
  306. instanceId?: string
  307. content: string
  308. attachmentRefs: OaCommentAttachmentRef[]
  309. status: 'normal' | 'revoked' | string
  310. revokedTime?: string
  311. createBy: string
  312. createByName?: string
  313. createTime: string
  314. canRevoke?: boolean
  315. mentions?: OaCommentMention[]
  316. }
  317. export function fetchOaFormAttachments(instanceId: string) {
  318. return request.get<{ items: Array<{ fieldKey: string; fieldLabel: string; files: OaCommentAttachmentRef[] }> }>({
  319. url: `${BASE}/instances/${instanceId}/form-attachments`
  320. })
  321. }
  322. export function fetchOaInstanceComments(instanceId: string) {
  323. return request.get<{ list: OaInstanceComment[] }>({
  324. url: `${BASE}/instances/${instanceId}/comments`
  325. })
  326. }
  327. export function fetchCreateOaComment(
  328. instanceId: string,
  329. data: {
  330. content?: string
  331. attachmentRefs?: OaCommentAttachmentRef[]
  332. mentionUserIds?: string[]
  333. }
  334. ) {
  335. return request.post<OaInstanceComment>({
  336. url: `${BASE}/instances/${instanceId}/comments`,
  337. data
  338. })
  339. }
  340. export function fetchRevokeOaComment(instanceId: string, commentId: string) {
  341. return request.post<OaInstanceComment>({
  342. url: `${BASE}/instances/${instanceId}/comments/${commentId}/revoke`
  343. })
  344. }
  345. export function fetchOaTasks(
  346. kind: 'pending' | 'done' | 'mine' | 'cc' | 'mention',
  347. params?: {
  348. readStatus?: 'unread' | 'read' | 'all'
  349. appName?: string
  350. initiatorName?: string
  351. applyTimeFrom?: string
  352. applyTimeTo?: string
  353. instanceStatus?: string
  354. page?: number
  355. pageSize?: number
  356. }
  357. ) {
  358. const appName = (params?.appName || '').trim()
  359. const initiatorName = (params?.initiatorName || '').trim()
  360. const applyTimeFrom = (params?.applyTimeFrom || '').trim()
  361. const applyTimeTo = (params?.applyTimeTo || '').trim()
  362. const instanceStatus = (params?.instanceStatus || '').trim()
  363. return request.get<{ list: any[]; total: number }>({
  364. url: `${BASE}/tasks/${kind}`,
  365. params: {
  366. page: params?.page ?? 1,
  367. pageSize: params?.pageSize ?? 20,
  368. ...(kind === 'cc' ? { readStatus: params?.readStatus ?? 'unread' } : {}),
  369. ...(appName ? { appName } : {}),
  370. ...(initiatorName ? { initiatorName } : {}),
  371. ...(applyTimeFrom ? { applyTimeFrom } : {}),
  372. ...(applyTimeTo ? { applyTimeTo } : {}),
  373. ...(instanceStatus ? { instanceStatus } : {})
  374. }
  375. })
  376. }
  377. export function fetchOaInstanceHistory(params: {
  378. appId: string
  379. instanceId?: string
  380. instanceStatus?: string
  381. initiatorName?: string
  382. applyTimeFrom?: string
  383. applyTimeTo?: string
  384. finishTimeFrom?: string
  385. finishTimeTo?: string
  386. initiatorDeptId?: string
  387. page?: number
  388. pageSize?: number
  389. }) {
  390. return request.get<{
  391. list: any[]
  392. total: number
  393. canViewAll?: boolean
  394. }>({
  395. url: `${BASE}/instances/history`,
  396. params
  397. })
  398. }
  399. export function fetchOaInstanceHistoryExport(params: {
  400. appId: string
  401. instanceId?: string
  402. instanceIds?: string
  403. instanceStatus?: string
  404. initiatorName?: string
  405. applyTimeFrom?: string
  406. applyTimeTo?: string
  407. finishTimeFrom?: string
  408. finishTimeTo?: string
  409. initiatorDeptId?: string
  410. }) {
  411. return request.get<{
  412. appName?: string
  413. businessColumns?: Array<{
  414. key: string
  415. label: string
  416. kind?: string
  417. subLabel?: string
  418. }>
  419. fixedColumns?: Array<{ key: string; label: string }>
  420. rows?: Array<{
  421. index?: number
  422. id?: string
  423. business?: Record<string, string>
  424. fixed?: Record<string, string>
  425. }>
  426. total?: number
  427. }>({
  428. url: `${BASE}/instances/history/export`,
  429. params
  430. })
  431. }
  432. export function fetchOaPendingTaskCount() {
  433. return request.get<{ count: number }>({ url: `${BASE}/tasks/pending/count` })
  434. }
  435. export function fetchOaCcUnreadCount() {
  436. return request.get<{ count: number }>({ url: `${BASE}/tasks/cc/unread-count` })
  437. }
  438. export function fetchMarkOaCcTaskRead(taskId: string) {
  439. return request.post({
  440. url: `${BASE}/tasks/${taskId}/read`,
  441. showSuccessMessage: false
  442. })
  443. }
  444. export function fetchBatchMarkOaCcTasksRead(ids: string[]) {
  445. return request.post({
  446. url: `${BASE}/tasks/cc/read-batch`,
  447. data: { ids },
  448. showSuccessMessage: true
  449. })
  450. }
  451. export function formatOaCcUnreadBadgeCount(count: number): string {
  452. return count > 99 ? '99+' : String(count)
  453. }
  454. export function fetchApproveOaTask(taskId: string, comment?: string) {
  455. return request.post({
  456. url: `${BASE}/tasks/${taskId}/approve`,
  457. data: { comment },
  458. showSuccessMessage: true
  459. })
  460. }
  461. export function fetchRejectOaTask(taskId: string, comment?: string) {
  462. return request.post({
  463. url: `${BASE}/tasks/${taskId}/reject`,
  464. data: { comment },
  465. showSuccessMessage: true
  466. })
  467. }
  468. export function fetchReturnOaTask(taskId: string, comment: string) {
  469. return request.post({
  470. url: `${BASE}/tasks/${taskId}/return`,
  471. data: { comment },
  472. showSuccessMessage: true
  473. })
  474. }
  475. export function fetchAddSignOaTask(
  476. taskId: string,
  477. data: { userIds: string[]; comment?: string }
  478. ) {
  479. return request.post({
  480. url: `${BASE}/tasks/${taskId}/add-sign`,
  481. data,
  482. showSuccessMessage: true
  483. })
  484. }
  485. export function fetchTransferOaTask(
  486. taskId: string,
  487. data: { targetUserId: string; comment?: string }
  488. ) {
  489. return request.post({
  490. url: `${BASE}/tasks/${taskId}/transfer`,
  491. data,
  492. showSuccessMessage: true
  493. })
  494. }
  495. export function fetchWithdrawOaInstance(instanceId: string) {
  496. return request.post({
  497. url: `${BASE}/instances/${instanceId}/withdraw`,
  498. showSuccessMessage: true
  499. })
  500. }
  501. // ---------------------------------------------------------------------------
  502. // 关联审批单
  503. // ---------------------------------------------------------------------------
  504. export type OaRelatedSummaryField = {
  505. label: string
  506. value: string
  507. fullWidth?: boolean
  508. /** 嵌套关联审批单的 instanceId 列表(可跳转 / 打印递归) */
  509. relatedIds?: string[]
  510. }
  511. export type OaRelatedSummary = {
  512. id: string
  513. unavailable?: boolean
  514. appName: string
  515. applyTime: string
  516. status: string
  517. fields: OaRelatedSummaryField[]
  518. }
  519. export type OaRelatedCandidatePreviewField = {
  520. label: string
  521. value: string
  522. }
  523. export type OaRelatedCandidate = {
  524. id: string
  525. appName: string
  526. title: string
  527. displayTitle: string
  528. initiatorUserName: string
  529. initiatorDeptName: string
  530. applyTime: string
  531. status: string
  532. statusText: string
  533. currentApproverNames: string
  534. previewFields: OaRelatedCandidatePreviewField[]
  535. }
  536. export function fetchOaRelatedCandidates(params?: {
  537. tab?: 'mine' | 'done' | 'cc'
  538. keyword?: string
  539. page?: number
  540. pageSize?: number
  541. }) {
  542. return request.get<{
  543. list: OaRelatedCandidate[]
  544. total: number
  545. page: number
  546. pageSize: number
  547. }>({
  548. url: `${BASE}/related-candidates`,
  549. params
  550. })
  551. }
  552. export function fetchOaRelatedSummaries(ids: string[], mode: 'picker' | 'view' = 'view') {
  553. return request.get<{ list: OaRelatedSummary[] }>({
  554. url: `${BASE}/related-summaries`,
  555. params: { ids: ids.filter(Boolean).join(','), mode }
  556. })
  557. }
  558. export type OaBankReceiptItem = {
  559. id?: string
  560. fileName: string
  561. fileUrl: string
  562. fileType?: string
  563. fileSize?: number | null
  564. createTime?: string
  565. }
  566. export function fetchOaBankReceipts(instanceId: string) {
  567. return request.get<{ items: OaBankReceiptItem[] }>({
  568. url: `${BASE}/instances/${instanceId}/bank-receipts`
  569. })
  570. }
  571. export function fetchReplaceOaBankReceipts(
  572. instanceId: string,
  573. items: Array<{
  574. fileUrl: string
  575. fileName?: string
  576. fileType?: string
  577. fileSize?: number | null
  578. }>
  579. ) {
  580. return request.put<{ items: OaBankReceiptItem[] }>({
  581. url: `${BASE}/instances/${instanceId}/bank-receipts`,
  582. data: { items }
  583. })
  584. }