!997 功能:模板标签

pull/997/MERGE
ZoeLeeFZ 4 years ago committed by ChenX
parent 3b8b6228a5
commit 63599ab293

@ -2,12 +2,14 @@ import { app } from "../../ApplicationServices/Application";
import { Command } from "../../Editor/CommandMachine"; import { Command } from "../../Editor/CommandMachine";
import { TemplateManage } from "../../UI/Components/Template/TemplateComponent"; import { TemplateManage } from "../../UI/Components/Template/TemplateComponent";
import { TempalteEditorStore } from "../../UI/Store/TemplateEditorStore"; import { TempalteEditorStore } from "../../UI/Store/TemplateEditorStore";
import { ITempTagProps } from "./TemplateTagCommand";
export class ShowTemplate implements Command export class ShowTemplate implements Command
{ {
constructor(private tag?: ITempTagProps) { }
async exec() async exec()
{ {
let store = TempalteEditorStore.GetInstance() as TempalteEditorStore; let store = TempalteEditorStore.GetInstance() as TempalteEditorStore;
app.Editor.ModalManage.RenderModeless(TemplateManage, { store }); app.Editor.ModalManage.RenderModeless(TemplateManage, { store, currentTag: this.tag });
} }
} }

@ -0,0 +1,129 @@
import { commandMachine } from "../../Editor/CommandMachine";
import { ShowTemplate } from "./ShowTemplate";
import { AppToaster } from "../../UI/Components/Toaster";
import { Intent } from "@blueprintjs/core";
import { PostJson, RequestStatus } from "../../Common/Request";
import { ConfigUrls } from "../../Common/HostUrl";
import { IndexedDbStore, StoreName } from "../../IndexedDb/IndexedDbStore";
import { GetIndexDBID } from "../../Common/Utils";
import { CommandList } from "../../UI/Components/CommandPanel/CommandList";
import { arrayRemoveIf } from "../../Common/ArrayExt";
export interface ITempTagProps
{
tagName: string;
description: string;
dirId: string;
}
export class TemplateTagCommand
{
//标签-id
private _tagList: ITempTagProps[] = [];
get TagList()
{
return this._tagList;
}
private CheckTagName(tagName: string)
{
let usedCmd = commandMachine.CommandMap.has(tagName) || CommandList.some(cmd => cmd.defaultCustom === tagName || cmd.command === tagName);
if (usedCmd && this._tagList.findIndex(tag => tag.tagName === tagName) < 0)
{
AppToaster.show({
message: "该标签已注册为系统命令",
timeout: 3000,
intent: Intent.DANGER,
});
return false;
}
return true;
}
GetTagById(tid: string)
{
return this._tagList.find(tag => tag.dirId === tid);
}
GetTagByName(tagName: string)
{
return this._tagList.find(d => d.tagName === tagName);
}
AddTag(tagName: string, dirId: string)
{
tagName = tagName.toUpperCase();
if (!this.CheckTagName(tagName)) return;
let tag = this.GetTagByName(tagName);
if (!tag)
tag = this.GetTagById(dirId);
if (!tag)
{
tag = {
tagName,
description: "",
dirId: dirId,
};
this._tagList.push(tag);
}
else
{
commandMachine.RemoveCommand(tag.tagName);
}
tag.tagName = tagName;
tag.dirId = dirId;
commandMachine.RegisterCommand(tagName, new ShowTemplate(tag));
AppToaster.show({
message: `标签:${tagName}添加成功`,
timeout: 3000,
intent: Intent.SUCCESS,
});
}
RemoveTag(tagName: string)
{
arrayRemoveIf(this._tagList, tag => tag.tagName === tagName);
commandMachine.RemoveCommand(tagName);
AppToaster.show({
message: `标签:${tagName}移除成功`,
timeout: 3000,
intent: Intent.SUCCESS,
});
}
async UploadTagList()
{
let data = await PostJson(ConfigUrls.Edit, { key: TemplateTagCommand.name, value: JSON.stringify(this._tagList) });
if (data.err_code === RequestStatus.Ok)
{
const dbStore = await IndexedDbStore.CADStore();
dbStore.Put(StoreName.ConfigData, GetIndexDBID(TemplateTagCommand.name), this._tagList.slice());
dbStore.Put(StoreName.ConfigVersion, GetIndexDBID(TemplateTagCommand.name), data.version);
}
}
ReadTagList(tags: ITempTagProps[])
{
if (!Array.isArray(tags)) return;
for (let tag of tags)
{
this._tagList.push(tag);
commandMachine.RegisterCommand(tag.tagName, new ShowTemplate(tag));
}
}
ModifyTagName(tagName: string, newName: string)
{
if (!this.CheckTagName(newName)) return;
let tag = this.GetTagByName(tagName);
if (tag)
{
commandMachine.RemoveCommand(tagName);
tag.tagName = newName;
commandMachine.RegisterCommand(newName, new ShowTemplate(tag));
}
}
}
export const templateTagCommand = new TemplateTagCommand();

