home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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">
  13. <cus-search @handleSearch="toSearch"></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 = (keyword) => {
  128. if (!keyword) return
  129. uni.navigateTo({ url: '/pagesHome/allActivity?keyword=' + encodeURIComponent(keyword) })
  130. }
  131. const bannerClick = e => {
  132. let banner = bannarOrigin.value[e];
  133. if(banner&&banner?.redirect){
  134. if(banner?.redirectType==1){//微信公众号
  135. uni.navigateTo({
  136. url:'/pages/webView?src='+banner?.redirect
  137. })
  138. }else if(banner?.redirectType==2){//微信小程序
  139. uni.navigateToMiniProgram({
  140. appId:banner?.redirect
  141. })
  142. }
  143. }
  144. }
  145. const changeType = (item,index) => {
  146. queryParams.value.categoryId = item.id;
  147. tlIndex.value = index;
  148. // if(typeList.value.length>4){
  149. // if(index<3) scrollLeft.value = 0
  150. // else{
  151. // scrollLeft.value = (index-2)*172/2;
  152. // }
  153. // }
  154. initList();
  155. getActivityList();
  156. }
  157. const initList = () => {
  158. queryParams.value.page = 1;
  159. isOver.value = false;
  160. activityList.value = [];
  161. }
  162. const toTurnPage = (url,needLogin) => {
  163. if(!needLogin){
  164. uni.navigateTo({ url })
  165. }
  166. }
  167. const getSwiperList = () => {
  168. proxy.$api.get('/core/advertisement/manage/page',{page:1,limit:-1}).then(({data:res})=>{
  169. if(res.code!==0) return proxy.$showToast(res.msg)
  170. const list = res.data.list.filter(l=>l.enable==1);
  171. bannarOrigin.value = list;
  172. bannarList.value = list.map(l=>l.fileUrl);
  173. })
  174. }
  175. const getTypeList = () => {
  176. proxy.$api.get('/core/activity/category/list').then(({data:res})=>{
  177. if(res.code!==0) return proxy.$showToast(res.msg)
  178. typeList.value = [{id:'',name:'全部'},...res.data.map(d=>({id:d.id,name:d.categoryName}))];
  179. })
  180. }
  181. const scrolltolower = () => {
  182. if(isOver.value) return
  183. getActivityList()
  184. }
  185. const getActivityList = () => {
  186. proxy.$api.get('/core/activity/page',queryParams.value).then(({data:res})=>{
  187. if(res.code!==0) return proxy.$showToast(res.msg)
  188. activityList.value = [...activityList.value,...res.data.list];
  189. activityList.value.forEach(a=>{
  190. let cc = calculateCountdown(a?.signupEndTime);
  191. a.endTimeText = cc===-1?a?.signupEndTime:(`还有${cc.days}天${cc.hours}小时${cc.minutes}分钟`)
  192. a.signupEndTime = a.signupEndTime?new Date(a.signupEndTime).Format('yyyy.MM.dd hh:mm'):''
  193. })
  194. queryParams.value.page++;
  195. if(res.data.list.length===0) isOver.value = true;
  196. })
  197. }
  198. const calculateCountdown = (datetime) => {
  199. if(!datetime) return -1;
  200. const targetDate = new Date(datetime);
  201. const now = new Date();
  202. const difference = targetDate.getTime() - now.getTime();
  203. if (difference <= 0) return -1;
  204. const days = Math.floor(difference / (1000 * 60 * 60 * 24));
  205. const hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  206. const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
  207. return {
  208. days,
  209. hours,
  210. minutes
  211. };
  212. }
  213. watch(()=>userStore.token,(newVal,oldVal)=>{
  214. if(oldVal!=newVal&&newVal){
  215. setTimeout(()=>{
  216. uni.showToast({
  217. title: '登录成功',
  218. icon: 'success'
  219. });
  220. },200)
  221. nextTick(()=>{
  222. getActivityList()
  223. })
  224. }
  225. })
  226. onMounted(()=>{
  227. if(uni.getStorageSync('userInfo')){
  228. queryParams.value.userId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
  229. }
  230. getSwiperList()
  231. getTypeList()
  232. getActivityList()
  233. })
  234. import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
  235. onShareAppMessage(() => {
  236. return {
  237. title: '善行少年 - 公益活动平台',
  238. path: '/pages/home'
  239. }
  240. })
  241. onShareTimeline(() => {
  242. return {
  243. title: '善行少年 - 公益活动平台',
  244. path: '/pages/home'
  245. }
  246. })
  247. </script>
  248. <style scoped lang="scss">
  249. ::v-deep .indicator__dot{
  250. width: 48rpx;
  251. height: 4rpx;
  252. background: #E2E5E9;
  253. border-radius: 2rpx;
  254. margin: 0 8rpx;
  255. }
  256. ::v-deep .indicator__dot--active{
  257. width: 48rpx;
  258. height: 4rpx;
  259. background: #00AE57;
  260. border-radius: 2rpx;
  261. }
  262. ::v-deep .u-swiper__wrapper__item__wrapper__image{
  263. border-radius: 24rpx !important;
  264. }
  265. .scroll-view_H {
  266. white-space: nowrap;
  267. width: 100%;
  268. }
  269. .scroll-view-item_H {
  270. display: inline-block;
  271. // width: 152rpx;
  272. height: 100%;
  273. margin-left: 20rpx;
  274. &:first-child{
  275. margin-left: 0;
  276. }
  277. }
  278. .tab_page{
  279. .c-box{
  280. width: 100%;
  281. height: 100%;
  282. overflow-y: auto;
  283. position: relative;
  284. &-search{
  285. width: 100%;
  286. padding: 20rpx 30rpx 0;
  287. box-sizing: border-box;
  288. }
  289. &-lunbo{
  290. width: 100%;
  291. height: 326rpx;
  292. margin-top: 20rpx;
  293. }
  294. &-title{
  295. margin-top: 58rpx;
  296. &-left{
  297. width: 170rpx;
  298. height: 44rpx;
  299. padding-left: 2rpx;
  300. font-family: PingFang-SC, PingFang-SC;
  301. font-weight: 800;
  302. font-size: 36rpx;
  303. color: #151B29;
  304. line-height: 36rpx;
  305. background-image: url('https://oss.familydaf.cn/sxsnfile/20251218/6198fa26a7ff4fc1bce530fbdfaa20db.png');
  306. background-size: 170rpx 31rpx;
  307. background-position: 0 20rpx;
  308. background-repeat: no-repeat;
  309. }
  310. &-right{
  311. font-family: PingFangSC, PingFang SC;
  312. font-weight: 400;
  313. font-size: 28rpx;
  314. color: #676775;
  315. line-height: 33rpx;
  316. }
  317. }
  318. &-type{
  319. width: 100%;
  320. height: 68rpx;
  321. margin-top: 31rpx;
  322. .cl_item{
  323. // width: 152rpx;
  324. padding: 0 21rpx;
  325. height: 68rpx;
  326. background: #FFFFFF;
  327. border-radius: 34rpx;
  328. font-family: PingFangSC, PingFang SC;
  329. font-weight: 400;
  330. font-size: 28rpx;
  331. color: #676775;
  332. line-height: 68rpx;
  333. text-align: center;
  334. &.active{
  335. background: #B7F358;
  336. font-weight: bold;
  337. font-size: 30rpx;
  338. color: #151B29;
  339. }
  340. }
  341. }
  342. &-list{
  343. width: 100%;
  344. flex: 1;
  345. overflow-y: auto;
  346. margin-top: 20rpx;
  347. }
  348. }
  349. }
  350. </style>