@/utils#dataURLtoFile TypeScript Examples
The following examples show how to use
@/utils#dataURLtoFile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From scorpio-h5-design with MIT License | 4 votes |
export default function() {
const { pageId, pageSchema, selectPage, setStateByObjectKeys } = useModel('bridge');
const addPageReq = useRequest(service.addPage, {
manual: true,
});
const editPageReq = useRequest(service.editPage, {
manual: true,
});
const [visible, { toggle }] = useBoolean(false);
const [qrcodeUrl, setQrcodeUrl] = useState('');
const save = async function() {
const dataURL = await window.postmate_mobile.get(childrenModel.CAPTURE);
if (dataURL) {
const file = dataURLtoFile(dataURL, new Date().getTime().toString());
const fileName = `${uuidv4()}.png`;
await ossClient.put(`design/${fileName}`, file);
selectPage.cover = `https://scorpio-design.lxzyl.cn/design/${fileName}`;
}
let res;
if (pageId) {
res = await editPageReq.run({
_id: pageId,
pageSchema,
});
} else {
res = await addPageReq.run({
pageSchema,
});
}
return res;
};
const onSave = async function() {
if (pageSchema.length === 0) {
return message.error('请新建页面后再保存!');
}
if (selectPage.components.length === 0) {
return message.error('至少添加一个组件后再保存!');
}
const res = await save();
const state = {
pageId: res._id,
};
setStateByObjectKeys(state);
message.success('保存成功!');
};
const onVisibleChange = async function() {
if (pageSchema.length === 0) {
return message.error('请新建页面后再操作!');
}
toggle();
await save();
const dataUrl = await QRCode.toDataURL(`${config.h5Base}?id=${pageId}`, {
margin: 0,
});
console.log('dataUrl: ', dataUrl);
setQrcodeUrl(dataUrl);
};
const overviewContent = (
<div className="overview-qrcode">
<img className="overview-qrcode-img" src={qrcodeUrl} />
</div>
);
const exportJson = function() {
const blob = new Blob([JSON.stringify(pageSchema)], { type: 'application/json' });
console.log('pageSchema: ', pageSchema);
FileSaver.saveAs(blob, `${pageSchema[0].props.title}.json`);
};
return (
<div className="design-header">
<div className="design-header-operations">
<div className="item" onClick={() => { history.push('/manage/page'); }}>
<i className="iconfont icon-shouye" />
<div className="text" >首页</div>
</div>
<div className="item" onClick={onSave}>
<i className="iconfont icon-baocun" />
<div className="text" >保存</div>
<Spin spinning={addPageReq.loading || editPageReq.loading}>
</Spin>
</div>
{/* <Popover
title="真机预览"
trigger="click"
visible={visible}
onVisibleChange={onVisibleChange}
content={overviewContent}
overlayClassName="overview-qrcode-popover"
>
<div className="item">
<i className="iconfont icon-shouji" />
<div className="text">预览</div>
</div>
</Popover> */}
<div className="item" onClick={exportJson}>
<i className="iconfont icon-json" />
<div className="text">导出</div>
</div>
{/* <div className="item">
<i className="iconfont icon-html" />
<div className="text">下载</div>
<i className="iconfont icon-new" style={{position: 'absolute', color: 'red', right: 0, top: 0}}/>
</div> */}
<div className="item" onClick={() => { window.open('https://github.com/lx544690189/scorpio-h5-design'); }}>
<i className="iconfont icon-github-fill" />
<div className="text">GITHUB</div>
</div>
</div>
</div>
);
}
Example #2
Source File: index.tsx From scorpio-h5-design with MIT License | 4 votes |
ComponentDetail = function() {
const { setStateByObjectKeys, pageSchema, selectComponent } = useModel('bridge');
const component = selectComponent as IComponentSchema;
const { onSubmit, loading } = Model.useContainer();
const SchemaRef = useRef<{ getValue: () => any }>(null);
function onTabChange(key: string) {
if (key === 'form') {
component.generatorSchema = SchemaRef.current?.getValue();
const state = {
pageSchema: [...pageSchema],
};
setStateByObjectKeys(state);
onChildrenReady(() => {
syncState({
payload: state,
type: IMessageType.syncState,
});
});
}
}
async function handelSubmit() {
component.generatorSchema = SchemaRef.current?.getValue();
const dataURL = await window.postmate_mobile.get(childrenModel.CAPTURE);
if (dataURL) {
const file = dataURLtoFile(dataURL, new Date().getTime().toString());
const fileName = `${uuidv4()}.png`;
await ossClient.put(`design/${fileName}`, file);
component.cover = `https://scorpio-design.lxzyl.cn/design/${fileName}`;
}
onSubmit();
}
const OperationsSlot = {
right: (
<Space className="manage-component-detail-tabs-extBtn">
<Button onClick={() => history.goBack()}>返回</Button>
<Button type="primary" onClick={handelSubmit}>保存</Button>
</Space>
),
};
const debouncedloading = useDebounce(loading, { wait: 500 });
return (
<Spin
spinning={debouncedloading}
wrapperClassName="blur-loading"
indicator={<Loading />}
>
<div className="manage-component-detail">
<div className="left">
<MobileSimulator loading={loading}/>
</div>
<div className="right">
<Tabs
className="manage-component-detail-tabs"
defaultActiveKey="1"
onChange={onTabChange}
tabBarExtraContent={OperationsSlot}
>
<TabPane tab="schema可视化配置" key="schema">
<Schema ref={SchemaRef} />
</TabPane>
<TabPane tab="schema手动编辑" key="code">
<Code />
</TabPane>
<TabPane tab="组件属性配置" key="form">
<Form />
</TabPane>
<TabPane tab="容器属性配置" key="container">
<BaseLayoutConfig />
</TabPane>
</Tabs>
</div>
</div>
</Spin>
);
}