@ -2,6 +2,7 @@ import { Object3D } from "three";
import { Entity } from "../DatabaseServices/Entity/Entity"; import { Entity } from "../DatabaseServices/Entity/Entity";
import { equaln } from "../Geometry/GeUtils"; import { equaln } from "../Geometry/GeUtils";
import { safeEval } from "./eval"; import { safeEval } from "./eval";
import { StoreageKeys } from "./StoreageKeys";
//仅数字构成的3位字符串(不以0开头) //仅数字构成的3位字符串(不以0开头)
export const digitStrReg = /^[^0\D]\d{0,2}$/; export const digitStrReg = /^[^0\D]\d{0,2}$/;
@ -242,3 +243,8 @@ export function getFileSize(size: number)
size /= 1024; size /= 1024;
} }
} }
export function GetIndexDBID(id: string)
{
return localStorage.getItem(StoreageKeys.Uid) + ":" + id;
}

@ -67,6 +67,12 @@ class CommandMachine
this.CommandMap.set(cmdName, cmd); this.CommandMap.set(cmdName, cmd);
this.m_CommandNameList.add(cmdName); this.m_CommandNameList.add(cmdName);
} }
RemoveCommand(cmdName: string)
{
cmdName = cmdName.toUpperCase();
this.CommandMap.delete(cmdName);
this.m_CommandNameList.delete(cmdName);
}
RegisterCustomCommand(oldName: string, newName: string) RegisterCustomCommand(oldName: string, newName: string)
{ {
let oldCmd = this.CommandMap.get(oldName); let oldCmd = this.CommandMap.get(oldName);

@ -232,3 +232,7 @@
width: 300px; width: 300px;
} }
} }
#commonModal .bp3-align-right {
justify-content: flex-end;
}

@ -151,10 +151,7 @@ export class CommonPanel extends React.Component<ICommonPanelProps, ICommonPanel
{ {
const originallySelected = nodeData.isSelected; const originallySelected = nodeData.isSelected;
this.forEachNode(this.state.nodes, n => (n.isSelected = false)); this.forEachNode(this.state.nodes, n => (n.isSelected = false));
if (isSelected) nodeData.isSelected = true;
nodeData.isSelected = isSelected;
else
nodeData.isSelected = originallySelected == null ? true : !originallySelected;
this.setState(this.state); this.setState(this.state);
}; };
//点击目录 //点击目录
@ -909,7 +906,7 @@ export class CommonPanel extends React.Component<ICommonPanelProps, ICommonPanel
</> </>
} }
<input <input
style={{ marginLeft: 5 }} style={{ marginLeft: 5, width: 80 }}
className="bp3-input" className="bp3-input"
placeholder="搜索..." placeholder="搜索..."
type="search" type="search"

