- 기계 보기 부품(A00_Common/line_stack_machine_sheet) — 836-1 제어 구역 그대로(기계 표 꼴 훅 sheet · 잠금 lock) + 기본 정보 · 손료 근거 접이 카드 + 비슷한 기계에서 시작 · 값 바꾸면 브라우저 계산기로 즉시 - 서버 POST /api/m02/machine-sheet(M02_MyMachine_Sheet) — 식 고름 + 식 문서 + 처음 줄 값 + 연결 기록 · 쓰기 없음 · 파이썬 bind ↔ TS bindDoc 짝 - 덮음 ↔ 기계 줄(common_util_machine_sheet) — 고침 없음 = 줄 바이트 같음 · 내 기계 바로 · 직접 자리 맞춤 - 내 기계 = M01 에 없는 기계만 — 화면 만들기 · 고치기에서 M01 과 같은 이름 · 규격 409(불러오기 자동 생성은 그대로) · [새 기계] · 고침 열림 - 옛 기계 양식 부품(ui_template_machine_form) 지움 — 쓰는 곳 0(부품 모음 견본 줄도 걷음) - 낡은 시험 test_821_3 test_stack_line_copy — 836-2 자동 따라옴(내 기계 고치면 SK 금액 따라감 · 갱신 할 것 없음)에 맞춤 - 지킴 시험 test_840_2 — M01 기계 655 대 박은 식 셈 = 요소 셈 · 줄 그대로 · 굴착기 덮음 · 내 기계 꼴 · M01 같은 이름 막음 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
2.8 KiB
TypeScript
78 lines
2.8 KiB
TypeScript
/* =============================================================================
|
|
* M01_MasterData_Machine_Api.ts
|
|
* M01 기계 화면 서버 호출(PLAN 821-2) — 양식 목록 · 시간당 경비 · 쓰는 곳 · 비슷한 기계 찾기 · 한 줄.
|
|
* 서버 = `M01_MasterData_Machine.py` · 시스템 관리자만.
|
|
* ========================================================================== */
|
|
|
|
import { API_BASE_URL } from "@config/config_frontend";
|
|
import type { MachinePick } from "../common_util/common_util_machine_sheet";
|
|
import type { Row } from "./M01_MasterData_Api_Fetch";
|
|
|
|
export interface MachineLists {
|
|
fuels: MachinePick[];
|
|
jobs: MachinePick[];
|
|
power: number;
|
|
hour: number;
|
|
books: string[];
|
|
/** 구분 → 원문 */
|
|
groups: Record<string, string>;
|
|
}
|
|
|
|
export interface MachineHourly {
|
|
노무비?: number;
|
|
재료비?: number;
|
|
경비?: number;
|
|
계?: number;
|
|
reason?: string;
|
|
}
|
|
|
|
async function get<T>(path: string, params: Record<string, string> = {}): Promise<T> {
|
|
const query = new URLSearchParams(params);
|
|
const res = await fetch(`${API_BASE_URL}/m01/machine${path}?${query}`, {
|
|
credentials: "include",
|
|
});
|
|
const body = (await res.json()) as T & { detail?: unknown };
|
|
if (!res.ok) throw new Error(String(body.detail ?? `HTTP ${res.status}`));
|
|
return body;
|
|
}
|
|
|
|
let lists: Promise<MachineLists> | null = null;
|
|
/** 한 번 받아 둠(페이지 다시 그리면 다시 받음) */
|
|
export const fetchMachineLists = (fresh = false): Promise<MachineLists> => {
|
|
if (!lists || fresh)
|
|
lists = get<MachineLists>("/lists").catch((e) => ((lists = null), Promise.reject(e)));
|
|
return lists;
|
|
};
|
|
|
|
export const fetchMachineHourly = (keys: string[]): Promise<Record<string, MachineHourly>> =>
|
|
keys.length ? get("/hourly", { keys: keys.join(",") }) : Promise.resolve({});
|
|
|
|
export const fetchMachineUses = async (key: string): Promise<string[]> =>
|
|
(await get<{ uses: string[] }>("/uses", { key })).uses;
|
|
|
|
export const findMachines = async (q: string): Promise<Row[]> =>
|
|
(await get<{ rows: Row[] }>("/find", { q })).rows;
|
|
|
|
/** 쓰는 계산식(822-2) — 방법 = 목록 · 꼴 · 그 기계 식 · 까닭 = 값이 모자란 칸 */
|
|
export interface MachineFormula {
|
|
키?: string;
|
|
이름?: string;
|
|
방법: "목록" | "꼴" | "그 기계 식";
|
|
까닭: string;
|
|
}
|
|
|
|
export async function fetchMachineFormula(row: Row): Promise<MachineFormula> {
|
|
const res = await fetch(`${API_BASE_URL}/m01/machine/formula`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(row),
|
|
});
|
|
const body = (await res.json()) as MachineFormula & { detail?: unknown };
|
|
if (!res.ok) throw new Error(String(body.detail ?? `HTTP ${res.status}`));
|
|
return body;
|
|
}
|
|
|
|
export const fetchMachineRow = (key: string): Promise<{ version: string; row: Row }> =>
|
|
get("/row", { key });
|