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,