From 1b9c47f6882598999d417e7b9c4f84dff65cc516 Mon Sep 17 00:00:00 2001 From: MrKBear Date: Thu, 17 Mar 2022 16:48:31 +0800 Subject: [PATCH] Add all group all range build in label --- .../Component/ObjectPicker/ObjectPicker.tsx | 58 ++++++++++--------- source/Component/PickerList/PickerList.tsx | 42 +++++++++++--- source/Localization/EN-US.ts | 2 + source/Localization/ZH-CN.ts | 2 + source/Model/Label.ts | 14 +++++ source/Model/Model.ts | 36 +++++++----- source/Panel/GroupDetails/GroupDetails.tsx | 2 +- 7 files changed, 107 insertions(+), 49 deletions(-) diff --git a/source/Component/ObjectPicker/ObjectPicker.tsx b/source/Component/ObjectPicker/ObjectPicker.tsx index 6da97ae..5566212 100644 --- a/source/Component/ObjectPicker/ObjectPicker.tsx +++ b/source/Component/ObjectPicker/ObjectPicker.tsx @@ -13,7 +13,7 @@ import "./ObjectPicker.scss"; type IObjectType = Label | Group | Range | CtrlObject; interface IObjectPickerProps extends ITextFieldProps { - type: Array<"L" | "G" | "R">; + type: string; value?: IObjectType; valueChange?: (value: IObjectType) => any; cleanValue?: () => any; @@ -28,33 +28,38 @@ class ObjectPicker extends Component = []; - if (this.props.status) { + if (!this.props.status) return option; - for (let i = 0; i < this.props.type.length; i++) { + if (this.props.type.includes("L")) { + for (let j = 0; j < this.props.status.model.labelPool.length; j++) { + option.push(this.props.status.model.labelPool[j]); + } - if (this.props.type[i] === "L") { - for (let j = 0; j < this.props.status.model.labelPool.length; j++) { - option.push(this.props.status.model.labelPool[j]); - } - } + if (this.props.type.includes("R")) { + option.push(this.props.status.model.allRangeLabel); + } - if (this.props.type[i] === "R") { - for (let j = 0; j < this.props.status.model.objectPool.length; j++) { - if (this.props.status.model.objectPool[j] instanceof Range) { - option.push(this.props.status.model.objectPool[j]); - } - } - } + if (this.props.type.includes("G")) { + option.push(this.props.status.model.allGroupLabel); + } + } - if (this.props.type[i] === "G") { - for (let j = 0; j < this.props.status.model.objectPool.length; j++) { - if (this.props.status.model.objectPool[j] instanceof Group) { - option.push(this.props.status.model.objectPool[j]); - } - } + if (this.props.type.includes("R")) { + for (let j = 0; j < this.props.status.model.objectPool.length; j++) { + if (this.props.status.model.objectPool[j] instanceof Range) { + option.push(this.props.status.model.objectPool[j]); } } } + + if (this.props.type.includes("G")) { + for (let j = 0; j < this.props.status.model.objectPool.length; j++) { + if (this.props.status.model.objectPool[j] instanceof Group) { + option.push(this.props.status.model.objectPool[j]); + } + } + } + return option; } @@ -100,9 +105,10 @@ class ObjectPicker extends Component { - disPlayInfo.name ? - {disPlayInfo.name} : - + disPlayInfo.needI18n ? + : + {disPlayInfo.name} }
; type IPickerListItem = CtrlObject | Label | Range | Group; -type IDisplayItem = { +interface IDisplayInfo { + color: string; + icon: string; + name: string; + needI18n?: boolean; +}; + +interface IDisplayItem { nameKey: AllI18nKeys; key: string; mark?: boolean; @@ -20,6 +26,7 @@ function getObjectDisplayInfo(item: IPickerListItem): IDisplayInfo { let color: number[] = []; let icon: string = "tag"; let name: string = ""; + let needI18n: boolean = false; if (item instanceof Range) { icon = "CubeShape" @@ -34,15 +41,30 @@ function getObjectDisplayInfo(item: IPickerListItem): IDisplayInfo { name = item.displayName; } if (item instanceof Label) { - icon = "tag"; - color = item.color.concat([]); - name = item.name; + + if (item.isBuildIn) { + needI18n = true; + if (item.id === "AllRange") { + icon = "ProductList"; + name = "Build.In.Label.Name.All.Range"; + } else if (item.id === "AllGroup") { + icon = "SizeLegacy"; + name = "Build.In.Label.Name.All.Group"; + } + } + + else { + icon = "tag"; + color = item.color.concat([]); + name = item.name; + } } return { - color: `rgb(${color[0]},${color[1]},${color[2]})`, + color: needI18n ? "transparent" : `rgb(${color[0]},${color[1]},${color[2]})`, icon: icon, - name: name + name: name, + needI18n: needI18n } } @@ -79,7 +101,11 @@ class PickerList extends Component {
- {displayInfo.name} + { + displayInfo.needI18n ? + : + displayInfo.name + }
; } diff --git a/source/Localization/EN-US.ts b/source/Localization/EN-US.ts index 6f733f4..0a03879 100644 --- a/source/Localization/EN-US.ts +++ b/source/Localization/EN-US.ts @@ -44,6 +44,8 @@ const EN_US = { "Panel.Info.Label.Details.View": "Edit view label attributes", "Panel.Title.Group.Details.View": "Group", "Panel.Info.Group.Details.View": "Edit view group attributes", + "Build.In.Label.Name.All.Group": "All group", + "Build.In.Label.Name.All.Range": "All range", "Common.No.Data": "No Data", "Common.No.Unknown.Error": "Unknown error", "Common.Attr.Title.Basic": "Basic properties", diff --git a/source/Localization/ZH-CN.ts b/source/Localization/ZH-CN.ts index 241761e..d5d3bf0 100644 --- a/source/Localization/ZH-CN.ts +++ b/source/Localization/ZH-CN.ts @@ -44,6 +44,8 @@ const ZH_CN = { "Panel.Info.Label.Details.View": "编辑查看标签属性", "Panel.Title.Group.Details.View": "群", "Panel.Info.Group.Details.View": "编辑查看群属性", + "Build.In.Label.Name.All.Group": "全部群", + "Build.In.Label.Name.All.Range": "全部范围", "Common.No.Data": "暂无数据", "Common.No.Unknown.Error": "未知错误", "Common.Attr.Title.Basic": "基础属性", diff --git a/source/Model/Label.ts b/source/Model/Label.ts index 7e3010c..032873b 100644 --- a/source/Model/Label.ts +++ b/source/Model/Label.ts @@ -5,6 +5,11 @@ import { ObjectID } from "./Renderer"; * 数据标签 */ class Label { + + /** + * 是否为内置标签 + */ + public isBuildIn: boolean = false; /** * 唯一标识符 @@ -54,12 +59,21 @@ class Label { */ public isDeleted(): boolean { if (this.deleteFlag) return true; + if (this.isBuildIn) return false; for (let i = 0; i < this.model.labelPool.length; i++) { if (this.model.labelPool[i].equal(this)) return false; } this.deleteFlag = true; return true; } + + /** + * 设置为内置标签 + */ + public setBuildInLabel(): this { + this.isBuildIn = true; + return this; + } } /** diff --git a/source/Model/Model.ts b/source/Model/Model.ts index 807dd64..cafec89 100644 --- a/source/Model/Model.ts +++ b/source/Model/Model.ts @@ -51,6 +51,16 @@ class Model extends Emitter { */ public labelPool: Label[] = []; + /** + * 内置标签-全部范围标签 + */ + public allRangeLabel = new Label(this, "AllRange").setBuildInLabel(); + + /** + * 内置标签-全部群标签 + */ + public allGroupLabel = new Label(this, "AllGroup").setBuildInLabel(); + /** * 添加标签 */ @@ -94,23 +104,21 @@ class Model extends Emitter { /** * 通过标签获取指定类型的对象 * @param label 标签 - * @param type 筛选类型 */ - public getObjectByLabel( - label: Label, type?: - (new (...p: any) => Range) | - (new (...p: any) => Group) - ): CtrlObject[] { + public getObjectByLabel(label: Label): CtrlObject[] { const res: CtrlObject[] = []; for (let i = 0; i < this.objectPool.length; i++) { - if (this.objectPool[i].hasLabel(label)) { - if (type) { - if (this.objectPool[i] instanceof type) { - res.push(this.objectPool[i]); - } - } else { - res.push(this.objectPool[i]); - } + + if (label.equal(this.allGroupLabel) && this.objectPool[i] instanceof Group) { + res.push(this.objectPool[i]); + } + + else if (label.equal(this.allRangeLabel) && this.objectPool[i] instanceof Range) { + res.push(this.objectPool[i]); + } + + else if (this.objectPool[i].hasLabel(label)) { + res.push(this.objectPool[i]); } } return res; diff --git a/source/Panel/GroupDetails/GroupDetails.tsx b/source/Panel/GroupDetails/GroupDetails.tsx index fdc5fe5..8844fdf 100644 --- a/source/Panel/GroupDetails/GroupDetails.tsx +++ b/source/Panel/GroupDetails/GroupDetails.tsx @@ -172,7 +172,7 @@ class GroupDetails extends Component { return <> { this.props.status?.changeGroupAttrib(group.id, "genRange", value);