From c7aece35a62b6e91fd98a625bf0e53f64bfbd18d Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 17 八月 2023 16:22:15 +0800 Subject: [PATCH] 2023-08-17 --- src/templates/sharecomponent/tablecomponent/index.jsx | 151 +++++++++++++++++++++++++++++++++----------------- 1 files changed, 99 insertions(+), 52 deletions(-) diff --git a/src/templates/sharecomponent/tablecomponent/index.jsx b/src/templates/sharecomponent/tablecomponent/index.jsx index b91c630..5f6c49a 100644 --- a/src/templates/sharecomponent/tablecomponent/index.jsx +++ b/src/templates/sharecomponent/tablecomponent/index.jsx @@ -1,13 +1,13 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { fromJS } from 'immutable' -import { Icon, Tooltip, Select, List, notification } from 'antd' +import { Tooltip, Select, List, notification } from 'antd' +import { QuestionCircleOutlined, CloseOutlined } from '@ant-design/icons' import moment from 'moment' import Api from '@/api' import Utils from '@/utils/utils.js' -import zhCN from '@/locales/zh-CN/model.js' -import enUS from '@/locales/en-US/model.js' +import MKEmitter from '@/utils/events.js' import { queryTableSql } from '@/utils/option.js' import './index.scss' @@ -22,12 +22,9 @@ } state = { - dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, tables: [], // 绯荤粺琛� - tableFields: [], // 宸查�夎〃瀛楁闆� + tableFields: [], // 宸查�夎〃瀛楁闆� selectedTables: [], // 宸查�夎〃 - searchlist: null, // 鎼滅储鏉′欢闆� - visible: false // 妯℃�佹鎺у埗 } /** @@ -36,15 +33,28 @@ UNSAFE_componentWillMount () { const { config } = this.props + let tables = config.tables ? fromJS(config.tables).toJS() : [] + + window.GLOB.publicTables = tables + this.setState({ - selectedTables: config.tables ? fromJS(config.tables).toJS() : [] + selectedTables: tables }, () => { this.gettableFields() }) } componentDidMount () { + MKEmitter.addListener('publicTableChange', this.publicTableChange) this.gettables() + } + + publicTableChange = (table, type) => { + if (type === 'plus') { + this.onTableChange(table) + } else if (type === 'del') { + this.deleteTable(table) + } } /** @@ -59,13 +69,20 @@ } param.LText = Utils.formatOptions(param.LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 浜戠鏁版嵁楠岃瘉 - param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true) // 浜戠鏁版嵁楠岃瘉 + if (window.GLOB.cloudServiceApi) { // 涓斿瓨鍦ㄤ簯绔湴鍧� + param.rduri = window.GLOB.cloudServiceApi + param.userid = sessionStorage.getItem('CloudUserID') || '' + param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' + } - Api.getSystemConfig(param).then(res => { + Api.getSystemCacheConfig(param).then(res => { if (res.status) { + let tbNames = res.data.map(item => item.TbName).join(',') + sessionStorage.setItem('mk_tb_names', ',' + tbNames.toLowerCase() + ',') this.setState({ tables: res.data }) @@ -80,12 +97,21 @@ } gettableFields = () => { - let deffers = this.state.selectedTables.map(item => { + let deffers = this.state.selectedTables.map((item, i) => { return new Promise(resolve => { - Api.getSystemConfig({func: 'sPC_Get_FieldName', TBName: item.TbName}).then(res => { - res.TBName = item.TbName - resolve(res) - }) + let param = {func: 'sPC_Get_FieldName', TBName: item.TbName} + if (window.GLOB.cloudServiceApi) { // 涓斿瓨鍦ㄤ簯绔湴鍧� + param.rduri = window.GLOB.cloudServiceApi + param.userid = sessionStorage.getItem('CloudUserID') || '' + param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' + } + + setTimeout(() => { + Api.getSystemCacheConfig(param).then(res => { + res.TBName = item.TbName + resolve(res) + }) + }, (i + 1) * 100) }) }) Promise.all(deffers).then(response => { @@ -97,23 +123,19 @@ columns: res.FDName.map(item => { let _type = item.FieldType.toLowerCase() let _decimal = 0 + let _length = 50 if (/^nvarchar/.test(_type)) { + try { // 瀛樺湪max + _length = +_type.match(/\d+/)[0] || 50 + } catch (e) { + _length = 2048 + } _type = 'text' } else if (/^int/.test(_type)) { _type = 'number' } else if (/^decimal/.test(_type)) { _decimal = _type.split(',')[1] _decimal = parseInt(_decimal) - if (_decimal > 4) { - _decimal = 4 - } - _type = 'number' - } else if (/^decimal/.test(_type)) { - _decimal = _type.split(',')[1] - _decimal = parseInt(_decimal) - if (_decimal > 4) { - _decimal = 4 - } _type = 'number' } else if (/^datetime/.test(_type)) { _type = 'datetime' @@ -124,11 +146,13 @@ } return { - field: item.FieldName, + field: item.FieldName || '', label: item.FieldDec, type: _type, datatype: _type, - decimal: _decimal + decimal: _decimal, + length: _length, + $datatype: item.FieldType.toLowerCase() } }) } @@ -145,8 +169,7 @@ this.setState({ tableFields: _columns }) - - this.props.updatetable(this.props.config, _columns) + window.GLOB.tableFields = _columns }) } @@ -160,20 +183,31 @@ let _table = tables.filter(item => item.TbName === value)[0] let isSelected = !!selectedTables.filter(cell => cell.TbName === value)[0] if (!isSelected) { + let _tables = [...selectedTables, _table] + + window.GLOB.publicTables = _tables + this.setState({ - selectedTables: [...selectedTables, _table] + selectedTables: _tables }) - let _config = {...config, tables: [...selectedTables, _table]} - - Api.getSystemConfig({func: 'sPC_Get_FieldName', TBName: value}).then(res => { + let _config = {...config, tables: _tables} + + Api.getCloudConfig({func: 'sPC_Get_FieldName', TBName: value}).then(res => { if (res.status) { let tabmsg = { - tableName: _table.name, + tableName: _table.TbName, columns: res.FDName.map(item => { let _type = item.FieldType.toLowerCase() let _decimal = 0 + let _length = 50 + if (/^nvarchar/.test(_type)) { + try { // 瀛樺湪max + _length = +_type.match(/\d+/)[0] || 50 + } catch (e) { + _length = 2048 + } _type = 'text' } else if (/^int/.test(_type)) { _type = 'number' @@ -194,15 +228,22 @@ label: item.FieldDec, type: _type, datatype: _type, - decimal: _decimal + decimal: _decimal, + length: _length, + $datatype: item.FieldType.toLowerCase() } }) } + + let _columns = [...tableFields, tabmsg] + this.setState({ - tableFields: [...tableFields, tabmsg] + tableFields: _columns }) - this.props.updatetable(_config, [...tableFields, tabmsg]) + window.GLOB.tableFields = _columns + + this.props.updatetable(_config) } else { notification.warning({ top: 92, @@ -224,12 +265,16 @@ let _tables = selectedTables.filter(item => item.TbName !== table.TbName) let _fields = tableFields.filter(item => item.tableName !== table.TbName) + window.GLOB.publicTables = _tables + this.setState({ selectedTables: _tables, tableFields: _fields }) - this.props.updatetable({...config, tables: _tables}, _fields) + window.GLOB.tableFields = _fields + + this.props.updatetable({...config, tables: _tables}) } /** @@ -239,20 +284,21 @@ this.setState = () => { return } + MKEmitter.removeListener('publicTableChange', this.publicTableChange) } render() { const { containerId } = this.props - const { dict, tables, selectedTables } = this.state + const { tables, selectedTables } = this.state return ( - <div className="model-table-tablemanage-view"> + <div className="model-tablename-manage-view"> {/* 琛ㄥ悕娣诲姞 */} <div className="ant-col ant-form-item-label"> <label> - <Tooltip placement="topLeft" title={dict['model.tooltip.table.guide']}> - <Icon type="question-circle" /> - {dict['header.menu.table.add']} + <Tooltip placement="topLeft" title="姝ゅ鍙互娣诲姞椤甸潰閰嶇疆鐩稿叧鐨勫父鐢ㄨ〃銆�"> + <QuestionCircleOutlined className="mk-form-tip" /> + 琛ㄥ悕 </Tooltip> </label> </div> @@ -261,17 +307,19 @@ className="tables" style={{ width: '100%' }} optionFilterProp="children" - value={dict['header.menu.table.placeholder']} - onChange={this.onTableChange} + value="璇烽�夋嫨琛ㄥ悕" + onSelect={this.onTableChange} + dropdownClassName="mk-tables" + dropdownMatchSelectWidth={false} showArrow={false} - getPopupContainer={() => document.getElementById(containerId)} + getPopupContainer={() => containerId ? document.getElementById(containerId) : document.body} filterOption={(input, option) => { - return option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0 || - option.props.value.toLowerCase().indexOf(input.toLowerCase()) >= 0 + return option.props.children[0].toLowerCase().indexOf(input.toLowerCase()) >= 0 || + option.props.children[2].toLowerCase().indexOf(input.toLowerCase()) >= 0 }} > {tables.map((table, index) => ( - <Option key={index} title={table.TbName} value={table.TbName}>{table.Remark}</Option> + <Option key={index} title={table.TbName} value={table.TbName}>{table.Remark}<br/>{table.TbName}</Option> ))} </Select> {selectedTables.length > 0 && <List @@ -280,8 +328,7 @@ dataSource={selectedTables} renderItem={(item, index) => <List.Item key={index} title={item.Remark + ' (' + item.TbName + ')'}> {item.Remark + ' (' + item.TbName + ')'} - <Icon type="close" onClick={() => this.deleteTable(item)}/> - <div className="bottom-mask"></div> + <CloseOutlined onClick={() => this.deleteTable(item)}/> </List.Item>} />} </div> -- Gitblit v1.8.0