UNPKG

@ovine/core

Version:

Build flexible admin system with json.

79 lines (78 loc) 3.22 kB
/** * 自定义 crud 组件 * 固定 table height 存在BUG,需要其他方式支持 */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { Renderer } from 'amis'; import React from 'react'; import { css } from 'styled-components'; import { crudCss } from "./styled"; const getAmisCrudSchema = (props) => { const { tableClassName = '', filter, headerToolbar = [] } = props, rest = __rest(props // const isSmScreen = window.innerWidth < breakpoints.md // 在小屏幕中 自动加入分页 // if ( // isSmScreen && // !headerToolbar.find((i: any) => i === 'pagination' || get(i, 'type') === 'pagination') // ) { // headerToolbar.push({ // type: 'pagination', // align: 'right', // }) // } , ["tableClassName", "filter", "headerToolbar"]); // const isSmScreen = window.innerWidth < breakpoints.md // 在小屏幕中 自动加入分页 // if ( // isSmScreen && // !headerToolbar.find((i: any) => i === 'pagination' || get(i, 'type') === 'pagination') // ) { // headerToolbar.push({ // type: 'pagination', // align: 'right', // }) // } const crudSchema = Object.assign(Object.assign({ keepItemSelectionOnPageChange: true }, rest), { type: 'crud', className: 'lib-crud r', tableClassName: `lib-crud-table ${tableClassName}`, // affixHeader: isSmScreen, headerToolbar, filter: Object.assign(Object.assign({}, filter), { title: '', submitText: '', wrapWithPanel: false }) }); return crudSchema; }; let LibCrud = class LibCrud extends React.Component { render() { const { css: getCss, render, className, htmlClassName } = this.props; const amisCurd = { className, htmlClassName, type: 'lib-css', css: (theme) => css ` ${crudCss(theme)}; ${!getCss ? null : typeof getCss === 'string' ? getCss : getCss(theme)}; `, body: getAmisCrudSchema(this.props), }; return render('body', amisCurd); } }; LibCrud = __decorate([ Renderer({ test: /(^|\/)lib-crud$/, name: 'lib-crud', }) ], LibCrud); export { LibCrud };