@ -66,6 +66,7 @@ export class HandleDirComponent extends React.Component<IHandleDirProps, {}>
{ {
this.inputEl.value = ""; this.inputEl.value = "";
this.container.removeEventListener('keydown', this.onKeydown); this.container.removeEventListener('keydown', this.onKeydown);
this.container.parentElement.focus();
} }
render() render()
{ {

@ -145,9 +145,86 @@
display: flex; display: flex;
} }
} }
.tag-list {
border-right: 1px solid #ccc;
display: flex;
width: 50%;
flex-wrap: wrap;
align-content: start;
.pagination {
margin-top: 20px;
}
&>.tag-img {
width: 25%;
outline: 1px solid #ccc;
height: 0;
text-align: center;
padding-bottom: calc(25% + 20px);
position: relative;
}
&>.tag-img:hover:after {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: #ccc;
opacity: 0.2;
}
}
.tag-name-list {
list-style: none;
width: 100px;
text-align: left;
padding: 0;
max-height: 100%;
overflow: auto;
border-right: 1px solid #ccc;
padding-right: 5px;
width: 20%;
li {
border-bottom: 1px solid #ccc;
padding: 5px;
cursor: pointer;
}
li:hover {
background-color: #ccc;
}
li.active {
background-color: rgba(19, 124, 189);
color: #fff;
}
}
} }
#commonModal .template-detail { #commonModal .template-detail {
&>.add-tag {
display: flex;
align-items: center;
padding-top: 10px;
input {
width: 100px;
}
button {
height: 20px;
min-height: 20px;
line-height: 20px;
padding: 0 5px;
}
}
&>div { &>div {
input { input {
height: 30px; height: 30px;
@ -201,6 +278,14 @@
} }
} }
#commonModal .tag-temp-detail {
flex: 1;
&>ul {
max-height: 100%;
}
}
#commonModal .template-design { #commonModal .template-design {
width: 40vw; width: 40vw;
height: 61vh; height: 61vh;
@ -377,3 +462,24 @@
} }
} }
} }
.tag-names {
padding: 0;
ul {
width: 100px;
text-align: center;
padding: 5px;
max-height: 200px;
overflow: auto;
li {
border-bottom: 1px solid #ccc;
padding: 2px 0;
}
li:hover {
background-color: #ccc;
}
}
}

