ForecastView.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <script setup>
  2. import { onMounted, ref } from 'vue';
  3. import { useRouter } from 'vue-router';
  4. import { NTabs, NTab } from 'naive-ui';
  5. import * as echarts from 'echarts';
  6. import { getAreaOptions } from './config/echartOptions'
  7. import { useChatStore } from '@/stores/modules/chatStore';
  8. import { BaseTable, ChatWelcome, RecodeSquareCardItem, TheSubMenu, TheChatView } from "@/components";
  9. import { ChatBaseCard, ChatAnswer } from '@/components/Chat';
  10. import { formatToData, replaceArray } from "@/utils/format";
  11. import { waterApi } from '@/api/water';
  12. import { useInfinite, useRecommend, useScroll } from '@/composables'
  13. import { inColumns, outColumns } from './config';
  14. const { recommendList } = useRecommend({ type: 3 });
  15. const { scrollRef, scrollToTop } = useScroll();
  16. const { recordList, isFetching, onScrolltolower, onRestore } = useInfinite('/front/bigModel/warning/pageList', { type: 2, warningStatus: 0 });
  17. const router = useRouter();
  18. const chatStore = useChatStore();
  19. const answerResult = ref("");
  20. const textDataSources = ref(null);
  21. const chartTitle = ref("");
  22. let chart = null;
  23. const echartRef = ref({});
  24. const subMenuRef = ref(null);
  25. // 进出水数据
  26. const jsTableData = ref([]);
  27. const csTableData = ref([]);
  28. const warningActive = ref(0);
  29. // 切换Tabs
  30. const onChangeTabs = warningStatus => {
  31. answerResult.value = '';
  32. textDataSources.value = '';
  33. onRestore({ warningStatus });
  34. warningActive.value = warningStatus;
  35. subMenuRef.value.scrollToTop();
  36. }
  37. // 打开详情
  38. const handleOpenContent = async ({ id, reason: title }) => {
  39. const { data } = await waterApi.getWaringDetails(id);
  40. const showVal = JSON.parse(data.showVal);
  41. const { basic, jsData, csData, chartsData, chartsTitle } = showVal;
  42. answerResult.value = data.answer;
  43. chartTitle.value = chartsTitle;
  44. basic.title = title
  45. textDataSources.value = formatToData({
  46. dataSource: basic,
  47. warnKey: '预测值',
  48. statusVal: !!warningActive.value ? '已完成' : basic['状态']
  49. });
  50. jsTableData.value = [jsData];
  51. csTableData.value = [csData];
  52. createLineChat(chartsData);
  53. scrollToTop();
  54. }
  55. // 创建图表
  56. const createLineChat = (data) => {
  57. const [xAxisData, yData] = data.reduce((acc, { time, val }) => {
  58. acc[0].push(time);
  59. acc[1].push(val);
  60. return acc;
  61. }, [[], []]);
  62. const seriesPast = replaceArray([...yData], yData.length - 3, 3, null);
  63. const seriesFuture = replaceArray([...yData], 0, 5, null);
  64. const option = getAreaOptions({xAxisData, seriesList: [seriesPast, seriesFuture]});
  65. chart.setOption(option);
  66. }
  67. // 欢迎 - 问答
  68. const handleWelcomeRecommend = question => {
  69. chatStore.setChatQuestion(question);
  70. router.push('/answer');
  71. }
  72. onMounted(() => {
  73. chart = echarts.init(echartRef.value, 'light', { width: 660, height: 200 });
  74. })
  75. </script>
  76. <template>
  77. <section class="flex items-start h-full" id="warning">
  78. <TheSubMenu title="预测预警" @scrollToLower="onScrolltolower" :loading="isFetching" ref="subMenuRef">
  79. <template #top>
  80. <div class="border-[#DAE5ED]">
  81. <n-tabs type="line" justify-content="space-evenly">
  82. <n-tab name="oasis" tab="正在预警" @click="onChangeTabs(0)"></n-tab>
  83. <n-tab name="thebeatles" tab="历史预警" @click="onChangeTabs(1)"></n-tab>
  84. </n-tabs>
  85. </div>
  86. </template>
  87. <div class="px-[12px] py-[14px] text-[#5e5e5e]">
  88. <p v-show="!recordList.length" class="pt-[30px] text-[12px] text-[#999] text-center">暂无预警数据</p>
  89. <div class="grid grid-cols-1 gap-[12px]">
  90. <RecodeSquareCardItem v-for="item in recordList" :key="item.id" :item="item" @on-click="handleOpenContent" />
  91. </div>
  92. </div>
  93. </TheSubMenu>
  94. <TheChatView ref="scrollRef" :is-footer="false">
  95. <ChatWelcome title="您好,我是LibraAI工艺管控助手" card-title="常见处理方案:" :sub-title="[
  96. '报警分析功能具备实时监测与预警机制,检测到异常情况推送相关工作人员确保问题及时处理',
  97. '报警时间为每小时警报,请大家及时处理'
  98. ]" v-if="!textDataSources" :card-content="recommendList" @on-click="handleWelcomeRecommend" />
  99. <ChatBaseCard v-show="textDataSources">
  100. <div class="waring-answer-wrapper">
  101. <dl class="message-inner warning-info_medium ">
  102. <dt class="mb-[2px] font-bold text-[#1A2029]">{{ textDataSources?.title }}</dt>
  103. <dd v-for="item, index in textDataSources?.list" :key="index"><span
  104. :class="{ 'text-[#F44C49]': item.isWarning }">{{ item.label }}: {{ item.value }}</span></dd>
  105. </dl>
  106. <div class="table-inner">
  107. <div class="warning-table mb-[8px]">
  108. <div class="title">
  109. <span>当前进水数据:</span>
  110. </div>
  111. <div class="main">
  112. <BaseTable :columns="inColumns" :data="jsTableData"></BaseTable>
  113. </div>
  114. </div>
  115. <div class="warning-table">
  116. <div class="title">
  117. <span>当前出水数据:</span>
  118. </div>
  119. <div class="main">
  120. <BaseTable :columns="outColumns" :data="csTableData"></BaseTable>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. <div class="echart-warpper">
  126. <span class="#1A2029 font-bold">{{ chartTitle }}</span>
  127. <div id="chartContainer" class="w-[660px] h-[200px]" ref="echartRef"></div>
  128. <ul class="flex justify-between w-[660px] text-center text-[12px] text-[#666] leading-[18px]">
  129. <li class="w-[400px] pl-[30px]">
  130. <span class="inline-block w-[10px] h-[2px] mb-[2px] mr-[4px] bg-[#2185da]"></span>
  131. <span>过去</span>
  132. </li>
  133. <li class="flex-1 pr-[30px]">
  134. <span class="inline-block w-[10px] h-[2px] mb-[2px] mr-[4px] bg-[#2ee055]"></span>
  135. <span>未来</span>
  136. </li>
  137. </ul>
  138. </div>
  139. </ChatBaseCard>
  140. <ChatAnswer :loading="false" :delay-loading="false" :toggleVisibleIcons="false" :content="answerResult" v-if="answerResult" class="reset-chart"/>
  141. </TheChatView>
  142. </section>
  143. </template>
  144. <style lang="scss" scoped>
  145. .echart-warpper {
  146. display: flex;
  147. align-items: center;
  148. justify-content: center;
  149. flex-flow: column;
  150. width: 100%;
  151. padding: 50px 0 30px 0;
  152. border-radius: 8px;
  153. }
  154. </style>