From 4b497403b94971206f7ca1cb2e2ff63b55c9a30e Mon Sep 17 00:00:00 2001
From: lxf <1371462558@qq.com>
Date: Wed, 16 Jul 2025 17:24:25 +0800
Subject: [PATCH] 页面升级vue3

---
 src/components/Transform/list-quotation/index.vue |  249 ++++++++++++++++++++++++-------------------------
 1 files changed, 121 insertions(+), 128 deletions(-)

diff --git a/src/components/Transform/list-quotation/index.vue b/src/components/Transform/list-quotation/index.vue
index d74095e..1087cd5 100644
--- a/src/components/Transform/list-quotation/index.vue
+++ b/src/components/Transform/list-quotation/index.vue
@@ -3,17 +3,17 @@
     <van-list>
       <!-- 热门 -->
       <div class="flex items-end justify-between" style="margin: 14px 0;">
-        <div class="block text-22 font-medium">{{ $t('Market') }}</div>
+        <div class="block text-22 font-medium">{{ t('Market') }}</div>
         <div class="relative text-13" @click="toggleDropdown">
           <div class="flex px-20 justify-between rounded-full bg-black text-white min-w-140 box-border">
-            <div class="block">{{ $t(topTitle) }}</div>
+            <div class="block">{{ t(topTitle) }}</div>
             <van-icon name="play" style="align-content:center;transform: rotate(90deg);" />
           </div>
           <div
             class="px-16 py-20 bg-black text-white flex flex-col absolute min-w-140 box-border top-25 rounded-11 leading-28"
             style="z-index:999;margin-top: 0.8rem;" v-show="isTopShow">
-            <div @click="changeType('货币兑换', 2)">{{ $t('货币兑换') }}</div>
-            <div @click="changeType('外汇交易', 1)">{{ $t('外汇交易') }}</div>
+            <div @click="changeType(t('货币兑换'), 2)">{{ t('货币兑换') }}</div>
+            <div @click="changeType(t('外汇交易'), 1)">{{ t('外汇交易') }}</div>
           </div>
         </div>
       </div>
@@ -21,11 +21,11 @@
 
       <transition-group :name="type" tag="div">
         <div>
-          <van-cell v-for="item in listData" :key="item.id" style="background-color: #f0f0f0;margin-bottom: 10px;">
+          <van-cell v-for="item in showList" :key="item.id" style="background-color: #f0f0f0;margin-bottom: 10px;">
             <ul class="flex justify-between w-full items-center" @click="onItemClick(item)">
               <li class="flex items-center left">
                 <img
-                  :src="item.symbol ? `${HOST_URL}/symbol/${item.symbol_data}.png` : handleImage('../../../assets/loading-default.png')"
+                  :src="item.symbol ? `${HOST_URL}/symbol/${item.symbol_data}.png` : handleImage('@/assets/loading-default.png')"
                   alt="logo" class="w-72 h-72 mr-16" />
                 <p class="flex flex-col">
                   <span class="flex items-end font-32 flex items-center">
@@ -51,135 +51,128 @@
     </van-list>
   </div>
 </template>
-<script>
-import { List, Cell } from 'vant'
-import { mapGetters, mapActions } from 'vuex'
+<script setup>
+import { ref, computed, onMounted, watch } from 'vue';
+import { useStore } from 'vuex';
+import { useI18n } from 'vue-i18n';
+import { useRouter } from 'vue-router';
+import { List, Cell, Icon } from 'vant';
 import { fixDate, setStorage } from "@/utils";
 import ExTabs from "@/components/Transform/ex-tabs/index.vue";
-import { HOST_URL } from '@/config'
+import { HOST_URL } from '@/config';
 import { SET_CURRENCY } from "@/store/const.store";
