From 3b43ee5ead5f625d532150afceddcf1b481b823d Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 29 五月 2020 00:09:36 +0800 Subject: [PATCH] 2020-05-29 --- src/templates/sharecomponent/settingcomponent/settingform/index.jsx | 275 ++++++++++++++++++++++-------------------------------- 1 files changed, 112 insertions(+), 163 deletions(-) diff --git a/src/templates/sharecomponent/settingcomponent/settingform/index.jsx b/src/templates/sharecomponent/settingcomponent/settingform/index.jsx index 23e8f91..960fa2a 100644 --- a/src/templates/sharecomponent/settingcomponent/settingform/index.jsx +++ b/src/templates/sharecomponent/settingcomponent/settingform/index.jsx @@ -1,11 +1,12 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { fromJS } from 'immutable' -import { Form, Row, Col, Input, Radio, Select, Tooltip, Icon, notification, InputNumber, Modal, Table, Popconfirm, Typography } from 'antd' +import { Form, Row, Col, Input, Radio, Select, Tooltip, Icon, notification, InputNumber, Modal, Table, Popconfirm, Typography, Button } from 'antd' import moment from 'moment' import Api from '@/api' import Utils from '@/utils/utils.js' +import SettingUtils from './utils.jsx' import CustomScript from './customscript' import './index.scss' @@ -25,6 +26,10 @@ state = { formlist: [], + btnloading: false, + search: '', + arr_field: '', + regoptions: [], setting: null, view: 'normal', systemScripts: [{ @@ -35,27 +40,15 @@ { title: 'SQL', dataIndex: 'sql', - width: '60%', + width: '70%', render: (text) => ( <Paragraph copyable ellipsis={{ rows: 5, expandable: true }}>{text}</Paragraph> ) }, { - title: '鍒濆鍖杝ql', - dataIndex: 'initsql', - width: '12%', - render: (text, record) => { - if (record.initsql === 'true') { - return '鏄�' - } else { - return '鍚�' - } - } - }, - { title: '鐘舵��', dataIndex: 'status', - width: '8%', + width: '10%', render: (text, record) => record.status === 'false' ? ( <div> @@ -95,6 +88,8 @@ } UNSAFE_componentWillMount() { + const { config } = this.props + let _formlist = fromJS(this.props.formlist).toJS() let interType = 'inner' @@ -110,8 +105,38 @@ delete _setting.subtabs + // 鎼滅储鏉′欢 + let allSearch = Utils.initMainSearch(config.search) + allSearch = Utils.getAllSearchOptions(allSearch) + + // 鏄剧ず鍒楀瓧娈碉紝鐢ㄤ簬鏌ヨ + let arr_field = [] + config.columns.forEach(col => { + if (col.field) { + arr_field.push(col.field) + } + }) + arr_field = arr_field.join(',') + + // 姝e垯鏇挎崲 + let regoptions = allSearch.map(item => { + return { + reg: new RegExp('@' + item.key + '@', 'ig'), + value: `'${item.value}'` + } + }) + + let _search = this.formatSearch(config.search) + _search = Utils.joinMainSearchkey(_search) + + _search = _search.replace(/@\$@/ig, '') + _search = _search ? 'where ' + _search : '' + this.setState({ setting: _setting, + search: _search, + arr_field: arr_field, + regoptions: regoptions, formlist: _formlist.map(item => { if (interType === 'inner' && ['sysInterface', 'interface', 'outerFunc'].includes(item.key)) { item.hidden = true @@ -192,7 +217,7 @@ }) reject() return - } else if (values.interType === 'inner') { + } else if (values.interType === 'inner' && !values.innerFunc && values.default !== 'false' && values.dataresource) { let error = Utils.verifySql(values.dataresource) if (error) { @@ -209,6 +234,7 @@ // 鏁版嵁婧愪繚瀛� if ( values.interType === 'inner' && !values.innerFunc && + values.default !== 'false' && /[^\s]+\s+[^\s]+/ig.test(values.dataresource) && this.props.config.setting.dataresource !== values.dataresource ) { @@ -232,25 +258,7 @@ resolve() }) } else { - if (values.scripts && values.scripts.length > 0) { - let _customScript = 'declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode=\'\',@retmsg =\'\'' - values.scripts.forEach(item => { - if (item.status === 'false' || item.initsql !== 'true') return - _customScript += ` - ${item.sql} - ` - }) - values.scripts.forEach(item => { - if (item.status === 'false' || item.initsql === 'true') return - _customScript += ` - ${item.sql} - ` - }) - - values.customScript = _customScript - } else { - values.customScript = '' - } + values.customScript = this.getCustomScript(values) this.sqlverify(values, resolve, reject) } @@ -260,37 +268,13 @@ }) }) } else { - let _loading = false let _setting = fromJS(this.state.setting).toJS() - - if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) { - _loading = true - } - - if (_setting.scripts && _setting.scripts.length > 0) { - let _customScript = 'declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode=\'\',@retmsg =\'\'' - _setting.scripts.forEach(item => { - if (item.status === 'false' || item.initsql !== 'true') return - _customScript += ` - ${item.sql} - ` - }) - _setting.scripts.forEach(item => { - if (item.status === 'false' || item.initsql === 'true') return - _customScript += ` - ${item.sql} - ` - }) - - _setting.customScript = _customScript - } else { - _setting.customScript = '' - } + _setting.customScript = this.getCustomScript(_setting) let _this = this return new Promise((resolve, reject) => { - if (_loading) { + if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) { confirm({ content: `瀛樺湪鏈繚瀛橀」锛岀‘瀹氭彁浜ゅ悧锛焋, okText: this.props.dict['model.confirm'], @@ -309,77 +293,43 @@ } } - sqlverify = (_setting, _resolve, _reject) => { - const { config } = this.props - - if (_setting.interType === 'inner' && !_setting.innerFunc && _setting.default !== 'false' && /\s/.test(_setting.dataresource)) { - let _dataresource = _setting.dataresource - let _customScript = _setting.customScript - - // 鎼滅储鏉′欢 - let allSearch = Utils.initMainSearch(config.search) - allSearch = Utils.getAllSearchOptions(allSearch) - - // 鏄剧ず鍒楀瓧娈碉紝鐢ㄤ簬鏌ヨ - let arr_field = [] - config.columns.forEach(col => { - if (col.field) { - arr_field.push(col.field) - } - }) - arr_field = arr_field.join(',') - - // 姝e垯鏇挎崲 - let regoptions = allSearch.map(item => { - return { - reg: new RegExp('@' + item.key + '@', 'ig'), - value: `'${item.value}'` - } - }) - regoptions.push({ - reg: new RegExp('@orderBy@', 'ig'), - value: _setting.order - }) - if (_setting.laypage !== 'false') { - regoptions.push({ - reg: new RegExp('@pageSize@', 'ig'), - value: 10 - }, { - reg: new RegExp('@pageIndex@', 'ig'), - value: 1 - }) - } - - // 鏁版嵁婧愬鐞�, 瀛樺湪鏄剧ず鍒楁椂 - if (arr_field) { - if (/\s/.test(_dataresource)) { - _dataresource = '(' + _dataresource + ') tb' - } - - _dataresource = `select ${_setting.laypage !== 'false' ? 'top 10' : ''} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_setting.order}) as rows from ${_dataresource}) tmptable ${_setting.laypage !== 'false' ? 'where rows > 0' : ''} order by tmptable.rows` - } - - if (_setting.queryType === 'statistics') { - regoptions.forEach(item => { - _dataresource = _dataresource.replace(item.reg, item.value) - }) - } - - if (_customScript) { - regoptions.forEach(item => { - _customScript = _customScript.replace(item.reg, item.value) - }) - - _dataresource = `${_customScript} - ${_dataresource} + getCustomScript = (setting) => { + let _customScript = '' + if (setting.scripts && setting.scripts.length > 0) { + setting.scripts.forEach(item => { + if (item.status === 'false') return + _customScript += ` + ${item.sql} ` - } + }) + } - _dataresource = _dataresource.replace(/@\$|\$@/ig, '') + if (_customScript) { + _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode='',@retmsg ='' + ${_customScript} + ` + } + return _customScript + } + + sqlverify = (_setting, _resolve, _reject, isChange = false) => { + const { arr_field, regoptions, search } = this.state + + if (!isChange && _setting.interType === 'inner' && !_setting.innerFunc && _setting.default === 'false' && !_setting.customScript) { + notification.warning({ + top: 92, + message: '涓嶆墽琛岄粯璁ql鏃讹紝璇锋坊鍔犺嚜瀹氫箟鑴氭湰锛�', + duration: 5 + }) + _reject() + return + } + + if (_setting.interType === 'inner' && !_setting.innerFunc && _setting.default !== 'false') { let param = { func: 's_debug_sql', - LText: _dataresource + LText: SettingUtils.getDebugSql(_setting, arr_field, regoptions, search) } param.LText = Utils.formatOptions(param.LText) param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' @@ -495,12 +445,11 @@ } changeView = () => { - const { view } = this.state + const { view, arr_field, regoptions, search } = this.state let _this = this if (view === 'normal') { this.handleConfirm('change').then(() => { - const { config } = this.props const { setting } = this.state if (setting.interType !== 'inner' || (setting.interType === 'inner' && setting.innerFunc)) { @@ -512,20 +461,7 @@ return } - let _search = this.formatSearch(config.search) - _search = Utils.joinMainSearchkey(_search) - - _search = _search.replace(/@\$@/ig, '') - _search = _search ? 'where ' + _search : '' - - let arr_field = [] - config.columns.forEach(col => { - if (col.field) { - arr_field.push(col.field) - } - }) - - arr_field = arr_field.join(',') + let _search = search let _dataresource = setting.dataresource @@ -534,18 +470,8 @@ } if (setting.queryType === 'statistics') { // 缁熻鏁版嵁婧愶紝鍐呭鏇挎崲 - let allSearch = Utils.initMainSearch(config.search) - allSearch = Utils.getAllSearchOptions(allSearch) - - let options = allSearch.map(item => { - return { - reg: new RegExp('@' + item.key + '@', 'ig'), - value: item.value - } - }) - - options.forEach(item => { - _dataresource = _dataresource.replace(item.reg, `'${item.value}'`) + regoptions.forEach(item => { + _dataresource = _dataresource.replace(item.reg, item.value) }) _search = '' @@ -555,12 +481,33 @@ let _scripts = fromJS(this.state.systemScripts).toJS() _scripts[0].value = LText - this.setState({ - view: 'custom', - systemScripts: _scripts - }) - this.scrolltop() + if (setting.default === 'false') { + this.setState({ + view: 'custom', + btnloading: false, + systemScripts: _scripts + }) + this.scrolltop() + } else { + this.setState({ + btnloading: true + }) + new Promise((resolve, reject) => { + this.sqlverify(setting, resolve, reject, true) + }).then(() => { + this.setState({ + view: 'custom', + btnloading: false, + systemScripts: _scripts + }) + this.scrolltop() + }, () => { + this.setState({ + btnloading: false + }) + }) + } }) } else { let _loading = false @@ -869,7 +816,7 @@ render() { const { config, type } = this.props - const { formlist, view, setting, scriptsColumns, systemScripts } = this.state + const { formlist, view, setting, scriptsColumns, systemScripts, arr_field, regoptions, search, btnloading } = this.state const formItemLayout = { labelCol: { xs: { span: 24 }, @@ -888,8 +835,10 @@ <CustomScript type={type} setting={setting} + swhere={search} + arr_field={arr_field} + regoptions={regoptions} dict={this.props.dict} - customScripts={setting.scripts} searches={config.search} systemScripts={systemScripts} scriptsChange={this.scriptsChange} @@ -907,7 +856,7 @@ <Form {...formItemLayout} className="model-table-setting-form" id="model-table-setting-form"> {view !=='custom' ? <Row gutter={24}>{this.getFields(formlist)}</Row> : null} <Row gutter={24}> - {view !=='custom' ? <span onClick={this.changeView} style={{float: 'right', color: '#1890ff', marginRight: 12, marginTop: 15, cursor: 'pointer'}}>鑷畾涔夎缃�<Icon style={{marginLeft: 5}} type="right" /></span> : null} + {view !=='custom' ? <Button onClick={this.changeView} className="to-custom-script" loading={btnloading}>鑷畾涔夎缃�<Icon style={{marginLeft: 5}} type="right" /></Button> : null} {view ==='custom' ? <span onClick={this.changeView} style={{float: 'left', color: '#1890ff', marginLeft: 12, marginTop: 15, cursor: 'pointer'}}><Icon style={{marginRight: 5}} type="left" />鍩虹璁剧疆</span> : null} </Row> </Form> -- Gitblit v1.8.0