api.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { iRulePayload } from "@/types/rule"
  2. import { iCreateSafe } from "@/types/safe"
  3. import request from "@/utils/common/request"
  4. /**
  5. * 获取当前标段的安全巡检列表
  6. * @param bidsectionId 标段id
  7. */
  8. export async function apiSafeList(bidsectionId: string) {
  9. const { data } = await request.get('/api/safe', { bidsectionId })
  10. return data
  11. }
  12. /**
  13. * 创建新的安全巡检记录
  14. * @param payload 载荷
  15. */
  16. export async function apiCreateSafe(payload: iCreateSafe) {
  17. const { data } = await request.post('/api/safe', payload)
  18. return data
  19. }
  20. /**
  21. * 获取当前的规则
  22. * @param bidsectionId 标段id
  23. */
  24. export async function apiGetRule(bidsectionId: string) {
  25. const { data } = await request.get('/api/rule', { bidsectionId })
  26. return data
  27. }
  28. /**
  29. * 提交编号规则设置
  30. * @param payload 载荷
  31. */
  32. export async function apiSaveRule(payload: iRulePayload) {
  33. // const egRule: string[] = []
  34. // payload.rule?.forEach(rule => {
  35. // if (rule.type === "code") {
  36. // egRule.push(new Array(rule.value.length).fill("_").join(""))
  37. // } else {
  38. // egRule.push(rule.value)
  39. // }
  40. // })
  41. // console.log(egRule)
  42. const newValue = payload.rule.reduce((prev, curr) => {
  43. // if (curr.type === 'code') {
  44. // prev[curr.type] = curr.value.length
  45. // } else {
  46. // prev[curr.type] = curr.value
  47. // }
  48. prev[curr.type] = curr.value
  49. return prev
  50. }, {})
  51. const { data } = await request.post('/api/rule', { ...payload, rule: JSON.stringify(newValue) })
  52. return data
  53. }
  54. /**
  55. *
  56. * @param bidsectionId 标段id
  57. * @param type 规则类型
  58. */
  59. export async function apiAutoCode(bidsectionId: string, type: string) {
  60. const { data } = await request.post("/api/rule/auto", { bidsectionId, type })
  61. return data
  62. }