Comparing version 1.1.0 to 1.1.1
/// <reference types="react" /> | ||
import * as React from 'react'; | ||
import { ListModalProps, MODE } from './interface'; | ||
import { ColumnProps } from 'antd/lib/table/interface'; | ||
import { ListModalProps, MODE, Column } from './interface'; | ||
export default class ListModal<T> extends React.Component<ListModalProps<T>> { | ||
rowKey: string; | ||
mode: MODE; | ||
editObject: {}; | ||
doAdd(record: any, save: any): void; | ||
doEdit(record: any, save: any): void; | ||
exitEditMode(record: any, save: boolean): void; | ||
edit(record: any): void; | ||
renderColumns(text: any, record: any, column: any): JSX.Element; | ||
del(record: any): void; | ||
buildEditColumn(): ColumnProps<T>[]; | ||
buildOption(): ColumnProps<T>[]; | ||
state: { | ||
@@ -21,9 +11,20 @@ list: any[]; | ||
columns: any[]; | ||
selectedRowKeys: any[]; | ||
selectedRowObjects: any[]; | ||
}; | ||
param: {}; | ||
search(pagination: any, filters: any, sorter: any): void; | ||
editObject: {}; | ||
componentWillMount(): void; | ||
componentDidUpdate(old: any): void; | ||
doAdd(record: any, save: any): void; | ||
doEdit(record: any, save: any): void; | ||
exitEditMode(record: any, save: boolean): void; | ||
edit(record: any): void; | ||
renderColumns(text: any, record: any, column: Column<T>): JSX.Element; | ||
del(record: any): void; | ||
buildEditColumn(): Column<T>[]; | ||
buildOption(): Column<T>[]; | ||
search(pagination: any, filters: any, sorter: any): void; | ||
add(): void; | ||
render(): JSX.Element; | ||
} |
@@ -38,11 +38,38 @@ "use strict"; | ||
_this.mode = interface_1.MODE.COMMON; | ||
_this.editObject = {}; | ||
_this.state = { | ||
list: [], | ||
total: 0, | ||
columns: [] | ||
columns: [], | ||
selectedRowKeys: [], | ||
selectedRowObjects: [] | ||
}; | ||
_this.param = {}; | ||
_this.editObject = {}; | ||
return _this; | ||
} | ||
ListModal.prototype.componentWillMount = function () { | ||
this.rowKey = this.props.rowKey || this.rowKey; | ||
}; | ||
ListModal.prototype.componentDidUpdate = function (old) { | ||
var _this = this; | ||
if (old.show === false && this.props.show === true) { | ||
var columns_1 = this.buildOption(); | ||
this.param = _.assign({}, { start: 0, count: 15 }, this.props.param); | ||
utils_1.Ajax.POST(this.props.query, this.param, function (json) { | ||
_this.setState({ | ||
list: json.list, | ||
total: json.total, | ||
columns: columns_1 | ||
}); | ||
}); | ||
} | ||
else if (old.show === true && this.props.show === false) { | ||
this.setState({ | ||
list: [], | ||
total: 0, | ||
selectedRowKeys: [], | ||
selectedRowObjects: [] | ||
}); | ||
} | ||
}; | ||
ListModal.prototype.doAdd = function (record, save) { | ||
@@ -114,2 +141,4 @@ var _this = this; | ||
var _this = this; | ||
// console.log(column) | ||
// console.log(column.type); | ||
return React.createElement(EditableCell, { editable: record._edit, value: text, onChange: function (txt) { return _this.editObject[column.dataIndex] = txt; } }); | ||
@@ -131,2 +160,3 @@ }; | ||
var columns = _.concat([], this.props.columns); | ||
// if (this.props.edit) {} | ||
columns.map(function (column) { | ||
@@ -139,9 +169,3 @@ column.render = function (text, record) { return _this.renderColumns(text, record, column); }; | ||
var _this = this; | ||
var columns = []; | ||
if (this.props.edit) { | ||
columns = this.buildEditColumn(); | ||
} | ||
else { | ||
columns = _.concat([], this.props.columns); | ||
} | ||
var columns = this.buildEditColumn(); | ||
if (this.props.edit || this.props.del || this.props.select) { | ||
@@ -152,2 +176,3 @@ var operCol = { | ||
className: 'talbe-actions', | ||
width: 100, | ||
render: function (text, editObject) { | ||
@@ -159,2 +184,5 @@ var acts = []; | ||
} | ||
else if (_this.props.select) { | ||
acts.push(React.createElement(antd_1.Button, { size: "small", onClick: function () { return _this.props.select([editObject]); } }, "\u9009\u62E9")); | ||
} | ||
else { | ||
@@ -168,5 +196,2 @@ if (_this.props.edit) { | ||
} | ||
if (_this.props.select) { | ||
acts.push(React.createElement(antd_1.Icon, { type: "check-square", title: "\u9009\u62E9", onClick: function () { return _this.setState({}); } })); | ||
} | ||
} | ||
@@ -182,25 +207,2 @@ return acts; | ||
}; | ||
ListModal.prototype.componentWillMount = function () { | ||
this.rowKey = this.props.rowKey || this.rowKey; | ||
}; | ||
ListModal.prototype.componentDidUpdate = function (old) { | ||
var _this = this; | ||
if (old.show === false && this.props.show === true) { | ||
var columns_1 = this.buildOption(); | ||
this.param = _.assign({}, { start: 0, count: 15 }, this.props.param); | ||
utils_1.Ajax.POST(this.props.query, this.param, function (json) { | ||
_this.setState({ | ||
list: json.list, | ||
total: json.total, | ||
columns: columns_1 | ||
}); | ||
}); | ||
} | ||
else if (old.show === true && this.props.show === false) { | ||
window.setTimeout(function () { return _this.setState({ | ||
list: [], | ||
total: 0 | ||
}); }, 1000); | ||
} | ||
}; | ||
ListModal.prototype.add = function () { | ||
@@ -224,3 +226,8 @@ if (this.mode === interface_1.MODE.COMMON) { | ||
var param = { title: [this.props.title] }; | ||
if (_.has(this.props, 'onOk')) { | ||
if (this.props.mutiSelect && this.props.select) { | ||
param.footer = React.createElement(antd_1.Button, { disabled: this.state.selectedRowKeys.length == 0, onClick: function (e) { return _this.props.select(_this.state.selectedRowObjects); }, type: "primary" }, | ||
"\u9009\u62E9", | ||
this.state.selectedRowKeys.length > 0 ? "(" + this.state.selectedRowKeys.length + ")" : ''); | ||
} | ||
else if (_.has(this.props, 'onOk')) { | ||
param.footer = React.createElement(antd_1.Button, { onClick: function (e) { return _this.props.onOk(null); }, type: "primary" }, "\u786E\u5B9A"); | ||
@@ -234,4 +241,11 @@ } | ||
} | ||
var tableParam = {}; | ||
if (this.props.mutiSelect && this.props.select) { | ||
tableParam.rowSelection = { | ||
selectedRowKeys: this.state.selectedRowKeys, | ||
onChange: function (selectedRowKeys, selectedRowObjects) { return _this.setState({ selectedRowKeys: selectedRowKeys, selectedRowObjects: selectedRowObjects }); } | ||
}; | ||
} | ||
return React.createElement(antd_1.Modal, __assign({}, param, { visible: this.props.show, width: this.props.width || 800, onCancel: this.props.onCancel, className: "admin-list-modal" }), | ||
React.createElement(antd_1.Table, { columns: this.state.columns, onChange: function (pagination, filters, sorter) { return _this.search(pagination, filters, sorter); }, dataSource: this.state.list, size: "small", pagination: { | ||
React.createElement(antd_1.Table, __assign({}, tableParam, { rowKey: this.rowKey, columns: this.state.columns, onChange: function (pagination, filters, sorter) { return _this.search(pagination, filters, sorter); }, dataSource: this.state.list, size: "small", pagination: { | ||
// current: this.state.current, | ||
@@ -243,3 +257,3 @@ total: this.state.total, | ||
pageSize: 15 | ||
} })); | ||
} }))); | ||
}; | ||
@@ -246,0 +260,0 @@ return ListModal; |
@@ -8,4 +8,8 @@ import { ModalProps } from 'antd/lib/modal/Modal'; | ||
} | ||
export interface Column<T> extends ColumnProps<T> { | ||
type?: string; | ||
options?: any[]; | ||
} | ||
export interface ListModalProps<T> extends ModalProps { | ||
columns: ColumnProps<T>[]; | ||
columns: Column<T>[]; | ||
show: boolean; | ||
@@ -16,2 +20,3 @@ query: string; | ||
del?: string; | ||
mutiSelect?: boolean; | ||
select?: Function; | ||
@@ -18,0 +23,0 @@ param?: any; |
{ | ||
"name": "vap", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "vap", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74355
36
1851