home.vue 11 KB

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