mirror of https://gitee.com/cf-fz/WebCAD.git
!1097 功能:绘制裤杆
parent
5f4466e3d5
commit
21438b50c7
@ -0,0 +1,93 @@
|
||||
import { Checkbox, Classes, Label, Spinner } from '@blueprintjs/core';
|
||||
import { observer } from 'mobx-react';
|
||||
import * as React from 'react';
|
||||
import { CheckObjectType } from '../../../Common/CheckoutVaildValue';
|
||||
import { KuGanStore } from '../../Store/KuGanStore';
|
||||
import { ToasterInput } from '../Toaster';
|
||||
import { observable } from 'mobx';
|
||||
|
||||
interface IKuGanDetailProps
|
||||
{
|
||||
store: KuGanStore;
|
||||
}
|
||||
|
||||
@observer
|
||||
export class KuGanDetail extends React.Component<IKuGanDetailProps> {
|
||||
@observable private isLoading = true;
|
||||
async componentDidMount()
|
||||
{
|
||||
await this.props.store.Load();
|
||||
this.isLoading = false;
|
||||
this.props.store.Watch();
|
||||
}
|
||||
componentWillUnmount()
|
||||
{
|
||||
this.props.store.StopWatch();
|
||||
}
|
||||
public render()
|
||||
{
|
||||
const store = this.props.store;
|
||||
const option = store.option;
|
||||
if (this.isLoading)
|
||||
return <Spinner />;
|
||||
return (
|
||||
<div className="kugan">
|
||||
<div className="flex">
|
||||
<Label className={Classes.INLINE}>
|
||||
<span>插入个数:</span>
|
||||
<ToasterInput
|
||||
optKey="count"
|
||||
option={option}
|
||||
uiOption={store.UIOption}
|
||||
type={CheckObjectType.BR}
|
||||
/>
|
||||
</Label>
|
||||
<Checkbox
|
||||
checked={option.isHor}
|
||||
inline
|
||||
label="横插"
|
||||
onChange={() => option.isHor = !option.isHor}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex">
|
||||
<Label className={Classes.INLINE}>
|
||||
<span>插入深度:</span>
|
||||
<ToasterInput
|
||||
isDisabled={option.isDefault}
|
||||
optKey="depth"
|
||||
option={option}
|
||||
uiOption={store.UIOption}
|
||||
type={CheckObjectType.BR}
|
||||
/>
|
||||
</Label>
|
||||
<Checkbox
|
||||
checked={option.isDefault}
|
||||
inline
|
||||
label="默认(板厚一半)"
|
||||
onChange={() => option.isDefault = !option.isDefault}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex">
|
||||
<Label className={Classes.INLINE}>
|
||||
<span>{option.isHor ? "前距:" : "左距:"}</span>
|
||||
<ToasterInput
|
||||
optKey="leftDist"
|
||||
option={option}
|
||||
uiOption={store.UIOption}
|
||||
type={CheckObjectType.OnlyNumber}
|
||||
/>
|
||||
</Label>
|
||||
<Label className={Classes.INLINE}>
|
||||
<span>{option.isHor ? "后距:" : "右距:"}</span>
|
||||
<ToasterInput
|
||||
optKey="rightDist"
|
||||
option={option}
|
||||
uiOption={store.UIOption}
|
||||
type={CheckObjectType.OnlyNumber}
|
||||
/>
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
|
||||
export interface IKuGangDrawOption
|
||||
{
|
||||
count: number;
|
||||
isHor: boolean;
|
||||
depth: number;
|
||||
isDefault: boolean;
|
||||
leftDist: number;
|
||||
rightDist: number;
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
import { IKuGangDrawOption } from "../Components/Template/TemplateInterface";
|
||||
import { DefaultKuGanOption } from "../../Editor/DefaultConfig";
|
||||
import { IUiOption } from "./BoardInterface";
|
||||
import { DataAdapter } from "../../Common/DataAdapter";
|
||||
import { observable, toJS, autorun, reaction, action } from "mobx";
|
||||
import { safeEval } from "../../Common/eval";
|
||||
import { PostJson, RequestStatus } from "../../Common/Request";
|
||||
import { ConfigUrls } from "../../Common/HostUrl";
|
||||
import { appCache } from "../../Common/AppCache";
|
||||
|
||||
export class KuGanStore
|
||||
{
|
||||
@observable option: IKuGangDrawOption = { ...DefaultKuGanOption };
|
||||
@observable uiOption: IUiOption<IKuGangDrawOption>;
|
||||
private watch: Function;
|
||||
private needUpdate = false;
|
||||
get UIOption()
|
||||
{
|
||||
if (!this.uiOption)
|
||||
this.uiOption = DataAdapter.ConvertUIData(this.option);
|
||||
return this.uiOption;
|
||||
}
|
||||
Watch()
|
||||
{
|
||||
this.watch = reaction(() => Object.keys(this.option).map(k => this.option[k]), () =>
|
||||
{
|
||||
this.needUpdate = true;
|
||||
});
|
||||
}
|
||||
StopWatch()
|
||||
{
|
||||
this.watch();
|
||||
this.watch = undefined;
|
||||
}
|
||||
HasInvailValue()
|
||||
{
|
||||
let uiOption = this.UIOption;
|
||||
let count = safeEval(uiOption.count);
|
||||
if (!count || count < 0) return true;
|
||||
|
||||
for (let k in uiOption)
|
||||
{
|
||||
if (k !== "count" && typeof uiOption[k] === 'string')
|
||||
{
|
||||
let v = safeEval(uiOption[k]);
|
||||
if (isNaN(v))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
async Upload()
|
||||
{
|
||||
if (!this.needUpdate) return;
|
||||
|
||||
if (this.HasInvailValue()) return;
|
||||
|
||||
let data = await PostJson(ConfigUrls.Edit, { key: KuGanStore.name, value: JSON.stringify(toJS(this.option)) });
|
||||
|
||||
if (data.err_code === RequestStatus.Ok)
|
||||
{
|
||||
appCache.set(KuGanStore.name, toJS(this.option));
|
||||
}
|
||||
this.needUpdate = false;
|
||||
}
|
||||
@action
|
||||
async Load()
|
||||
{
|
||||
if (appCache.has(KuGanStore.name))
|
||||
{
|
||||
Object.assign(this.option, appCache.get(KuGanStore.name));
|
||||
Object.assign(this.UIOption, DataAdapter.ConvertUIData(appCache.get(KuGanStore.name)));
|
||||
}
|
||||
else
|
||||
{
|
||||
let data = await PostJson(ConfigUrls.Get, { key: KuGanStore.name }, false);
|
||||
if (data.err_code === RequestStatus.Ok && data.value)
|
||||
{
|
||||
let config = JSON.parse(data.value);
|
||||
appCache.set(KuGanStore.name, JSON.parse(data.value));
|
||||
Object.assign(this.option, config);
|
||||
Object.assign(this.UIOption, DataAdapter.ConvertUIData(config));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const kuGanStore = new KuGanStore();
|
Loading…
Reference in new issue