修复 message 不弹出

This commit is contained in:
Wang Kejun 2022-12-01 19:00:26 +08:00
parent f80931a7e2
commit 0d13e335dd
8 changed files with 87 additions and 36 deletions

View File

@ -9,11 +9,15 @@ function render(props) {
var _a = props.data, _b = _a.placement, placement = _b === void 0 ? 'bottom' : _b, _c = _a.style, style = _c === void 0 ? {} : _c; var _a = props.data, _b = _a.placement, placement = _b === void 0 ? 'bottom' : _b, _c = _a.style, style = _c === void 0 ? {} : _c;
var _d = props.methods, printCachedStore = _d.printCachedStore, printDebugStore = _d.printDebugStore, printRunningTree = _d.printRunningTree, resetInitialData = _d.resetInitialData, downloadEnv = _d.downloadEnv, resetEnv = _d.resetEnv; var _d = props.methods, printCachedStore = _d.printCachedStore, printDebugStore = _d.printDebugStore, printRunningTree = _d.printRunningTree, resetInitialData = _d.resetInitialData, downloadEnv = _d.downloadEnv, resetEnv = _d.resetEnv;
var _e = tslib_1.__read((0, react_1.useState)(false), 2), visible = _e[0], setVisible = _e[1]; var _e = tslib_1.__read((0, react_1.useState)(false), 2), visible = _e[0], setVisible = _e[1];
return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsx)(antd_1.Button, { type: "text", shape: "circle", icon: (0, jsx_runtime_1.jsx)(icons_1.UpOutlined, { style: { fontSize: 12 } }), style: tslib_1.__assign({ position: 'fixed', bottom: 0, right: '45vw', zIndex: 999 }, style), onClick: function () { return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsx)(antd_1.Button, { type: "text", shape: "circle", icon: (0, jsx_runtime_1.jsx)(icons_1.UpOutlined, { style: { fontSize: 12 } }), style: tslib_1.__assign({ position: 'fixed', bottom: 0, right: 'calc(100% / 2 - 16px)', zIndex: 999, width: 32, height: 32 }, style), onClick: function () {
setVisible(true); setVisible(true);
} }), (0, jsx_runtime_1.jsxs)(antd_1.Drawer, tslib_1.__assign({ placement: placement, open: visible, onClose: function () { } }), (0, jsx_runtime_1.jsxs)(antd_1.Drawer, tslib_1.__assign({ getContainer: false, placement: placement, open: visible, onClose: function () {
setVisible(false); setVisible(false);
}, title: "Debug\u63A7\u5236\u53F0", footer: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}) }, { children: [(0, jsx_runtime_1.jsx)("input", { type: "file", accept: "application/json", hidden: true, id: "upload", onChange: function () { }, title: "Debug\u63A7\u5236\u53F0", footer: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}), rootStyle: {
width: '100vw',
}, bodyStyle: {
width: '100vw',
} }, { children: [(0, jsx_runtime_1.jsx)("input", { type: "file", accept: "application/json", hidden: true, id: "upload", onChange: function () {
var file = document.getElementById('upload') var file = document.getElementById('upload')
.files[0]; .files[0];
if (typeof FileReader === undefined) { if (typeof FileReader === undefined) {

View File

@ -7,9 +7,10 @@ exports.default = OakComponent({
formData: function (_a) { formData: function (_a) {
var props = _a.props; var props = _a.props;
var data = this.consumeMessage(); var data = this.consumeMessage();
if (process.env.OAK_PLATFORM === 'wechatMp') {
if (data) { if (data) {
var self_1 = this; var self_1 = this;
message_1.default[data.type](Object.assign({}, process.env.OAK_PLATFORM === 'wechatMp' && { message_1.default[data.type](Object.assign({
// 处理小程序 // 处理小程序
offset: [20, 32], offset: [20, 32],
icon: true, icon: true,
@ -17,6 +18,10 @@ exports.default = OakComponent({
}, data)); }, data));
} }
return {}; return {};
}
return {
data: data,
};
}, },
lifetimes: { lifetimes: {
attached: function () { attached: function () {

View File

@ -1 +1,7 @@
export default function render(): null; /// <reference types="react" />
import { MessageProps } from 'oak-frontend-base/lib/types/Message';
export default function render(props: {
data: {
data: MessageProps;
};
}): JSX.Element;

View File

@ -1,6 +1,17 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
function render() { var tslib_1 = require("tslib");
return null; var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var antd_1 = require("antd");
function render(props) {
var _a = tslib_1.__read(antd_1.message.useMessage(), 2), messageApi = _a[0], contextHolder = _a[1];
var data = props.data.data;
(0, react_1.useEffect)(function () {
if (data) {
messageApi[data.type](data);
}
}, [data]);
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: contextHolder });
} }
exports.default = render; exports.default = render;

View File

@ -80,7 +80,7 @@
"gen:areaDebug": "ts-node ./scripts/generateAreaDebug.ts", "gen:areaDebug": "ts-node ./scripts/generateAreaDebug.ts",
"clean:dir": "ts-node ./scripts/cleanDtsAndJs", "clean:dir": "ts-node ./scripts/cleanDtsAndJs",
"test": "ts-node ./test/test.ts", "test": "ts-node ./test/test.ts",
"prepare": "rimraf node_modules/react & rimraf node_modules/react-dom & rimraf node_modules/react-router" "prepare": "rimraf node_modules/react & rimraf node_modules/react-dom & rimraf node_modules/react-router & rimraf node_modules/antd"
}, },
"main": "lib/index" "main": "lib/index"
} }

View File

@ -27,8 +27,10 @@ export default function render(props: WebComponentProps<EntityDict, 'address', t
style={{ style={{
position: 'fixed', position: 'fixed',
bottom: 0, bottom: 0,
right: '45vw', right: 'calc(100% / 2 - 16px)',
zIndex: 999, zIndex: 999,
width: 32,
height: 32,
...style, ...style,
}} }}
onClick={() => { onClick={() => {
@ -36,6 +38,7 @@ export default function render(props: WebComponentProps<EntityDict, 'address', t
}} }}
/> />
<Drawer <Drawer
getContainer={false}
placement={placement} placement={placement}
open={visible} open={visible}
onClose={() => { onClose={() => {
@ -43,6 +46,12 @@ export default function render(props: WebComponentProps<EntityDict, 'address', t
}} }}
title="Debug控制台" title="Debug控制台"
footer={<></>} footer={<></>}
rootStyle={{
width: '100vw',
}}
bodyStyle={{
width: '100vw',
}}
> >
<input <input
type="file" type="file"

View File

@ -5,12 +5,12 @@ export default OakComponent({
isList: false, isList: false,
formData({ props }) { formData({ props }) {
const data = this.consumeMessage() as MessageProps; const data = this.consumeMessage() as MessageProps;
if (process.env.OAK_PLATFORM === 'wechatMp') {
if (data) { if (data) {
const self = this; const self = this;
Message[data.type as MessageProps['type']]( Message[data.type as MessageProps['type']](
Object.assign( Object.assign(
{}, {
process.env.OAK_PLATFORM === 'wechatMp' && {
// 处理小程序 // 处理小程序
offset: [20, 32], offset: [20, 32],
icon: true, icon: true,
@ -21,6 +21,11 @@ export default OakComponent({
); );
} }
return {}; return {};
}
return {
data,
};
}, },
lifetimes: { lifetimes: {
attached() { attached() {

View File

@ -1,6 +1,17 @@
import * as React from 'react'; import React, { useEffect } from 'react';
import { message } from 'antd';
import { MessageProps } from 'oak-frontend-base/lib/types/Message';
export default function render() { export default function render(props: { data: { data: MessageProps } }) {
return null; const [messageApi, contextHolder] = message.useMessage();
const { data } = props.data;
useEffect(() => {
if (data) {
messageApi[data.type as MessageProps['type']](data as any);
}
}, [data]);
return <>{contextHolder}</>;
} }