From 4f2e4e84fd2cdca1407ac06c1b44319518be39b9 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 21 十二月 2020 19:11:05 +0800 Subject: [PATCH] 2020-12-21 --- src/menu/datasource/verifycard/index.jsx | 99 ++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 89 insertions(+), 10 deletions(-) diff --git a/src/menu/datasource/verifycard/index.jsx b/src/menu/datasource/verifycard/index.jsx index a5742f5..a8f732c 100644 --- a/src/menu/datasource/verifycard/index.jsx +++ b/src/menu/datasource/verifycard/index.jsx @@ -33,11 +33,8 @@ loading: false, initsql: '', // sql楠岃瘉鏃跺彉閲忓0鏄庡強璧嬪�� usefulfields: '', - defaultsql: '', // 榛樿Sql - systemScripts: [{ - name: '榛樿sql', - value: '' - }], + defaultsql: '', // 榛樿Sql + systemScripts: [], colColumns: [ { title: '鍚嶇О', @@ -227,7 +224,7 @@ }) this.setState({ - systemScripts: [...this.state.systemScripts, ..._scripts] + systemScripts: _scripts }) } else { notification.warning({ @@ -372,11 +369,13 @@ activeKey: val, loading: false }) + this.getdefaultSql() }, () => { // 楠岃瘉澶辫触 this.setState({ activeKey: val, loading: false }) + this.getdefaultSql() }, true) }) }, () => { @@ -387,6 +386,7 @@ activeKey: val, loading: false }) + this.getdefaultSql() } else if (activeKey === 'scripts') { let _loading = false if (this.scriptsForm && this.scriptsForm.state.editItem) { @@ -412,6 +412,84 @@ loading: false }) } + } + + getdefaultSql = () => { + const { columns, searches, setting } = 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 + + if (/\s/.test(_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` + } + + this.setState({defaultsql}) + } + + /** + * @description 鑾峰彇鍏ㄩ儴鎼滅储鏉′欢 + * @param {Array} searches 鎼滅储鏉′欢鏁扮粍 + */ + formatSearch (searches) { + if (!searches || searches.length === 0) 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') { + let copy = fromJS(item).toJS() + copy.key = search.datefield + + 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')] + } else if (item.type === 'daterange') { + item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')] + } else if (item.type === 'multiselect') { + item.value = ['@$@'] + } else { + item.value = '@$@' + } + newsearches.push(item) + }) + + return newsearches } submitDataSource = () => { @@ -542,12 +620,12 @@ render() { const { menu, config } = this.props - const { columns, setting, scripts, colColumns, scriptsColumns, activeKey, loading, searches } = this.state + const { columns, setting, scripts, colColumns, scriptsColumns, activeKey, loading, searches, defaultsql } = this.state return ( <div id="model-data-source-wrap"> {loading && <Spin size="large" />} - <Tabs activeKey={activeKey} className="verify-card-box" onChange={this.changeTab}> + <Tabs activeKey={activeKey} className="data-source-card-box" onChange={this.changeTab}> <TabPane tab="鏁版嵁婧�" key="setting"> <SettingForm menu={menu} @@ -567,7 +645,7 @@ tableFields={menu.tableFields} updatefield={this.updatefields} /> - <EditTable data={columns} columns={colColumns} onChange={(columns) => this.setState({columns})}/> + <EditTable actions={['edit', 'move', 'copy', 'del']} type="datasourcefield" data={columns} columns={colColumns} onChange={(columns) => this.setState({columns})}/> </TabPane> <TabPane tab={ <span> @@ -578,6 +656,7 @@ <CustomScriptsForm setting={setting} searches={searches} + defaultsql={defaultsql} initsql={this.state.initsql} dict={this.props.dict} customScripts={scripts} @@ -586,7 +665,7 @@ scriptSubmit={this.scriptSubmit} wrappedComponentRef={(inst) => this.scriptsForm = inst} /> - <EditTable data={scripts} actions={[]} columns={scriptsColumns} onChange={this.changeScripts}/> + <EditTable actions={['move']} data={scripts} columns={scriptsColumns} onChange={this.changeScripts}/> </TabPane> </Tabs> </div> -- Gitblit v1.8.0