Commit bcaab1e292116803acaa93cee195cc14b8988a3b

Authored by ww
1 parent 45281440

perf: 优化查询物模型属性历史数据,新增排序字段

... ... @@ -2,6 +2,7 @@ import { DeviceProfileModel } from '../../device/model/deviceModel';
2 2 import { HistoryData } from './model';
3 3 import { defHttp } from '/@/utils/http/axios';
4 4 import { isString } from '/@/utils/is';
  5 +import { OrderByEnum } from '/@/views/device/localtion/cpns/TimePeriodForm/config';
5 6
6 7 // 获取设备配置
7 8 export const getDeviceProfile = (deviceType?: string) => {
... ... @@ -12,11 +13,11 @@ export const getDeviceProfile = (deviceType?: string) => {
12 13 };
13 14
14 15 // 获取历史数据
15   -export const getDeviceHistoryInfo = (params: Recordable, orderBy?: string) => {
  16 +export const getDeviceHistoryInfo = (params: Recordable, orderBy = OrderByEnum.DESC) => {
16 17 return defHttp.get<HistoryData>(
17 18 {
18 19 url: `/plugins/telemetry/DEVICE/${params.entityId}/values/timeseries`,
19   - params: { ...params, entityId: null, orderBy: orderBy || 'DESC' },
  20 + params: { orderBy, ...params, entityId: null },
20 21 },
21 22 {
22 23 joinPrefix: false,
... ...
... ... @@ -5,7 +5,10 @@
5 5 import { useECharts } from '/@/hooks/web/useECharts';
6 6 import { AggregateDataEnum, selectDeviceAttrSchema } from '/@/views/device/localtion/config.data';
7 7 import { useTimePeriodForm } from '/@/views/device/localtion/cpns/TimePeriodForm';
8   - import { defaultSchemas } from '/@/views/device/localtion/cpns/TimePeriodForm/config';
  8 + import {
  9 + defaultSchemas,
  10 + OrderByEnum,
  11 + } from '/@/views/device/localtion/cpns/TimePeriodForm/config';
9 12 import TimePeriodForm from '/@/views/device/localtion/cpns/TimePeriodForm/TimePeriodForm.vue';
10 13 import { useGridLayout } from '/@/hooks/component/useGridLayout';
11 14 import { ColEx } from '/@/components/Form/src/types';
... ... @@ -184,7 +187,6 @@
184 187 if (props.attr) {
185 188 method.setFieldsValue({ keys: props.attr });
186 189 const attrInfo = unref(deviceAttrs).find((item) => item.identifier === props.attr);
187   - console.log({ attrInfo });
188 190 if (
189 191 [DataTypeEnum.IS_STRING, DataTypeEnum.IS_STRUCT].includes(
190 192 attrInfo?.detail.dataType.type as unknown as DataTypeEnum
... ... @@ -198,7 +200,7 @@
198 200 } catch (error) {}
199 201 };
200 202
201   - const openHistoryPanel = async (orderBy?: string) => {
  203 + const openHistoryPanel = async (orderBy = OrderByEnum.ASC) => {
202 204 await nextTick();
203 205 method.updateSchema({
204 206 field: 'keys',
... ...
... ... @@ -32,13 +32,14 @@ export function useHistoryData() {
32 32 };
33 33
34 34 function getSearchParams(value: Partial<Record<SchemaFiled, string>>) {
35   - const { startTs, endTs, interval, agg, limit, keys, way, deviceId } = value;
  35 + const { startTs, endTs, interval, agg, limit, keys, way, deviceId, orderBy } = value;
36 36 const basicRecord = {
37 37 entityId: deviceId,
38 38 keys: keys ? keys : unref(getDeviceKeys).join(),
39 39 interval,
40 40 agg,
41 41 limit,
  42 + orderBy,
42 43 };
43 44 if (way === QueryWay.LATEST) {
44 45 return Object.assign(basicRecord, {
... ...
... ... @@ -21,6 +21,16 @@ export enum SchemaFiled {
21 21 ORDER_BY = 'orderBy',
22 22 }
23 23
  24 +export enum OrderByEnum {
  25 + DESC = 'DESC',
  26 + ASC = 'ASC',
  27 +}
  28 +
  29 +export enum OrderByNameEnum {
  30 + DESC = '降序',
  31 + ASC = '升序',
  32 +}
  33 +
24 34 export enum AggregateDataEnum {
25 35 MIN = 'MIN',
26 36 MAX = 'MAX',
... ... @@ -31,6 +41,18 @@ export enum AggregateDataEnum {
31 41 }
32 42 export const defaultSchemas: FormSchema[] = [
33 43 {
  44 + field: SchemaFiled.ORDER_BY,
  45 + label: '数据排序',
  46 + component: 'Select',
  47 + defaultValue: OrderByEnum.ASC,
  48 + componentProps: {
  49 + options: Object.values(OrderByEnum).map((value) => ({
  50 + value,
  51 + label: OrderByNameEnum[value],
  52 + })),
  53 + },
  54 + },
  55 + {
34 56 field: SchemaFiled.WAY,
35 57 label: '查询方式',
36 58 component: 'RadioGroup',
... ...
... ... @@ -8,6 +8,7 @@ import {
8 8 getPacketIntervalByValue,
9 9 intervalOption,
10 10 } from '/@/views/device/localtion/cpns/TimePeriodForm/helper';
  11 +import { OrderByEnum, OrderByNameEnum } from '/@/views/device/localtion/cpns/TimePeriodForm/config';
11 12 export enum QueryWay {
12 13 LATEST = 'latest',
13 14 TIME_PERIOD = 'timePeriod',
... ... @@ -38,6 +39,18 @@ export enum AggregateDataEnum {
38 39 export const formSchema = (): FormSchema[] => {
39 40 return [
40 41 {
  42 + field: SchemaFiled.ORDER_BY,
  43 + label: '数据排序',
  44 + component: 'Select',
  45 + defaultValue: OrderByEnum.ASC,
  46 + componentProps: {
  47 + options: Object.values(OrderByEnum).map((value) => ({
  48 + value,
  49 + label: OrderByNameEnum[value],
  50 + })),
  51 + },
  52 + },
  53 + {
41 54 field: SchemaFiled.DEVICE_ID,
42 55 label: '设备名称',
43 56 component: 'Select',
... ...
... ... @@ -22,6 +22,7 @@
22 22 import { ModalParamsType } from '/#/utils';
23 23 import { WidgetDataType } from '../../hooks/useDataSource';
24 24 import { ExtraDataSource } from '../../types';
  25 + import { OrderByEnum } from '/@/views/device/localtion/cpns/TimePeriodForm/config';
25 26
26 27 type DeviceOption = Record<'label' | 'value' | 'organizationId', string>;
27 28
... ... @@ -211,6 +212,7 @@
211 212 endTs: Date.now(),
212 213 agg: AggregateDataEnum.NONE,
213 214 limit: 7,
  215 + orderBy: OrderByEnum.ASC,
214 216 });
215 217 historyData.value = getTableHistoryData(res);
216 218 // 判断对象是否为空
... ...