Skip to content

Commit

Permalink
ISVJ-6584 大屏能支持显示数据服务的字段别名 review by luox
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Nov 10, 2023
1 parent 3662b63 commit f56210d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/common/_utils/EchartsDataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ export default class EchartsDataService {
const sortMatchItem = datasetOptions.find(item => item.sort && item.sort !== 'unsort');
const xField = datasetOptions[0].xField;
const yFields = datasetOptions.map(item => item.yField);
const fieldCaptions = data.fieldCaptions; // 所有字段
const xFieldIndex = fieldCaptions.indexOf(xField); // x字段的下标
const fields = data.fields; // 所有字段
const xFieldIndex = fields.indexOf(xField); // x字段的下标
const fieldValueIndex = this._getUniqFieldDatas(data, xFieldIndex);
const xData = this._stasticXData(fieldValueIndex);
const yDatas = [];
yFields.forEach(yField => {
const yFieldIndex = fieldCaptions.indexOf(yField); // y字段的下标
const yFieldIndex = fields.indexOf(yField); // y字段的下标
const fieldValues = yFieldIndex < 0 ? [] : data.fieldValues[yFieldIndex]; // y字段的所有feature值
const yData = this._stasticYData(fieldValues, fieldValueIndex);
yDatas.push(yData);
Expand Down Expand Up @@ -391,11 +391,11 @@ export default class EchartsDataService {
* @returns {Object} 解析好的Ydata,xdata
*/
_fieldsData(data, datasetOption, features) {
let fieldCaptions, fieldValues, xFieldIndex, yFieldIndex, xData, yData, result;
let fields, fieldValues, xFieldIndex, yFieldIndex, xData, yData, result;
let { yField, xField, isStastic } = datasetOption;
fieldCaptions = data.fieldCaptions; // 所有x字段
xFieldIndex = fieldCaptions.indexOf(xField); // x字段的下标
yFieldIndex = fieldCaptions.indexOf(yField); // y字段的下标
fields = data.fields; // 所有x字段
xFieldIndex = fields.indexOf(xField); // x字段的下标
yFieldIndex = fields.indexOf(yField); // y字段的下标
fieldValues = yFieldIndex < 0 ? [] : data.fieldValues[yFieldIndex]; // y字段的所有feature值
// 该数据是否需要统计,统计的是数组下标
if (isStastic) {
Expand Down
10 changes: 10 additions & 0 deletions src/common/_utils/__tests__/iServerRestService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ describe('iServerRestService', () => {
expect(params[0][0].queryOption).toBe('ATTRIBUTEANDGEOMETRY');
done();
});
it('_getDataFeaturesBySql', done => {
const service = new iServerRestService('url', { hasGeometry: true });
service._getDataFeaturesBySql('mock', {});
service.on({
getdatasucceeded: data => {
expect(data.fields).toEqual(['SMID', '名称'])
done();
},
})
});
});
13 changes: 12 additions & 1 deletion src/common/_utils/iServerRestService.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,19 @@ export default class iServerRestService extends Events {
// 数据来自restdata---results.result.features
this.features = results.result.features;
features = this.features.features;
let fields = []; let fieldCaptions = []; let fieldTypes = [];
if(results.result.datasetInfos) {
const fieldInfos = results.result.datasetInfos[0].fieldInfos;
fieldInfos.forEach(fieldInfo => {
if(fieldInfo.name) {
fields.push(fieldInfo.name.toUpperCase());
fieldCaptions.push(fieldInfo.caption.toUpperCase());
fieldTypes.push(fieldInfo.type);
}
});
}
if (features && features.length > 0) {
data = statisticsFeatures(features);
data = statisticsFeatures(features, fields, fieldCaptions, fieldTypes);
data.totalCount = results.result.totalCount;
} else {
this.triggerEvent('featureisempty', {
Expand Down
21 changes: 14 additions & 7 deletions src/common/_utils/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ export function statisticsFeatures(features, fields, fieldCaptions, fieldTypes)
const data = {
features,
fields: fields || [],
fieldCaptions: fieldCaptions || [],
fieldValues: [],
fieldTypes
};
if (features && !!features.length && !fieldCaptions && !fields) {
const properties = Object.assign({}, features[0].properties, features[features.length - 1].properties);
// 获取每个字段的名字和类型
for (let attr in properties) {
data.fieldCaptions.push(attr);
data.fields.push(attr);
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;
});
}
const properties = Object.assign({}, features[0].properties, features[features.length - 1].properties);
data.fields = Object.keys(properties);
}

for (let m in data.fields) {
const fieldValue = [];
for (let j in features) {
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 @@ -559,6 +559,9 @@ var results = {
var GetFeaturesBySQLService = (SuperMap.GetFeaturesBySQLService = (url, options) => {
const result = {
result: {
datasetInfos: [{
fieldInfos:[{name: "SmID", caption: "SmID", type: "INT32"}, {name: "NAME", caption: "名称", type: "WTEXT"}]
}],
features: {
type: 'FeatureCollection',
features: [
Expand Down

0 comments on commit f56210d

Please sign in to comment.