@ -1,4 +1,4 @@
import { Button, Classes, Intent } from '@blueprintjs/core'; import { Button, Classes, Intent, Card, Popover } from '@blueprintjs/core';
import { observable } from 'mobx'; import { observable } from 'mobx';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import * as React from 'react'; import * as React from 'react';
@ -13,7 +13,7 @@ import { Board } from '../../../DatabaseServices/Entity/Board';
import { Entity } from '../../../DatabaseServices/Entity/Entity'; import { Entity } from '../../../DatabaseServices/Entity/Entity';
import { EditorOnlineTemplate, GetOnlineTemplate, ReplaceTemplate, SetTemplatePositionAndSetParent, UploadTemplate } from '../../../DatabaseServices/Template/TempateUtils'; import { EditorOnlineTemplate, GetOnlineTemplate, ReplaceTemplate, SetTemplatePositionAndSetParent, UploadTemplate } from '../../../DatabaseServices/Template/TempateUtils';
import { TemplateRecord } from '../../../DatabaseServices/Template/TemplateRecord'; import { TemplateRecord } from '../../../DatabaseServices/Template/TemplateRecord';
import { CommandWrap } from '../../../Editor/CommandMachine'; import { CommandWrap, commandMachine } from '../../../Editor/CommandMachine';
import { JigUtils } from '../../../Editor/JigUtils'; import { JigUtils } from '../../../Editor/JigUtils';
import { PromptStatus } from '../../../Editor/PromptResult'; import { PromptStatus } from '../../../Editor/PromptResult';
import { PointSelectSpaceClamp } from '../../../Geometry/SpaceParse/PointSelectSpaceClamp'; import { PointSelectSpaceClamp } from '../../../Geometry/SpaceParse/PointSelectSpaceClamp';
@ -31,9 +31,12 @@ import { TemplateVisualSpace } from '../../../DatabaseServices/Template/ProgramT
import { IDrawerDoorTempInfo, HandleHorPos, HandleVePos } from '../../Store/DoorInterface'; import { IDrawerDoorTempInfo, HandleHorPos, HandleVePos } from '../../Store/DoorInterface';
import { BoardOpenDir, IDrawBoardAutoCutOption } from '../../Store/BoardInterface'; import { BoardOpenDir, IDrawBoardAutoCutOption } from '../../Store/BoardInterface';
import { DoorStore } from '../../Store/DoorDrawerStore/DoorStore'; import { DoorStore } from '../../Store/DoorDrawerStore/DoorStore';
import { AutoCutCheckbox } from '../Board/BoardCommon'; import { TemplateTagCom, ITemplateTagComProps } from './TemplateTagCom';
import { UploadAutoCutConfig, ReadAutoCutConfig } from '../../../Add-on/TemplateSearch';
import { AutoCutting } from '../../../Add-on/BoardCutting/AutoCuttingReactor'; import { AutoCutting } from '../../../Add-on/BoardCutting/AutoCuttingReactor';
import { ReadAutoCutConfig, UploadAutoCutConfig } from '../../../Add-on/TemplateSearch'; import { AutoCutCheckbox } from '../Board/BoardCommon';
import { templateTagCommand, ITempTagProps } from '../../../Add-on/Template/TemplateTagCommand';
import { KeyBoard } from '../../../Common/KeyEnum';
export interface INeedUpdateParams export interface INeedUpdateParams
{ {
@ -44,8 +47,14 @@ export interface INeedUpdateParams
isLock?: boolean; isLock?: boolean;
} }
export interface ITemplateManage
{
store?: TempalteEditorStore;
currentTag?: ITempTagProps;
}
@observer @observer
export class TemplateManage extends React.Component<{ store: TempalteEditorStore; }, {}> { export class TemplateManage extends React.Component<ITemplateManage, {}> {
@observable private option: IGetRoomInfo = { @observable private option: IGetRoomInfo = {
roomName: "", roomName: "",
cabName: "", cabName: "",
@ -67,6 +76,7 @@ export class TemplateManage extends React.Component<{ store: TempalteEditorStore
private renderNav = () => private renderNav = () =>
{ {
return ( return (
<>
<Button <Button
text="创建模板" text="创建模板"
icon="cloud-upload" icon="cloud-upload"
@ -76,6 +86,49 @@ export class TemplateManage extends React.Component<{ store: TempalteEditorStore
}} }}
onClick={this.startCreateTemplate} onClick={this.startCreateTemplate}
/> />
<Popover
position="bottom"
autoFocus
usePortal={false}
onOpening={el =>
{
el.onkeydown = e =>
{
e.stopPropagation();
if (e.keyCode === KeyBoard.Escape)
(el.parentElement.previousElementSibling.children[0] as HTMLButtonElement).click();
};
}}
onClosing={el =>
{
el.onkeydown = null;
}}
content={
<div tabIndex={-1} className="bp3-card tag-names">
<ul className={Classes.LIST_UNSTYLED}>
{
templateTagCommand.TagList.map(tg =>
{
return (
<li data-tag={tg.tagName} onClick={this.selectTemplateTag} >{tg.tagName}</li>
);
})
}
</ul>
</div>
}
target={
<Button
text="选择标签"
icon="tag"
intent={Intent.PRIMARY}
style={{
marginRight: 10,
}}
/>}
/>
</>
); );
}; };
private renderMenuItems = () => private renderMenuItems = () =>
@ -550,27 +603,31 @@ export class TemplateManage extends React.Component<{ store: TempalteEditorStore
{ {
await ReadAutoCutConfig(TemplateManage.name, this.autoCutOption); await ReadAutoCutConfig(TemplateManage.name, this.autoCutOption);
} }
async componentWillUnmount() private selectTemplateTag = (e: React.MouseEvent<HTMLLIElement>) =>
{ {
await UploadAutoCutConfig(TemplateManage.name, this.autoCutOption); let tag = e.currentTarget.getAttribute('data-tag');
} commandMachine.ExecCommand(tag);
public render() };
private renderBody = () =>
{
if (this.props.currentTag)
return this.renderTemplateInfo();
else
return this.renderTemplateList();
};
private renderTemplateInfo = () =>
{ {
return ( return (
<div <TemplateTagCom
className={Classes.DIALOG_CONTAINER} currentTag={this.props.currentTag}
id="commonModal" currentProps={this.currentProps}
> currentTemplateInfo={this.currentTemplateInfo}
<div className={Classes.DIALOG + " template"}>
<ModalHeader
title="模板"
icon="bold"
close={() => app.Editor.ModalManage.Destory()}
/> />
<div );
className={Classes.DIALOG_BODY} };
> private renderTemplateList = () =>
<CommonPanel {
return <CommonPanel
defaultDirId={DirectoryId.TemplateDir} defaultDirId={DirectoryId.TemplateDir}
renderNav={this.renderNav} renderNav={this.renderNav}
renderMenuItems={this.renderMenuItems} renderMenuItems={this.renderMenuItems}
@ -599,7 +656,31 @@ export class TemplateManage extends React.Component<{ store: TempalteEditorStore
title="输入模板名称" title="输入模板名称"
/> />
} }
</CommonPanel> </CommonPanel>;
};
componentWillUnmount()
{
templateTagCommand.UploadTagList();
}
public render()
{
let title = this.props.currentTag ? "模板标签管理" : "模板";
return (
<div
className={Classes.DIALOG_CONTAINER}
id="commonModal"
>
<div className={Classes.DIALOG + " template"}>
<ModalHeader
title={title}
close={() => app.Editor.ModalManage.Destory()}
/>
<div
className={Classes.DIALOG_BODY}
>
{
this.renderBody()
}
</div> </div>
<div className={Classes.DIALOG_FOOTER} > <div className={Classes.DIALOG_FOOTER} >
<GetRoomCabName <GetRoomCabName

@ -9,11 +9,12 @@ import { TemplateParam } from '../../../DatabaseServices/Template/Param/Template
import { AppToaster, ToasterInput } from '../Toaster'; import { AppToaster, ToasterInput } from '../Toaster';
import { INeedUpdateParams } from './TemplateComponent'; import { INeedUpdateParams } from './TemplateComponent';
import { IDrawerDoorTempInfo, ISelectTempInfo, HandleHorPos, HandleVePos } from '../../Store/DoorInterface'; import { IDrawerDoorTempInfo, ISelectTempInfo, HandleHorPos, HandleVePos } from '../../Store/DoorInterface';
import { hot } from 'react-hot-loader/root';
import { CheckObjectType } from '../../../Common/CheckoutVaildValue'; import { CheckObjectType } from '../../../Common/CheckoutVaildValue';
import { DoorStore } from '../../Store/DoorDrawerStore/DoorStore'; import { DoorStore } from '../../Store/DoorDrawerStore/DoorStore';
import { safeEval } from '../../../Common/eval'; import { safeEval } from '../../../Common/eval';
import { SetBoardDataItem } from '../Board/BoardCommon'; import { SetBoardDataItem } from '../Board/BoardCommon';
import { templateTagCommand } from '../../../Add-on/Template/TemplateTagCommand';
import { IDirectoryProps } from '../SourceManage/CommonPanel';
export interface ITemplateDetailProps export interface ITemplateDetailProps
{ {
@ -28,6 +29,8 @@ export interface ITemplateDetailProps
isUpload?: boolean; isUpload?: boolean;
disableKeys?: string[]; disableKeys?: string[];
onBlur?: (name: string, val: string) => void; onBlur?: (name: string, val: string) => void;
isShowTag?: boolean;
currentDir?: IDirectoryProps;
} }
const POSITION_PAR = ["PX", "PY", "PZ"]; const POSITION_PAR = ["PX", "PY", "PZ"];
@ -46,6 +49,9 @@ const IconStyle: React.CSSProperties = {
@observer @observer
export class TemplateDetail extends React.Component<ITemplateDetailProps> { export class TemplateDetail extends React.Component<ITemplateDetailProps> {
static defaultProps = {
isShowTag: true
};
public render() public render()
{ {
let disabledKeys = this.props.disableKeys || []; let disabledKeys = this.props.disableKeys || [];
@ -54,6 +60,19 @@ export class TemplateDetail extends React.Component<ITemplateDetailProps> {
return ( return (
<div className={"template-detail " + this.props.className} style={this.props.style}> <div className={"template-detail " + this.props.className} style={this.props.style}>
{
this.props.isShowTag && !this.props.showSelectTemp && this.props.currentInfo && <Label className={Classes.INLINE + " add-tag"}>
<input
type="text"
className={Classes.INPUT}
value={this.props.currentInfo.tagName}
onChange={e => this.props.currentInfo.tagName = e.target.value}
disabled={!!this.props.currentInfo?.id}
/>
<Button text="附加到标签" intent={Intent.SUCCESS} onClick={this.addTag} />
<Button text="移除标签" intent={Intent.DANGER} onClick={this.removeTag} />
</Label>
}
<ul onKeyDown={e => e.stopPropagation()}> <ul onKeyDown={e => e.stopPropagation()}>
<li> <li>
<span></span> <span></span>
@ -255,6 +274,7 @@ export class TemplateDetail extends React.Component<ITemplateDetailProps> {
}); });
if (data.err_code === RequestStatus.Ok) if (data.err_code === RequestStatus.Ok)
{ {
if (this.props.getData)
await this.props.getData(); await this.props.getData();
AppToaster.show({ AppToaster.show({
message: "模板参数已更新", message: "模板参数已更新",
@ -262,4 +282,23 @@ export class TemplateDetail extends React.Component<ITemplateDetailProps> {
}); });
} }
}; };
private addTag = () =>
{
const tagName = this.props.currentInfo.tagName;
if (!tagName?.trim() || !this.props.currentDir.id)
{
AppToaster.show({
message: "标签为空或者没选择目录",
timeout: 2000,
intent: Intent.DANGER
});
return;
}
templateTagCommand.AddTag(tagName, this.props.currentDir.id);
};
private removeTag = () =>
{
this.props.currentInfo.tagName = "";
templateTagCommand.RemoveTag(this.props.currentInfo.tagName);
};
} }

@ -1,4 +1,4 @@
import { observable, IObservableValue } from 'mobx'; import { observable, IObservableValue, reaction } from 'mobx';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import * as React from 'react'; import * as React from 'react';
import { CURRENT_HOST, PublishTemplateUrl } from '../../../Common/HostUrl'; import { CURRENT_HOST, PublishTemplateUrl } from '../../../Common/HostUrl';
@ -12,6 +12,7 @@ import { IDrawerDoorTempInfo, ISelectTempInfo, DrawerTempParName, DisableChangeP
import { AppToaster } from '../Toaster'; import { AppToaster } from '../Toaster';
import { IDirectoryProps } from '../SourceManage/CommonPanel'; import { IDirectoryProps } from '../SourceManage/CommonPanel';
import { IGetRoomInfo } from './GetRoomCabName'; import { IGetRoomInfo } from './GetRoomCabName';
import { templateTagCommand } from '../../../Add-on/Template/TemplateTagCommand';
export interface ITemplateListProps export interface ITemplateListProps
{ {
@ -47,6 +48,19 @@ export interface ITempItemBack
@observer @observer
export class TemplateList extends React.Component<ITemplateListProps> { export class TemplateList extends React.Component<ITemplateListProps> {
private _params: TemplateParam[] = []; private _params: TemplateParam[] = [];
private watchDir: Function;
UNSAFE_componentWillMount()
{
this.watchDir = reaction(() => this.props.currentDir.id, id =>
{
this.props.currentInfo.tagName = templateTagCommand.GetTagById(id)?.tagName ?? "";
});
}
componentWillUnmount()
{
this.watchDir();
this.watchDir = null;
}
public render() public render()
{ {
return ( return (
@ -128,6 +142,7 @@ export class TemplateList extends React.Component<ITemplateListProps> {
selectInfo={this.props.selectInfo} selectInfo={this.props.selectInfo}
isUpload={!this.props.forbidDelete} isUpload={!this.props.forbidDelete}
disableKeys={!this.props.forbidDelete ? undefined : DisableChangeParName} disableKeys={!this.props.forbidDelete ? undefined : DisableChangeParName}
currentDir={this.props.currentDir}
/> />
</div> </div>
); );

@ -0,0 +1,223 @@
import * as React from 'react';
import { PostJson, RequestStatus } from '../../../Common/Request';
import { TemplateUrls, CURRENT_HOST } from '../../../Common/HostUrl';
import { observable } from 'mobx';
import { IDrawerDoorTempInfo } from '../../Store/DoorInterface';
import { templateTagCommand, ITempTagProps } from '../../../Add-on/Template/TemplateTagCommand';
import { TemplateParamsIn, inflate } from '../../../Common/SerializeMaterial';
import { TemplateDetail } from './TemplateDetail';
import { INeedUpdateParams } from './TemplateComponent';
import { observer } from 'mobx-react';
import { Card, Icon, Intent, ContextMenu, Menu, MenuItem } from '@blueprintjs/core';
import { TemplateParam } from '../../../DatabaseServices/Template/Param/TemplateParam';
import { Pagination } from '../SourceManage/Pagination';
import { MouseKey } from '../../../Common/KeyEnum';
import { HandleDirComponent } from '../SourceManage/HandleDirComponent';
export interface ITemplateTagComProps
{
currentTag: ITempTagProps;
currentTemplateInfo: IDrawerDoorTempInfo;
currentProps: INeedUpdateParams[];
}
@observer
export class TemplateTagCom extends React.Component<ITemplateTagComProps> {
@observable private params: TemplateParam[] = [];
@observable private dataList = [];
@observable private pageData = {
count: 0,
currentPage: 1,
pageCount: 16,
};
@observable private currentTag: ITempTagProps = { tagName: "", dirId: "", description: "" };
private canInput = observable.box(false);
private isDesc = true;
async UNSAFE_componentWillMount()
{
this.currentTag = this.props.currentTag;
await this.readTemplateInfo();
}
componentWillUnmount()
{
templateTagCommand.UploadTagList();
}
public render()
{
return (
<Card tabIndex={-1} className="flex" style={{ height: "100%" }}>
<ul className="tag-name-list">
{
templateTagCommand.TagList.map(tag =>
{
return (
<li className={tag.dirId === this.currentTag?.dirId ? "active" : ""} data-id={tag.tagName} onMouseDown={this.selectTemplateTag} >
<Icon icon="tag" />
{tag.tagName} | {tag.description}</li>
);
})
}
</ul>
<div className="tag-list">
{
this.dataList.map(d =>
{
return (
<div className="tag-img"
onClick={() => this.selectTemp(d)}
>
<div style={{ height: 0, paddingBottom: "100%", textAlign: "center" }}>
<img src={d.logo} style={{ height: "auto", width: "80%" }} alt="" />
</div>
<p>{d.name}</p>
</div>
);
})
}
{
this.pageData.count > this.pageData.pageCount && <Pagination
pageData={this.pageData}
getImgListFun={this.readTemplateInfo}
/>
}
</div>
<TemplateDetail
className="tag-temp-detail"
updateParams={this.props.currentProps}
currentInfo={this.props.currentTemplateInfo}
showSelectTemp={false}
isUpload={true}
disableKeys={undefined}
isShowTag={false}
params={this.params}
/>
{
this.canInput.get() && <HandleDirComponent
defualtValue={this.isDesc ? this.currentTag.description : this.currentTag.tagName}
isReset={false}
isOpen={this.canInput}
title={this.isDesc ? "备注" : "标签名"}
handleFunc={this.addTagDesc}
/>
}
</Card>
);
}
private readTemplateInfo = async (pageData?: { curr_page: number; }) =>
{
if (pageData)
this.pageData.currentPage = pageData.curr_page;
let data = await PostJson(TemplateUrls.list, { dir_id: this.currentTag.dirId, page_count: this.pageData.pageCount, curr_page: this.pageData.currentPage });
if (data.err_code === RequestStatus.Ok)
{
this.pageData.count = Number(data.count);
let tempData = data.modules;
observable(this.dataList).replace(tempData.map(d =>
{
return {
logo: CURRENT_HOST + "/" + d.logo,
mid: d.module_id,
name: d.name,
props: d.props,
};
}));
if (this.dataList.length === 1)
{
this.selectTemp(this.dataList[0]);
}
}
};
private selectTemplateTag = async (e: React.MouseEvent<HTMLLIElement>) =>
{
if (e.button === MouseKey.Right)
{
this.showContextMenu(e);
}
let tagName = e.currentTarget.getAttribute('data-id');
Object.assign(this.currentTag, templateTagCommand.GetTagByName(tagName));
await this.readTemplateInfo();
};
private _propsCache = new Map<string, TemplateParam[]>();
private selectTemp(data: { mid: string, name: string, props: string; })
{
const { mid, name, props } = data;
this.props.currentTemplateInfo.id = mid;
this.props.currentTemplateInfo.name = name;
let pars: TemplateParam[];
if (this._propsCache.has(props))
{
pars = this._propsCache.get(props);
}
else
pars = TemplateParamsIn(JSON.parse(inflate(props)));
observable(this.params).replace(pars);
observable(this.props.currentProps).replace(pars.map(p =>
{
return {
name: p.name,
value: p.value,
description: p.description,
expr: p.expr,
};
}));
}
//展示右键菜单
private showContextMenu = (e: React.MouseEvent<HTMLElement>) =>
{
let tagName = e.currentTarget.getAttribute('data-id');
ContextMenu.show(
<Menu>
<MenuItem
icon="annotation"
text="修改标签"
onClick={() =>
{
this.isDesc = false;
this.canInput.set(true);
}}
/>
<MenuItem
icon="comment"
text="编辑描述"
onClick={() =>
{
this.isDesc = true;
this.canInput.set(true);
}}
/>
<MenuItem
icon="trash"
text="移除标签"
intent={Intent.DANGER}
onClick={() => this.removeTag(tagName)}
/>
</Menu>,
{ left: e.clientX, top: e.clientY },
() => this.setState({ isContextMenuOpen: false }),
);
this.setState({ isContextMenuOpen: true });
e.stopPropagation();
e.preventDefault();
};
private removeTag = (tagName: string) =>
{
if (confirm("确定移除标签?"))
{
this.dataList.length = 0;
templateTagCommand.RemoveTag(tagName);
}
};
private addTagDesc = (val: string) =>
{
if (this.isDesc)
templateTagCommand.GetTagByName(this.currentTag.tagName).description = val;
else
templateTagCommand.ModifyTagName(this.currentTag.tagName, val.toUpperCase());
this.canInput.set(false);
};
}

@ -126,6 +126,7 @@ export interface IDrawerDoorTempInfo
props?: INeedUpdateParams[]; props?: INeedUpdateParams[];
title?: string; title?: string;
isHandle?: boolean; isHandle?: boolean;
tagName?: string;
} }
/**选择的模板信息,temp-抽屉或门板,handletemp-拉手模板,其他是铰链模板 */ /**选择的模板信息,temp-抽屉或门板,handletemp-拉手模板,其他是铰链模板 */

@ -24,14 +24,11 @@ import { CADFiler } from "../../DatabaseServices/CADFiler";
import { AppConfirm } from "../Components/Common/Confirm"; import { AppConfirm } from "../Components/Common/Confirm";
import { FileServer } from "../../DatabaseServices/FileServer"; import { FileServer } from "../../DatabaseServices/FileServer";
import { CommandServer } from "../../DatabaseServices/CommandServer"; import { CommandServer } from "../../DatabaseServices/CommandServer";
import { TemplateTagCommand, templateTagCommand } from "../../Add-on/Template/TemplateTagCommand";
import { GetIndexDBID } from "../../Common/Utils";
type BehindConfigType = { option: BehindBoardOption, processData: BoardProcessOption, grooveData: IGrooveOption; }; type BehindConfigType = { option: BehindBoardOption, processData: BoardProcessOption, grooveData: IGrooveOption; };
function GetIndexDBID(id)
{
return localStorage.getItem(StoreageKeys.Uid) + ":" + id;
}
interface ISaveOption interface ISaveOption
{ {
isInit?: boolean; isInit?: boolean;
@ -372,7 +369,7 @@ export class UserConfigStore extends Singleton
} }
async CacheAllConfigs() async CacheAllConfigs()
{ {
let keys = [...Object.values(BoardModalType), StoreageKeys.ConfigName, CommandServer.name]; let keys = [...Object.values(BoardModalType), StoreageKeys.ConfigName, TemplateTagCommand.name, CommandServer.name];
let query = []; let query = [];
const store = await IndexedDbStore.CADStore(); const store = await IndexedDbStore.CADStore();
@ -428,11 +425,17 @@ export class UserConfigStore extends Singleton
} }
async GetUserConfigNames() async GetUserConfigNames()
{ {
//读取用户配置
let config = await this.GetAllConfigs(StoreageKeys.ConfigName); let config = await this.GetAllConfigs(StoreageKeys.ConfigName);
if (config) if (config)
{ {
Object.assign(userConfig.userConfigName, config); Object.assign(userConfig.userConfigName, config);
} }
//读取模板标签
config = await this.GetAllConfigs(TemplateTagCommand.name);
if (config)
templateTagCommand.ReadTagList(config as any[]);
} }
async UploadUserConfigNames(dbStore: IndexedDbStore) async UploadUserConfigNames(dbStore: IndexedDbStore)
{ {

Loading…
Cancel
Save