index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <template>
  2. <div class="container">
  3. <div class="head-bg" />
  4. <div class="head-nav-bar">{{$t("dapp.Exploration")}}</div>
  5. <div class="search-box">
  6. <svg-icon class="search-icon" name="search" />
  7. <van-field v-model="searchValue" :placeholder="$t('dapp.EnterTheNameOrURLOfTheDApp')" />
  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="$t('dapp.All')" 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 + $t('dapp.ApplicationsOnTheChain') }}
  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 + $t('dapp.ApplicationsOnTheChain') }}
  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: $t('dapp.HotRecommendation'),
  146. children: [],
  147. },
  148. {
  149. title: $t('dapp.BrowsingHistory'),
  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. oaid:systemStore.DeviceId
  217. })
  218. );
  219. openDapp(item.url, { dapp });
  220. };
  221. const loadHistoryList = () => {
  222. const history = systemStore.DAPP_CACHE_KEY;
  223. tabsAppConfig.value[1].children = history;
  224. };
  225. onMounted(async () => {
  226. getdappSlides();
  227. gethotlist();
  228. getdappList();
  229. loadHistoryList(); // 加载浏览记录
  230. });
  231. </script>
  232. <style lang="less" scoped>
  233. .container {
  234. height: calc(100vh - 50px);
  235. overflow: hidden;
  236. }
  237. .container::-webkit-scrollbar {
  238. width: 0;
  239. }
  240. .head-bg {
  241. .fn-head-bg();
  242. }
  243. .head-nav-bar {
  244. width: 100%;
  245. height: 26px;
  246. display: flex;
  247. justify-content: center;
  248. margin-top: 40px;
  249. font-weight: 500;
  250. font-size: 19px;
  251. color: #000000;
  252. }
  253. .search-box {
  254. flex: 1;
  255. display: flex;
  256. align-items: center;
  257. height: 33px;
  258. margin: 15px 17px 0 17px;
  259. border-radius: 23px 23px 23px 23px;
  260. background-color: #e3edfd;
  261. color: #95a9ed;
  262. .search-icon {
  263. height: 25px;
  264. width: 25px;
  265. margin-left: 6px;
  266. }
  267. :deep(.van-cell) {
  268. flex: 1;
  269. font-size: 15px;
  270. margin: 0 6px;
  271. padding: 0 !important;
  272. background: #e3edfd !important;
  273. line-height: 25px !important;
  274. width: initial !important;
  275. box-sizing: border-box;
  276. }
  277. :deep(.van-field__control) {
  278. color: #95a9ed !important;
  279. }
  280. :deep(.van-field__control::placeholder) {
  281. color: #95a9ed;
  282. }
  283. }
  284. .swipe-box {
  285. height: 180px;
  286. margin: 17px 17px 0 17px;
  287. border-radius: 17px 17px 17px 17px;
  288. .swipe-item {
  289. height: 160px;
  290. width: 100%;
  291. border-radius: 17px 17px 17px 17px;
  292. overflow: hidden;
  293. }
  294. .swipe-image {
  295. height: 160px;
  296. width: 100%;
  297. }
  298. .custom-indicator {
  299. position: absolute;
  300. right: 5px;
  301. bottom: 0px;
  302. width: 100%;
  303. display: flex;
  304. justify-content: center;
  305. align-items: flex-end;
  306. .active {
  307. background: @theme-color1;
  308. }
  309. }
  310. .custom-indicator-item {
  311. display: flex;
  312. width: 15px;
  313. height: 2px;
  314. background: @theme-color2;
  315. border-radius: 5px 5px 5px 5px;
  316. margin: 0 2px;
  317. }
  318. }
  319. .tabs-wrapper-card {
  320. height: 130px;
  321. margin-top: 40px;
  322. :deep(.van-tabs__nav) {
  323. padding: 3px;
  324. background: #f2f2f2;
  325. border: 0px;
  326. }
  327. :deep(.van-tabs__nav--card) {
  328. border-radius: 32px 32px 32px 32px;
  329. }
  330. :deep(.van-tab--active) {
  331. border-radius: 32px 32px 32px 32px;
  332. color: @theme-color1 !important;
  333. background-color: @bg-color1;
  334. }
  335. :deep(.van-tab--card) {
  336. color: @font-color2;
  337. border-right: 0px;
  338. }
  339. }
  340. .tabs-content-body {
  341. display: flex;
  342. width: 100%;
  343. padding: 20px 0 0 17px;
  344. overflow: auto;
  345. box-sizing: border-box;
  346. .tabs-content-item {
  347. display: flex;
  348. flex-direction: column;
  349. align-items: center;
  350. width: 50px;
  351. min-width: 50px;
  352. font-size: 12px;
  353. margin-right: 26px;
  354. span {
  355. margin-top: 4px;
  356. }
  357. .tabs-content-item-icon {
  358. width: 42px;
  359. height: 42px;
  360. }
  361. }
  362. }
  363. .tabs-content-body::-webkit-scrollbar {
  364. height: 0;
  365. }
  366. .tabs-wrapper {
  367. padding: 0 12px;
  368. :deep(.van-tabs__nav) {
  369. background: transparent;
  370. }
  371. :deep(.van-tab) {
  372. border-bottom: 1px solid #d8d8d8;
  373. }
  374. :deep(.van-tabs__line) {
  375. height: 1px;
  376. width: 58px;
  377. }
  378. :deep(.van-tabs__wrap) {
  379. height: 30px;
  380. }
  381. :deep(.van-tab--active) {
  382. color: @theme-color1;
  383. }
  384. :deep(.van-tabs__line) {
  385. background: @theme-color1 !important;
  386. }
  387. .tab-box {
  388. padding: 16px 10px 0px;
  389. height: calc(100vh - 590px);
  390. overflow-y: auto;
  391. &::-webkit-scrollbar {
  392. display: none;
  393. }
  394. .tab-box-label {
  395. font-family:
  396. PingFang SC,
  397. PingFang SC;
  398. font-weight: 500;
  399. font-size: 15px;
  400. color: #000000;
  401. margin-bottom: 12px;
  402. }
  403. .tab-box-list {
  404. display: flex;
  405. margin-bottom: 17px;
  406. align-items: center;
  407. .tab-box-list-img {
  408. width: 42px;
  409. height: 42px;
  410. margin-right: 9px;
  411. flex-shrink: 0;
  412. }
  413. .tab-box-ri {
  414. font-family:
  415. PingFang SC,
  416. PingFang SC;
  417. font-weight: 500;
  418. font-size: 15px;
  419. color: @font-color2;
  420. .hot-icon {
  421. width: 15px;
  422. height: 15px;
  423. margin-right: 4px;
  424. position: relative;
  425. top: -3px;
  426. }
  427. .rm-icon {
  428. width: 33px;
  429. height: 15px;
  430. }
  431. .tab-box-ri-cont {
  432. margin-top: 3px;
  433. font-weight: 400;
  434. font-size: 12px;
  435. color: #8d8d8d;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. </style>