UNPKG

@doreamonjs/page-detail

Version:
177 lines (176 loc) 10.3 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DetailPage = void 0; const react_1 = __importStar(require("react")); const doreamon_1 = __importDefault(require("@zodash/doreamon")); const components_1 = require("@doreamonjs/components"); const antd_1 = require("antd"); const icons_1 = require("@ant-design/icons"); require("./index.less"); const componentName = 'doreamonjs-design-page-detail'; const DetailPage = (props) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1; const [isMobile] = react_1.useState((_b = (_a = window.matchMedia) === null || _a === void 0 ? void 0 : _a.call(window, "(max-width: 767px)")) === null || _b === void 0 ? void 0 : _b.matches); const values = (_d = (_c = props === null || props === void 0 ? void 0 : props.datasets) === null || _c === void 0 ? void 0 : _c.values) !== null && _d !== void 0 ? _d : {}; let basisNode = null; if (typeof ((_e = props.attributes.detail) === null || _e === void 0 ? void 0 : _e.basis) === 'function') { basisNode = props.attributes.detail.basis(props.datasets.values, props); } else { const details = (_f = props.attributes.detail.basis) === null || _f === void 0 ? void 0 : _f.items; const renderBasisBottom = (_h = (_g = props.attributes.detail) === null || _g === void 0 ? void 0 : _g.basis) === null || _h === void 0 ? void 0 : _h.renderBottom; let title = (_m = (_k = (_j = values === null || values === void 0 ? void 0 : values.title) !== null && _j !== void 0 ? _j : values === null || values === void 0 ? void 0 : values.name) !== null && _k !== void 0 ? _k : (_l = props.attributes) === null || _l === void 0 ? void 0 : _l.title) !== null && _m !== void 0 ? _m : '-'; let subTitle = (_o = values === null || values === void 0 ? void 0 : values.subTitle) !== null && _o !== void 0 ? _o : (_p = props.attributes) === null || _p === void 0 ? void 0 : _p.subTitle; if (!!((_r = (_q = props.attributes.detail) === null || _q === void 0 ? void 0 : _q.basis) === null || _r === void 0 ? void 0 : _r.title)) { const title_ = props.attributes.detail.basis.title; if (typeof title_ === 'function') { title = title_(values, props); } else { title = title_; } } if (!!((_t = (_s = props.attributes.detail) === null || _s === void 0 ? void 0 : _s.basis) === null || _t === void 0 ? void 0 : _t.subTitle)) { const subTitle_ = props.attributes.detail.basis.subTitle; if (typeof subTitle_ === 'function') { subTitle = subTitle_(values, props); } else { subTitle = subTitle_; } } const onGoHome = () => { // return (window as any)?.__DOREAMONJS_SDK?.shared?.router?.go?.('/'); return window.location.href = '/'; }; const onGoBack = () => { var _a, _b, _c, _d, _e; return (_e = (_d = (_c = (_b = (_a = window) === null || _a === void 0 ? void 0 : _a.__DOREAMONJS_SDK) === null || _b === void 0 ? void 0 : _b.shared) === null || _c === void 0 ? void 0 : _c.router) === null || _d === void 0 ? void 0 : _d.goBack) === null || _e === void 0 ? void 0 : _e.call(_d); }; if (((_v = (_u = props.attributes.detail) === null || _u === void 0 ? void 0 : _u.basis) === null || _v === void 0 ? void 0 : _v.hideContentInMobile) && isMobile) { basisNode = (react_1.default.createElement(react_1.default.Fragment, null, react_1.default.createElement(components_1.Card, { title: !isMobile ? title : (react_1.default.createElement("div", null, react_1.default.createElement(icons_1.HomeOutlined, { style: { marginRight: 8 }, onClick: onGoHome }), react_1.default.createElement(icons_1.ArrowLeftOutlined, { style: { marginRight: 8 }, onClick: onGoBack }), react_1.default.createElement("div", { style: { display: 'inline-block' } }, title))), bodyStyle: { paddingTop: 0, paddingBottom: 0, } }), !!renderBasisBottom && (react_1.default.createElement("div", { style: { padding: 24, paddingTop: 0, } }, renderBasisBottom(values, props))))); } else { basisNode = (react_1.default.createElement(react_1.default.Fragment, null, react_1.default.createElement(components_1.Card.Information, { title: !isMobile ? title : (react_1.default.createElement("div", null, react_1.default.createElement(icons_1.HomeOutlined, { style: { marginRight: 8 }, onClick: onGoHome }), react_1.default.createElement(icons_1.ArrowLeftOutlined, { style: { marginRight: 8 }, onClick: onGoBack }), react_1.default.createElement("div", { style: { display: 'inline-block' } }, title))), subTitle: subTitle, actions: props.attributes.actions, allowActionTypes: ['custom'], column: (_y = (_x = (_w = props.attributes.detail) === null || _w === void 0 ? void 0 : _w.basis) === null || _x === void 0 ? void 0 : _x.column) !== null && _y !== void 0 ? _y : 2, items: details, data: values, onActionClick: (action, values) => { props.onActionTrigger(action, { values, }); } }), !!renderBasisBottom && (react_1.default.createElement("div", { style: { padding: 24, paddingTop: 0, } }, renderBasisBottom(values, props))))); } } let detailNode = null; if (typeof props.attributes.detail.modules === 'function') { detailNode = props.attributes.detail.modules(values, props); } else { const defaultTab = (_z = props.attributes.detail.modules) === null || _z === void 0 ? void 0 : _z.default; const tabs = (_1 = (_0 = props.attributes.detail.modules) === null || _0 === void 0 ? void 0 : _0.items) === null || _1 === void 0 ? void 0 : _1.filter((tab, index) => { let isVisible = tab.visible; if (typeof tab.visible === 'function') { isVisible = tab.visible(values, tab, index, props); } return isVisible !== false; }).map((tab, index) => { let title = tab.title; let render = tab.render; if (typeof title === 'function') { title = title(values, props); } if (!!tab.render && typeof tab.render === 'function') { render = () => { return tab.render(values, index, props); }; } return { ...tab, title, render, }; }); detailNode = (react_1.default.createElement(components_1.Tab, { className: 'tab', items: tabs, defaultValue: defaultTab })); } const isLoading = () => { var _a; const id = (_a = doreamon_1.default.dom.router.getQuery()) === null || _a === void 0 ? void 0 : _a.id; if (typeof props.attributes.detail.loading === 'function') { return props.attributes.detail.loading(id, values, props); } if (Object.keys(values).length === 0) { return true; } // check values.id if (!!(values === null || values === void 0 ? void 0 : values.id)) { if (typeof (values === null || values === void 0 ? void 0 : values.id) === 'string') { return id !== (values === null || values === void 0 ? void 0 : values.id); } else if (typeof (values === null || values === void 0 ? void 0 : values.id) === 'number') { return +id !== (values === null || values === void 0 ? void 0 : values.id); } } else if (!!(values === null || values === void 0 ? void 0 : values._id)) { // check values._id if (typeof (values === null || values === void 0 ? void 0 : values._id) === 'string') { return id !== (values === null || values === void 0 ? void 0 : values._id); } else if (typeof (values === null || values === void 0 ? void 0 : values._id) === 'number') { return +id !== (values === null || values === void 0 ? void 0 : values._id); } } return false; }; if (isLoading()) { return (react_1.default.createElement("div", { style: { width: '100%', height: '500px', backgroundColor: '#fff', padding: '10px 20px', } }, react_1.default.createElement(antd_1.Skeleton, { paragraph: { rows: 10 } }))); } return (react_1.default.createElement("div", { className: doreamon_1.default.classnames('page', componentName, props.className) }, basisNode, detailNode)); }; exports.DetailPage = DetailPage; exports.default = exports.DetailPage;