Skip to content

Commit

Permalink
【fix】数据查询显示字段别名 review by qiw
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Nov 22, 2023
1 parent ab8d5cc commit 13514f2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 34 deletions.
19 changes: 19 additions & 0 deletions src/mapboxgl/query/QueryViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getFeatureCenter, getValueCaseInsensitive } from 'vue-iclient/src/commo
import bbox from '@turf/bbox';
import envelope from '@turf/envelope';
import transformScale from '@turf/transform-scale';
import { statisticsFeatures } from 'vue-iclient/src/common/_utils/statistics';

/**
* @class QueryViewModel
Expand Down Expand Up @@ -170,6 +171,12 @@ export default class QueryViewModel extends mapboxgl.Evented {
let result = serviceResult.result;
if (result && result.totalCount !== 0) {
let resultFeatures = result.recordsets[0].features.features;
if(result.recordsets[0].fieldCaptions) {
let fields = result.recordsets[0].fields;
let fieldCaptions = result.recordsets[0].fieldCaptions;
let features = result.recordsets[0].features.features;
resultFeatures = statisticsFeatures(features, fields, fieldCaptions).features;
}
resultFeatures.length > 0 && (this.queryResult = { name: restMapParameter.name, result: resultFeatures });
this._addResultLayer(this.queryResult);
/**
Expand All @@ -194,6 +201,18 @@ export default class QueryViewModel extends mapboxgl.Evented {
let result = serviceResult.result;
if (result && result.totalCount !== 0) {
let resultFeatures = result.features.features;
if(result.datasetInfos) {
let fields = [];
let fieldCaptions = [];
const fieldInfos = result.datasetInfos[0].fieldInfos;
fieldInfos.forEach(fieldInfo => {
if(fieldInfo.name) {
fields.push(fieldInfo.name.toUpperCase());
fieldCaptions.push(fieldInfo.caption.toUpperCase());
}
});
resultFeatures = statisticsFeatures(resultFeatures, fields, fieldCaptions).features;
}
resultFeatures.length > 0 && (this.queryResult = { name: restDataParameter.name, result: resultFeatures });
this._addResultLayer(this.queryResult);
this.fire('querysucceeded', { result: this.queryResult });
Expand Down
8 changes: 6 additions & 2 deletions src/mapboxgl/query/__tests__/Query.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ describe('query', () => {
expect(wrapper.vm.mapTarget).toBe('map');
const spyquery = jest.spyOn(wrapper.vm, 'query');
wrapper.find(SmButton).find('.sm-component-query__a-button').trigger('click');
wrapper.vm.viewModel.on('querysucceeded', (res) => {
expect(res.result.result[0].properties['名称']).toBe('四川省');
done();
});
wrapper.vm.$nextTick(() => {
expect(spyquery).toBeCalled();
done();
});
});

Expand All @@ -111,7 +114,8 @@ describe('query', () => {
expect(wrapper.vm.mapTarget).toBe('map');
const spyAddlayer = jest.spyOn(wrapper.vm.map, 'addLayer');
const spyquery = jest.spyOn(wrapper.vm, 'query');
wrapper.vm.viewModel.on('querysucceeded', () => {
wrapper.vm.viewModel.on('querysucceeded', (res) => {
expect(res.result.result[0].properties['名称']).toBe('四川省');
expect(spyAddlayer).toBeCalled();
done();
});
Expand Down
39 changes: 7 additions & 32 deletions test/unit/mocks/services.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import airport from './data/airport.json';
const fakeDataServiceResult = {
result: {
datasetInfos: [{
fieldInfos:[{name: "SmID", caption: "SmID", type: "INT32"}, {name: "NAME", caption: "名称", type: "WTEXT"}]
}],
currentCount: 1,
totalCount: 1,
features: {
Expand Down Expand Up @@ -78,22 +81,8 @@ const fakeMapServiceResult = {
]
},
fieldCaptions: [
'SmID',
'SmX',
'SmY',
'SmLibTileID',
'SmUserID',
'SmGeometrySize',
'USERID',
'POP',
'CAPITAL_LO',
'CAPITAL_CH',
'COUNTRY_CH',
'CAPITAL_EN',
'COUNTRY_EN',
'COUNTRY',
'CAP_POP',
'CAPITAL'
'SMID',
'名称'
],
fieldTypes: [
'INT32',
Expand All @@ -114,22 +103,8 @@ const fakeMapServiceResult = {
'WTEXT'
],
fields: [
'SmID',
'SmX',
'SmY',
'SmLibTileID',
'SmUserID',
'SmGeometrySize',
'USERID',
'POP',
'CAPITAL_LO',
'CAPITAL_CH',
'COUNTRY_CH',
'CAPITAL_EN',
'COUNTRY_EN',
'COUNTRY',
'CAP_POP',
'CAPITAL'
'SMID',
'NAME'
]
}
],
Expand Down
3 changes: 3 additions & 0 deletions test/unit/mocks/supermap.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ var QueryBySQLService = (SuperMap.QueryBySQLService = (url, options) => {
fields: {
0: 'SmID'
},
fieldCaptions: {
0: 'SmID'
},
features: {
type: 'FeatureCollection',
features: [
Expand Down

0 comments on commit 13514f2

Please sign in to comment.