Skip to content

Commit

Permalink
[fix]rest服务有别名,查询后保留fieldCaptions字段,不对原数据进行替换 review by luox
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Oct 10, 2024
1 parent 529e531 commit 9f15840
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
10 changes: 6 additions & 4 deletions src/common/_utils/__tests__/iServerRestService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ describe('iServerRestService', () => {
service.on({
getdatasucceeded: function (data) {
expect(data.features[0].geometry).toBeTruthy();
expect(data.features[0].properties['名称']).toBeTruthy();
expect(data.features[0].properties.NAME).toBeFalsy();
expect(data.features[0].properties['NAME']).toBeTruthy();
expect(data.features[0].properties['名称']).toBeFalsy();
expect(mockPostParams).toMatch(/'attributeFilter':"NAME LIKE '%25A%25'/);
done();
}
Expand All @@ -155,7 +155,8 @@ describe('iServerRestService', () => {
);
service.on({
getdatasucceeded: data => {
expect(data.fields).toEqual(['SMID', '名称']);
expect(data.fields).toEqual(['SMID', 'NAME']);
expect(data.fieldCaptions).toEqual(['SMID', '名称']);
done();
}
});
Expand All @@ -169,7 +170,8 @@ describe('iServerRestService', () => {
);
service.on({
getdatasucceeded: data => {
expect(data.fields).toEqual(['SMID', '名称']);
expect(data.fields).toEqual(['SMID', 'NAME']);
expect(data.fieldCaptions).toEqual(['SMID', '名称']);
expect(mockPostParams).toMatch(/'attributeFilter':"NAME LIKE '%25A%25'/);
done();
}
Expand Down
7 changes: 4 additions & 3 deletions src/common/_utils/iServerRestService.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,11 @@ export default class iServerRestService extends Events {
});
return;
}
let fields = [];
let fieldCaptions = [];
let fieldTypes = [];
let fields, fieldCaptions, fieldTypes;
if (results.result.datasetInfos) {
fields = [];
fieldCaptions = [];
fieldTypes = [];
const fieldInfos = results.result.datasetInfos[0].fieldInfos;
fieldInfos.forEach(fieldInfo => {
if (fieldInfo.name) {
Expand Down
20 changes: 6 additions & 14 deletions src/common/_utils/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,17 @@ export function statisticsFeatures(features, fields, fieldCaptions, fieldTypes)
const data = {
features,
fields: fields || [],
fieldCaptions: fieldCaptions || [],
fieldValues: [],
fieldTypes
};
if(features && !!features.length) {
if(fieldCaptions && fieldCaptions.length) {
features.forEach(feature => {
const newProperties = {};
for (const field in feature.properties) {
const index = fields.indexOf(field);
const fieldCaption = fieldCaptions[index];
newProperties[fieldCaption || field] = feature.properties[field];
}
feature.properties = newProperties;
});
}
if (features && !!features.length && !fieldCaptions && !fields) {
const properties = Object.assign({}, features[0].properties, features[features.length - 1].properties);
data.fields = Object.keys(properties);
for (let attr in properties) {
data.fieldCaptions.push(attr);
data.fields.push(attr);
}
}

for (let m in data.fields) {
const fieldValue = [];
for (let j in features) {
Expand Down
6 changes: 3 additions & 3 deletions src/mapboxgl/query/__tests__/Query.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('query', () => {
expect(wrapper.vm.mapTarget).toBe('map');
const spyquery = jest.spyOn(wrapper.vm, 'query');
wrapper.vm.viewModel.on('querysucceeded', res => {
expect(res.result.result[0].properties['名称']).toBe('四川省');
expect(res.result.result[0].properties['NAME']).toBe('四川省');
done();
});
wrapper.find(SmButton).find('.sm-component-query__a-button').trigger('click');
Expand All @@ -133,7 +133,7 @@ describe('query', () => {
const spyAddlayer = jest.spyOn(wrapper.vm.map, 'addLayer');
const spyquery = jest.spyOn(wrapper.vm, 'query');
wrapper.vm.viewModel.on('querysucceeded', res => {
expect(res.result.result[0].properties['名称']).toBe('四川省');
expect(res.result.result[0].properties['NAME']).toBe('四川省');
expect(spyAddlayer).toBeCalled();
done();
});
Expand Down Expand Up @@ -334,7 +334,7 @@ describe('query', () => {
expect(wrapper.vm.mapTarget).toBe('map');
const spyquery = jest.spyOn(wrapper.vm, 'query');
wrapper.vm.viewModel.on('querysucceeded', res => {
expect(res.result.result[0].properties['名称']).toBe('四川省');
expect(res.result.result[0].properties['NAME']).toBe('四川省');
expect(wrapper.vm.activeTab).toBe('result');
wrapper.find('.sm-component-query__job-button').trigger('click');
expect(wrapper.vm.activeTab).toBe('job');
Expand Down

0 comments on commit 9f15840

Please sign in to comment.