提交 bf922ed1 authored 作者: 钟是志's avatar 钟是志

18983 职业技能竞赛选择指导老师,第一次输入工号和姓名,可以搜索到。再次搜索其它老师工号,姓名、还有根据学院搜索,有时候根本搜索不到。属于大bug,要解决。用户体验很差。

上级 c4b6843d
import React from 'react' import React from 'react';
import { Tree, Upload, Icon, Button, message, Span, Modal, Tag, Table } from 'antd'; import { Button, message, Modal, Tag, Table } from 'antd';
import FormList from './formList/index'; import FormList from './formList/index';
const TreeNode = Tree.TreeNode;
import { connect } from 'dva'; import { connect } from 'dva';
@connect(({ DataColumn, SqlManageEntity, loading }) => ({ @connect(({ DataColumn, SqlManageEntity, loading }) => ({
DataColumn, SqlManageEntity, DataColumn,
loading: loading.models.DataColumn || loading.models.SqlManageEntity SqlManageEntity,
loading: loading.models.DataColumn || loading.models.SqlManageEntity,
})) }))
export default class TableSelect extends React.Component { export default class TableSelect extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props);
const value = props.value || {}; const value = props.value || {};
this.state = { this.state = {
...@@ -21,17 +19,18 @@ export default class TableSelect extends React.Component { ...@@ -21,17 +19,18 @@ export default class TableSelect extends React.Component {
isAll: value.isAll != null ? value.isAll : false, isAll: value.isAll != null ? value.isAll : false,
querys: value.querys || [], querys: value.querys || [],
sql: value.sql, sql: value.sql,
} };
} }
triggerChange = (changedValue) => { triggerChange = changedValue => {
// Should provide an event to pass value to Form. // Should provide an event to pass value to Form.
const onChange = this.props.onChange; const onChange = this.props.onChange;
if (onChange) { if (onChange) {
console.log("changedValue", changedValue) console.log('changedValue', changedValue);
onChange(Object.assign({}, this.state, changedValue)); onChange(Object.assign({}, this.state, changedValue));
} }
} };
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
// Should be a controlled component. // Should be a controlled component.
if ('value' in nextProps) { if ('value' in nextProps) {
...@@ -43,167 +42,215 @@ export default class TableSelect extends React.Component { ...@@ -43,167 +42,215 @@ export default class TableSelect extends React.Component {
// //
} }
} }
remove = (rowKey) => {
console.log(rowKey) remove = rowKey => {
const { selects } = this.state const { selects } = this.state;
delete selects[rowKey] delete selects[rowKey];
console.log(selects)
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.setState({ selects }); this.setState({ selects });
} }
this.triggerChange({ selects }); this.triggerChange({ selects });
} };
select = (obj) => { select = obj => {
var { selects } = this.state var { selects } = this.state;
const { json: { isMultiple, optionType } } = this.props const {
let valueName = this.props.json.valueName json: { isMultiple, optionType },
} = this.props;
if (optionType == "reference" && this.props.dataColumn.referenceObjId) { let valueName = this.props.json.valueName;
valueName = this.props.dataColumn.referenceCodeName
if (optionType == 'reference' && this.props.dataColumn.referenceObjId) {
valueName = this.props.dataColumn.referenceCodeName;
} }
const kk = obj[valueName] const kk = obj[valueName];
if (kk == null) { if (kk == null) {
message.error("指定的取值字段不存在或者值为空") message.error('指定的取值字段不存在或者值为空');
return return;
} }
if (!isMultiple) { if (!isMultiple) {
selects = { [kk]: { ...obj, selectKey: kk } } selects = { [kk]: { ...obj, selectKey: kk } };
} else { } else {
selects[kk] = obj; selects[kk] = obj;
selects[kk].selectKey = kk selects[kk].selectKey = kk;
} }
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.setState({ selects }); this.setState({ selects });
} }
this.triggerChange({ selects }); this.triggerChange({ selects });
};
close = i => {
var { values, labels } = this.state;
values.splice(i, 1);
labels.splice(i, 1);
}
close = (i) => {
var { values, labels } = this.state
values.splice(i, 1)
labels.splice(i, 1)
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.setState({ values, labels }); this.setState({ values, labels });
} }
this.triggerChange({ values, labels }); this.triggerChange({ values, labels });
};
}
open = () => { open = () => {
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.setState({ visiable: true }); this.setState({ visiable: true });
} }
this.triggerChange({ visiable: true }); this.triggerChange({ visiable: true });
};
}
closeModal = () => { closeModal = () => {
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.setState({ visiable: false }); this.setState({ visiable: false });
} }
const { resetSearchText } = this.props;
resetSearchText && resetSearchText();
this.triggerChange({ visiable: false }); this.triggerChange({ visiable: false });
};
}
render() { render() {
const { json: { isMultiple, sql, optionType, showTable }, dataColumn: { referenceObjId }, sqlModel, columns, dataSource } = this.props const {
let { valueName, labelName } = this.props.json json: { isMultiple, sql, optionType, showTable },
if (optionType == "reference" && referenceObjId) { dataColumn: { referenceObjId },
valueName = this.props.dataColumn.referenceCodeName sqlModel,
labelName = this.props.dataColumn.referenceNameName columns,
dataSource,
} = this.props;
let { valueName, labelName } = this.props.json;
if (optionType == 'reference' && referenceObjId) {
valueName = this.props.dataColumn.referenceCodeName;
labelName = this.props.dataColumn.referenceNameName;
} }
if (valueName == null || valueName == '') {
return <>请指定取值的列名</>;
if (valueName == null || valueName == "") {
return <>请指定取值的列名</>
} }
const { selects, visiable, labels } = this.state const { selects, visiable, labels } = this.state;
const keys = [];
const keys = []
for (let i in selects) { for (let i in selects) {
keys.push(selects[i][valueName]) keys.push(selects[i][valueName]);
} }
const columns2 = [
...columns,
const columns2 = [...columns, { {
title: "操作", title: '操作',
render: (val, record) => <a onClick={this.remove.bind(this, record.selectKey)}>移除</a> render: (val, record) => <a onClick={this.remove.bind(this, record.selectKey)}>移除</a>,
}] },
const columns3 = [...columns, { ];
title: "操作", const columns3 = [
...columns,
{
title: '操作',
render: (val, record) => render: (val, record) =>
keys.includes(record[valueName]) ? <span>已选择</span> : <a onClick={this.select.bind(this, record)}>选择</a> keys.includes(record[valueName]) ? (
}] <span>已选择</span>
) : (
<a onClick={this.select.bind(this, record)}>选择</a>
),
},
];
const custom = { const custom = {
isAll: this.state.isAll, isAll: this.state.isAll,
querys: this.state.querys, querys: this.state.querys,
sql: this.state.sql, sql: this.state.sql,
} };
// console.log(columns3) let allWidth = 0;
let allWidth = 0
if (columns3) { if (columns3) {
columns3.map((item, index) => { columns3.map((item, index) => {
if (index === columns3.length - 1) { if (index === columns3.length - 1) {
item.fixed = 'right' item.fixed = 'right';
item.width = 50 item.width = 50;
allWidth += 50 allWidth += 50;
return item return item;
} }
if (index === columns3.length - 2) { if (index === columns3.length - 2) {
allWidth += 150 allWidth += 150;
} else { } else {
if (item.width) { if (item.width) {
allWidth += item.width allWidth += item.width;
} else { } else {
item.width = 180 item.width = 180;
allWidth += 180 allWidth += 180;
} }
} }
return item return item;
}) });
} }
return ( return (
<div> <div>
{Object.keys(selects).length > 0 ? {Object.keys(selects).length > 0 ? (
showTable ? <Table rowKey={valueName} size="small" dataSource={Object.values(selects)} columns={columns2} pagination={false} /> : showTable ? (
Object.keys(selects).map((k) => <Tag key={k} closable onClose={this.remove.bind(this, k)}>{selects[k][labelName]}</Tag>) <Table
: "" rowKey={valueName}
} size="small"
dataSource={Object.values(selects)}
columns={columns2}
<Button type="primary" onClick={this.open}>选择</Button> pagination={false}
<Modal />
width={this.props.get==='mobile'?"100%":"60%"} ) : (
Object.keys(selects).map(k => (
<Tag key={k} closable onClose={this.remove.bind(this, k)}>
{selects[k][labelName]}
</Tag>
))
)
) : (
''
)}
<Button type="primary" onClick={this.open}>
选择
</Button>
{
visiable && <Modal
width={this.props.get === 'mobile' ? '100%' : '60%'}
maskClosable={false} maskClosable={false}
title={`请选择`} title={`请选择`}
visible={visiable} visible={visiable}
onOk={this.closeModal} onOk={this.closeModal}
onCancel={this.closeModal} onCancel={this.closeModal}
> >
{optionType == 'reference' ? (
{optionType == "reference" ? referenceObjId ? referenceObjId ? (
<FormList rights={this.props.rights || []} notShowBack={true} value={custom} objId={referenceObjId} isFormCom={true} isSelect={true} selects={keys} valueName={valueName} callback={this.select} sql={sql} /> <FormList
: "未关联数据对象" rights={this.props.rights || []}
: sqlModel.dataObjId ? notShowBack={true}
<FormList rights={this.props.rights || []} notShowBack={true} value={custom} objId={sqlModel.dataObjId} isFormCom={true} isSelect={true} selects={keys} valueName={valueName} callback={this.select} sql={sql} /> value={custom}
: <Table rowKey={valueName} size="small" dataSource={dataSource.list} columns={columns3} scroll={{ x: allWidth }} />} objId={referenceObjId}
isFormCom={true}
isSelect={true}
selects={keys}
valueName={valueName}
callback={this.select}
sql={sql}
/>
) : (
'未关联数据对象'
)
) : sqlModel.dataObjId ? (
<FormList
rights={this.props.rights || []}
notShowBack={true}
value={custom}
objId={sqlModel.dataObjId}
isFormCom={true}
isSelect={true}
selects={keys}
valueName={valueName}
callback={this.select}
sql={sql}
/>
) : (
<Table
rowKey={valueName}
size="small"
dataSource={dataSource.list}
columns={columns3}
scroll={{ x: allWidth }}
/>
)}
</Modal> </Modal>
</div> }
</div>
); );
} }
} }
...@@ -375,13 +375,18 @@ export default class tableCom extends Component { ...@@ -375,13 +375,18 @@ export default class tableCom extends Component {
count = []; count = [];
handleSearch = (selectedKeys, confirm) => { handleSearch = (selectedKeys, confirm) => {
confirm(); confirm();
this.setState({searchText: selectedKeys[0]}); this.setState({searchText: selectedKeys[0]});
}; };
handleReset = clearFilters => { handleReset = clearFilters => {
clearFilters(); clearFilters();
this.setState({searchText: ''}); this.resetSearchText();
};
resetSearchText = () => {
this.setState({
searchText: '',
});
}; };
getColumnSearchProps = (dataIndex, title) => ({ getColumnSearchProps = (dataIndex, title) => ({
...@@ -445,14 +450,14 @@ export default class tableCom extends Component { ...@@ -445,14 +450,14 @@ export default class tableCom extends Component {
} }
}, },
}); });
searchJson=(value,json,level,labs)=>{ searchJson = (value, json, level, labs) => {
for(var i=0;i<json.length;i++){ for (var i = 0; i < json.length; i++) {
if(json[i].value==value[level]){ if (json[i].value == value[level]) {
labs.push(json[i].label) labs.push(json[i].label)
if(json[i].children){ if (json[i].children) {
this.searchJson(value,json[i].children,level+1,labs); this.searchJson(value, json[i].children, level + 1, labs);
} }
break; break;
} }
...@@ -560,7 +565,7 @@ export default class tableCom extends Component { ...@@ -560,7 +565,7 @@ export default class tableCom extends Component {
} }
} }
dataFilter = ['Select', 'Radio', 'Checkbox','Cascader']; dataFilter = ['Select', 'Radio', 'Checkbox', 'Cascader'];
getData = (json, dataColumn, obj, init) => { getData = (json, dataColumn, obj, init) => {
...@@ -714,14 +719,14 @@ export default class tableCom extends Component { ...@@ -714,14 +719,14 @@ export default class tableCom extends Component {
break; break;
case 'func': case 'func':
if (json.funcs != null && json.funcs != '') { if (json.funcs != null && json.funcs != '') {
if(json.comName=="Cascader"){ if (json.comName == "Cascader") {
try { try {
this.getFunctionValue(json.funcs, {base52: this.props.uuid}, json, () => { this.getFunctionValue(json.funcs, {base52: this.props.uuid}, json, () => {
if (init != null && Object.keys(init).length > 0) { if (init != null && Object.keys(init).length > 0) {
let base52 = dataColumn.base52; let base52 = dataColumn.base52;
let vlu = this.props.form.getFieldValue(base52); let vlu = this.props.form.getFieldValue(base52);
const labs = []; const labs = [];
this.searchJson(vlu,this.state.options,0,labs) this.searchJson(vlu, this.state.options, 0, labs)
this.setState({labels: labs}); this.setState({labels: labs});
} else if (!this.props.isEdit && Object.keys(obj).length > 0) { } else if (!this.props.isEdit && Object.keys(obj).length > 0) {
...@@ -730,14 +735,14 @@ export default class tableCom extends Component { ...@@ -730,14 +735,14 @@ export default class tableCom extends Component {
const vlu = obj[base52]; const vlu = obj[base52];
const labs = []; const labs = [];
this.searchJson(vlu,this.state.options,0,labs) this.searchJson(vlu, this.state.options, 0, labs)
this.setState({labels: labs}); this.setState({labels: labs});
} }
}); });
} catch (e) { } catch (e) {
message.error('公式选项配置存在问题'); message.error('公式选项配置存在问题');
} }
}else{ } else {
try { try {
this.getFunctionValue(json.funcs, {base52: this.props.uuid}, json, () => { this.getFunctionValue(json.funcs, {base52: this.props.uuid}, json, () => {
if (init != null && Object.keys(init).length > 0) { if (init != null && Object.keys(init).length > 0) {
...@@ -791,9 +796,6 @@ export default class tableCom extends Component { ...@@ -791,9 +796,6 @@ export default class tableCom extends Component {
} }
} }
break; break;
} }
...@@ -2087,9 +2089,9 @@ export default class tableCom extends Component { ...@@ -2087,9 +2089,9 @@ export default class tableCom extends Component {
break; break;
case 'Cascader': case 'Cascader':
cm= <span> cm = <span>
{labels != null {labels != null
? labels.join(json.spliter?json.spliter:"") ? labels.join(json.spliter ? json.spliter : "")
: ''} : ''}
</span> </span>
break; break;
...@@ -2819,7 +2821,7 @@ export default class tableCom extends Component { ...@@ -2819,7 +2821,7 @@ export default class tableCom extends Component {
showSearch showSearch
disabled={disabled} disabled={disabled}
placeholder={json.placeholder} placeholder={json.placeholder}
style={{width: json.width}} />); style={{width: json.width}}/>);
if ( if (
get === 'mobile' && get === 'mobile' &&
((json.isMobileLabel != null && json.isMobileLabel) || ((json.isMobileLabel != null && json.isMobileLabel) ||
...@@ -2873,6 +2875,7 @@ export default class tableCom extends Component { ...@@ -2873,6 +2875,7 @@ export default class tableCom extends Component {
columns={this.state.columns} columns={this.state.columns}
dataSource={this.state.dataSource} dataSource={this.state.dataSource}
sqlModel={this.state.sqlModel} sqlModel={this.state.sqlModel}
resetSearchText={this.resetSearchText}
/>, />,
); );
if ( if (
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论