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

注入中台函数库

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