From b625a1e1e08a1c164eae61bffd3a703b4c057a22 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Thu, 23 Apr 2026 10:18:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E7=BA=A7=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 74 +++++++++++++++---- src/utils/ajax.js | 49 ++++++++++++ src/utils/httpRequest.js | 52 +++++++++++++ .../modules/sift/advancedSearchCenter.vue | 38 ++++++++++ 4 files changed, 198 insertions(+), 15 deletions(-) diff --git a/src/main.js b/src/main.js index 639954c7..2e443897 100644 --- a/src/main.js +++ b/src/main.js @@ -87,11 +87,49 @@ function pickFormulaValue (row) { return formula.split('..')[0] || '' } if (symbol === 'in' || symbol === 'ne') { - return formula.split(';')[0] || '' + return formula } return formula } +function buildAdvancedContextStorageKey (path) { + return 'advanced_search_context_' + String(path || '') +} + +function normalizeRoutePath (path) { + var p = String(path || '').trim() + if (!p) { + return '' + } + if (p.charAt(0) !== '/') { + p = '/' + p + } + return p +} + +function parseAdvancedContextByPath (path) { + var normalizedPath = normalizeRoutePath(path) + var raw = sessionStorage.getItem(buildAdvancedContextStorageKey(normalizedPath)) + if (!raw && normalizedPath.indexOf('/modules/') === 0) { + raw = sessionStorage.getItem(buildAdvancedContextStorageKey(normalizedPath.substring('/modules'.length))) + } + if (!raw && normalizedPath.indexOf('/modules/') !== 0) { + raw = sessionStorage.getItem(buildAdvancedContextStorageKey('/modules' + normalizedPath)) + } + if (!raw) { + return null + } + try { + var context = JSON.parse(raw) + if (!context || !Array.isArray(context.conditions) || context.conditions.length <= 0) { + return null + } + return context + } catch (e) { + return null + } +} + Vue.mixin({ mounted () { this.__applySavedRuleFromRoute() @@ -116,19 +154,21 @@ Vue.mixin({ return } var routeQuery = this.$route.query + var routePath = normalizeRoutePath(this.$route.path || '') var menuId = routeQuery.menuId var itemNo = routeQuery.itemNo if (!menuId || !itemNo) { return } - var routeMetaMenuId = this.$route.meta && this.$route.meta.menuId - if (routeMetaMenuId && String(routeMetaMenuId) !== String(menuId)) { - return - } var cacheKey = [this.$route.path || '', menuId, itemNo].join('_') if (this.__savedRuleAppliedKey === cacheKey) { return } + var existContext = parseAdvancedContextByPath(routePath) + if (existContext) { + this.__savedRuleAppliedKey = cacheKey + return + } try { var userId = String((this.$store && this.$store.state && this.$store.state.user && this.$store.state.user.id) || '') if (!userId) { @@ -147,16 +187,20 @@ Vue.mixin({ if (!rows.length) { return } - rows.forEach(row => { - var fieldName = row && row.fieldName ? String(row.fieldName) : '' - if (!fieldName) { - return - } - if (!Object.prototype.hasOwnProperty.call(queryModel, fieldName)) { - return - } - this.$set(queryModel, fieldName, pickFormulaValue(row)) - }) + try { + var contextRows = rows + .filter(row => row && row.fieldName && row.symbol && row.formula) + .map(row => ({ + fieldName: String(row.fieldName), + symbol: String(row.symbol).toLowerCase(), + formula: String(row.formula) + })) + sessionStorage.setItem(buildAdvancedContextStorageKey(routePath), JSON.stringify({ + menuUrl: routePath, + conditions: contextRows + })) + } catch (e) { + } if (Object.prototype.hasOwnProperty.call(this, 'pageIndex')) { this.pageIndex = 1 } diff --git a/src/utils/ajax.js b/src/utils/ajax.js index 747ac47b..dfb44b4b 100644 --- a/src/utils/ajax.js +++ b/src/utils/ajax.js @@ -1,5 +1,6 @@ import Vue from "vue"; import axios from 'axios'; +import router from '@/router' const qs = require('qs'); var apiServer = (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi/' : window.SITE_CONFIG.baseUrl); @@ -8,6 +9,46 @@ const resolveAcceptLanguage = () => { return locale === 'en' ? 'en-US' : 'zh-CN'; }; +const resolveAdvancedSearchHeaders = () => { + const route = router && router.currentRoute ? router.currentRoute : {} + let routePath = String(route.path || '').trim() + if (!routePath) { + return {} + } + if (routePath.charAt(0) !== '/') { + routePath = '/' + routePath + } + const key = 'advanced_search_context_' + routePath + let matchedKey = key + let raw = sessionStorage.getItem(key) + if (!raw && routePath.indexOf('/modules/') === 0) { + matchedKey = 'advanced_search_context_' + routePath.substring('/modules'.length) + raw = sessionStorage.getItem(matchedKey) + } + if (!raw && routePath.indexOf('/modules/') !== 0) { + matchedKey = 'advanced_search_context_' + '/modules' + routePath + raw = sessionStorage.getItem(matchedKey) + } + if (!raw) { + return {} + } + try { + const context = JSON.parse(raw) + if (!context || !context.menuUrl || !Array.isArray(context.conditions) || context.conditions.length <= 0) { + sessionStorage.removeItem(matchedKey) + return {} + } + sessionStorage.removeItem(matchedKey) + return { + 'X-Advanced-Search-Menu': String(context.menuUrl), + 'X-Advanced-Search-Conditions': encodeURIComponent(JSON.stringify(context.conditions)) + } + } catch (e) { + sessionStorage.removeItem(matchedKey) + return {} + } +} + var http = axios.create({ timeout: 10000, headers: {}, @@ -29,6 +70,10 @@ export default { 'Accept-Language': resolveAcceptLanguage() } }; + const advancedHeaders = resolveAdvancedSearchHeaders() + Object.keys(advancedHeaders).forEach(key => { + config.headers[key] = advancedHeaders[key] + }) let p = http.post(apiServer +url, JSON.stringify(data), config); if (callback) { p.then(res => { @@ -52,6 +97,10 @@ export default { xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhr.setRequestHeader("token", Vue.cookie.get('token') ); xhr.setRequestHeader("Accept-Language", resolveAcceptLanguage()); + const advancedHeaders = resolveAdvancedSearchHeaders() + Object.keys(advancedHeaders).forEach(key => { + xhr.setRequestHeader(key, advancedHeaders[key]); + }) xhr.onreadystatechange = function (e) { if (xhr.readyState === 4) { if (xhr.status === 200) { diff --git a/src/utils/httpRequest.js b/src/utils/httpRequest.js index afca9c54..836f35c6 100644 --- a/src/utils/httpRequest.js +++ b/src/utils/httpRequest.js @@ -10,6 +10,46 @@ const resolveAcceptLanguage = () => { return locale === 'en' ? 'en-US' : 'zh-CN' } +const resolveAdvancedSearchHeaders = () => { + const route = router && router.currentRoute ? router.currentRoute : {} + let routePath = String(route.path || '').trim() + if (!routePath) { + return {} + } + if (routePath.charAt(0) !== '/') { + routePath = '/' + routePath + } + const key = 'advanced_search_context_' + routePath + let matchedKey = key + let raw = sessionStorage.getItem(key) + if (!raw && routePath.indexOf('/modules/') === 0) { + matchedKey = 'advanced_search_context_' + routePath.substring('/modules'.length) + raw = sessionStorage.getItem(matchedKey) + } + if (!raw && routePath.indexOf('/modules/') !== 0) { + matchedKey = 'advanced_search_context_' + '/modules' + routePath + raw = sessionStorage.getItem(matchedKey) + } + if (!raw) { + return {} + } + try { + const context = JSON.parse(raw) + if (!context || !context.menuUrl || !Array.isArray(context.conditions) || context.conditions.length <= 0) { + sessionStorage.removeItem(matchedKey) + return {} + } + sessionStorage.removeItem(matchedKey) + return { + 'X-Advanced-Search-Menu': String(context.menuUrl), + 'X-Advanced-Search-Conditions': encodeURIComponent(JSON.stringify(context.conditions)) + } + } catch (e) { + sessionStorage.removeItem(matchedKey) + return {} + } +} + // axios.defaults.withCredentials = false const http = axios.create({ timeout: 1000 * 300, @@ -26,6 +66,10 @@ const http = axios.create({ http.interceptors.request.use(config => { config.headers['token'] = Vue.cookie.get('token') // 请求头带上token config.headers['Accept-Language'] = resolveAcceptLanguage() + const advancedHeaders = resolveAdvancedSearchHeaders() + Object.keys(advancedHeaders).forEach(key => { + config.headers[key] = advancedHeaders[key] + }) return config }, error => { return Promise.reject(error) @@ -100,6 +144,10 @@ const instance = axios.create({ instance.interceptors.request.use(config => { config.headers['token'] = Vue.cookie.get('token') // 请求头带上token config.headers['Accept-Language'] = resolveAcceptLanguage() + const advancedHeaders = resolveAdvancedSearchHeaders() + Object.keys(advancedHeaders).forEach(key => { + config.headers[key] = advancedHeaders[key] + }) return config }, error => { return Promise.reject(error) @@ -136,6 +184,10 @@ const instance2 = axios.create({ instance2.interceptors.request.use(config => { config.headers['token'] = Vue.cookie.get('token') // 请求头带上token config.headers['Accept-Language'] = resolveAcceptLanguage() + const advancedHeaders = resolveAdvancedSearchHeaders() + Object.keys(advancedHeaders).forEach(key => { + config.headers[key] = advancedHeaders[key] + }) return config }, error => { return Promise.reject(error) diff --git a/src/views/modules/sift/advancedSearchCenter.vue b/src/views/modules/sift/advancedSearchCenter.vue index 70798b30..6d88152c 100644 --- a/src/views/modules/sift/advancedSearchCenter.vue +++ b/src/views/modules/sift/advancedSearchCenter.vue @@ -416,6 +416,7 @@ export default { count: countMap[key] !== undefined ? countMap[key] : null, menuName: item.menuName || (menu ? menu.name : ('菜单' + item.menuId)), conditionPreviewList: this.buildConditionPreviewList(detailMap[key]), + conditionDetailList: detailMap[key] || [], schemeColor: rowColor }) }) @@ -446,6 +447,33 @@ export default { menuId: row.menuId || '', itemNo: row.itemNo || '' } + var routePath = routeRow.routePath || '' + if (!routePath && routeRow.routeName) { + try { + var resolved = this.$router.resolve({ name: routeRow.routeName, query: query }) + routePath = resolved && resolved.route ? resolved.route.path : '' + } catch (e) { + routePath = '' + } + } + routePath = this.normalizeContextRoutePath(routePath) + if (routePath) { + try { + var key = 'advanced_search_context_' + routePath + var conditionRows = (row.conditionDetailList || []) + .filter(item => item && item.fieldName && item.symbol && item.formula) + .map(item => ({ + fieldName: String(item.fieldName), + symbol: String(item.symbol).toLowerCase(), + formula: String(item.formula) + })) + sessionStorage.setItem(key, JSON.stringify({ + menuUrl: routePath, + conditions: conditionRows + })) + } catch (e) { + } + } if (routeRow.routeName) { this.$router.push({ name: routeRow.routeName, query: query }) return @@ -461,6 +489,16 @@ export default { this.routeResolvingKey = '' } }, + normalizeContextRoutePath (path) { + var p = String(path || '').trim() + if (!p) { + return '' + } + if (p.charAt(0) !== '/') { + p = '/' + p + } + return p + }, openCreateDialog () { this.dialogMode = 'create' this.settingDialogVisible = true