Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
render() {
if(this.state.hasError) {
return null
}
const { selected, params={}, data, cellKey, editMode, wrapStyle, widgetWrap,
dispatchData, removeCell, selectCell, copyCell, onSettings, ...extraProps } = this.props
// is should display
if(!this.state.display || params == null) { return null }
const animed = params.animate && params.animate.active
const Widget = app.load_dict('dashboard_widgets')[params.type] || MissWidgetType
const style = { height: '100%', padding: 0, position: 'relative', userSelect: 'none', ...wrapStyle }
const cellSelected = selected && editMode
if(cellSelected) {
style['boxShadow'] = '0px 0px 1px #f00'
}
const widgetParams = this.state.widgetParams
const canSelect = Widget.CanSelect || !Widget.Container
const wrapId = 'dashboard-cell-wrap-' + cellKey.replace(/[\/\.]/g, '_')
const cellStyle = widgetParams.style ? <style scope="{true}">{_transformSheet(widgetParams.style, wrapId)}</style> : null
const typeClassName = 'dashboard-widget-' + params.type.replace(/[\/\.]/g, '_')
const wrapClassName = [ 'dashboard-cell-wrap', typeClassName ].join(' ')
const wrap = widgetWrap || ((widget) => (editMode ? (
<div style="{style}" id="{wrapId}"></div>
Object.keys(cells).map(key => {
const cell = cells[key]
const Widget = app.load_dict('dashboard_widgets')[cell.type]
if(Widget && Widget.sampleData) {
Widget.sampleData(cell, (key, data) => {
dispatch({ dashboard, type: '@@x-dashboard/UPDATE_DATA', key, data })
})
}
})
},
render() {
const { params: { layers, editLayer }, ...props } = this.props
const widgets = app.load_dict('dashboard_widgets')
return (
<nav>
{
Object.keys(widgets).map(key => {
const Widget = widgets[key]
return <menuitem>this.addCell(key)}>{Widget.Title}</menuitem>
})
}
<menuitem>this.changeLayer(null)}>取消编辑</menuitem>
{
layers && layers.map((layer, i) => {
return <menuitem>this.changeLayer(i)}>{`第${i+1}层`}</menuitem></nav>
addCell(type) {
const Widget = app.load_dict('dashboard_widgets')[type]
const { params: { editLayer } } = this.props
const params = {
key: (Math.random() * 100).toString(),
params: {
layer: editLayer,
type,
title: '未命名标题'
},
layout: { x: 0, y: 0, w: 4, h: 4 }
}
this.props.addCell(params)
if(this.props.onAddCell) {
this.props.onAddCell(params.key)
}
}
getWidget: () => app.load_dict('dashboard_widgets')['xadmin-dashboard/main'] || Box
}
render() {
const { cells, selectedCell } = this.props
const widgets = app.load_dict('dashboard_widgets')
const Node = ( nodeName ) => {
return (cells[nodeName] && cells[nodeName].childrenCells || []).map(key =>{
const cell = cells[key]
const children = Node(key)
const Widget = widgets[cell.type] || {}
const title = (cell.name ? <span>{cell.name} <span style="{{">[{Widget.Title}]</span></span> : Widget.Title)
const cellTitle =
if(children && children.length > 0) {
return (
{ children }
)
} else {
return
export default ({ input, label, meta, field, option, group: FieldGroup }) => {
let renderItems = field.itemsRender || defaultItemsRender
if(typeof renderItems === 'string') {
renderItems = app.load_dict('array_render')[renderItems]
}
const { items } = field
const fieldsBuilder = (name, index, removeBtn, itemLable) => {
const itemFields = items.fields ? (items.fields
.map(f => { return { ...f,
key: name + '.' + f.key,
name: name + '.' + f.name
} })) : [ { ...items, key: name, name: name, label: itemLable } ]
return objectBuilder(itemFields, items.render, option)
}
return (
)
query: ({ cell }) => {
const Widget = app.load_dict('dashboard_widgets')[cell.type]
return new Promise((resolve) => {
if(Widget && Widget.sampleData) {
Widget.sampleData(cell, resolve)
} else {
resolve([])
}
} )
}
}
saveParams = (values) => {
const { params, cellKey, parent } = this.props
if(parent && parent.type) {
const Container = app.load_dict('dashboard_widgets')[parent.type]
if(Container && Container.saveChildLayout) {
const parentParams = Container.saveChildLayout(parent, cellKey, values)
this.props.saveLayoutParam(parentParams)
}
}
this.props.onClose && this.props.onClose()
}