home.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <view class="tab_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
  3. <up-navbar title=" " bgColor="transparent">
  4. <template #left>
  5. <view class="u-nav-slot" slot="left" style="display: flex;background-color: transparent;">
  6. <image src="https://oss.familydaf.cn/sxsnfile/20260105/087c26c68a18424c83763a768a2fd81d.png" style="width: 370rpx;height: 40rpx;"></image>
  7. </view>
  8. </template>
  9. </up-navbar>
  10. <image src="https://oss.familydaf.cn/sxsnfile/20251218/ee40161fef4647f0b736d118e554dc2f.png" class="top_bg_img" mode="widthFix"></image>
  11. <view class="c-box adffc">
  12. <view class="c-box-lunbo">
  13. <up-swiper
  14. :list="bannarList"
  15. @change="e => current = e.current"
  16. @click="bannerClick"
  17. :autoplay="true"
  18. :interval="2000"
  19. :duration="200"
  20. :circular="true"
  21. imgMode="scaleToFill"
  22. height="326rpx"
  23. >
  24. <template #indicator>
  25. <view class="indicator adf">
  26. <view class="indicator__dot" v-for="(item, index) in bannarList" :key="index"
  27. :class="[index === current && 'indicator__dot--active']">
  28. </view>
  29. </view>
  30. </template>
  31. </up-swiper>
  32. </view>
  33. <view class="c-box-title adfacjb">
  34. <view class="c-box-title-left">公益活动</view>
  35. <view class="c-box-title-right adfac" @click="toTurnPage('/pagesHome/allActivity',false)">更多 <up-icon name="arrow-right" size="30rpx" style="margin-left: 10rpx;"></up-icon></view>
  36. </view>
  37. <view class="c-box-type">
  38. <scroll-view class="scroll-view_H" scroll-x="true" scroll-with-animation="true" :scroll-left="scrollLeft">
  39. <view class="scroll-view-item_H" :id="'svih_'+index" v-for="(item,index) in typeList" :key="index" @click="changeType(item,index)">
  40. <view class="cl_item" :class="{'active':tlIndex===index}">
  41. <text>{{item.name}}</text>
  42. </view>
  43. </view>
  44. </scroll-view>
  45. </view>
  46. <view class="c-box-list" v-if="activityList.length">
  47. <up-list @scrolltolower="scrolltolower" style="height: 100%;">
  48. <up-list-item v-for="(item, index) in activityList" :key="item.id">
  49. <NonprofitActivety :item="item" :index="index"></NonprofitActivety>
  50. </up-list-item>
  51. </up-list>
  52. </view>
  53. <view class="dataEmpty" v-else>
  54. <page-empty></page-empty>
  55. </view>
  56. </view>
  57. <login-register></login-register>
  58. <CusTabbar :tabbarIndex="0"></CusTabbar>
  59. </view>
  60. </template>
  61. <script setup name="">
  62. import CusTabbar from '@/components/CusTabbar/index.vue'
  63. import NonprofitActivety from '@/components/pages/nonprofitActivety/index.vue'
  64. import PageEmpty from '@/components/pageEmpty/index.vue'
  65. import { ref, getCurrentInstance, onMounted, nextTick, watch } from 'vue'
  66. const { proxy } = getCurrentInstance()
  67. import { useUserStore } from '@/common/stores/user';
  68. const userStore = useUserStore();
  69. import { onLoad } from '@dcloudio/uni-app'
  70. const parseUrlParams = (url) => {
  71. const result = {}
  72. const queryStr = url.indexOf('?') !== -1 ? url.split('?')[1] : (url.indexOf('#') !== -1 ? url.split('#')[1] : '')
  73. if (!queryStr) return result
  74. queryStr.split('&').forEach(pair => {
  75. const [key, val] = pair.split('=')
  76. if (key) result[decodeURIComponent(key)] = decodeURIComponent(val || '')
  77. })
  78. return result
  79. }
  80. onLoad((options) => {
  81. console.log('[onLoad] options:', JSON.stringify(options))
  82. console.log('[onLoad] options.q:', options.q, '| typeof:', typeof options.q)
  83. console.log('[onLoad] 条件判断 options && options.q:', !!(options && options.q))
  84. if (options && options.q) {
  85. console.log('[onLoad] 进入 if 分支')
  86. const url = decodeURIComponent(options.q)
  87. console.log('[onLoad] 解码后 url:', url)
  88. const params = parseUrlParams(url)
  89. console.log('[onLoad] 解析参数:', JSON.stringify(params))
  90. const channelId = params.channel
  91. console.log('[onLoad] channelId:', channelId)
  92. if (!channelId) {
  93. console.log('[onLoad] channelId 为空,退出')
  94. return
  95. }
  96. const token = uni.getStorageSync('token')
  97. console.log('[onLoad] token:', token ? '有值' : '无值(未登录)')
  98. if (!token) return
  99. proxy.$api.post(`/channel/bind?channelId=${channelId}`, {}).then(({ data: res }) => {
  100. console.log('[onLoad] bind 结果:', JSON.stringify(res))
  101. if (res.code === 0) {
  102. uni.showToast({ title: '渠道加入成功', icon: 'success', duration: 2000 })
  103. } else {
  104. console.error('渠道绑定失败:', res.msg)
  105. }
  106. })
  107. }
  108. })
  109. const bannarList = ref([])
  110. const bannarOrigin = ref([])
  111. const current = ref(0)
  112. const typeList = ref([])
  113. const tlIndex = ref(0)
  114. const scrollLeft = ref(0)
  115. const isOver = ref(false)
  116. const activityList = ref([])
  117. const queryParams = ref({
  118. page:1,
  119. limit:10,
  120. categoryId:'',
  121. userId:''
  122. })
  123. const bannerClick = e => {
  124. let banner = bannarOrigin.value[e];
  125. if(banner&&banner?.redirect){
  126. if(banner?.redirectType==1){//微信公众号
  127. uni.navigateTo({
  128. url:'/pages/webView?src='+banner?.redirect
  129. })
  130. }else if(banner?.redirectType==2){//微信小程序
  131. uni.navigateToMiniProgram({
  132. appId:banner?.redirect
  133. })
  134. }
  135. }
  136. }
  137. const changeType = (item,index) => {
  138. queryParams.value.categoryId = item.id;
  139. tlIndex.value = index;
  140. // if(typeList.value.length>4){
  141. // if(index<3) scrollLeft.value = 0
  142. // else{
  143. // scrollLeft.value = (index-2)*172/2;
  144. // }
  145. // }
  146. initList();
  147. getActivityList();
  148. }
  149. const initList = () => {
  150. queryParams.value.page = 1;
  151. isOver.value = false;
  152. activityList.value = [];
  153. }
  154. const toTurnPage = (url,needLogin) => {
  155. if(!needLogin){
  156. uni.navigateTo({ url })
  157. }
  158. }
  159. const getSwiperList = () => {
  160. proxy.$api.get('/core/advertisement/manage/page',{page:1,limit:-1}).then(({data:res})=>{
  161. if(res.code!==0) return proxy.$showToast(res.msg)
  162. const list = res.data.list.filter(l=>l.enable==1);
  163. bannarOrigin.value = list;
  164. bannarList.value = list.map(l=>l.fileUrl);
  165. })
  166. }
  167. const getTypeList = () => {
  168. proxy.$api.get('/core/activity/category/list').then(({data:res})=>{
  169. if(res.code!==0) return proxy.$showToast(res.msg)
  170. typeList.value = [{id:'',name:'全部'},...res.data.map(d=>({id:d.id,name:d.categoryName}))];
  171. })
  172. }
  173. const scrolltolower = () => {
  174. if(isOver.value) return
  175. getActivityList()
  176. }
  177. const getActivityList = () => {
  178. proxy.$api.get('/core/activity/page',queryParams.value).then(({data:res})=>{
  179. if(res.code!==0) return proxy.$showToast(res.msg)
  180. activityList.value = [...activityList.value,...res.data.list];
  181. activityList.value.forEach(a=>{
  182. let cc = calculateCountdown(a?.signupEndTime);
  183. a.endTimeText = cc===-1?a?.signupEndTime:(`还有${cc.days}天${cc.hours}小时${cc.minutes}分钟`)
  184. a.signupEndTime = a.signupEndTime?new Date(a.signupEndTime).Format('yyyy.MM.dd hh:mm'):''
  185. })
  186. queryParams.value.page++;
  187. if(res.data.list.length===0) isOver.value = true;
  188. })
  189. }
  190. const calculateCountdown = (datetime) => {
  191. if(!datetime) return -1;
  192. const targetDate = new Date(datetime);
  193. const now = new Date();
  194. const difference = targetDate.getTime() - now.getTime();
  195. if (difference <= 0) return -1;
  196. const days = Math.floor(difference / (1000 * 60 * 60 * 24));
  197. const hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  198. const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
  199. return {
  200. days,
  201. hours,
  202. minutes
  203. };
  204. }
  205. watch(()=>userStore.token,(newVal,oldVal)=>{
  206. if(oldVal!=newVal&&newVal){
  207. setTimeout(()=>{
  208. uni.showToast({
  209. title: '登录成功',
  210. icon: 'success'
  211. });
  212. },200)
  213. nextTick(()=>{
  214. getActivityList()
  215. })
  216. }
  217. })
  218. onMounted(()=>{
  219. if(uni.getStorageSync('userInfo')){
  220. queryParams.value.userId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
  221. }
  222. getSwiperList()
  223. getTypeList()
  224. getActivityList()
  225. })
  226. </script>
  227. <style scoped lang="scss">
  228. ::v-deep .indicator__dot{
  229. width: 48rpx;
  230. height: 4rpx;
  231. background: #E2E5E9;
  232. border-radius: 2rpx;
  233. margin: 0 8rpx;
  234. }
  235. ::v-deep .indicator__dot--active{
  236. width: 48rpx;
  237. height: 4rpx;
  238. background: #00AE57;
  239. border-radius: 2rpx;
  240. }
  241. ::v-deep .u-swiper__wrapper__item__wrapper__image{
  242. border-radius: 24rpx !important;
  243. }
  244. .scroll-view_H {
  245. white-space: nowrap;
  246. width: 100%;
  247. }
  248. .scroll-view-item_H {
  249. display: inline-block;
  250. // width: 152rpx;
  251. height: 100%;
  252. margin-left: 20rpx;
  253. &:first-child{
  254. margin-left: 0;
  255. }
  256. }
  257. .tab_page{
  258. .c-box{
  259. width: 100%;
  260. height: 100%;
  261. overflow-y: auto;
  262. position: relative;
  263. &-lunbo{
  264. width: 100%;
  265. height: 326rpx;
  266. margin-top: 20rpx;
  267. }
  268. &-title{
  269. margin-top: 58rpx;
  270. &-left{
  271. width: 170rpx;
  272. height: 44rpx;
  273. padding-left: 2rpx;
  274. font-family: PingFang-SC, PingFang-SC;
  275. font-weight: 800;
  276. font-size: 36rpx;
  277. color: #151B29;
  278. line-height: 36rpx;
  279. background-image: url('https://oss.familydaf.cn/sxsnfile/20251218/6198fa26a7ff4fc1bce530fbdfaa20db.png');
  280. background-size: 170rpx 31rpx;
  281. background-position: 0 20rpx;
  282. background-repeat: no-repeat;
  283. }
  284. &-right{
  285. font-family: PingFangSC, PingFang SC;
  286. font-weight: 400;
  287. font-size: 28rpx;
  288. color: #676775;
  289. line-height: 33rpx;
  290. }
  291. }
  292. &-type{
  293. width: 100%;
  294. height: 68rpx;
  295. margin-top: 31rpx;
  296. .cl_item{
  297. // width: 152rpx;
  298. padding: 0 21rpx;
  299. height: 68rpx;
  300. background: #FFFFFF;
  301. border-radius: 34rpx;
  302. font-family: PingFangSC, PingFang SC;
  303. font-weight: 400;
  304. font-size: 28rpx;
  305. color: #676775;
  306. line-height: 68rpx;
  307. text-align: center;
  308. &.active{
  309. background: #B7F358;
  310. font-weight: bold;
  311. font-size: 30rpx;
  312. color: #151B29;
  313. }
  314. }
  315. }
  316. &-list{
  317. width: 100%;
  318. flex: 1;
  319. overflow-y: auto;
  320. margin-top: 20rpx;
  321. }
  322. }
  323. }
  324. </style>