DataPickerModal.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <a-modal
  3. :visible="visible"
  4. :title="null"
  5. :footer="null"
  6. :width="620"
  7. :closable="false"
  8. :destroy-on-close="true"
  9. wrap-class-name="data-interpretation-modal"
  10. @cancel="$emit('close')"
  11. >
  12. <div class="di-header">
  13. <span class="di-header__title"><img :src="aiIcon" width="20" height="20" alt="" class="di-header__icon" />数据解读</span>
  14. <span class="di-header__close" @click="$emit('close')">✕</span>
  15. </div>
  16. <div ref="bodyRef" class="di-body">
  17. <div class="di-section">
  18. <div class="di-section__title">监测对象</div>
  19. <div class="di-section__content di-section__content--target">{{ props.itemName }}</div>
  20. </div>
  21. <div class="di-section">
  22. <div class="di-section__title">分析结论</div>
  23. <div class="di-section__content">
  24. <div v-if="showProcess" class="di-process">
  25. <div v-if="processCollapsed" class="di-process__summary" @click="processCollapsed = false">
  26. <span class="di-process__summary-icon">▸</span>
  27. <span>查看处理过程</span>
  28. </div>
  29. <template v-else>
  30. <div v-if="!props.loading" class="di-process__summary" @click="processCollapsed = true">
  31. <span class="di-process__summary-icon">▾</span>
  32. <span>收起处理过程</span>
  33. </div>
  34. <div v-if="thinking" class="di-process__row di-process__thinking"><a-spin size="small" /><span>AI 正在思考...</span></div>
  35. <div v-if="todos.length > 0" class="di-process__todos">
  36. <div v-for="(todo, i) in todos" :key="i" class="di-todo-item" :class="`di-todo-item--${todo.status}`">
  37. <span class="di-todo-item__icon">
  38. <span v-if="todo.status === 'completed'" class="di-todo-check">✓</span>
  39. <span v-else-if="todo.status === 'in_progress'" class="di-todo-spinner"></span>
  40. <span v-else class="di-todo-dot"></span>
  41. </span>
  42. <span class="di-todo-item__text">{{ todo.content }}</span>
  43. </div>
  44. </div>
  45. <div v-if="props.latestMessage && loading" class="di-process__row di-process__message">
  46. <span class="di-process__dot"></span><span>{{ props.latestMessage }}</span>
  47. </div>
  48. </template>
  49. </div>
  50. <div v-if="loading && !hasContent" class="di-loading"><a-spin tip="正在分析数据..." /></div>
  51. <div v-if="hasContent" class="di-markdown" v-html="renderedText"></div>
  52. <div v-else-if="error && !loading" class="di-error">数据解读失败:{{ error }}</div>
  53. </div>
  54. </div>
  55. </div>
  56. <div v-if="loading && hasContent" class="di-streaming-bar"><a-spin size="small" /><span class="di-streaming-bar__tip">AI 正在生成...</span></div>
  57. </a-modal>
  58. </template>
  59. <script lang="ts" setup>
  60. import { computed, ref, watch, nextTick, onMounted, onBeforeUnmount } from 'vue';
  61. import { marked } from 'marked';
  62. import type { TodoItem, ToolCallRecord } from '../types';
  63. import aiIcon from '@/assets/images/ventAI/dataPicker/AI-icon.svg';
  64. const props = defineProps<{
  65. visible: boolean;
  66. loading: boolean;
  67. streamingText: string;
  68. error: string | null;
  69. thinking: boolean;
  70. todos: TodoItem[];
  71. executingTools: string[];
  72. toolCalls: ToolCallRecord[];
  73. latestMessage: string;
  74. itemName: string;
  75. }>();
  76. defineEmits<{ close: [] }>();
  77. const bodyRef = ref<HTMLDivElement>();
  78. const isNearBottom = ref(true);
  79. function checkNearBottom() {
  80. const el = bodyRef.value;
  81. if (!el) return;
  82. isNearBottom.value = el.scrollHeight - el.scrollTop - el.clientHeight < 40;
  83. }
  84. function scrollToBottom() {
  85. const el = bodyRef.value;
  86. if (!el) return;
  87. el.scrollTop = el.scrollHeight;
  88. }
  89. let scrollListenerAttached = false;
  90. onMounted(() => {
  91. const el = bodyRef.value;
  92. if (el) {
  93. el.addEventListener('scroll', checkNearBottom, { passive: true });
  94. scrollListenerAttached = true;
  95. }
  96. });
  97. onBeforeUnmount(() => {
  98. if (scrollListenerAttached && bodyRef.value) {
  99. bodyRef.value.removeEventListener('scroll', checkNearBottom);
  100. }
  101. });
  102. const hasContent = computed(() => !!props.streamingText);
  103. const hasProcess = computed(
  104. () => props.thinking || props.todos.length > 0 || props.executingTools.length > 0 || props.toolCalls.length > 0 || !!props.latestMessage
  105. );
  106. const showProcess = computed(() => hasProcess.value);
  107. const processCollapsed = ref(false);
  108. watch(
  109. () => props.loading,
  110. (val, oldVal) => {
  111. if (oldVal && !val && hasProcess.value) processCollapsed.value = true;
  112. }
  113. );
  114. watch(
  115. () => [props.streamingText, props.latestMessage, props.todos],
  116. () => {
  117. if (isNearBottom.value) {
  118. nextTick(scrollToBottom);
  119. }
  120. },
  121. { deep: true }
  122. );
  123. const renderedText = computed(() => {
  124. if (!props.streamingText) return '';
  125. const processed = props.streamingText.replace(/<br\s*\/?>/gi, ' \n');
  126. return marked.parse(processed);
  127. });
  128. </script>
  129. <style lang="less">
  130. .data-interpretation-modal {
  131. position: fixed !important;
  132. top: 0 !important;
  133. left: 0 !important;
  134. width: 100vw !important;
  135. height: 100vh !important;
  136. display: flex !important;
  137. align-items: flex-start !important;
  138. justify-content: center !important;
  139. padding-top: 10vh;
  140. z-index: 1000 !important;
  141. .ant-modal {
  142. top: 0;
  143. max-width: 90vw;
  144. }
  145. .ant-modal-content {
  146. color: var(--vent-font-color) !important;
  147. background-color: rgba(9, 23, 44, 0.3);
  148. border: 1px solid #3df6ff;
  149. box-shadow: inset 0 0 12px #2cb6ff;
  150. backdrop-filter: blur(30px);
  151. }
  152. .ant-modal-body {
  153. padding: 0;
  154. max-height: 75vh;
  155. overflow-y: auto;
  156. }
  157. .ant-spin-text {
  158. color: #c8d6e5;
  159. }
  160. }
  161. </style>
  162. <style lang="less" scoped>
  163. .di-header {
  164. display: flex;
  165. justify-content: space-between;
  166. align-items: center;
  167. padding: 8px;
  168. border-bottom: 1px solid rgba(30, 144, 255, 0.15);
  169. flex-shrink: 0;
  170. background-color: rgba(57, 163, 255, 0.2);
  171. &__title {
  172. font-size: 18px;
  173. font-weight: bold;
  174. color: #fff;
  175. letter-spacing: 2px;
  176. display: flex;
  177. align-items: center;
  178. gap: 8px;
  179. }
  180. &__icon {
  181. display: inline-block;
  182. }
  183. &__close {
  184. cursor: pointer;
  185. font-size: 18px;
  186. color: #8899aa;
  187. &:hover {
  188. color: #fff;
  189. }
  190. }
  191. }
  192. .di-body {
  193. padding: 18px 24px;
  194. min-height: 120px;
  195. max-height: 700px;
  196. overflow-y: auto;
  197. }
  198. .di-section {
  199. margin-bottom: 16px;
  200. &:last-child {
  201. margin-bottom: 0;
  202. }
  203. &__title {
  204. color: #c9f0ff;
  205. font-size: 15px;
  206. font-weight: bold;
  207. margin-bottom: 8px;
  208. }
  209. &__content {
  210. border-top: 2px solid #2cb6ff;
  211. background: rgba(36, 138, 191, 0.1);
  212. padding: 12px;
  213. &--target {
  214. color: #fff;
  215. font-size: 14px;
  216. }
  217. }
  218. }
  219. .di-loading {
  220. display: flex;
  221. justify-content: center;
  222. align-items: center;
  223. padding: 40px 0;
  224. }
  225. .di-process {
  226. margin-bottom: 16px;
  227. // border-bottom: 1px solid rgba(30, 144, 255, 0.12);
  228. &__row {
  229. display: flex;
  230. align-items: center;
  231. gap: 8px;
  232. padding: 6px 0;
  233. font-size: 13px;
  234. color: #8899aa;
  235. }
  236. }
  237. .di-process__thinking {
  238. color: #4da6ff;
  239. font-size: 13px;
  240. }
  241. .di-process__executing {
  242. color: #c8a853;
  243. font-size: 13px;
  244. }
  245. .di-process__message {
  246. color: #8899aa;
  247. font-size: 13px;
  248. }
  249. .di-process__dot {
  250. width: 6px;
  251. height: 6px;
  252. border-radius: 50%;
  253. background: #4da6ff;
  254. animation: di-pulse 1.4s ease-in-out infinite;
  255. }
  256. @keyframes di-pulse {
  257. 0%,
  258. 100% {
  259. opacity: 0.3;
  260. }
  261. 50% {
  262. opacity: 1;
  263. }
  264. }
  265. .di-process__summary {
  266. display: flex;
  267. align-items: center;
  268. gap: 6px;
  269. padding: 6px 0;
  270. font-size: 13px;
  271. color: #8899aa;
  272. cursor: pointer;
  273. user-select: none;
  274. &:hover {
  275. color: #4da6ff;
  276. }
  277. }
  278. .di-process__summary-icon {
  279. font-size: 12px;
  280. }
  281. .di-process__todos {
  282. margin: 6px 0;
  283. }
  284. .di-todo-item {
  285. display: flex;
  286. align-items: center;
  287. gap: 8px;
  288. padding: 4px 0;
  289. font-size: 13px;
  290. line-height: 1.6;
  291. &__icon {
  292. flex-shrink: 0;
  293. width: 16px;
  294. display: flex;
  295. align-items: center;
  296. justify-content: center;
  297. }
  298. &__text {
  299. color: #c8d6e5;
  300. }
  301. &--completed &__text {
  302. color: #6b7a8a;
  303. text-decoration: line-through;
  304. }
  305. &--in_progress &__text {
  306. color: #4da6ff;
  307. }
  308. }
  309. .di-todo-check {
  310. color: #27ae60;
  311. font-size: 12px;
  312. font-weight: bold;
  313. }
  314. .di-todo-dot {
  315. width: 6px;
  316. height: 6px;
  317. border-radius: 50%;
  318. background: #4a5568;
  319. display: inline-block;
  320. }
  321. .di-todo-spinner {
  322. width: 12px;
  323. height: 12px;
  324. border: 2px solid rgba(77, 166, 255, 0.25);
  325. border-top-color: #4da6ff;
  326. border-radius: 50%;
  327. animation: di-spin 0.8s linear infinite;
  328. }
  329. @keyframes di-spin {
  330. to {
  331. transform: rotate(360deg);
  332. }
  333. }
  334. .di-markdown {
  335. line-height: 1.8;
  336. color: #fff;
  337. word-break: break-word;
  338. :deep(h1),
  339. :deep(h2),
  340. :deep(h3),
  341. :deep(h4) {
  342. color: #4da6ff;
  343. margin: 12px 0 8px;
  344. }
  345. :deep(p) {
  346. margin: 6px 0;
  347. }
  348. :deep(ul),
  349. :deep(ol) {
  350. padding-left: 20px;
  351. margin: 6px 0;
  352. }
  353. :deep(strong) {
  354. color: #fff;
  355. }
  356. :deep(code) {
  357. background: rgba(30, 144, 255, 0.15);
  358. padding: 1px 5px;
  359. border-radius: 3px;
  360. font-size: 13px;
  361. }
  362. :deep(pre) {
  363. background: rgba(0, 0, 0, 0.3);
  364. padding: 12px;
  365. border-radius: 6px;
  366. overflow-x: auto;
  367. }
  368. :deep(blockquote) {
  369. border-left: 3px solid #4da6ff;
  370. padding-left: 12px;
  371. margin: 8px 0;
  372. color: #8899aa;
  373. }
  374. :deep(table) {
  375. width: 100%;
  376. border-collapse: collapse;
  377. margin: 8px 0;
  378. th,
  379. td {
  380. border: 1px solid rgba(30, 144, 255, 0.2);
  381. padding: 6px 10px;
  382. text-align: left;
  383. }
  384. th {
  385. background: rgba(30, 144, 255, 0.1);
  386. color: #000;
  387. }
  388. }
  389. }
  390. .di-streaming-bar {
  391. display: flex;
  392. align-items: center;
  393. gap: 8px;
  394. padding: 8px 24px 16px;
  395. border-top: 1px solid rgba(30, 144, 255, 0.1);
  396. &__tip {
  397. font-size: 12px;
  398. color: #8899aa;
  399. }
  400. }
  401. .di-error {
  402. padding: 40px;
  403. text-align: center;
  404. color: #e74c3c;
  405. }
  406. </style>