From 308d3b3b7883a92a761dfaf4f607a9f4658213cf Mon Sep 17 00:00:00 2001
From: Codex Assistant <codex@example.com>
Date: 星期四, 06 十一月 2025 09:58:25 +0800
Subject: [PATCH] 修改页面

---
 wx/pages/index/index.js |  278 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 248 insertions(+), 30 deletions(-)

diff --git a/wx/pages/index/index.js b/wx/pages/index/index.js
index 3b64423..ba5d944 100644
--- a/wx/pages/index/index.js
+++ b/wx/pages/index/index.js
@@ -21,17 +21,20 @@
     // 绛涢�夋潯浠�
     filterStatus: 'all', // all, upcoming, ongoing, ended
     // 杞挱鍥惧綋鍓嶇储寮�
-    currentBannerIndex: 0
+    currentBannerIndex: 0,
+    // 鍒嗕韩鐩稿叧鏁版嵁
+    shareActivityId: null,
+    shareActivityName: null
   },
 
   onLoad(options) {
     console.log('棣栭〉鍔犺浇')
-    this.loadBanners()
-    this.loadActivities()
   },
 
   onShow() {
     console.log('棣栭〉鏄剧ず')
+    // 缁熶竴绯荤粺瀵艰埅鏍忔爣棰�
+    try { wx.setNavigationBarTitle({ title: '钃塭鍒�' }) } catch (e) {}
     // 妫�鏌ョ櫥褰曠姸鎬�
     if (!app.globalData.token) {
       app.login()
@@ -40,6 +43,9 @@
     if (typeof this.getTabBar === 'function' && this.getTabBar()) {
       this.getTabBar().init();
     }
+    // 鍔犺浇鏁版嵁
+    this.loadBanners()
+    this.loadActivities()
   },
 
   onPullDownRefresh() {
@@ -141,7 +147,7 @@
               type: 'image',
               url: banner.coverImage.fullUrl,
               thumbUrl: banner.coverImage.fullThumbUrl
-            })
+            });
           }
           
           return {
@@ -160,7 +166,7 @@
   },
 
   // 鍔犺浇璧涗簨鍒楄〃