-// import { useI18n } from "vue-i18n";
-// const t = useI18n()
-export default {
-  name: 'ListQuotation',
-  data() {
-    return {
-      fixDate,
-      HOST_URL,
-      active: 0,
-      isTopShow: false,
-      topTitle: this.$t('货币兑换'),
-      topValue: 2,
-      type: 'left' //left 从左往右 right 从有王座
-    }
-  },
 
-  props: {
-    showMore: {
-      type: Boolean,
-      default: true
-    },
-    listData: {
-      type: Array,
-      default() {
-        return []
-      }
-    },
-    tabActive: {
-      type: Number,
-      default: 0
-    },
+// 状态定义
+const isTopShow = ref(false);
+const topTitle = ref('');
+const topValue = ref(2);
+const type = ref('left');
+const active = ref(0);
+const showList = ref([]);
+
+// 依赖注入
+const store = useStore();
+const { t } = useI18n();
+const router = useRouter();
+
+// Props定义
+const props = defineProps({
+  showMore: {
+    type: Boolean,
+    default: true
   },
-  computed: {
-    ...mapGetters({ currency: 'home/currency' }),
+  listData: {
+    type: Array,
+    default: () => []
   },
-  components: {
-    [List.name]: List,
-    [Cell.name]: Cell,
-    ExTabs
-  }, mounted() {
-    this.SET_CURRENCY()
-  },
-  methods: {
-    ...mapActions('home', [SET_CURRENCY]),
-    changeType(tit, val) {
-      this.topTitle = tit
-      this.topValue = val
-      this.$emit('onfetchQList', val)
-    },
-    toggleDropdown() {
-      if (this.isTopShow) {
-        this.isTopShow = false
-      } else {
-        this.isTopShow = true
-      }
-    },
-    onItemClick(item) {
-      if (this.topValue == 2) { //现货
-        setStorage('symbol', item.symbol)
-        this.$router.push({
-          path: `/cryptos/perpetualContract/${item.symbol}`,
-          query: { selectIndex: 2 }
-        });
-      } else {
-        setStorage('symbol', item.symbol)
-        this.$router.push({
-          path: `/cryptos/trade/${item.symbol}`,
-        });
-      }
-    },
-    handleImage(url) {
-      return new URL(url, import.meta.url).href
-    },
-    onTabs(val) {
-      if (this.active < val) {
-        this.type = 'right'
-      } else {
-        this.type = 'left'
-      }
-      this.active = val
-      if (val == 0) {
-        this.showList = [...this.listData];
-      } else if (val == 1) {
-        this.showList = [...this.listData].sort(this.compare("change_ratio_str", 'up'))
-      } else if (val == 2) {
-        this.showList = [...this.listData].sort(this.compare("change_ratio_str", 'down'))
-      } else if (val == 3) {
-        this.showList = [...this.listData].sort(this.compare("volume", 'up'))
-      }
-    },
-    compare(p, type) { //这是比较函数
-      return function (m, n) {
-        var a = m[p];
-        var b = n[p];
-        if (a == b) {
-          return
-        }
-        if (type == 'up') {
-          return b - a; //升序
-        } else if (type == 'down') {
-          return a - b; //降序
-        } else {
-          return a - b;
-        }
-      }
-    }
-  },
-  watch: {
-    listData() {
-      if (this.active == 0) {
-        this.showList = [...this.listData];
-      } else if (this.active == 1) {
-        this.showList = [...this.listData].sort(this.compare("change_ratio_str", 'up'))
-      } else if (this.active == 2) {
-        this.showList = [...this.listData].sort(this.compare("change_ratio_str", 'down'))
-      } else if (this.active == 3) {
-        this.showList = [...this.listData].sort(this.compare("volume", 'up'))
-      }
-      this.$forceUpdate();
-    }
+  tabActive: {
+    type: Number,
+    default: 0
   }
-}
+});
+
+// Emits定义
+const emit = defineEmits(['onfetchQList']);
+
+// 计算属性
+const currency = computed(() => store.getters['home/currency']);
+
+// 生命周期
+onMounted(() => {
+  topTitle.value = t('货币兑换');
+  store.dispatch('home/' + SET_CURRENCY);
+  showList.value = [...props.listData];
+});
+
+// 方法定义
+const changeType = (tit, val) => {
+  topTitle.value = tit;
+  topValue.value = val;
+  emit('onfetchQList', val);
+};
+
+const toggleDropdown = () => {
+  isTopShow.value = !isTopShow.value;
+};
+
+const onItemClick = (item) => {
+  setStorage('symbol', item.symbol);
+  if (topValue.value === 2) {
+    router.push({
+      path: `/cryptos/perpetualContract/${item.symbol}`,
+      query: { selectIndex: 2 }
+    });
+  } else {
+    router.push({
+      path: `/cryptos/trade/${item.symbol}`
+    });
+  }
+};
+
+const handleImage = (url) => {
+  return new URL(url, import.meta.url).href;
+};
+
+const onTabs = (val) => {
+  type.value = active.value < val ? 'right' : 'left';
+  active.value = val;
+  sortListData(val);
+};
+
+const compare = (p, sortType) => {
+  return (m, n) => {
+    const a = m[p];
+    const b = n[p];
+    if (a === b) return 0;
+    return sortType === 'up' ? b - a : a - b;
+  };
+};
+
+const sortListData = (val) => {
+  switch(val) {
+    case 0:
+      showList.value = [...props.listData];
+      break;
+    case 1:
+      showList.value = [...props.listData].sort(compare('change_ratio_str', 'up'));
+      break;
+    case 2:
+      showList.value = [...props.listData].sort(compare('change_ratio_str', 'down'));
+      break;
+    case 3:
+      showList.value = [...props.listData].sort(compare('volume', 'up'));
+      break;
+  }
+};
+
+// 监听器
+watch(
+  () => props.listData,
+  () => {
+    sortListData(active.value);
+  },
+  { deep: true }
+);
 </script>
 <style lang="scss" scoped>
 @import "@/assets/init.scss";

--
Gitblit v1.9.3