1
PC-20250623MANY\Administrator
2025-08-24 1b8ed300551b88bd86b80b8dfa52d2d6c2b7fdb2
src/page/markets/markets.vue
@@ -20,18 +20,17 @@
    <div class="tabs flex-between">
      <div
        class="tab_item flex-center"
        :class="{ active: item.value == tab }"
        :class="{ active: item.pid == tab }"
        v-for="item in tabList"
        :key="item.value"
        @click="tab = item.value"
        :key="item.pid"
        @click="tab = item.pid"
      >
        <span>{{ item.name }}</span>
        <span class="line-one">{{ item.abbreviation }}</span>
      </div>
    </div>
    <div class="markets_echart">
      <index-component :ids="'markets'"></index-component>
      <!-- <van-skeleton title :row="3" /> -->
      <index-component :ids="'markets'" :dataObj="kData"></index-component>
    </div>
    <stock-list :propOption="propOption"></stock-list>
@@ -54,22 +53,49 @@
        {
          text: this.$t("美国"),
          value: "US",
          name: "美国"
          name: this.$t("美国")
        },
        {
          text: this.$t("墨西哥"),
          value: "MX",
          name: "墨西哥"
          text: this.$t("hk1"),
          value: "HK",
          name: this.$t("hk1")
        },
        {
          text: this.$t("tw"),
          value: "TW",
          name: this.$t("tw")
        },
        {
          text: this.$t("id1"),
          value: "IN",
          name: this.$t("id1")
        }
      ],
      tabList: [
        { name: "Dow Jones", value: 1 },
        { name: "S&P 500", value: 2 },
        { name: "NASDAQ", value: 3 }
      tabList: [],
      usList: [
        { abbreviation: "Dow Jones" },
        { abbreviation: "S&P 500" },
        { abbreviation: "NASDAQ" }
      ],
      hkList: [
        { abbreviation: "恒生指數" },
        { abbreviation: "恒生中國企業指數" },
        { abbreviation: "HSCEI Covered Call Index" }
      ],
      twList: [
        { abbreviation: "臺灣證券交易所發行量加權股價指數" },
        { abbreviation: "櫃買指數" },
        { abbreviation: "臺灣50指數" }
      ],
      inList: [
        { abbreviation: "Nifty 50 Index" },
        { abbreviation: "Nifty Bank Index" },
        { abbreviation: "Nifty Financial Services Index" }
      ],
      tab: 1,
      pageNum: 1,
      pageSize: 10
      pageSize: 10,
      kData: {}
    };
  },
  components: {
@@ -78,24 +104,69 @@
    stockList,
    indexComponent
  },
  watch: {
    tab() {
      this.getIndicesAndKData();
    }
  },
  computed: {
    switchText() { // 切换文字
    switchText() {
      // 切换文字
      return this.$t(this.$store.state.marketsSwitch.name) || this.$t("美国");
    },
    propOption() { // 传递给列表组件的类型值
    propOption() {
      // 传递给列表组件的类型值
      return { stockType: this.$store.state.marketsSwitch.value };
    }
  },
  created() {
    if (!this.$store.state.marketsSwitch.name) { // 如果没有选过,默认选择第一个
  async created() {
    if (!this.$store.state.marketsSwitch.name) {
      // 如果没有选过,默认选择第一个
      this.$store.commit("MARKET_CHANGE", this.actions[0]);
    }
    await this.getTabData();
    this.tab = this.tabList[0].pid;
  },
  mounted() {},
  methods: {
    // 选择
    onSelect(e) {
    async onSelect(e) {
      this.$store.commit("MARKET_CHANGE", e);
      await this.getTabData();
      this.tab = this.tabList[0].pid;
    },
    // 获取tab数据
    async getTabData() {
      let stockType = this.$store.state.marketsSwitch.value;
      let data = await api.getIndicesList({
        stockType
      });
      // 数据重构
      let list = [];
      if (stockType == "US") list = this.usList;
      else if (stockType == "HK") list = this.hkList;
      else if (stockType == "TW") list = this.twList;
      else if (stockType == "IN") list = this.inList;
      this.tabList = list.map((item, index) => {
        item = { ...item, ...data.data[index + 1] };
        return item;
      });
      // console.log("dadadadadad", this.tabList);
    },
    // 获取指数图
    async getIndicesAndKData() {
      let data = await api.getIndicesAndKData({
        pid: this.tab,
        stockType: this.$store.state.marketsSwitch.value
      });
      this.kData = data.data;
      // console.log("getIndicesAndKData", this.kData);
    },
    // tab切换
    tabChange() {
      this.getIndicesAndKData();
    }
  }
};
@@ -134,6 +205,7 @@
      width: 32%;
      height: 0.8em;
      border-radius: 0.5em;
      padding: 0 .25em;
      span {
        font-size: 0.4em;