-  loadActivities() {
+  loadActivities(isLoadMore = false) {
     this.setData({ loading: true })
     
     const { currentPage, pageSize, searchKeyword, filterStatus } = this.data
@@ -168,9 +174,21 @@
     // 鍚嶇О鎼滅储鏉′欢
     const nameFilter = searchKeyword || ""
     
+    // 鐘舵�佺瓫閫夋潯浠讹細灏嗗墠绔殑绛涢�夌姸鎬佽浆鎹负鍚庣鐨剆tate鍙傛暟
+    let stateFilter = null
+    if (filterStatus !== 'all') {
+      // 鏍规嵁filterStatus鏄犲皠鍒板搴旂殑state鍊�
+      const stateMapping = {
+        'upcoming': 1,    // 鍗冲皢寮�濮� -> 鍙戝竷鐘舵��
+        'ongoing': 1,     // 杩涜涓� -> 鍙戝竷鐘舵��  
+        'ended': 2        // 宸茬粨鏉� -> 鍏抽棴鐘舵��
+      }
+      stateFilter = stateMapping[filterStatus]
+    }
+    
     return app.graphqlRequest(`
-      query getActivities($page: Int!, $size: Int!, $name: String) {
-        activities(page: $page, size: $size, name: $name) {
+      query getActivities($page: Int!, $size: Int!, $name: String, $state: Int) {
+        activities(page: $page, size: $size, name: $name, state: $state) {
           content {
             id
             name
@@ -199,26 +217,26 @@
     `, {
       page: currentPage,
       size: pageSize,
-      name: nameFilter
+      name: nameFilter,
+      state: 1
     }).then(data => {
       if (data.activities) {
         let newActivities = data.activities.content
+        // 璋冭瘯锛氳緭鍑烘姤鍚嶆埅姝㈠師濮嬪��
+        try {
+          console.log('娲诲姩鍘熷鎶ュ悕鎴:', newActivities.map(a => ({ id: a.id, name: a.name, signupDeadline: a.signupDeadline })))
+        } catch (e) {}
         
         // 涓烘瘡涓椿鍔ㄦ坊鍔犲悕绉版枃瀛�
-        newActivities = newActivities.map(activity => ({
-          ...activity,
-          nameText: (activity.name || '娲诲姩').substring(0, 2)
-        }))
+        // newActivities = newActivities.map(activity => ({
+        //   ...activity,
+        //   nameText: (activity.name || '娲诲姩').substring(0, 2)
+        // }))
         
-        // 鏍规嵁绛涢�夌姸鎬佽繃婊ゆ椿鍔�
-        if (filterStatus !== 'all') {
-          newActivities = newActivities.filter(activity => activity.state === filterStatus)
-        }
-        
-        // 鍚堝苟鏁版嵁
-        const mergedActivities = currentPage === 1 
-          ? newActivities 
-          : [...this.data.activities, ...newActivities]
+        // 鍚堝苟鏁版嵁锛氬彧鏈夊湪鐪熸鐨勫姞杞芥洿澶氭椂鎵嶈拷鍔狅紝鍏朵粬鎯呭喌閮芥槸鍏ㄩ噺鏇挎崲
+        const mergedActivities = isLoadMore && this.data.activities.length > 0
+          ? [...this.data.activities, ...newActivities]
+          : newActivities
         
         this.setData({
           activities: mergedActivities,
@@ -238,7 +256,7 @@
     this.setData({
       currentPage: this.data.currentPage + 1
     })
-    this.loadActivities()
+    this.loadActivities(true) // 浼犲叆true琛ㄧず杩欐槸鍔犺浇鏇村
   },
 
   // 杞挱鍥惧垏鎹�
@@ -323,18 +341,59 @@
     utils.navigateTo('/pages/activity/detail', { id: activityId })
   },
 
-  // 鐐瑰嚮璧涗簨鍗$墖
-  onActivityTap(e) {
-    const index = e.currentTarget.dataset.index
-    const activity = this.data.activities[index]
-    if (activity) {
-      this.goToActivityDetail(activity.id)
-    }
-  },
 
   // 鏍煎紡鍖栨棩鏈�
   formatDate(date) {
     return utils.formatDate(date, 'MM-DD HH:mm')
+  },
+
+  // 璁捐绋块渶瑕佺殑 YYYY-MM-DD锛堝己鍏煎锛氱洿鎺ユ埅鍙栧墠10浣嶏紝閬垮厤 JSCore 鏃ユ湡瑙f瀽宸紓锛�
+  formatDateYYYYMMDD(date) {
+    if (!date && date !== 0) return '鈥�'
+    // 瀛楃涓诧細浼樺厛鍖归厤 YYYY-MM-DD 鐩存帴杩斿洖锛岄伩鍏嶈В鏋�
+    if (typeof date === 'string') {
+      const m = date.match(/^(\d{4}-\d{2}-\d{2})/)
+      if (m) return m[1]
+    }
+    // 鏁板�硷細鏃堕棿鎴筹紙绉�/姣锛夊厹搴�
+    if (typeof date === 'number') {
+      const ts = date > 1e12 ? date : date * 1000
+      const d = new Date(ts)
+      if (!isNaN(d.getTime())) {
+        const y = d.getFullYear()
+        const m = String(d.getMonth() + 1).padStart(2, '0')
+        const day = String(d.getDate()).padStart(2, '0')
+        return `${y}-${m}-${day}`
+      }
+    }
+    // 鍏朵粬鎯呭喌璧板伐鍏峰嚱鏁板厹搴�
+    const v = utils.formatDate(date, 'YYYY-MM-DD')
+    return v && typeof v === 'string' && v.trim() ? v : '鈥�'
+  },
+  onTest(e){
+    const activityId = e.currentTarget.dataset.id
+    const xid = e.currentTarget.dataset.xid;
+    const idx = e.currentTarget.dataset.idx;
+    
+    // 绠�鍖栫殑璋冭瘯淇℃伅
+    console.log('鐐瑰嚮娲诲姩璇︽儏 - ID:', activityId, '鍚嶇О:', xid, '绱㈠紩:', idx)
+    
+    if (activityId) {
+      this.goToActivityDetail(activityId)
+    }
+  },
+  // 鐐瑰嚮"璇︽儏"鎸夐挳锛堜笌鍗$墖鐐瑰嚮涓�鑷达級
+  onActivityDetailTap(e) {
+    const activityId = e.currentTarget.dataset.id
+    const xid = e.currentTarget.dataset.xid;
+    const idx = e.currentTarget.dataset.idx;
+    
+    // 绠�鍖栫殑璋冭瘯淇℃伅
+    console.log('鐐瑰嚮娲诲姩璇︽儏 - ID:', activityId, '鍚嶇О:', xid, '绱㈠紩:', idx)
+    
+    if (activityId) {
+      this.goToActivityDetail(activityId)
+    }
   },
 
   // 鑾峰彇鐘舵�佹枃鏈�
@@ -379,5 +438,164 @@
     return now <= signupDeadline && 
            activity.state === 'SIGNUP' &&
            activity.playerCount < activity.playerMax
+  },
+
+  // 鍒嗕韩鍗曚釜姣旇禌
+  onShareActivity(e) {
+    const { id, name } = e.currentTarget.dataset
+    
+    // 鏄剧ず鍒嗕韩閫夐」
+    wx.showActionSheet({
+      itemList: ['鍒嗕韩缁欐湅鍙�', '鐢熸垚鍒嗕韩娴锋姤'],
+      success: (res) => {
+        if (res.tapIndex === 0) {
+          // 鍒嗕韩缁欐湅鍙�
+          this.shareToFriend(id, name)
+        } else if (res.tapIndex === 1) {
+          // 鐢熸垚鍒嗕韩娴锋姤
+          this.generateSharePoster(id, name)
+        }
+      },
+      fail: (res) => {
+        console.log('鐢ㄦ埛鍙栨秷鍒嗕韩')
+      }
+    })
+  },
+
+  // 鍒嗕韩缁欐湅鍙�
+  shareToFriend(activityId, activityName) {
+    wx.showShareMenu({
+      withShareTicket: true,
+      menus: ['shareAppMessage', 'shareTimeline']
+    })
+    
+    // 璁剧疆褰撳墠瑕佸垎浜殑娲诲姩淇℃伅
+    this.setData({
+      shareActivityId: activityId,
+      shareActivityName: activityName
+    })
+    
+    // 瑙﹀彂鍒嗕韩
+    wx.updateShareMenu({
+      withShareTicket: true,
+      isUpdatableMessage: true,
+      activityId: 'share_activity_' + activityId,
+      templateInfo: {
+        parameterList: [{
+          name: 'activity_name',
+          value: activityName
+        }]
+      }
+    })
+    
+    wx.showToast({
+      title: '璇风偣鍑诲彸涓婅鍒嗕韩',
+      icon: 'none',
+      duration: 2000
+    })
+  },
+
+  // 鐢熸垚鍒嗕韩娴锋姤
+  generateSharePoster(activityId, activityName) {
+    wx.showLoading({
+      title: '鐢熸垚娴锋姤涓�...'
+    })
+    
+    // 杩欓噷鍙互璋冪敤鍚庣API鐢熸垚鍒嗕韩娴锋姤
+    // 鎴栬�呬娇鐢╟anvas鍦ㄥ墠绔敓鎴�
+    setTimeout(() => {
+      wx.hideLoading()
+      wx.showToast({
+        title: '娴锋姤鐢熸垚鍔熻兘寮�鍙戜腑',
+        icon: 'none',
+        duration: 2000
+      })
+    }, 1500)
+  },
+
+  // 椤甸潰鍒嗕韩鍔熻兘 - 鍒嗕韩缁欐湅鍙�
+  onShareAppMessage(res) {
+    console.log('鍒嗕韩缁欐湅鍙�', res)
+    
+    // 濡傛灉鏄粠姣旇禌鍗$墖鍒嗕韩
+    if (this.data.shareActivityId && this.data.shareActivityName) {
+      const shareData = {
+        title: `${this.data.shareActivityName} - 钃塭鍒涙瘮璧涘钩鍙癭,
+        path: `/pages/activity/detail?id=${this.data.shareActivityId}`,
+        imageUrl: '', // 鍙互璁剧疆鍒嗕韩鍥剧墖
+        success: (res) => {
+          console.log('鍒嗕韩鎴愬姛', res)
+          wx.showToast({
+            title: '鍒嗕韩鎴愬姛',
+            icon: 'success',
+            duration: 2000
+          })
+          // 娓呴櫎鍒嗕韩鐘舵��
+          this.setData({
+            shareActivityId: null,
+            shareActivityName: null
+          })
+        },
+        fail: (res) => {
+          console.log('鍒嗕韩澶辫触', res)
+          wx.showToast({
+            title: '鍒嗕韩澶辫触',
+            icon: 'none',
+            duration: 2000
+          })
+        }
+      }
+      return shareData
+    }
+    
+    // 榛樿鍒嗕韩鏁翠釜棣栭〉
+    return {
+      title: '钃塭鍒涙瘮璧涘钩鍙� - 鍙戠幇绮惧僵姣旇禌',
+      path: '/pages/index/index',
+      imageUrl: '', // 鍙互璁剧疆榛樿鍒嗕韩鍥剧墖
+      success: (res) => {
+        console.log('鍒嗕韩鎴愬姛', res)
+        wx.showToast({
+          title: '鍒嗕韩鎴愬姛',
+          icon: 'success',
+          duration: 2000
+        })
+      },
+      fail: (res) => {
+        console.log('鍒嗕韩澶辫触', res)
+        wx.showToast({
+          title: '鍒嗕韩澶辫触',
+          icon: 'none',
+          duration: 2000
+        })
+      }
+    }
+  },
+
+  // 鍒嗕韩鍒版湅鍙嬪湀
+  onShareTimeline() {
+    console.log('鍒嗕韩鍒版湅鍙嬪湀')
+    
+    return {
+      title: '钃塭鍒涙瘮璧涘钩鍙� - 鍙戠幇绮惧僵姣旇禌',
+      query: '',
+      imageUrl: '', // 鍙互璁剧疆鍒嗕韩鍥剧墖
+      success: (res) => {
+        console.log('鍒嗕韩鍒版湅鍙嬪湀鎴愬姛', res)
+        wx.showToast({
+          title: '鍒嗕韩鎴愬姛',
+          icon: 'success',
+          duration: 2000
+        })
+      },
+      fail: (res) => {
+        console.log('鍒嗕韩鍒版湅鍙嬪湀澶辫触', res)
+        wx.showToast({
+          title: '鍒嗕韩澶辫触',
+          icon: 'none',
+          duration: 2000
+        })
+      }
+    }
   }
 })
\ No newline at end of file

--
Gitblit v1.8.0