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.

229 lines
6.4 KiB

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