You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4770 lines
137 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <script setup>
  2. import { ref, onMounted, watch, nextTick, reactive, onUnmounted } from "vue";
  3. import { ElDialog } from "element-plus";
  4. import { getReplyStreamAPI, getReplyAPI, TTSAPI, getQuestionAPI, qsArpAamClickAPI } from "../api/AIxiaocaishen";
  5. import { useUserStore } from '../store/userPessionCode'
  6. import { useChatStore } from '../store/chat'
  7. import { useAudioStore } from '../store/audio'
  8. import { useDataStore } from '@/store/dataList.js'
  9. import { marked } from 'marked'; // 引入marked库
  10. import katex from 'katex'; // 引入 KaTeX 库
  11. import { htmlToText } from 'html-to-text';
  12. import { Howl, Howler } from 'howler';
  13. import * as echarts from 'echarts'
  14. import AIgif1 from '@/assets/img/AIchat/AIgif1.gif'
  15. import AIgif2 from '@/assets/img/AIchat/AIgif2.gif'
  16. import AIgif3 from '@/assets/img/AIchat/AIgif3.gif'
  17. import AIgif4 from '@/assets/img/AIchat/AIgif4.gif'
  18. import AIgif5 from '@/assets/img/AIchat/AIgif5.gif'
  19. import AIgif6 from '@/assets/img/AIchat/AIgif6.gif'
  20. import AIgif7 from '@/assets/img/AIchat/AIgif7.gif'
  21. const gifList = [
  22. AIgif1,
  23. AIgif2,
  24. AIgif3,
  25. AIgif4,
  26. AIgif5,
  27. AIgif6,
  28. AIgif7
  29. ]
  30. const chatStore = useChatStore()
  31. const audioStore = useAudioStore()
  32. const dataStore = useDataStore()
  33. // 随机GIF
  34. const currentGif = ref("");
  35. // 推荐问题飘屏数据
  36. const questionsList = ref([])
  37. const getQuestionsList = async () => {
  38. const result = await getQuestionAPI()
  39. questionsList.value = result.data
  40. }
  41. // 定义自定义事件
  42. const emit = defineEmits(["updateMessage", "sendMessage"]);
  43. // 弹窗控制
  44. const dialogVisible = ref(false);
  45. const currentQuestions = ref("");
  46. const showQuestions = async (questions) => {
  47. const click = await qsArpAamClickAPI({
  48. token: localStorage.getItem('localToken'),
  49. id: questions.id
  50. })
  51. console.log(click);
  52. currentQuestions.value = questions;
  53. // 触发自定义事件
  54. emit("updateMessage", questions.title);
  55. // emit("sendMessage");
  56. };
  57. // 飘屏控制
  58. const floatingTopMouseEnter = function () {
  59. const userAgent = navigator.userAgent.toLowerCase();
  60. const mobileKeywords = ['mobile', 'android', 'iphone', 'ipad', 'ipod'];
  61. const isMobile = mobileKeywords.some(keyword => userAgent.includes(keyword));
  62. if (isMobile) {
  63. return
  64. }
  65. console.log("鼠标指上去");
  66. const floatTop = document.getElementById("top");
  67. floatTop.style.animationPlayState = "paused";
  68. }
  69. const floatingTopMouseLeave = function () {
  70. const userAgent = navigator.userAgent.toLowerCase();
  71. const mobileKeywords = ['mobile', 'android', 'iphone', 'ipad', 'ipod'];
  72. const isMobile = mobileKeywords.some(keyword => userAgent.includes(keyword));
  73. if (isMobile) {
  74. return
  75. }
  76. console.log("鼠标指下去");
  77. const floatTop = document.getElementById("top");
  78. floatTop.style.animationPlayState = "running"
  79. }
  80. const floatingBottomMouseEnter = function () {
  81. const userAgent = navigator.userAgent.toLowerCase();
  82. const mobileKeywords = ['mobile', 'android', 'iphone', 'ipad', 'ipod'];
  83. const isMobile = mobileKeywords.some(keyword => userAgent.includes(keyword));
  84. if (isMobile) {
  85. return
  86. }
  87. console.log("鼠标指上去");
  88. const floatBottom = document.getElementById("bottom");
  89. floatBottom.style.animationPlayState = "paused";
  90. }
  91. const floatingBottomMouseLeave = function () {
  92. const userAgent = navigator.userAgent.toLowerCase();
  93. const mobileKeywords = ['mobile', 'android', 'iphone', 'ipad', 'ipod'];
  94. const isMobile = mobileKeywords.some(keyword => userAgent.includes(keyword));
  95. if (isMobile) {
  96. return
  97. }
  98. console.log("鼠标指下去");
  99. const floatBottom = document.getElementById("bottom");
  100. floatBottom.style.animationPlayState = "running"
  101. }
  102. // 音频播放方法
  103. const playAudio = (url) => {
  104. // 添加空值校验
  105. if (!url) {
  106. console.warn('音频URL为空,跳过播放');
  107. audioStore.isPlaying = false;
  108. return;
  109. }
  110. const handlePlay = () => {
  111. // if (audioStore.soundInstance) {
  112. // Howler.unload(); // 添加清理旧实例
  113. // // audioStore.soundInstance.stop()
  114. // }
  115. if (audioStore.isNewInstance) {
  116. const newSound = new Howl({
  117. src: [url],
  118. html5: true, // 强制HTML5 Audio解决iOS兼容问题
  119. format: ['mp3', 'acc'],
  120. rate: 1.2, // 调整播放速度
  121. onplay: () => {
  122. audioStore.isPlaying = true // 改为更新store状态
  123. newSound.volume(1) // 添加音量设置
  124. },
  125. onend: () => audioStore.isPlaying = false,
  126. onstop: () => audioStore.isPlaying = false,
  127. onloaderror: (id, err) => {
  128. console.error('音频加载失败:', err);
  129. ElMessage.error('音频播放失败,请检查网络连接');
  130. }
  131. });
  132. if (audioStore.nowSound) {
  133. audioStore.nowSound.stop()
  134. }
  135. audioStore.nowSound = newSound;
  136. audioStore.isNewInstance = false;
  137. console.log('新音频')
  138. } else {
  139. console.log('已经有音频')
  140. }
  141. const newSound = audioStore.nowSound;
  142. // 添加立即播放逻辑
  143. newSound.play()
  144. audioStore.setAudioInstance(newSound);
  145. Howler._howls.push(newSound); // 强制注册到全局管理
  146. // // 处理浏览器自动播放策略
  147. // if (Howler.autoUnlock) {
  148. // Howler.autoUnlock();
  149. // }
  150. }
  151. // if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
  152. // document.addEventListener('touchstart', handlePlay, { once: true });
  153. // ElMessage.info('请轻触屏幕以启用音频播放');
  154. // } else {
  155. // handlePlay();
  156. // }
  157. handlePlay();
  158. // Howler.volume(1.0) // 添加全局音量设置
  159. };
  160. // 新增暂停方法
  161. const pauseAudio = () => {
  162. if (audioStore.soundInstance) {
  163. // 添加移动端特殊处理
  164. // if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
  165. // Howler.pause(); // iOS需要强制停止音频上下文
  166. // } else {
  167. // audioStore.soundInstance.pause();
  168. // }
  169. audioStore.soundInstance.pause();
  170. audioStore.isPlaying = false;
  171. // // 添加状态同步
  172. // nextTick(() => {
  173. // Howler.unload();
  174. // audioStore.soundInstance = null;
  175. // });
  176. }
  177. };
  178. // 获取消息
  179. const chatMsg = computed(() => chatStore.messages)
  180. const props = defineProps({
  181. messages: Array,
  182. chartData: {
  183. type: Object,
  184. default: null
  185. },
  186. index: {
  187. type: Number,
  188. required: true
  189. }
  190. });
  191. // 打字机效果
  192. const typewriterContent = ref("")
  193. const isTyping = ref(false)
  194. const typeWriter = (text, callback) => {
  195. let index = 0
  196. isTyping.value = true
  197. typewriterContent.value = ""
  198. const typingInterval = setInterval(() => {
  199. if (index < text.length) {
  200. typewriterContent.value += text.charAt(index)
  201. index++
  202. // 自动滚动到底部
  203. nextTick(() => {
  204. const container = document.querySelector('.message-area')
  205. if (container) container.scrollTop = container.scrollHeight
  206. })
  207. } else {
  208. clearInterval(typingInterval)
  209. isTyping.value = false
  210. if (callback) callback()
  211. }
  212. }, 50) // 调整速度(毫秒)
  213. }
  214. const hasValidData = ref(false)
  215. // 创建一个非响应式的对象来存储图表实例
  216. const chartInstancesMap = {};
  217. // 存储上一次的消息的length
  218. const previousMessagesLength = ref(0);
  219. watch(
  220. () => props.messages,
  221. async (newVal, oldVal) => {
  222. // console.log(newVal, 'newVal')
  223. // console.log(oldVal, 'oldVal')
  224. // console.log(previousMessagesLength.value, 'previousMessagesLength')
  225. // console.log(newVal.length, 'newVal.length')
  226. // // 添加空值判断
  227. if (!newVal?.length || newVal === previousMessagesLength.value) return;
  228. previousMessagesLength.value = newVal.length;
  229. if (newVal.length > 0) {
  230. console.log("消息列表已更新,最新消息:", newVal[newVal.length - 1])
  231. chatStore.messages.push(newVal[newVal.length - 1])
  232. console.log("消息列表已更新,最新消息:", chatMsg[chatMsg.length - 1]);
  233. console.log('token', localStorage.getItem('localToken'));
  234. // 获取权限
  235. const userStore = useUserStore();
  236. const params = {
  237. content: newVal[newVal.length - 1].content,
  238. userData: {
  239. token: localStorage.getItem('localToken'),
  240. // language: "cn",
  241. // brainPrivilegeState: userStore.brainPerssion,
  242. // swordPrivilegeState: userStore.swordPerssion,
  243. // stockForecastPrivile: userStore.pricePerssion,
  244. // spaceForecastPrivile: userStore.timePerssion,
  245. // aibullPrivilegeState: userStore.aibullPerssion,
  246. // aigoldBullPrivilegeS: userStore.aiGnbullPerssion,
  247. // airadarPrivilegeStat: userStore.airadarPerssion,
  248. // marketList: "hk,cn,usa,my,sg,vi,in,gb"
  249. // token: "+SsksARQgUHIbIG3rRnnbZi0+fEeMx8pywnIlrmTxo5EOPR/wjWDV7w7+ZUseiBtf9kFa/atmNx6QfSpv5w",
  250. language: "cn",
  251. brainPrivilegeState: "1",
  252. swordPrivilegeState: "1",
  253. stockForecastPrivile: "1",
  254. spaceForecastPrivile: "1",
  255. aibullPrivilegeState: "1",
  256. aigoldBullPrivilegeS: "1",
  257. airadarPrivilegeStat: "1",
  258. marketList: "hk,cn,usa,my,sg,vi,in,gb"
  259. }
  260. }
  261. try {
  262. chatStore.messages.push({
  263. sender: "ai",
  264. content:
  265. `<div>
  266. <span>AI正在思考中</span>
  267. <el-icon class="is-loading">
  268. <Loading />
  269. </el-icon>
  270. </div>`
  271. });
  272. // 调用工作流获取回复
  273. const result = (await getReplyAPI(params)).json();
  274. // console.log(result, "result");
  275. // 获取结果
  276. const ans = ref();
  277. await result.then((res) => {
  278. // console.log(res.data, "res");
  279. // 解析 data 字段中的 JSON
  280. ans.value = JSON.parse(res.data);
  281. })
  282. console.log(ans.value, "ans");
  283. const AIcontent = ref("");
  284. // 处理不同的 answer 字段
  285. if (ans.value.resp !== "" && ans.value.resp !== null) {
  286. console.log('执行回绝话术')
  287. AIcontent.value = ans.value.resp;
  288. // 修改后的消息处理逻辑
  289. const processedContent = marked(AIcontent.value);
  290. const katexRegex = /\$\$(.*?)\$\$/g;
  291. // const plainTextContent = htmlToText(processedContent);
  292. const aiContent = processedContent.replace(katexRegex, (match, formula) => {
  293. try {
  294. return katex.renderToString(formula, { throwOnError: false });
  295. } catch (error) {
  296. console.error('KaTeX 渲染错误:', error);
  297. return match;
  298. }
  299. });
  300. console.log(aiContent, 'aiContent');
  301. chatStore.messages.pop();
  302. chatStore.messages.push({
  303. sender: "ai",
  304. content: aiContent,
  305. });
  306. chatStore.setLoading(false);
  307. } else { // 判断是否是股票问题
  308. if (ans.value.answer !== "") {
  309. AIcontent.value = ans.value.answer;
  310. const type = ans.value.type;
  311. const data = JSON.parse(ans.value.data);
  312. console.log("处理 K 线数据 - 开始");
  313. console.log(data, "data");
  314. const Kline20 = {
  315. name: data.data.HomePage.StockInformation.Name,
  316. Kline: data.data,
  317. type: type
  318. }
  319. // 打印K线数据结构
  320. console.log("K线数据结构:", Kline20);
  321. console.log("K线数据名称:", Kline20.name);
  322. console.log("K线数据类型:", Kline20.type);
  323. console.log("K线数据:", Kline20.Kline ? Kline20.Kline : null);
  324. // 设置数据有效标志
  325. hasValidData.value = true;
  326. console.log("hasValidData设置为:", hasValidData.value);
  327. chatStore.messages.pop();
  328. // 先推送K线图消息
  329. const klineMessageId = `kline-${Date.now()}`;
  330. console.log("生成K线消息ID:", klineMessageId);
  331. chatStore.messages.push({
  332. sender: "ai",
  333. type: "kline",
  334. chartData: Kline20,
  335. messageId: klineMessageId,
  336. hasValidData: true // 添加hasValidData标志
  337. });
  338. console.log("K线消息已添加到聊天列表");
  339. // 再推送文字分析内容的消息
  340. chatStore.messages.push({
  341. sender: "ai",
  342. content: "AI正在思考中..."
  343. });
  344. // 在渲染完成后初始化图表
  345. nextTick(() => {
  346. console.log("nextTick开始 - 准备渲染图表");
  347. console.log("消息列表:", chatStore.messages);
  348. // 寻找最新添加的K线消息索引
  349. let klineIndex = -1;
  350. for (let i = 0; i < chatStore.messages.length; i++) {
  351. if (chatStore.messages[i].messageId === klineMessageId) {
  352. klineIndex = i;
  353. break;
  354. }
  355. }
  356. console.log("找到的K线消息索引:", klineIndex);
  357. if (klineIndex !== -1) {
  358. const containerId = `kline-container-${klineIndex}`;
  359. console.log("图表容器ID:", containerId);
  360. // 确保DOM已经渲染完成
  361. setTimeout(() => {
  362. console.log("延时执行,确保DOM已渲染");
  363. KlineCanvsEcharts(containerId);
  364. }, 100); // 短暂延时确保DOM已渲染
  365. } else {
  366. console.warn("未找到K线消息");
  367. }
  368. });
  369. }
  370. // 修改后的消息处理逻辑
  371. const processedContent = marked(AIcontent.value);
  372. const katexRegex = /\$\$(.*?)\$\$/g;
  373. const plainTextContent = htmlToText(processedContent);
  374. // 获取音频数据
  375. const TTSResult = (await TTSAPI({
  376. language: "cn",
  377. content: plainTextContent
  378. })).json()
  379. const tts = ref();
  380. await TTSResult.then((res) => {
  381. tts.value = JSON.parse(res.data);
  382. })
  383. const ttsUrl = ref();
  384. if (tts.value.tts_cn !== null) {
  385. audioStore.ttsUrl = tts.value.tts_cn.url;
  386. ttsUrl.value = tts.value.tts_cn.url;
  387. audioStore.isNewInstance = true;
  388. } else if (tts.value.tts_en !== null) {
  389. audioStore.ttsUrl = tts.value.tts_en.url;
  390. ttsUrl.value = tts.value.tts_en.url;
  391. audioStore.isNewInstance = true;
  392. }
  393. if (ttsUrl.value) {
  394. nextTick(() => {
  395. if (audioStore.isVoiceEnabled) {
  396. console.log("ttsUrl.value", ttsUrl.value)
  397. // 播放音频
  398. playAudio(ttsUrl.value)
  399. }
  400. });
  401. }
  402. chatStore.messages.pop();
  403. // 先推送初始消息
  404. const aiMessage = reactive({
  405. sender: "ai",
  406. content: "",
  407. isTyping: true,
  408. });
  409. chatStore.messages.push(aiMessage);
  410. let index = 0;
  411. const typingInterval = setInterval(() => {
  412. if (index < processedContent.length) {
  413. aiMessage.content += processedContent.charAt(index);
  414. index++;
  415. } else {
  416. clearInterval(typingInterval);
  417. aiMessage.isTyping = false;
  418. // 延迟处理KaTeX确保DOM已更新
  419. nextTick(() => {
  420. aiMessage.content = aiMessage.content.replace(katexRegex, (match, formula) => {
  421. try {
  422. return katex.renderToString(formula, { throwOnError: false });
  423. } catch (error) {
  424. console.error('KaTeX 渲染错误:', error);
  425. return match;
  426. }
  427. });
  428. chatStore.setLoading(false);
  429. });
  430. }
  431. }, 50); // 调整速度为50ms/字符
  432. // } else {
  433. // chatStore.messages.pop();
  434. // chatStore.messages.push({
  435. // sender: "ai",
  436. // content: status.msg
  437. // });
  438. // chatStore.setLoading(false);
  439. // }
  440. }
  441. }
  442. catch (e) {
  443. console.error('请求失败:', e);
  444. hasValidData.value = false; // 请求失败时设置数据无效
  445. chatStore.messages.pop();
  446. chatStore.messages.push({
  447. sender: "ai",
  448. content: "AI思考失败,请稍后再试... ",
  449. });
  450. chatStore.setLoading(false);
  451. }
  452. finally {
  453. await chatStore.getUserCount();
  454. }
  455. }
  456. },
  457. { deep: true }
  458. );
  459. function KlineCanvsEcharts(containerId) {
  460. function vwToPx(vw) {
  461. console.log((window.innerWidth * vw) / 100, 'vwToPx');
  462. return (window.innerWidth * vw) / 100
  463. }
  464. console.log('KLine渲染: 开始处理数据, 容器ID:', containerId);
  465. // 从 chatStore 中获取数据
  466. const messages = chatStore.messages;
  467. console.log('KLine渲染: 获取到的消息:', messages);
  468. let klineMessageIndex = -1;
  469. let klineData = null;
  470. // 查找最近的 K线 消息
  471. // for (let i = messages.length - 1; i >= 0; i--) {
  472. // console.log('KLine渲染: 检查消息:', messages[i]);
  473. // if (messages[i].type === 'kline' && messages[i].chartData) {
  474. // klineMessageIndex = i;
  475. // klineData = messages[i].chartData;
  476. // console.log('KLine渲染: 找到K线消息索引:', klineMessageIndex);
  477. // console.log('KLine渲染: 找到K线数据:', klineData);
  478. // break;
  479. // }
  480. // }
  481. klineMessageIndex = containerId.split('-')[2]
  482. console.log('KLine渲染: 找到K线消息索引:', klineMessageIndex);
  483. if (messages[klineMessageIndex].type === 'kline' && messages[klineMessageIndex].chartData) {
  484. klineData = messages[klineMessageIndex].chartData
  485. }
  486. if (!klineData || !klineData.Kline) {
  487. console.warn('KLine渲染: 数据无效 - 在chatStore中找不到有效的K线数据');
  488. return;
  489. }
  490. // 获取容器元素
  491. const container = document.getElementById(containerId);
  492. if (!container) {
  493. console.error('KLine渲染: 找不到容器元素:', containerId);
  494. return;
  495. }
  496. // 创建图表实例
  497. console.log('KLine渲染: 创建图表实例');
  498. try {
  499. // 如果已有实例,先销毁
  500. if (chartInstancesMap[containerId]) {
  501. console.log('KLine渲染: 销毁已有图表实例');
  502. chartInstancesMap[containerId].dispose();
  503. delete chartInstancesMap[containerId];
  504. }
  505. // 使用普通变量存储实例
  506. chartInstancesMap[containerId] = echarts.init(container);
  507. console.log('KLine渲染: 图表实例创建成功');
  508. } catch (error) {
  509. console.error('KLine渲染: 图表实例创建失败:', error);
  510. return;
  511. }
  512. const data = klineData.Kline.AIGoldBull;
  513. console.log('KLine渲染: Kline数据', data);
  514. // 切割数据方法
  515. const splitData = (a) => {
  516. console.log('KLine渲染: 开始数据切割');
  517. const categoryData = [];
  518. let values = [];
  519. for (let i = 0; i < a.length; i++) {
  520. categoryData.push(a[i][0]);
  521. values.push([a[i][1], a[i][2], a[i][3], a[i][4]]);
  522. }
  523. console.log('KLine渲染: 日期数据点数量', categoryData.length);
  524. console.log('KLine渲染: 值数据点数量', values.length);
  525. return { categoryData, values };
  526. };
  527. var KlineOption = {};
  528. // 检测设备类型
  529. const isMobile = window.innerWidth < 768;
  530. const isTablet = window.innerWidth >= 768 && window.innerWidth < 1024;
  531. console.log('KLine渲染: 设备类型', isMobile ? '移动设备' : isTablet ? '平板设备' : '桌面设备');
  532. // 给配置项
  533. console.log('KLine渲染: 开始配置图表选项');
  534. if (klineData.type === 1) {
  535. console.log('进入第一分类')
  536. const arr1 = []
  537. const arr2 = []
  538. const arr3 = []
  539. const arr4 = []
  540. // 动态K线
  541. const changeColorKline = (QSXH, KLine20) => {
  542. if (QSXH) {
  543. QSXH.map((item) => {
  544. KLine20.map((kline_item) => {
  545. if (item[1] == 1 && item[0] == kline_item[0]) {
  546. arr1.push(kline_item)
  547. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  548. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  549. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  550. }
  551. if (item[1] == 2 && item[0] == kline_item[0]) {
  552. arr2.push(kline_item)
  553. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  554. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  555. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  556. }
  557. if (item[1] == 3 && item[0] == kline_item[0]) {
  558. arr3.push(kline_item)
  559. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  560. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  561. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  562. }
  563. if (item[1] == 4 && item[0] == kline_item[0]) {
  564. arr4.push(kline_item)
  565. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  566. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  567. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  568. }
  569. })
  570. })
  571. }
  572. }
  573. changeColorKline(data.QSXH, data.KLine20)
  574. var dealData = splitData(data.KLine20)
  575. var dealData1 = splitData(arr1)
  576. var dealData2 = splitData(arr2)
  577. var dealData3 = splitData(arr3)
  578. var dealData4 = splitData(arr4)
  579. console.log('dealData', dealData);
  580. console.log('dealData1', dealData1);
  581. console.log('dealData2', dealData2);
  582. console.log('dealData3', dealData3);
  583. console.log('dealData4', dealData4);
  584. var dealGnBullData = data.JN //金牛版成交量数据
  585. // 处理MA数据,创建两段重叠的数据
  586. function processMAData(data) {
  587. let processedData = []
  588. // 初始化处理后的数据结构
  589. data.forEach((item, idx) => {
  590. processedData.push({
  591. date: item[0],
  592. value: item[1],
  593. type: item[2]
  594. })
  595. })
  596. // 当某一种type只存在一天,设置另一种type透明
  597. let singleTypeRed = [{ min: 0, max: 0, color: '#000' }]
  598. let singleTypeYellow = [{ min: 0, max: 0, color: '#000' }]
  599. let singleTypeGreen = [{ min: 0, max: 0, color: '#000' }]
  600. // 在类型切换点添加过渡点
  601. for (let i = 1; i < processedData.length; i++) {
  602. if (processedData[i].type !== processedData[i - 1].type) {
  603. if (
  604. i == processedData.length - 1 ||
  605. (processedData[i].type !== processedData[i + 1].type &&
  606. processedData[i - 1].type === processedData[i + 1].type)
  607. ) {
  608. if (processedData[i - 1].type === 0) {
  609. singleTypeGreen.push({ min: i - 1, max: i, color: 'rgba(0,0,0,0)' })
  610. } else if (processedData[i - 1].type === 1) {
  611. singleTypeRed.push({ min: i - 1, max: i, color: 'rgba(0,0,0,0)' })
  612. } else if (processedData[i - 1].type === 2) {
  613. singleTypeYellow.push({ min: i - 1, max: i, color: 'rgba(0,0,0,0)' })
  614. }
  615. }
  616. }
  617. if (processedData[i].type !== processedData[i - 1].type) {
  618. if (processedData[i].type == 0) {
  619. processedData[i - 1].isTransitionGreen = 1
  620. } else if (processedData[i].type == 1) {
  621. processedData[i - 1].isTransitionRed = 1
  622. } else if (processedData[i].type == 2) {
  623. processedData[i - 1].isTransitionYellow = 1
  624. }
  625. // // 创建过渡点,使用前一个点的值
  626. // processedData[i - 1].isTransition = true
  627. }
  628. }
  629. // 分离红绿数据,包含过渡点
  630. let greenData = []
  631. let redData = []
  632. let yellowData = []
  633. processedData.forEach((item, idx) => {
  634. const point = [item.date, item.value]
  635. if (item.type === 0) {
  636. greenData.push(point)
  637. redData.push([item.date, '-'])
  638. yellowData.push([item.date, '-'])
  639. // if (item.isTransition) {
  640. // // 添加过渡点到红色线
  641. // redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  642. // yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  643. // }
  644. if (item.isTransitionGreen) {
  645. greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  646. } else if (item.isTransitionRed) {
  647. redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  648. } else if (item.isTransitionYellow) {
  649. yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  650. }
  651. } else if (item.type === 1) {
  652. redData.push(point)
  653. greenData.push([item.date, '-'])
  654. yellowData.push([item.date, '-'])
  655. // if (item.isTransition) {
  656. // // 添加过渡点到绿色线
  657. // greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  658. // yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  659. // }
  660. if (item.isTransitionGreen) {
  661. greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  662. } else if (item.isTransitionRed) {
  663. redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  664. } else if (item.isTransitionYellow) {
  665. yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  666. }
  667. } else if (item.type === 2) {
  668. redData.push([item.date, '-'])
  669. greenData.push([item.date, '-'])
  670. yellowData.push(point)
  671. // if (item.isTransition) {
  672. // // 添加过渡点到绿色线
  673. // greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  674. // redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  675. // }
  676. if (item.isTransitionGreen) {
  677. greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  678. } else if (item.isTransitionRed) {
  679. redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  680. } else if (item.isTransitionYellow) {
  681. yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  682. }
  683. }
  684. })
  685. return {
  686. greenData: greenData,
  687. redData: redData,
  688. yellowData: yellowData,
  689. singleTypeGreen: singleTypeGreen,
  690. singleTypeRed: singleTypeRed,
  691. singleTypeYellow: singleTypeYellow
  692. }
  693. }
  694. const maData = processMAData(data.FCX)
  695. console.log('maData', maData)
  696. // 牵牛绳的数据
  697. // 如果第一个字段的第一个数据为-1的话,不展示牵牛绳
  698. if (data.FCX[0][1] == '-1') {
  699. maData.greenData = []
  700. maData.redData = []
  701. maData.yellowData = []
  702. }
  703. // 生成文字标注
  704. const processBarData = (data) => {
  705. const barData = []
  706. const markPointData = []
  707. data.forEach((item) => {
  708. let color
  709. // 根据 item[4] 设置不同的颜色
  710. switch (item[4]) {
  711. case 1:
  712. color = '#13E113' // 绿色
  713. break
  714. case 2:
  715. color = '#FF0E00' // 红色
  716. break
  717. case 3:
  718. color = '#0000FE' // 深蓝色(倍量阳)
  719. break
  720. case 4:
  721. color = '#1397FF' // 浅蓝色(倍量阴)
  722. break
  723. }
  724. barData.push({
  725. value: item[5],
  726. itemStyle: {
  727. normal: {
  728. color: color // 动态设置颜色
  729. }
  730. }
  731. })
  732. // 小牛
  733. if (item[1] === 1) {
  734. markPointData.push({
  735. coord: [item[0], item[5]],
  736. symbol:
  737. 'image://https://d31zlh4on95l9h.cloudfront.net/images/5iujb101000d5si3v3hr7w2vg0h43z1u.png',
  738. symbolSize: [30, 30], // 图片大小
  739. label: {
  740. normal: {
  741. color: 'rgba(0, 0, 0, 0)' //字体颜色
  742. }
  743. }
  744. })
  745. }
  746. // 大牛
  747. // 中部标记(红色牛)
  748. if (item[2] === 1) {
  749. markPointData.push({
  750. coord: [item[0], item[5] / 2],
  751. symbol:
  752. 'image://https://d31zlh4on95l9h.cloudfront.net/images/5iujaz01000d5si016bxdf6vh0377d2h.png',
  753. symbolSize: [30, 30], // 图片大小
  754. label: {
  755. normal: {
  756. color: 'rgba(0, 0, 0, 0)' //字体颜色
  757. }
  758. }
  759. })
  760. }
  761. // 金牛
  762. // 底部标记(金牛)
  763. if (item[3] === 1) {
  764. markPointData.push({
  765. coord: [item[0], 0],
  766. symbol:
  767. 'image://https://d31zlh4on95l9h.cloudfront.net/images/5iujb001000d5shzls0tmd4vs0e5tdrw.png',
  768. symbolSize: [30, 30], // 图片大小
  769. label: {
  770. normal: {
  771. color: 'rgba(0, 0, 0, 0)' //字体颜色
  772. }
  773. }
  774. })
  775. }
  776. })
  777. return { barData, markPointData }
  778. }
  779. const { barData, markPointData } = processBarData(dealGnBullData)
  780. // 配置项
  781. KlineOption = {
  782. // 底部选项
  783. // animation: false,
  784. // 手放上去显示的内容
  785. legend: [
  786. {
  787. //图例文字的样式
  788. textStyle: {
  789. color: 'black', //图例文字颜色
  790. fontSize: window.innerWidth > 768 ? 15 : vwToPx(2.8) // 响应式字体大小
  791. },
  792. width: '100%', // 确保有足够的宽度容纳图例
  793. left: 'center',
  794. itemGap: window.innerWidth > 768 ? 20 : 10, // 控制图例项之间的间距
  795. itemWidth: 10, // 调整颜色块的宽度
  796. itemHeight: 10, // 调整颜色块的高度
  797. data: [
  798. {
  799. name: '进攻K线',
  800. itemStyle: {
  801. color: 'rgb(255,0,0)'
  802. }
  803. },
  804. {
  805. name: '防守K线',
  806. itemStyle: {
  807. color: 'red'
  808. }
  809. },
  810. {
  811. name: '推进K线',
  812. itemStyle: {
  813. color: 'orange'
  814. }
  815. },
  816. {
  817. name: '撤退K线',
  818. itemStyle: {
  819. color: 'rgb(84,252,252)'
  820. }
  821. }
  822. ]
  823. },
  824. {
  825. //图例文字的样式
  826. textStyle: {
  827. color: 'black', //图例文字颜色
  828. fontSize: window.innerWidth > 768 ? 15 : vwToPx(2.8) // 响应式字体大小
  829. },
  830. orient: 'horizontal', // 设置图例水平布局
  831. top: '5%',
  832. width: '100%', // 确保有足够的宽度容纳图例
  833. left: 'center',
  834. itemGap: 15, // 控制图例项之间的间距
  835. data: [
  836. // 牵牛绳
  837. {
  838. name: '{green|━}{red|━} ' + '牵牛绳', // 将牵牛绳样式应用到文本前缀
  839. icon: 'none', // 去掉默认图例图标
  840. textStyle: {
  841. rich: {
  842. green: {
  843. color: 'green',
  844. fontSize: window.innerWidth > 768 ? 20 : 10
  845. },
  846. red: {
  847. color: 'red',
  848. fontSize: window.innerWidth > 768 ? 20 : 10
  849. }
  850. }
  851. }
  852. },
  853. {
  854. name: '龙线'
  855. },
  856. {
  857. name: '虫线'
  858. }
  859. ]
  860. }
  861. ],
  862. tooltip: {
  863. // 调用接口之后方法
  864. formatter: function (a, b, d) {
  865. if (a[0].seriesIndex == 0) {
  866. const KlineTag = ref([]) // 判断几根K线
  867. const AIBullTag = ref([])
  868. // 找到第一个满足条件的数据
  869. KlineTag.value = a.find((item) => item.data[1])?.data || []
  870. // 找到第一个满足条件的非 '-' 数据
  871. AIBullTag.value = a.slice(4).find((item) => item.data[1] !== '-')?.data || []
  872. return (
  873. a[0].name +
  874. '<br/>' +
  875. '开盘价' +
  876. ':' +
  877. KlineTag.value[1] +
  878. '<br/>' +
  879. '收盘价' +
  880. ':' +
  881. KlineTag.value[2] +
  882. '<br/>' +
  883. '最低价' +
  884. ':' +
  885. KlineTag.value[3] +
  886. '<br/>' +
  887. '最高价' +
  888. ':' +
  889. KlineTag.value[4] +
  890. '<br/>' +
  891. '牵牛绳' +
  892. ':' +
  893. AIBullTag.value[1]
  894. )
  895. } else {
  896. // 格式化成交量显示
  897. let formattedVolume
  898. if (a[0].data.value >= 10000) {
  899. formattedVolume = (a[0].data.value / 10000).toFixed(2) + 'w'
  900. } else {
  901. formattedVolume = a[0].data.value
  902. }
  903. return a[0].name + '<br/>' + '成交量' + ':' + formattedVolume
  904. }
  905. },
  906. trigger: 'axis',
  907. axisPointer: {
  908. //坐标轴指示器配置项
  909. type: 'cross' //‘line’直线指示器,‘cross’十字准星指示器,‘shadow’阴影指示器
  910. },
  911. backgroundColor: 'rgba(119, 120, 125, 0.6)', // 提示框浮层的边框颜色。
  912. borderWidth: 1, // 提示框浮层的边框宽。
  913. borderColor: '#77787D', // 提示框浮层的边框颜色。
  914. padding: 10, // 提示框浮层内边距,
  915. textStyle: {
  916. //提示框浮层上的文字样式
  917. color: '#fff'
  918. }
  919. },
  920. // 手放上去时拉的框
  921. axisPointer: {
  922. link: [
  923. {
  924. xAxisIndex: 'all' // 同时触发所有图形的 x 坐标轴指示器
  925. }
  926. ],
  927. label: {
  928. backgroundColor: '#77787D' // 文本标签的背景颜色
  929. }
  930. },
  931. toolbox: {
  932. show: false
  933. },
  934. grid: [
  935. {
  936. left: window.innerWidth > 768 ? '18%' : '15%',
  937. // right: window.innerWidth > 768 ? '4%' : '2.5%',
  938. height: window.innerWidth > 768 ? '60%' : '57%',
  939. top: window.innerWidth > 768 ? '8%' : '12%',
  940. // height: '33%',
  941. containLabel: false
  942. },
  943. {
  944. left: window.innerWidth > 768 ? '18%' : '15%',
  945. // right: window.innerWidth > 768 ? '4%' : '2.5%',
  946. top: window.innerWidth > 768 ? '72%' : '73%',
  947. height: '20%',
  948. containLabel: false
  949. }
  950. ],
  951. xAxis: [
  952. {
  953. type: 'category',
  954. data: dealData.categoryData,
  955. boundaryGap: true, // 坐标轴两边是否留空,false表示不留空(通常用于K线图)
  956. axisLine: { onZero: false }, // 设置坐标轴是否通过零点,onZero:false表示不强制穿过零点
  957. splitLine: { show: false }, // 是否显示分隔线,false表示不显示
  958. min: 'dataMin', // 坐标轴最小值,'dataMin'表示从数据的最小值开始
  959. max: 'dataMax', // 坐标轴最大值,'dataMax'表示从数据的最大值开始
  960. axisPointer: {
  961. z: 100 // 坐标轴指示器的层级,较大的值会让它显示在其他元素上方
  962. },
  963. axisLine: {
  964. lineStyle: {
  965. color: 'black' // 坐标轴线的颜色
  966. }
  967. }, //
  968. axisLabel: { show: false }, // 隐藏刻度标签
  969. axisTick: { show: false } // 隐藏刻度线
  970. },
  971. // 下方成交量图的X轴
  972. {
  973. type: 'category',
  974. gridIndex: 1,
  975. data: dealData.categoryData,
  976. boundaryGap: true,
  977. axisLine: { lineStyle: { color: 'black' } },
  978. axisLabel: {
  979. show: true,
  980. // fontSize: window.innerWidth > 768 ? 10 : 8,
  981. interval: 'auto'
  982. },
  983. axisTick: { show: false } // 隐藏刻度线
  984. }
  985. ],
  986. // 控制纵坐标展示数据
  987. yAxis: [
  988. {
  989. scale: true,
  990. gridIndex: 0,
  991. position: 'left',
  992. axisLabel: {
  993. inside: false,
  994. align: 'right',
  995. fontSize: window.innerWidth > 768 ? 15 : 10
  996. },
  997. axisLine: {
  998. show: true,
  999. lineStyle: {
  1000. fontSize: '',
  1001. color: 'black'
  1002. }
  1003. },
  1004. axisTick: { show: false },
  1005. splitLine: { show: false }
  1006. },
  1007. // 下方成交量图的Y轴
  1008. {
  1009. scale: true,
  1010. gridIndex: 1,
  1011. splitNumber: 4, // 增加分割数以获得更好的间距
  1012. minInterval: 1, // 确保标签之间的最小间隔
  1013. axisLabel: {
  1014. show: true,
  1015. fontSize: window.innerWidth > 768 ? 15 : 10,
  1016. margin: 8, // 添加边距以获得更好的间距
  1017. formatter: (value) => {
  1018. if (value >= 1000000000) {
  1019. return (value / 1000000000).toFixed(1) + 'B'
  1020. } else if (value >= 1000000) {
  1021. return (value / 1000000).toFixed(1) + 'M'
  1022. } else if (value >= 10000) {
  1023. return (value / 10000).toFixed(1) + 'W'
  1024. }
  1025. return value.toFixed(0)
  1026. }
  1027. },
  1028. axisLine: { show: true, lineStyle: { color: 'black' } },
  1029. axisTick: { show: false },
  1030. splitLine: { show: true, lineStyle: { type: 'dashed' } }, // 添加分割线以提高可读性
  1031. boundaryGap: ['20%', '20%'] // 为坐标轴边界添加内边距
  1032. }
  1033. ],
  1034. // 下拉条
  1035. dataZoom: [
  1036. {
  1037. type: 'inside',
  1038. xAxisIndex: [0, 1],
  1039. start: 55,
  1040. end: 100
  1041. },
  1042. {
  1043. show: true,
  1044. xAxisIndex: [0, 1],
  1045. type: 'slider',
  1046. top: window.innerWidth > 768 ? '95%' : '91%',
  1047. left: window.innerWidth > 768 ? '18%' : '15%',
  1048. // left: window.innerWidth > 768 ? '10%' : '8%',
  1049. start: 98,
  1050. end: 100
  1051. }
  1052. ],
  1053. visualMap: [
  1054. {
  1055. type: 'piecewise',
  1056. show: false,
  1057. pieces: maData.singleTypeGreen,
  1058. outOfRange: {
  1059. color: 'green'
  1060. },
  1061. dimension: 0,
  1062. seriesIndex: 6
  1063. },
  1064. {
  1065. type: 'piecewise',
  1066. show: false,
  1067. pieces: maData.singleTypeRed,
  1068. outOfRange: {
  1069. color: 'red'
  1070. },
  1071. dimension: 0,
  1072. seriesIndex: 7
  1073. },
  1074. {
  1075. type: 'piecewise',
  1076. show: false,
  1077. pieces: maData.singleTypeYellow,
  1078. outOfRange: {
  1079. color: 'yellow'
  1080. },
  1081. dimension: 0,
  1082. seriesIndex: 8
  1083. }
  1084. ],
  1085. series: [
  1086. // 第一条K线
  1087. {
  1088. name: '进攻K线',
  1089. type: 'candlestick',
  1090. barWidth: '50%', // 设置和上方图表一致的柱子宽度
  1091. data: dealData1.values,
  1092. xAxisIndex: 0, // 使用第一个 X 轴
  1093. yAxisIndex: 0, // 使用第一个 Y 轴
  1094. itemStyle: {
  1095. normal: {
  1096. color: 'rgb(255,0,0)', // 默认颜色
  1097. color0: 'rgb(255,0,0)',
  1098. borderColor: 'rgb(255,0,0)',
  1099. borderColor0: 'rgb(255,0,0)'
  1100. }
  1101. },
  1102. gridIndex: 0
  1103. },
  1104. //
  1105. {
  1106. name: '推进K线',
  1107. type: 'candlestick',
  1108. barWidth: '50%', // 设置和上方图表一致的柱子宽度
  1109. data: dealData2.values,
  1110. xAxisIndex: 0, // 使用第一个 X 轴
  1111. yAxisIndex: 0, // 使用第一个 Y 轴
  1112. itemStyle: {
  1113. normal: {
  1114. color: 'rgb(0,0,252)', // 默认颜色
  1115. color0: 'rgb(0,0,252)',
  1116. borderColor: 'rgb(0,0,252)',
  1117. borderColor0: 'rgb(0,0,252)'
  1118. }
  1119. },
  1120. gridIndex: 0
  1121. },
  1122. {
  1123. name: '防守K线',
  1124. type: 'candlestick',
  1125. barWidth: '50%', // 设置和上方图表一致的柱子宽度
  1126. data: dealData3.values,
  1127. xAxisIndex: 0, // 使用第一个 X 轴
  1128. yAxisIndex: 0, // 使用第一个 Y 轴
  1129. itemStyle: {
  1130. normal: {
  1131. color: 'orange', // 默认颜色
  1132. color0: 'orange',
  1133. borderColor: 'orange',
  1134. borderColor0: 'orange'
  1135. }
  1136. },
  1137. gridIndex: 0
  1138. },
  1139. {
  1140. name: '撤退K线',
  1141. type: 'candlestick',
  1142. barWidth: '50%', // 设置和上方图表一致的柱子宽度
  1143. data: dealData4.values,
  1144. xAxisIndex: 0, // 使用第一个 X 轴
  1145. yAxisIndex: 0, // 使用第一个 Y 轴
  1146. itemStyle: {
  1147. normal: {
  1148. color: 'rgb(84,252,252)', // 默认颜色
  1149. color0: 'rgb(84,252,252)',
  1150. borderColor: 'rgb(84,252,252)',
  1151. borderColor0: 'rgb(84,252,252)'
  1152. }
  1153. },
  1154. gridIndex: 0
  1155. },
  1156. //成交量柱状图
  1157. {
  1158. name: '成交量',
  1159. type: 'bar',
  1160. barWidth: '70%', // 设置和上方图表一致的柱子宽度
  1161. xAxisIndex: 1,
  1162. yAxisIndex: 1,
  1163. data: barData,
  1164. markPoint: {
  1165. data: markPointData,
  1166. label: {
  1167. show: false // 确保隐藏标记的值
  1168. }
  1169. }
  1170. },
  1171. {
  1172. name: '{green|━}{red|━} ' + '牵牛绳', // 将牵牛绳样式应用到文本前缀
  1173. type: 'line',
  1174. data: [], // 设置为空数组,不显示数据点
  1175. smooth: true,
  1176. symbol: 'none',
  1177. xAxisIndex: 0, // 线图与第一个 K 线图共享 X 轴
  1178. yAxisIndex: 0, // 线图与第一个 K 线图共享 Y 轴
  1179. showSymbol: false, // 隐藏符号
  1180. lineStyle: {
  1181. opacity: 0 // 使线条透明
  1182. },
  1183. itemStyle: {
  1184. normal: {
  1185. color: 'green'
  1186. }
  1187. },
  1188. gridIndex: 0 // 确保线图与第一个K线图共享网格
  1189. },
  1190. {
  1191. name: '虫线',
  1192. type: 'line',
  1193. data: maData.greenData,
  1194. smooth: true,
  1195. symbol: 'none',
  1196. xAxisIndex: 0, // 线图与第一个 K 线图共享 X 轴
  1197. yAxisIndex: 0, // 线图与第一个 K 线图共享 Y 轴
  1198. itemStyle: {
  1199. normal: {
  1200. color: 'green',
  1201. lineStyle: {
  1202. // color: 'orange', // 线的颜色
  1203. width: 2, // 线宽
  1204. type: 'solid' // 线类型
  1205. }
  1206. }
  1207. },
  1208. gridIndex: 0 // 确保线图与第一个K线图共享网格
  1209. },
  1210. {
  1211. name: '龙线',
  1212. type: 'line',
  1213. data: maData.redData,
  1214. smooth: true,
  1215. symbol: 'none',
  1216. xAxisIndex: 0, // 线图与第一个 K 线图共享 X 轴
  1217. yAxisIndex: 0, // 线图与第一个 K 线图共享 Y 轴
  1218. itemStyle: {
  1219. normal: {
  1220. color: 'red',
  1221. lineStyle: {
  1222. // color: 'orange', // 线的颜色
  1223. width: 2, // 线宽
  1224. type: 'solid' // 线类型
  1225. }
  1226. }
  1227. },
  1228. gridIndex: 0 // 确保线图与第一个K线图共享网格
  1229. },
  1230. {
  1231. name: '黄色',
  1232. type: 'line',
  1233. data: maData.yellowData,
  1234. smooth: true,
  1235. symbol: 'none',
  1236. xAxisIndex: 0,
  1237. yAxisIndex: 0,
  1238. itemStyle: {
  1239. normal: {
  1240. color: 'yellow',
  1241. lineStyle: {
  1242. width: 2,
  1243. type: 'solid'
  1244. }
  1245. }
  1246. },
  1247. gridIndex: 0
  1248. }
  1249. ]
  1250. // graphic: {
  1251. // markPointData : generateGraphicmarkPointData(data11111)
  1252. // }
  1253. }
  1254. } else if (klineData.type === 2) {
  1255. console.log('进入第二分类')
  1256. const arr1 = []
  1257. const arr2 = []
  1258. const arr3 = []
  1259. const arr4 = []
  1260. const changeColorKline = (QSXH, KLine20) => {
  1261. if (QSXH) {
  1262. QSXH.map((item) => {
  1263. KLine20.map((kline_item) => {
  1264. if (item[1] == 1 && item[0] == kline_item[0]) {
  1265. arr1.push(kline_item)
  1266. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  1267. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  1268. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  1269. }
  1270. if (item[1] == 2 && item[0] == kline_item[0]) {
  1271. arr2.push(kline_item)
  1272. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  1273. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  1274. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  1275. }
  1276. if (item[1] == 3 && item[0] == kline_item[0]) {
  1277. arr3.push(kline_item)
  1278. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  1279. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  1280. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  1281. }
  1282. if (item[1] == 4 && item[0] == kline_item[0]) {
  1283. arr4.push(kline_item)
  1284. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  1285. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  1286. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  1287. }
  1288. })
  1289. })
  1290. }
  1291. }
  1292. console.log(arr1, arr2, arr3, arr4)
  1293. changeColorKline(data.QSXH, data.KLine20)
  1294. var dealData = splitData(data.KLine20)
  1295. var dealData1 = splitData(arr1)
  1296. var dealData2 = splitData(arr2)
  1297. var dealData3 = splitData(arr3)
  1298. var dealData4 = splitData(arr4)
  1299. var dealGnBullData = data.JN
  1300. function processMAData(data) {
  1301. let processedData = []
  1302. data.forEach((item, idx) => {
  1303. processedData.push({
  1304. date: item[0],
  1305. value: item[1],
  1306. type: item[2]
  1307. })
  1308. })
  1309. // 当某一种type只存在一天,设置另一种type透明
  1310. let singleTypeRed = [{ min: 0, max: 0, color: '#000' }]
  1311. let singleTypeYellow = [{ min: 0, max: 0, color: '#000' }]
  1312. let singleTypeGreen = [{ min: 0, max: 0, color: '#000' }]
  1313. for (let i = 1; i < processedData.length; i++) {
  1314. if (processedData[i].type !== processedData[i - 1].type) {
  1315. if (
  1316. i == processedData.length - 1 ||
  1317. (processedData[i].type !== processedData[i + 1].type &&
  1318. processedData[i - 1].type === processedData[i + 1].type)
  1319. ) {
  1320. if (processedData[i - 1].type === 0) {
  1321. singleTypeGreen.push({ min: i - 1, max: i, color: 'rgba(0,0,0,0)' })
  1322. } else if (processedData[i - 1].type === 1) {
  1323. singleTypeRed.push({ min: i - 1, max: i, color: 'rgba(0,0,0,0)' })
  1324. } else if (processedData[i - 1].type === 2) {
  1325. singleTypeYellow.push({ min: i - 1, max: i, color: 'rgba(0,0,0,0)' })
  1326. }
  1327. }
  1328. }
  1329. if (processedData[i].type !== processedData[i - 1].type) {
  1330. if (processedData[i].type == 0) {
  1331. processedData[i - 1].isTransitionGreen = 1
  1332. } else if (processedData[i].type == 1) {
  1333. processedData[i - 1].isTransitionRed = 1
  1334. } else if (processedData[i].type == 2) {
  1335. processedData[i - 1].isTransitionYellow = 1
  1336. }
  1337. // // 创建过渡点,使用前一个点的值
  1338. // processedData[i - 1].isTransition = true
  1339. }
  1340. }
  1341. let greenData = []
  1342. let redData = []
  1343. let yellowData = []
  1344. processedData.forEach((item, idx) => {
  1345. const point = [item.date, item.value]
  1346. if (item.type === 0) {
  1347. greenData.push(point)
  1348. redData.push([item.date, '-'])
  1349. yellowData.push([item.date, '-'])
  1350. // if (item.isTransition) {
  1351. // redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1352. // yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1353. // }
  1354. if (item.isTransitionGreen) {
  1355. greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1356. } else if (item.isTransitionRed) {
  1357. redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1358. } else if (item.isTransitionYellow) {
  1359. yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1360. }
  1361. } else if (item.type === 1) {
  1362. redData.push(point)
  1363. greenData.push([item.date, '-'])
  1364. yellowData.push([item.date, '-'])
  1365. // if (item.isTransition) {
  1366. // greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1367. // yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1368. // }
  1369. if (item.isTransitionGreen) {
  1370. greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1371. } else if (item.isTransitionRed) {
  1372. redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1373. } else if (item.isTransitionYellow) {
  1374. yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1375. }
  1376. } else if (item.type === 2) {
  1377. redData.push([item.date, '-'])
  1378. greenData.push([item.date, '-'])
  1379. yellowData.push(point)
  1380. // if (item.isTransition) {
  1381. // greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1382. // redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1383. // }
  1384. if (item.isTransitionGreen) {
  1385. greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1386. } else if (item.isTransitionRed) {
  1387. redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1388. } else if (item.isTransitionYellow) {
  1389. yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  1390. }
  1391. }
  1392. })
  1393. return {
  1394. greenData: greenData,
  1395. redData: redData,
  1396. yellowData: yellowData,
  1397. singleTypeGreen: singleTypeGreen,
  1398. singleTypeRed: singleTypeRed,
  1399. singleTypeYellow: singleTypeYellow
  1400. }
  1401. }
  1402. const maData = processMAData(data.FCX)
  1403. const maDuchiData = processMAData(data.DNC)
  1404. if (data.FCX[0][1] == '-1') {
  1405. maData.greenData = []
  1406. maData.redData = []
  1407. maData.yellowData = []
  1408. }
  1409. const processBarData = (data) => {
  1410. const barData = []
  1411. const markPointData = []
  1412. data.forEach((item) => {
  1413. let color
  1414. switch (item[4]) {
  1415. case 1:
  1416. color = '#13E113'
  1417. break
  1418. case 2:
  1419. color = '#FF0E00'
  1420. break
  1421. case 3:
  1422. color = '#0000FE'
  1423. break
  1424. case 4:
  1425. color = '#1397FF'
  1426. break
  1427. }
  1428. barData.push({
  1429. value: item[5],
  1430. itemStyle: {
  1431. normal: {
  1432. color: color
  1433. }
  1434. }
  1435. })
  1436. if (item[1] === 1) {
  1437. markPointData.push({
  1438. coord: [item[0], item[5]],
  1439. symbol:
  1440. 'image://https://d31zlh4on95l9h.cloudfront.net/images/5iujb101000d5si3v3hr7w2vg0h43z1u.png',
  1441. symbolSize: [30, 30],
  1442. label: {
  1443. normal: {
  1444. color: 'rgba(0, 0, 0, 0)'
  1445. }
  1446. }
  1447. })
  1448. }
  1449. if (item[2] === 1) {
  1450. markPointData.push({
  1451. coord: [item[0], item[5] / 2],
  1452. symbol:
  1453. 'image://https://d31zlh4on95l9h.cloudfront.net/images/5iujaz01000d5si016bxdf6vh0377d2h.png',
  1454. symbolSize: [30, 30],
  1455. label: {
  1456. normal: {
  1457. color: 'rgba(0, 0, 0, 0)'
  1458. }
  1459. }
  1460. })
  1461. }
  1462. if (item[3] === 1) {
  1463. markPointData.push({
  1464. coord: [item[0], 0],
  1465. symbol:
  1466. 'image://https://d31zlh4on95l9h.cloudfront.net/images/5iujb001000d5shzls0tmd4vs0e5tdrw.png',
  1467. symbolSize: [30, 30],
  1468. label: {
  1469. normal: {
  1470. color: 'rgba(0, 0, 0, 0)'
  1471. }
  1472. }
  1473. })
  1474. }
  1475. })
  1476. return { barData, markPointData }
  1477. }
  1478. const { barData, markPointData } = processBarData(dealGnBullData)
  1479. KlineOption = {
  1480. legend: [
  1481. {
  1482. textStyle: {
  1483. color: 'black',
  1484. fontSize: window.innerWidth > 768 ? 15 : vwToPx(1.8)
  1485. },
  1486. width: '100%',
  1487. top: window.innerWidth > 768 ? '0%' : '-1%',
  1488. left: 'center',
  1489. itemGap: window.innerWidth > 768 ? 20 : 10,
  1490. itemWidth: 10,
  1491. itemHeight: 10,
  1492. data: [
  1493. {
  1494. name: '进攻K线',
  1495. itemStyle: {
  1496. color: 'rgb(255,0,0)'
  1497. }
  1498. },
  1499. {
  1500. name: '防守K线',
  1501. itemStyle: {
  1502. color: 'red'
  1503. }
  1504. },
  1505. {
  1506. name: '推进K线',
  1507. itemStyle: {
  1508. color: 'orange'
  1509. }
  1510. },
  1511. {
  1512. name: '撤退K线',
  1513. itemStyle: {
  1514. color: 'rgb(84,252,252)'
  1515. }
  1516. }
  1517. ]
  1518. },
  1519. {
  1520. textStyle: {
  1521. color: 'black',
  1522. fontSize: window.innerWidth > 768 ? 15 : vwToPx(1.8)
  1523. },
  1524. orient: 'horizontal',
  1525. top: window.innerWidth > 768 ? '3%' : '2%',
  1526. width: '100%',
  1527. left: 'center',
  1528. itemGap: 15,
  1529. data: [
  1530. {
  1531. name: '{green|━}{red|━} ' + '牵牛绳',
  1532. icon: 'none',
  1533. textStyle: {
  1534. rich: {
  1535. green: {
  1536. color: 'green',
  1537. fontSize: window.innerWidth > 768 ? 20 : 10
  1538. },
  1539. red: {
  1540. color: 'red',
  1541. fontSize: window.innerWidth > 768 ? 20 : 10
  1542. }
  1543. }
  1544. }
  1545. },
  1546. {
  1547. name: '龙线'
  1548. },
  1549. {
  1550. name: '虫线'
  1551. }
  1552. ]
  1553. },
  1554. {
  1555. textStyle: {
  1556. color: 'black',
  1557. fontSize: window.innerWidth > 768 ? 15 : vwToPx(1.8)
  1558. },
  1559. orient: 'horizontal',
  1560. top: window.innerWidth > 768 ? '72%' : '64%',
  1561. width: '100%',
  1562. left: 'center',
  1563. itemGap: 15,
  1564. data: [
  1565. {
  1566. name: '{green|━}{red|━} ' + '度牛尺',
  1567. icon: 'none',
  1568. textStyle: {
  1569. rich: {
  1570. green: {
  1571. color: 'green',
  1572. fontSize: window.innerWidth > 768 ? 20 : 10
  1573. },
  1574. red: {
  1575. color: 'red',
  1576. fontSize: window.innerWidth > 768 ? 20 : 10
  1577. }
  1578. }
  1579. }
  1580. }
  1581. ]
  1582. }
  1583. ],
  1584. tooltip: {
  1585. formatter: function (a, b, d) {
  1586. if (a[0].seriesIndex == 0) {
  1587. const KlineTag = ref([])
  1588. const AIBullTag = ref([])
  1589. KlineTag.value = a.find((item) => item.data[1])?.data || []
  1590. AIBullTag.value = a.slice(4).find((item) => item.data[1] !== '-')?.data || []
  1591. // console.log(AIBullTag.value)
  1592. return (
  1593. a[0].name +
  1594. '<br/>' +
  1595. '开盘价' +
  1596. ':' +
  1597. KlineTag.value[1] +
  1598. '<br/>' +
  1599. '收盘价' +
  1600. ':' +
  1601. KlineTag.value[2] +
  1602. '<br/>' +
  1603. '最低价' +
  1604. ':' +
  1605. KlineTag.value[3] +
  1606. '<br/>' +
  1607. '最高价' +
  1608. ':' +
  1609. KlineTag.value[4] +
  1610. '<br/>' +
  1611. '牵牛绳' +
  1612. ':' +
  1613. AIBullTag.value[1]
  1614. )
  1615. }
  1616. if (a[0].seriesIndex == 4) {
  1617. let formattedVolume
  1618. if (a[0].data.value >= 10000) {
  1619. formattedVolume = (a[0].data.value / 10000).toFixed(2) + 'w'
  1620. } else {
  1621. formattedVolume = a[0].data.value
  1622. }
  1623. return a[0].name + '<br/>' + '成交量' + ':' + formattedVolume
  1624. }
  1625. if ([10, 11, 12].includes(a[0].seriesIndex)) {
  1626. const duchiData = a.find((item) => item.data && item.data[1] !== '-')
  1627. return duchiData
  1628. ? a[0].axisValue + '<br/>' + '度牛尺' + ':' + duchiData.data[1]
  1629. : null
  1630. }
  1631. },
  1632. trigger: 'axis',
  1633. axisPointer: {
  1634. type: 'cross'
  1635. },
  1636. backgroundColor: 'rgba(119, 120, 125, 0.6)',
  1637. borderWidth: 1,
  1638. borderColor: '#77787D',
  1639. padding: 10,
  1640. textStyle: {
  1641. color: '#fff'
  1642. }
  1643. },
  1644. axisPointer: {
  1645. link: [
  1646. {
  1647. xAxisIndex: 'all'
  1648. }
  1649. ],
  1650. label: {
  1651. backgroundColor: '#77787D'
  1652. }
  1653. },
  1654. toolbox: {
  1655. show: false
  1656. },
  1657. grid: [
  1658. {
  1659. // left: window.innerWidth > 768 ? '8%' : '15%',
  1660. // right: window.innerWidth > 768 ? '4%' : '2.5%',
  1661. top: window.innerWidth > 768 ? '10%' : '5%',
  1662. height: window.innerWidth > 768 ? '36%' : '34%',
  1663. containLabel: false
  1664. },
  1665. {
  1666. // left: window.innerWidth > 768 ? '8%' : '15%',
  1667. // right: window.innerWidth > 768 ? '4%' : '2.5%',
  1668. top: window.innerWidth > 768 ? '50%' : '42%',
  1669. height: window.innerWidth > 768 ? '20%' : '22%',
  1670. containLabel: false
  1671. },
  1672. {
  1673. // left: window.innerWidth > 768 ? '8%' : '15%',
  1674. // right: window.innerWidth > 768 ? '4%' : '2.5%',
  1675. top: window.innerWidth > 768 ? '78%' : '70%',
  1676. height: window.innerWidth > 768 ? '20%' : '22%',
  1677. containLabel: false
  1678. }
  1679. ],
  1680. xAxis: [
  1681. {
  1682. type: 'category',
  1683. data: dealData.categoryData,
  1684. boundaryGap: true,
  1685. axisLine: { onZero: false },
  1686. splitLine: { show: false },
  1687. min: 'dataMin',
  1688. max: 'dataMax',
  1689. axisPointer: {
  1690. z: 100
  1691. },
  1692. axisLine: {
  1693. lineStyle: {
  1694. color: 'black'
  1695. }
  1696. }, //
  1697. axisLabel: { show: false },
  1698. axisTick: { show: false }
  1699. },
  1700. {
  1701. type: 'category',
  1702. gridIndex: 1,
  1703. data: dealData.categoryData,
  1704. boundaryGap: true,
  1705. axisLine: { lineStyle: { color: 'black' } },
  1706. axisLabel: {
  1707. show: false,
  1708. interval: 'auto'
  1709. }
  1710. },
  1711. {
  1712. type: 'category',
  1713. gridIndex: 2,
  1714. data: dealData.categoryData,
  1715. boundaryGap: true,
  1716. axisLine: { lineStyle: { color: 'black' } },
  1717. axisLabel: {
  1718. show: true,
  1719. interval: 'auto'
  1720. }
  1721. }
  1722. ],
  1723. yAxis: [
  1724. {
  1725. scale: true,
  1726. gridIndex: 0,
  1727. position: 'left',
  1728. axisLabel: {
  1729. inside: false,
  1730. align: 'right',
  1731. fontSize: window.innerWidth > 768 ? 15 : 10
  1732. },
  1733. axisLine: {
  1734. show: true,
  1735. lineStyle: {
  1736. fontSize: '',
  1737. color: 'black'
  1738. }
  1739. },
  1740. axisTick: { show: false },
  1741. splitLine: { show: false }
  1742. },
  1743. {
  1744. scale: true,
  1745. gridIndex: 1,
  1746. splitNumber: 4,
  1747. min: 0,
  1748. minInterval: 1,
  1749. axisLabel: {
  1750. show: true,
  1751. fontSize: window.innerWidth > 768 ? 15 : 10,
  1752. margin: 8,
  1753. formatter: (value) => {
  1754. if (value >= 1000000000) {
  1755. return (value / 1000000000).toFixed(1) + 'B'
  1756. } else if (value >= 1000000) {
  1757. return (value / 1000000).toFixed(1) + 'M'
  1758. } else if (value >= 10000) {
  1759. return (value / 10000).toFixed(1) + 'W'
  1760. }
  1761. return value.toFixed(0)
  1762. }
  1763. },
  1764. axisLine: { show: true, lineStyle: { color: 'black' } },
  1765. axisTick: { show: false },
  1766. splitLine: { show: true, lineStyle: { type: 'dashed' } },
  1767. boundaryGap: ['20%', '20%']
  1768. },
  1769. {
  1770. type: 'value',
  1771. gridIndex: 2,
  1772. min: 0,
  1773. max: 100,
  1774. axisLabel: {
  1775. show: true,
  1776. fontSize: window.innerWidth > 768 ? 15 : 10,
  1777. formatter: function (value) {
  1778. var customValues = [0, 20, 50, 80, 100]
  1779. return customValues.indexOf(value) > -1 ? value : ''
  1780. }
  1781. },
  1782. axisLine: {
  1783. show: true,
  1784. lineStyle: {
  1785. color: 'black'
  1786. }
  1787. },
  1788. axisTick: {
  1789. show: false
  1790. },
  1791. splitNumber: 10,
  1792. splitLine: {
  1793. show: true,
  1794. lineStyle: {
  1795. type: 'dashed',
  1796. color: '#fff',
  1797. width: 1
  1798. },
  1799. interval: function (index, value) {
  1800. return [20, 50, 80, 100].indexOf(value) > -1
  1801. }
  1802. }
  1803. }
  1804. ],
  1805. dataZoom: [
  1806. {
  1807. type: 'inside',
  1808. xAxisIndex: [0, 1, 2],
  1809. start: 55,
  1810. end: 100
  1811. },
  1812. {
  1813. show: true,
  1814. xAxisIndex: [0, 1, 2],
  1815. type: 'slider',
  1816. top: window.innerWidth > 768 ? '95%' : '96%',
  1817. left: window.innerWidth > 768 ? '10%' : '8%',
  1818. start: 98,
  1819. end: 100
  1820. }
  1821. ],
  1822. visualMap: [
  1823. {
  1824. type: 'piecewise',
  1825. show: false,
  1826. pieces: maData.singleTypeGreen,
  1827. outOfRange: {
  1828. color: 'green'
  1829. },
  1830. dimension: 0,
  1831. seriesIndex: 7
  1832. },
  1833. {
  1834. type: 'piecewise',
  1835. show: false,
  1836. pieces: maData.singleTypeRed,
  1837. outOfRange: {
  1838. color: 'red'
  1839. },
  1840. dimension: 0,
  1841. seriesIndex: 8
  1842. },
  1843. {
  1844. type: 'piecewise',
  1845. show: false,
  1846. pieces: maData.singleTypeYellow,
  1847. outOfRange: {
  1848. color: 'yellow'
  1849. },
  1850. dimension: 0,
  1851. seriesIndex: 9
  1852. }
  1853. ],
  1854. series: [
  1855. {
  1856. name: '进攻K线',
  1857. type: 'candlestick',
  1858. barWidth: '50%',
  1859. data: dealData1.values,
  1860. xAxisIndex: 0,
  1861. yAxisIndex: 0,
  1862. itemStyle: {
  1863. normal: {
  1864. color: 'rgb(255,0,0)',
  1865. color0: 'rgb(255,0,0)',
  1866. borderColor: 'rgb(255,0,0)',
  1867. borderColor0: 'rgb(255,0,0)'
  1868. }
  1869. },
  1870. gridIndex: 0
  1871. },
  1872. //
  1873. {
  1874. name: '推进K线',
  1875. type: 'candlestick',
  1876. barWidth: '50%',
  1877. data: dealData2.values,
  1878. xAxisIndex: 0,
  1879. yAxisIndex: 0,
  1880. itemStyle: {
  1881. normal: {
  1882. color: 'rgb(0,0,252)',
  1883. color0: 'rgb(0,0,252)',
  1884. borderColor: 'rgb(0,0,252)',
  1885. borderColor0: 'rgb(0,0,252)'
  1886. }
  1887. },
  1888. gridIndex: 0
  1889. },
  1890. {
  1891. name: '防守K线',
  1892. type: 'candlestick',
  1893. barWidth: '50%',
  1894. data: dealData3.values,
  1895. xAxisIndex: 0,
  1896. yAxisIndex: 0,
  1897. itemStyle: {
  1898. normal: {
  1899. color: 'orange',
  1900. color0: 'orange',
  1901. borderColor: 'orange',
  1902. borderColor0: 'orange'
  1903. }
  1904. },
  1905. gridIndex: 0
  1906. },
  1907. {
  1908. name: '撤退K线',
  1909. type: 'candlestick',
  1910. barWidth: '50%',
  1911. data: dealData4.values,
  1912. xAxisIndex: 0,
  1913. yAxisIndex: 0,
  1914. itemStyle: {
  1915. normal: {
  1916. color: 'rgb(84,252,252)',
  1917. color0: 'rgb(84,252,252)',
  1918. borderColor: 'rgb(84,252,252)',
  1919. borderColor0: 'rgb(84,252,252)'
  1920. }
  1921. },
  1922. gridIndex: 0
  1923. },
  1924. {
  1925. name: '成交量',
  1926. type: 'bar',
  1927. barWidth: '70%',
  1928. xAxisIndex: 1,
  1929. yAxisIndex: 1,
  1930. data: barData,
  1931. markPoint: {
  1932. data: markPointData,
  1933. label: {
  1934. show: false
  1935. }
  1936. }
  1937. },
  1938. {
  1939. name: '{green|━}{red|━} ' + '牵牛绳',
  1940. type: 'line',
  1941. data: [],
  1942. smooth: true,
  1943. symbol: 'none',
  1944. xAxisIndex: 0,
  1945. yAxisIndex: 0,
  1946. showSymbol: false,
  1947. lineStyle: {
  1948. opacity: 0
  1949. },
  1950. itemStyle: {
  1951. normal: {
  1952. color: 'green'
  1953. }
  1954. },
  1955. gridIndex: 0
  1956. },
  1957. {
  1958. name: '{green|━}{red|━} ' + '度牛尺',
  1959. type: 'line',
  1960. data: [],
  1961. smooth: true,
  1962. symbol: 'none',
  1963. xAxisIndex: 0,
  1964. yAxisIndex: 0,
  1965. showSymbol: false,
  1966. lineStyle: {
  1967. opacity: 0
  1968. },
  1969. itemStyle: {
  1970. normal: {
  1971. color: 'green'
  1972. }
  1973. },
  1974. gridIndex: 0
  1975. },
  1976. {
  1977. name: '虫线',
  1978. type: 'line',
  1979. data: maData.greenData,
  1980. smooth: true,
  1981. symbol: 'none',
  1982. xAxisIndex: 0,
  1983. yAxisIndex: 0,
  1984. itemStyle: {
  1985. normal: {
  1986. color: 'green',
  1987. lineStyle: {
  1988. width: 2,
  1989. type: 'solid'
  1990. }
  1991. }
  1992. },
  1993. gridIndex: 0
  1994. },
  1995. {
  1996. name: '龙线',
  1997. type: 'line',
  1998. data: maData.redData,
  1999. smooth: true,
  2000. symbol: 'none',
  2001. xAxisIndex: 0,
  2002. yAxisIndex: 0,
  2003. itemStyle: {
  2004. normal: {
  2005. color: 'red',
  2006. lineStyle: {
  2007. width: 2,
  2008. type: 'solid'
  2009. }
  2010. }
  2011. },
  2012. gridIndex: 0
  2013. },
  2014. {
  2015. name: '黄色',
  2016. type: 'line',
  2017. data: maData.yellowData,
  2018. smooth: true,
  2019. symbol: 'none',
  2020. xAxisIndex: 0,
  2021. yAxisIndex: 0,
  2022. itemStyle: {
  2023. normal: {
  2024. color: 'yellow',
  2025. lineStyle: {
  2026. width: 2,
  2027. type: 'solid'
  2028. }
  2029. }
  2030. },
  2031. gridIndex: 0
  2032. },
  2033. {
  2034. name: '背景区域',
  2035. type: 'line',
  2036. data: [],
  2037. xAxisIndex: 2,
  2038. yAxisIndex: 2,
  2039. markArea: {
  2040. silent: true,
  2041. itemStyle: {
  2042. normal: {
  2043. opacity: 1
  2044. }
  2045. },
  2046. label: {
  2047. normal: {
  2048. show: true,
  2049. position: 'insideRight',
  2050. fontSize: window.innerWidth > 768 ? 16 : 12,
  2051. fontWeight: 'bold',
  2052. color: '#13E113',
  2053. distance: 10
  2054. }
  2055. },
  2056. data: [
  2057. [
  2058. {
  2059. yAxis: 0,
  2060. itemStyle: {
  2061. normal: {
  2062. color: '#CFFFCF'
  2063. }
  2064. },
  2065. label: {
  2066. normal: {
  2067. formatter: '度牛区'
  2068. }
  2069. }
  2070. },
  2071. {
  2072. yAxis: 20
  2073. }
  2074. ],
  2075. [
  2076. {
  2077. yAxis: 20,
  2078. itemStyle: {
  2079. normal: {
  2080. color: '#A6FFFF'
  2081. }
  2082. }
  2083. },
  2084. {
  2085. yAxis: 40
  2086. }
  2087. ],
  2088. [
  2089. {
  2090. yAxis: 40,
  2091. itemStyle: {
  2092. normal: {
  2093. color: '#FFF686'
  2094. }
  2095. }
  2096. },
  2097. {
  2098. yAxis: 60
  2099. }
  2100. ],
  2101. [
  2102. {
  2103. yAxis: 60,
  2104. itemStyle: {
  2105. normal: { color: '#FFD2B3' }
  2106. }
  2107. },
  2108. {
  2109. yAxis: 80
  2110. }
  2111. ],
  2112. [
  2113. {
  2114. yAxis: 80,
  2115. itemStyle: {
  2116. normal: { color: '#FFB8B8' }
  2117. },
  2118. label: {
  2119. normal: {
  2120. formatter: '度牛区',
  2121. color: '#FF0000',
  2122. position: 'insideLeft',
  2123. distance: 10
  2124. }
  2125. }
  2126. },
  2127. {
  2128. yAxis: 100
  2129. }
  2130. ]
  2131. ]
  2132. }
  2133. },
  2134. {
  2135. name: '度牛尺',
  2136. type: 'line',
  2137. data: maDuchiData.greenData,
  2138. symbol: 'none',
  2139. xAxisIndex: 2,
  2140. yAxisIndex: 2,
  2141. itemStyle: {
  2142. normal: {
  2143. color: 'green',
  2144. lineStyle: {
  2145. width: 2,
  2146. type: 'solid'
  2147. }
  2148. }
  2149. },
  2150. gridIndex: 2,
  2151. markPoint: {
  2152. symbol: 'rect',
  2153. symbolSize: (value, params) => {
  2154. const width = window.innerWidth
  2155. const baseHeight = 36
  2156. if (width <= 375) {
  2157. return [2, 16]
  2158. } else if (width <= 768) {
  2159. return [2, 24]
  2160. }
  2161. return [2, baseHeight]
  2162. },
  2163. itemStyle: {
  2164. normal: {
  2165. label: {
  2166. show: false
  2167. }
  2168. }
  2169. },
  2170. data: [
  2171. ...maDuchiData.greenData
  2172. .map((item) => {
  2173. if (item[1] === 0) {
  2174. return {
  2175. coord: [item[0], 20],
  2176. symbolOffset: window.innerWidth > 768 ? [0, 20] : [0, 12],
  2177. itemStyle: {
  2178. color: '#00ff00'
  2179. }
  2180. }
  2181. }
  2182. })
  2183. .filter(Boolean)
  2184. ]
  2185. }
  2186. },
  2187. {
  2188. type: 'line',
  2189. data: maDuchiData.redData,
  2190. // smooth: true,
  2191. symbol: 'none',
  2192. xAxisIndex: 2,
  2193. yAxisIndex: 2,
  2194. itemStyle: {
  2195. normal: {
  2196. color: 'red',
  2197. lineStyle: {
  2198. width: 2,
  2199. type: 'solid'
  2200. }
  2201. }
  2202. },
  2203. gridIndex: 2,
  2204. markPoint: {
  2205. symbol: 'rect',
  2206. symbolSize: (value, params) => {
  2207. const width = window.innerWidth
  2208. const baseHeight = 36
  2209. if (width <= 375) {
  2210. return [2, 16]
  2211. } else if (width <= 768) {
  2212. return [2, 24]
  2213. }
  2214. return [2, baseHeight]
  2215. },
  2216. itemStyle: {
  2217. normal: {
  2218. label: {
  2219. show: false
  2220. }
  2221. }
  2222. },
  2223. data: [
  2224. ...maDuchiData.redData
  2225. .map((item) => {
  2226. if (item[1] === 100) {
  2227. return {
  2228. coord: [item[0], 80],
  2229. symbolOffset: window.innerWidth > 768 ? [0, -20] : [0, -12],
  2230. itemStyle: {
  2231. color: '#ff0000'
  2232. }
  2233. }
  2234. }
  2235. })
  2236. .filter(Boolean)
  2237. ]
  2238. }
  2239. },
  2240. {
  2241. name: '辅助线',
  2242. type: 'line',
  2243. data: [],
  2244. xAxisIndex: 2,
  2245. yAxisIndex: 2,
  2246. markLine: {
  2247. silent: true,
  2248. symbol: 'none',
  2249. lineStyle: {
  2250. color: '#000000',
  2251. width: 3,
  2252. type: 'solid'
  2253. },
  2254. data: [{ yAxis: 20 }]
  2255. }
  2256. },
  2257. {
  2258. name: '辅助线',
  2259. type: 'line',
  2260. data: [],
  2261. xAxisIndex: 2,
  2262. yAxisIndex: 2,
  2263. markLine: {
  2264. silent: true,
  2265. symbol: 'none',
  2266. lineStyle: {
  2267. color: '#000000',
  2268. width: 3,
  2269. type: 'solid'
  2270. },
  2271. data: [{ yAxis: 50 }]
  2272. }
  2273. },
  2274. {
  2275. name: '辅助线',
  2276. type: 'line',
  2277. data: [],
  2278. xAxisIndex: 2,
  2279. yAxisIndex: 2,
  2280. markLine: {
  2281. silent: true,
  2282. symbol: 'none',
  2283. lineStyle: {
  2284. color: '#000000',
  2285. width: 3,
  2286. type: 'solid'
  2287. },
  2288. data: [{ yAxis: 80 }]
  2289. }
  2290. },
  2291. {
  2292. name: '辅助线',
  2293. type: 'line',
  2294. data: [],
  2295. xAxisIndex: 2,
  2296. yAxisIndex: 2,
  2297. markLine: {
  2298. silent: true,
  2299. symbol: 'none',
  2300. lineStyle: {
  2301. color: '#000000',
  2302. width: 3,
  2303. type: 'solid'
  2304. },
  2305. data: [{ yAxis: 100 }]
  2306. }
  2307. }
  2308. ]
  2309. }
  2310. } else if (klineData.type === 3 || klineData.type === 4 || klineData.type === 8 || klineData.type === 9 || klineData.type === 10) {
  2311. console.log('进入3,4,8,9,10分类')
  2312. const arr1 = []
  2313. const arr2 = []
  2314. const arr3 = []
  2315. const arr4 = []
  2316. // k线的数据
  2317. // 动态K线
  2318. const changeColorKline = (QSXH, KLine20) => {
  2319. console.log(QSXH, KLine20)
  2320. if (QSXH) {
  2321. QSXH.map((item) => {
  2322. KLine20.map((kline_item) => {
  2323. if (item[1] == 1 && item[0] == kline_item[0]) {
  2324. arr1.push(kline_item)
  2325. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  2326. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  2327. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  2328. }
  2329. if (item[1] == 2 && item[0] == kline_item[0]) {
  2330. arr2.push(kline_item)
  2331. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  2332. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  2333. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  2334. }
  2335. if (item[1] == 3 && item[0] == kline_item[0]) {
  2336. arr3.push(kline_item)
  2337. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  2338. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  2339. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  2340. }
  2341. if (item[1] == 4 && item[0] == kline_item[0]) {
  2342. arr4.push(kline_item)
  2343. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  2344. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  2345. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  2346. }
  2347. })
  2348. })
  2349. }
  2350. }
  2351. changeColorKline(data.QSXH, data.KLine20)
  2352. var dealData = splitData(data.KLine20)
  2353. var dealData1 = splitData(arr1)
  2354. var dealData2 = splitData(arr2)
  2355. var dealData3 = splitData(arr3)
  2356. var dealData4 = splitData(arr4)
  2357. // 处理MA数据,创建两段重叠的数据
  2358. function processMAData(data) {
  2359. let processedData = []
  2360. // 初始化处理后的数据结构
  2361. data.forEach((item, idx) => {
  2362. processedData.push({
  2363. date: item[0],
  2364. value: item[1],
  2365. type: item[2]
  2366. })
  2367. })
  2368. // 当某一种type只存在一天,设置另一种type透明
  2369. let singleTypeRed = [{ min: 0, max: 0, color: '#000' }]
  2370. let singleTypeYellow = [{ min: 0, max: 0, color: '#000' }]
  2371. let singleTypeGreen = [{ min: 0, max: 0, color: '#000' }]
  2372. // 在类型切换点添加过渡点
  2373. for (let i = 1; i < processedData.length; i++) {
  2374. if (processedData[i].type !== processedData[i - 1].type) {
  2375. if (
  2376. i == processedData.length - 1 ||
  2377. (processedData[i].type !== processedData[i + 1].type &&
  2378. processedData[i - 1].type === processedData[i + 1].type)
  2379. ) {
  2380. if (processedData[i - 1].type === 0) {
  2381. singleTypeGreen.push({ min: i - 1, max: i, color: 'rgba(0,0,0,0)' })
  2382. } else if (processedData[i - 1].type === 1) {
  2383. singleTypeRed.push({ min: i - 1, max: i, color: 'rgba(0,0,0,0)' })
  2384. } else if (processedData[i - 1].type === 2) {
  2385. singleTypeYellow.push({ min: i - 1, max: i, color: 'rgba(0,0,0,0)' })
  2386. }
  2387. }
  2388. }
  2389. if (processedData[i].type !== processedData[i - 1].type) {
  2390. if (processedData[i].type == 0) {
  2391. processedData[i - 1].isTransitionGreen = 1
  2392. } else if (processedData[i].type == 1) {
  2393. processedData[i - 1].isTransitionRed = 1
  2394. } else if (processedData[i].type == 2) {
  2395. processedData[i - 1].isTransitionYellow = 1
  2396. }
  2397. // // 创建过渡点,使用前一个点的值
  2398. // processedData[i - 1].isTransition = true
  2399. }
  2400. }
  2401. // 分离红绿数据,包含过渡点
  2402. let greenData = []
  2403. let redData = []
  2404. let yellowData = []
  2405. processedData.forEach((item, idx) => {
  2406. const point = [item.date, item.value]
  2407. if (item.type === 0) {
  2408. greenData.push(point)
  2409. redData.push([item.date, '-'])
  2410. yellowData.push([item.date, '-'])
  2411. // if (item.isTransition) {
  2412. // // 添加过渡点到红色线
  2413. // redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2414. // yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2415. // }
  2416. if (item.isTransitionGreen) {
  2417. greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2418. } else if (item.isTransitionRed) {
  2419. redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2420. } else if (item.isTransitionYellow) {
  2421. yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2422. }
  2423. } else if (item.type === 1) {
  2424. redData.push(point)
  2425. greenData.push([item.date, '-'])
  2426. yellowData.push([item.date, '-'])
  2427. // if (item.isTransition) {
  2428. // // 添加过渡点到绿色线
  2429. // greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2430. // yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2431. // }
  2432. if (item.isTransitionGreen) {
  2433. greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2434. } else if (item.isTransitionRed) {
  2435. redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2436. } else if (item.isTransitionYellow) {
  2437. yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2438. }
  2439. } else if (item.type === 2) {
  2440. redData.push([item.date, '-'])
  2441. greenData.push([item.date, '-'])
  2442. yellowData.push(point)
  2443. // if (item.isTransition) {
  2444. // // 添加过渡点到绿色线
  2445. // greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2446. // redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2447. // }
  2448. if (item.isTransitionGreen) {
  2449. greenData[greenData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2450. } else if (item.isTransitionRed) {
  2451. redData[redData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2452. } else if (item.isTransitionYellow) {
  2453. yellowData[yellowData.length - 1] = [processedData[idx].date, processedData[idx].value]
  2454. }
  2455. }
  2456. })
  2457. // console.log('greenData', greenData)
  2458. // console.log('redData', redData)
  2459. // console.log('yellowData', yellowData)
  2460. // console.log('green', singleTypeGreen)
  2461. // console.log('red', singleTypeRed)
  2462. // console.log('yellow', singleTypeYellow)
  2463. return {
  2464. greenData: greenData,
  2465. redData: redData,
  2466. yellowData: yellowData,
  2467. singleTypeGreen: singleTypeGreen,
  2468. singleTypeRed: singleTypeRed,
  2469. singleTypeYellow: singleTypeYellow
  2470. }
  2471. }
  2472. const maData = processMAData(data.FCX)
  2473. // 牵牛绳的数据
  2474. // 如果第一个字段的第一个数据为-1的话,不展示牵牛绳
  2475. if (data.FCX[0][1] == '-1') {
  2476. maData.greenData = []
  2477. maData.redData = []
  2478. maData.yellowData = []
  2479. }
  2480. // K线图距离顶部的距离
  2481. // 配置项
  2482. KlineOption = {
  2483. // 底部选项
  2484. // animation: false,
  2485. // 手放上去显示的内容
  2486. legend: [
  2487. {
  2488. //图例文字的样式
  2489. textStyle: {
  2490. color: 'black', //图例文字颜色
  2491. fontSize: window.innerWidth > 768 ? 15 : vwToPx(1.8) // 响应式字体大小
  2492. },
  2493. width: '100%', // 确保有足够的宽度容纳图例
  2494. left: 'center',
  2495. itemGap: window.innerWidth > 768 ? 20 : 10, // 控制图例项之间的间距
  2496. itemWidth: 10, // 调整颜色块的宽度
  2497. itemHeight: 10, // 调整颜色块的高度
  2498. data: [
  2499. {
  2500. name: '进攻K线',
  2501. itemStyle: {
  2502. color: 'rgb(255,0,0)'
  2503. }
  2504. },
  2505. {
  2506. name: '防守K线',
  2507. itemStyle: {
  2508. color: 'red'
  2509. }
  2510. },
  2511. {
  2512. name: '推进K线',
  2513. itemStyle: {
  2514. color: 'orange'
  2515. }
  2516. },
  2517. {
  2518. name: '撤退K线',
  2519. itemStyle: {
  2520. color: 'rgb(84,252,252'
  2521. }
  2522. }
  2523. ]
  2524. },
  2525. {
  2526. //图例文字的样式
  2527. textStyle: {
  2528. color: 'black', //图例文字颜色
  2529. fontSize: window.innerWidth > 768 ? 15 : vwToPx(1.8) // 响应式字体大小
  2530. },
  2531. orient: 'horizontal', // 设置图例水平布局
  2532. top: window.innerWidth > 768 ? '8%' : '8%',
  2533. width: '100%', // 确保有足够的宽度容纳图例
  2534. left: 'center',
  2535. itemGap: 15, // 控制图例项之间的间距
  2536. data: [
  2537. // 牵牛绳
  2538. {
  2539. name: '{green|━}{red|━} ' + '牵牛绳', // 将牵牛绳样式应用到文本前缀
  2540. icon: 'none', // 去掉默认图例图标
  2541. textStyle: {
  2542. rich: {
  2543. green: {
  2544. color: 'green',
  2545. fontSize: window.innerWidth > 768 ? 20 : 10
  2546. },
  2547. red: {
  2548. color: 'red',
  2549. fontSize: window.innerWidth > 768 ? 20 : 10
  2550. }
  2551. }
  2552. }
  2553. },
  2554. {
  2555. name: '龙线'
  2556. },
  2557. {
  2558. name: '虫线'
  2559. }
  2560. ]
  2561. }
  2562. ],
  2563. tooltip: {
  2564. // 调用接口之后方法
  2565. formatter: function (a, b, d) {
  2566. if (a[0].seriesIndex == 0) {
  2567. const KlineTag = ref([]) // 判断几根K线
  2568. const AIBullTag = ref([])
  2569. // 找到第一个满足条件的数据
  2570. KlineTag.value = a.find((item) => item.data[1])?.data || []
  2571. // 找到第一个满足条件的非 '-' 数据
  2572. AIBullTag.value = a.slice(4).find((item) => item.data[1] !== '-')?.data || []
  2573. return (
  2574. a[0].name +
  2575. '<br/>' +
  2576. '开盘价' +
  2577. ':' +
  2578. KlineTag.value[1] +
  2579. '<br/>' +
  2580. '收盘价' +
  2581. ':' +
  2582. KlineTag.value[2] +
  2583. '<br/>' +
  2584. '最低价' +
  2585. ':' +
  2586. KlineTag.value[3] +
  2587. '<br/>' +
  2588. '最高价' +
  2589. ':' +
  2590. KlineTag.value[4] +
  2591. '<br/>' +
  2592. '牵牛绳' +
  2593. ':' +
  2594. AIBullTag.value[1]
  2595. )
  2596. // }else if(a[0].seriesIndex == 5){
  2597. // return a[0].name+ "<br/>" + a[0].seriesName + ":" + a[0].value + "<br/>" + a[1].seriesName + ":" + a[1].value + "<br/>" + a[2].seriesName + ":" + a[2].value + "<br/>" + a[3].seriesName + ":" + a[3].value + "<br/>" + a[4].seriesName + ":" + a[4].value + "<br/>" + a[5].seriesName + ":" + a[5].value
  2598. } else {
  2599. return (
  2600. a[0].name +
  2601. '<br/>' +
  2602. '开盘价' +
  2603. ':' +
  2604. a[0].data[1] +
  2605. '<br/>' +
  2606. '收盘价' +
  2607. ':' +
  2608. a[0].data[2] +
  2609. '<br/>' +
  2610. '最低价' +
  2611. ':' +
  2612. a[0].data[3] +
  2613. '<br/>' +
  2614. '最高价' +
  2615. ':' +
  2616. a[0].data[4] +
  2617. '<br/>'
  2618. )
  2619. }
  2620. },
  2621. trigger: 'axis',
  2622. axisPointer: {
  2623. //坐标轴指示器配置项
  2624. type: 'cross' //‘line’直线指示器,‘cross’十字准星指示器,‘shadow’阴影指示器
  2625. },
  2626. backgroundColor: 'rgba(119, 120, 125, 0.6)', // 提示框浮层的边框颜色。
  2627. borderWidth: 1, // 提示框浮层的边框宽。
  2628. borderColor: '#77787D', // 提示框浮层的边框颜色。
  2629. padding: 10, // 提示框浮层内边距,
  2630. textStyle: {
  2631. //提示框浮层上的文字样式
  2632. color: '#fff'
  2633. }
  2634. },
  2635. // 手放上去时拉的框
  2636. axisPointer: {
  2637. link: [
  2638. {
  2639. xAxisIndex: 'all' // 同时触发所有图形的 x 坐标轴指示器
  2640. }
  2641. ],
  2642. label: {
  2643. backgroundColor: '#77787D' // 文本标签的背景颜色
  2644. }
  2645. },
  2646. toolbox: {
  2647. show: false
  2648. },
  2649. grid: [
  2650. {
  2651. // left: window.innerWidth > 768 ? '8%' : '15%',
  2652. // right: window.innerWidth > 768 ? '7%' : '2.5%',
  2653. height: window.innerWidth > 768 ? '40%' : '37%',
  2654. top: window.innerWidth > 768 ? '10%' : '12%',
  2655. containLabel: false
  2656. },
  2657. {
  2658. // left: window.innerWidth > 768 ? '8%' : '15%',
  2659. // right: window.innerWidth > 768 ? '7%' : '2.5%',
  2660. top: window.innerWidth > 768 ? '53%' : '52%',
  2661. height: window.innerWidth > 768 ? '40%' : '37%',
  2662. containLabel: false
  2663. }
  2664. ],
  2665. xAxis: [
  2666. {
  2667. type: 'category',
  2668. data: dealData.categoryData,
  2669. boundaryGap: true, // 坐标轴两边是否留空,false表示不留空(通常用于K线图)
  2670. axisLine: { onZero: false }, // 设置坐标轴是否通过零点,onZero:false表示不强制穿过零点
  2671. splitLine: { show: false }, // 是否显示分隔线,false表示不显示
  2672. min: 'dataMin', // 坐标轴最小值,'dataMin'表示从数据的最小值开始
  2673. max: 'dataMax', // 坐标轴最大值,'dataMax'表示从数据的最大值开始
  2674. axisPointer: {
  2675. z: 100 // 坐标轴指示器的层级,较大的值会让它显示在其他元素上方
  2676. },
  2677. axisLine: {
  2678. lineStyle: {
  2679. color: 'black' // 坐标轴线的颜色
  2680. }
  2681. }, //
  2682. axisLabel: { show: false }, // 隐藏刻度标签
  2683. axisTick: { show: false } // 隐藏刻度线
  2684. },
  2685. {
  2686. type: 'category',
  2687. gridIndex: 1,
  2688. data: dealData.categoryData,
  2689. boundaryGap: true,
  2690. axisLine: {
  2691. show: false
  2692. },
  2693. axisTick: { show: false } // 隐藏刻度线 // 只保留一个 axisLine 定义
  2694. // 对于第二个类别轴,通常也不需要设置 min 和 max
  2695. }
  2696. ],
  2697. // 控制纵坐标展示数据
  2698. yAxis: [
  2699. {
  2700. scale: true,
  2701. gridIndex: 0,
  2702. axisLabel: {
  2703. show: true,
  2704. fontSize: window.innerWidth > 768 ? 15 : 10
  2705. },
  2706. axisLine: {
  2707. lineStyle: {
  2708. fontSize: '',
  2709. color: 'black'
  2710. }
  2711. },
  2712. axisTick: { show: false },
  2713. splitLine: { show: false }
  2714. },
  2715. {
  2716. scale: true,
  2717. gridIndex: 1,
  2718. splitNumber: 2,
  2719. axisLabel: { show: true, fontSize: window.innerWidth > 768 ? 15 : 10 },
  2720. axisLine: {
  2721. lineStyle: {
  2722. color: 'black'
  2723. }
  2724. },
  2725. axisTick: { show: false },
  2726. splitLine: { show: false }
  2727. }
  2728. ],
  2729. // 下拉条
  2730. dataZoom: [
  2731. {
  2732. type: 'inside',
  2733. xAxisIndex: [0, 1],
  2734. start: 55,
  2735. end: 100
  2736. },
  2737. {
  2738. show: true,
  2739. xAxisIndex: [0, 1],
  2740. type: 'slider',
  2741. top: window.innerWidth > 768 ? '92%' : '91%',
  2742. left: window.innerWidth > 768 ? '10%' : '8%',
  2743. start: 98,
  2744. end: 100
  2745. }
  2746. ],
  2747. visualMap: [
  2748. {
  2749. type: 'piecewise',
  2750. show: false,
  2751. pieces: maData.singleTypeGreen,
  2752. outOfRange: {
  2753. color: 'green'
  2754. },
  2755. dimension: 0,
  2756. seriesIndex: 6
  2757. },
  2758. {
  2759. type: 'piecewise',
  2760. show: false,
  2761. pieces: maData.singleTypeRed,
  2762. outOfRange: {
  2763. color: 'red'
  2764. },
  2765. dimension: 0,
  2766. seriesIndex: 7
  2767. },
  2768. {
  2769. type: 'piecewise',
  2770. show: false,
  2771. pieces: maData.singleTypeYellow,
  2772. outOfRange: {
  2773. color: 'yellow'
  2774. },
  2775. dimension: 0,
  2776. seriesIndex: 8
  2777. }
  2778. ],
  2779. series: [
  2780. // 第一条K线
  2781. {
  2782. name: '进攻K线',
  2783. type: 'candlestick',
  2784. data: dealData1.values,
  2785. xAxisIndex: 0, // 使用第一个 X 轴
  2786. yAxisIndex: 0, // 使用第一个 Y 轴
  2787. itemStyle: {
  2788. normal: {
  2789. color: 'rgb(255,0,0)', // 默认颜色
  2790. color0: 'rgb(255,0,0)',
  2791. borderColor: 'rgb(255,0,0)',
  2792. borderColor0: 'rgb(255,0,0)'
  2793. }
  2794. },
  2795. gridIndex: 0
  2796. },
  2797. //
  2798. {
  2799. name: '推进K线',
  2800. type: 'candlestick',
  2801. data: dealData2.values,
  2802. xAxisIndex: 0, // 使用第一个 X 轴
  2803. yAxisIndex: 0, // 使用第一个 Y 轴
  2804. itemStyle: {
  2805. normal: {
  2806. color: 'rgb(0,0,252)', // 默认颜色
  2807. color0: 'rgb(0,0,252)',
  2808. borderColor: 'rgb(0,0,252)',
  2809. borderColor0: 'rgb(0,0,252)'
  2810. }
  2811. },
  2812. gridIndex: 0
  2813. },
  2814. {
  2815. name: '防守K线',
  2816. type: 'candlestick',
  2817. data: dealData3.values,
  2818. xAxisIndex: 0, // 使用第一个 X 轴
  2819. yAxisIndex: 0, // 使用第一个 Y 轴
  2820. itemStyle: {
  2821. normal: {
  2822. color: 'orange', // 默认颜色
  2823. color0: 'orange',
  2824. borderColor: 'orange',
  2825. borderColor0: 'orange'
  2826. }
  2827. },
  2828. gridIndex: 0
  2829. },
  2830. {
  2831. name: '撤退K线',
  2832. type: 'candlestick',
  2833. data: dealData4.values,
  2834. xAxisIndex: 0, // 使用第一个 X 轴
  2835. yAxisIndex: 0, // 使用第一个 Y 轴
  2836. itemStyle: {
  2837. normal: {
  2838. color: 'rgb(84,252,252)', // 默认颜色
  2839. color0: 'rgb(84,252,252)',
  2840. borderColor: 'rgb(84,252,252)',
  2841. borderColor0: 'rgb(84,252,252)'
  2842. }
  2843. },
  2844. gridIndex: 0
  2845. },
  2846. // 第二条K线
  2847. {
  2848. type: 'candlestick',
  2849. name: '日K',
  2850. xAxisIndex: 1, // 使用第二个 X 轴
  2851. yAxisIndex: 1, // 使用第二个 Y 轴
  2852. data: dealData.values,
  2853. itemStyle: {
  2854. normal: {
  2855. color0: 'red',
  2856. color: 'green',
  2857. borderColor0: 'red',
  2858. borderColor: 'green'
  2859. }
  2860. },
  2861. gridIndex: 1
  2862. },
  2863. {
  2864. name: '{green|━}{red|━} ' + '牵牛绳', // 将牵牛绳样式应用到文本前缀
  2865. type: 'line',
  2866. data: [], // 设置为空数组,不显示数据点
  2867. smooth: true,
  2868. symbol: 'none',
  2869. xAxisIndex: 0, // 线图与第一个 K 线图共享 X 轴
  2870. yAxisIndex: 0, // 线图与第一个 K 线图共享 Y 轴
  2871. showSymbol: false, // 隐藏符号
  2872. lineStyle: {
  2873. opacity: 0 // 使线条透明
  2874. },
  2875. itemStyle: {
  2876. normal: {
  2877. color: 'green'
  2878. }
  2879. },
  2880. gridIndex: 0 // 确保线图与第一个K线图共享网格
  2881. },
  2882. {
  2883. name: '虫线',
  2884. type: 'line',
  2885. data: maData.greenData,
  2886. smooth: true,
  2887. symbol: 'none',
  2888. xAxisIndex: 0, // 线图与第一个 K 线图共享 X 轴
  2889. yAxisIndex: 0, // 线图与第一个 K 线图共享 Y 轴
  2890. itemStyle: {
  2891. normal: {
  2892. color: 'green',
  2893. lineStyle: {
  2894. // color: 'orange', // 线的颜色
  2895. width: 2, // 线宽
  2896. type: 'solid' // 线类型
  2897. }
  2898. }
  2899. },
  2900. gridIndex: 0 // 确保线图与第一个K线图共享网格
  2901. },
  2902. {
  2903. name: '龙线',
  2904. type: 'line',
  2905. data: maData.redData,
  2906. smooth: true,
  2907. symbol: 'none',
  2908. xAxisIndex: 0, // 线图与第一个 K 线图共享 X 轴
  2909. yAxisIndex: 0, // 线图与第一个 K 线图共享 Y 轴
  2910. itemStyle: {
  2911. normal: {
  2912. color: 'red',
  2913. lineStyle: {
  2914. // color: 'orange', // 线的颜色
  2915. width: 2, // 线宽
  2916. type: 'solid' // 线类型
  2917. }
  2918. }
  2919. },
  2920. gridIndex: 0 // 确保线图与第一个K线图共享网格
  2921. },
  2922. {
  2923. name: '黄色',
  2924. type: 'line',
  2925. data: maData.yellowData,
  2926. smooth: true,
  2927. symbol: 'none',
  2928. xAxisIndex: 0,
  2929. yAxisIndex: 0,
  2930. itemStyle: {
  2931. normal: {
  2932. color: 'yellow',
  2933. lineStyle: {
  2934. width: 2,
  2935. type: 'solid'
  2936. }
  2937. }
  2938. },
  2939. gridIndex: 0
  2940. }
  2941. ]
  2942. }
  2943. } else if (klineData.type === 5 || klineData.type === 7) {
  2944. console.log('进入第7分类')
  2945. const upColor = '#00da3c'
  2946. const downColor = '#ec0000'
  2947. function calculateMA(index, data) {
  2948. let result = []
  2949. if (data.FTLINE) {
  2950. data.FTLINE.forEach((item) => {
  2951. result.push(item[index])
  2952. })
  2953. }
  2954. return result
  2955. }
  2956. var dealData = splitData(data.KLine20)
  2957. var bodongliang = splitData(data.WAVEVOL)
  2958. function bodongliangData(values, i) {
  2959. return values.map((subArray) => subArray[i])
  2960. }
  2961. KlineOption = {
  2962. animation: false,
  2963. legend: {
  2964. textStyle: {
  2965. fontSize: window.innerWidth > 768 ? 15 : vwToPx(1.8)
  2966. },
  2967. left: 'center',
  2968. data: [
  2969. {
  2970. name: '天线'
  2971. },
  2972. {
  2973. name: '飞线',
  2974. itemStyle: {
  2975. color: '#000'
  2976. }
  2977. },
  2978. {
  2979. name: '中线'
  2980. },
  2981. {
  2982. name: '流线'
  2983. }
  2984. ]
  2985. },
  2986. tooltip: [
  2987. {
  2988. trigger: 'axis',
  2989. formatter: function (a, b, d) {
  2990. if (a[0].seriesIndex == 0) {
  2991. return (
  2992. a[0].name +
  2993. '<br/>' +
  2994. '开盘价' +
  2995. ':' +
  2996. a[0].data[1] +
  2997. '<br/>' +
  2998. '收盘价' +
  2999. ':' +
  3000. a[0].data[2] +
  3001. '<br/>' +
  3002. '最低价' +
  3003. ':' +
  3004. a[0].data[3] +
  3005. '<br/>' +
  3006. '最高价' +
  3007. ':' +
  3008. a[0].data[4] +
  3009. '<br/>' +
  3010. a[3].marker +
  3011. a[3].seriesName +
  3012. ':' +
  3013. a[3].value +
  3014. '<br/>' +
  3015. a[1].marker +
  3016. a[1].seriesName +
  3017. ':' +
  3018. a[1].value +
  3019. '<br/>' +
  3020. a[2].marker +
  3021. a[2].seriesName +
  3022. ':' +
  3023. a[2].value +
  3024. '<br/>' +
  3025. a[4].marker +
  3026. a[4].seriesName +
  3027. ':' +
  3028. a[4].value
  3029. )
  3030. // }else if(a[0].seriesIndex == 5){
  3031. // console.log(a[0].seriesIndex,'a[0].seriesIndex')
  3032. // return a[0].name+ "<br/>" + a[0].seriesName + ":" + a[0].value + "<br/>" + a[1].seriesName + ":" + a[1].value + "<br/>" + a[2].seriesName + ":" + a[2].value + "<br/>" + a[3].seriesName + ":" + a[3].value + "<br/>" + a[4].seriesName + ":" + a[4].value + "<br/>" + a[5].seriesName + ":" + a[5].value
  3033. } else {
  3034. return (
  3035. a[0].name +
  3036. '<br/>' +
  3037. a[0].marker +
  3038. a[0].seriesName +
  3039. ':' +
  3040. a[0].value +
  3041. '<br/>' +
  3042. a[1].marker +
  3043. a[1].seriesName +
  3044. ':' +
  3045. a[1].value +
  3046. '<br/>' +
  3047. a[2].marker +
  3048. a[2].seriesName +
  3049. ':' +
  3050. a[2].value +
  3051. '<br/>' +
  3052. a[3].marker +
  3053. a[3].seriesName +
  3054. ':' +
  3055. a[3].value +
  3056. '<br/>' +
  3057. a[4].marker +
  3058. a[4].seriesName +
  3059. ':' +
  3060. a[4].value +
  3061. '<br/>'
  3062. )
  3063. }
  3064. },
  3065. axisPointer: {
  3066. type: 'cross'
  3067. },
  3068. backgroundColor: '#fff',
  3069. borderWidth: 1,
  3070. borderColor: '#ccc',
  3071. padding: 10,
  3072. textStyle: {
  3073. color: '#000'
  3074. }
  3075. }
  3076. ],
  3077. axisPointer: {
  3078. link: [
  3079. {
  3080. xAxisIndex: 'all'
  3081. }
  3082. ],
  3083. label: {
  3084. backgroundColor: '#777'
  3085. }
  3086. },
  3087. toolbox: {
  3088. show: false
  3089. },
  3090. visualMap: {
  3091. show: false,
  3092. seriesIndex: 5,
  3093. dimension: 2,
  3094. pieces: [
  3095. {
  3096. value: 1,
  3097. color: downColor
  3098. },
  3099. {
  3100. value: -1,
  3101. color: upColor
  3102. }
  3103. ]
  3104. },
  3105. grid: [
  3106. {
  3107. top: '8%',
  3108. // left: window.innerWidth > 768 ? '10%' : '17%',
  3109. right: '8%',
  3110. height: '40%',
  3111. containLabel: false
  3112. },
  3113. {
  3114. // left: window.innerWidth > 768 ? '10%' : '17%',
  3115. right: '8%',
  3116. top: '10%',
  3117. height: '1%',
  3118. containLabel: false
  3119. },
  3120. {
  3121. // left: window.innerWidth > 768 ? '10%' : '17%',
  3122. right: '8%',
  3123. top: window.innerWidth > 768 ? '60%' : '63%',
  3124. height: '30%',
  3125. containLabel: false
  3126. }
  3127. ],
  3128. xAxis: [
  3129. {
  3130. type: 'category',
  3131. data: dealData.categoryData,
  3132. boundaryGap: true,
  3133. axisLine: { onZero: false },
  3134. splitLine: { show: false },
  3135. min: 'dataMin',
  3136. max: 'dataMax',
  3137. axisPointer: {
  3138. z: 100
  3139. },
  3140. axisLine: {
  3141. lineStyle: {
  3142. color: '#8392A5'
  3143. }
  3144. }
  3145. },
  3146. {
  3147. type: 'category',
  3148. gridIndex: 1,
  3149. data: [],
  3150. boundaryGap: true,
  3151. axisLine: { onZero: false },
  3152. axisTick: { show: false },
  3153. splitLine: { show: false },
  3154. axisLabel: { show: false },
  3155. min: 'dataMin',
  3156. max: 'dataMax',
  3157. show: false
  3158. },
  3159. {
  3160. type: 'category',
  3161. gridIndex: 2,
  3162. data: dealData.categoryData,
  3163. boundaryGap: true,
  3164. axisLine: {
  3165. onZero: true,
  3166. lineStyle: {
  3167. color: '#8392A5'
  3168. }
  3169. },
  3170. axisTick: { show: false },
  3171. splitLine: { show: false },
  3172. axisLabel: { show: false },
  3173. min: 'dataMin',
  3174. max: 'dataMax'
  3175. }
  3176. ],
  3177. yAxis: [
  3178. {
  3179. scale: true,
  3180. splitArea: {
  3181. show: false
  3182. },
  3183. splitLine: {
  3184. show: !1
  3185. },
  3186. axisLine: {
  3187. lineStyle: {
  3188. color: '#8392A5'
  3189. }
  3190. }
  3191. },
  3192. {
  3193. scale: true,
  3194. gridIndex: 1,
  3195. splitNumber: 2,
  3196. min: '0',
  3197. max: '100',
  3198. axisLabel: { show: false },
  3199. axisLine: { show: false },
  3200. axisTick: { show: false },
  3201. splitLine: { show: false }
  3202. },
  3203. {
  3204. scale: true,
  3205. gridIndex: 2,
  3206. splitNumber: 2,
  3207. axisLabel: { show: true },
  3208. axisLine: { onZero: true },
  3209. axisLine: {
  3210. show: true,
  3211. onZero: false,
  3212. lineStyle: {
  3213. color: '#8392A5'
  3214. }
  3215. },
  3216. axisTick: { show: true },
  3217. splitLine: { show: false }
  3218. }
  3219. ],
  3220. dataZoom: [
  3221. {
  3222. type: 'inside',
  3223. xAxisIndex: [0, 1, 2],
  3224. start: 50,
  3225. end: 100,
  3226. textStyle: {
  3227. color: '#8392A5'
  3228. }
  3229. },
  3230. {
  3231. show: true,
  3232. xAxisIndex: [0, 1, 2],
  3233. type: 'slider',
  3234. top: '85%',
  3235. start: 50,
  3236. end: 100,
  3237. textStyle: {
  3238. color: '#8392A5'
  3239. }
  3240. }
  3241. ],
  3242. series: [
  3243. {
  3244. name: 'Dow-Jones index',
  3245. type: 'candlestick',
  3246. data: dealData.values,
  3247. itemStyle: {
  3248. normal: {
  3249. color0: '#ec0000',
  3250. color: '#00da3c',
  3251. borderColor0: '#ec0000',
  3252. borderColor: '#00da3c'
  3253. }
  3254. }
  3255. },
  3256. {
  3257. name: '飞线',
  3258. type: 'line',
  3259. data: calculateMA(1, data),
  3260. smooth: true,
  3261. symbol: 'none',
  3262. itemStyle: {
  3263. normal: {
  3264. color: '#00a32e',
  3265. lineStyle: {
  3266. color: '#00a32e',
  3267. width: 2,
  3268. type: 'solid'
  3269. }
  3270. }
  3271. }
  3272. },
  3273. {
  3274. name: '中线',
  3275. type: 'line',
  3276. data: calculateMA(2, data),
  3277. smooth: true,
  3278. symbol: 'none',
  3279. itemStyle: {
  3280. normal: {
  3281. color: '#de0000',
  3282. lineStyle: {
  3283. color: '#de0000',
  3284. width: 2,
  3285. type: 'solid'
  3286. }
  3287. }
  3288. }
  3289. },
  3290. {
  3291. name: '天线',
  3292. type: 'line',
  3293. data: calculateMA(3, data),
  3294. smooth: true,
  3295. symbol: 'none',
  3296. itemStyle: {
  3297. normal: {
  3298. color: '#ffb300',
  3299. lineStyle: {
  3300. color: '#ffb300',
  3301. width: 2,
  3302. type: 'solid'
  3303. }
  3304. }
  3305. }
  3306. },
  3307. {
  3308. name: '流线',
  3309. type: 'line',
  3310. data: calculateMA(4, data),
  3311. smooth: true,
  3312. symbol: 'none',
  3313. itemStyle: {
  3314. normal: {
  3315. color: '#00c8ff',
  3316. lineStyle: {
  3317. color: '#00c8ff',
  3318. width: 2,
  3319. type: 'solid'
  3320. }
  3321. }
  3322. }
  3323. },
  3324. {
  3325. name: '买盘',
  3326. data: bodongliangData(bodongliang.values, 1),
  3327. xAxisIndex: 2,
  3328. yAxisIndex: 2,
  3329. type: 'bar',
  3330. stack: '1',
  3331. itemStyle: {
  3332. normal: {
  3333. color: '#ec0000'
  3334. }
  3335. }
  3336. },
  3337. {
  3338. name: '卖盘',
  3339. data: bodongliangData(bodongliang.values, 0),
  3340. xAxisIndex: 2,
  3341. yAxisIndex: 2,
  3342. type: 'bar',
  3343. stack: '1',
  3344. itemStyle: {
  3345. normal: {
  3346. color: '#00ffff'
  3347. }
  3348. }
  3349. },
  3350. {
  3351. name: 'CJ',
  3352. data: bodongliangData(bodongliang.values, 2),
  3353. xAxisIndex: 2,
  3354. yAxisIndex: 2,
  3355. type: 'line',
  3356. smooth: !0,
  3357. showSymbol: false,
  3358. itemStyle: {
  3359. normal: {
  3360. color: '#B0B0B0'
  3361. }
  3362. },
  3363. lineStyle: {
  3364. width: 2
  3365. }
  3366. },
  3367. {
  3368. name: 'CD',
  3369. data: bodongliangData(bodongliang.values, 3),
  3370. xAxisIndex: 2,
  3371. yAxisIndex: 2,
  3372. type: 'line',
  3373. smooth: !0,
  3374. showSymbol: false,
  3375. itemStyle: {
  3376. normal: {
  3377. color: '#ffb300'
  3378. }
  3379. },
  3380. lineStyle: {
  3381. width: 2
  3382. }
  3383. },
  3384. {
  3385. name: 'CK',
  3386. data: bodongliangData(bodongliang.values, 4),
  3387. xAxisIndex: 2,
  3388. yAxisIndex: 2,
  3389. type: 'line',
  3390. smooth: !0,
  3391. showSymbol: false,
  3392. itemStyle: {
  3393. normal: {
  3394. color: '#ff00ff'
  3395. }
  3396. },
  3397. lineStyle: {
  3398. width: 2
  3399. }
  3400. }
  3401. ]
  3402. }
  3403. } else if (klineData.type === 6) {
  3404. console.log('进入第6分类')
  3405. var bodongliang = splitData(data.WAVEVOL)
  3406. function bodongliangData(values, i) {
  3407. return values.map((subArray) => subArray[i])
  3408. }
  3409. function calculateMA(index, data) {
  3410. let result = []
  3411. if (data.FTLINE) {
  3412. data.FTLINE.forEach((item) => {
  3413. result.push(item[index])
  3414. })
  3415. }
  3416. return result
  3417. }
  3418. function vwToPx(vw) {
  3419. return (window.innerWidth * vw) / 100
  3420. }
  3421. const arr1 = []
  3422. const arr2 = []
  3423. const arr3 = []
  3424. const arr4 = []
  3425. const changeColorKline = (QSXH, KLine20) => {
  3426. if (QSXH) {
  3427. QSXH.map((item) => {
  3428. KLine20.map((kline_item) => {
  3429. if (item[1] == 1 && item[0] == kline_item[0]) {
  3430. arr1.push(kline_item)
  3431. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  3432. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  3433. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  3434. }
  3435. if (item[1] == 2 && item[0] == kline_item[0]) {
  3436. arr2.push(kline_item)
  3437. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  3438. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  3439. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  3440. }
  3441. if (item[1] == 3 && item[0] == kline_item[0]) {
  3442. arr3.push(kline_item)
  3443. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  3444. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  3445. arr4.push([kline_item[0], null, null, null, null, null, null, null])
  3446. }
  3447. if (item[1] == 4 && item[0] == kline_item[0]) {
  3448. arr4.push(kline_item)
  3449. arr2.push([kline_item[0], null, null, null, null, null, null, null])
  3450. arr3.push([kline_item[0], null, null, null, null, null, null, null])
  3451. arr1.push([kline_item[0], null, null, null, null, null, null, null])
  3452. }
  3453. })
  3454. })
  3455. }
  3456. }
  3457. changeColorKline(data.QSXH, data.KLine20)
  3458. var dealData = splitData(data.KLine20)
  3459. var dealData1 = splitData(arr1)
  3460. var dealData2 = splitData(arr2)
  3461. var dealData3 = splitData(arr3)
  3462. var dealData4 = splitData(arr4)
  3463. var dealGnBullData = data.JN
  3464. const processBarData = (data) => {
  3465. const barData = []
  3466. const markPointData = []
  3467. data.forEach((item) => {
  3468. let color
  3469. switch (item[4]) {
  3470. case 1:
  3471. color = '#13E113'
  3472. break
  3473. case 2:
  3474. color = '#FF0E00'
  3475. break
  3476. case 3:
  3477. color = '#0000FE'
  3478. break
  3479. case 4:
  3480. color = '#1397FF'
  3481. break
  3482. }
  3483. barData.push({
  3484. value: item[5],
  3485. itemStyle: {
  3486. normal: {
  3487. color: color
  3488. }
  3489. }
  3490. })
  3491. if (item[1] === 1) {
  3492. markPointData.push({
  3493. coord: [item[0], item[5]],
  3494. symbol:
  3495. 'image://https://d31zlh4on95l9h.cloudfront.net/images/5iujb101000d5si3v3hr7w2vg0h43z1u.png',
  3496. symbolSize: [30, 30],
  3497. label: {
  3498. normal: {
  3499. color: 'rgba(0, 0, 0, 0)'
  3500. }
  3501. }
  3502. })
  3503. }
  3504. if (item[2] === 1) {
  3505. markPointData.push({
  3506. coord: [item[0], item[5] / 2],
  3507. symbol:
  3508. 'image://https://d31zlh4on95l9h.cloudfront.net/images/5iujaz01000d5si016bxdf6vh0377d2h.png',
  3509. symbolSize: [30, 30],
  3510. label: {
  3511. normal: {
  3512. color: 'rgba(0, 0, 0, 0)'
  3513. }
  3514. }
  3515. })
  3516. }
  3517. if (item[3] === 1) {
  3518. markPointData.push({
  3519. coord: [item[0], 0],
  3520. symbol:
  3521. 'image://https://d31zlh4on95l9h.cloudfront.net/images/5iujb001000d5shzls0tmd4vs0e5tdrw.png',
  3522. symbolSize: [30, 30],
  3523. label: {
  3524. normal: {
  3525. color: 'rgba(0, 0, 0, 0)'
  3526. }
  3527. }
  3528. })
  3529. }
  3530. })
  3531. return { barData, markPointData }
  3532. }
  3533. const { barData, markPointData } = processBarData(dealGnBullData)
  3534. KlineOption = {
  3535. legend: [
  3536. {
  3537. textStyle: {
  3538. color: 'black',
  3539. fontSize: window.innerWidth > 768 ? 15 : vwToPx(1.8)
  3540. },
  3541. width: '100%',
  3542. // top: ,
  3543. left: 'center',
  3544. itemGap: window.innerWidth > 768 ? 20 : 10,
  3545. itemWidth: 10,
  3546. itemHeight: 10,
  3547. data: [
  3548. {
  3549. name: '进攻K线',
  3550. itemStyle: {
  3551. color: 'rgb(255,0,0)'
  3552. }
  3553. },
  3554. {
  3555. name: '防守K线',
  3556. itemStyle: {
  3557. color: 'red'
  3558. }
  3559. },
  3560. {
  3561. name: '推进K线',
  3562. itemStyle: {
  3563. color: 'orange'
  3564. }
  3565. },
  3566. {
  3567. name: '撤退K线',
  3568. itemStyle: {
  3569. color: 'rgb(84,252,252)'
  3570. }
  3571. }
  3572. ]
  3573. },
  3574. {
  3575. textStyle: {
  3576. color: 'black',
  3577. fontSize: window.innerWidth > 768 ? 15 : vwToPx(2.8)
  3578. },
  3579. width: '100%',
  3580. top: '5%',
  3581. left: 'center',
  3582. itemGap: window.innerWidth > 768 ? 20 : 10,
  3583. itemWidth: 10,
  3584. itemHeight: 10,
  3585. data: [
  3586. {
  3587. name: '天线'
  3588. },
  3589. {
  3590. name: '飞线',
  3591. itemStyle: {
  3592. color: '#fff'
  3593. }
  3594. },
  3595. {
  3596. name: '中线'
  3597. },
  3598. {
  3599. name: '流线'
  3600. }
  3601. ]
  3602. },
  3603. {
  3604. textStyle: {
  3605. color: 'black',
  3606. fontSize: window.innerWidth > 768 ? 15 : vwToPx(2.8)
  3607. },
  3608. orient: 'horizontal',
  3609. top: window.innerWidth > 768 ? '8%' : '8%',
  3610. width: '100%',
  3611. left: 'center',
  3612. itemGap: 15,
  3613. data: [
  3614. {
  3615. name: '龙线'
  3616. },
  3617. {
  3618. name: '虫线'
  3619. }
  3620. ]
  3621. }
  3622. ],
  3623. tooltip: {
  3624. formatter: function (a, b, d) {
  3625. if (a[0].seriesIndex == 0) {
  3626. const KlineTag = ref([])
  3627. const AIBullTag = ref([])
  3628. KlineTag.value = a.find((item) => item.data[1])?.data || []
  3629. AIBullTag.value = a.slice(4).find((item) => item.data[1] !== '-')?.data || []
  3630. return (
  3631. a[0].name +
  3632. '<br/>' +
  3633. '开盘价' +
  3634. ':' +
  3635. KlineTag.value[1] +
  3636. '<br/>' +
  3637. '收盘价' +
  3638. ':' +
  3639. KlineTag.value[2] +
  3640. '<br/>' +
  3641. '最低价' +
  3642. ':' +
  3643. KlineTag.value[3] +
  3644. '<br/>' +
  3645. '最高价' +
  3646. ':' +
  3647. KlineTag.value[4] +
  3648. '<br/>' +
  3649. a[4].seriesName +
  3650. ':' +
  3651. a[4].value +
  3652. '<br/>' +
  3653. a[5].seriesName +
  3654. ':' +
  3655. a[5].value +
  3656. '<br/>' +
  3657. a[6].seriesName +
  3658. ':' +
  3659. a[6].value +
  3660. '<br/>' +
  3661. a[7].seriesName +
  3662. ':' +
  3663. a[7].value
  3664. )
  3665. }
  3666. if (a[0].seriesIndex == 4) {
  3667. let formattedVolume
  3668. if (a[0].data.value >= 10000) {
  3669. formattedVolume = (a[0].data.value / 10000).toFixed(2) + 'w'
  3670. } else {
  3671. formattedVolume = a[0].data.value
  3672. }
  3673. return a[0].name + '<br/>' + '成交量' + ':' + formattedVolume
  3674. }
  3675. if (a[0].seriesIndex == 9) {
  3676. return (
  3677. a[0].name +
  3678. '<br/>' +
  3679. a[0].marker +
  3680. a[0].seriesName +
  3681. ':' +
  3682. a[0].value +
  3683. '<br/>' +
  3684. a[1].marker +
  3685. a[1].seriesName +
  3686. ':' +
  3687. a[1].value +
  3688. '<br/>' +
  3689. a[2].marker +
  3690. a[2].seriesName +
  3691. ':' +
  3692. a[2].value +
  3693. '<br/>' +
  3694. a[3].marker +
  3695. a[3].seriesName +
  3696. ':' +
  3697. a[3].value +
  3698. '<br/>' +
  3699. a[4].marker +
  3700. a[4].seriesName +
  3701. ':' +
  3702. a[4].value +
  3703. '<br/>'
  3704. )
  3705. }
  3706. },
  3707. trigger: 'axis',
  3708. axisPointer: {
  3709. type: 'cross'
  3710. },
  3711. backgroundColor: 'rgba(119, 120, 125, 0.6)',
  3712. borderWidth: 1,
  3713. borderColor: '#77787D',
  3714. padding: 10,
  3715. textStyle: {
  3716. color: '#fff'
  3717. }
  3718. },
  3719. axisPointer: {
  3720. link: [
  3721. {
  3722. xAxisIndex: 'all'
  3723. }
  3724. ],
  3725. label: {
  3726. backgroundColor: '#77787D'
  3727. }
  3728. },
  3729. toolbox: {
  3730. show: false
  3731. },
  3732. grid: [
  3733. {
  3734. left: window.innerWidth > 768 ? '14%' : '15%',
  3735. right: window.innerWidth > 768 ? '4%' : '5%',
  3736. top: window.innerWidth > 768 ? '10%' : '12%',
  3737. height: window.innerWidth > 768 ? '36%' : '34%',
  3738. containLabel: false
  3739. },
  3740. {
  3741. left: window.innerWidth > 768 ? '14%' : '15%',
  3742. right: window.innerWidth > 768 ? '4%' : '5%',
  3743. top: window.innerWidth > 768 ? '50%' : '50%',
  3744. height: window.innerWidth > 768 ? '20%' : '22%',
  3745. containLabel: false
  3746. },
  3747. {
  3748. left: window.innerWidth > 768 ? '14%' : '15%',
  3749. right: window.innerWidth > 768 ? '4%' : '5%',
  3750. top: window.innerWidth > 768 ? '74%' : '75%',
  3751. height: window.innerWidth > 768 ? '20%' : '20%',
  3752. containLabel: false
  3753. }
  3754. ],
  3755. xAxis: [
  3756. {
  3757. type: 'category',
  3758. data: dealData.categoryData,
  3759. boundaryGap: true,
  3760. axisLine: { onZero: false },
  3761. splitLine: { show: false },
  3762. min: 'dataMin',
  3763. max: 'dataMax',
  3764. axisPointer: {
  3765. z: 100
  3766. },
  3767. axisLine: {
  3768. lineStyle: {
  3769. color: 'black'
  3770. }
  3771. }, //
  3772. axisLabel: { show: false },
  3773. axisTick: { show: false }
  3774. },
  3775. {
  3776. type: 'category',
  3777. gridIndex: 1,
  3778. data: dealData.categoryData,
  3779. boundaryGap: true,
  3780. axisLine: { lineStyle: { color: 'black' } },
  3781. axisLabel: {
  3782. show: false,
  3783. // fontSize: window.innerWidth > 768 ? 10 : 8,
  3784. interval: 'auto'
  3785. },
  3786. axisTick: { show: false }
  3787. },
  3788. {
  3789. type: 'category',
  3790. gridIndex: 2,
  3791. data: dealData.categoryData,
  3792. boundaryGap: true,
  3793. axisLine: { lineStyle: { color: 'black' } },
  3794. axisLabel: {
  3795. show: true,
  3796. interval: 'auto'
  3797. },
  3798. axisTick: { show: false }
  3799. }
  3800. ],
  3801. yAxis: [
  3802. {
  3803. scale: true,
  3804. gridIndex: 0,
  3805. position: 'left',
  3806. axisLabel: {
  3807. inside: false,
  3808. align: 'right',
  3809. fontSize: window.innerWidth > 768 ? 15 : 10
  3810. },
  3811. axisLine: {
  3812. show: true,
  3813. lineStyle: {
  3814. fontSize: '',
  3815. color: 'black'
  3816. }
  3817. },
  3818. axisTick: { show: false },
  3819. splitLine: { show: false }
  3820. },
  3821. {
  3822. scale: true,
  3823. gridIndex: 1,
  3824. splitNumber: 4,
  3825. min: 0,
  3826. minInterval: 1,
  3827. axisLabel: {
  3828. show: true,
  3829. fontSize: window.innerWidth > 768 ? 15 : 10,
  3830. margin: 8,
  3831. formatter: (value) => {
  3832. if (value >= 1000000000) {
  3833. return (value / 1000000000).toFixed(1) + 'B'
  3834. } else if (value >= 1000000) {
  3835. return (value / 1000000).toFixed(1) + 'M'
  3836. } else if (value >= 10000) {
  3837. return (value / 10000).toFixed(1) + 'W'
  3838. }
  3839. return value.toFixed(0)
  3840. }
  3841. },
  3842. axisLine: { show: true, lineStyle: { color: 'black' } },
  3843. axisTick: { show: false },
  3844. splitLine: { show: true, lineStyle: { type: 'dashed' } },
  3845. boundaryGap: ['20%', '20%']
  3846. },
  3847. {
  3848. scale: true,
  3849. gridIndex: 2,
  3850. splitNumber: 2,
  3851. axisLabel: {
  3852. show: true,
  3853. fontSize: window.innerWidth > 768 ? 15 : 10
  3854. },
  3855. axisLine: { show: true, lineStyle: { color: 'black' } },
  3856. axisTick: { show: false },
  3857. splitLine: { show: false }
  3858. }
  3859. ],
  3860. dataZoom: [
  3861. {
  3862. type: 'inside',
  3863. xAxisIndex: [0, 1, 2],
  3864. start: 55,
  3865. end: 100
  3866. },
  3867. {
  3868. show: true,
  3869. xAxisIndex: [0, 1, 2],
  3870. type: 'slider',
  3871. top: window.innerWidth > 768 ? '95%' : '95%',
  3872. left: window.innerWidth > 768 ? '14%' : '14%',
  3873. start: 98,
  3874. end: 100
  3875. }
  3876. ],
  3877. series: [
  3878. {
  3879. name: '进攻K线',
  3880. type: 'candlestick',
  3881. barWidth: '50%',
  3882. data: dealData1.values,
  3883. xAxisIndex: 0,
  3884. yAxisIndex: 0,
  3885. itemStyle: {
  3886. normal: {
  3887. color: 'rgb(255,0,0)',
  3888. color0: 'rgb(255,0,0)',
  3889. borderColor: 'rgb(255,0,0)',
  3890. borderColor0: 'rgb(255,0,0)'
  3891. }
  3892. },
  3893. gridIndex: 0
  3894. },
  3895. //
  3896. {
  3897. name: '推进K线',
  3898. type: 'candlestick',
  3899. barWidth: '50%',
  3900. data: dealData2.values,
  3901. // markPoint: { data: dealMarkPointData },
  3902. xAxisIndex: 0,
  3903. yAxisIndex: 0,
  3904. itemStyle: {
  3905. normal: {
  3906. color: 'rgb(0,0,252)',
  3907. color0: 'rgb(0,0,252)',
  3908. borderColor: 'rgb(0,0,252)',
  3909. borderColor0: 'rgb(0,0,252)'
  3910. }
  3911. },
  3912. gridIndex: 0
  3913. },
  3914. {
  3915. name: '防守K线',
  3916. type: 'candlestick',
  3917. barWidth: '50%',
  3918. data: dealData3.values,
  3919. xAxisIndex: 0,
  3920. yAxisIndex: 0,
  3921. itemStyle: {
  3922. normal: {
  3923. color: 'orange',
  3924. color0: 'orange',
  3925. borderColor: 'orange',
  3926. borderColor0: 'orange'
  3927. }
  3928. },
  3929. gridIndex: 0
  3930. },
  3931. {
  3932. name: '撤退K线',
  3933. type: 'candlestick',
  3934. barWidth: '50%',
  3935. data: dealData4.values,
  3936. xAxisIndex: 0,
  3937. yAxisIndex: 0,
  3938. itemStyle: {
  3939. normal: {
  3940. color: 'rgb(84,252,252)',
  3941. color0: 'rgb(84,252,252)',
  3942. borderColor: 'rgb(84,252,252)',
  3943. borderColor0: 'rgb(84,252,252)'
  3944. }
  3945. },
  3946. gridIndex: 0
  3947. },
  3948. {
  3949. name: '成交量',
  3950. type: 'bar',
  3951. barWidth: '70%',
  3952. xAxisIndex: 1,
  3953. yAxisIndex: 1,
  3954. data: barData,
  3955. markPoint: {
  3956. data: markPointData,
  3957. label: {
  3958. show: false
  3959. }
  3960. }
  3961. },
  3962. {
  3963. name: '飞线',
  3964. type: 'line',
  3965. data: calculateMA(1, data),
  3966. smooth: true,
  3967. symbol: 'none',
  3968. itemStyle: {
  3969. normal: {
  3970. color: '#00a32e',
  3971. lineStyle: {
  3972. color: '#00a32e',
  3973. width: 2,
  3974. type: 'solid'
  3975. }
  3976. }
  3977. }
  3978. },
  3979. {
  3980. name: '中线',
  3981. type: 'line',
  3982. data: calculateMA(2, data),
  3983. smooth: true,
  3984. symbol: 'none',
  3985. itemStyle: {
  3986. normal: {
  3987. color: '#de0000',
  3988. lineStyle: {
  3989. color: '#de0000',
  3990. width: 2,
  3991. type: 'solid'
  3992. }
  3993. }
  3994. }
  3995. },
  3996. {
  3997. name: '天线',
  3998. type: 'line',
  3999. data: calculateMA(3, data),
  4000. smooth: true,
  4001. symbol: 'none',
  4002. itemStyle: {
  4003. normal: {
  4004. color: '#ffb300',
  4005. lineStyle: {
  4006. color: '#ffb300',
  4007. width: 2,
  4008. type: 'solid'
  4009. }
  4010. }
  4011. }
  4012. },
  4013. {
  4014. name: '流线',
  4015. type: 'line',
  4016. data: calculateMA(4, data),
  4017. smooth: true,
  4018. symbol: 'none',
  4019. itemStyle: {
  4020. normal: {
  4021. color: '#00c8ff',
  4022. lineStyle: {
  4023. color: '#00c8ff',
  4024. width: 2,
  4025. type: 'solid'
  4026. }
  4027. }
  4028. }
  4029. },
  4030. {
  4031. name: '买盘',
  4032. data: bodongliangData(bodongliang.values, 1),
  4033. barWidth: '70%',
  4034. xAxisIndex: 2,
  4035. yAxisIndex: 2,
  4036. type: 'bar',
  4037. stack: '1',
  4038. itemStyle: {
  4039. normal: {
  4040. color: '#ec0000'
  4041. }
  4042. }
  4043. },
  4044. {
  4045. name: '卖盘',
  4046. data: bodongliangData(bodongliang.values, 0),
  4047. barWidth: '70%',
  4048. xAxisIndex: 2,
  4049. yAxisIndex: 2,
  4050. type: 'bar',
  4051. stack: '1',
  4052. itemStyle: {
  4053. normal: {
  4054. color: '#00ffff'
  4055. }
  4056. }
  4057. },
  4058. {
  4059. name: 'CJ',
  4060. data: bodongliangData(bodongliang.values, 2),
  4061. xAxisIndex: 2,
  4062. yAxisIndex: 2,
  4063. type: 'line',
  4064. smooth: !0,
  4065. showSymbol: false,
  4066. itemStyle: {
  4067. normal: {
  4068. color: '#000'
  4069. }
  4070. },
  4071. lineStyle: {
  4072. width: 2
  4073. }
  4074. },
  4075. {
  4076. name: 'CD',
  4077. data: bodongliangData(bodongliang.values, 3),
  4078. xAxisIndex: 2,
  4079. yAxisIndex: 2,
  4080. type: 'line',
  4081. smooth: !0,
  4082. showSymbol: false,
  4083. itemStyle: {
  4084. normal: {
  4085. color: '#ffb300'
  4086. }
  4087. },
  4088. lineStyle: {
  4089. width: 2
  4090. }
  4091. },
  4092. {
  4093. name: 'CK',
  4094. data: bodongliangData(bodongliang.values, 4),
  4095. xAxisIndex: 2,
  4096. yAxisIndex: 2,
  4097. type: 'line',
  4098. smooth: !0,
  4099. showSymbol: false,
  4100. itemStyle: {
  4101. normal: {
  4102. color: '#ff00ff'
  4103. }
  4104. },
  4105. lineStyle: {
  4106. width: 2
  4107. }
  4108. }
  4109. ]
  4110. // graphic: {
  4111. // markPointData : generateGraphicmarkPointData(data11111)
  4112. // }
  4113. }
  4114. } else {
  4115. console.log('其他分类')
  4116. var dealData = splitData(data.KLine20)
  4117. console.log('dealData', dealData)
  4118. KlineOption = {
  4119. title: {
  4120. text: klineData.name,
  4121. left: 50,
  4122. },
  4123. tooltip: {
  4124. trigger: 'axis',
  4125. formatter: function (a, b, d) {
  4126. let def =
  4127. a[0].name +
  4128. '<br/>' +
  4129. '开盘价' +
  4130. a[0].data[1] +
  4131. '<br/>' +
  4132. '收盘价' +
  4133. a[0].data[2] +
  4134. '<br/>' +
  4135. '最低价' +
  4136. a[0].data[3] +
  4137. '<br/>' +
  4138. '最高价' +
  4139. a[0].data[4];
  4140. if (a[1] && a[1].seriesName) {
  4141. def += '<br/>' + a[1].seriesName + ':' + a[1].value;
  4142. }
  4143. return def;
  4144. },
  4145. axisPointer: {
  4146. animation: false,
  4147. type: 'line',
  4148. lineStyle: {
  4149. color: '#376df4',
  4150. width: 2,
  4151. opacity: 1
  4152. }
  4153. },
  4154. confine: true // 确保提示框不超出画布
  4155. },
  4156. //控制坐标轴
  4157. grid: {
  4158. left: '12%',
  4159. right: '10%',
  4160. bottom: '10%',
  4161. top: '18%'
  4162. },
  4163. xAxis: {
  4164. type: 'category',
  4165. data: dealData.categoryData,
  4166. axisLine: { lineStyle: { color: '#8392A5' } }
  4167. },
  4168. yAxis: {
  4169. scale: !0, //true
  4170. // 自定义纵坐标现实的数据
  4171. axisLabel: {
  4172. formatter: function (value) {
  4173. return value // 返回原始值
  4174. }
  4175. },
  4176. axisLine: { lineStyle: { color: '#8392A5' } },
  4177. splitLine: {
  4178. show: !1
  4179. }
  4180. },
  4181. dataZoom: [
  4182. {
  4183. textStyle: {
  4184. color: '#8392A5'
  4185. },
  4186. handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
  4187. handleSize: '80%',
  4188. dataBackground: {
  4189. areaStyle: {
  4190. color: '#8392A5'
  4191. },
  4192. lineStyle: {
  4193. opacity: 0.8,
  4194. color: '#8392A5'
  4195. }
  4196. },
  4197. handleStyle: {
  4198. color: '#fff',
  4199. shadowBlur: 3,
  4200. shadowColor: 'rgba(0, 0, 0, 0.6)',
  4201. shadowOffsetX: 2,
  4202. shadowOffsetY: 2
  4203. }
  4204. },
  4205. {
  4206. type: 'inside',
  4207. start: 1,
  4208. end: 100,
  4209. zoomOnMouseWheel: true,
  4210. moveOnMouseMove: true
  4211. }
  4212. ],
  4213. animation: false,
  4214. series: [
  4215. {
  4216. type: 'candlestick',
  4217. name: '\u65e5K',
  4218. data: dealData.values,
  4219. itemStyle: {
  4220. normal: {
  4221. color0: '#FD1050',
  4222. color: '#0CF49B',
  4223. borderColor0: '#FD1050',
  4224. borderColor: '#0CF49B'
  4225. }
  4226. },
  4227. // barWidth: isMobile ? 6 : isTablet ? 8 : 10
  4228. },
  4229. {
  4230. name: 'MA5',
  4231. type: 'line',
  4232. data: (function (a) {
  4233. for (var MA5 = [], d = 0, g = dealData.values.length; d < g; d++) {
  4234. if (d < a) {
  4235. MA5.push('-')
  4236. } else {
  4237. for (var f = 0, e = 0; e < a; e++) {
  4238. f += dealData.values[d - e][1]
  4239. }
  4240. MA5.push((f / a).toFixed(2))
  4241. }
  4242. }
  4243. return MA5
  4244. })(5),
  4245. smooth: true,
  4246. lineStyle: {
  4247. width: isMobile ? 1 : 2,
  4248. opacity: 0.8
  4249. }
  4250. }
  4251. ]
  4252. };
  4253. }
  4254. console.log('KLine渲染: 图表配置完成');
  4255. try {
  4256. // 应用配置
  4257. console.log('KLine渲染: 开始设置图表选项');
  4258. chartInstancesMap[containerId].setOption(KlineOption);
  4259. console.log('KLine渲染: 图表选项设置成功');
  4260. // 窗口大小变化时重新渲染图表
  4261. const resizeFunc = function () {
  4262. console.log('窗口大小改变,调整图表大小');
  4263. if (chartInstancesMap[containerId] && !chartInstancesMap[containerId].isDisposed()) {
  4264. // 如果设备类型发生变化,重新渲染
  4265. const newIsMobile = window.innerWidth < 768;
  4266. const newIsTablet = window.innerWidth >= 768 && window.innerWidth < 1024;
  4267. if (newIsMobile !== isMobile || newIsTablet !== isTablet) {
  4268. console.log('设备类型变化,重新渲染图表');
  4269. KlineCanvsEcharts(containerId);
  4270. return;
  4271. }
  4272. chartInstancesMap[containerId].resize();
  4273. }
  4274. };
  4275. // 给resize事件绑定一个特定的函数名,便于后续移除
  4276. window[`resize_${containerId}`] = resizeFunc;
  4277. // 绑定resize事件
  4278. window.removeEventListener('resize', window[`resize_${containerId}`]);
  4279. window.addEventListener('resize', window[`resize_${containerId}`]);
  4280. console.log('KLine渲染: 图表渲染完成');
  4281. } catch (error) {
  4282. console.error('KLine渲染: 图表渲染出错', error);
  4283. }
  4284. }
  4285. watch(
  4286. () => audioStore.isVoiceEnabled,
  4287. (newVal) => {
  4288. // 添加状态锁定逻辑
  4289. if (newVal === audioStore.lastVoiceState) return;
  4290. audioStore.lastVoiceState = newVal;
  4291. if (newVal) {
  4292. console.log("开启语音播放");
  4293. // 添加重试机制
  4294. const tryPlay = () => {
  4295. if (!audioStore.ttsUrl) return; // 新增空值判断
  4296. if (audioStore.soundInstance?.playing()) return;
  4297. playAudio(audioStore.ttsUrl);
  4298. setTimeout(() => {
  4299. if (!audioStore.soundInstance?.playing()) {
  4300. Howler.unload();
  4301. }
  4302. }, 1000);
  4303. };
  4304. tryPlay();
  4305. } else {
  4306. console.log("关闭语音播放");
  4307. pauseAudio();
  4308. // 强制停止并释放资源
  4309. // Howler.stop();
  4310. // Howler.unload();
  4311. // if (audioStore.soundInstance) {
  4312. // audioStore.soundInstance.off(); // 移除所有事件监听
  4313. // audioStore.soundInstance = null;
  4314. // }
  4315. }
  4316. },
  4317. { immediate: true }
  4318. )
  4319. watch(
  4320. () => dataStore.activeTabIndex,
  4321. (newVal) => {
  4322. setTimeout(() => {
  4323. console.log("activeTabIndex变化:", newVal);
  4324. // 当标签页切换回来时,重新渲染所有图表
  4325. if (newVal === 0) {
  4326. console.log("切换到AI聊天页,重新渲染图表");
  4327. // 延迟执行以确保DOM已渲染
  4328. renderAllKlineCharts();
  4329. }
  4330. }, 300);
  4331. },
  4332. { immediate: true } // 添加immediate属性,确保初始化时执行一次
  4333. )
  4334. // 添加渲染所有K线图的方法
  4335. function renderAllKlineCharts() {
  4336. console.log("重新渲染所有K线图");
  4337. // 查找所有K线消息
  4338. const messages = chatStore.messages;
  4339. for (let i = 0; i < messages.length; i++) {
  4340. if (messages[i].type === 'kline' && messages[i].chartData) {
  4341. const containerId = `kline-container-${i}`;
  4342. console.log(`尝试渲染K线图: ${containerId}`);
  4343. // 确保DOM已经渲染
  4344. const container = document.getElementById(containerId);
  4345. if (container) {
  4346. // 渲染图表
  4347. KlineCanvsEcharts(containerId);
  4348. } else {
  4349. console.warn(`找不到容器: ${containerId}`);
  4350. }
  4351. }
  4352. }
  4353. }
  4354. // 初始化随机GIF
  4355. onMounted(() => {
  4356. const random = Math.floor(Math.random() * 6) + 1;
  4357. currentGif.value = gifList[random];
  4358. getQuestionsList();
  4359. console.log("组件挂载完成");
  4360. // 添加DOM变化监听器
  4361. const observer = new MutationObserver((mutations) => {
  4362. mutations.forEach((mutation) => {
  4363. if (mutation.type === 'childList' && mutation.addedNodes.length) {
  4364. // 检查是否添加了图表容器
  4365. const containers = document.querySelectorAll('[id^="kline-container-"]');
  4366. if (containers.length) {
  4367. // console.log("DOM变化监听到K线容器:", Array.from(containers).map(el => el.id));
  4368. }
  4369. }
  4370. });
  4371. });
  4372. // 开始监听DOM变化
  4373. observer.observe(document.body, { childList: true, subtree: true });
  4374. });
  4375. // 组件卸载时清理所有图表实例和事件监听器
  4376. onUnmounted(() => {
  4377. // 清理所有图表实例
  4378. Object.keys(chartInstancesMap).forEach(key => {
  4379. if (chartInstancesMap[key]) {
  4380. // 移除resize事件监听
  4381. if (window[`resize_${key}`]) {
  4382. window.removeEventListener('resize', window[`resize_${key}`]);
  4383. delete window[`resize_${key}`];
  4384. }
  4385. // 销毁图表实例
  4386. chartInstancesMap[key].dispose();
  4387. delete chartInstancesMap[key];
  4388. }
  4389. });
  4390. });
  4391. </script>
  4392. <template>
  4393. <div class="chat-container">
  4394. <!-- GIF区域 -->
  4395. <div class="gif-area">
  4396. <img :src="currentGif" alt="AI动画" />
  4397. <div class="marquee-container">
  4398. <div id="top" class="marquee-row top" @mouseenter="floatingTopMouseEnter" @mouseleave="floatingTopMouseLeave">
  4399. <div v-for="(questions, index) in questionsList.slice(0, 5)" :key="'top' + index" class="marquee-item"
  4400. @click="showQuestions(questions)">
  4401. {{ questions.title }}
  4402. </div>
  4403. </div>
  4404. <div id="bottom" class="marquee-row bottom" @mouseenter="floatingBottomMouseEnter"
  4405. @mouseleave="floatingBottomMouseLeave">
  4406. <div v-for="(questions, index) in questionsList.slice(5, 10)" :key="'bottom' + index" class="marquee-item"
  4407. @click="showQuestions(questions)">
  4408. {{ questions.title }}
  4409. </div>
  4410. </div>
  4411. </div>
  4412. </div>
  4413. <!-- 消息区域 -->
  4414. <!-- <div class="message-area">
  4415. <div v-for="(msg, index) in chatMsg" :key="index" :class="['message-bubble', msg.sender]">
  4416. {{ msg.content }}
  4417. </div>
  4418. </div> -->
  4419. <!-- <div class="message-area">
  4420. <div v-for="(msg, index) in chatMsg" :key="index" :class="['message-bubble', msg.sender]" v-html="msg.content">
  4421. </div>
  4422. </div> -->
  4423. <!-- <div v-for="(msg, index) in chatMsg" :key="index" :class="['message-bubble', msg.sender]" v-html="msg.content">
  4424. </div> -->
  4425. <div v-for="(msg, index) in chatMsg" :key="index" :class="['message-bubble', msg.sender]">
  4426. <div v-if="msg.type === 'kline'" class="kline-container">
  4427. <div :id="'kline-container-' + index" class="chart-mount-point">
  4428. <div v-if="!msg.hasValidData" class="no-data-message">
  4429. <p>暂无K线数据</p>
  4430. </div>
  4431. </div>
  4432. </div>
  4433. <div v-else v-html="msg.content"></div>
  4434. </div>
  4435. <!-- 新闻弹窗 -->
  4436. <el-dialog v-model="dialogVisible" title="新闻详情" width="60%">
  4437. <p>{{ currentQuestions.content }}</p>
  4438. </el-dialog>
  4439. </div>
  4440. </template>
  4441. <style scoped>
  4442. .chat-container {
  4443. display: flex;
  4444. flex-direction: column;
  4445. overflow: hidden;
  4446. }
  4447. .gif-area {
  4448. /* position: relative; */
  4449. /* height: 30vh; */
  4450. display: flex;
  4451. flex-direction: column;
  4452. justify-content: center;
  4453. align-items: center;
  4454. flex-shrink: 0;
  4455. /* 防止GIF区域被压缩 */
  4456. }
  4457. .gif-area img {
  4458. width: 30%;
  4459. /* 改为百分比单位 */
  4460. min-width: 200px;
  4461. /* 最小尺寸 */
  4462. max-width: 400px;
  4463. /* 最大尺寸 */
  4464. height: auto;
  4465. left: 50%;
  4466. transition: all 0.3s;
  4467. /* 添加过渡效果 */
  4468. }
  4469. .message-area {
  4470. margin-top: 2%;
  4471. flex: 1;
  4472. /* 消息区域占据剩余空间 */
  4473. overflow-y: auto;
  4474. padding: 20px;
  4475. display: flex;
  4476. flex-direction: column;
  4477. gap: 15px;
  4478. }
  4479. .marquee-container {
  4480. /* position: absolute; */
  4481. bottom: 0;
  4482. width: 100%;
  4483. /* ga */
  4484. }
  4485. .marquee-row {
  4486. white-space: nowrap;
  4487. overflow: visible;
  4488. padding: 8px 0;
  4489. width: 100%;
  4490. }
  4491. .marquee-item {
  4492. display: inline-block;
  4493. margin: 0 15px;
  4494. padding: 8px 20px;
  4495. background: rgba(255, 255, 255, 0.9);
  4496. /* 白色背景 */
  4497. border-radius: 10px;
  4498. /* 圆角矩形 */
  4499. color: #333;
  4500. /* 文字颜色改为深色 */
  4501. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  4502. /* 添加阴影 */
  4503. transition: all 0.3s;
  4504. transition: color 0.3s;
  4505. }
  4506. .top {
  4507. animation: marquee 25s linear infinite;
  4508. /* 默认动画是运行状态 */
  4509. animation-play-state: running;
  4510. }
  4511. .bottom {
  4512. animation: marquee 15s linear infinite reverse;
  4513. /* 默认动画是运行状态 */
  4514. animation-play-state: running;
  4515. }
  4516. /* 添加PC端专用速度 */
  4517. @media (min-width: 768px) {
  4518. .top {
  4519. animation-duration: 35s;
  4520. /* PC端改为35秒 */
  4521. }
  4522. .bottom {
  4523. animation-duration: 35s;
  4524. /* PC端改为35秒 */
  4525. }
  4526. }
  4527. @keyframes marquee {
  4528. 0% {
  4529. transform: translateX(100%);
  4530. }
  4531. 100% {
  4532. transform: translateX(-250%);
  4533. }
  4534. }
  4535. .message-bubble {
  4536. max-width: 70%;
  4537. margin: 10px 0px;
  4538. padding: 15px 25px;
  4539. border-radius: 10px;
  4540. position: relative;
  4541. }
  4542. .message-bubble.user {
  4543. background: #8263f0;
  4544. color: white;
  4545. margin-left: auto;
  4546. margin-right: 20px;
  4547. /* border-bottom-right-radius: 5px; */
  4548. }
  4549. .message-bubble.ai {
  4550. background: #ffffff;
  4551. color: #333;
  4552. margin-right: auto;
  4553. margin-left: 20px;
  4554. /* border-bottom-left-radius: 5px; */
  4555. }
  4556. .kline-container {
  4557. margin-top: 10px;
  4558. /* 最小高度 */
  4559. min-height: 320px;
  4560. /* 视口高度单位 */
  4561. height: 40vh;
  4562. min-width: 50vw;
  4563. }
  4564. @media (max-width: 768px) {
  4565. .kline-container {
  4566. min-width: 75vw;
  4567. }
  4568. }
  4569. .kline-container .chart-mount-point {
  4570. height: 100%;
  4571. width: 100%;
  4572. }
  4573. </style>