From ecabd56432b4c4bda307dbe4767038cae0a3d5ae Mon Sep 17 00:00:00 2001 From: xiongjj Date: Wed, 20 Nov 2024 20:42:29 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=E3=80=91=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=81=97=E6=BC=8F=E5=88=A4=E6=96=ADiportalda?= =?UTF-8?q?ta=E6=98=AF=E5=90=A6=E5=8F=91=E5=B8=83=E6=9C=8D=E5=8A=A1,=20?= =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81=E6=9C=AA=E5=8F=91=E5=B8=83=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E6=95=B0=E6=8D=AE;=20review=20by=20songym?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/_utils/get-features.js | 6 ++- src/common/_utils/iPortalDataService.js | 15 ++++++- src/mapboxgl/query/QueryViewModel.js | 6 ++- src/mapboxgl/query/__tests__/Query.spec.js | 47 ++++++++++++++++++++++ 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/common/_utils/get-features.js b/src/common/_utils/get-features.js index 5833b6f2..10ce29c7 100644 --- a/src/common/_utils/get-features.js +++ b/src/common/_utils/get-features.js @@ -23,7 +23,8 @@ export default function getFeatures(dataset) { orderBy, returnFeaturesOnly, bounds, - keyWord + keyWord, + onlyService } = dataset; if (dataset && (url || geoJSON) && type) { let queryInfo = { @@ -62,6 +63,9 @@ export default function getFeatures(dataset) { params = [datasetInfo, queryInfo]; } else if (type === 'iPortal') { queryInfo.withCredentials = withCredentials; + if (onlyService !== undefined) { + queryInfo.onlyService = onlyService; + } superMapService = new iPortalDataService(url, withCredentials, { epsgCode, resourceId: dataset.id, diff --git a/src/common/_utils/iPortalDataService.js b/src/common/_utils/iPortalDataService.js index afbcf3b3..2acf456e 100644 --- a/src/common/_utils/iPortalDataService.js +++ b/src/common/_utils/iPortalDataService.js @@ -2,6 +2,7 @@ import { FetchRequest, Util } from 'vue-iclient/static/libs/iclient-common/iclie import iServerRestService, { vertifyEpsgCode, transformFeatures } from 'vue-iclient/src/common/_utils/iServerRestService'; import { isXField, isYField, handleWithCredentials, handleDataParentRes } from 'vue-iclient/src/common/_utils/util'; import { Events } from 'vue-iclient/src/common/_types/event/Events'; +import { geti18n } from 'vue-iclient/src/common/_lang/index'; /** * @class iPortalDataService @@ -78,10 +79,12 @@ export default class iPortalDataService extends Events { } let datasetUrl = this.url; - if (preferContent) { + const onlyService = queryInfo.onlyService; + if (preferContent && !onlyService) { this._getDatafromContent(datasetUrl, queryInfo); return; } + delete queryInfo.onlyService; FetchRequest.get(datasetUrl, null, { withCredentials: this.withCredentials }) @@ -100,8 +103,16 @@ export default class iPortalDataService extends Events { this._getStructureDatafromContent(); return; } + const hasService = data.dataItemServices && data.dataItemServices.length > 0; + if (onlyService && !hasService) { + this.triggerEvent('getdatafailed', { + error: { message: geti18n().t('query.seviceNotSupport') }, + onlyService + }); + return; + } // 是否有rest服务 - if (data.dataItemServices && data.dataItemServices.length > 0) { + if (hasService) { let dataItemServices = data.dataItemServices; let resultData = dataItemServices.find( item => diff --git a/src/mapboxgl/query/QueryViewModel.js b/src/mapboxgl/query/QueryViewModel.js index b90fd690..6b14d796 100644 --- a/src/mapboxgl/query/QueryViewModel.js +++ b/src/mapboxgl/query/QueryViewModel.js @@ -81,6 +81,9 @@ export default class QueryViewModel extends mapboxgl.Evented { keyWord: queryParameter.queryMode === 'KEYWORD' ? queryParameter.attributeFilter : '', bounds: this.bounds }; + if (queryParameter.type === 'iPortal') { + queryOptions.onlyService = true; + } const res = await getFeatures({ ...queryParameter, ...queryOptions }); if (res.type === 'featureisempty') { this.fire('queryfailed', { message: geti18n().t('query.noResults') }); @@ -90,7 +93,8 @@ export default class QueryViewModel extends mapboxgl.Evented { this._addResultLayer(this.queryResult); this.fire('querysucceeded', { result: this.queryResult, layers: [this.layerID, this.strokeLayerID].filter(item => !!item) }); } catch (error) { - this.fire('queryfailed', { message: geti18n().t('query.queryFailed') }); + const message = error.onlyService ? geti18n().t('query.seviceNotSupport') : geti18n().t('query.queryFailed'); + this.fire('queryfailed', { message }); } } } diff --git a/src/mapboxgl/query/__tests__/Query.spec.js b/src/mapboxgl/query/__tests__/Query.spec.js index cd4a6107..c35c5ea1 100644 --- a/src/mapboxgl/query/__tests__/Query.spec.js +++ b/src/mapboxgl/query/__tests__/Query.spec.js @@ -39,6 +39,9 @@ describe('query', () => { if (url.indexOf('/123') > -1) { return Promise.resolve(new Response(JSON.stringify(datas))); } + if (url.indexOf('/1763883342') > -1) { + return Promise.resolve(new Response(JSON.stringify({ ...datas, dataItemServices: [] }))); + } if (url.includes('/content')) { return Promise.resolve(new Response(JSON.stringify(iportal_content))); } @@ -103,6 +106,50 @@ describe('query', () => { }); }); + it('iPortal unpublished Data', async done => { + wrapper = mount(SmQuery, { + localVue, + propsData: { + mapTarget: 'map', + iportalData: [ + { + name: '四川省电站发电-四川发电站上月发电量', + displayName: '分段&-四川省电站发电-四川发电站上月发电量', + mapTarget: 'map_1731901870198', + type: 'iPortal', + id: '1763883342', + url: 'http://lcoalhost:8190/iportal/web/datas/1763883342', + dataType: 'GEOJSON', + updateTime: '2024-10-25 11:38:12', + serviceStatus: 'PUBLISHED', + dataItemServices: null, + withCredentials: false, + preferContent: true, + maxFeatures: 8, + queryMode: 'SQL', + fields: [], + attributeFilter: 'SmID>0' + } + ] + } + }); + await mapSubComponentLoaded(wrapper); + expect(wrapper.vm.mapTarget).toBe('map'); + const queryErrorTip = jest.spyOn(Message, 'warning'); + wrapper.vm.$on('query-failed', (e) => { + expect(queryErrorTip).toHaveBeenCalledTimes(1); + expect(queryErrorTip).toHaveBeenCalledWith(e.message); + expect(e.message).toBe('query.seviceNotSupport'); + expect(wrapper.vm.isQuery).toBe(false); + expect(wrapper.vm.activeTab).toBe('job'); + expect(wrapper.vm.activeResultIndexList).toEqual([]); + expect(wrapper.vm.queryResult).toBeNull(); + expect(wrapper.vm.activeQueryJob).toBeNull(); + done(); + }) + wrapper.find(SmButton).find('.sm-component-query__a-button').trigger('click'); + }); + it('restData Service', async done => { wrapper = mount(SmQuery, { localVue,