From 9a1416e0b5cdb40f49b3c2061b04b35551d77e99 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 19 九月 2023 18:14:21 +0800 Subject: [PATCH] 2023-09-19 --- src/templates/sharecomponent/actioncomponent/verifyexcelout/utils.jsx | 133 -------- /dev/null | 45 --- src/menu/datasource/verifycard/utils.jsx | 79 ---- src/views/tabledesign/index.jsx | 4 src/templates/sharecomponent/settingcomponent/settingform/index.jsx | 157 --------- src/templates/zshare/customscript/index.jsx | 27 + src/menu/datasource/verifycard/customscript/index.jsx | 75 +--- src/utils/utils-custom.js | 172 +++++++++++ src/templates/sharecomponent/settingcomponent/settingform/utils.jsx | 110 +------ src/views/menudesign/index.jsx | 4 src/menu/datasource/verifycard/index.jsx | 89 ----- src/templates/sharecomponent/actioncomponent/verifyexcelout/index.jsx | 2 12 files changed, 274 insertions(+), 623 deletions(-) diff --git a/src/menu/datasource/verifycard/customscript/index.jsx b/src/menu/datasource/verifycard/customscript/index.jsx index 5babfa1..aee86c2 100644 --- a/src/menu/datasource/verifycard/customscript/index.jsx +++ b/src/menu/datasource/verifycard/customscript/index.jsx @@ -33,74 +33,41 @@ UNSAFE_componentWillMount() { const { searches } = this.props + this.getSearchField(searches) + } + + UNSAFE_componentWillReceiveProps (nextProps) { + if (!is(fromJS(this.props.searches), fromJS(nextProps.searches))) { + this.getSearchField(nextProps.searches) + } + } + + getSearchField = (searches) => { let _usefulFields = [] searches.forEach(item => { - if (!item.field) return - - if (item.type === 'group') { - _usefulFields.push(item.field) - _usefulFields.push(item.datefield) - _usefulFields.push(item.datefield + '1') - } else if (['dateweek', 'datemonth'].includes(item.type)) { - _usefulFields.push(item.field) - _usefulFields.push(item.field + '1') + if (['dateweek', 'datemonth'].includes(item.type)) { + _usefulFields.push(item.key) + _usefulFields.push(item.key + '1') } else if (item.type === 'daterange') { - let _skey = item.field - let _ekey = item.field + '1' + let _skey = item.key + let _ekey = item.key + '1' - if (/,/.test(item.field)) { - _skey = item.field.split(',')[0] - _ekey = item.field.split(',')[1] + if (/,/.test(item.key)) { + _skey = item.key.split(',')[0] + _ekey = item.key.split(',')[1] } _usefulFields.push(_skey) _usefulFields.push(_ekey) - } else if (item.type === 'date' && _usefulFields.includes(item.field)) { - _usefulFields.push(item.field + '1') + } else if (item.type === 'date' && _usefulFields.includes(item.key)) { + _usefulFields.push(item.key + '1') } else { - _usefulFields.push(item.field) + _usefulFields.push(item.key) } }) this.setState({ usefulFields: _usefulFields.join(', ') }) - } - - UNSAFE_componentWillReceiveProps (nextProps) { - if (!is(fromJS(this.props.searches), fromJS(nextProps.searches))) { - - let _usefulFields = [] - nextProps.searches.forEach(item => { - if (!item.field) return - - if (item.type === 'group') { - _usefulFields.push(item.field) - _usefulFields.push(item.datefield) - _usefulFields.push(item.datefield + '1') - } else if (['dateweek', 'datemonth'].includes(item.type)) { - _usefulFields.push(item.field) - _usefulFields.push(item.field + '1') - } else if (item.type === 'daterange') { - let _skey = item.field - let _ekey = item.field + '1' - - if (/,/.test(item.field)) { - _skey = item.field.split(',')[0] - _ekey = item.field.split(',')[1] - } - _usefulFields.push(_skey) - _usefulFields.push(_ekey) - } else if (item.type === 'date' && _usefulFields.includes(item.field)) { - _usefulFields.push(item.field + '1') - } else { - _usefulFields.push(item.field) - } - }) - - this.setState({ - usefulFields: _usefulFields.join(', ') - }) - } } edit = (record) => { diff --git a/src/menu/datasource/verifycard/index.jsx b/src/menu/datasource/verifycard/index.jsx index 266395c..97016ce 100644 --- a/src/menu/datasource/verifycard/index.jsx +++ b/src/menu/datasource/verifycard/index.jsx @@ -8,7 +8,7 @@ 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' @@ -44,7 +44,6 @@ initsql: '', // sql楠岃瘉鏃跺彉閲忓0鏄庡強璧嬪�� usefulfields: '', defaultsql: '', // 榛樿Sql - defaultSearch: '', systemScripts: [], median: {}, visible: false, @@ -210,11 +209,6 @@ }) } - 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() : [] @@ -227,8 +221,7 @@ subColumns: subColumns, setting: _setting, median: _setting, - searches: search, - defaultSearch: _search, + searches: formatSearch(search), searchKey: '', debugId: _setting.debugId || '' }) @@ -426,15 +419,8 @@ 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(() => { // 楠岃瘉鎴愬姛 @@ -513,9 +499,12 @@ } 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) + _search = _search ? 'where ' + _search : '' if (setting.dataresource) { let _dataresource = setting.dataresource @@ -524,59 +513,10 @@ _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 = () => { @@ -611,15 +551,8 @@ 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(() => { resolve({setting: res, columns, subColumns, scripts, cols }) }, reject, 'submit') @@ -674,7 +607,7 @@ sqlverify = (resolve, reject, type, testScripts) => { const { config } = this.props - const { columns, setting, scripts, searches, defaultSearch, debugId } = this.state + const { columns, setting, scripts, searches, debugId } = this.state let _scripts = scripts.filter(item => item.status !== 'false') @@ -697,7 +630,7 @@ } if ((setting.interType === 'system' && setting.execute !== 'false') || _scripts.length > 0) { - let r = SettingUtils.getDebugSql(setting, _scripts, columns, searches, defaultSearch, config.type) + let r = SettingUtils.getDebugSql(setting, _scripts, columns, searches, config.type) let _debugId = md5(r.sql) diff --git a/src/menu/datasource/verifycard/utils.jsx b/src/menu/datasource/verifycard/utils.jsx index ad11e06..cea7779 100644 --- a/src/menu/datasource/verifycard/utils.jsx +++ b/src/menu/datasource/verifycard/utils.jsx @@ -1,4 +1,6 @@ +import { getSearchRegs, joinMainSearchkey } from '@/utils/utils-custom.js' + export default class SettingUtils { /** * @description 鐢熸垚椤甸潰鏌ヨ璇彞 @@ -7,7 +9,7 @@ * @return {Object} setting 椤甸潰璁剧疆 * @return {Array} columns 鏄剧ず瀛楁 */ - static getDebugSql (setting, scripts, columns, searches = [], defSearch, type) { + static getDebugSql (setting, scripts, columns, searches = [], type) { let sql = '' let error = '' let _dataresource = '' @@ -95,85 +97,28 @@ } // 姝e垯鏇挎崲 - let _regoptions = [] - let _fields = [] let custompage = /@pageSize@|@orderBy@/i.test(_dataresource + _customScript) + let _regoptions = getSearchRegs(searches) - searches.forEach(item => { - if (!item.field) return - if (item.datefield) { - _regoptions.push({ - reg: new RegExp('@' + item.datefield + '@', 'ig') - }) - _regoptions.push({ - reg: new RegExp('@' + item.datefield + '1@', 'ig') - }) - } - if (['dateweek', 'datemonth', 'range'].includes(item.type)) { - _regoptions.push({ - reg: new RegExp('@' + item.field + '@', 'ig') - }) - _regoptions.push({ - reg: new RegExp('@' + item.field + '1@', 'ig') - }) - } else if (item.type === 'daterange') { - let _skey = item.field - let _ekey = item.field + '1' - - if (/,/.test(item.field)) { - _skey = item.field.split(',')[0] - _ekey = item.field.split(',')[1] - } - - _regoptions.push({ - reg: new RegExp('@' + _skey + '@', 'ig') - }) - _regoptions.push({ - reg: new RegExp('@' + _ekey + '@', 'ig') - }) - } else if (item.type === 'date') { - if (_fields.includes(item.field)) { - _regoptions.push({ - reg: new RegExp('@' + item.field + '1@', 'ig') - }) - } else { - _fields.push(item.field) - _regoptions.push({ - reg: new RegExp('@' + item.field + '@', 'ig') - }) - } - } else if (item.type === 'text' || item.type === 'select') { - item.field.split(',').forEach(field => { - _regoptions.push({ - reg: new RegExp('@' + field + '@', 'ig') - }) - }) - } else { - _regoptions.push({ - reg: new RegExp('@' + item.field + '@', 'ig') - }) - } - }) + let _search = joinMainSearchkey(searches) + _search = _search ? 'where ' + _search : '' _regoptions.push({ reg: new RegExp('@orderBy@', 'ig'), - }, { - reg: new RegExp('@UserName@', 'ig'), - }, { - reg: new RegExp('@FullName@', 'ig'), + value: setting.order || '' }, { reg: new RegExp('@pageSize@', 'ig'), + value: 9999 }, { reg: new RegExp('@pageIndex@', 'ig'), + value: 1 }) _regoptions.forEach(item => { - _dataresource = _dataresource.replace(item.reg, '0') - _customScript = _customScript.replace(item.reg, '0') - _tailScript = _tailScript.replace(item.reg, '0') + _dataresource = _dataresource.replace(item.reg, item.value || '0') + _customScript = _customScript.replace(item.reg, item.value || '0') + _tailScript = _tailScript.replace(item.reg, item.value || '0') }) - - let _search = defSearch if (setting.queryType === 'statistics') { _search = '' diff --git a/src/templates/sharecomponent/actioncomponent/verifyexcelout/index.jsx b/src/templates/sharecomponent/actioncomponent/verifyexcelout/index.jsx index 85e463d..f3efa4d 100644 --- a/src/templates/sharecomponent/actioncomponent/verifyexcelout/index.jsx +++ b/src/templates/sharecomponent/actioncomponent/verifyexcelout/index.jsx @@ -884,7 +884,7 @@ return } - let sql = SettingUtils.getDebugSql(verify, scripts, (verify.useSearch === 'true' ? searches : []), Utils) + let sql = SettingUtils.getDebugSql(verify, scripts, (verify.useSearch === 'true' ? searches : [])) let _debugId = md5(sql) diff --git a/src/templates/sharecomponent/actioncomponent/verifyexcelout/utils.jsx b/src/templates/sharecomponent/actioncomponent/verifyexcelout/utils.jsx index 939f64d..e3b1342 100644 --- a/src/templates/sharecomponent/actioncomponent/verifyexcelout/utils.jsx +++ b/src/templates/sharecomponent/actioncomponent/verifyexcelout/utils.jsx @@ -1,18 +1,17 @@ -import moment from 'moment' +import { formatSearch, getSearchRegs, joinMainSearchkey } from '@/utils/utils-custom.js' export default class SettingUtils { /** * @description 鐢熸垚椤甸潰鏌ヨ璇彞 */ - static getDebugSql (verify, scripts, searches, Utils) { + static getDebugSql (verify, scripts, searches) { let sql = '' let _dataresource = verify.dataresource || '' - let regoptions = this.getRegOptions(searches) - let _search = this.formatSearch(searches) - _search = Utils.joinMainSearchkey(_search) + let _search = formatSearch(searches) + let regoptions = getSearchRegs(_search) - _search = _search.replace(/@\$@/ig, '') + _search = joinMainSearchkey(_search) _search = _search ? 'where ' + _search : '' let arr_field = [] @@ -129,127 +128,5 @@ } return sql - } - - /** - * @description 鑾峰彇鍏ㄩ儴鎼滅储鏉′欢 - * @param {Array} searches 鎼滅储鏉′欢鏁扮粍 - */ - static 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') { - 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 === 'multiselect' || (item.type === 'checkcard' && search.multiple === 'true')) { - item.type = 'multi' - item.value = '@$@' - } else { - item.value = '@$@' - } - newsearches.push(item) - }) - - return newsearches - } - - /** - * @description 鑾峰彇鎼滅储鐢ㄤ簬姝e垯鏇挎崲 - * @param {Array} searches 鎼滅储鏉′欢 - * @return {String} searchText 鎷兼帴缁撴灉 - */ - static getRegOptions (searches) { - if (!searches || searches.length === 0) return [] - - let options = [] - let fieldmap = new Map() - searches.forEach(search => { - let item = { - key: search.field, - value: '0' - } - - if (fieldmap.has(item.key)) { - item.key = item.key + '1' - } - - fieldmap.set(item.key, true) - - if (search.type === 'group') { - options.push({ - key: search.field, - value: '0' - }) - options.push({ - key: search.datefield, - value: '0' - }) - options.push({ - key: search.datefield + '1', - value: '0' - }) - options.push(item) - } else if (['datemonth', 'dateweek'].includes(search.type)) { - options.push(item) - options.push({ - key: item.key + '1', - value: '0' - }) - } else if (search.type === 'daterange') { - let _skey = search.field - let _ekey = search.field + '1' - - if (/,/.test(search.field)) { - _skey = search.field.split(',')[0] - _ekey = search.field.split(',')[1] - } - - options.push({ - key: _skey, - value: '0' - }) - options.push({ - key: _ekey, - value: '0' - }) - } else if (search.type === 'text' || search.type === 'select') { - item.key.split(',').forEach(field => { - let cell = JSON.parse(JSON.stringify(item)) - cell.key = field - - options.push(cell) - }) - } else { - options.push(item) - } - }) - - return options } } \ No newline at end of file diff --git a/src/templates/sharecomponent/settingcomponent/settingform/index.jsx b/src/templates/sharecomponent/settingcomponent/settingform/index.jsx index c796d48..3c65cb8 100644 --- a/src/templates/sharecomponent/settingcomponent/settingform/index.jsx +++ b/src/templates/sharecomponent/settingcomponent/settingform/index.jsx @@ -3,10 +3,10 @@ import { fromJS } from 'immutable' import { Form, notification, Modal, Spin, Tabs, Typography, Popconfirm, Button } from 'antd' import { CheckCircleOutlined, StopOutlined, SwapOutlined, DeleteOutlined, BorderOutlined } from '@ant-design/icons' -import moment from 'moment' import Api from '@/api' import Utils from '@/utils/utils.js' +import { formatSearch, joinMainSearchkey } from '@/utils/utils-custom.js' import SettingUtils from './utils.jsx' import asyncComponent from '@/utils/asyncComponent' import DataSource from './datasource' @@ -30,9 +30,8 @@ formlist: [], btnloading: false, activeKey: 'setting', - search: '', + searches: [], arr_field: '', - regoptions: [], setting: null, defaultSql: '', visible: false, @@ -78,25 +77,7 @@ }) } - // 鎼滅储鐨剋here鏉′欢 - let _search = this.formatSearch(search) - _search = Utils.joinMainSearchkey(_search) - - _search = _search.replace(/@\$@/ig, '') - _search = _search ? 'where ' + _search : '' - let status = fromJS(_setting).toJS() - let regoptions = this.getRegOptions(search) - - if (config.urlFields && config.urlFields.length > 0) { - config.urlFields.forEach(field => { - regoptions.push({ - key: field, - value: '0', - type: 'url' - }) - }) - } if (window.GLOB.funcs && window.GLOB.funcs.length > 0) { window.GLOB.funcs.forEach(m => { @@ -112,9 +93,8 @@ this.setState({ setting: _setting, - search: _search, + searches: formatSearch(search), arr_field: arr_field.join(','), - regoptions: regoptions, // 鎼滅储鏉′欢锛屾鍒欐浛鎹� columns: columns, scripts: _scripts, status @@ -123,123 +103,6 @@ componentDidMount () { this.props.updRecord(this.state.status) - } - - getRegOptions = (searches) => { - if (!searches || searches.length === 0) return [] - - let options = [] - let fieldmap = new Map() - searches.forEach(search => { - let item = { - key: search.field, - value: '0' - } - - if (fieldmap.has(item.key)) { - item.key = item.key + '1' - } - - fieldmap.set(item.key, true) - - if (search.type === 'group') { - options.push({ - key: search.field, - value: '0' - }) - options.push({ - key: search.datefield, - value: '0' - }) - options.push({ - key: search.datefield + '1', - value: '0' - }) - options.push(item) - } else if (['datemonth', 'dateweek'].includes(search.type)) { - options.push(item) - options.push({ - key: item.key + '1', - value: '0' - }) - } else if (search.type === 'daterange') { - let _skey = search.field - let _ekey = search.field + '1' - - if (/,/.test(search.field)) { - _skey = search.field.split(',')[0] - _ekey = search.field.split(',')[1] - } - - options.push({ - key: _skey, - value: '0' - }) - options.push({ - key: _ekey, - value: '0' - }) - } else if (search.type === 'text' || search.type === 'select') { - item.key.split(',').forEach(field => { - let cell = JSON.parse(JSON.stringify(item)) - cell.key = field - - options.push(cell) - }) - } else { - options.push(item) - } - }) - - return options - } - - /** - * @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') { - 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 === 'multiselect' || (item.type === 'checkcard' && search.multiple === 'true')) { - item.type = 'multi' - item.value = '@$@' - } else { - item.value = '@$@' - } - newsearches.push(item) - }) - - return newsearches } handleConfirm = (trigger) => { @@ -297,7 +160,8 @@ } sqlverify = (_resolve, _reject, type, uscripts) => { - const { setting, scripts, arr_field, regoptions, search } = this.state + const { config } = this.props + const { setting, scripts, arr_field, searches } = this.state if (setting.interType !== 'system') { // 涓嶄娇鐢ㄧ郴缁熸帴鍙f椂锛屼笉闇�瑕乻ql楠岃瘉 _resolve() @@ -316,7 +180,7 @@ } else if (type === 'scripts' && _scripts.length === 0) { _resolve() } else { // type 涓� submit 銆� verify 锛屼互鍙婂叾浠栭渶瑕侀獙璇佺殑鍦烘櫙 - let r = SettingUtils.getDebugSql(setting, _scripts, arr_field, regoptions, search) + let r = SettingUtils.getDebugSql(setting, _scripts, arr_field, searches, config.urlFields) if (r.errors) { notification.warning({ @@ -341,7 +205,7 @@ // 鏍囩鍒囨崲 changeTab = (val) => { - const { activeKey, search, arr_field } = this.state + const { activeKey, searches, arr_field } = this.state if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.scriptsForm.props.form.getFieldValue('sql'))) { notification.warning({ @@ -357,11 +221,14 @@ if (res.dataresource) { let _dataresource = res.dataresource + let _search = joinMainSearchkey(searches) + _search = _search ? 'where ' + _search : '' + 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` + _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({ @@ -517,7 +384,7 @@ scripts={scripts} defaultSql={defaultSql} urlFields={config.urlFields} - searches={this.props.search} + searches={this.state.searches} scriptsChange={this.scriptsChange} scriptsUpdate={this.scriptsUpdate} wrappedComponentRef={(inst) => this.scriptsForm = inst} diff --git a/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx b/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx deleted file mode 100644 index 42ee457..0000000 --- a/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.jsx +++ /dev/null @@ -1,500 +0,0 @@ -import React, {Component} from 'react' -import PropTypes from 'prop-types' -import { fromJS } from 'immutable' -import { Form, Row, Col, Button, notification, Select, Popconfirm, Typography, Modal, Radio, Tooltip } from 'antd' -import { StopOutlined, CheckCircleOutlined, EditOutlined, SwapOutlined, DeleteOutlined } from '@ant-design/icons' -import moment from 'moment' - -import Utils from '@/utils/utils.js' -import Api from '@/api' -import SettingUtils from '../utils' -import CodeMirror from '@/templates/zshare/codemirror' -import asyncComponent from '@/utils/asyncComponent' -import './index.scss' - -const { Paragraph } = Typography -const EditTable = asyncComponent(() => import('@/templates/zshare/editTable')) - -class CustomForm extends Component { - static propTpyes = { - setting: PropTypes.object, // 璁剧疆 - scripts: PropTypes.array, // 鑷畾涔夎剼鏈垪琛� - searches: PropTypes.array, // 鎼滅储鏉′欢 - urlFields: PropTypes.any, // url鍙橀噺 - regoptions: PropTypes.any, // 姝e垯鏇挎崲 - scriptsChange: PropTypes.func, // 鑷畾涔夎剼鏈垏鎹㈡椂楠岃瘉 - scriptsUpdate: PropTypes.func // 琛ㄥ崟 - } - - state = { - wrapId: Utils.getuuid(), - editItem: null, - loading: false, - usefulFields: '', - urlFields: '', - systemScripts: [], - scriptsColumns: [ - { - title: 'SQL', - dataIndex: 'sql', - width: '60%', - render: (text) => { - let title = text.match(/^\s*\/\*.+\*\//) - title = title && title[0] ? title[0] : '' - let _text = title ? text.replace(title, '') : text - - return ( - <div> - {title ? <span style={{color: '#a50'}}>{title}<span style={{fontSize: '12px', marginLeft: '5px'}}>{_text.length}</span></span> : null} - <Paragraph copyable={{ text: text }} ellipsis={{ rows: 4, expandable: true }}>{_text}</Paragraph> - </div> - ) - } - }, - { - title: '鎵ц浣嶇疆', - dataIndex: 'position', - width: '13%', - render: (text, record) => { - if (record.position === 'front') { - return <span style={{color: '#26C281'}}>sql鍓�</span> - } else { - return <span style={{color: '#1890ff'}}>sql鍚�</span> - } - } - }, - { - title: '鐘舵��', - dataIndex: 'status', - width: '12%', - render: (text, record) => record.status === 'false' ? - ( - <div style={{color: '#ff4d4f'}}> - 绂佺敤 - <StopOutlined style={{marginLeft: '5px'}} /> - </div> - ) : - ( - <div style={{color: '#26C281'}}> - 鍚敤 - <CheckCircleOutlined style={{marginLeft: '5px'}}/> - </div> - ) - }, - { - title: '鎿嶄綔', - align: 'center', - width: '15%', - dataIndex: 'operation', - render: (text, record) => - (<div style={{textAlign: 'center'}}> - <span className="operation-btn" title="缂栬緫" onClick={() => this.handleEdit(record)} style={{color: '#1890ff'}}><EditOutlined /></span> - <span className="operation-btn" title="鐘舵�佸垏鎹�" onClick={() => this.handleStatus(record)} style={{color: '#8E44AD'}}><SwapOutlined /></span> - <Popconfirm - overlayClassName="popover-confirm" - title="纭畾鍒犻櫎鍚�?" - onConfirm={() => this.handleDelete(record) - }> - <span className="operation-btn" style={{color: '#ff4d4f'}}><DeleteOutlined /></span> - </Popconfirm> - </div>) - } - ] - } - - UNSAFE_componentWillMount() { - const { searches, scripts, urlFields } = this.props - - let _usefulFields = [] - let scriptsColumns = fromJS(this.state.scriptsColumns).toJS() - let _urlFields = '' - - if (searches) { - searches.forEach(item => { - if (!item.field) return - if (item.type === 'group') { - _usefulFields.push(item.field) - _usefulFields.push(item.datefield) - _usefulFields.push(item.datefield + '1') - } else if (['dateweek', 'datemonth', 'daterange'].includes(item.type)) { - _usefulFields.push(item.field) - _usefulFields.push(item.field + '1') - } else if (_usefulFields.includes(item.field)) { - _usefulFields.push(item.field + '1') - } else { - _usefulFields.push(item.field.replace(/,/ig, ', ')) - } - }) - - _urlFields = urlFields ? urlFields.join(', ') : '' - _usefulFields = _usefulFields.join(', ') - scriptsColumns = scriptsColumns.filter(item => { - if (item.dataIndex === 'sql') { - item.width = '70%' - } - return item.dataIndex !== 'position' - }) - } else { - _usefulFields = null - } - - this.setState({ - urlFields: _urlFields, - usefulFields: _usefulFields, - scripts: fromJS(scripts).toJS(), - scriptsColumns - }) - } - - componentDidMount () { - this.getsysScript() - } - - getsysScript = () => { - if (sessionStorage.getItem('mk_sys_scripts')) { - this.setState({ - systemScripts: JSON.parse(sessionStorage.getItem('mk_sys_scripts')) - }) - return - } - - 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) - - let _sParam = { - func: 'sPC_Get_SelectedList', - LText: _scriptSql, - obj_name: 'data', - arr_field: 'funcname,longparam' - } - - _sParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') - _sParam.secretkey = Utils.encrypt(_sParam.LText, _sParam.timestamp) - _sParam.open_key = Utils.encryptOpenKey(_sParam.secretkey, _sParam.timestamp) // 浜戠鏁版嵁楠岃瘉 - - Api.getCloudConfig(_sParam).then(res => { - if (res.status) { - let _scripts = res.data.map(item => { - return { - name: item.funcname, - value: window.decodeURIComponent(window.atob(item.longparam)) - } - }) - - sessionStorage.setItem('mk_sys_scripts', JSON.stringify(_scripts)) - - this.setState({ - systemScripts: _scripts - }) - } else { - notification.warning({ - top: 92, - message: res.message, - duration: 5 - }) - } - }) - } - - handleCancel = () => { - this.setState({ - editItem: null - }) - this.props.form.setFieldsValue({ - sql: '' - }) - } - - handleConfirm = () => { - const { scripts, editItem } = this.state - - let _sql = this.props.form.getFieldValue('sql') - - if (!_sql) { - notification.warning({ - top: 92, - message: '璇峰~鍐欒嚜瀹氫箟鑴氭湰锛�', - duration: 5 - }) - return - } else if (/^\s+$/.test(_sql)) { - notification.warning({ - top: 92, - message: '鑷畾涔夎剼鏈笉鍙负绌猴紒', - duration: 5 - }) - return - } - - let values = { - uuid: editItem && editItem.uuid ? editItem.uuid : Utils.getuuid(), - sql: _sql, - } - - if (this.props.form.getFieldValue('position')) { - values.position = this.props.form.getFieldValue('position') - } - - let _quot = values.sql.match(/'{1}/g) - let _lparen = values.sql.match(/\({1}/g) - let _rparen = values.sql.match(/\){1}/g) - - _quot = _quot ? _quot.length : 0 - _lparen = _lparen ? _lparen.length : 0 - _rparen = _rparen ? _rparen.length : 0 - - if (_quot % 2 !== 0) { - notification.warning({ - top: 92, - message: 'sql涓璡'蹇呴』鎴愬鍑虹幇', - duration: 5 - }) - return - } else if (_lparen !== _rparen) { - notification.warning({ - top: 92, - message: 'sql涓�()蹇呴』鎴愬鍑虹幇', - duration: 5 - }) - return - } else if (/--/ig.test(values.sql)) { - notification.warning({ - top: 92, - message: '鑷畾涔塻ql璇彞涓紝涓嶅彲鍑虹幇瀛楃 -- 锛屾敞閲婅鐢� /*鍐呭*/', - duration: 5 - }) - return - } else if (/,,/ig.test(values.sql)) { - notification.warning({ - top: 92, - message: '鑷畾涔塻ql璇彞涓紝涓嶅彲鍑虹幇杩炵画鐨勮嫳鏂囬�楀彿锛�,,锛�', - duration: 5 - }) - return - } - - let error = Utils.verifySql(values.sql, 'customscript') - - if (error) { - notification.warning({ - top: 92, - message: 'sql涓笉鍙娇鐢�' + error, - duration: 5 - }) - return - } - - let _scripts = fromJS(scripts).toJS() - - if (editItem && editItem.uuid) { - _scripts = _scripts.map(item => { - if (item.uuid === values.uuid) { - return values - } else { - return item - } - }) - } else { - _scripts.push(values) - } - - let sql = SettingUtils.getCustomDebugSql(_scripts, this.props.regoptions) - sql = sql.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id)@/ig, `'1949-10-01 15:00:00'`) - - this.setState({loading: true}) - Api.sDebug(sql).then(result => { - if (result.status || result.ErrCode === '-2') { - this.setState({ - loading: false, - scripts: _scripts, - editItem: null - }) - - this.props.scriptsUpdate(_scripts) - this.props.form.setFieldsValue({ - sql: '' - }) - } else { - this.setState({loading: false}) - Modal.error({ - title: result.message - }) - } - }) - } - - selectScript = (value, option) => { - if (!value || !option) return - let _sql = this.props.form.getFieldValue('sql') - if (_sql) { - _sql = _sql + ` - - ` - } - - _sql = _sql.replace(/\s{6}$/, '') - _sql = _sql + `/*${option.props.children}*/ - ` - _sql = _sql.replace(/\s{4}$/, '') - _sql = _sql + value - - this.props.form.setFieldsValue({ - sql: _sql - }) - } - - handleEdit = (record) => { - const { usefulFields } = this.state - this.setState({ - editItem: record - }) - - if (usefulFields) { - this.props.form.setFieldsValue({ - sql: record.sql - }) - } else { - this.props.form.setFieldsValue({ - sql: record.sql, - position: record.position || 'back' - }) - } - - this.scrolltop() - } - - scrolltop = () => { - let node = document.getElementById(this.state.wrapId).parentNode - - if (node && node.scrollTop) { - let inter = Math.ceil(node.scrollTop / 10) - - let timer = setInterval(() => { - if (node.scrollTop - inter > 0) { - node.scrollTop = node.scrollTop - inter - } else { - node.scrollTop = 0 - clearInterval(timer) - } - }, 10) - } - } - - changeScripts = (scripts) => { - this.setState({scripts}) - this.props.scriptsUpdate(scripts) - } - - handleStatus = (record) => { - let scripts = fromJS(this.state.scripts).toJS() - record.status = record.status === 'false' ? 'true' : 'false' - - scripts = scripts.map(item => { - if (item.uuid === record.uuid) { - return record - } else { - return item - } - }) - - this.setState({scripts}) - this.props.scriptsUpdate(scripts) - } - - handleDelete = (record) => { - let scripts = fromJS(this.state.scripts).toJS() - scripts = scripts.filter(item => item.uuid !== record.uuid) - - this.setState({ scripts }) - this.props.scriptsUpdate(scripts) - } - - render() { - const { setting, scripts } = this.props - const { getFieldDecorator } = this.props.form - const { usefulFields, scriptsColumns, systemScripts, urlFields, wrapId } = this.state - const formItemLayout = { - labelCol: { - xs: { span: 24 }, - sm: { span: 8 } - }, - wrapperCol: { - xs: { span: 24 }, - sm: { span: 16 } - } - } - - return ( - <div className="modal-menu-setting-script" id={wrapId}> - <Form {...formItemLayout}> - <Row gutter={24}> - <Col span={4}> - <Form.Item labelCol={{span: 17}} wrapperCol={{span: 7}} label={'鍥炶皟琛ㄥ悕'} style={{whiteSpace: 'nowrap', margin: 0}}> - {setting.cbTable} - </Form.Item> - </Col> - <Col span={20}> - <Form.Item labelCol={{span: 4}} wrapperCol={{span: 20}} label={'鎶ラ敊瀛楁'} style={{margin: 0}}> - ErrorCode锛堝鍔犲悗缂�NT琛ㄧず鏁版嵁涓嶅洖婊氾紝濡侲NT銆丯NT銆丗NT銆丯MNT銆丆NT銆�-2NT锛�, retmsg - </Form.Item> - </Col> - <Col span={24} className="sqlfield"> - <Form.Item label={'鍙敤瀛楁'}> - <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'鍏叡鍊硷紝璇锋寜鐓xxx@鏍煎紡浣跨敤銆�'}><span style={{color: '#1890ff'}}>BID, ID, LoginUID, SessionUid, UserID, Appkey, time_id</span></Tooltip>, - <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'绯荤粺鍙橀噺锛岀郴缁熶細瀹氫箟鍙橀噺骞惰祴鍊笺��'}><span style={{color: '#fa8c16'}}>UserName, FullName, RoleID, mk_departmentcode, mk_organization, mk_user_type, mk_nation, mk_province, mk_city, mk_district, mk_address</span></Tooltip> - {usefulFields ? <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'鎼滅储鏉′欢鍙橀噺锛岃鎸夌収@xxx@鏍煎紡浣跨敤銆�'}>, {usefulFields}</Tooltip> : ''} - {urlFields ?<Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'url鍙橀噺锛岃鎸夌収@xxx@鏍煎紡浣跨敤銆�'}>, <span style={{color: '#13c2c2'}}>{urlFields}</span></Tooltip> : ''} - </Form.Item> - </Col> - {!usefulFields ? <Col span={8} style={{whiteSpace: 'nowrap'}}> - <Form.Item style={{marginBottom: 0}} label="鎵ц浣嶇疆"> - {getFieldDecorator('position', { - initialValue: 'front' - })( - <Radio.Group> - <Radio value="front">sql鍓�</Radio> - <Radio value="back">sql鍚�</Radio> - </Radio.Group> - )} - </Form.Item> - </Col> : null} - <Col span={10} className="quick-add"> - <Form.Item label={'蹇嵎娣诲姞'} style={{marginBottom: 0}}> - <Select - allowClear - showSearch - filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} - onChange={this.selectScript} - > - {!usefulFields ? <Select.Option key="default" value={`declare @${setting.cbTable} table (mk_api_key nvarchar(100),mk_level nvarchar(10),mk_id nvarchar(50),mk_bid nvarchar(50))\n/*@${setting.cbTable}_data table (mk_level nvarchar(10),mk_id nvarchar(50),mk_bid nvarchar(50))*/`}>榛樿sql</Select.Option> : null} - {systemScripts.map((option, i) => - <Select.Option style={{whiteSpace: 'normal'}} key={i} value={option.value}>{option.name}</Select.Option> - )} - </Select> - </Form.Item> - </Col> - <Col span={6} className="add"> - <Button onClick={this.handleConfirm} loading={this.state.loading} className="mk-green" style={{marginTop: 5, marginBottom: 15, marginLeft: 30}}> - 淇濆瓨 - </Button> - <Button onClick={this.handleCancel} style={{marginTop: 5, marginBottom: 15, marginLeft: 10}}> - 鍙栨秷 - </Button> - </Col> - <Col span={24} className="sql"> - <Form.Item label={'sql'}> - {getFieldDecorator('sql', { - initialValue: '' - })(<CodeMirror />)} - </Form.Item> - </Col> - </Row> - </Form> - <EditTable data={scripts} actions={['move']} columns={scriptsColumns} onChange={this.changeScripts}/> - </div> - ) - } -} - -export default Form.create()(CustomForm) \ No newline at end of file diff --git a/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.scss b/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.scss deleted file mode 100644 index 945809b..0000000 --- a/src/templates/sharecomponent/settingcomponent/settingform/simplescript/index.scss +++ /dev/null @@ -1,45 +0,0 @@ -.modal-menu-setting-script { - .sqlfield { - .ant-form-item { - margin-bottom: 5px; - } - .ant-form-item-control { - line-height: 24px; - } - .ant-form-item-label { - line-height: 25px; - } - .ant-form-item-children { - line-height: 22px; - } - .ant-col-sm-8 { - width: 10.5%; - } - .ant-col-sm-16 { - width: 89.5%; - } - } - .quick-add { - .ant-col-sm-8 { - width: 26%; - } - .ant-col-sm-16 { - width: 74%; - } - } - .sql { - .ant-col-sm-8 { - width: 10.5%; - } - .ant-col-sm-16 { - width: 89.5%; - padding-top: 4px; - } - .CodeMirror { - height: 350px; - } - } - div.ant-typography { - margin-bottom: 0; - } -} \ No newline at end of file diff --git a/src/templates/sharecomponent/settingcomponent/settingform/utils.jsx b/src/templates/sharecomponent/settingcomponent/settingform/utils.jsx index aca603b..4f1413c 100644 --- a/src/templates/sharecomponent/settingcomponent/settingform/utils.jsx +++ b/src/templates/sharecomponent/settingcomponent/settingform/utils.jsx @@ -1,13 +1,11 @@ +import { getSearchRegs, joinMainSearchkey } from '@/utils/utils-custom.js' + export default class SettingUtils { /** * @description 鐢熸垚椤甸潰鏌ヨ璇彞 - * @return {String} arr_field 鏄剧ず鍒楀瓧娈� - * @return {String} search 鎼滅储鏉′欢 - * @return {Object} setting 椤甸潰璁剧疆 - * @return {Array} regoptions 鎼滅储鏉′欢姝e垯鏇挎崲 */ - static getDebugSql (setting, scripts, arr_field, regoptions, search) { + static getDebugSql (setting, scripts, arr_field, searches = [], urlFields) { let sql = '' let _dataresource = setting.dataresource || '' let _customScript = '' @@ -53,22 +51,22 @@ _customScript = _customScript.replace(/@db@/ig, window.GLOB.externalDatabase) } + let _regoptions = getSearchRegs(searches) + + let _search = joinMainSearchkey(searches) + _search = _search ? 'where ' + _search : '' + // 姝e垯鏇挎崲 - let _regoptions = regoptions.map(item => { - return { - reg: new RegExp('@' + item.key + '@', 'ig'), - value: `'0'`, - type: item.type || '' - } - }) + if (urlFields && urlFields.length > 0) { + urlFields.forEach(field => { + _regoptions.push({ + reg: new RegExp('@' + field + '@', 'ig'), + value: `'0'` + }) + }) + } _regoptions.push({ - reg: new RegExp('@userName@', 'ig'), - value: `''` - }, { - reg: new RegExp('@fullName@', 'ig'), - value: `''` - }, { reg: new RegExp('@orderBy@', 'ig'), value: setting.order }, { @@ -79,24 +77,13 @@ value: 1 }) - let _search = search + _regoptions.forEach(item => { + _dataresource = _dataresource.replace(item.reg, item.value) + _customScript = _customScript.replace(item.reg, item.value) + }) if (setting.queryType === 'statistics' && _dataresource) { - _regoptions.forEach(item => { - _dataresource = _dataresource.replace(item.reg, item.value) - }) _search = '' - } else if (_dataresource) { - _regoptions.forEach(item => { - if (item.type !== 'url') return - _dataresource = _dataresource.replace(item.reg, item.value) - }) - } - - if (_customScript) { - _regoptions.forEach(item => { - _customScript = _customScript.replace(item.reg, item.value) - }) } // 鏁版嵁婧愬鐞�, 瀛樺湪鏄剧ず鍒楁椂 @@ -139,62 +126,5 @@ } return { sql, errors: errors.join('锛�') } - } - - /** - * @description 鐢熸垚鍓嶇疆鎴栧悗缃鍙� - * @return {String} scripts 鑴氭湰 - * @return {Array} regoptions 鎼滅储鏉′欢姝e垯鏇挎崲 - */ - static getCustomDebugSql (scripts, regoptions) { - let sql = '' - let _customScript = '' - - scripts.forEach(script => { - if (script.status === 'false') return - - _customScript += ` - ${script.sql} - ` - }) - - if (_customScript) { - _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20),@mk_nation nvarchar(50),@mk_province nvarchar(50),@mk_city nvarchar(50),@mk_district nvarchar(50),@mk_address nvarchar(100) select @ErrorCode='',@retmsg ='' - ${_customScript} - ` - } - - if (window.GLOB.funcs && window.GLOB.funcs.length > 0) { - window.GLOB.funcs.forEach(item => { - let reg = new RegExp('\\$ex@' + item.func_code + '@ex\\$', 'ig') - _customScript = _customScript.replace(reg, `/*$ex@${item.func_code}-begin*/\n${item.key_sql}\n/*@ex$-end*/`) - }) - } - - _customScript = _customScript.replace(/@\$|\$@/ig, '') - _customScript = _customScript.replace(/@userName@|@fullName@/ig, `''`) - - // 姝e垯鏇挎崲 - if (regoptions) { - let _regoptions = regoptions.map(item => { - return { - reg: new RegExp('@' + item.key + '@', 'ig'), - value: `'0'` - } - }) - _regoptions.forEach(item => { - _customScript = _customScript.replace(item.reg, item.value) - }) - } - - if (_customScript) { - sql = `${_customScript} - aaa: - if @ErrorCode!='' - insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select '1949-10-01 15:00:00',@ErrorCode, @retmsg,'1949-10-01 15:00:00' - ` - } - - return sql } } \ No newline at end of file diff --git a/src/templates/zshare/customscript/index.jsx b/src/templates/zshare/customscript/index.jsx index 662e012..3791423 100644 --- a/src/templates/zshare/customscript/index.jsx +++ b/src/templates/zshare/customscript/index.jsx @@ -94,18 +94,23 @@ let _usefulFields = [] searches.forEach(item => { - if (!item.field) return - if (item.type === 'group') { - _usefulFields.push(item.field) - _usefulFields.push(item.datefield) - _usefulFields.push(item.datefield + '1') - } else if (['dateweek', 'datemonth', 'daterange'].includes(item.type)) { - _usefulFields.push(item.field) - _usefulFields.push(item.field + '1') - } else if (_usefulFields.includes(item.field)) { - _usefulFields.push(item.field + '1') + if (['dateweek', 'datemonth'].includes(item.type)) { + _usefulFields.push(item.key) + _usefulFields.push(item.key + '1') + } else if (item.type === 'daterange') { + let _skey = item.key + let _ekey = item.key + '1' + + if (/,/.test(item.key)) { + _skey = item.key.split(',')[0] + _ekey = item.key.split(',')[1] + } + _usefulFields.push(_skey) + _usefulFields.push(_ekey) + } else if (item.type === 'date' && _usefulFields.includes(item.key)) { + _usefulFields.push(item.key + '1') } else { - _usefulFields.push(item.field.replace(/,/ig, ', ')) + _usefulFields.push(item.key.replace(/,/ig, ', ')) } }) diff --git a/src/utils/utils-custom.js b/src/utils/utils-custom.js index e6dd77b..9ad1446 100644 --- a/src/utils/utils-custom.js +++ b/src/utils/utils-custom.js @@ -932,6 +932,178 @@ } /** + * @description 鏍煎紡鍖栨悳绱㈡潯浠� + */ +export function formatSearch (searches) { + if (!searches) return [] + + let newsearches = [] + searches.forEach(item => { + if (!item.field) return + + if (item.type === 'group') { + newsearches.push({ + key: item.field, + match: '', + type: item.type, + value: 'customized', + forbid: true + }, { + key: item.datefield, + match: 'between', + type: 'daterange', + value: '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000', + forbid: item.query === 'false' + }) + } else { + let value = item.initval + let type = item.type + + if (item.type === 'date') { + value = '1949-10-01 00:00:00.000' + } else if (item.type === 'datemonth') { + value = '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000' + } else if (item.type === 'dateweek') { + value = '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000' + } else if (item.type === 'daterange') { + value = '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000' + } else if (item.type === 'range') { + value = `${item.minValue},${item.maxValue}` + } else if (item.type === 'multiselect' || (item.type === 'checkcard' && item.multiple === 'true')) { + type = 'multi' + value = '0' + } else { + value = '0' + } + newsearches.push({ + key: item.field, + match: item.match, + type: type, + value: value, + precision: item.precision || 'day', + forbid: item.query === 'false' + }) + } + }) + + return newsearches +} + +/** + * @description 鎷兼帴where鏉′欢 + */ +export function joinMainSearchkey (searches) { + if (!searches || searches.length === 0) return '' + + let searchText = [] + searches.forEach(item => { + if (item.forbid) return + + if (item.type === 'text' || item.type === 'select') { // 缁煎悎鎼滅储锛屾枃鏈垨涓嬫媺锛屾墍鏈夊瓧娈垫嫾鎺� + let str = item.match === 'like' || item.match === 'not like' ? '%' : '' + let fields = item.key.split(',').map(field => { + return field + ' ' + item.match + ' \'' + str + item.value + str + '\'' + }) + + searchText.push('(' + fields.join(' OR ') + ')') + } else if (item.type === 'checkcard') { + let str = item.match === 'like' || item.match === 'not like' ? '%' : '' + + searchText.push('(' + item.key + ' ' + item.match + ' \'' + str + item.value + str + '\')') + } else if (item.type === 'multi') { + searchText.push(`('${item.value}' ${item.match} '%'+${item.key}+'%')`) + } else if (item.type === 'date') { + searchText.push('(' + item.key + ' ' + item.match + ' \'' + item.value + '\')') + } else if (item.type === 'datemonth' || item.type === 'dateweek' || item.type === 'range') { + let val = item.value.split(',') + searchText.push('(' + item.key + ' >= \'' + val[0] + '\' AND ' + item.key + ' < \'' + val[1] + '\')') + } else if (item.type === 'daterange') { + let val = item.value.split(',') + + let _skey = item.key + let _ekey = item.key + + if (/,/.test(item.key)) { + _skey = item.key.split(',')[0] + _ekey = item.key.split(',')[1] + } + + searchText.push('(' + _skey + ' >= \'' + val[0] + '\' AND ' + _ekey + ' < \'' + val[1] + '\')') + } else { + searchText.push('(' + item.key + ' ' + item.match + ' \'' + item.value + '\')') + } + }) + + return searchText.join(' AND ') +} + +/** + * @description 鑾峰彇鎼滅储姝e垯鏇挎崲 + */ +export function getSearchRegs (searches) { + if (!searches) return [] + + let options = [] + let fieldmap = new Map() + searches.forEach(item => { + if (item.type === 'date') { + if (fieldmap.has(item.key)) { + options.push({ + reg: new RegExp('@' + item.key + '1@', 'ig'), + value: `'${item.value}'` + }) + } else { + fieldmap.set(item.key, true) + options.push({ + reg: new RegExp('@' + item.key + '@', 'ig'), + value: `'${item.value}'` + }) + } + } else if (['dateweek', 'datemonth', 'range'].includes(item.type)) { + let val = item.value.split(',') + options.push({ + reg: new RegExp('@' + item.key + '@', 'ig'), + value: `'${val[0]}'` + }, { + reg: new RegExp('@' + item.key + '1@', 'ig'), + value: `'${val[1]}'` + }) + } else if (item.type === 'daterange') { + let val = item.value.split(',') + let _skey = item.key + let _ekey = item.key + '1' + + if (/,/.test(item.key)) { + _skey = item.key.split(',')[0] + _ekey = item.key.split(',')[1] + } + + options.push({ + reg: new RegExp('@' + _skey + '@', 'ig'), + value: `'${val[0]}'` + }, { + reg: new RegExp('@' + _ekey + '@', 'ig'), + value: `'${val[1]}'` + }) + } else if (item.type === 'text' || item.type === 'select') { + item.key.split(',').forEach(field => { + options.push({ + reg: new RegExp('@' + field + '@', 'ig'), + value: `'${item.value}'` + }) + }) + } else { + options.push({ + reg: new RegExp('@' + item.key + '@', 'ig'), + value: `'${item.value}'` + }) + } + }) + + return options +} + +/** * @description 閲嶇疆绉诲姩绔痵tyle * @return {Object} style */ diff --git a/src/views/menudesign/index.jsx b/src/views/menudesign/index.jsx index 53a7629..292a3cc 100644 --- a/src/views/menudesign/index.jsx +++ b/src/views/menudesign/index.jsx @@ -36,7 +36,7 @@ const PasteController = asyncComponent(() => import('@/menu/pastecontroller')) const StyleController = asyncComponent(() => import('@/menu/stylecontroller')) const ReplaceField = asyncComponent(() => import('@/menu/replaceField')) -// const Debug = asyncComponent(() => import('@/menu/debug')) +const Debug = asyncComponent(() => import('@/menu/debug')) const NormalCss = asyncComponent(() => import('@/menu/normalCss')) const Versions = asyncComponent(() => import('@/menu/versions')) const TableNodes = asyncComponent(() => import('@/menu/tablenodes')) @@ -1162,7 +1162,7 @@ <div className={'menu-view' + (menuloading ? ' saving' : '') + (eyeopen ? ' eye-open' : '')}> <Card bordered={false} extra={ <div className="mk-opeartion-list"> - {/* <Debug config={config}/> */} + <Debug config={config}/> <Button className="mk-border-purple" onClick={() => this.setState({eyeopen: !eyeopen})}>{!eyeopen ? <EyeOutlined /> : <EyeInvisibleOutlined />} 缁勪欢鍚�</Button> <Versions MenuId={MenuId} open_edition={config ? config.open_edition : ''}/> <TableNodes config={config} /> diff --git a/src/views/tabledesign/index.jsx b/src/views/tabledesign/index.jsx index fd5c387..cb48eb5 100644 --- a/src/views/tabledesign/index.jsx +++ b/src/views/tabledesign/index.jsx @@ -34,7 +34,7 @@ const BgController = asyncComponent(() => import('@/pc/bgcontroller')) const StyleController = asyncComponent(() => import('@/menu/stylecontroller')) const ReplaceField = asyncComponent(() => import('@/menu/replaceField')) -// const Debug = asyncComponent(() => import('@/menu/debug')) +const Debug = asyncComponent(() => import('@/menu/debug')) const Versions = asyncComponent(() => import('@/menu/versions')) const Transfer = asyncComponent(() => import('@/menu/transfer')) const Unattended = asyncComponent(() => import('@/templates/zshare/unattended')) @@ -872,7 +872,7 @@ <div className={'menu-view' + (menuloading ? ' saving' : '')}> <Card bordered={false} extra={ <div className="mk-opeartion-list"> - {/* {config ? <Debug config={config}/> : null} */} + {config ? <Debug config={config}/> : null} {config ? <Transfer config={config}/> : null} {config ? <Unattended config={config} updateConfig={this.updateConfig}/> : null} <Versions MenuId={MenuId} open_edition={config ? config.open_edition : ''}/> -- Gitblit v1.8.0