index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <script lang="ts" setup>
  2. import couponBg from '@img/index/coupon-bg.png'
  3. import indexBg from '@img/index/index-bg.png'
  4. import { pathToBase64 } from 'image-tools'
  5. import { ref } from 'vue'
  6. import DiscountCoupon from '@/components/discountCoupon.vue'
  7. import SpendAndSaveCoupon from '@/components/spendAndSaveCoupon.vue'
  8. import { useTokenStore } from '@/store/token'
  9. defineOptions({
  10. name: 'Home',
  11. })
  12. definePage({
  13. // 使用 type: "home" 属性设置首页,其他页面不需要设置,默认为page
  14. type: 'home',
  15. style: {
  16. // 'custom' 表示开启自定义导航栏,默认 'default'
  17. navigationStyle: 'custom',
  18. navigationBarTitleText: '首页',
  19. },
  20. })
  21. const couponBgBase64 = ref(couponBg)
  22. const indexBgBase64 = ref(indexBg)
  23. const tokenStore = useTokenStore()
  24. const { hasLogin, wxLogin } = tokenStore
  25. console.log('hasLogin:', hasLogin)
  26. // 将图片路径转换为base64格式
  27. async function convertImageToBase64() {
  28. try {
  29. // 转换首页背景图
  30. indexBgBase64.value = await pathToBase64(indexBg)
  31. // 转换优惠券背景图
  32. couponBgBase64.value = await pathToBase64(couponBg)
  33. console.log('图片转换base64成功')
  34. }
  35. catch (error) {
  36. console.error('图片转换base64失败:', error)
  37. }
  38. }
  39. onLoad(async () => {
  40. console.log('测试 uni API 自动引入: onLoad')
  41. await convertImageToBase64()
  42. })
  43. // #ifdef MP-WEIXIN
  44. async function login() {
  45. await tokenStore.wxLogin()
  46. }
  47. // #endif
  48. // 顶部导航栏高度,设置banner位置
  49. const navigationBarHeight = ref(0)
  50. // #ifdef MP-WEIXIN
  51. function getNavigationBarHeight() {
  52. uni.getSystemInfo({
  53. success: (res) => {
  54. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  55. console.log('顶部导航栏高度:', res.statusBarHeight, menuButtonInfo)
  56. // 顶部导航栏高度 = 状态栏高度 + 胶囊的高度
  57. navigationBarHeight.value = res.statusBarHeight + menuButtonInfo.height + 12
  58. },
  59. })
  60. }
  61. getNavigationBarHeight()
  62. // #endif
  63. </script>
  64. <template>
  65. <view class="home-container">
  66. <!-- 顶部区域 -->
  67. <view class="home-header" :style="{ backgroundImage: `url('${indexBgBase64}')` }">
  68. <view class="home-header-avatar-info" :style="{ paddingTop: `${navigationBarHeight + 10}px` }">
  69. <view class="absolute left-5 z-1 text-xl c-white" :style="{ top: `${navigationBarHeight - 39}px` }">
  70. 券中心
  71. </view>
  72. <view class="home-header-balance">
  73. 我的收益(元)
  74. </view>
  75. <view class="home-header-balance-num">
  76. <view class="home-header-balance-num-amount">
  77. 7297491.08
  78. </view>
  79. </view>
  80. </view>
  81. <view class="home-header-tips">
  82. <view class="home-header-tips-item">
  83. <view class="home-header-tips-item-num">
  84. 115张
  85. </view>
  86. <view class="home-header-tips-item-des">
  87. 已核销
  88. </view>
  89. </view>
  90. <view class="home-header-tips-item">
  91. <view class="home-header-tips-item-num">
  92. 68张
  93. </view>
  94. <view class="home-header-tips-item-des">
  95. 未核销
  96. </view>
  97. </view>
  98. <view class="home-header-tips-item">
  99. <view class="home-header-tips-item-num">
  100. 68张
  101. </view>
  102. <view class="home-header-tips-item-des">
  103. 已发放
  104. </view>
  105. </view>
  106. </view>
  107. <view v-if="!hasLogin" class="home-hidden" @click="login">
  108. <image class="home-hidden-img" src="@img/index/lock.png" mode="scaleToFill" />
  109. <view class="home-hidden-text">
  110. 请登录,查看更多内容~
  111. </view>
  112. </view>
  113. </view>
  114. <!-- 满减券 -->
  115. <view class="home-header-coupon" :style="{ backgroundImage: `url('${couponBgBase64}')` }">
  116. <view class="home-header-coupon-title">
  117. <image class="home-header-coupon-title-icon" src="@img/index/icon1.png" mode="scaleToFill" />
  118. <view class="home-header-coupon-title-text">
  119. 满减券
  120. </view>
  121. <view class="home-header-coupon-title-des">
  122. 平台满减&nbsp;&nbsp;乐享不停
  123. </view>
  124. </view>
  125. <view class="home-header-coupon-content">
  126. <spend-and-save-coupon />
  127. <spend-and-save-coupon />
  128. <spend-and-save-coupon />
  129. </view>
  130. <view class="home-header-coupon-btn">
  131. <up-button class="home-header-coupon-btn-text" text="查看更多优惠券"
  132. color="linear-gradient(0deg, #FFE8CE 0%, #FBB8A0 100%)" />
  133. </view>
  134. </view>
  135. <!-- 折扣券 -->
  136. <view class="home-coupon">
  137. <view class="home-coupon-title">
  138. <image class="home-coupon-title-icon" src="@img/index/icon2.png" mode="scaleToFill" />
  139. <view class="home-coupon-title-text">
  140. 折扣券
  141. </view>
  142. <view class="home-coupon-title-des">
  143. 分享折扣&nbsp;&nbsp;立享优惠
  144. </view>
  145. <view class="home-coupon-title-more">
  146. <view class="home-coupon-title-more-text">
  147. 更多
  148. </view>
  149. <up-icon size="14" name="arrow-right" />
  150. </view>
  151. </view>
  152. <view class="home-coupon-content">
  153. <discount-coupon />
  154. <discount-coupon />
  155. <discount-coupon />
  156. </view>
  157. </view>
  158. </view>
  159. </template>
  160. <style lang="scss" scoped>
  161. .home-container {
  162. font-family: Alibaba PuHuiTi;
  163. min-height: 100vh;
  164. background-color: #f5f5f5;
  165. line-height: 1;
  166. position: relative;
  167. .home-header {
  168. height: 550rpx;
  169. // background-image: url('@img/index/index-bg.png');
  170. background-repeat: no-repeat;
  171. background-position: -80px top;
  172. background-size: 125% 200%;
  173. box-sizing: border-box;
  174. .home-header-avatar-info {
  175. display: flex;
  176. flex-direction: column;
  177. justify-content: center;
  178. text-align: center;
  179. gap: 30rpx;
  180. padding: 0 24rpx;
  181. .home-header-balance {
  182. font-weight: 400;
  183. font-size: 26rpx;
  184. color: #ffffff;
  185. }
  186. .home-header-balance-num {
  187. display: flex;
  188. justify-content: space-between;
  189. align-items: center;
  190. .home-header-balance-num-amount {
  191. width: 100%;
  192. font-weight: 500;
  193. font-size: 65rpx;
  194. color: #ffffff;
  195. }
  196. .home-header-balance-num-btns {
  197. display: flex;
  198. gap: 15rpx;
  199. .home-header-balance-num-btn {
  200. padding: 20rpx 40rpx;
  201. border-radius: 33rpx;
  202. font-weight: 400;
  203. font-size: 26rpx;
  204. &.js {
  205. background: #da4c47;
  206. color: #ffffff;
  207. }
  208. &.tx {
  209. background: #bfbfbf;
  210. color: #747474;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. .home-header-tips {
  217. height: 124rpx;
  218. display: flex;
  219. // background: linear-gradient(114deg, #f67873, #fb847f, #f67873);
  220. border-radius: 10rpx;
  221. margin: 47rpx 24rpx 0 24rpx;
  222. .home-header-tips-item {
  223. flex: 1;
  224. display: flex;
  225. flex-direction: column;
  226. justify-content: center;
  227. align-items: center;
  228. gap: 15rpx;
  229. font-weight: 500;
  230. font-size: 34rpx;
  231. color: #ffffff;
  232. line-height: 1;
  233. position: relative;
  234. &:not(:last-child):after {
  235. content: '';
  236. position: absolute;
  237. top: 50%;
  238. right: 0;
  239. transform: translateY(-50%);
  240. width: 2px;
  241. height: 40rpx;
  242. background: #ffffff;
  243. }
  244. .home-header-tips-item-num {
  245. font-weight: bold;
  246. }
  247. .home-header-tips-item-des {
  248. font-weight: 400;
  249. font-size: 24rpx;
  250. color: #ffffff;
  251. }
  252. }
  253. }
  254. .home-hidden {
  255. height: 550rpx;
  256. width: 100%;
  257. position: absolute;
  258. top: 0;
  259. right: 0;
  260. display: flex;
  261. flex-direction: column;
  262. justify-content: center;
  263. align-items: center;
  264. background-color: rgba(255, 255, 255, 0.1);
  265. backdrop-filter: blur(25rpx);
  266. -webkit-backdrop-filter: blur(25rpx);
  267. .home-hidden-img {
  268. width: 209rpx;
  269. height: 209rpx;
  270. object-fit: cover;
  271. }
  272. .home-hidden-text {
  273. font-weight: 400;
  274. font-size: 26rpx;
  275. color: #ffffff;
  276. margin-top: -25rpx;
  277. }
  278. }
  279. }
  280. // 优惠券
  281. .home-header-coupon {
  282. position: relative;
  283. background-repeat: no-repeat;
  284. background-position: right top;
  285. background-size: 100% auto;
  286. height: 419rpx;
  287. margin: -75rpx 20rpx 20rpx 20rpx;
  288. gap: 20rpx;
  289. padding: 28rpx 20rpx;
  290. .home-header-coupon-title {
  291. display: flex;
  292. flex-direction: row;
  293. .home-header-coupon-title-icon {
  294. width: 38rpx;
  295. height: 38rpx;
  296. object-fit: cover;
  297. margin-right: 13rpx;
  298. }
  299. .home-header-coupon-title-text {
  300. font-weight: 500;
  301. font-size: 30rpx;
  302. color: #333333;
  303. margin-right: 21rpx;
  304. }
  305. .home-header-coupon-title-des {
  306. display: inline-flex;
  307. align-items: center;
  308. font-size: 24rpx;
  309. font-weight: 400;
  310. color: #888888;
  311. }
  312. }
  313. .home-header-coupon-content {
  314. height: 238rpx;
  315. display: flex;
  316. flex-direction: row;
  317. align-items: flex-end;
  318. gap: 20rpx;
  319. }
  320. .home-header-coupon-btn {
  321. padding: 21rpx 70rpx 22px 69rpx;
  322. .home-header-coupon-btn-text {
  323. box-shadow: 0rpx 4rpx 7rpx 0rpx rgba(230, 77, 13, 0.17);
  324. border-radius: 37rpx;
  325. color: #651e03 !important;
  326. font-size: 26rpx;
  327. font-weight: 400;
  328. }
  329. }
  330. }
  331. // 折扣券
  332. .home-coupon {
  333. margin: -20rpx 20rpx 20rpx 20rpx;
  334. padding: 28rpx 20rpx;
  335. background-color: #ffffff;
  336. border-radius: 15rpx;
  337. .home-coupon-title {
  338. display: flex;
  339. flex-direction: row;
  340. .home-coupon-title-icon {
  341. width: 38rpx;
  342. height: 38rpx;
  343. object-fit: cover;
  344. margin-right: 13rpx;
  345. }
  346. .home-coupon-title-text {
  347. font-weight: 500;
  348. font-size: 30rpx;
  349. color: #333333;
  350. margin-right: 21rpx;
  351. }
  352. .home-coupon-title-des {
  353. display: inline-flex;
  354. align-items: center;
  355. font-size: 24rpx;
  356. font-weight: 400;
  357. color: #888888;
  358. }
  359. .home-coupon-title-more {
  360. margin-left: auto;
  361. display: flex;
  362. flex-direction: row;
  363. align-items: center;
  364. .home-coupon-title-more-text {
  365. font-weight: 400;
  366. font-size: 24rpx;
  367. color: #666666;
  368. height: 23rpx;
  369. line-height: 23rpx;
  370. }
  371. }
  372. }
  373. .home-coupon-content {
  374. padding-top: 28rpx;
  375. display: flex;
  376. flex-direction: column;
  377. gap: 20rpx;
  378. }
  379. }
  380. }
  381. </style>