| | |
| | | import PropTypes from 'prop-types' |
| | | import { fromJS } from 'immutable' |
| | | import { Form, Tabs, Popconfirm, notification, Modal, Typography, Spin, message, Button, Input } from 'antd' |
| | | import { StopOutlined, CheckCircleOutlined, EditOutlined, SwapOutlined, DeleteOutlined, CopyOutlined, BorderOutlined, SnippetsOutlined } from '@ant-design/icons' |
| | | 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' |
| | | |
| | | import { formatSearch, joinMainSearchkey } from '@/utils/utils-custom.js' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import ColForm from './columnform' |
| | | import CustomScriptsForm from './customscript' |
| | |
| | | const { TabPane } = Tabs |
| | | const { Paragraph } = Typography |
| | | const { Search } = Input |
| | | const { confirm } = Modal |
| | | |
| | | const CodeMirror = asyncComponent(() => import('@/templates/zshare/codemirror')) |
| | | const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent')) |
| | |
| | | |
| | | class VerifyCard extends Component { |
| | | static propTpyes = { |
| | | config: PropTypes.object, // 组件配置信息 |
| | | config: PropTypes.object, |
| | | updRecord: PropTypes.func |
| | | } |
| | | |
| | | state = { |
| | |
| | | subColumns: [], |
| | | activeKey: 'setting', |
| | | loading: false, |
| | | colLoading: false, |
| | | searchKey: '', |
| | | initsql: '', // sql验证时变量声明及赋值 |
| | | usefulfields: '', |
| | | defaultsql: '', // 默认Sql |
| | | defaultSearch: '', |
| | | defaultsql: '', |
| | | systemScripts: [], |
| | | median: {}, |
| | | visible: false, |
| | | editLineId: '', |
| | | pvisible: false, |
| | | reload: false, |
| | | script: null, |
| | | oriConfig: null, |
| | | scriptValue: '', |
| | | cols: null, |
| | | colColumns: [ |
| | | { |
| | | title: '名称', |
| | | dataIndex: 'label', |
| | | inputType: 'input', |
| | | editable: true, |
| | | searchable: true, |
| | | width: '28%' |
| | | }, |
| | | { |
| | |
| | | editable: true, |
| | | unique: true, |
| | | strict: true, |
| | | searchable: true, |
| | | copy: true, |
| | | rules: [{ |
| | | pattern: /^[\u4E00-\u9FA50-9a-zA-Z_]*$/ig, |
| | |
| | | { value: 'Nvarchar(512)', text: 'Nvarchar(512)' }, |
| | | { value: 'Nvarchar(1024)', text: 'Nvarchar(1024)' }, |
| | | { value: 'Nvarchar(2048)', text: 'Nvarchar(2048)' }, |
| | | { value: 'Nvarchar(4000)', text: 'Nvarchar(4000)' }, |
| | | { value: 'Nvarchar(max)', text: 'Nvarchar(max)' }, |
| | | { value: 'Int', text: 'Int' }, |
| | | { value: 'Decimal(18,0)', text: 'Decimal(18,0)' }, |
| | |
| | | { |
| | | title: 'SQL', |
| | | dataIndex: 'sql', |
| | | width: '72%', |
| | | width: '65%', |
| | | render: (text) => { |
| | | let title = text.match(/^\s*\/\*.+\*\//) |
| | | title = title && title[0] ? title[0] : '' |
| | |
| | | } |
| | | }, |
| | | { |
| | | title: '执行位置', |
| | | dataIndex: 'position', |
| | | width: '10%', |
| | | render: (text, record) => { |
| | | if (record.position === 'back') { |
| | | return <span style={{color: '#1890ff'}}>后置</span> |
| | | } else { |
| | | return <span style={{color: '#26C281'}}>前置</span> |
| | | } |
| | | } |
| | | }, |
| | | { |
| | | title: '状态', |
| | | dataIndex: 'status', |
| | | width: '13%', |
| | | width: '10%', |
| | | render: (text, record) => record.status === 'false' ? |
| | | ( |
| | | <div style={{color: '#ff4d4f'}}> |
| | |
| | | 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 _search = this.formatSearch(search) |
| | | _search = Utils.joinMainSearchkey(_search) |
| | | |
| | | _search = _search.replace(/@\$@/ig, '') |
| | | _search = _search ? 'where ' + _search : '' |
| | | 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)) { |
| | | col.datatype = col.datatype.replace(/^nvarchar/, 'Nvarchar') |
| | | } else if (/^decimal/.test(col.datatype)) { |
| | | col.datatype = col.datatype.replace(/^decimal/, 'Decimal') |
| | | } else if (/^int/.test(col.datatype)) { |
| | | col.datatype = col.datatype.replace(/^int/, 'Int') |
| | | } |
| | | }) |
| | | subColumns.forEach(col => { |
| | | if (!col.datatype) return |
| | | if (/^nvarchar/.test(col.datatype)) { |
| | | col.datatype = col.datatype.replace(/^nvarchar/, 'Nvarchar') |
| | | } else if (/^decimal/.test(col.datatype)) { |
| | | col.datatype = col.datatype.replace(/^decimal/, 'Decimal') |
| | | } else if (/^int/.test(col.datatype)) { |
| | | col.datatype = col.datatype.replace(/^int/, 'Int') |
| | | } |
| | | }) |
| | | |
| | | this.setState({ |
| | | scripts, |
| | |
| | | subColumns: subColumns, |
| | | setting: _setting, |
| | | median: _setting, |
| | | searches: search, |
| | | defaultSearch: _search, |
| | | searches: formatSearch(search), |
| | | searchKey: '', |
| | | debugId: _setting.debugId || '' |
| | | debugId: _setting.debugId || '', |
| | | oriConfig: fromJS({ |
| | | scripts, |
| | | columns: columns, |
| | | subColumns: subColumns, |
| | | setting: _setting |
| | | }).toJS() |
| | | }) |
| | | |
| | | this.getsysScript() |
| | |
| | | |
| | | let _scriptSql = `Select distinct func+Remark as funcname,longparam, s.Sort from s_custom_script s inner join (select OpenID from sapp where ID=@Appkey@) p on s.openid = case when s.appkey='' then s.openid else p.OpenID end order by s.Sort` |
| | | |
| | | _scriptSql = Utils.formatOptions(_scriptSql) |
| | | _scriptSql = Utils.formatOptions(_scriptSql, 'x') |
| | | |
| | | let _sParam = { |
| | | func: 'sPC_Get_SelectedList', |
| | | LText: _scriptSql, |
| | | obj_name: 'data', |
| | | arr_field: 'funcname,longparam' |
| | | arr_field: 'funcname,longparam', |
| | | exec_type: 'x' |
| | | } |
| | | |
| | | _sParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | _sParam.secretkey = Utils.encrypt(_sParam.LText, _sParam.timestamp) |
| | | |
| | | _sParam.secretkey = Utils.encrypt('', _sParam.timestamp) |
| | | _sParam.open_key = Utils.encryptOpenKey(_sParam.secretkey, _sParam.timestamp) // 云端数据验证 |
| | | |
| | | Api.getSystemConfig(_sParam).then(res => { |
| | | Api.getCloudConfig(_sParam).then(res => { |
| | | if (res.status) { |
| | | let _scripts = res.data.map(item => { |
| | | return { |
| | |
| | | if (values.uuid) { |
| | | scripts = scripts.map(item => { |
| | | if (item.uuid === values.uuid) { |
| | | values.$index = item.$index || '' |
| | | return values |
| | | } else { |
| | | return item |
| | |
| | | } |
| | | |
| | | return new Promise((resolve, reject) => { |
| | | this.sqlverify(resolve, reject, false, scripts) |
| | | this.sqlverify(resolve, reject, 'script', scripts) |
| | | }) |
| | | } |
| | | |
| | |
| | | search = [...search, ...mainSearch] |
| | | } |
| | | |
| | | let _search = this.formatSearch(search) |
| | | _search = Utils.joinMainSearchkey(_search) |
| | | |
| | | _search = _search.replace(/@\$@/ig, '') |
| | | _search = _search ? 'where ' + _search : '' |
| | | |
| | | this.setState({ |
| | | searches: search, |
| | | defaultSearch: _search, |
| | | searches: formatSearch(search), |
| | | setting: res |
| | | }, () => { |
| | | this.sqlverify(() => { // 验证成功 |
| | |
| | | loading: false |
| | | }) |
| | | this.getdefaultSql() |
| | | }, true) |
| | | }, 'change') |
| | | }) |
| | | }, () => { |
| | | this.setState({loading: false}) |
| | |
| | | } |
| | | |
| | | getdefaultSql = () => { |
| | | const { columns, setting, defaultSearch } = this.state |
| | | const { columns, setting, searches } = this.state |
| | | let defaultsql = '' |
| | | let arr_field = columns.map(col => col.field).join(',') |
| | | |
| | | let _search = joinMainSearchkey(searches) |
| | | |
| | | 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} ${defaultSearch}) 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} ${_search}) tmptable where rows > (@pageSize@ * (@pageIndex@ - 1)) order by tmptable.rows` |
| | | } |
| | | |
| | | this.setState({defaultsql}) |
| | | } |
| | | |
| | | /** |
| | | * @description 获取全部搜索条件 |
| | | * @param {Array} searches 搜索条件数组 |
| | | */ |
| | | formatSearch (searches) { |
| | | if (!searches) return [] |
| | | |
| | | let newsearches = [] |
| | | searches.forEach(search => { |
| | | if (!search.field) return |
| | | |
| | | let item = { |
| | | key: search.field, |
| | | match: search.match, |
| | | type: search.type, |
| | | label: search.label, |
| | | value: search.initval, |
| | | required: search.required === 'true' |
| | | } |
| | | if (item.type === 'group') { |
| | | item.key = search.datefield |
| | | item.type = 'daterange' |
| | | item.match = 'between' |
| | | item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')].join(',') |
| | | |
| | | newsearches.push(item) |
| | | 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().format('YYYY-MM-DD') |
| | | } else if (item.type === 'daterange') { |
| | | 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 = '@$@' |
| | | } |
| | | newsearches.push(item) |
| | | }) |
| | | |
| | | return newsearches |
| | | } |
| | | |
| | | submitDataSource = () => { |
| | | const { config, mainSearch } = this.props |
| | | const { activeKey, setting, columns, subColumns, scripts } = 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()) |
| | |
| | | }) |
| | | return Promise.reject() |
| | | } |
| | | } else if (config.subtype === 'editable') { |
| | | let _arr = [] |
| | | columns.forEach(col => { |
| | | let key = col.field.toLowerCase() |
| | | if (['jskey', 'data_type', 'bid'].includes(key)) { |
| | | _arr.push(col.field) |
| | | } |
| | | }) |
| | | |
| | | if (_arr.length > 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '字段集中不可使用' + _arr.join('、') + '!注:此字段为提交时的系统字段。', |
| | | duration: 5 |
| | | }) |
| | | return Promise.reject() |
| | | } |
| | | } |
| | | |
| | | if (median.interType === 'system') { |
| | | let _loading = false |
| | | if (this.scriptsForm && this.scriptsForm.state.editItem) { |
| | | _loading = true |
| | | } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.scriptsForm.props.form.getFieldValue('sql'))) { |
| | | _loading = true |
| | | } |
| | | |
| | | if (_loading) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '存在未保存脚本,请点击确定保存,或点击取消放弃修改!', |
| | | duration: 5 |
| | | }) |
| | | this.setState({activeKey: 'scripts'}) |
| | | return Promise.reject() |
| | | } |
| | | } |
| | | |
| | | return new Promise((resolve, reject) => { |
| | |
| | | if (res.useMSearch === 'true') { // 使用主搜索条件 |
| | | search = [...search, ...mainSearch] |
| | | } |
| | | |
| | | let _search = this.formatSearch(search) |
| | | _search = Utils.joinMainSearchkey(_search) |
| | | |
| | | _search = _search.replace(/@\$@/ig, '') |
| | | _search = _search ? 'where ' + _search : '' |
| | | let _searches = formatSearch(search) |
| | | |
| | | this.setState({ |
| | | searches: search, |
| | | defaultSearch: _search, |
| | | searches: _searches, |
| | | setting: res |
| | | }, () => { |
| | | this.sqlverify(() => { resolve({setting: res, columns, subColumns, scripts }) }, reject, false) |
| | | this.sqlverify(() => { resolve({setting: res, columns, subColumns, scripts, cols, searches: _searches }) }, reject, 'submit') |
| | | }) |
| | | }, () => { |
| | | reject() |
| | |
| | | reject() |
| | | return |
| | | } |
| | | this.sqlverify(() => { resolve({setting, columns, subColumns, scripts }) }, reject, false) |
| | | 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 }) }, reject, false) |
| | | this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols, searches }) }, reject, 'submit') |
| | | } else if (activeKey === 'scripts') { |
| | | let _loading = false |
| | | if (this.scriptsForm && this.scriptsForm.state.editItem) { |
| | | _loading = true |
| | | } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.scriptsForm.props.form.getFieldValue('sql'))) { |
| | | _loading = true |
| | | } |
| | | |
| | | if (_loading) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '存在未保存脚本,请点击确定保存,或点击取消放弃修改!', |
| | | duration: 5 |
| | | }) |
| | | reject() |
| | | return |
| | | } |
| | | |
| | | this.sqlverify(() => { resolve({setting, columns, subColumns, scripts }) }, reject, false) |
| | | this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols, searches }) }, reject, 'submit') |
| | | } |
| | | }) |
| | | } |
| | | |
| | | sqlverify = (resolve, reject, change = false, testScripts) => { |
| | | 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) => { |
| | | const { config } = this.props |
| | | const { columns, setting, scripts, searches, defaultSearch, debugId } = this.state |
| | | const { columns, setting, scripts, searches, debugId, subColumns } = this.state |
| | | |
| | | let _scripts = scripts.filter(item => item.status !== 'false') |
| | | |
| | | if (testScripts) { |
| | | _scripts = testScripts.filter(item => item.status !== 'false') |
| | | } |
| | | if (!change && setting.interType === 'system' && setting.execute === 'false' && _scripts.length === 0) { |
| | | if (type !== 'change' && setting.interType === 'system' && setting.execute === 'false' && _scripts.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '不执行默认sql时,请添加自定义脚本!', |
| | |
| | | return |
| | | } |
| | | |
| | | if (change && columns.length === 0) { |
| | | if (type === 'change' && columns.length === 0) { |
| | | reject() |
| | | return |
| | | } |
| | | |
| | | if ((setting.interType === 'system' && setting.execute !== 'false') || _scripts.length > 0) { |
| | | let timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | let r = SettingUtils.getDebugSql(setting, _scripts, columns, searches, defaultSearch, config.type, '2023-04-20 15:29:37') |
| | | let _columns = columns |
| | | if (config.subtype === 'dualdatacard') { |
| | | _columns = [...columns, ...subColumns] |
| | | } |
| | | |
| | | let _debugId = md5(r.sql) |
| | | let r = SettingUtils.getDebugSql(setting, _scripts, _columns, searches, config.subtype, config.hasExtend) |
| | | |
| | | if (debugId === _debugId) { |
| | | if (r.custompage && setting.laypage === 'true' && _columns.findIndex(col => col.field === 'mk_total') === -1) { |
| | | if (config.subtype !== 'basetable') { |
| | | Modal.warning({ |
| | | title: `数据源或自定义脚本中使用自定义分页排序时,请在字段集中添加 mk_total。`, |
| | | okText: '知道了', |
| | | onOk: () => { |
| | | reject() |
| | | } |
| | | }) |
| | | return |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '数据源或自定义脚本中使用自定义分页排序时,请在显示列中添加 mk_total。', |
| | | duration: 5 |
| | | }) |
| | | } |
| | | } |
| | | |
| | | if (debugId === r.debugId) { |
| | | resolve() |
| | | return |
| | | } |
| | |
| | | }) |
| | | } |
| | | |
| | | let param = { |
| | | func: 's_debug_sql', |
| | | exec_type: 'y', |
| | | LText: r.sql |
| | | } |
| | | param.LText = Utils.formatOptions(param.LText) |
| | | param.timestamp = timestamp |
| | | param.secretkey = Utils.encrypt('', timestamp) |
| | | Api.sDebug(r.sql).then(result => { |
| | | if (result.status || result.ErrCode === '-2') { |
| | | this.setState({debugId: r.debugId}, () => { |
| | | resolve() |
| | | }) |
| | | } else { |
| | | if (/列名\s*'[a-zA-Z0-9_-]+'\s*无效/.test(result.message)) { |
| | | let tail = '' |
| | | let type = '' |
| | | if (setting.execute !== 'false' && setting.queryType !== 'statistics') { |
| | | searches.forEach(item => { |
| | | if (item.forbid) return |
| | | item.key.split(',').forEach(field => { |
| | | if (new RegExp(`'${field}'`).test(result.message)) { |
| | | tail = field |
| | | type = '搜索条件' |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | let sumParam = null |
| | | if (r.sumSql) { |
| | | sumParam = { |
| | | func: 's_debug_sql', |
| | | exec_type: 'y', |
| | | LText: r.sumSql |
| | | } |
| | | sumParam.LText = Utils.formatOptions(sumParam.LText) |
| | | sumParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | sumParam.secretkey = Utils.encrypt('', sumParam.timestamp) |
| | | } |
| | | |
| | | Api.genericInterface(param).then(result => { |
| | | if (result.status) { |
| | | if (sumParam) { |
| | | Api.genericInterface(sumParam).then(res => { |
| | | if (res.status) { |
| | | this.setState({debugId: _debugId}, () => { |
| | | resolve() |
| | | if (!tail && setting.order) { |
| | | let keys = setting.order.replace(/\s+(asc|desc)/ig, '').replace(/\s+/g, '') |
| | | keys.split(',').forEach(field => { |
| | | if (new RegExp(`'${field}'`).test(result.message)) { |
| | | tail = field |
| | | type = '排序' |
| | | } |
| | | }) |
| | | } |
| | | |
| | | if (!tail) { |
| | | columns.forEach(item => { |
| | | if (new RegExp(`'${item.field}'`).test(result.message)) { |
| | | tail = item.field |
| | | if (config.subtype === 'basetable') { |
| | | type = '显示列' |
| | | } else { |
| | | type = '字段集' |
| | | } |
| | | } |
| | | }) |
| | | if (!tail && config.subtype === 'dualdatacard') { |
| | | subColumns.forEach(item => { |
| | | if (new RegExp(`'${item.field}'`).test(result.message)) { |
| | | tail = item.field |
| | | type = '子表字段集' |
| | | } |
| | | }) |
| | | } else { |
| | | } |
| | | } |
| | | |
| | | if (tail) { |
| | | result.message = result.message.replace(/ROLLBACK TRANSACTION 请求没有对应的 BEGIN TRANSACTION。/, '') |
| | | result.message = <>{result.message}<span style={{color: 'red'}}>注:{type}中存在字段{tail}</span></> |
| | | } |
| | | } |
| | | if (type === 'submit') { |
| | | Modal.confirm({ |
| | | title: result.message, |
| | | okText: '知道了', |
| | | cancelText: '强制保存', |
| | | onOk: () => { |
| | | reject() |
| | | Modal.error({ |
| | | title: res.message |
| | | }) |
| | | }, |
| | | onCancel() { |
| | | resolve() |
| | | } |
| | | }) |
| | | } else { |
| | | this.setState({debugId: _debugId}, () => { |
| | | resolve() |
| | | reject() |
| | | Modal.error({ |
| | | title: result.message, |
| | | okText: '知道了' |
| | | }) |
| | | } |
| | | } else { |
| | | reject() |
| | | Modal.error({ |
| | | title: result.message |
| | | }) |
| | | } |
| | | }) |
| | | } else { |
| | |
| | | return |
| | | } |
| | | |
| | | let editLineId = '' |
| | | if (script) { |
| | | editLineId = script.uuid |
| | | _scripts = _scripts.map(item => { |
| | | if (script.uuid === item.uuid) { |
| | | item.sql = scriptValue |
| | |
| | | status: 'true' |
| | | } |
| | | |
| | | editLineId = _script.uuid |
| | | _scripts.push(_script) |
| | | } |
| | | |
| | | this.setState({loading: true}) |
| | | this.setState({loading: true, editLineId}) |
| | | |
| | | this.sqlverify(() => {this.setState({scripts: _scripts, script: null, scriptValue: '', loading: false})}, () => {this.setState({loading: false})}, false, _scripts) |
| | | this.sqlverify(() => {this.setState({scripts: _scripts, script: null, scriptValue: '', loading: false})}, () => {this.setState({loading: false})}, 'script', _scripts) |
| | | } |
| | | |
| | | updatefields = (columns) => { |
| | |
| | | this.setState({reload: false}) |
| | | }) |
| | | } |
| | | |
| | | this.props.updRecord({...res.data.setting}) |
| | | }) |
| | | } |
| | | |
| | | updateStatus = (res) => { |
| | | this.setState({median: {...res}}) |
| | | this.props.updRecord({...res}) |
| | | } |
| | | |
| | | copyColumns = () => { |
| | | const { columns } = this.state |
| | | const { config } = this.props |
| | | const { columns, subColumns, setting } = this.state |
| | | |
| | | let _columns = columns |
| | | let m = [] |
| | | let n = [] |
| | | let s = [] |
| | | |
| | | columns.forEach(col => { |
| | | m.push(`${col.field} ${col.datatype}`) |
| | | n.push(col.field) |
| | | 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)) { |
| | | s.unshift(`${Math.round(Math.random() * 10)} as ${col.field}`) |
| | | } else if (/datetime/.test(col.datatype)) { |
| | | s.unshift(`'${moment().format('YYYY-MM-DD HH:mm:ss')}' as ${col.field}`) |
| | | } else if (/date/.test(col.datatype)) { |
| | | s.unshift(`'${moment().format('YYYY-MM-DD')}' as ${col.field}`) |
| | | } else { |
| | | s.unshift(`'${col.label}' as ${col.field}`) |
| | | } |
| | | }) |
| | | |
| | | if (window.debugger) { |
| | | 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') |
| | | oInput.value = `/*${m.join(',')}*/ |
| | | ${n.join(',')}` |
| | | oInput.value = `create table #${setting.tableName || 'tb'} |
| | | (${m.join(',')},sort_id INT IDENTITY(1,1)) |
| | | insert into #${setting.tableName || 'tb'} |
| | | (${n.join(',')}) |
| | | select ${n.join(',')} |
| | | from ${setting.dataresource ? `(${setting.dataresource.replace(/\n/g, ' ')}) tb` : setting.tableName || 'tb'} |
| | | order by @orderBy@ |
| | | |
| | | declare @mk_total int |
| | | set @mk_total = 0 |
| | | |
| | | select @mk_total = count(1) from #${setting.tableName || 'tb'} |
| | | declare @pageIndex_top int |
| | | set @pageIndex_top=(@pageIndex@-1)*@pageSize@ |
| | | |
| | | if @mk_total > @pageIndex@*@pageSize@ |
| | | delete #${setting.tableName || 'tb'} where sort_id > @pageIndex@*@pageSize@ |
| | | |
| | | if @pageIndex_top > 0 |
| | | delete #${setting.tableName || 'tb'} where sort_id <= @pageIndex_top |
| | | |
| | | drop table #${setting.tableName || 'tb'}${extend}` |
| | | |
| | | document.body.appendChild(oInput) |
| | | oInput.select() |
| | | document.execCommand('Copy') |
| | |
| | | message.success('复制成功。') |
| | | } |
| | | |
| | | addProcess = () => { |
| | | const { config } = this.props |
| | | const { columns } = this.state |
| | | |
| | | let fields = [] |
| | | let cols = [] |
| | | let _cols = columns.map(item => item.field.toLowerCase()) |
| | | |
| | | if (!_cols.includes('remark_w')) { |
| | | fields.push({ uuid: Utils.getuuid(), label: '备注', field: 'remark_w', datatype: 'Nvarchar(50)', fieldlength: 50, type: 'text' }) |
| | | cols.push({ uuid: Utils.getuuid(), Width: 120, label: '备注', field: 'remark_w', type: 'text', Hide: 'false', IsSort: 'false', fieldlength: 50 }) |
| | | } |
| | | if (!_cols.includes('statusname_w')) { |
| | | fields.push({ uuid: Utils.getuuid(), label: '状态', field: 'statusname_w', datatype: 'Nvarchar(50)', fieldlength: 50, type: 'text' }) |
| | | cols.push({ uuid: Utils.getuuid(), Width: 120, label: '状态', field: 'statusname_w', type: 'text', Hide: 'false', IsSort: 'false', fieldlength: 50 }) |
| | | } |
| | | if (!_cols.includes('works_flow_param')) { |
| | | fields.push({ uuid: Utils.getuuid(), label: '流程参数', field: 'works_flow_param', datatype: 'Nvarchar(512)', fieldlength: 512, type: 'text' }) |
| | | cols.push({ uuid: Utils.getuuid(), Width: 120, label: '流程参数', field: 'works_flow_param', type: 'text', Hide: 'true', IsSort: 'false', fieldlength: 512 }) |
| | | } |
| | | |
| | | if (fields.length === 0) return |
| | | |
| | | const that = this |
| | | |
| | | if (config.subtype !== 'basetable') { |
| | | cols = null |
| | | } |
| | | |
| | | confirm({ |
| | | content: cols ? '显示列中是否添加工作流字段?' : '字段集中是否添加工作流字段?', |
| | | onOk() { |
| | | that.setState({ |
| | | cols: cols, |
| | | columns: [...fields, ...columns] |
| | | }) |
| | | }, |
| | | onCancel() {} |
| | | }) |
| | | } |
| | | |
| | | updateColumns = (tableName) => { |
| | | const { config } = this.props |
| | | const { colLoading, columns } = this.state |
| | | |
| | | if (colLoading || columns.length > 0) return |
| | | |
| | | if (config.subtype === 'basetable') return |
| | | |
| | | let param = {func: 'sPC_Get_FieldName', TBName: tableName} |
| | | if (window.GLOB.cloudServiceApi) { // 且存在云端地址 |
| | | param.rduri = window.GLOB.cloudServiceApi |
| | | param.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } |
| | | |
| | | this.setState({colLoading: true}) |
| | | |
| | | Api.getSystemCacheConfig(param).then(result => { |
| | | this.setState({colLoading: false}) |
| | | if (!result.status) return |
| | | |
| | | let fields = [] |
| | | result.FDName.forEach(item => { |
| | | if (item.f_type !== 0) return |
| | | |
| | | if (/nvarchar|int|decimal/ig.test(item.FieldType) || item.FieldType === 'date' || item.FieldType === 'datetime') { |
| | | fields.unshift({ |
| | | uuid: Utils.getuuid(), |
| | | label: item.FieldDec, |
| | | field: item.FieldName, |
| | | datatype: item.FieldType.toLowerCase() |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | if (fields.length === 0) return |
| | | |
| | | this.setState({columns: fields}) |
| | | }, () => { |
| | | this.setState({colLoading: false}) |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * @description 组件销毁,清除state更新 |
| | | */ |
| | |
| | | |
| | | render() { |
| | | const { config } = this.props |
| | | const { columns, subColumns, median, setting, scripts, colColumns, scriptsColumns, activeKey, loading, searches, defaultsql, visible, pvisible, reload, script, scriptValue, searchKey } = this.state |
| | | const { columns, subColumns, median, setting, scripts, colColumns, scriptsColumns, activeKey, loading, searches, defaultsql, visible, pvisible, reload, script, scriptValue, searchKey, editLineId } = this.state |
| | | |
| | | return ( |
| | | <div className="model-data-source-wrap"> |
| | |
| | | subColumns={subColumns} |
| | | setting={setting} |
| | | scripts={scripts} |
| | | updateStatus={(res) => this.setState({median: {...res}})} |
| | | updateStatus={this.updateStatus} |
| | | updateColumns={this.updateColumns} |
| | | addProcess={this.addProcess} |
| | | wrappedComponentRef={(inst) => this.settingForm = inst} |
| | | /> : null} |
| | | </TabPane> |
| | | {config.subtype !== 'basetable' ? <TabPane tab={ |
| | | {!['basetable', 'invoice', 'invTable'].includes(config.subtype) ? <TabPane tab={ |
| | | <span> |
| | | 字段集 |
| | | {columns.length ? <span className="count-tip">{columns.length}</span> : null} |
| | |
| | | updatefield={this.updatefields} |
| | | /> |
| | | <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> : null} |
| | | </TabPane> : <TabPane tab={ |
| | | <span> |
| | | 字段集<TableOutlined style={{marginLeft: '5px', fontSize: '12px'}} /> |
| | | {columns.length ? <span className="count-tip">{columns.length}</span> : null} |
| | | </span> |
| | | } key="columns"> |
| | | <div className="base-table-columns"></div> |
| | | <EditTable actions={[]} searchKey={searchKey} type="datasourcefield" data={columns} columns={colColumns}/> |
| | | </TabPane>} |
| | | {config.subtype === 'dualdatacard' ? <TabPane tab={ |
| | | <span> |
| | | 子表字段集 |
| | |
| | | <span> |
| | | 自定义脚本 |
| | | {scripts.length ? <span className="count-tip">{scripts.length}</span> : null} |
| | | {config.type !== 'interface' && activeKey === 'setting' ? <CopyOutlined title="复制数据源" className="mk-copy-datasource" onClick={(e) => {e.stopPropagation();this.copyDatasource()}}/> : null} |
| | | {config.type !== 'interface' && activeKey === 'setting' ? <SnippetsOutlined title="导入数据源" className="mk-paste-datasource" onClick={(e) => {e.stopPropagation();this.setState({pvisible: true})}}/> : null} |
| | | {activeKey === 'setting' ? <CopyOutlined title="复制数据源" className="mk-copy-datasource" onClick={(e) => {e.stopPropagation();this.copyDatasource()}}/> : null} |
| | | {activeKey === 'setting' ? <SnippetsOutlined title="导入数据源" className="mk-paste-datasource" onClick={(e) => {e.stopPropagation();this.setState({pvisible: true})}}/> : null} |
| | | {activeKey === 'columns' ? <CopyOutlined title="以逗号拼接形式复制字段" className="mk-copy-fields" onClick={(e) => {e.stopPropagation();this.copyColumns()}}/> : null} |
| | | {activeKey === 'subcolumns' ? <CopyOutlined title="以逗号拼接形式复制字段" className="mk-copy-fields" onClick={(e) => {e.stopPropagation();this.copySubColumns()}}/> : null} |
| | | {activeKey === 'subcolumns' || activeKey === 'columns' ? <span onClick={(e) => {e.stopPropagation()}}><Search className="mk-search-fields" defaultValue={searchKey} allowClear onSearch={(val, e) => {e.stopPropagation();this.setState({searchKey: val})}} /></span> : null} |
| | |
| | | }) |
| | | return |
| | | } |
| | | this.setState({visible: true, script: null, scriptValue: ''}) |
| | | this.setState({visible: true, script: null, scriptValue: '', editLineId: ''}) |
| | | }}/> : 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} |
| | | scriptSubmit={this.scriptSubmit} |
| | | addProcess={this.addProcess} |
| | | wrappedComponentRef={(inst) => this.scriptsForm = inst} |
| | | /> |
| | | <EditTable actions={['move']} data={scripts} columns={scriptsColumns} onChange={this.changeScripts}/> |
| | |
| | | </div> |
| | | ) |
| | | } else { |
| | | let sign = '' |
| | | if (script && script.uuid === item.uuid) { |
| | | sign = 'active' |
| | | } else if (editLineId === item.uuid) { |
| | | sign = 'edited' |
| | | } |
| | | return ( |
| | | <div className={'script-item ' + (script && script.uuid === item.uuid ? 'active' : '') } key={item.uuid}> |
| | | <div className={'script-item ' + sign} key={item.uuid}> |
| | | <div style={{cursor: 'pointer'}} onClick={() => { |
| | | this.setState({script: item, scriptValue: item.sql}) |
| | | }}> |