index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <route lang="json">
  2. {
  3. "style": {
  4. "navigationBarTitleText": "我的荣誉",
  5. "navigationStyle": "custom"
  6. }
  7. }
  8. </route>
  9. <script setup lang="ts">
  10. import NavbarEvo from '@/components/navbar-evo.vue'
  11. import Card from '@/components/card.vue'
  12. import SectionHeading from '@/components/section-heading.vue'
  13. import {
  14. getBadges,
  15. getCertificates,
  16. getHonorStatistics,
  17. getListCollectionBadge,
  18. } from '../../../core/libs/requests'
  19. import { useRouter } from '../../../core/utils/router'
  20. import arcBottom from '@designer-hub/assets/src/libs/assets/arcBottom'
  21. import { NetImages } from '../../../core/libs/net-images'
  22. import ProgressEvo from '@/components/progress-evo.vue'
  23. import { Certificate } from '@/core/libs/models'
  24. import dayjs from 'dayjs'
  25. import { useUserStore } from '@/store'
  26. import { storeToRefs } from 'pinia'
  27. const id = ref()
  28. const isShared = ref(false)
  29. const router = useRouter()
  30. const userStore = useUserStore()
  31. const { userInfo } = storeToRefs(userStore)
  32. const active = ref('badge')
  33. const autoplay = ref<boolean>(false)
  34. const tabs = ref([
  35. { label: '徽章', value: 'badge' },
  36. { label: '证书', value: 'certificate' },
  37. ])
  38. const { data: statistics, run: setStatistics } = useRequest(() =>
  39. getHonorStatistics({ userId: id.value }),
  40. )
  41. const { data: badges, run: setBadges } = useRequest(() => getBadges({ userId: id.value }), {
  42. initialData: {},
  43. })
  44. const { data: collectionBadges, run: setCollectionBadges } = useRequest(
  45. () => getListCollectionBadge({ userId: id.value }),
  46. { initialData: [] },
  47. )
  48. const { data: certificates, run: setCertificates } = useRequest(
  49. () => getCertificates({ userId: id.value }),
  50. {
  51. initialData: [],
  52. },
  53. )
  54. const save = async (filePath: string) => {
  55. uni.downloadFile({
  56. url: filePath, // 下载资源的网络地址
  57. success: (res) => {
  58. if (res.statusCode === 200) {
  59. uni.saveImageToPhotosAlbum({
  60. filePath: res.tempFilePath, // 临时文件路径
  61. success: () => {
  62. uni.showToast({ title: '已保存相册', icon: 'none' })
  63. },
  64. fail: (err) => {
  65. uni.showToast({
  66. title: '保存失败',
  67. icon: 'none',
  68. })
  69. },
  70. })
  71. }
  72. },
  73. fail: (err) => {
  74. uni.showToast({
  75. title: '下载失败',
  76. icon: 'none',
  77. })
  78. },
  79. })
  80. }
  81. const handleSwiperChange = (e: any) => {
  82. console.log(e)
  83. }
  84. const handleGetCondition = (badge: any) => {
  85. uni.navigateTo({
  86. url: `/pages/mine/honors/detail/collection?id=${badge}`,
  87. })
  88. }
  89. const handleGetBadge = (badge: any) => {
  90. uni.navigateTo({
  91. url: `/pages/mine/honors/leaderboard/index?id=${badge}`,
  92. })
  93. }
  94. const currentCertificate = ref<Certificate | undefined>()
  95. const isOwner = computed(() => String(userInfo.value?.userId) === id.value)
  96. onLoad(async (query?: Record<string | 'active' | 'id' | 'isShared', string>) => {
  97. console.log('query:::::', query)
  98. if (Object.keys(query).length !== 0) {
  99. if (query?.active) {
  100. active.value = query.active
  101. }
  102. if (query?.id) {
  103. id.value = query.id
  104. }
  105. if (query?.isShared) {
  106. isShared.value = true
  107. }
  108. }
  109. await setStatistics()
  110. await setBadges()
  111. await setCertificates()
  112. await setCollectionBadges()
  113. })
  114. </script>
  115. <template>
  116. <div class="flex-grow bg-gradient-to-b from-[#181614] to-[#0f0f0f] flex flex-col gap-4 p-3.5">
  117. <div class="aspect-[1.63/1] m--3.5 overflow-hidden relative">
  118. <wd-img width="100%" mode="widthFix" :src="NetImages.HonorsHeader"></wd-img>
  119. <div class="absolute left-7 bottom-6.5">
  120. <div
  121. class="text-white text-3xl font-bold font-['Alimama_ShuHeiTi'] leading-relaxed pr-2.5"
  122. style="
  123. background: linear-gradient(92deg, #fff 0.4%, #ffebb2 107.42%);
  124. -webkit-background-clip: text;
  125. background-clip: text;
  126. -webkit-text-fill-color: transparent;
  127. "
  128. >
  129. 荣誉主页
  130. </div>
  131. <div class="mt-4 flex justify-between">
  132. <template
  133. v-for="(it, i) in [
  134. { label: '获得徽章', value: statistics?.badgeCount, unit: '枚' },
  135. { label: '获得证书', value: statistics?.certCount, unit: '个' },
  136. ]"
  137. :key="i"
  138. >
  139. <div class="flex flex-col items-center gap-1.25">
  140. <div
  141. class="text-center text-[#f6e8da]/80 text-xs font-normal font-['PingFang_SC'] leading-snug"
  142. >
  143. {{ it.label }}
  144. </div>
  145. <div class="flex items-end gap-1">
  146. <div
  147. class="text-center text-white text-2xl font-medium font-['D-DIN-PRO'] leading-6"
  148. >
  149. {{ it.value }}
  150. </div>
  151. <div
  152. class="text-center text-[#f6e8da]/80 text-xs font-normal font-['PingFang_SC'] leading-snug"
  153. >
  154. {{ it.unit }}
  155. </div>
  156. </div>
  157. </div>
  158. </template>
  159. </div>
  160. </div>
  161. </div>
  162. <NavbarEvo dark fixed transparent></NavbarEvo>
  163. <!-- <wd-tabs v-model="active">
  164. <template v-for="(it, i) in tabs" :key="i">
  165. <wd-tab :title="it.label" :name="it.value"></wd-tab>
  166. </template>
  167. </wd-tabs> -->
  168. <div class="flex items-center justify-around">
  169. <template v-for="(it, i) in tabs" :key="i">
  170. <div class="flex flex-col items-center gap-1" @click="active = it.value">
  171. <div
  172. class="text-center font-normal font-['PingFang_SC']"
  173. :class="`${it.value === active ? 'text-white text-lg leading-relaxed ' : 'text-white/60 text-base leading-normal'}`"
  174. >
  175. {{ it.label }}
  176. </div>
  177. <wd-img v-if="it.value === active" width="17" height="5.6" :src="arcBottom"></wd-img>
  178. </div>
  179. </template>
  180. </div>
  181. <template v-if="active === 'badge'">
  182. <view class="h-[145px]" v-if="String(userInfo.userId) === id">
  183. <swiper :autoplay="autoplay" @change="handleSwiperChange">
  184. <swiper-item v-for="item in collectionBadges" :key="item.id">
  185. <Card custom-class="border border-solid bg-[#25221f]! border-[rgba(255,236,185,0.20)]">
  186. <div class="grid grid-cols-[90px_1fr] gap-x-4">
  187. <div class="grid-row-start-1 grid-row-end-4 col-start-1">
  188. <wd-img
  189. width="90"
  190. height="90"
  191. :src="
  192. item.userSize === item.badgeSize
  193. ? item.badgeYesObtainedImage
  194. : item.badgeNotObtainedImage
  195. "
  196. ></wd-img>
  197. </div>
  198. <div class="row-start-1 col-start-2 flex items-center justify-between">
  199. <div
  200. class="text-center text-[#ffecb9] text-lg font-normal font-['PingFang_SC'] leading-relaxed"
  201. >
  202. {{ item.badgeName }}
  203. </div>
  204. <div
  205. class="h-[26px] px-2.5 rounded-[30px] border border-solid border-[#ffecb9] justify-center items-center gap-2.5 inline-flex"
  206. >
  207. <div
  208. class="text-center text-[#ffecb9] text-xs font-normal font-['PingFang_SC'] leading-relaxed"
  209. @click="handleGetCondition(item.id)"
  210. >
  211. 获取条件
  212. </div>
  213. </div>
  214. </div>
  215. <div class="row-start-2 col-start-2">
  216. <div
  217. class="text-start text-white/60 text-xs font-normal font-['PingFang_SC'] leading-relaxed"
  218. >
  219. {{ item.badgeDescription }}
  220. </div>
  221. </div>
  222. <div class="row-start-3 col-start-2 flex items-center gap-4">
  223. <div class="flex-1">
  224. <ProgressEvo
  225. :height="5"
  226. :model-value="
  227. (
  228. Number.parseInt(item.userSize as any) /
  229. Number.parseInt(item.badgeSize as any)
  230. ).toFixed(2) * 100
  231. "
  232. color="linear-gradient(90deg, #FFDA72 0%, #FFECB9 100%)"
  233. ></ProgressEvo>
  234. </div>
  235. <div>
  236. <span class="text-white text-xs font-normal font-['PingFang_SC'] leading-none">
  237. {{ item.userSize }}
  238. </span>
  239. <span
  240. class="text-[#a1a1a1] text-xs font-normal font-['PingFang_SC'] leading-none"
  241. >
  242. /{{ item.badgeSize }}
  243. </span>
  244. </div>
  245. </div>
  246. <div class="row-start-4 col-start-1 flex items-center justify-center">
  247. <div
  248. class="w-[59px] h-[21px] px-2.5 bg-[#524c3b] rounded-[30px] shadow shadow-inner justify-center items-center gap-0.5 inline-flex"
  249. >
  250. <div
  251. class="text-center text-[#ffecb9] text-[10px] font-normal font-['PingFang_SC'] leading-relaxed"
  252. @click="handleGetBadge(item.id)"
  253. >
  254. 获取榜
  255. </div>
  256. </div>
  257. </div>
  258. </div>
  259. </Card>
  260. </swiper-item>
  261. </swiper>
  262. </view>
  263. <template v-for="([key, it], index) in Object.entries(badges)" :key="index">
  264. <Card
  265. v-if="!((!isOwner || isShared) && ['积分徽章', '积分徽章'].includes(key))"
  266. custom-class="bg-[#171615]! text-white border border-solid border-[rgba(255,236,185,0.20)]"
  267. >
  268. <div class="flex items-center gap-2 py-4">
  269. <div class="w-1.5 h-1.5 bg-[#ffecb9] rounded-full"></div>
  270. <SectionHeading :title="key.toString()" dark></SectionHeading>
  271. </div>
  272. <div class="grid grid-cols-3 gap-y-6">
  273. <template v-for="(item, i) in it" :key="i">
  274. <div
  275. class="w-full px-4 box-border"
  276. @click="
  277. router.push(
  278. `/pages/mine/honors/detail/index?type=badge&data=${JSON.stringify(item)}`,
  279. )
  280. "
  281. >
  282. <wd-img
  283. width="100%"
  284. mode="widthFix"
  285. :src="item.quantity ? item.badgeYesObtainedImage : item.badgeNotObtainedImage"
  286. ></wd-img>
  287. <div
  288. class="text-center text-white text-xs font-normal font-['PingFang_SC'] leading-relaxed"
  289. >
  290. {{ item.badgeName }}
  291. </div>
  292. </div>
  293. </template>
  294. </div>
  295. <!-- {{ it }} -->
  296. </Card>
  297. </template>
  298. </template>
  299. <template v-if="active === 'certificate'">
  300. <div>
  301. <div class="grid grid-cols-2 gap-2.5">
  302. <template v-for="(it, i) in certificates" :key="i">
  303. <div class="aspect-[1.35/1]" @click="currentCertificate = it">
  304. <wd-img
  305. width="100%"
  306. height="100%"
  307. :src="it.certificateImage"
  308. mode="aspectFill"
  309. custom-class="vertical-bottom"
  310. ></wd-img>
  311. </div>
  312. </template>
  313. </div>
  314. </div>
  315. </template>
  316. <wd-overlay :show="currentCertificate !== undefined" @click="currentCertificate = undefined">
  317. <div class="h-full flex flex-col items-center justify-around">
  318. <div class="flex flex-col">
  319. <wd-img
  320. width="85vw"
  321. height="94vw"
  322. :src="currentCertificate?.certificateImage"
  323. mode="aspectFit"
  324. ></wd-img>
  325. <div
  326. class="text-center text-white text-xl font-normal font-['PingFang_SC'] uppercase mt-7"
  327. >
  328. {{ currentCertificate?.certificateName }}
  329. </div>
  330. <div class="flex center gap-3">
  331. <div class="w-3.5 h-[1.5px] bg-white"></div>
  332. <div class="text-center text-white text-sm font-normal font-['PingFang_SC'] uppercase">
  333. <!-- 2024年10月2日获得-->
  334. {{ dayjs(currentCertificate?.createTime).format('YYYY年MM月DD日') }}获得
  335. </div>
  336. <div class="w-3.5 h-[1.5px] bg-white"></div>
  337. </div>
  338. </div>
  339. <wd-button custom-class="bg-[#0CBE7D]!" @click="save(currentCertificate?.certificateImage)">
  340. 保存到本地
  341. </wd-button>
  342. </div>
  343. </wd-overlay>
  344. </div>
  345. </template>