mirror of https://gitee.com/cf-fz/WebCAD.git
!724 材质发布和购买
parent
27e1782e38
commit
2c7bfc4148
@ -0,0 +1,12 @@
|
|||||||
|
import { Command } from "../Editor/CommandMachine";
|
||||||
|
import { app } from "../ApplicationServices/Application";
|
||||||
|
import { MetarialShop } from './../UI/MaterialEditor/MaterialShop';
|
||||||
|
import { ModalPosition } from "../UI/Components/Modal/ModalsManage";
|
||||||
|
|
||||||
|
export class BuyMaterial implements Command
|
||||||
|
{
|
||||||
|
exec()
|
||||||
|
{
|
||||||
|
app.Editor.ModalManage.RenderModal(MetarialShop, ModalPosition.Center, {});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { app } from './../../../ApplicationServices/Application';
|
||||||
|
import { Classes, Button } from '@blueprintjs/core';
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
|
import { observable } from 'mobx';
|
||||||
|
|
||||||
|
interface ICommonIframeProps
|
||||||
|
{
|
||||||
|
url: string;
|
||||||
|
title: string;
|
||||||
|
onMessage: (e: MessageEvent) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
@observer
|
||||||
|
export class CommonIframe extends React.Component<ICommonIframeProps, {}>{
|
||||||
|
|
||||||
|
@observable isMax = false;
|
||||||
|
componentDidMount()
|
||||||
|
{
|
||||||
|
this.changeModalSize();
|
||||||
|
window.addEventListener("message", this.props.onMessage);
|
||||||
|
}
|
||||||
|
componentWillUnmount()
|
||||||
|
{
|
||||||
|
window.removeEventListener("message", this.props.onMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
render()
|
||||||
|
{
|
||||||
|
const { url, title } = this.props;
|
||||||
|
return (
|
||||||
|
<div className={Classes.DIALOG_CONTAINER}>
|
||||||
|
<div className={Classes.DIALOG + " board-config"}>
|
||||||
|
<div className={Classes.DIALOG_HEADER} data-id="dragArea">
|
||||||
|
<h4 className="bp3-heading">{title}</h4>
|
||||||
|
<Button
|
||||||
|
minimal
|
||||||
|
icon={this.isMax ? "minimize" : "maximize"}
|
||||||
|
onClick={this.changeModalSize}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
aria-label="Close"
|
||||||
|
minimal
|
||||||
|
icon="cross"
|
||||||
|
className={Classes.DIALOG_CLOSE_BUTTON}
|
||||||
|
onClick={() => app.Editor.ModalManage.Clear()}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className={Classes.DIALOG_BODY}>
|
||||||
|
<iframe
|
||||||
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
minWidth: 1000,
|
||||||
|
minHeight: 600
|
||||||
|
}}
|
||||||
|
src={url}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
private changeModalSize = () =>
|
||||||
|
{
|
||||||
|
this.isMax = !this.isMax;
|
||||||
|
app.Editor.ModalManage.ScaleModalSize();
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { CURRENT_HOST, MaterialUrls } from './../../Common/HostUrl';
|
||||||
|
import { CommandWrap } from "../../Editor/CommandMachine";
|
||||||
|
import { PostJson, RequestStatus } from "../../Common/Request";
|
||||||
|
import { inflate } from "../../Common/SerializeMaterial";
|
||||||
|
import { MaterialInAndAppendAppData } from './../../Common/SerializeMaterial';
|
||||||
|
import { AppToaster } from './../Components/Toaster';
|
||||||
|
import { CommonIframe } from './../Components/Common/CommonIframe';
|
||||||
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
|
||||||
|
export class MetarialShop extends React.Component<{}, {}>{
|
||||||
|
private mtlIdSet = new Set();
|
||||||
|
|
||||||
|
OnMessage = async (e: MessageEvent) =>
|
||||||
|
{
|
||||||
|
if (e.origin !== CURRENT_HOST) return;
|
||||||
|
this.handleBuy(e.data.material_id);
|
||||||
|
};
|
||||||
|
private handleBuy = (material_id: string) =>
|
||||||
|
{
|
||||||
|
if (this.mtlIdSet.has(material_id))
|
||||||
|
{
|
||||||
|
AppToaster.show({
|
||||||
|
message: "材质重复购买",
|
||||||
|
timeout: 2000,
|
||||||
|
intent: Intent.WARNING
|
||||||
|
}, "bugMat");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CommandWrap(async () =>
|
||||||
|
{
|
||||||
|
let data = await PostJson(MaterialUrls.publishDetail, { material_id });
|
||||||
|
|
||||||
|
if (data.err_code === RequestStatus.Ok && data.materials.file)
|
||||||
|
{
|
||||||
|
this.mtlIdSet.add(material_id);
|
||||||
|
let file = data.materials.file;
|
||||||
|
let json = inflate(file);
|
||||||
|
let mtl = MaterialInAndAppendAppData(JSON.parse(json), data.materials.name);
|
||||||
|
if (mtl)
|
||||||
|
{
|
||||||
|
AppToaster.show({
|
||||||
|
message: "材质已应用到图纸",
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, "购买材质");
|
||||||
|
};
|
||||||
|
render()
|
||||||
|
{
|
||||||
|
return <CommonIframe
|
||||||
|
url={MaterialUrls.buy}
|
||||||
|
title="材质购买"
|
||||||
|
onMessage={this.OnMessage}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue