From 03a22ec6f9ad7303d10b4c65bb5bc6fa5cbd448a Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 22 十月 2022 23:21:42 +0800 Subject: [PATCH] 2022-10-22 --- src/menu/datasource/index.jsx | 200 +++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 173 insertions(+), 27 deletions(-) diff --git a/src/menu/datasource/index.jsx b/src/menu/datasource/index.jsx index 37ae5a1..569dbba 100644 --- a/src/menu/datasource/index.jsx +++ b/src/menu/datasource/index.jsx @@ -1,12 +1,11 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { Icon, Modal } from 'antd' +import { Modal } from 'antd' +import { SettingOutlined } from '@ant-design/icons' -import zhCN from '@/locales/zh-CN/model.js' -import enUS from '@/locales/en-US/model.js' import VerifyCard from './verifycard' +import MKEmitter from '@/utils/events.js' import './index.scss' class DataSource extends Component { @@ -16,8 +15,9 @@ } state = { - dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, + appType: sessionStorage.getItem('appType'), sourcelist: [], + mainSearch: [], visible: false, loading: false, setting: null @@ -34,9 +34,114 @@ } editDataSource = () => { + const { config } = this.props + const { appType } = this.state + + if (config.type === 'interface') { // 鍏叡鏁版嵁婧愪笉浣跨敤鎼滅储 + this.setState({visible: true}) + return + } + + let search = [] + let menu = fromJS(window.GLOB.customMenu).toJS() + + if (appType === 'mob') { + let ms = null + menu.components.forEach(item => { + if (item.type === 'topbar' && item.wrap.type !== 'navbar' && item.search) { + ms = item.search + } else if (item.type === 'search' && item.wrap.field) { + search.push({ + type: 'text', + label: item.wrap.label, + field: item.wrap.field, + match: item.wrap.match, + required: item.wrap.required, + value: item.wrap.initval || '' + }) + } + }) + + if (ms) { + if (ms.setting.type === 'search') { + search.push({ + type: 'text', + label: '鎼滅储鏍�', + field: ms.setting.field, + match: ms.setting.match, + required: ms.setting.required, + value: ms.setting.initval || '' + }) + } + ms.fields.forEach(item => { + if (item.type === 'range') { + item.initval = `${item.minValue},${item.maxValue}` + } + search.push(item) + }) + + ms.groups.forEach(group => { + if (group.setting.type === 'search') { + search.push({ + type: 'text', + label: group.wrap.name, + field: group.setting.field, + match: group.setting.match, + required: group.setting.required, + value: group.setting.initval || '' + }) + } + + group.fields.forEach(item => { + if (item.type === 'range') { + item.initval = `${item.minValue},${item.maxValue}` + } + search.push(item) + }) + }) + } + } else { + let _search = null + let filterComponent = (box) => { + box.components.forEach(item => { + if (_search) return + + if (item.type === 'search') { + box.slist = [...box.slist, item.search] + } else if (item.uuid === config.uuid) { + _search = box.slist.pop() + } else if (item.type === 'group') { + item.components.forEach(m => { + if (m.uuid !== config.uuid) return + _search = box.slist.pop() + }) + } else if (item.type === 'tabs') { + item.subtabs.forEach(tab => { + tab.slist = [...box.slist] + filterComponent(tab) + }) + } + }) + } + menu.slist = [] + filterComponent(menu) + + if (_search) { + search = _search + } else { + menu.components.forEach(item => { + if (item.type !== 'search') return + search = item.search + }) + } + } + this.setState({ - visible: true + visible: true, + mainSearch: search }) + + MKEmitter.emit('modalStatus', '鏁版嵁婧�') } verifySubmit = () => { @@ -45,36 +150,87 @@ this.setState({loading: true}) this.verifyRef.submitDataSource().then(res => { + if (res.columns) { + res.columns = res.columns.map(item => { + + if (/int/ig.test(item.datatype)) { + item.type = 'number' + item.decimal = 0 + } else if (/Decimal/ig.test(item.datatype)) { + item.type = 'number' + item.decimal = +item.datatype.replace(/^Decimal\(18,/ig, '').replace(/\)/ig, '') + } else { + item.type = 'text' + item.fieldlength = +item.datatype.replace(/^Nvarchar\(/ig, '').replace(/\)/ig, '') + } + return item + }) + } + + let maxScript = 0 + + if (window.GLOB.funcs && window.GLOB.funcs.length > 0) { + window.GLOB.funcs.forEach(m => { + let reg = new RegExp('\\$ex@' + m.func_code + '@ex\\$', 'ig') + if (res.setting.dataresource) { + res.setting.dataresource = res.setting.dataresource.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`) + } + res.scripts.forEach(item => { + item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`) + + if (item.status === 'false') return + + if (/exec\s/ig.test(item.sql)) { + maxScript = 1000 + } else if (item.sql.length > maxScript) { + maxScript = item.sql.length + } + }) + }) + } else { + res.scripts.forEach(item => { + if (item.status === 'false') return + + if (/exec\s/ig.test(item.sql)) { + maxScript = 1000 + } else if (item.sql.length > maxScript) { + maxScript = item.sql.length + } + }) + } + + res.setting.maxScript = maxScript + this.setState({loading: false, visible: false}) this.props.updateConfig({...config, ...res}) + + MKEmitter.emit('modalStatus', false) }, () => { this.setState({loading: false}) }) } render () { - const { config, menu } = this.props - const { visible, dict, loading } = this.state + const { config } = this.props + const { visible, loading, mainSearch } = this.state return ( <div className="model-datasource"> - <Icon type="setting" onClick={() => this.editDataSource()} /> + <SettingOutlined title="鏁版嵁婧�" onClick={() => this.editDataSource()} /> <Modal - wrapClassName="model-datasource-verify-modal popview-modal" - title={'鏁版嵁婧愰厤缃�'} + wrapClassName="mk-pop-modal" + title="" visible={visible} width={'75vw'} maskClosable={false} - style={{minWidth: '900px', maxWidth: '1200px'}} - okText={dict['model.submit']} + okText="鎻愪氦" onOk={this.verifySubmit} confirmLoading={loading} - onCancel={() => { this.setState({ visible: false }) }} + onCancel={() => { MKEmitter.emit('modalStatus', false);this.setState({ visible: false }) }} destroyOnClose > <VerifyCard - dict={dict} - menu={menu} + mainSearch={mainSearch} config={config} wrappedComponentRef={(inst) => this.verifyRef = inst} /> @@ -84,14 +240,4 @@ } } -const mapStateToProps = (state) => { - return { - menu: state.customMenu - } -} - -const mapDispatchToProps = () => { - return {} -} - -export default connect(mapStateToProps, mapDispatchToProps)(DataSource) \ No newline at end of file +export default DataSource \ No newline at end of file -- Gitblit v1.8.0