| | |
| | | import { Form, Tabs, Popconfirm, notification, Modal, Typography, Spin, message, Button, Input } from 'antd' |
| | | import { StopOutlined, CheckCircleOutlined, TableOutlined, EditOutlined, SwapOutlined, DeleteOutlined, CopyOutlined, BorderOutlined, SnippetsOutlined } from '@ant-design/icons' |
| | | import moment from 'moment' |
| | | import md5 from 'md5' |
| | | |
| | | import Api from '@/api' |
| | | import Utils from '@/utils/utils.js' |
| | |
| | | const { Search } = Input |
| | | const { confirm } = Modal |
| | | |
| | | const ExcelOut = asyncComponent(() => import('./excelout')) |
| | | const CodeMirror = asyncComponent(() => import('@/templates/zshare/codemirror')) |
| | | const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent')) |
| | | const EditTable = asyncComponent(() => import('@/templates/zshare/editTable')) |
| | |
| | | loading: false, |
| | | colLoading: false, |
| | | searchKey: '', |
| | | initsql: '', // sql验证时变量声明及赋值 |
| | | usefulfields: '', |
| | | defaultsql: '', // 默认Sql |
| | | defaultsql: '', |
| | | systemScripts: [], |
| | | median: {}, |
| | | visible: false, |
| | |
| | | pvisible: false, |
| | | reload: false, |
| | | script: null, |
| | | oriConfig: null, |
| | | scriptValue: '', |
| | | cols: null, |
| | | colColumns: [ |
| | |
| | | let _setting = fromJS(config.setting).toJS() |
| | | let scripts = config.scripts ? fromJS(config.scripts).toJS() : [] |
| | | |
| | | if (window.GLOB.funcs && window.GLOB.funcs.length > 0) { |
| | | window.GLOB.funcs.forEach(m => { |
| | | let reg = new RegExp(`\\/\\*\\$ex@${m.func_code}-begin\\*\\/[\\s\\S]+\\/\\*@ex\\$-end\\*\\/`, 'ig') |
| | | if (_setting.dataresource) { |
| | | _setting.dataresource = _setting.dataresource.replace(reg, `$ex@${m.func_code}@ex$`) |
| | | } |
| | | scripts && scripts.forEach(item => { |
| | | item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`) |
| | | }) |
| | | }) |
| | | } |
| | | // if (window.GLOB.funcs && window.GLOB.funcs.length > 0) { |
| | | // window.GLOB.funcs.forEach(m => { |
| | | // let reg = new RegExp(`\\/\\*\\$ex@${m.func_code}-begin\\*\\/[\\s\\S]+\\/\\*@ex\\$-end\\*\\/`, 'ig') |
| | | // if (_setting.dataresource) { |
| | | // _setting.dataresource = _setting.dataresource.replace(reg, `$ex@${m.func_code}@ex$`) |
| | | // } |
| | | // scripts && scripts.forEach(item => { |
| | | // item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`) |
| | | // }) |
| | | // }) |
| | | // } |
| | | |
| | | let columns = config.columns ? fromJS(config.columns).toJS() : [] |
| | | let subColumns = config.subColumns ? fromJS(config.subColumns).toJS() : [] |
| | | |
| | | columns.reverse() |
| | | if (!config.fixedCol) { |
| | | columns.reverse() |
| | | } |
| | | subColumns.reverse() |
| | | |
| | | |
| | | columns.forEach(col => { |
| | | if (!col.datatype) return |
| | | if (/^nvarchar/.test(col.datatype)) { |
| | |
| | | median: _setting, |
| | | searches: formatSearch(search), |
| | | searchKey: '', |
| | | debugId: _setting.debugId || '' |
| | | debugId: _setting.debugId || '', |
| | | oriConfig: fromJS({ |
| | | scripts, |
| | | columns: columns, |
| | | subColumns: subColumns, |
| | | setting: _setting |
| | | }).toJS() |
| | | }) |
| | | |
| | | this.getsysScript() |
| | |
| | | |
| | | submitDataSource = () => { |
| | | const { config, mainSearch } = this.props |
| | | const { activeKey, setting, columns, subColumns, scripts, cols, median } = this.state |
| | | const { activeKey, setting, columns, subColumns, scripts, cols, median, searches } = this.state |
| | | |
| | | if (config.subtype === 'dualdatacard') { |
| | | let arr = columns.map(col => col.field.toLowerCase()) |
| | |
| | | if (res.useMSearch === 'true') { // 使用主搜索条件 |
| | | search = [...search, ...mainSearch] |
| | | } |
| | | let _searches = formatSearch(search) |
| | | |
| | | this.setState({ |
| | | searches: formatSearch(search), |
| | | searches: _searches, |
| | | setting: res |
| | | }, () => { |
| | | this.sqlverify(() => { resolve({setting: res, columns, subColumns, scripts, cols }) }, reject, 'submit') |
| | | this.sqlverify(() => { resolve({setting: res, columns, subColumns, scripts, cols, searches: _searches }) }, reject, 'submit') |
| | | }) |
| | | }, () => { |
| | | reject() |
| | |
| | | reject() |
| | | return |
| | | } |
| | | this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols }) }, reject, 'submit') |
| | | this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols, searches }) }, reject, 'submit') |
| | | } else if (activeKey === 'subcolumns') { |
| | | if (this.subdatasource && this.subdatasource.state.editingKey) { |
| | | notification.warning({ |
| | |
| | | reject() |
| | | return |
| | | } |
| | | this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols }) }, reject, 'submit') |
| | | this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols, searches }) }, reject, 'submit') |
| | | } else if (activeKey === 'scripts') { |
| | | this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols }) }, reject, 'submit') |
| | | this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols, searches }) }, reject, 'submit') |
| | | } |
| | | }) |
| | | } |
| | | |
| | | closeDataSource = (callback) => { |
| | | const { setting, columns, subColumns, scripts, oriConfig } = this.state |
| | | |
| | | let line = scripts.map(item => item.sql).join('') |
| | | line += columns.map(item => item.field + item.datatype).join('') |
| | | line += subColumns.map(item => item.field + item.datatype).join('') |
| | | line += setting.interType + (setting.dataresource || '') + (setting.order || '') + (setting.primaryKey || '') |
| | | |
| | | let _line = oriConfig.scripts.map(item => item.sql).join('') |
| | | _line += oriConfig.columns.map(item => item.field + item.datatype).join('') |
| | | _line += oriConfig.subColumns.map(item => item.field + item.datatype).join('') |
| | | _line += oriConfig.setting.interType + (oriConfig.setting.dataresource || '') + (oriConfig.setting.order || '') + (oriConfig.setting.primaryKey || '') |
| | | |
| | | if (line !== _line) { |
| | | confirm({ |
| | | content: '数据源已修改,确定取消吗?', |
| | | onOk() { |
| | | callback() |
| | | }, |
| | | onCancel() {} |
| | | }) |
| | | } else { |
| | | callback() |
| | | } |
| | | } |
| | | |
| | | sqlverify = (resolve, reject, type, testScripts) => { |
| | |
| | | _columns = [...columns, ...subColumns] |
| | | } |
| | | |
| | | let r = SettingUtils.getDebugSql(setting, _scripts, _columns, searches, config.subtype) |
| | | let r = SettingUtils.getDebugSql(setting, _scripts, _columns, searches, config.subtype, config.hasExtend) |
| | | |
| | | let _debugId = md5(r.sql) |
| | | |
| | | if (r.custompage && setting.laypage === 'true' && _columns.findIndex(col => col.field === 'mk_total') === -1) { |
| | | if (config.subtype !== 'basetable') { |
| | | Modal.warning({ |
| | |
| | | } |
| | | } |
| | | |
| | | if (debugId === _debugId) { |
| | | if (debugId === r.debugId) { |
| | | resolve() |
| | | return |
| | | } |
| | |
| | | |
| | | Api.sDebug(r.sql).then(result => { |
| | | if (result.status || result.ErrCode === '-2') { |
| | | this.setState({debugId: _debugId}, () => { |
| | | this.setState({debugId: r.debugId}, () => { |
| | | resolve() |
| | | }) |
| | | } else { |
| | |
| | | } |
| | | |
| | | copyColumns = () => { |
| | | const { columns, setting } = this.state |
| | | const { config } = this.props |
| | | const { columns, subColumns, setting } = this.state |
| | | |
| | | let _columns = columns |
| | | let m = [] |
| | | let n = [] |
| | | let s = [] |
| | | |
| | | columns.forEach(col => { |
| | | if (subColumns && subColumns.length) { |
| | | _columns = [...columns, ...subColumns] |
| | | } |
| | | |
| | | _columns.forEach(col => { |
| | | m.unshift(`${col.field} ${col.datatype}`) |
| | | n.unshift(col.field) |
| | | if (/decimal|int/ig.test(col.datatype)) { |
| | |
| | | }) |
| | | |
| | | if (window.debugger) { |
| | | console.info('select ' + s.join(', ')) |
| | | window.mkInfo('select ' + s.join(', ')) |
| | | } |
| | | |
| | | let extend = '' |
| | | if (config.hasExtend) { |
| | | extend = [] |
| | | let mapCol = (cols) => { |
| | | cols.forEach(col => { |
| | | if (col.type === 'extend') { |
| | | let datatype = 'Nvarchar(50)' |
| | | _columns.forEach(c => { |
| | | if (c.field === col.field) { |
| | | datatype = c.datatype |
| | | } |
| | | }) |
| | | for (let i = 1; i < col.quota; i++) { |
| | | extend.push(`${col.field}${i} ${datatype}`) |
| | | } |
| | | } else if (col.type === 'colspan' && col.subcols) { |
| | | mapCol(col.subcols) |
| | | } |
| | | }) |
| | | } |
| | | mapCol(config.cols) |
| | | extend = ` |
| | | /* 扩展列字段 */ |
| | | /* ${extend.join(',')} */ |
| | | ` |
| | | } |
| | | |
| | | let oInput = document.createElement('input') |
| | |
| | | if @pageIndex_top > 0 |
| | | delete #${setting.tableName || 'tb'} where sort_id <= @pageIndex_top |
| | | |
| | | drop table #${setting.tableName || 'tb'}` |
| | | drop table #${setting.tableName || 'tb'}${extend}` |
| | | |
| | | document.body.appendChild(oInput) |
| | | oInput.select() |
| | |
| | | addProcess = () => { |
| | | const { config } = this.props |
| | | const { columns } = this.state |
| | | |
| | | if (config.subtype === 'dualdatacard') return |
| | | |
| | | let fields = [] |
| | | let cols = [] |
| | |
| | | type="fields" |
| | | updatefield={this.updatefields} |
| | | /> |
| | | <ExcelOut data={columns} setting={setting}/> |
| | | <EditTable actions={['edit', 'move', 'copy', 'del', 'clear']} searchKey={searchKey} type="datasourcefield" wrappedComponentRef={(inst) => this.datasource = inst} data={columns} columns={colColumns} onChange={(columns) => this.setState({columns})}/> |
| | | </TabPane> : <TabPane tab={ |
| | | <span> |
| | |
| | | </span> |
| | | } key="columns"> |
| | | <div className="base-table-columns"></div> |
| | | <ExcelOut data={columns} setting={setting}/> |
| | | <EditTable actions={[]} searchKey={searchKey} type="datasourcefield" data={columns} columns={colColumns}/> |
| | | </TabPane>} |
| | | {config.subtype === 'dualdatacard' ? <TabPane tab={ |
| | |
| | | type="fields" |
| | | updatefield={this.updateSubfields} |
| | | /> |
| | | <ExcelOut data={subColumns} setting={setting}/> |
| | | <EditTable actions={['edit', 'move', 'copy', 'del', 'clear']} searchKey={searchKey} type="datasourcefield" wrappedComponentRef={(inst) => this.subdatasource = inst} data={subColumns} columns={colColumns} onChange={(subColumns) => this.setState({subColumns})}/> |
| | | </TabPane> : null} |
| | | <TabPane tab={ |
| | |
| | | }}/> : null} |
| | | <CustomScriptsForm |
| | | type={config.type} |
| | | hasExtend={config.hasExtend} |
| | | setting={setting} |
| | | searches={searches} |
| | | defaultsql={defaultsql} |
| | | initsql={this.state.initsql} |
| | | customScripts={scripts} |
| | | systemScripts={this.state.systemScripts} |
| | | scriptsChange={this.scriptsChange} |