import { iRulePayload } from "@/types/rule" import { iCreateSafe } from "@/types/safe" import request from "@/utils/common/request" /** * 获取当前标段的安全巡检列表 * @param bidsectionId 标段id */ export async function apiSafeList(bidsectionId: string) { const { data } = await request.get('/api/safe', { bidsectionId }) return data } /** * 创建新的安全巡检记录 * @param payload 载荷 */ export async function apiCreateSafe(payload: iCreateSafe) { const { data } = await request.post('/api/safe', payload) return data } /** * 获取当前的规则 * @param bidsectionId 标段id */ export async function apiGetRule(bidsectionId: string) { const { data } = await request.get('/api/rule', { bidsectionId }) return data } /** * 提交编号规则设置 * @param payload 载荷 */ export async function apiSaveRule(payload: iRulePayload) { // const egRule: string[] = [] // payload.rule?.forEach(rule => { // if (rule.type === "code") { // egRule.push(new Array(rule.value.length).fill("_").join("")) // } else { // egRule.push(rule.value) // } // }) // console.log(egRule) const newValue = payload.rule.reduce((prev, curr) => { // if (curr.type === 'code') { // prev[curr.type] = curr.value.length // } else { // prev[curr.type] = curr.value // } prev[curr.type] = curr.value return prev }, {}) const { data } = await request.post('/api/rule', { ...payload, rule: JSON.stringify(newValue) }) return data } /** * * @param bidsectionId 标段id * @param type 规则类型 */ export async function apiAutoCode(bidsectionId: string, type: string) { const { data } = await request.post("/api/rule/auto", { bidsectionId, type }) return data }