提交 adfefd92 authored 作者: 王绍森's avatar 王绍森

增加List组件

上级 fbf8b038
/**
* 国家励志奖学金
* 钟是志
* 2019年11月28日
* 因业务复杂只能特殊开发
* */
import React, { Component } from 'react';
import ApplyPage from '../index';
import { getDefaultValues } from '../../destruction';
import { message } from 'antd';
const getIndex = (arr, name) => {
return arr.findIndex((x) => {
return x.name === name;
});
};
const GJLZJXJApply = WrappedComponent => class extends Component {
diyFunction = () => {
this.instanceComponent.handleButtonSet = () => {
let that = this.instanceComponent;
const { addFields, workId, tableInfo } = that.state;
const bankNumIndex = getIndex(addFields, '工商银行卡号');
const defaultValues = getDefaultValues(addFields, tableInfo);
const beforeSubmit = (data, ModalFormComponent) => {
const bankKey = addFields[bankNumIndex].key;
if(data[bankKey] && data[bankKey].replace(/\s/g,"").length !== 19){
message.warning('请输入正确的19位工商银行卡卡号');
return false;
}
return data;
};
return [
{
type: 'add',
name: '申请',
component: 'ModalForm',
workId,
fields: addFields,
modalWidth: 800,
values: {
...defaultValues,
},
beforeSubmit,
nameSpan: { big: 6, small: 6 },
fileSpan: { big: 1, small: 1 },
},
];
};
};
componentDidMount() {
console.log(this.instanceComponent);
this.diyFunction();
}
render() {
return (
<WrappedComponent
ref={instanceComponent => this.instanceComponent = instanceComponent}
/>
);
}
};
export default KNXSRDApply(ApplyPage); // 高阶组件
/**
* 困难学生家庭情况调查-申请
* 钟是志
* 2019年11月6日
* 因业务复杂只能特殊开发
* */
import React, { Component } from 'react';
import ApplyPage from '../index';
import { getDefaultValues } from '../../destruction';
import { deepCopy } from '@/baseComponent/utils';
const getIndex = (arr, name) => {
return arr.findIndex((x) => {
return x.name === name;
});
};
const KNXSJTQKSQ = WrappedComponent => class extends Component {
diyFunction = () => {
this.instanceComponent.handleButtonSet = () => {
let that = this.instanceComponent;
const { addFields, workId, tableInfo } = that.state;
const familyTypeIndex = getIndex(addFields, '家庭类型');
const fileIndex = getIndex(addFields, '家庭类型证明材料');
const famliyMemberIndex = getIndex(addFields, '家庭成员(不含自己)');
const famliyMoneyIndex = getIndex(addFields, '家庭人均年收入(元)');
const familyNumberIndex = getIndex(addFields, '家庭人口数');
const defaultValues = getDefaultValues(addFields, tableInfo);
const diyFormStateChange = (value, key, ModalFormComponent) => {
let oldValue = ModalFormComponent.state.formValues;
if (typeof value === 'object') {
oldValue[key] = deepCopy(value);
} else {
oldValue[key] = value;
}
if (familyTypeIndex >= 0 && key === addFields[familyTypeIndex].key) { // 改变家庭类型时.
let testOne = value.substring(0, 1);
if ([2, 3, 4, 5, 6, 7].indexOf(Number(testOne)) > -1) {
// 如果学生勾选了项目234567,就必须要上传附件;
addFields[fileIndex].required = true;
} else {
addFields[fileIndex].required = false;
}
that.setState({ addFields });
}
if (famliyMemberIndex >= 0 && key === addFields[famliyMemberIndex].key) { // 改变家庭成员时
let money = 0;
const famliyMemberFileds = addFields[famliyMemberIndex].componentProps.thisFields;
const onePersonIndex = getIndex(famliyMemberFileds, '年收入(元)');
for (let item of value) {
money = money + item[famliyMemberFileds[onePersonIndex].key];
}
oldValue[addFields[famliyMoneyIndex].key] = parseInt(money / (value.length + 1 ), 10); // 计算家庭平均年收入
oldValue[addFields[familyNumberIndex].key] = value.length + 1; // 计算家庭人数
}
ModalFormComponent.setState({
formValues: oldValue,
});
};
return [
{
type: 'add',
name: '申请',
component: 'ModalForm',
diyFormStateChange,
workId,
fields: addFields,
modalWidth: 800,
values: {
...defaultValues,
},
nameSpan: { big: 6, small: 6 },
fileSpan: { big: 1, small: 1 },
},
];
};
};
componentDidMount() {
console.log(this.instanceComponent);
this.diyFunction();
}
render() {
return (
<WrappedComponent
ref={instanceComponent => this.instanceComponent = instanceComponent}
/>
);
}
};
export default KNXSJTQKSQ(ApplyPage); // 高阶组件
/**
* 困难学生申请
* 钟是志
* 2019年11月6日
* 因业务复杂只能特殊开发
* */
import React, { Component } from 'react';
import ApplyPage from '../index';
import { getDefaultValues } from '../../destruction';
import { message } from 'antd';
const getIndex = (arr, name) => {
return arr.findIndex((x) => {
return x.name === name;
});
};
const KNXSRDApply = WrappedComponent => class extends Component {
diyFunction = () => {
this.instanceComponent.handleButtonSet = () => {
let that = this.instanceComponent;
const { addFields, workId, tableInfo } = that.state;
const bankNumIndex = getIndex(addFields, '工商银行卡号');
const defaultValues = getDefaultValues(addFields, tableInfo);
const beforeSubmit = (data, ModalFormComponent) => {
const bankKey = addFields[bankNumIndex].key;
if(data[bankKey] && data[bankKey].replace(/\s/g,"").length !== 19){
message.warning('请输入正确的19位工商银行卡卡号');
return false;
}
return data;
};
return [
{
type: 'add',
name: '申请',
component: 'ModalForm',
workId,
fields: addFields,
modalWidth: 800,
values: {
...defaultValues,
},
beforeSubmit,
nameSpan: { big: 6, small: 6 },
fileSpan: { big: 1, small: 1 },
},
];
};
};
componentDidMount() {
console.log(this.instanceComponent);
this.diyFunction();
}
render() {
return (
<WrappedComponent
ref={instanceComponent => this.instanceComponent = instanceComponent}
/>
);
}
};
export default KNXSRDApply(ApplyPage); // 高阶组件
差异被折叠。
/**
* 事务页面。 根据一站式服务大厅的事务接口。达到增删发起事务流程
* 2019年10月23日 09:48:13
* 钟是志
*
* */
import { message } from 'antd';
import React, { Fragment } from 'react';
import * as service from '../publicApiService';
import * as destructionFunc from '../destruction';
import { Link, hashHistory } from 'dva/router';
import { getDefaultValues } from '../destruction';
import { getApplyPage } from '../publicApiService';
import { getHuanGeToken } from '@/utils/authority';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import List from './List';
import pageSetting from './pageSetting';
import ButtonDiy from '@/baseComponent/ButtonDiy';
import Shell from '@/baseComponent/Shell';
import config from '@/config/config';
// import test from './2333';
export default class AffairPage extends React.Component {
constructor(props) {
super(props);
// const idObj = service.getId();
if (!idObj) {
message.error('没有配置数据id,无法使用该功能');
}
this.state = {
showIframe: false,
columns: [],
workId: idObj.workId,
searchCondition: [],
dataBaseId: idObj.dataBaseId,
addFields: [], // 新增时填写的字段。
};
};
getFormDetail = (workId) => {
service.getFormDetail(workId).then((response) => {
if (typeof response.unifiedServicePatternModel === 'undefined') {
return false;
}
destructionFunc.destructionGetDetail(response).then((x) => {
const { addFields, tableInfo, allConfigSetInfo } = x;
this.setState({
addFields,
tableInfo,
allConfigSetInfo,
}, () => {
this.giveDetailColumns();
});
});
});
};
giveDetailColumns = () => {
const { columns, workId, dataBaseId, addFields } = this.state;
columns.push(
{
dataIndex: 'operation',
title: '操作',
fixed: columns.length > 12 ? 'right' : false,
render: (text, record) => {
return (<Link to={
{
pathname: './Detail',
state: {
workId,
dataBaseId,
record,
addFields,
},
}}>
详情
</Link>);
},
},
);
this.setState({
columns,
});
};
handleButtonSet = () => {
return [
{
type: 'add',
name: '申请',
component: 'Normal',
handleClick: () => {
this.setState({
showIframe: true,
}, () => {
});
},
},
];
};
handleSearchSet = () => {
const { columns, searchCondition } = this.state;
const pageSearch = {
search: {
field: {},
getPageService: getApplyPage,
responseCallBack: (response) => {
return response;
},
condition: searchCondition,
nameSpan: { big: 8, small: 9 },
fileSpan: { big: 4, small: 4 },
},
tableRowKey: 'id',
columns,
};
return pageSearch;
};
componentDidMount() {
if (!getHuanGeToken()) {
message.error('您的数据未同步,请联系管理员!');
return false;
}
const { workId } = this.state;
service.getColumns(workId).then((response) => {
if (response) {
this.setState({
columns: response,
}, () => {
this.getFormDetail(workId);
});
}
});
window.addEventListener('message', (event) => {
if (event.data === 'returnList') {
this.setState({
showIframe: false,
}, () => {
this.ListComponent.getPage();
});
}
if(event.data.indexOf('iframeHeight') > -1){
let height = Number(event.data.split('-')[1]);
document.getElementById('applyIframeId').height = height;
}
}, false);
return true;
}
render() {
const { workId, dataBaseId, addFields, showIframe } = this.state;
const url = config.onestopPC.split('/#/');
let iframeUrl = `${url[0]}/#/IFrameForApply?id=${workId}&token=${getHuanGeToken()}`;
// iframeUrl = `http://localhost:8000/onestop/IFrameForApply?id=${workId}&token=${getHuanGeToken()}`;
return (
<PageHeaderWrapper title="">
<div style={{
display: showIframe ? 'none' : 'block',
}}>
<List listConfig={pageSetting.listConfig}
pageButton={this.handleButtonSet({})}
pageSearch={this.handleSearchSet({})}
addFields={addFields}
ref={ListComponent => this.ListComponent = ListComponent}
workId={workId}
dataBaseId={dataBaseId}
/>
</div>
<div style={{
visibility: showIframe ? 'visible' : 'hidden',
width: '100%',
backgroundColor: '#fff',
paddingLeft: '24px',
}}>
<Shell>
<div style={{
height: '54px',
padding: '12px 0 12px 12px',
display: showIframe ? 'block' : 'none',
}}>
<ButtonDiy name="返回"
className="defaultBlue"
handleClick={() => {
this.setState({
showIframe: false,
});
}}
icon="arrow-left"
/>
</div>
</Shell>
<iframe src={iframeUrl}
frameBorder={0}
id='applyIframeId'
name='applyIframe'
marginWidth="0"
marginHeight="0"
allowTransparency="yes"
seamless
scrolling={'no'}
style={{
width: '100%',
minHeight: '800px',
overflowY: 'hidden',
backgroundColor: '#fff',
}}
/>
</div>
</PageHeaderWrapper>
);
}
}
const pageSetting = {
type: 'list', // 页面类型 list列表 可能包含有其他类型的 比如 detail 详情 add 新增 update 更新 等等 ....
listConfig:{
selectRows: true, // 是否可以行选择,
paging: true, // 是否可以分页,
searchArea: false, // 是否拥有 搜索区dom,
buttonArea: true, // 是否拥有 按钮区,
}
};
export default pageSetting;
import pageSetting from './pageSetting';
import React, { Component, Fragment } from 'react';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import List from '../ApplyPage/List';
import ListTab from './ListTab';
import { deepCopy } from '@/baseComponent/utils';
import { getApplyPage, getHandledPage, getWaitPage } from '@/pages/App/FormInsertDiy/AffairPage/publicApiService';
export default class AuditPage extends Component {
constructor(props) {
super(props);
this.state={
}
};
componentDidMount(){
}
handleButtonSet = () => {
const { addFields, workId } = this.props;
return {
tab1: [
],
tab2: [],
};
};
handleSearchSet = () => {
const { columns, searchCondition} = this.props;
const tab1 = {
search: {
field: {
},
getPageService: getWaitPage,
responseCallBack: (response) => {
return response;
},
condition: searchCondition,
nameSpan: { big: 8, small: 9 },
fileSpan: { big: 4, small: 4 },
},
tableRowKey: 'id',
columns,
};
const tab2 = {
search: {
field: {
},
getPageService: getHandledPage,
responseCallBack: (response) => {
return response;
},
condition: searchCondition,
nameSpan: { big: 8, small: 9 },
fileSpan: { big: 4, small: 4 },
},
tableRowKey: 'id',
columns,
};
return {
tab1,
tab2,
};
};
render() {
const { workId, dataBaseId, addFields } = this.props;
return (
<PageHeaderWrapper title="">
<ListTab tabList={pageSetting.tabList}
pageButton={this.handleButtonSet({
})}
workId={workId}
dataBaseId={dataBaseId}
addFields={addFields}
pageSearch={this.handleSearchSet({
})}/>
</PageHeaderWrapper>
);
}
}
差异被折叠。
import React, { Component, Fragment } from 'react';
import { Tabs } from 'antd';
import styles from '@/baseComponent/index.less';
import PropTypes from 'prop-types';
import Shell from '@/baseComponent/Shell';
import List from './List';
const TabPane = Tabs.TabPane;
export default class ListTab extends Component {
constructor(props) {
super(props);
const { tabList } = this.props;
const tabKeys = Object.keys(tabList);
this.state = {
activeKey: tabKeys[0],
tabKeys: tabKeys,
};
}
handleChangeTab = (activeKey) => {
this.setState({
activeKey: '-111111',
},()=>{
setTimeout(()=>{
this.setState({
activeKey: activeKey,
})
} ,30);
});
};
render() {
const { tabList, pageSearch, pageButton, workId, dataBaseId, addFields } = this.props;
const { activeKey, tabKeys } = this.state;
return (
<Fragment>
<Shell>
<Tabs activeKey={activeKey}
className={styles.ListTab}
onChange={this.handleChangeTab}>
{tabKeys.map((item) => {
return <TabPane tab={tabList[item].name} key={item}>
</TabPane>
})}
</Tabs>
</Shell>
{tabKeys.map((item) => {
return activeKey === item ?
<List listConfig={tabList[item].listConfig}
key={item}
workId={workId}
addFields={addFields}
dataBaseId={dataBaseId}
pageSearch={pageSearch[item]}
pageButton={pageButton[item]}
/> : null;
})}
</Fragment>
);
}
}
ListTab.propTypes = {};
ListTab.defaultProps = {};
/**
* 事务页面。 根据一站式服务大厅的事务接口。达到增删发起事务流程
* 2019年10月23日 09:48:13
* 钟是志
*
* */
import { Row, Col, message } from 'antd';
import React, { Fragment } from 'react';
import * as service from '../publicApiService';
import AuditPage from './AuditPage';
import * as destructionFunc from '../destruction';
import { Link ,hashHistory} from 'dva/router';
export default class Index extends React.Component {
constructor(props) {
super(props);
// const idObj = service.getId();
if (!idObj) {
message.error('没有配置数据id,无法使用该功能');
}
this.state = {
columns: [],
dataList: [],
headerInfo: [],
workId: idObj.workId,
searchCondition: [],
dataBaseId: idObj.dataBaseId,
addCondition: [],
addFields: [], // 新增时填写的字段。
tableInfo: {}, // 表格配置属性
allConfigSetInfo: {}, // getFormDetail 返回的数据
};
};
getFormDetail = (workId) => {
const { dataBaseId } = this.state;
/*service.getQueryCondition(dataBaseId).then((response) => {
this.setState({searchCondition: response})
});*/
service.getFormDetail(workId).then((response) => {
if (typeof response.unifiedServicePatternModel === 'undefined') {
return false;
}
destructionFunc.destructionGetDetail(response).then((x) => {
const { addFields, tableInfo, allConfigSetInfo } = x;
this.setState({
addFields,
tableInfo,
allConfigSetInfo,
},() => {
this.giveDetailColumns();
});
});
});
};
giveDetailColumns = () =>{
const { columns, workId, dataBaseId, addFields, tableInfo } = this.state;
columns.push(
{
dataIndex: 'operation',
title: '操作',
fixed: columns.length > 12 ? 'right' : false,
render: (text, record) => {
return ( <Link to={
{
pathname: "./Detail",
state: {
workId,
dataBaseId,
record,
addFields,
tableInfo
},
}}>
详情
</Link> );
},
},
);
this.setState({
columns,
})
};
componentDidMount() {
const { workId, dataBaseId, addFields } = this.state;
service.getColumns(workId).then((response) => {
if (response && response.length) {
this.setState({
columns: response, // 表头
},()=>{
this.getFormDetail(workId);
});
}
});
}
render() {
const { workId, dataBaseId, columns, searchCondition, addFields, allConfigSetInfo, tableInfo } = this.state;
return (
<AuditPage
workId={workId}
dataBaseId={dataBaseId}
columns={columns}
addFields={addFields}
tableInfo={tableInfo}
allConfigSetInfo={allConfigSetInfo}
searchCondition={searchCondition}
/>
);
}
}
const pageSetting = {
type: 'listTab', // 页面类型
tabList: {
tab1:{
name:'待处理',
listConfig:{
selectRows: true, // 是否可以行选择,
paging: true, // 是否可以分页,
searchArea: false, // 是否拥有 搜索区dom,
buttonArea: true, // 是否拥有 按钮区,
}
},
tab2:{
name:'已处理',
listConfig:{
selectRows: true, // 是否可以行选择,
paging: true, // 是否可以分页,
searchArea: false, // 是否拥有 搜索区dom,
buttonArea: true, // 是否拥有 按钮区,
}
},
},
};
export default pageSetting;
/**
* 赖井平
* 2019年3月2日
* 用于 批量弹窗操作
* */
import ButtonDiy from '@/baseComponent/ButtonDiy';
import ModalDiy from '@/baseComponent/ModalDiy';
import FormArray from '../component/FormArray';
import React, { Component, Fragment } from 'react';
import { checkDate } from '@/baseComponent/utils';
import { message } from 'antd';
import PropTypes from 'prop-types';
export default class ModalBatch extends Component {
constructor(props) {
super(props);
const { values } = this.props;
this.state = {
showModal: false,
formValues: { ...values }, // 将默认值传进去 用于新增时可能遇到的需要传值的情况
};
}
componentWillUnmount() {
}
changeShow = () => {
const { beforeShowModel, selectRows, initFormValues } = this.props;
const { formValues, showModal } = this.state;
if (!selectRows.length && !this.state.showModal) {
message.warning('请至少选择一条数据');
return false;
}
if(initFormValues && !showModal){
initFormValues(selectRows,formValues).then((response)=>{
this.setState({
formValues: response ,
},()=>{
//console.log(this.state.formValues);
})
});
}
/**
* 设置modal是否显示
* */
let flag;
if (!showModal && beforeShowModel) {
beforeShowModel(this.props, ({ text, type, isNotShow }) => {
flag = isNotShow;
if (isNotShow && text) {
message[type](text);
}
});
}
if (flag) {
return false;
}
/**
* 设置modal是否显示
* */
this.clearData();
this.setState({
showModal: !showModal,
});
};
formStateChange = (value, key) => {
let oldValue = this.state.formValues;
oldValue[key] = value;
this.setState({
formValues: oldValue,
});
};
clearData = () => {
const { values, giveDefaultValue, selectRows} = this.props;
let formValues = {
...values,
};
if(giveDefaultValue){
formValues = giveDefaultValue(selectRows,formValues);
}
this.setState({
formValues,
});
};
handleOk = () => {
let { formValues } = this.state;
let param = { ...formValues };
const { fields, url, responseCallBack, getPage,
beforeSubmit, selectRows, postKey, sourceKey,
handleSelectRows, apiServiceApi } = this.props;
for (let item of fields) {
if (item.required && !formValues[item.key] && formValues[item.key] !== 0) {
message.warning(`${item.name}是必填项,请填写`);
return false;
}
/**
* 校验开始时间必须在结束时间之前
* */
if (item.rule && item.rule === 'mustAfterStart') {
const check = checkDate(formValues[item.key], formValues[item.checkKey]);
if (!check) {
message.warning(`${item.name}必须在${item.checkKeyName}之后`);
return false;
}
}
}
param[postKey] = selectRows.map((item) => {
return item[sourceKey];
});
if (beforeSubmit) {
let postData = beforeSubmit(this.props, formValues);
param = {
...param,
...postData,
};
}
apiServiceApi(param).then((response) => {
if (response) {
if (responseCallBack && !responseCallBack(response)) {
this.changeShow();
return false;
} else {
handleSelectRows([]);
message.success('保存成功');
this.changeShow();
getPage();
}
} else {
this.changeShow();
return false;
}
});
};
render() {
const { showModal, formValues } = this.state;
const { name, className, fields, nameSpan, fileSpan } = this.props;
return (
<Fragment>
<ButtonDiy name={name}
className={className}
handleClick={this.changeShow}/>
{showModal ?
<ModalDiy handleOk={this.handleOk}
title={name}
handleCancel={this.changeShow}
>
<FormArray config={fields}
value={formValues}
changeValue={this.formStateChange}
nameSpan={nameSpan}
fileSpan={fileSpan}
style={{ paddingTop: '0px' }}
/>
</ModalDiy> : null}
</Fragment>);
}
}
ModalBatch.propTypes = {
name: PropTypes.string, // 按钮名称和 弹窗的标题
className: PropTypes.string, // 按钮样式
fields: PropTypes.array.isRequired, // 填写的字段的配置
values: PropTypes.object, // 如果有默认参数 则在页面的业务逻辑中传进来
url: PropTypes.string.isRequired, // 接口url
responseCallBack: PropTypes.func, // 接口返回数据检查
getPage: PropTypes.func, // 刷新页面的方法
nameSpan: PropTypes.object, // 页面排版
fileSpan: PropTypes.object, // 页面排版
};
ModalBatch.defaultProps = {
name: '新增',
className: 'primaryBlue',
values: {},
sourceKey: 'id',
postKey: 'ids',
selectRows: [],
url: 'asdasd/asdasd',
responseCallBack: (response) => {
return !!response;
},
/*beforeShowModel: (props, callback) => {
},*/
nameSpan: { big: 4, small: 4 },
fileSpan: { big: 1, small: 1 },
};
/**
* 钟是志
* 2019年2月26日
* 用于 弹出提示信息 确认用户是否执行XXX操作
* 一个按钮 + 点击按钮显示的提示
* 点确定 调接口->关闭弹窗 刷新页面
* */
import ButtonDiy from '@/baseComponent/ButtonDiy';
import React, { Component, Fragment } from 'react';
import { message, Modal } from 'antd';
import PropTypes from 'prop-types';
import * as service from '@/highOrderComponent/Service';
export default class ModalConfirm extends Component {
handleConfirm = () => {
const { selectRows,name, contentSentence, onlyOne, checkSelectRow, noNeedCheckSelect,listData } = this.props;
if(typeof noNeedCheckSelect === 'undefined' && !selectRows.length){
message.warning('请至少选择一条数据');
return false;
}
if(onlyOne && selectRows.length > 1){
message.warning('只能选择一条数据进行操作');
return false;
}
if(checkSelectRow){
let res = checkSelectRow(selectRows, listData);
if(res && res.result === false){
message.warning(res.info);
return false;
}
}
Modal.confirm({
title: name,
content: contentSentence,
onOk: this.handleOk,
okText: '确定',
cancelText: '取消',
});
};
handleOk = () => {
const { selectRows, postKey, sourceKey, url,
responseCallBack, getPage,fields,formValues,
beforeUpdate,search } = this.props;
let data = {};
if(fields){
data = {...fields};
}
data[postKey] = selectRows.map( (item) => {
return item[sourceKey];
});
data[postKey] = data[postKey].join(',');
if(beforeUpdate){
data = beforeUpdate(data,selectRows,formValues,search);
}
service.addOrUpdate(data,url).then((response) => {
if(responseCallBack && !responseCallBack(response)){
return false;
}
if(!response){
return false;
}else{
message.success('操作成功');
getPage();
}
});
};
render() {
const { name, className } = this.props;
return (
<Fragment>
<ButtonDiy name={name}
className={className}
handleClick={this.handleConfirm}/>
</Fragment>);
}
}
ModalConfirm.propTypes = {
name: PropTypes.string, // 按钮名称和 弹窗的标题
selectRows: PropTypes.array.isRequired, // 选择的数据.数组类型
className: PropTypes.string, // 按钮样式
sourceKey: PropTypes.string.isRequired, // 通过什么字段删除
postKey: PropTypes.string, // 提交的字段名.
url: PropTypes.string.isRequired, // 接口url
responseCallBack: PropTypes.func, // 接口返回数据检查
getPage: PropTypes.func.isRequired, // 刷新页面的方法
};
ModalConfirm.defaultProps = {
name: '一键审核通过',
className: 'defaultBlue',
url: 'asdasd/asdasd',
contentSentence: '您确认xxxxx吗?',
sourceKey: 'id',
postKey: 'ids',
selectRows: [],
responseCallBack: (response)=>{
return !!response;
},
};
/**
* 钟是志
* 2019年2月26日
* 用于 弹出提示信息 确认用户是否删除数据
* 一个删除按钮 + 点击按钮显示的提示
* 点确定 调接口->关闭弹窗 刷新页面
* */
import ButtonDiy from '@/baseComponent/ButtonDiy';
import React, { Component, Fragment } from 'react';
import { message, Modal } from 'antd';
import PropTypes from 'prop-types';
import * as service from '@/highOrderComponent/Service';
export default class ModalDelete extends Component {
handleDelete = () => {
const { selectRows, checkBeforeDelete, cannotDeleteSentence, deleteSentence} = this.props;
if(!selectRows.length){
message.warning('请选择你要删除的数据');
return false;
}
if(checkBeforeDelete){
const check = checkBeforeDelete(selectRows);
if(!check){
if(cannotDeleteSentence){
message.warning(cannotDeleteSentence);
return false;
}else{
message.warning('数据关联,不能删除');
return false;
}
}
}
Modal.confirm({
title: '删除',
content: deleteSentence || `你确定要删除吗?`,
onOk: this.handleOk,
okText: '确认',
cancelText: '取消',
});
};
handleOk = () => {
const { selectRows, postKey, sourceKey, url, responseCallBack, getPage } = this.props;
const data = {};
data[postKey] = selectRows.map( (item) => {
return item[sourceKey];
});
data[postKey] = data[postKey].join(',');
service.deleteData(data,url).then((response) => {
if(!response){
getPage();
}
if(responseCallBack && !responseCallBack(response)){
return false;
}else{
message.success('删除成功');
getPage();
}
});
};
render() {
const { name, className } = this.props;
return (
<Fragment>
<ButtonDiy name={name}
className={className}
handleClick={this.handleDelete}/>
</Fragment>);
}
}
ModalDelete.propTypes = {
name: PropTypes.string, // 按钮名称和 弹窗的标题
selectRows: PropTypes.array.isRequired, // 选择的数据.
className: PropTypes.string, // 按钮样式
sourceKey: PropTypes.string.isRequired, // 通过什么字段删除
postKey: PropTypes.string, // 提交的字段名. ids
url: PropTypes.string.isRequired, // 接口url
responseCallBack: PropTypes.func, // 接口返回数据检查
getPage: PropTypes.func, // 刷新页面的方法
checkBeforeDelete: PropTypes.func, // 在删除前对数据进行检查 如果返回false 则不能删除数据
};
ModalDelete.defaultProps = {
name: '删除',
className: 'defaultRed',
url: 'asdasd/asdasd',
deleteKey: 'id',
postKey: 'ids',
selectRows: [],
responseCallBack: (response)=>{
return !!response;
},
};
/**
* 钟是志
* 2019年2月26日
* 用于 新增弹出modal
* 一个按钮 + 点击按钮显示的弹窗
* 弹窗中包含一个表单 并填写数据后点确定 调接口->关闭弹窗 刷新页面
* */
import ButtonDiy from '@/baseComponent/ButtonDiy';
import ModalDiy from '@/baseComponent/ModalDiy';
import React, { Component, Fragment } from 'react';
import { deepCopy, } from '@/baseComponent/utils';
import { mustHaveValue } from '../../config/index';
import { message } from 'antd';
import PropTypes from 'prop-types';
import { startProcess } from '../publicApiService';
import { transLateTimeTOUnix } from '@/pages/App/FormInsertDiy/config';
import FormArray from '../component/FormArray';
export default class ModalForm extends Component {
constructor(props) {
super(props);
const { values } = this.props;
this.state={
showModal: false,
formValues: { ...values }, // 将默认值传进去 用于新增时可能遇到的需要传值的情况
requireOtherFiled:{}
};
}
componentWillUnmount(){
}
changeShow = () => {
const { showModal } = this.state;
this.clearData();
this.setState({
showModal: !showModal,
});
};
formStateChange = (value, key) => {
const {diyFormStateChange} = this.props;
if(diyFormStateChange){
return diyFormStateChange(value, key, this);
}
let oldValue = this.state.formValues;
if(typeof value === 'object'){
oldValue[key] = deepCopy(value);
}else{
oldValue[key] = value;
}
this.setState({
formValues: oldValue,
});
};
clearData = () => {
const { values } = this.props;
this.setState({
formValues: {...values},
});
};
handleOk = () => {
let { formValues} = this.state;
const { fields, url, responseCallBack, getPage, beforeSubmit, workId, seriousOptions } = this.props;
if(!mustHaveValue(fields,formValues)){
return false;
}
let data = {
...formValues,
};
for(let item of fields){
if(data[item.key]){
data[item.key] = transLateTimeTOUnix(data[item.key], item.dataType);
}
if(data[item.endKey]){
data[item.endKey] = transLateTimeTOUnix(data[item.endKey], item.dataType);
}
}
if(beforeSubmit){
data = beforeSubmit(data,this);
if(!data){
return false;
}
}
const postData = {
content: JSON.stringify(data),
appId: workId,
};
if(seriousOptions && seriousOptions.length){
postData.level = seriousOptions[0].key;
}
startProcess(postData).then((response) => {
if(!responseCallBack(response)){
this.changeShow();
return false;
}else{
message.success('保存成功');
getPage();
this.changeShow();
}
})
};
render() {
const { showModal, formValues } = this.state;
const { name, className, fields, nameSpan, fileSpan, icon ,modalWidth} = this.props;
return (
<Fragment>
<ButtonDiy name={name}
className={className}
icon={icon}
handleClick={this.changeShow}/>
{showModal ?
<ModalDiy handleOk={this.handleOk}
title={name}
handleCancel={this.changeShow}
width={modalWidth}
>
<FormArray config={fields}
value={formValues}
changeValue={this.formStateChange}
nameSpan={nameSpan}
fileSpan={fileSpan}/>
</ModalDiy> : null}
</Fragment>);
}
}
ModalForm.propTypes = {
name: PropTypes.string, // 按钮名称和 弹窗的标题
className: PropTypes.string, // 按钮样式
fields: PropTypes.array.isRequired, // 填写的字段的配置
values: PropTypes.object, // 如果有默认参数 则在页面的业务逻辑中传进来
url: PropTypes.string.isRequired, // 接口url
icon: PropTypes.string, // 按钮图标
responseCallBack: PropTypes.func, // 接口返回数据检查
getPage: PropTypes.func, // 刷新页面的方法
nameSpan: PropTypes.object, // 页面排版
fileSpan: PropTypes.object, // 页面排版
};
ModalForm.defaultProps = {
name: '新增',
className: 'primaryBlue',
values: {},
url: 'asdasd/asdasd',
responseCallBack: (response)=>{
return !!response;
},
getPage: () => {
},
nameSpan: {big: 5, small: 5 },
fileSpan: {big: 1, small: 1 },
};
import ButtonDiy from '@/baseComponent/ButtonDiy';
import React, { Component, Fragment } from 'react';
/*
import ExportInfo from '@/components/App/ExportInfo';
import ImportUtil from '@/components/App/ImportUtil';
import ModalDelete from './ModalDelete';
import ModalConfirm from './ModalConfirm';
*/
import ModalBatch from './ModalBatch';
import ModalForm from './ModalForm';
export default class ButtonListDom extends Component {
render() {
const { config, getPage, selectRows, formValues, children, search,listData } = this.props;
return (<div style={{ height: '50px', padding: '12px 0 12px 12px', positon:'relative'}}>
{config.map((item, i) => {
switch (item.component) {
case 'ModalForm': // 新增按钮 + 弹窗
return <ModalForm {...item}
key={item.type}
getPage={getPage}
selectRows={selectRows}
/>;
/* case 'ModalDelete': // 删除按钮
return <ModalDelete {...item}
key={item.type}
getPage={getPage}
selectRows={selectRows}
/>;
case 'ImportUtil': // 导入
return <ImportUtil {...item.props}
key={item.type}
callback={() => getPage()}
/>;
case 'ExportInfo': // 导出
return <ExportInfo {...item.props}
key={item.type}
/>;
case 'ModalConfirm': // 一般按钮 点击后弹出是否确定的 Modal Info
return <ModalConfirm key={item.type}
{...item}
getPage={getPage}
listData={listData}
formValues={formValues}
search={search}
selectRows={selectRows}/>;
*/
case 'ModalBatch': // 一般按钮 点击后弹出 填写一些类似 审核理由 意见之类的信息
return <ModalBatch key={item.type}
{...item}
handleSelectRows={this.props.handleSelectRows}
getPage={getPage}
selectRows={selectRows}/>;
case 'OpenUrl': // 点击按钮 打开一个新窗口
return window.open(item.url);
case "Normal":
return(
<ButtonDiy name={item.name}
key={item.type}
className={item.className || 'defaultBule'}
handleClick={() => {item.handleClick(selectRows, formValues, getPage,search)}}
/>
);
case 'RenderComponent':
return item.render({
name: item.name,
selectRows,
formValues,
getPage,
search,
listData
});
default:
break;
// return <ButtonDiy></ButtonDiy>;
}
})}
<span style={{display:'inline-block'}}>{children}</span>
</div>);
}
}
import React, { Fragment, Component } from 'react';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import Shell from '@/baseComponent/Shell';
import BlockTitle from '@/baseComponent/BlockTitle';
import ButtonDiy from '@/baseComponent/ButtonDiy';
import router from 'umi/router';
import FormArray from './component/FormArray';
import { getDetailInfo, handleAudit } from '@/pages/App/FormInsertDiy/AffairPage/publicApiService';
import { isJSON } from '@/baseComponent/utils';
import { Col, Row, Timeline, Icon, Tabs } from 'antd';
import ModalBatch from './ButtonListDom/ModalBatch';
import FlowImg from './component/FlowImg';
import { getHuanGeToken } from '@/utils/authority';
import config from '@/config/config';
const { TabPane } = Tabs;
/*
export default class Detail extends Component {
/!**
* workId,dataBaseId,record,addFields
* *!/
constructor(props) {
super(props);
this.state = {
detailInfo: {
content: {},
taskInfo: [],
},
show: false,
};
}
componentDidMount() {
const { state } = this.props.location;
const { record } = state;
getDetailInfo(record.id).then((x) => {
if (x) {
if (isJSON(x.content)) {
x.content = JSON.parse(x.content);
}
if(typeof x.content === 'object' && x.content.defaultValues){
for(let z in x.content.defaultValues){
x.content = {
...x.content,
...x.content.defaultValues[z],
}
} }
this.setState({
detailInfo: x,
show: true,
});
}
});
}
buttonDom = () => {
const { detailInfo } = this.state;
const { btns } = detailInfo;
let res = [];
if(typeof btns !== 'undefined' && Array.isArray(btns)){
for(let z of btns){
res.push(
{
type: z.name,
name: z.name,
component: 'ModalBatch',
className: z.name !== '通过' ? 'defaultRed' : 'defaultBlue',
nameSpan: { big: 4, small: 5 },
fileSpan: { big: 1, small: 1 },
values: {
[z.key]: z.value,
},
fields: [
{
key: 'reason',
name: '审核意见',
type: 'textarea',
},
],
beforeSubmit: (props, formValues) => {
return {
taskForm : {},
examineMap: JSON.stringify(formValues),
};
},
sourceKey: 'taskId',
postKey: 'taskIds',
apiServiceApi: handleAudit,
}
)
}
return res;
}
return [];
};
render() {
const { state } = this.props.location;
const { record, addFields, workId } = state;
const { detailInfo, show } = this.state;
const Btns = this.buttonDom();
const dot1 = <Icon type={'check-circle'}
style={{ fontSize: '16px', color: 'rgb(82, 196, 26)' }}/>;
const dot2 = <Icon type={'clock-circle-o'}
style={{ fontSize: '16px', color: 'red' }}/>;
if(!show){
return null;
}
return (<PageHeaderWrapper title="">
<Shell>
<div style={{ height: '54px', padding: '12px 0 12px 12px' }}>
<ButtonDiy name="返回"
className="defaultBlue"
icon="arrow-left"
handleClick={() => {
router.goBack();
}}
/>
{
Btns.map((item)=>{
return <ModalBatch key={item.type}
{...item}
handleSelectRows={()=>{console.log('清空')}}
getPage={()=>{router.goBack()}}
selectRows={[record]}/>
})
}
</div>
</Shell>
<Shell>
<BlockTitle
isSmall={true}
title={'申请信息'}
/>
<Row>
<Col span={20}>
<FormArray config={addFields}
value={detailInfo.content}
changeValue={() => {
console.log(xxx);
}}
disabled={true}
readOnly={true}
fileSpan={{ big: 2, small: 2 }}
nameSpan={{ big: 6, small: 7 }}
/>
</Col>
</Row>
</Shell>
<Shell>
<Tabs>
<TabPane tab={'审批状态'} key={'1'}>
<Row>
<Col span={16} offset={2} style={{paddingTop: '30px', paddingBottom: '30px'}}>
<Timeline>
{
detailInfo.taskInfo.map((item) => {
let reason = item.respdesc;
if(item.taskVariable && item.taskVariable.reason){
reason = item.taskVariable.reason;
}
return (
<Timeline.Item dot={item.endTime ? dot1 : dot2}
key={item.id}
>
{item.assignee ? <p><b>{item.assignee}</b></p> : <p>&nbsp; </p>}
<p>审批流程: {item.name}</p>
<p>审批状态: {item.status}</p>
<p>审批原因: {reason}</p>
</Timeline.Item>
);
})
}
</Timeline>
</Col>
</Row>
</TabPane>
<TabPane tab={'流程图'} key={'2'}>
<FlowImg id={workId}/>
</TabPane>
</Tabs>
</Shell>
</PageHeaderWrapper>)
;
}
}*/
export default class Detail extends Component{
constructor(props){
super(props);
const { state } = this.props.location;
let id = '';
if(state && state.record && state.record.id){
const { record } = state;
id = record.id;
}
this.state={
id,
};
}
componentDidMount(){
window.addEventListener('message', (event) => {
if(event.data.indexOf('iframeDetailHeight') > -1){
let height = Number(event.data.split('-')[1]);
document.getElementById('detailIframeId').height = height;
}
}, false);
}
showAll = () => {
this.setState({
showAll: true,
});
};
render(){
const { id, showAll } = this.state;
const url = config.onestopPC.split('/#/');
let iframeUrl = `${url[0]}/#/IframeForDetail?id=${id}&token=${getHuanGeToken()}`;
// iframeUrl = `http://localhost:8000/onestop/IframeForDetail?id=${id}&token=${getHuanGeToken()}`;
return (
<PageHeaderWrapper title="">
<Shell>
<div style={{
height: '54px',
padding: '12px 0 12px 12px',
}}>
{
showAll ?
<ButtonDiy name="返回"
className="defaultBlue"
handleClick={()=>{
router.goBack();
}}
icon="arrow-left"
/>
: null
}
</div>
</Shell>
<Shell>
<iframe src={iframeUrl}
frameBorder={0}
id='detailIframeId'
name='applyIframe'
marginWidth="0"
marginHeight="0"
onLoad={this.showAll}
allowTransparency="yes"
seamless
scrolling={'no'}
style={{
width: '100%',
overflowY: 'hidden',
minHeight: '800px',
}}
/>
</Shell>
</PageHeaderWrapper>
)
}
}
import React, { Component, Fragment } from 'react';
import { Upload, message } from 'antd';
import ButtonDiy from '@/baseComponent/ButtonDiy';
import * as service from '@/baseComponent/UploadImgDiy/service';
import PropTypes from 'prop-types';
export default class ButtonUpload extends Component {
constructor(props) {
super(props);
this.state = {
fileSize: props.fileSize || 2,
loading: false,
};
}
checkSize(file) {
const { fileSize } = this.state;
let flag = false;
if (fileSize && file.size / 1024 / 1024 > fileSize) {
message.error(`单个文件大小不能超过${fileSize}MB!`);
flag = true;
}
return flag;
}
uploadFile = () => {
const { onChange } = this.props;
const file = this.fileInput.files[this.fileInput.files.length - 1];
if (!file || this.checkSize(file)) {
return;
}
this.setState({
loading: true,
});
service.uploadFile({
file: file,
}).then(res => {
this.setState({
loading: false,
});
if (res) {
message.success('上传成功');
let data = {
files: [
{
path: res.url,
name: file.name,
},
],
};
onChange && onChange(data, this.fileInput);
}
});
};
selectFile = () => {
this.fileInput.click();
};
render() {
const { accept, buttonName, buttonClassName, value, readOnly, disabled } = this.props;
const { loading } = this.state;
const viewDom = <a href={value}
target="_blank">点击查看</a>;
if (readOnly || disabled) {
if(typeof value === 'object'){
if(Array.isArray(value.files) && value.files.length){
return <a href={value.files[0].path}
target="_blank">点击查看</a>;
}else{
return null;
}
}
if (value) {
return viewDom;
}
return null;
}
return (
<Fragment>
<label>
<ButtonDiy name={loading ? '上传中' : buttonName}
loading={loading}
handleClick={this.selectFile}
className={buttonClassName}
/>
<input type="file"
accept={accept}
style={{ display: 'none' }}
onChange={this.uploadFile}
ref={input => {
this.fileInput = input;
}}
/>
{this.fileInput && this.fileInput.value.split('\\').pop()
|| value
|| <span style={{ color: '#D2D2D2' }}>未选择任何文件</span>}
</label>
</Fragment>
);
}
}
ButtonUpload.propTypes = {
fileSize: PropTypes.number, // 文件大小限制
accept: PropTypes.string, // 上传类型限制
buttonName: PropTypes.string, // 上传按钮名称
buttonClassName: PropTypes.string, //按钮样式
onChange: PropTypes.func, // 上传成功回调
};
ButtonUpload.defaultProps = {
fileSize: 2,
accept: '',
buttonName: '选择文件',
buttonClassName: 'defaultBlue',
onChange: () => {
},
};
/**
* 钟是志
* 2019年11月5日
* 流程引擎 ChildForm组件
*
* */
import ButtonDiy from '@/baseComponent/ButtonDiy';
import ModalDiy from '@/baseComponent/ModalDiy';
import React, { Component, Fragment } from 'react';
import { mustHaveValue } from '@/baseComponent/utils';
import { Badge, Icon } from 'antd';
import FormArray from './FormArray';
export default class ChildForm extends Component {
constructor(props) {
super(props);
this.state = {
showModal: false,
formValues: [{
formKey: Math.random(),
}],
requireOtherFiled: {},
};
}
changeShow = () => {
const { value } = this.props;
const { showModal } = this.state;
if (!value || typeof value !== 'object' || !Array.isArray(value)) {
this.setState({
formValues: [{
formKey: Math.random(),
}],
showModal: !showModal,
});
} else {
let formValues = [];
for (let item of value) {
formValues.push(
{
formKey: Math.random(),
...item,
});
}
this.setState({
formValues,
showModal: !showModal,
});
}
};
formStateChange = (value, key, index) => {
let oldValue = this.state.formValues;
oldValue[index][key] = value;
this.setState({
formValues: oldValue,
});
};
addOneForm = () => {
let oldValue = this.state.formValues;
oldValue.push({
formKey: Math.random(),
});
this.setState({
formValues: oldValue,
});
};
deleteOneForm = (index) => {
let oldValue = this.state.formValues;
oldValue.splice(index, 1);
this.setState({
formValues: oldValue,
});
};
componentDidMount() {
}
handleOk = () => {
const { formValues } = this.state;
const { config } = this.props;
const { componentProps: { thisFields } } = config;
for (let item of formValues) {
if (!mustHaveValue(thisFields, item)) {
return false;
}
}
this.props.onChange(formValues, config.key);
this.changeShow();
return false;
};
render() {
const { showModal, formValues } = this.state;
const { config, disabled } = this.props;
const { componentProps: { thisFields } } = config;
const modalProps = {
handleOk: this.handleOk,
title: config.name,
handleCancel: this.changeShow,
width: 800,
};
if(disabled){
modalProps.footer = null;
}
const Fields = [];
for(let item of thisFields){
if(item.comName !== 'Label'){
Fields.push(item.name);
}
}
const Filter = [];
for(let item of thisFields){
let name = '';
if(item.defaultValue){
name = item.defaultValue.replace(/[\r\n]/g,"");
}
if(item.comName === 'Label' && name && Fields.indexOf(name) > -1){
continue;
}else{
Filter.push(item);
}
}
return (
<Fragment>
<ButtonDiy name={disabled ? '查看' : '编辑'}
handleClick={this.changeShow}/>
{showModal ?
<ModalDiy {...modalProps}>
{
formValues.map((x, index) => {
return (
<div
style={{
border: '1px solid gray',
width: '95%',
margin: '0 auto',
marginBottom: '15px',
}}
key={x.formKey}>
{
disabled ?
<Badge count={
<Icon type={'check'}
style={{
color: '#52c41a',
paddingTop: '20px',
paddingRight: '20px',
}}/>
}
>
<FormArray config={thisFields}
value={x}
changeValue={(value, key) => {
this.formStateChange(value, key, index);
}}
disabled={disabled}
nameSpan={{ big: 7, small: 7 }}
fileSpan={{ big: 2, small: 2 }}/>
</Badge>
: <Badge count={
<Icon type={'close-circle'}
onClick={() => {
this.deleteOneForm(index);
}}
style={{
color: '#f5222d',
paddingTop: '20px',
paddingRight: '20px',
}}/>
}
>
<FormArray config={Filter}
value={x}
changeValue={(value, key) => {
this.formStateChange(value, key, index);
}}
disabled={disabled}
nameSpan={{ big: 9, small: 9 }}
fileSpan={{ big: 2, small: 2 }}/>
</Badge>
}
</div>
);
})
}
{
disabled ? null :
<div style={{ paddingTop: '20px', textAlign: 'center' }}>
<ButtonDiy name={'新增'}
className={'defaultRed'}
handleClick={this.addOneForm}
/>
</div>
}
</ModalDiy> : null}
</Fragment>);
}
}
/**
* 徐立
* 2019年9月22日
* 流程图
*/
import React, { Component } from 'react'
import config from '@/config/config';
export default class FlowImg extends Component {
render() {
let { id } = this.props;
return (
<div style={{
width:'98%',
textAlign:'center',
minHeight: '300px',
paddingTop: '50px',
paddingBottom: '50px',
overflowX: 'auto',
}}>
<img src={config.sqlFormsServer + '/UnifiedAppFormApi/getProcessImg?appId='+id} alt=""/>
</div>
)
}
}
/**
* 钟是志
* 2019年11月4日 17:39:34
* 流程引擎 TableSelect
*/
import { Divider, Modal, Popconfirm } from 'antd';
import React, { Component, Fragment } from 'react';
import ButtonDiy from '@/baseComponent/ButtonDiy';
import StandardTable from '@/components/StandardTable';
import { Link } from 'react-router-dom';
import { handleSqlData } from '../publicApiService';
import { date, format } from '../../config';
import moment from 'moment';
import { deepCopy } from '@/baseComponent/utils';
export default class TableSelect extends Component {
constructor(props) {
super(props);
this.state = {
showModal: false,
formValues: {},
selectedRows: [],
showDetail: true,
list: [],
pagination: {
current: 1,
total: 1,
pageSize: 10,
showQuickJumper: true,
onChange: (current, size) => {
this.pageChange(current, size);
},
},
};
}
handleSelectRows = rows => {
this.setState({
selectedRows: rows,
});
};
/*formStateChange = (value, key) => {
let oldValue = this.state.formValues;
oldValue[key] = value;
this.setState({
formValues: oldValue,
});
};*/
showModal = () => {
this.setState(
{
showModal: true,
}, () => {
this.getPeopleInfo();
});
};
pageChange = (current, size) => {
this.setState({
pagination: {
...this.state.pagination,
current: current,
pageSize: size,
},
}, () => {
// this.getPeopleInfo();
});
};
componentDidMount() {
// this.getPeopleInfo();
}
getPeopleInfo = () => {
const { config, value } = this.props;
const { componentProps: { sqlKey, allValues, valueName } } = config;
const { pagination, formValues } = this.state;
const data = {
...formValues,
sqlKey,
allValues,
};
data.pageSize = pagination.pageSize;
data.pageNo = pagination.current;
handleSqlData(data).then((response) => {
if (response.total) { // 后续增加分页.
} else {
pagination.total = response.length;
}
for (let item of response) {
item[valueName] = item[valueName] + '';
}
this.setState({
list: response,
pagination,
});
});
};
stateChange = (key, value) => {
this.setState({
[key]: value,
});
};
onChange = (value) => {
const { config } = this.props;
this.setState({
showDetail: false,
},()=>{
this.props.onChange(value, config.key);
setTimeout(()=>{
this.setState({
showDetail: true,
})
}, 50);
});
};
cancelSelect = (record) => {
const { config } = this.props;
let value = deepCopy(this.props.value);
const { labelName, valueName } = config.componentProps;
if (value && typeof value === 'object' && value.selects) {
delete value.selects[record[valueName]];
}
this.onChange(value);
};
handleSelect = (record) => {
const { config } = this.props;
let value = deepCopy(this.props.value);
const { labelName, valueName, isMultiple } = config.componentProps;
if (typeof value === 'object') {
if (value.selects && isMultiple === true) {
value.selects[record[valueName]] = {
...record,
};
} else {
value.selects = {
[record[valueName]]: {
...record,
},
};
}
} else {
value = {
selects: {
[record[valueName]]: {
...record,
},
},
};
}
this.onChange(value);
};
handleColumns = () => {
const { config, value } = this.props;
const { showDetail } = this.state;
const { valueName } = config.componentProps;
const info = value && typeof value === 'object' && value.selects ? value.selects : {};
let keys = Object.keys(info);
const { componentProps: { columnsData } } = config;
const { cols } = columnsData;
let columns = [];
for (let item in cols) {
columns.push(
{
dataIndex: cols[item].name,
title: cols[item].title,
dataType: cols[item].type,
},
);
}
for (let item of columns) {
if (item.dataType && date.indexOf(item.dataType) > -1) {
item.render = (text, record) => {
if (!text) {
return '';
}
if (!isNaN(parseInt(text, 10)) && parseInt(text, 10) > 10000000) {
text = parseInt(text, 10);
}
return moment(text).format(format[item.dataType]);
};
}
}
if (columns.length && showDetail) {
columns.push(
{
title: '操作',
// fixed: 'right',
dataIndex: 'operation',
render: (text, record) => {
if (keys.indexOf(record[valueName]) > -1) {
return (<a
style={{color: 'red'}}
onClick={() => {
this.cancelSelect(record);
}}>
取消选择
</a>);
}
return (<a onClick={() => {
this.handleSelect(record);
}}>选择</a>);
},
},
);
}
return columns;
};
render() {
const { config, disabled } = this.props;
const { labelName, valueName } = config.componentProps;
const { showModal, list, pagination, selectedRows } = this.state;
const value = deepCopy(this.props.value);
const columns = this.handleColumns();
const info = value && typeof value === 'object' && value.selects ? value.selects : {};
const re = [];
for (let item in info) {
const one = info[item];
re.push(
{
name: one[labelName],
value: one[valueName],
},
);
}
return (
<Fragment>
{!showModal ?
<Fragment>
<span>
{re.length ? re.map((x) => {
return <span key={x.value}>{x.name}&nbsp;&nbsp;</span>;
})
: ''}
</span>
{disabled ? null : <ButtonDiy
name={'选择'}
className={'defaultBlue'}
handleClick={this.showModal}/>}
</Fragment>
:
<Modal title={'选择'}
visible={true}
width={1200}
maskClosable={false}
footer={null}
onCancel={() => {
this.stateChange('showModal', false);
}}>
<div style={{ overflowY: 'auto', maxHeight: '600px' }}>
<StandardTable
rowKey={valueName}
selectedRows={selectedRows}
data={{ list, pagination }}
columns={columns}
onSelectRow={this.handleSelectRows}
noSelectRow={true}
/>
</div>
</Modal>
}
</Fragment>
);
}
}
差异被折叠。
import { text, number, date } from '../config/index';
import { isJSON } from '@/baseComponent/utils';
import { translateAddFields } from '../config/index';
const handleSqlModels = (sqlModels, defaultValues) => {
if (typeof sqlModels === 'undefined' || !Array.isArray(sqlModels)) {
return [];
} else {
let res = [];
for (let x of sqlModels) {
let key = x.key;
if (!isJSON(x.cols)) {
let info = x.dataObjModel.columnModels;
for (let item in info) {
let z = info[item];
let oneFields = {
key: key + '_' + z.name,
name: z.title,
dataType: z.type,
required: false,
dataId: item,
comName: date.indexOf(z.type) > -1 ? 'DatePicker' : 'Input',
disabled: true,
};
oneFields.defaultValue = defaultValues[oneFields.key] || '';
res.push(oneFields);
}
continue;
}
let info = JSON.parse(x.cols); // name, title, type
for (let item in info) {
let z = info[item];
let oneFields = {
key: key + '_' + z.name,
name: z.title,
dataType: z.type,
required: false,
dataId: item,
comName: date.indexOf(z.type) > -1 ? 'DatePicker' : 'Input',
disabled: true,
};
oneFields.defaultValue = defaultValues[oneFields.key] || '';
res.push(oneFields);
}
}
return res;
}
};
const funcHandleFileds = (source, obj, fieldsColumns) => {
let fileds = [];
for (let item of source) {
for (let info of item) {
let oneFiled = {};
if (info.content) {
let content = info.content;
oneFiled = {
comName: content.comName,
name: content.label || '',
};
if(content.comName === 'DatePicker'){
if(content.format){
oneFiled.format = content.format;
}
}
if(content.comName === 'PartForm'){
const { childFormKey, columnIds, } = content;
let thisSource = obj[childFormKey].items;
let thisFields = funcHandleFileds(thisSource, obj, fieldsColumns);
for (let i = 0; i < thisFields.length; i++) {
if (typeof thisFields[i].c1 !== 'undefined') {
thisFields[i] = {
...fieldsColumns[thisFields[i].c1],
...thisFields[i],
};
}
}
oneFiled.componentProps = {
columnIds,
childFormKey,
thisFields,
};
}
if(content.comName === 'RangePicker'){
if(content.format){
oneFiled.format = content.format;
}
}
if (content.comName === 'Description') {
oneFiled.key = content.sqls[1];
}
if(['Radio', 'Select', 'Checkbox'].indexOf(content.comName)> -1){ // 枚举值
if(content.optionType){
oneFiled.optionType = content.optionType;
switch (oneFiled.optionType) {
case 'enum':
if(content.enums){
let options = isJSON(content.enums) ? JSON.parse(content.enums) : [];
options = options.map((x)=>{
return { key: x.value, name: x.label };
});
oneFiled.options = options;
}
break;
case 'reference':
oneFiled.filterSql = content.filterSql;
break;
case 'sql':
oneFiled.sqlKey = content.sqlKey;
oneFiled.labelName = content.labelName;
oneFiled.valueName = content.valueName;
break;
default:
oneFiled.options =[];
break;
}
}
}
if(content.comName === 'ChildForm'){
const { childFormKey, columnIds, } = content;
let thisSource = obj[childFormKey].items;
let thisFields = funcHandleFileds(thisSource, obj, fieldsColumns);
for (let i = 0; i < thisFields.length; i++) {
if (typeof thisFields[i].c1 !== 'undefined' && typeof fieldsColumns[thisFields[i].c1] !== 'undefined') {
thisFields[i] = {
...fieldsColumns[thisFields[i].c1],
...thisFields[i],
};
}
}
oneFiled.componentProps = {
columnIds,
childFormKey,
thisFields,
};
}
if(content.comName === 'TableSelect'){
oneFiled.componentProps = {
sqlKey: content.sqlKey,
labelName: content.labelName,
valueName: content.valueName,
isMultiple: content.isMultiple,
};
}
if(content.comName === 'Label'){ // 提示信息显示
if(info.hidden){
continue;
}
oneFiled.key = content.initialValue ? content.initialValue.slice(0, 10) : ' ';
oneFiled.name = ' ';
oneFiled.defaultValue = content.initialValue;
oneFiled.dataType = 'TEXT';
}
for (let j in content.columnIds) {
let oneFields = content.columnIds[j];
oneFiled[j] = oneFields[1];
}
fileds.push(oneFiled);
}
}
}
return fileds;
};
export async function destructionGetDetail(response) {
/**
* 如果数据校验不通过直接pass 返回默认值,
* */
if (typeof response.unifiedServicePatternModel === 'undefined' ||
!isJSON(response.unifiedServicePatternModel.content) ||
!Array.isArray(response.unifiedServicePatternModel.dataObjModels) ||
!response.unifiedServicePatternModel.dataObjModels.length ||
typeof response.unifiedServicePatternModel.dataObjModels[0].columnModels === 'undefined'
) {
return {
addFields: [],
tableInfo: {},
allConfigSetInfo: response,
};
}
const basicPatternModel = response.unifiedServicePatternModel;
/** 正式开始 **/
/*** 字段name, dataType ***/
let fieldsColumns = {};
for(let dataObjModels of basicPatternModel.dataObjModels){
let columns = dataObjModels.columnModels;
for (let item of columns) {
fieldsColumns[item.base52] = {
name: item.title,
dataType: item.type,
key: item.base52,
dataId: item.id,
referenceCodeName: item.referenceCodeName,
referenceNameName: item.referenceNameName,
required: Boolean(!item.isNull),
};
}
}
/*** 字段组件类型 ***/
let data = JSON.parse(basicPatternModel.content);
let key = data.init;
let source = data.datas[key].items;
let fileds = funcHandleFileds(source, data.datas, fieldsColumns);
/*** 字段默认值 ***/
let sqlModeData = handleSqlModels(basicPatternModel.sqlModels, basicPatternModel.defaultValues); //Array
let defaultBinds = data.datas[key].defaultBinds;
let defaultKeys = {};
if(defaultBinds){
for(let item in defaultBinds){
let one = defaultBinds[item];
if(one && one.columnIds && one.sqls){
defaultKeys[one.sqls[1]] = one.columnIds[1];
}
}
}
for(let item of sqlModeData){
if(defaultKeys[item.key]){
item.defaultKey = defaultKeys[item.key];
}
}
/*** 流程表数据 ***/
let tableInfo = {
base52: basicPatternModel.dataObjModels[0].base52,
name: basicPatternModel.dataObjModels[0].name,
defaultValuesId: key,
};
for(let i = 0; i < fileds.length; i++){
let item = fileds[i];
if(item.comName === 'Description'){
if(item.key && !item.defaultValue && basicPatternModel.defaultValues && basicPatternModel.defaultValues[item.key]){
item.defaultValue = basicPatternModel.defaultValues[item.key];
}
for(let x of sqlModeData){
if(x.key === item.key){
item.c1 = x.defaultKey;
fileds[i] = {
...item,
...x,
}
}
}
}
}
for (let i = 0; i < fileds.length; i++) {
if (typeof fileds[i].c1 !== 'undefined') {
if(fileds[i].key && fieldsColumns[fileds[i].c1] && fieldsColumns[fileds[i].c1].key && fileds[i].key !== fieldsColumns[fileds[i].c1].key){
fileds[i].onestopDefaultKey = fileds[i].key;
}
fileds[i] = {
...fileds[i],
...fieldsColumns[fileds[i].c1],
};
}
}
return {
addFields: await translateAddFields(fileds, tableInfo),
tableInfo,
allConfigSetInfo: response,
};
}
export function getDefaultValues(addFields = [], tableInfo = {}){
const values = {
defaultValues: {
[tableInfo.defaultValuesId]: {},
}
};
const defalutValues = {};
for(let item of addFields){
if(typeof item.defaultValue !== 'undefined'){
values[item.key] = item.defaultValue;
// values[item.onestopDefaultKey] = item.defaultValue;l;l
}
if(typeof item.defaultKey !== 'undefined' && item.defaultKey){
values[item.defaultKey] = item.defaultValue; // 表单渲染需要这个值
defalutValues[item.key] = item.defaultValue;
defalutValues[item.onestopDefaultKey] = item.defaultValue;
}
}
values.defaultValues[tableInfo.defaultValuesId] = defalutValues; //传给后台需要这个值
return values;
}
/**
* 事务页面。 根据一站式服务大厅的事务接口。达到增删发起事务流程
* 2019年10月23日 09:48:13
* 钟是志
*
* */
import { apiRequest } from '../request';
import { getFormArrayConfig } from '../config/index';
import { setHuanGeToken } from '@/utils/authority';
import { isJSON } from '@/baseComponent/utils';
const giveValue = (x) => {
if(x && x.rows){
let res = [];
for(let item of x.rows){
res.push({
...item.hisTaskListData,
...item,
});
}
x.rows = res;
return x;
}else{
return {
rows: [],
total: 1,
};
}
};
const getOtherToken = () => {
let userName = sessionStorage.getItem("currentUser");
if(isJSON(userName)){
let name = JSON.parse(userName).name;
return apiRequest(`/UserApi/loginByCount?username=${name}`, {}).then((res)=>{
if(res){
setHuanGeToken(res.token);
}
});
}
};
const getId = () => { // 获取流程引擎 事务workId 和表dataBaseId
let path = window.location.href;
path = path.split('/');
// let idObj = config[path.pop()];
let idObj;
if (typeof idObj === 'undefined') {
console.error('没有找到对应的流程引擎id');
return false;
} else {
const { dataBaseId, workId } = idObj;
return {
dataBaseId,
workId,
};
}
};
const getColumns2 = (id) => { // 获取表头 workId
return apiRequest('/DataColumnApi/getHeaderList', { dataObjId: id }).then((response)=>{
if(response){
return response.map((x)=>{
return {
title: x.title,
dataIndex: x.name,
type: x.type,
}
})
}
});
};
const getPages = (info) => { // 获取代办事项 分页数据 workId
// workId, pageSize, pageNo,
if (typeof info.pageNo === 'undefined') {
info.pageNo = 1;
info.pageSize = 10;
}
return apiRequest('/UnifiedAppFormApi/getWaitPage', info);
};
const getQueryCondition = (dataObjId) => { // 获取搜索条件 dataBaseId //暂时未生效. 因为欢哥那边不支持
return [];
return apiRequest('/DataColumnApi/getHeaderList', { dataObjId }).then((response) => {
let res = [];
if(response){
for(let item of response){
if(item.isShowQuery){
let sear = getFormArrayConfig([item]);
if(!Array.isArray(sear)){
return false;
}
delete sear[0].required;
delete sear[0].placeHolder;
res.push(sear[0]);
}
}
}
return res;
});
};
const getListPage = (info) => { // 获取表数据。dataObjId
if (typeof info.pageNo === 'undefined') {
info.pageNo = 1;
info.pageSize = 10;
}
return apiRequest('/DataObjApi/getFormDataPage', info);
};
const deleteFormData = (dataBaseId, id) => { // 删除表数据.
const info = {
keys: JSON.stringify({id}),
objId: dataBaseId,
};
return apiRequest('/DataObjApi/deleteFormData', info);
};
/****************************** 以上接口暂时不用 ****************************/
const getColumns = (workId) => { // 获取表头 workId
return apiRequest('/UnifiedAppFormApi/getFormTitle', { id: workId });
};
/**
* 获取下拉枚举值
* */
const getOptions = async (id, filterSql = undefined, key, name) => {
return await apiRequest('/DataColumnApi/getOptions', {id, filterSql}).then((x)=>{
if(x){
return x.map((y)=>{
return {
key: y[key],
name: y[name],
}
})
}else{
return [];
}
});
};
/**
* 获取下拉枚举值 通过sql语句
* */
const getSqlOptions = async (id, sqlKey = undefined, key, name ) => {
return await apiRequest('/DataColumnApi/getSqlOptions', {id, sqlKey}).then((x)=>{
if(x){
return x.map((y)=>{
return {
key: y[key],
name: y[name],
}
})
}else{
return [];
}
});
};
/**
* 获取发起流程填写的字段表单详情
* */
const getFormDetail = (id) => {
return apiRequest('/UnifiedAppApi/getDetail', {id}).then((x)=>{
if(x){
return x;
}else{
return {};
}
});
};
/**
* 发起流程
* */
const startProcess = (info) => {
return apiRequest('/UnifiedAppFormApi/startProcess', info).then((x)=>{
if(x){
return x;
}else{
return null;
}
});
};
/**
* 查询已发起的流程的分页接口
*
* */
const getApplyPage = (info) => {
return apiRequest('/UnifiedAppFormApi/getApplyPage', info).then((x)=>{
return giveValue(x);
});
};
/**
* 查询一个流程的详情数据
*
* */
const getDetailInfo = (id) => {
return apiRequest('/UnifiedAppFormApi/getFormDetail', {id}).then((x)=>{
if(x){
return x;
}else{
return null;
}
});
};
/**
* 待办业务
* pageSize: 10
* appId: 1185524814832467968
* pageNo: 1
* */
const getWaitPage = (info) => {
return apiRequest('/UnifiedAppFormApi/getWaitPage', info).then((x) => {
return giveValue(x);
})
};
/**
* 已办业务
* pageSize: 10
* appId: 1185524814832467968
* pageNo: 1
* */
const getHandledPage = (info) => {
return apiRequest('/UnifiedAppFormApi/getHandledPage', info).then((x) => {
return giveValue(x);
})
};
/**
* 审核接口,支持批量
* taskIds: 08d8d359-f7a6-11e9-9a27-0242b1fd760b
* examineMap: {"examine":"0","reason":"通过"}
* taskForm: {}
* */
const handleAudit = (info) => {
return apiRequest('/UnifiedAppFormApi/examineProcess', info).then((x) => {
if(x){
return x;
}
})
};
const handleSqlData = (info) => {
return apiRequest('/DataColumnApi/getSqlData', info).then((x) => {
if(x){
return x;
}else{
return [];
}
})
};
const handleSqlfind = async(sqlKey = '') => {
return await apiRequest('/SqlManageEntityApi/find', {sqlKey}).then((x) => {
if(x){
return x;
}else{
return null;
}
})
};
/**
* 流程紧急度
* 2019年12月5日
* 钟是志
* 先默认给后台传个值 保证能提交申请
* */
const getSeriousOptions = () => {
return apiRequest('/UnifiedAppFormLevelApi/getAll', {}).then((x)=>{
if(x){
return x.map((s)=>{
return {
key: s.id,
name: s.name,
color: s.color,
}
})
}
});
};
export {
getId, getColumns, getPages, getQueryCondition,
getListPage, deleteFormData, getColumns2, getFormDetail,
getOptions, startProcess, getApplyPage, getOtherToken,
getDetailInfo, getWaitPage, getHandledPage, handleAudit,
handleSqlData,handleSqlfind, getSqlOptions, getSeriousOptions,
};
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论