| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { fromJS } from 'immutable' |
| | | import { Form, Tabs, Popconfirm, Icon, notification, Modal, Typography, Spin } from 'antd' |
| | | import { Form, Tabs, Popconfirm, Icon, notification, Modal, Typography, Spin, message } from 'antd' |
| | | import moment from 'moment' |
| | | |
| | | import Api from '@/api' |
| | |
| | | initsql: '', // sql验证时变量声明及赋值 |
| | | usefulfields: '', |
| | | defaultsql: '', // 默认Sql |
| | | defaultSearch: '', |
| | | systemScripts: [], |
| | | colColumns: [ |
| | | { |
| | |
| | | inputType: 'input', |
| | | editable: true, |
| | | unique: true, |
| | | copy: true, |
| | | width: '28%' |
| | | }, |
| | | { |
| | |
| | | getcomponentmarks(menu, config) |
| | | |
| | | let _setting = fromJS(config.setting).toJS() |
| | | let 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$`) |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | let _search = this.formatSearch(search) |
| | | _search = Utils.joinMainSearchkey(_search) |
| | | |
| | | _search = _search.replace(/@\$@/ig, '') |
| | | _search = _search ? 'where ' + _search : '' |
| | | |
| | | this.setState({ |
| | | scripts, |
| | | columns: fromJS(config.columns).toJS(), |
| | | setting: _setting, |
| | | scripts: fromJS(config.scripts).toJS(), |
| | | searches: search, |
| | | defaultSearch: _search, |
| | | varMarks: Marks |
| | | }) |
| | | |
| | |
| | | return |
| | | } |
| | | |
| | | let _search = this.formatSearch(search) |
| | | _search = Utils.joinMainSearchkey(_search) |
| | | |
| | | _search = _search.replace(/@\$@/ig, '') |
| | | _search = _search ? 'where ' + _search : '' |
| | | |
| | | this.setState({ |
| | | searches: search, |
| | | defaultSearch: _search, |
| | | setting: res |
| | | }, () => { |
| | | this.sqlverify(() => { // 验证成功 |
| | |
| | | } |
| | | |
| | | getdefaultSql = () => { |
| | | const { columns, searches, setting } = this.state |
| | | const { columns, setting, defaultSearch } = this.state |
| | | let defaultsql = '' |
| | | let arr_field = columns.map(col => col.field).join(',') |
| | | |
| | | let _search = this.formatSearch(searches) |
| | | _search = Utils.joinMainSearchkey(_search) |
| | | |
| | | _search = _search.replace(/@\$@/ig, '') |
| | | _search = _search ? 'where ' + _search : '' |
| | | |
| | | if (setting.dataresource) { |
| | | let _dataresource = setting.dataresource |
| | |
| | | _dataresource = '(' + _dataresource + ') tb' |
| | | } |
| | | |
| | | defaultsql = `select top @pageSize@ ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by @orderBy@) as rows from ${_dataresource} ${_search}) tmptable where rows > (@pageSize@ * (@pageIndex@ - 1)) order by tmptable.rows` |
| | | defaultsql = `select top @pageSize@ ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by @orderBy@) as rows from ${_dataresource} ${defaultSearch}) tmptable where rows > (@pageSize@ * (@pageIndex@ - 1)) order by tmptable.rows` |
| | | } |
| | | |
| | | this.setState({defaultsql}) |
| | |
| | | * @param {Array} searches 搜索条件数组 |
| | | */ |
| | | formatSearch (searches) { |
| | | if (!searches || searches.length === 0) return [] |
| | | if (!searches) return [] |
| | | |
| | | let newsearches = [] |
| | | searches.forEach(search => { |
| | |
| | | required: search.required === 'true' |
| | | } |
| | | if (item.type === 'group') { |
| | | let copy = fromJS(item).toJS() |
| | | copy.key = search.datefield |
| | | item.key = search.datefield |
| | | item.type = 'daterange' |
| | | item.match = 'between' |
| | | item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')].join(',') |
| | | |
| | | item.value = search.initval && search.initval[0] ? search.initval[0] : '@$@' |
| | | item.match = '=' |
| | | |
| | | copy.type = 'daterange' |
| | | copy.match = 'between' |
| | | copy.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')] |
| | | |
| | | if (search.transfer === 'true') { |
| | | newsearches.push(item) |
| | | } |
| | | newsearches.push(copy) |
| | | return |
| | | } else if (item.type === 'date') { |
| | | item.value = moment().format('YYYY-MM-DD') |
| | | } else if (item.type === 'datemonth') { |
| | | item.value = moment().format('YYYY-MM') |
| | | } else if (item.type === 'dateweek') { |
| | | item.value = [moment().startOf('week').format('YYYY-MM-DD'), moment().endOf('week').format('YYYY-MM-DD')] |
| | | item.value = moment().format('YYYY-MM-DD') |
| | | } else if (item.type === 'daterange') { |
| | | item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')] |
| | | } else if (item.type === 'multiselect') { |
| | | item.value = ['@$@'] |
| | | item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')].join(',') |
| | | } else if (item.type === 'range') { |
| | | |
| | | } else if (item.type === 'multiselect' || (item.type === 'checkcard' && search.multiple === 'true')) { |
| | | item.type = 'multi' |
| | | item.value = '@$@' |
| | | } else { |
| | | item.value = '@$@' |
| | | } |
| | |
| | | return |
| | | } |
| | | |
| | | let _search = this.formatSearch(search) |
| | | _search = Utils.joinMainSearchkey(_search) |
| | | |
| | | _search = _search.replace(/@\$@/ig, '') |
| | | _search = _search ? 'where ' + _search : '' |
| | | |
| | | this.setState({ |
| | | searches: search, |
| | | defaultSearch: _search, |
| | | setting: res |
| | | }, () => { |
| | | this.sqlverify(() => { resolve({setting: res, columns, scripts }) }, reject, false) |
| | |
| | | } |
| | | |
| | | sqlverify = (resolve, reject, change = false, testScripts) => { |
| | | const { columns, setting, scripts, searches } = this.state |
| | | const { columns, setting, scripts, searches, defaultSearch } = this.state |
| | | |
| | | let _scripts = scripts.filter(item => item.status !== 'false') |
| | | |
| | |
| | | } |
| | | |
| | | if ((setting.interType === 'system' && setting.execute !== 'false') || _scripts.length > 0) { |
| | | let result = SettingUtils.getDebugSql(setting, _scripts, columns, searches) |
| | | let result = SettingUtils.getDebugSql(setting, _scripts, columns, searches, defaultSearch) |
| | | |
| | | if (result.error) { |
| | | notification.warning({ |
| | |
| | | }) |
| | | } |
| | | |
| | | copyColumns = () => { |
| | | const { columns } = this.state |
| | | let m = [] |
| | | let n = [] |
| | | |
| | | columns.forEach(col => { |
| | | m.push(`${col.field}(${col.label})`) |
| | | n.push(col.field) |
| | | }) |
| | | |
| | | let oInput = document.createElement('input') |
| | | oInput.value = `/*${m.join(',')}*/ |
| | | ${n.join(',')}` |
| | | document.body.appendChild(oInput) |
| | | oInput.select() |
| | | document.execCommand('Copy') |
| | | document.body.removeChild(oInput) |
| | | |
| | | message.success('复制成功。') |
| | | } |
| | | |
| | | /** |
| | | * @description 组件销毁,清除state更新 |
| | | */ |
| | |
| | | type="fields" |
| | | updatefield={this.updatefields} |
| | | /> |
| | | <Icon type="copy" onClick={this.copyColumns} style={{position: 'absolute', cursor: 'pointer', zIndex: 1, top: '-35px', right: '0px', color: '#1890ff'}} /> |
| | | <EditTable actions={['edit', 'move', 'copy', 'del']} type="datasourcefield" data={columns} columns={colColumns} onChange={(columns) => this.setState({columns})}/> |
| | | </TabPane> |
| | | <TabPane tab={ |