| | |
| | | |
| | | componentDidMount () { |
| | | const { config } = this.props |
| | | if (config.js && config.wrap.compileMode !== 'custom') { |
| | | if (config.js) { |
| | | try { |
| | | // eslint-disable-next-line no-eval |
| | | eval(config.js) |
| | | // eval(config.js) |
| | | // eslint-disable-next-line |
| | | let evalfunc = eval('(true && function (data) {' + config.js + '})') |
| | | evalfunc([]) |
| | | } catch (e) { |
| | | message.warning(config.name + 'JS 执行失败!') |
| | | console.warn(config.name + e) |
| | |
| | | } |
| | | } |
| | | if (config.html !== nextProps.config.html || config.js !== nextProps.config.js) { |
| | | if (nextProps.config.js && nextProps.config.wrap.compileMode !== 'custom') { |
| | | if (nextProps.config.js) { |
| | | try { |
| | | // eslint-disable-next-line no-eval |
| | | eval(nextProps.config.js) |
| | | let evalfunc = eval('(true && function (data) {' + nextProps.config.js + '})') |
| | | evalfunc([]) |
| | | } catch (e) { |
| | | message.warning(config.name + 'JS 执行失败!') |
| | | console.warn(config.name + e) |
| | |
| | | {value: 'dynamic', label: '动态'}, |
| | | {value: 'static', label: '静态'}, |
| | | ], |
| | | controlFields: [ |
| | | {field: 'compileMode', values: ['dynamic']} |
| | | ] |
| | | // controlFields: [ |
| | | // {field: 'compileMode', values: ['dynamic']} |
| | | // ] |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'compileMode', |
| | | label: '编译方式', |
| | | initval: wrap.compileMode || 'replace', |
| | | required: false, |
| | | options: [ |
| | | {value: 'replace', label: '字段替换'}, |
| | | {value: 'custom', label: '自定义'}, |
| | | ] |
| | | }, |
| | | // { |
| | | // type: 'radio', |
| | | // field: 'compileMode', |
| | | // label: '编译方式', |
| | | // initval: wrap.compileMode || 'replace', |
| | | // required: false, |
| | | // options: [ |
| | | // {value: 'replace', label: '字段替换'}, |
| | | // {value: 'custom', label: '自定义'}, |
| | | // ] |
| | | // }, |
| | | { |
| | | type: 'radio', |
| | | field: 'permission', |
| | |
| | | config: null, // 图表配置信息 |
| | | loading: false, // 数据加载状态 |
| | | sync: false, // 是否统一请求数据 |
| | | data: {}, // 数据 |
| | | data: [], // 数据 |
| | | html: '', |
| | | } |
| | | |
| | |
| | | const { data, initdata } = this.props |
| | | let _config = fromJS(this.props.config).toJS() |
| | | |
| | | let _data = {} |
| | | let _data = [] |
| | | let _sync = false |
| | | |
| | | let BID = '' |
| | |
| | | _sync = _config.setting.sync === 'true' |
| | | |
| | | if (_sync && data) { |
| | | _data = data[_config.dataName] || {} |
| | | _data = data[_config.dataName] || [] |
| | | _sync = false |
| | | this.loaded = true |
| | | } else if (_sync && initdata) { |
| | |
| | | const { sync, config } = this.state |
| | | |
| | | if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) { |
| | | let _data = {} |
| | | let _data = [] |
| | | if (nextProps.data && nextProps.data[config.dataName]) { |
| | | _data = nextProps.data[config.dataName] |
| | | } |
| | |
| | | |
| | | if (config.wrap.datatype === 'static') { |
| | | this.setState({ |
| | | data: {}, |
| | | data: [], |
| | | loading: false |
| | | }) |
| | | return |
| | | } else if (config.setting.supModule && !BID) { // BID 不存在时,不做查询 |
| | | this.setState({ |
| | | data: {}, |
| | | data: [], |
| | | loading: false |
| | | }) |
| | | this.loaded = true |
| | |
| | | |
| | | let result = await Api.genericInterface(param) |
| | | if (result.status) { |
| | | let _data = result.data || {} |
| | | let _data = result.data || [] |
| | | |
| | | this.loaded = true |
| | | if (config.$cache && config.setting.onload !== 'false') { |
| | |
| | | const { html, js, wrap, columns } = this.state.config |
| | | |
| | | let _html = html |
| | | if (_html && wrap.datatype !== 'static' && wrap.compileMode !== 'custom') { |
| | | let _data = data |
| | | if (Array.isArray(_data)) { |
| | | _data = _data[0] || {} |
| | | } |
| | | columns.forEach(col => { |
| | | if (col.field) { |
| | | let val = (_data[col.field] || _data[col.field] === 0) ? _data[col.field] : '' |
| | | let reg = new RegExp('@' + col.field + '@', 'ig') |
| | | if (_html && wrap.datatype !== 'static') { |
| | | if (/@[\u4E00-\u9FA50-9a-zA-Z_]+@/ig.test(_html)) { |
| | | let _data = data[0] || {} |
| | | |
| | | _html = _html.replace(reg, val) |
| | | } |
| | | }) |
| | | columns.forEach(col => { |
| | | if (col.field) { |
| | | let val = _data[col.field] !== undefined ? _data[col.field] : '' |
| | | let reg = new RegExp('@' + col.field + '@', 'ig') |
| | | |
| | | _html = _html.replace(reg, val) |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | this.setState({html: _html}, () => { |
| | | if (js) { |
| | | try { |
| | | if (wrap.compileMode !== 'custom') { |
| | | // eslint-disable-next-line no-eval |
| | | eval(js) |
| | | } else { |
| | | // eslint-disable-next-line |
| | | let evalfunc = eval('(true && function (data) {' + js + '})') |
| | | evalfunc(data) |
| | | } |
| | | // eslint-disable-next-line |
| | | let evalfunc = eval('(true && function (data) {' + js + '})') |
| | | evalfunc(data) |
| | | // if (wrap.compileMode !== 'custom') { |
| | | // // eslint-disable-next-line no-eval |
| | | // eval(js) |
| | | // } else { |
| | | // // eslint-disable-next-line |
| | | // let evalfunc = eval('(true && function (data) {' + js + '})') |
| | | // evalfunc(data) |
| | | // } |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |