diff --git a/src/hooks/eventHandler.hook.ts b/src/hooks/eventHandler.hook.ts index d7645cf..3df34ba 100644 --- a/src/hooks/eventHandler.hook.ts +++ b/src/hooks/eventHandler.hook.ts @@ -6,24 +6,14 @@ import { EventBus } from '@/utils/eventBus'; const chartEditStore = useChartEditStore(); const ceshiFunction = mapFun(); - -// 交互事件 -export const eventHandlerHook = ( +export const eventCommonHandler = ( componentList: any, - interactConfigEvents: any, + elementList: any, type: string, params: any = null, ) => { let obj: any = {}; let index = 0; - const elementList: any = []; - for (let i = 0; i < interactConfigEvents.length; i++) { - if (interactConfigEvents[i].type == type) { - for (let j = 0; j < interactConfigEvents[i].movementList.length; j++) { - elementList.push(interactConfigEvents[i].movementList[j]); - } - } - } for (let i = 0; i < componentList.length; i++) { for (let j = 0; j < elementList.length; j++) { if (elementList[j].movement == 'newaddress') { @@ -102,3 +92,38 @@ export const eventHandlerHook = ( } } }; +// 交互事件 +export const eventHandlerHook = ( + componentList: any, + interactConfigEvents: any, + type: string, + params: any = null, +) => { + const elementList: any = []; + for (let i = 0; i < interactConfigEvents.length; i++) { + if (interactConfigEvents[i].type == type) { + if (!interactConfigEvents[i].movementList) { + return false; + } + for (let j = 0; j < interactConfigEvents[i].movementList.length; j++) { + elementList.push(interactConfigEvents[i].movementList[j]); + } + } + } + + if (componentList.length == 0 || elementList.length == 0) { + return false; + } + eventCommonHandler(componentList, elementList, type, params); +}; +// websocket事件 +export const websocketEvent = (interactConfigEvents: any, params: any = null) => { + console.log('websocketEvent', interactConfigEvents, params); + interactConfigEvents.forEach((element) => { + if (element.messageType == params.type) { + element.elementId.forEach((item) => { + EventBus.emit(item + 'websocket', params); + }); + } + }); +}; diff --git a/src/packages/components/Icons/Default/Icon/index.vue b/src/packages/components/Icons/Default/Icon/index.vue index deea59f..5b7232d 100644 --- a/src/packages/components/Icons/Default/Icon/index.vue +++ b/src/packages/components/Icons/Default/Icon/index.vue @@ -20,6 +20,7 @@ import { GoIconify } from '@/components/GoIconify'; import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'; import { eventHandlerHook } from '@/hooks/eventHandler.hook'; + import { EventBus } from '@/utils/eventBus'; const chartEditStore = useChartEditStore(); const props = defineProps({ @@ -30,7 +31,6 @@ }); const { w, h } = toRefs(props.chartConfig.attr); const { dataset, color, size, rotate } = toRefs(props.chartConfig.option); - const clickBtn = (val) => { eventHandlerHook( chartEditStore.getComponentList, @@ -71,6 +71,16 @@ val, ); }; + onMounted(() => { + // 获取eventBus传过来的值 + EventBus.on(props.chartConfig.id + 'dataupdate', (data) => { + console.log('data', data); + }); + // websocket传过来的值 + EventBus.on(props.chartConfig.id + 'websocket', (data) => { + console.log('data', data); + }); + }); diff --git a/src/packages/components/Zhigan/Zhigan/HeadMoreButton/svg/title.vue b/src/packages/components/Zhigan/Zhigan/HeadMoreButton/svg/title.vue index e299c46..5cd93aa 100644 --- a/src/packages/components/Zhigan/Zhigan/HeadMoreButton/svg/title.vue +++ b/src/packages/components/Zhigan/Zhigan/HeadMoreButton/svg/title.vue @@ -1,9 +1,9 @@ diff --git a/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/config.ts b/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/config.ts index d1d32dc..4a042c4 100644 --- a/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/config.ts +++ b/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/config.ts @@ -1,7 +1,7 @@ import cloneDeep from 'lodash/cloneDeep' import { PublicConfigClass } from '@/packages/public' import { CreateComponentType } from '@/packages/index.d' -import { chartInitConfig } from '@/settings/designSetting' +import { chartInitConfig, requestSqlConfig } from '@/settings/designSetting' import { MeiRiShangBaoConfig } from './index' import dataJson from './data.json' @@ -12,7 +12,7 @@ export const option = { dataStyle: { listWidth: 363, listHeight: 28, - sortOrder: true, + sortOrder: '1', titleColor: '#FFFFFF', titleFontSize: 16, timeColor: '#16E795', @@ -28,6 +28,8 @@ export const option = { export default class Config extends PublicConfigClass implements CreateComponentType { public key = MeiRiShangBaoConfig.key public attr = { ...chartInitConfig, w: 400, h: 200, zIndex: -1 } + public request = { ...requestSqlConfig, requestSQLContent: { sql: 'select * from zg_meirishangbaoshuliangtongji' }, } + public filter = "return res.result;" public chartConfig = cloneDeep(MeiRiShangBaoConfig) public option = cloneDeep(option) } diff --git a/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/config.vue b/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/config.vue index f899ff7..6d9a468 100644 --- a/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/config.vue +++ b/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/config.vue @@ -57,13 +57,17 @@ > - - - - - - 排序方式 - + + + 数量排序 + 时间排序 + 排序方式 + + diff --git a/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/index.vue b/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/index.vue index 8aa03cc..8793f2c 100644 --- a/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/index.vue +++ b/src/packages/components/Zhigan/Zhigan/MeiRiShangBao/index.vue @@ -40,45 +40,6 @@ dataStyle: props.chartConfig.option.dataStyle, }); - watch( - () => option.dataStyle.sortOrder, - () => { - if (option.dataStyle.sortOrder) { - // 数量排序 - option.dataset = option.dataset.sort((a, b) => parseInt(b.num) - parseInt(a.num)); - option.dataset = option.dataset.map((item, index) => { - const order = String(index + 1); - const newKey = Number(order) >= 10 ? `${order}` : `0${order}`; - return { - ...item, - mouseFlag: true, - key: newKey, - }; - }); - } else { - // 时间排序 - option.dataset = option.dataset.sort((a, b) => { - const timeA = dayjs(a.time, 'HH:mm:ss'); - const timeB = dayjs(b.time, 'HH:mm:ss'); - return timeB.diff(timeA); - }); - option.dataset = option.dataset.map((item, index) => { - const order = String(index + 1); - const newKey = Number(order) >= 10 ? `${order}` : `0${order}`; - return { - ...item, - mouseFlag: true, - key: newKey, - }; - }); - } - }, - { - immediate: true, - deep: true, - }, - ); - watch( () => w.value, () => { @@ -100,6 +61,54 @@ deep: true, }, ); + + watch( + () => option.dataStyle.sortOrder, + () => { + sort(); + }, + { + immediate: true, + deep: true, + }, + ); + + function sort() { + if (option.dataStyle.sortOrder == '0') { + // 数量排序 + option.dataset = option.dataset.sort((a, b) => parseInt(b.num) - parseInt(a.num)); + option.dataset = option.dataset.map((item, index) => { + const order = String(index + 1); + const newKey = Number(order) >= 10 ? `${order}` : `0${order}`; + return { + ...item, + mouseFlag: true, + key: newKey, + }; + }); + } + if (option.dataStyle.sortOrder == '1') { + // 时间排序 + option.dataset = option.dataset.sort((a, b) => { + return dayjs(b.time).diff(dayjs(a.time)); + }); + option.dataset = option.dataset.map((item, index) => { + const order = String(index + 1); + const newKey = Number(order) >= 10 ? `${order}` : `0${order}`; + return { + ...item, + mouseFlag: true, + key: newKey, + }; + }); + } + } + + // 数据callback处理(预览时触发) + useChartDataFetch(props.chartConfig, useChartEditStore, (resData: any[]) => { + option.dataset = resData; + sort(); + }); diff --git a/src/views/preview/suspenseIndex.vue b/src/views/preview/suspenseIndex.vue index 5aea605..bf546b3 100644 --- a/src/views/preview/suspenseIndex.vue +++ b/src/views/preview/suspenseIndex.vue @@ -23,6 +23,7 @@
+
@@ -30,7 +31,7 @@