提交 ebe6c000 authored 作者: 徐立's avatar 徐立

注入中台函数库

上级 b1ee5caf
...@@ -9,7 +9,6 @@ import { Row, Col ,Input,message} from 'antd' ...@@ -9,7 +9,6 @@ import { Row, Col ,Input,message} from 'antd'
import TableCom from '../tableCompon' import TableCom from '../tableCompon'
import {Toast} from 'antd-mobile' import {Toast} from 'antd-mobile'
import router from 'umi/router' import router from 'umi/router'
import { formulaList } from '../excelInitFuc/functionList';
import IsNewTable from './isNewTable'; import IsNewTable from './isNewTable';
export default class ZdyTable extends Component { export default class ZdyTable extends Component {
constructor(props){ constructor(props){
...@@ -38,19 +37,6 @@ export default class ZdyTable extends Component { ...@@ -38,19 +37,6 @@ export default class ZdyTable extends Component {
} }
componentDidMount(){ componentDidMount(){
if(!window.functionObj){ // 检查是否注册
/**
* 注册全局函数集
* 动态生成表单配置函数所使用
*/
let functionObj = {}
formulaList.map(item => {
item.children.map(arr=> {
functionObj[arr.callKey] = arr.function
})
})
window.functionObj = functionObj
}
let { let {
postData, // 数据源 postData, // 数据源
isCg, // 用户点击草稿页面进入 isCg, // 用户点击草稿页面进入
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -7,6 +7,7 @@ import { Button,Modal,Row,Col,Select } from 'antd'; ...@@ -7,6 +7,7 @@ import { Button,Modal,Row,Col,Select } from 'antd';
import funcList from './functionList'; import funcList from './functionList';
import AceEditor from "react-ace"; import AceEditor from "react-ace";
import styles from './style.less'; import styles from './style.less';
import Throttle from 'lodash-decorators/throttle';
const { Option } = Select; const { Option } = Select;
export default class index extends Component { export default class index extends Component {
state = { state = {
...@@ -16,6 +17,8 @@ export default class index extends Component { ...@@ -16,6 +17,8 @@ export default class index extends Component {
checkedList: [], // 用户选中的函数数据 checkedList: [], // 用户选中的函数数据
checkedFuc: '', // 用户选择的函数 checkedFuc: '', // 用户选择的函数
aceValue:'', // 编辑器输入内容 aceValue:'', // 编辑器输入内容
callKey: '', // 选择函数调用名
resultValue: '', // 计算结果
}; };
/** /**
* 展示模态框回调 * 展示模态框回调
...@@ -29,11 +32,11 @@ export default class index extends Component { ...@@ -29,11 +32,11 @@ export default class index extends Component {
* 模态框确定函数回调 * 模态框确定函数回调
*/ */
handleOk = e => { handleOk = e => {
const { checkedFuc } = this.state const { checkedFuc,callKey } = this.state
this.setState({ this.setState({
visible: false, visible: false,
}); });
this.props.setPitchOff(checkedFuc) this.props.setPitchOff(`$.${callKey}()`)
}; };
/** /**
* 模态框取消函数回调 * 模态框取消函数回调
...@@ -60,7 +63,8 @@ export default class index extends Component { ...@@ -60,7 +63,8 @@ export default class index extends Component {
func:item.function, func:item.function,
funcName:item.funcName, funcName:item.funcName,
params:item.params, params:item.params,
demo:item.demo demo:item.demo,
callKey:item.callKey,
}) })
}) })
this.setState({ this.setState({
...@@ -77,7 +81,8 @@ export default class index extends Component { ...@@ -77,7 +81,8 @@ export default class index extends Component {
key:item.name, key:item.name,
func:item.function, func:item.function,
params:item.params, params:item.params,
demo:item.demo demo:item.demo,
callKey:item.callKey,
}) })
}) })
}) })
...@@ -97,7 +102,11 @@ export default class index extends Component { ...@@ -97,7 +102,11 @@ export default class index extends Component {
checkedList: arr, checkedList: arr,
checkedFuc: arr[0].func, checkedFuc: arr[0].func,
aceValue: arr[0].func.toString(), aceValue: arr[0].func.toString(),
callKey: arr[0].callKey
},() => {
this.getListData(this.state.checkedList[0].demo)
}) })
} }
/** /**
* 数据格式化等操作 * 数据格式化等操作
...@@ -117,7 +126,8 @@ export default class index extends Component { ...@@ -117,7 +126,8 @@ export default class index extends Component {
key:item.name, key:item.name,
func:item.function, func:item.function,
params:item.params, params:item.params,
demo:item.demo demo:item.demo,
callKey:item.callKey,
}) })
}) })
}) })
...@@ -129,6 +139,7 @@ export default class index extends Component { ...@@ -129,6 +139,7 @@ export default class index extends Component {
/** /**
* 根据传入的数组长度返回对应的函数传入值 * 根据传入的数组长度返回对应的函数传入值
*/ */
@Throttle(1)
getListData = (List) => { getListData = (List) => {
const { checkedFuc } = this.state const { checkedFuc } = this.state
let ary = [] let ary = []
...@@ -136,14 +147,21 @@ export default class index extends Component { ...@@ -136,14 +147,21 @@ export default class index extends Component {
ary.push(item.value) ary.push(item.value)
return item return item
}) })
return checkedFuc(...ary) let data = checkedFuc(...ary)
this.setState({
resultValue: data
})
} }
componentWillReceiveProps(nextProps){ componentWillReceiveProps(nextProps){
const { isPicth } = nextProps const { isPicth } = nextProps
const { visible } = this.state
if(visible !== isPicth){
this.setState({ this.setState({
visible:isPicth visible:isPicth
}) })
} }
}
// 编辑起状态函数 // 编辑起状态函数
onAceChange = (newValue) => { onAceChange = (newValue) => {
this.setState({ this.setState({
...@@ -151,7 +169,7 @@ export default class index extends Component { ...@@ -151,7 +169,7 @@ export default class index extends Component {
}) })
} }
render() { render() {
const { selectOne,selectTwo,checkedList,checkedFuc,aceValue } = this.state const { selectOne,selectTwo,checkedList,checkedFuc,aceValue,resultValue } = this.state
const { isShowBtn,isPicth } = this.props const { isShowBtn,isPicth } = this.props
return ( return (
<> <>
...@@ -270,8 +288,25 @@ export default class index extends Component { ...@@ -270,8 +288,25 @@ export default class index extends Component {
</Col> </Col>
</Row> </Row>
<Row gutter={16}> <Row gutter={16}>
<Col span={5} className={styles.left_title}>计算结果:</Col> <Col
<Col span={16} className={styles.right_content}>{typeof this.getListData(checkedList[0].demo) == 'object'||typeof this.getListData(checkedList[0].demo) == 'boolean'?JSON.stringify(this.getListData(checkedList[0].demo)):this.getListData(checkedList[0].demo)}</Col> span={5}
className={styles.left_title}>
计算结果:
</Col>
<Col
span={16}
className={styles.right_content}>
{
resultValue?
typeof resultValue === 'object'
|| typeof resultValue === 'boolean'?
JSON.stringify(resultValue)
:resultValue
:typeof resultValue === 'boolean'?
JSON.stringify(resultValue)
:null
}
</Col>
</Row> </Row>
</div> </div>
):<div className={styles.noList}> ):<div className={styles.noList}>
...@@ -285,3 +320,4 @@ export default class index extends Component { ...@@ -285,3 +320,4 @@ export default class index extends Component {
) )
} }
} }
...@@ -47,7 +47,7 @@ export default class Basics extends Component { ...@@ -47,7 +47,7 @@ export default class Basics extends Component {
!isEmpty(item.children)?item.children.map((arr,index)=> { !isEmpty(item.children)?item.children.map((arr,index)=> {
return <div key={index}><Tooltip return <div key={index}><Tooltip
placement="right" title={<div><div>函数名称:<br />{arr.name}</div><div>函数简介:<br />{arr.funcName}</div><div>注:<br />点击可快捷添加入输入栏</div></div>}><div placement="right" title={<div><div>函数名称:<br />{arr.name}</div><div>函数简介:<br />{arr.funcName}</div><div>注:<br />点击可快捷添加入输入栏</div></div>}><div
onClick={()=>{setCloseAll();setFunction(arr.function)}} onClick={()=>{setCloseAll();setFunction(`$.${arr.callKey}()`)}}
className={styles.top_list}> className={styles.top_list}>
<Icon style={{fontSize:12,marginRight:8}} type="edit"/> <Icon style={{fontSize:12,marginRight:8}} type="edit"/>
{arr.name} {arr.name}
......
...@@ -15,13 +15,6 @@ export default class rollTab extends Component { ...@@ -15,13 +15,6 @@ export default class rollTab extends Component {
} }
} }
componentDidMount(){ componentDidMount(){
let functionObj = {}
formulaList.map(item => {
item.children.map(arr=> {
functionObj[arr.callKey] = arr.function
})
})
window.functionObj = functionObj
this.setState({ this.setState({
tabList:formulaList tabList:formulaList
},()=>{ },()=>{
......
...@@ -64,6 +64,7 @@ const Bs64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' ...@@ -64,6 +64,7 @@ const Bs64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
const base64 = baseX(Bs64) const base64 = baseX(Bs64)
import {Base16Encode} from "../Base16/index" import {Base16Encode} from "../Base16/index"
import { getToken } from '../utils/token'; import { getToken } from '../utils/token';
import { formulaList } from '../excelInitFuc/functionList';
// import FilePreview from '../filePreview'; // import FilePreview from '../filePreview';
const Item = MobileList.Item; const Item = MobileList.Item;
const Brief = Item.Brief; const Brief = Item.Brief;
...@@ -1115,9 +1116,18 @@ export default class tableCom extends Component { ...@@ -1115,9 +1116,18 @@ export default class tableCom extends Component {
return return
} */ } */
const base52 = column.base52 const base52 = column.base52
/**
* 中台函数库注入
* 动态生成表单配置函数所使用
*/
let functionObj = {}
formulaList.map(item => {
item.children.map(arr=> {
functionObj[arr.callKey] = arr.function
})
})
try { try {
var fun1 = new Function("obj","init", "defaultValues", "env", "index", "fatherCode", "utils", fun); var fun1 = new Function("obj","init", "defaultValues", "env", "index", "fatherCode", "utils","$", fun);
let obj let obj
if(!this.props.isEdit&&this.props.fatherCode){ if(!this.props.isEdit&&this.props.fatherCode){
...@@ -1137,9 +1147,9 @@ export default class tableCom extends Component { ...@@ -1137,9 +1147,9 @@ export default class tableCom extends Component {
setValues: this.setValues.bind(this, base52, json), setValues: this.setValues.bind(this, base52, json),
req: this.reqUtil.bind(this, base52, json,callback), req: this.reqUtil.bind(this, base52, json,callback),
md5: md5, md5: md5,
render:this.getRender,base64:getBase64 render:this.getRender,base64:getBase64,
}, },
functionObj
) )
if (base52) { if (base52) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论