index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <div class="container">
  3. <div class="tab-box">
  4. <div class="tab-box-text"
  5. :class="tabIndex == i?'active-border':''"
  6. v-for="(item,i) in tabList" :key="i" @click="tabIndex = i"
  7. >
  8. <van-image class="tab-box-icon" round :src="item.img"/>
  9. <text>{{item.name}}</text>
  10. </div>
  11. </div>
  12. <div class="content">
  13. <Draggable v-model="items" item-key="id">
  14. <template #item="{ element }">
  15. <div class="sort-box">
  16. <div class="sort-title">
  17. <div>{{ element.name }}</div>
  18. <svg-icon class="sort-icon" name="px" />
  19. </div>
  20. <div class="card-box" :class="element.id == walletStore.id?'active-border':''">
  21. <div class="card-box-lf">
  22. <van-image class="card-box-lf-icon" round :src="element.img"/>
  23. <div class="card-box-lf-text">
  24. <div>{{ element.name }}</div>
  25. <div class="address">
  26. <span>{{ short(element.address) }}</span>
  27. <svg-icon class="im-copy-btn" name="copy" style="width:16px;height:16px;margin-left:2px" :data-clipboard-text="element.address"/>
  28. </div>
  29. </div>
  30. </div>
  31. <svg-icon name="bj" style="width:16px;height:16px;color:#4F4F4F" @click="goToPage(element.id)"/>
  32. </div>
  33. </div>
  34. </template>
  35. </Draggable>
  36. </div>
  37. </div>
  38. </template>
  39. <script setup>
  40. import Draggable from 'vuedraggable';
  41. import { useWalletStore } from '@/stores/modules/walletStore';
  42. import { useRouter } from 'vue-router'
  43. import { useCopy } from "@/hooks/use-copy.js";
  44. useCopy();
  45. const walletStore = useWalletStore();
  46. const router = useRouter();
  47. const tabList = [
  48.   { name: 'ACC', img: 'https://wallet.angeltokens.io/storage/images/acc.svg' },
  49. { name: 'Ethereum', img: 'https://wallet.angeltokens.io/storage/images/eth.svg' },
  50.   { name: 'BNB', img: 'https://wallet.angeltokens.io/storage/images/bsc.svg' }
  51. ];
  52. const tabIndex = ref(0);
  53. /* 地址缩写 */
  54. const short = (addr) =>
  55. addr ? addr.slice(0, 6) + '...' + addr.slice(-6) : '';
  56. /* 核心:带 setter 的 computed */
  57. const items = computed({
  58. /* getter:根据当前 tab 过滤 */
  59. get() {
  60. const currName = tabList[tabIndex.value].name;
  61. return walletStore.walletList
  62. .filter(w => w.accountName === currName)
  63. .map(w => ({
  64. id: w.id,
  65. name: w.username,
  66. img: w.avatar,
  67. address: w.account,
  68. _raw: w, // 保留原始对象引用,更新时用
  69. }));
  70. },
  71. /* setter:拖拽后新顺序 -> 回写 Pinia */
  72. set(newOrder) {
  73. const currName = tabList[tabIndex.value].name;
  74. // 取出其他币种保持原顺序
  75. const others = walletStore.walletList.filter(
  76. w => w.accountName !== currName
  77. );
  78. // 新顺序的新数组(去掉临时字段 _raw)
  79. const reordered = newOrder.map(o => o._raw);
  80. // 合并并回写
  81. walletStore.walletList = [...others, ...reordered];
  82. // 有 pinia-plugin-persist 时,这一句可省;否则手动持久化
  83. walletStore.$persist?.();
  84. },
  85. });
  86. const goToPage = (id) => {
  87. router.push({
  88. path: 'walletDetail',
  89. query:{
  90. id
  91. }
  92. })
  93. }
  94. </script>
  95. <style scoped lang="less">
  96. .container{
  97. height: 100%;
  98. display: flex;
  99. flex-direction: column;
  100. }
  101. .content{
  102. flex: 1;
  103. display: flex;
  104. flex-direction: column;
  105. overflow: auto;
  106. }
  107. .content::-webkit-scrollbar{
  108. width: 0;
  109. }
  110. .tab-box{
  111. margin: 16px 16px 24px;
  112. display: flex;
  113. align-items: center;
  114. .tab-box-text{
  115. border-radius: 27px;
  116. border: 1px solid #8D8D8D;
  117. display: flex;
  118. align-items: center;
  119. padding: 6px 8px;
  120. margin-right: 10px;
  121. font-family: PingFang SC, PingFang SC;
  122. font-weight: 400;
  123. font-size: 15px;
  124. color: #8D8D8D;
  125. .tab-box-icon{
  126. width: 20px;
  127. height: 20px;
  128. margin-right: 4px;
  129. }
  130. }
  131. .active-border{
  132. border: 1px solid #000000;
  133. color: #000000;
  134. }
  135. }
  136. .sort-box{
  137. padding: 0 16px;
  138. margin-bottom: 17px;
  139. cursor: move;
  140. .sort-title{
  141. display: flex;
  142. align-items: center;
  143. justify-content: space-between;
  144. font-family: PingFang SC, PingFang SC;
  145. font-weight: 500;
  146. font-size: 12px;
  147. color: #4F4F4F;
  148. margin-bottom: 6px;
  149. .sort-icon{
  150. width: 16px;
  151. height: 16px;
  152. }
  153. }
  154. .card-box{
  155. background: #F2F2F2;
  156. border-radius: 8px;
  157. border: 1px solid #D8D8D8;
  158. padding: 16px 42px 16px 16px;
  159. display: flex;
  160. align-items: center;
  161. justify-content: space-between;
  162. .card-box-lf{
  163. display: flex;
  164. align-items: center;
  165. .card-box-lf-icon{
  166. width: 30px;
  167. height: 30px;
  168. margin-right: 8px;
  169. }
  170. .card-box-lf-text{
  171. font-family: PingFang SC, PingFang SC;
  172. font-weight: 400;
  173. font-size: 15px;
  174. color: #000000;
  175. .address{
  176. font-size: 12px;
  177. color: #8D8D8D;
  178. display: flex;
  179. align-items: center;
  180. }
  181. }
  182. }
  183. }
  184. .active-border{
  185. border: 1px solid @theme-color1;
  186. }
  187. }
  188. </style>