From ba9e189dd33c8d48f7f4ac36bcefeef9afb426f8 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 17 七月 2023 23:40:49 +0800 Subject: [PATCH] 2023-07-17 --- src/tabviews/custom/components/code/sand-box/index.jsx | 108 ++++++++++++++++++++++++++++++++--------------------- 1 files changed, 65 insertions(+), 43 deletions(-) diff --git a/src/tabviews/custom/components/code/sand-box/index.jsx b/src/tabviews/custom/components/code/sand-box/index.jsx index a9edce6..6bdaf07 100644 --- a/src/tabviews/custom/components/code/sand-box/index.jsx +++ b/src/tabviews/custom/components/code/sand-box/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Spin, notification } from 'antd' +import { Spin, notification, Modal } from 'antd' import Api from '@/api' import UtilsDM from '@/utils/utils-datamanage.js' @@ -20,8 +20,9 @@ config: null, // 鍥捐〃閰嶇疆淇℃伅 loading: false, // 鏁版嵁鍔犺浇鐘舵�� sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 - data: {}, // 鏁版嵁 + data: [], // 鏁版嵁 html: '', + result: {} } loaded = false @@ -30,7 +31,7 @@ const { data, initdata } = this.props let _config = fromJS(this.props.config).toJS() - let _data = {} + let _data = [] let _sync = false let BID = '' @@ -49,7 +50,7 @@ _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) { @@ -97,7 +98,7 @@ Api.getLCacheConfig(config.uuid).then(res => { if (!res || this.loaded) return - this.setState({data: res[0]}, () => { + this.setState({data: res}, () => { this.renderView() }) }) @@ -122,20 +123,20 @@ 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] } this.loaded = true - this.setState({sync: false, data: _data}) - if (!is(fromJS(this.state.data), fromJS(_data))) { setTimeout(() => { this.renderView() }, 10) } + + this.setState({sync: false, data: _data}) } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { this.setState({}, () => { this.loadData() @@ -157,13 +158,13 @@ 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 @@ -186,66 +187,87 @@ let result = await Api.genericInterface(param) if (result.status) { - let _data = result.data || {} + let _data = result.data || [] this.loaded = true - if (config.$cache) { + if (config.$cache && config.setting.onload !== 'false') { Api.writeCacheConfig(config.uuid, result.data || '') } - this.setState({ - data: _data, - loading: false - }) - if (!is(fromJS(this.state.data), fromJS(_data))) { setTimeout(() => { this.renderView() }, 10) } + + let _result = {...result} + delete _result.data + + this.setState({ + data: _data, + result: _result, + loading: false + }) + + if (result.message) { + if (result.ErrCode === 'Y') { + Modal.success({ + title: result.message + }) + } else if (result.ErrCode === 'S') { + notification.success({ + top: 92, + message: result.message, + duration: 2 + }) + } + } } else { this.setState({ loading: false }) - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) + + if (!result.message) return + if (result.ErrCode === 'N') { + Modal.error({ + title: result.message + }) + } else if (result.ErrCode !== '-2') { + notification.error({ + top: 92, + message: result.message, + duration: 10 + }) + } } } renderView = () => { - const { data } = this.state + const { data, result } = this.state 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, result) {' + js + '})') + evalfunc(data, result) } catch (e) { console.warn(e) } -- Gitblit v1.8.0