qcast-front/src/util/roof-pitch-warning.js
ysCha c2d8aeb572 [2089] useSwal alert html 지원 + 저구배 경고 줄바꿈 수정
- useSwal alert 분기에 html 옵션 지원 추가 (html 있으면 html, 없으면 text)
- roof-pitch-warning: text → html + \n을 <br>로 치환하여 줄바꿈 렌더링
- ja.json: 構造物 → 架台 용어 수정 + \n 추가
- ko.json: 문구 다듬기 + \n 추가
2026-06-04 09:46:47 +09:00

81 lines
2.7 KiB
JavaScript

/**
* [LOW-PITCH-WARN 2026-05-06]
* 저구배 + 특정 기와 제품 조합 사용 시 시공 매뉴얼 안내 alert.
*
* 트리거 (호출 위치):
* 1) PlacementShapeSetting handleSaveBtn — 배치면 초기설정 저장
* 2) useRoofAllocationSetting handleSave — 屋根面の割り当て
* 3) useRoofAllocationSetting handleSaveContext — 屋根材変更 후 割り当て
*
* 조건:
* roofMatlCd ∈ 6종 AND (2 ≤ pitch < 2.5 OR 11.31 ≤ angle < 14.04)
*
* 동작:
* 안내 alert (OK 만). 중단 흐름 없음 — OK 누르면 저장 진행.
* 등록된 지붕재 여러 개일 경우, 해당하는 지붕재마다 순차로 alert.
* 세션 캐시 없음 — 트리거마다 매번 표시.
*/
/** 경고 대상 屋根材 ID 6종 */
export const LOW_PITCH_RESTRICTED_ROOF_IDS = new Set([
'ROOF_ID_WA_53A',
'ROOF_ID_WA_53B',
'ROOF_ID_HIRA_C',
'ROOF_ID_HIRA_D',
'ROOF_ID_HIRA_S',
'ROOF_ID_HIRA_SEME',
])
/** 寸 하한(포함) ~ 寸 상한(제외) */
const PITCH_LOW_INCLUSIVE = 2
const PITCH_HIGH_EXCLUSIVE = 2.5
/** 度 하한(포함) ~ 度 상한(제외) — 2寸≈11.31°, 2.5寸≈14.04° */
const ANGLE_LOW_INCLUSIVE = 11.31
const ANGLE_HIGH_EXCLUSIVE = 14.04
/**
* 단일 지붕재가 경고 대상인지 판정.
* pitch / angle 둘 중 하나라도 범위에 들면 true.
* (roofAngleSet 이 'slope' 면 pitch 만, 'flat' 이면 angle 만 갱신될 수 있어 OR.)
*/
export const isLowPitchRestricted = (roof) => {
if (!roof) return false
if (!LOW_PITCH_RESTRICTED_ROOF_IDS.has(roof.roofMatlCd)) return false
const pitch = Number(roof.pitch)
const angle = Number(roof.angle)
const pitchInRange =
!Number.isNaN(pitch) && pitch >= PITCH_LOW_INCLUSIVE && pitch < PITCH_HIGH_EXCLUSIVE
const angleInRange =
!Number.isNaN(angle) && angle >= ANGLE_LOW_INCLUSIVE && angle < ANGLE_HIGH_EXCLUSIVE
return pitchInRange || angleInRange
}
/**
* 지붕재 배열에 대해 순차로 안내 alert 띄우기.
* OK 만 있는 단순 안내 — 중단 흐름 없음. await 로 모달 닫힘까지 대기.
*
* @param {Array} roofs - 지붕재 배열 (단일이면 [roof])
* @param {Function} swalFire - useSwal().swalFire
* @param {Function} getMessage - useMessage().getMessage
* @returns {Promise<void>}
*/
export const notifyLowPitchRestrictionForRoofs = async (roofs, swalFire, getMessage) => {
if (!Array.isArray(roofs) || roofs.length === 0) return
for (const roof of roofs) {
if (!isLowPitchRestricted(roof)) continue
await new Promise((resolve) => {
swalFire({
type: 'alert',
icon: 'warning',
html: getMessage('modal.roof.material.low.pitch.warning').replace(/\n/g, '<br>'),
confirmFn: () => resolve(),
})
})
}
}