diff --git a/src/UI/Components/Board/BoardCommon.tsx b/src/UI/Components/Board/BoardCommon.tsx index b29c4d12e..6e027cb56 100644 --- a/src/UI/Components/Board/BoardCommon.tsx +++ b/src/UI/Components/Board/BoardCommon.tsx @@ -5,7 +5,7 @@ import * as React from 'react'; import { app } from '../../../ApplicationServices/Application'; import { EBoardKeyList } from '../../../Common/BoardKeyList'; import { CheckObjectType } from '../../../Common/CheckoutVaildValue'; -import { Intent, Toaster } from '../../../Common/Toaster'; +import { Intent } from '../../../Common/Toaster'; import { FixedNotZero } from '../../../Common/Utils'; import { safeEval } from '../../../Common/eval'; import { Board } from '../../../DatabaseServices/Entity/Board'; @@ -401,34 +401,36 @@ export const ItemName = observer( onChange={e => { opt.name = e.target.value; - + }} + onBlur={() => + { if (opt.openDir == null) return; - if (opt.openDir === BoardOpenDir.None)//为非门板且名称中有开门只进行提示 + //猜测用户输入的门板类型 非门板 左开门板 ... + let guessDir: BoardOpenDir = BoardOpenDir.None; + if (opt.name.includes("门")) { - if (opt.name.includes("开门")) - { - Toaster({ - message: `当前板类型是非门板,但是板名称为${opt.name},请检查是否正确!`, - timeout: 3000, - intent: Intent.WARNING, - }); - return; - } - return;//其余情况不提示 + let dir = openDirOptions.find((dir, i) => i !== 0 && opt.name.includes(dir.label)); + if (dir) + guessDir = dir.value; } - for (let dirOption of openDirOptions) + //如果当前的类型和用户输入的不一致 + if (guessDir !== opt.openDir) { - if (opt.name.includes(dirOption.label) && opt.openDir !== dirOption.value)//如果板名称有板方向的值且方向不等于当前方向 - { - ShowToasterOpenDirAndNameCheck("更改开门方向", () => + if (guessDir === BoardOpenDir.None) + ShowToasterOpenDirAndNameCheck(opt, "类型改为非门板", () => { - opt.openDir = dirOption.value; + opt.openDir = guessDir; + }); + else + ShowToasterOpenDirAndNameCheck(opt, "更改开门方向", () => + { + opt.openDir = guessDir; }); - break; - } } + else + AppToaster.dismiss("openDirCheck"); }} dir="auto" /> @@ -812,49 +814,48 @@ export const BoardOpenDirSelect = observer((data: { opt?: BoardConfigOption, cla options={openDirOptions} onChange={e => { + const openDir = safeEval(e.target.value); data.opt.openDir = openDir; - const currentLabel = openDirOptions[openDir]; - if (data.opt.name.includes(currentLabel.label)) return;//名字和当前的门板类型一样就不校验 - - if (openDir === BoardOpenDir.None && openDirOptions.filter((v) => data.opt.name.includes(v.label)).length && data.opt.name)//板名称有方向值,开门方向修改成非门板时有提示 + //猜测用户输入的门板类型 非门板 左开门板 ... + let guessDir: BoardOpenDir = BoardOpenDir.None; + if (data.opt.name.includes("门")) { - ShowToasterOpenDirAndNameCheck("更改板名", () => - { - data.opt.name = ""; - }); - return; + let dir = openDirOptions.find((dir, i) => i !== 0 && data.opt.name.includes(dir.label)); + if (dir) + guessDir = dir.value; } - for (let dirName of openDirOptions) + if (openDir !== guessDir) { - if (dirName.label === openDirOptions[0].label) continue; - const index = data.opt.name.indexOf(dirName.label); - if (index > -1) + if (openDir === BoardOpenDir.None)//板名称有方向值,开门方向修改成非门板时有提示 { - ShowToasterOpenDirAndNameCheck("更改板名", () => + ShowToasterOpenDirAndNameCheck(data.opt, "更改板名为:", () => { - const nameList = data.opt.name.split(""); - nameList[index] = currentLabel.label; - data.opt.name = nameList.join(""); + data.opt.name = ""; }); - break; } + else + ShowToasterOpenDirAndNameCheck(data.opt, "更改板名为:" + `${currentLabel.label}开门板`, () => + { + data.opt.name = `${currentLabel.label}开门板`; + }); } - + else + AppToaster.dismiss("openDirCheck"); }} /> ); -export function ShowToasterOpenDirAndNameCheck(text: string, callback: () => void) +export function ShowToasterOpenDirAndNameCheck(opt: { name: string; openDir?: BoardOpenDir; }, text: string, callback: () => void) { AppToaster.show({ message: <> - {"板名称的方向与开门方向不同,请检查"} + {`当前开门方向为${openDirOptions.find(v => v.value === opt.openDir).label},板名称为${opt.name},请检查是否正确`}    , - timeout: 3000, + timeout: 8000, intent: Intent.WARNING, }, "openDirCheck"); }