1
jhzh
2026-05-22 ef52095f5e9f0a9fe2da779bb1573947d77d75b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<template>
  <div class="quotes-list-wrap">
    <!-- 头部:All / Spot / Futures + 搜索图标 -->
    <div class="quotes-header">
      <div class="quotes-header-tabs">
        <span
          v-for="(tab, idx) in headerTabs"
          :key="idx"
          class="quotes-header-tab"
          :class="{ 'quotes-header-tab--active': headerActive === idx }"
          @click="headerActive = idx"
        >
          {{ tab }}
        </span>
      </div>
      <div class="quotes-header-search" @click="onSearchClick">
        <van-icon name="search" size="22" />
      </div>
    </div>
    <div class="quotes-list pb-60 pl-5 pr-5" id="cryptos">
      <list-quatation :listData="qList" :tabActive="2" :tabShow="false" />
    </div>
  </div>
</template>
 
<script setup>
import { ref, computed, onBeforeUnmount } from 'vue';
import { useStore } from "vuex";
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { _getHomeList } from '@/service/cryptos.api'
import { TIME_OUT } from "@/config";
import ListQuatation from "@/components/Transform/list-quotation/index.vue";
 
const { t } = useI18n();
const router = useRouter();
const store = useStore();
 
const headerActive = ref(2);
const headerTabs = computed(() => [t('全部'), t('现货'), t('永续')]);
 
const onSearchClick = () => {
  router.push('/optional/search');
};
 
//#region 行情数据----------------------------------------
let qList = ref([])
let qListCope = ref([]) // 备份数据
let key = ref('') // 搜索关键词
let timeout = ref(null)
const coinArr = computed(() => store.getters['home/coinArr']);
 
const fetchQList = async () => { // 获取行情
  const list = await _getHomeList(coinArr.value.join(',')).catch(() => {
  })
 
  if (!(list instanceof Array)) {
    return
  }
 
  // 通过关键字进行筛选
  if (key.value) {
    qList.value = list.filter(item => {
      return item.symbol_data.toLowerCase().includes(key.value.toLowerCase()) || item.name.toLowerCase().includes(key.value.toLowerCase())
    })
  } else {
    qList.value = list
  }
  qListCope.value = list; // 备份数据
 
  if (timeout.value) {
    clearTimeout(timeout.value)
  }
  timeout.value = setTimeout(async () => {
    await fetchQList()
  }, TIME_OUT)
}
fetchQList()
 
onBeforeUnmount(() => {
  if (timeout.value) {
    clearInterval(timeout.value)
  }
})
//#endregion----------------------------------------------
 
// 搜索
const onSearch = (val) => {
  key.value = val
 
  if (!val) {
    qList.value = qListCope.value
    return
  }
  let newList = qListCope.value.filter(item => {
    return item.symbol_data.toLowerCase().includes(val.toLowerCase()) || item.name.toLowerCase().includes(val.toLowerCase())
  })
  qList.value = newList
}
</script>
<style lang="scss" scoped>
.quotes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 16px 16px;
  background: #f0f0f0;
}
 
.quotes-header-tabs {
  display: flex;
  align-items: center;
  gap: 24px;
}
 
.quotes-header-tab {
  font-size: 16px;
  color: #999;
  cursor: pointer;
  font-weight: 500;
}
 
.quotes-header-tab--active {
  color: #5e2bc8;
  font-weight: 600;
}
 
.quotes-header-search {
  color: #999;
  cursor: pointer;
  padding: 4px;
}
 
.quotes-list {
  min-height: 100vh;
 
  :deep(.active) {
    background-color: $bg_yellow;
    border-radius: 3rem;
  }
}
</style>