index.vue 11 KB

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