From d33d00cafeea2c4f980ea3af268d9260269edcc1 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 25 一月 2021 18:24:20 +0800 Subject: [PATCH] 2021-01-25 --- src/tabviews/commontable/index.jsx | 285 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 262 insertions(+), 23 deletions(-) diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx index 2139f68..37c74e9 100644 --- a/src/tabviews/commontable/index.jsx +++ b/src/tabviews/commontable/index.jsx @@ -8,6 +8,7 @@ import zhCN from '@/locales/zh-CN/main.js' import enUS from '@/locales/en-US/main.js' import Utils from '@/utils/utils.js' +import options from '@/store/options.js' import UtilsDM from '@/utils/utils-datamanage.js' import UtilsUpdate from '@/utils/utils-update.js' import asyncComponent from '@/utils/asyncComponent' @@ -64,6 +65,7 @@ statFields: [], // 鍚堣瀛楁 statFValue: [], // 鍚堣鍊� absFields: [], // 缁濆鍊煎瓧娈� + loadCustomApi: true // 鍔犺浇澶栭儴璧勬簮 } /** @@ -86,6 +88,7 @@ config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) config.MenuID = this.props.MenuID config.MenuName = MenuName + config.setting.MenuName = MenuName } catch (e) { console.warn('Parse Failure') config = '' @@ -210,7 +213,7 @@ config.setting.execute = config.setting.default !== 'false' // 榛樿sql鏄惁鎵ц锛岃浆涓篵oolean 缁熶竴鏍煎紡 config.setting.customScript = '' // 鑷畾涔夎剼鏈� - if (config.setting.interType === 'system') { + if (config.setting.interType === 'system' || (config.setting.interType === 'custom' && config.setting.requestMode === 'system')) { if (config.setting.scripts && config.setting.scripts.length > 0) { let _customScript = '' config.setting.scripts.forEach(item => { @@ -363,8 +366,7 @@ search: Utils.initMainSearch(initSearch) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 }, () => { if (config.setting.onload !== 'false' && valid) { // 鍒濆鍖栧彲鍔犺浇 - this.loadmaindata() - this.getStatFieldsValue() + this.loadData() } this.setShortcut() }) @@ -422,11 +424,8 @@ } } - /** - * @description 涓昏〃鏁版嵁鍔犺浇 - */ - async loadmaindata () { - const { setting, arr_field, BIDs, search, orderBy, BID, pageIndex, pageSize, absFields } = this.state + loadData = () => { + const { setting, search, BIDs, loadCustomApi } = this.state let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0)) this.setState({ @@ -448,7 +447,253 @@ duration: 3 }) return + } else if (window.GLOB.systemType === 'production' && !setting.proInterface) { + notification.warning({ + top: 92, + message: '鏈缃寮忕郴缁熷湴鍧�!', + duration: 3 + }) + return } + + if (setting.interType === 'custom' && loadCustomApi) { + if (setting.execTime === 'once') { + this.setState({loadCustomApi: false}) + } + + this.loadOutResource() + if (setting.execType === 'async') { + this.loadmaindata() + } + } else { + this.loadmaindata() + } + } + + loadOutResource = () => { + const { setting, search, BID } = this.state + + let param = UtilsDM.getPrevQueryParams(setting, search, BID, this.props.menuType) + + if (setting.execType === 'sync') { + this.setState({ + loading: true + }) + } + + Api.genericInterface(param).then(res => { + if (res.status) { + if (res.mk_ex_invoke === 'false') { + this.loadmaindata() + } else { + this.customOuterRequest(res) + } + } else { + this.setState({ + loading: false + }) + notification.error({ + top: 92, + message: res.message, + duration: 10 + }) + } + }, () => { + this.setState({ + loading: false + }) + }) + } + + customOuterRequest = (result) => { + const { setting } = this.state + let url = '' + + if (window.GLOB.systemType === 'production') { + url = setting.proInterface + } else { + url = setting.interface + } + + let mkey = result.mk_api_key || '' + + delete result.mk_ex_invoke + delete result.status + delete result.message + delete result.ErrCode + delete result.ErrMesg + delete result.mk_api_key + + let param = {} + + Object.keys(result).forEach(key => { + key = key.replace(/^mk_/ig, '') + param[key] = result[key] + }) + + Api.directRequest(url, setting.method, param).then(res => { + if (typeof(res) !== 'object' || Array.isArray(res)) { + let error = '鏈煡鐨勮繑鍥炵粨鏋滐紒' + + if (typeof(res) === 'string') { + error = res + } + + let _result = { + mk_api_key: mkey, + $ErrCode: 'E', + $ErrMesg: error + } + + this.customCallbackRequest(_result) + } else { + res.mk_api_key = mkey + this.customCallbackRequest(res) + } + }, () => { + this.setState({ + loading: false + }) + }) + } + + customCallbackRequest = (result) => { + const { setting } = this.state + let lines = [] + let pre = setting.callbackType === 'script' ? '@' : '' + + let errSql = '' + if (result.$ErrCode === 'E') { + errSql = ` + set @ErrorCode='E' + set @retmsg='${result.$ErrMesg}' + ` + delete result.$ErrCode + delete result.$ErrMesg + } + + let getDefaultSql = (obj, tb, bid, level) => { + let keys = [] + let vals = [] + let subObjs = [] + let id = Utils.getuuid() + + delete obj.$$key + + Object.keys(obj).forEach(key => { + let val = obj[key] + if (typeof(val) === 'object') { + if (Array.isArray(val)) { + val.forEach(item => { + if (typeof(item) !== 'object' || Array.isArray(item)) return + if (Object.keys(item).length > 0) { + item.$$key = tb + '_' + key + subObjs.push(item) + } + }) + } else if (Object.keys(val).length > 0) { + val.$$key = tb + '_' + key + subObjs.push(val) + } + } else if (val !== null && val !== undefined) { + keys.push(key) + vals.push(`'${val}'`) + } + }) + + lines.push({ + table: tb, + insert: `Insert into ${pre}${tb} (${keys.join(',')},mk_level,mk_id,mk_bid)`, + select: `Select ${vals.join(',')},'${level}','${id}','${bid}'` + }) + + subObjs.forEach(item => { + getDefaultSql(item, item.$$key, id, level + 1) + }) + } + + getDefaultSql(result, setting.cbTable, '', 1) + + let lineMap = new Map() + lines.forEach(line => { + if (lineMap.has(line.table)) { + let _line = lineMap.get(line.table) + _line.selects.push(line.select) + lineMap.set(line.table, _line) + } else { + lineMap.set(line.table, { + table: line.table, + insert: line.insert, + selects: [line.select] + }) + } + }) + + let param = {} + + if (setting.callbackType === 'script') { // 浣跨敤鑷畾涔夎剼鏈� + let sql = [...lineMap.values()].map(item => (` + ${item.insert} + ${item.selects.join(` union all + `)} + `)) + sql = sql.join('') + + param = UtilsDM.getCallBackQueryParams(setting, sql, errSql) + + if (this.state.BID) { + param.BID = this.state.BID + } + + if (this.props.menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉 + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) + } + } else { + param.func = 's_ex_result_back' + param.s_ex_result = [...lineMap.values()].map((item, index) => ({ + MenuID: this.state.config.MenuID, + MenuName: this.state.config.MenuName, + TableName: item.table, + LongText: window.btoa(window.encodeURIComponent(`${item.insert} ${item.selects.join(` union all `)}`)), + Sort: index + 1 + })) + + if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) { + let sql = [...lineMap.values()].map(item => (` + ${item.insert} + ${item.selects.join(` union all + `)} + `)) + sql = sql.join('') + console.info(sql.replace(/\n\s{10}/ig, '\n')) + } + } + + Api.genericInterface(param).then(res => { + if (res.status) { + this.loadmaindata() + } else { + this.setState({ + loading: false + }) + notification.error({ + top: 92, + message: res.message, + duration: 10 + }) + } + }, () => { + this.setState({ + loading: false + }) + }) + } + + /** + * @description 涓昏〃鏁版嵁鍔犺浇 + */ + async loadmaindata () { + const { setting, arr_field, search, orderBy, BID, pageIndex, pageSize, absFields } = this.state this.setState({ loading: true @@ -462,6 +707,9 @@ } let result = await Api.genericInterface(param) + + this.getStatFieldsValue() + if (result.status) { this.setState({ data: result.data.map((item, index) => { @@ -567,12 +815,7 @@ getStatFieldsValue = () => { const { setting, search, BID, orderBy, statFields } = this.state - if (statFields.length === 0 || setting.interType !== 'system' || !setting.dataresource) return - - let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0)) - if (requireFields.length > 0) { - return - } + if (statFields.length === 0 || !(setting.interType === 'system' || (setting.interType === 'custom' && setting.requestMode === 'system')) || !setting.dataresource) return let _orderBy = orderBy || setting.order let param = UtilsDM.getStatQueryDataParams(setting, statFields, search, _orderBy, BID, this.props.menuType) @@ -627,8 +870,7 @@ search: searches, setting: {...setting, onload: 'true'} }, () => { - this.loadmaindata() - this.getStatFieldsValue() + this.loadData() }) } else { MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable') // 鍒楄〃閲嶇疆 @@ -636,8 +878,7 @@ pageIndex: 1, search: searches }, () => { - this.loadmaindata() - this.getStatFieldsValue() + this.loadData() }) } } @@ -659,7 +900,7 @@ pageSize: pagination.pageSize, orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : '' }, () => { - this.loadmaindata() + this.loadData() }) } @@ -672,13 +913,11 @@ this.setState({ pageIndex: 1 }, () => { - this.loadmaindata() - this.getStatFieldsValue() + this.loadData() }) } else { MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable', 'false') // 鍒楄〃閲嶇疆 - this.loadmaindata() - this.getStatFieldsValue() + this.loadData() } } -- Gitblit v1.8.0