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.

218 lines
6.1 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. import { defineStore } from "pinia";
  2. import { ref, watch } from "vue";
  3. import { useUserStore } from "./userPessionCode";
  4. import { useLanguage } from "@/utils/languageService";
  5. import { dataListAPI } from "@/api/AIxiaocaishen";
  6. // import { useSkeletonStore } from '@/utils/skeletonLoader'
  7. import { useRoute } from "vue-router";
  8. // const skeletonStore = useSkeletonStore()
  9. // const { t } = useLanguage()
  10. export const useDataStore = defineStore("data", () => {
  11. const route = useRoute();
  12. console.log(route, "地址栏携带的参数。。。。。。");
  13. const userStore = useUserStore();
  14. const brainDataList = ref(null);
  15. const swordDataList = ref(null);
  16. const priceDataList = ref(null);
  17. const timeDataList = ref(null);
  18. const showALLData = ref(null);
  19. const HomePage = ref(null);
  20. const AIBull = ref(null);
  21. const AIGoldBull = ref(null);
  22. const AIRadar = ref(null);
  23. const loading = ref(false);
  24. const klineData = ref(null);
  25. const activeTabIndex = ref(null);
  26. const isFeedback = ref(false); // 用于控制是否显示反馈页面的标志
  27. const setKlineData = (data) => {
  28. klineData.value = data;
  29. };
  30. const setActiveTabIndex = (index) => {
  31. activeTabIndex.value = index;
  32. };
  33. const getQueryVariable = (variable) => {
  34. const query = window.location.search.substring(1);
  35. // console.log(query,'query')
  36. const vars = query.split("&");
  37. // console.log(vars,'vars')
  38. for (let i = 0; i < vars.length; i++) {
  39. const pair = vars[i].split("=");
  40. if (pair[0] === variable) {
  41. return pair[1];
  42. }
  43. }
  44. return "";
  45. };
  46. // const getAnswer = (result) => {
  47. // const data = result.data;
  48. // const vars = query.split('&')
  49. // for (let i = 0; i < vars.length; i++) {
  50. // const pair = vars[i].split('=')
  51. // if (pair[0] === variable) {
  52. // return pair[1]
  53. // }
  54. // }
  55. // return ''
  56. // }
  57. // 使用示例,获取地址栏参数
  58. const token = ref(getQueryVariable("token"));
  59. const market = ref(getQueryVariable("market"));
  60. const code = ref(getQueryVariable("code"));
  61. console.log(token.value); // 输出 token 的值,例如 "111"
  62. const fetchChartData = async (market,code) => {
  63. const getTokenString = String(localStorage.getItem("localToken"));
  64. // const getMarketString = String(localStorage.getItem("localMarket"));
  65. // const getCodeString = String(localStorage.getItem("localCode"));
  66. // const getMarket = String()
  67. try {
  68. const res = await dataListAPI({
  69. token: getTokenString || "",
  70. market: market || "gb",
  71. code: code || "NDX",
  72. language: "cn", //t.value.suoxie,
  73. brainPrivilegeState: userStore.brainPerssion,
  74. swordPrivilegeState: userStore.swordPerssion,
  75. stockForecastPrivilegeState: userStore.pricePerssion,
  76. spaceForecastPrivilegeState: userStore.timePerssion,
  77. aibullPrivilegeState: userStore.aibullPerssion,
  78. aigoldBullPrivilegeState: userStore.aiGnbullPerssion,
  79. airadarPrivilegeState: userStore.airadarPerssion,
  80. marketList: userStore.aiGoldMarketList,
  81. });
  82. brainDataList.value = res.data.Brain;
  83. swordDataList.value = res.data.Sword;
  84. priceDataList.value = res.data.StockForecast;
  85. timeDataList.value = res.data.SpaceForecast;
  86. showALLData.value = res.data.ShowAll;
  87. HomePage.value = res.data.HomePage;
  88. AIBull.value = res.data.AIBull;
  89. AIGoldBull.value = res.data.AIGoldBull;
  90. AIRadar.value = res.data.AIRadar;
  91. } catch (error) {
  92. console.error("获取图表数据出错:", error);
  93. } finally {
  94. loading.value = false;
  95. console.log("数据获取过程结束");
  96. }
  97. };
  98. // 获取路径上market的值
  99. const getMarket = () => {
  100. let market = "";
  101. const queryMarket = getQueryVariable("market");
  102. if (queryMarket) {
  103. if (
  104. ["sg", "my", "in", "hk", "th", "vi", "usa", "can", "gb", "cn"].includes(
  105. queryMarket
  106. )
  107. ) {
  108. return queryMarket;
  109. } else {
  110. switch (queryMarket) {
  111. case "SGX":
  112. return "sg";
  113. case "BMB":
  114. return "my";
  115. case "IDX":
  116. return "in";
  117. case "HKEX":
  118. return "hk";
  119. case "SET":
  120. return "th";
  121. case "HN":
  122. return "vi";
  123. case "HONSE":
  124. return "vi";
  125. case "AMERA":
  126. return "usa";
  127. case "NYSE":
  128. return "usa";
  129. case "NASDAQ":
  130. return "usa";
  131. case "DLD":
  132. return "can";
  133. case "DLDCY":
  134. return "can";
  135. case "GINDEX":
  136. return "gb";
  137. case "BZ":
  138. return "cn";
  139. case "SH":
  140. return "cn";
  141. case "SZ":
  142. return "cn";
  143. default:
  144. return "无市场数据";
  145. }
  146. }
  147. }
  148. return "";
  149. };
  150. const isLoading = ref(true);
  151. const initData = async () => {
  152. isLoading.value = true;
  153. try {
  154. // 初始化逻辑
  155. } catch (error) {
  156. console.error("Error loading data:", error);
  157. } finally {
  158. isLoading.value = false;
  159. }
  160. };
  161. // watch(
  162. // () => [userStore.isReady, t.value?.suoxie],
  163. // ([isReady]) => {
  164. // console.log('isReady 或 language 变化:', isReady)
  165. // if (isReady) {
  166. // setTimeout(() => fetchChartData(), 500)
  167. // }
  168. // },
  169. // { immediate: true, deep: true }
  170. // )
  171. watch(
  172. () => window.location.ancestorOrigins,
  173. (newQuery, oldQuery) => {
  174. console.log("newQuery", newQuery);
  175. // if () {
  176. // fetchChartData();
  177. // }
  178. }
  179. );
  180. // watch(() => userStore.aibullPerssion, (newValue) => {
  181. // if (newValue === 1) fetchChartData()
  182. // })
  183. initData();
  184. return {
  185. // brainDataList,
  186. // swordDataList,
  187. // priceDataList,
  188. // timeDataList,
  189. // showALLData,
  190. HomePage,
  191. // AIBull,
  192. AIGoldBull,
  193. // loading,
  194. // AIRadar,
  195. fetchChartData,
  196. activeTabIndex,
  197. klineData,
  198. setKlineData,
  199. initData,
  200. getMarket,
  201. getQueryVariable,
  202. setActiveTabIndex,
  203. isFeedback,
  204. };
  205. });