| | |
| | | systemScripts: [], |
| | | median: {}, |
| | | visible: false, |
| | | editLineId: '', |
| | | pvisible: false, |
| | | reload: false, |
| | | script: null, |
| | |
| | | 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, |
| | |
| | | |
| | | 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.getCloudConfig(_sParam).then(res => { |
| | |
| | | if (values.uuid) { |
| | | scripts = scripts.map(item => { |
| | | if (item.uuid === values.uuid) { |
| | | values.$index = item.$index || '' |
| | | return values |
| | | } else { |
| | | return item |
| | |
| | | |
| | | submitDataSource = () => { |
| | | const { config, mainSearch } = this.props |
| | | const { activeKey, setting, columns, subColumns, scripts, cols } = this.state |
| | | const { activeKey, setting, columns, subColumns, scripts, cols, median } = this.state |
| | | |
| | | if (config.subtype === 'dualdatacard') { |
| | | let arr = columns.map(col => col.field.toLowerCase()) |
| | |
| | | message: '子表中字段' + _arr.join('、') + '与主表字段重复!', |
| | | duration: 5 |
| | | }) |
| | | 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() |
| | | } |
| | | } |
| | |
| | | } |
| | | this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols }) }, 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, cols }) }, reject, 'submit') |
| | | } |
| | | }) |
| | |
| | | if (config.subtype === 'dualdatacard') { |
| | | _columns = [...columns, ...subColumns] |
| | | } |
| | | let r = SettingUtils.getDebugSql(setting, _scripts, _columns, searches, config.type) |
| | | |
| | | let r = SettingUtils.getDebugSql(setting, _scripts, _columns, searches, config.subtype) |
| | | |
| | | 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({ |
| | | title: `数据源或自定义脚本中使用自定义分页排序时,请在字段集中添加 mk_total。`, |
| | | okText: '知道了', |
| | | onOk: () => { |
| | | reject() |
| | | } |
| | | }) |
| | | return |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '数据源或自定义脚本中使用自定义分页排序时,请在显示列中添加 mk_total。', |
| | | duration: 5 |
| | | }) |
| | | } |
| | | } |
| | | |
| | | if (debugId === _debugId) { |
| | | resolve() |
| | |
| | | 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 = '搜索条件' |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | 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 = '子表字段集' |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | 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, |
| | |
| | | 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})}, 'script', _scripts) |
| | | } |
| | |
| | | } |
| | | |
| | | copyColumns = () => { |
| | | const { columns } = this.state |
| | | const { columns, setting } = this.state |
| | | |
| | | let m = [] |
| | | let n = [] |
| | | let s = [] |
| | |
| | | } |
| | | |
| | | 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'}` |
| | | |
| | | document.body.appendChild(oInput) |
| | | oInput.select() |
| | | document.execCommand('Copy') |
| | |
| | | |
| | | 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"> |
| | |
| | | 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} |
| | |
| | | <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} |
| | |
| | | </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}) |
| | | }}> |