Browse Source

feat: save

gemercheung 1 year ago
parent
commit
b2f05cae01

+ 16 - 13
app.js

@@ -100,28 +100,30 @@ App({
         let {
           code
         } = res;
-
+        // debugger
         if (code) {
           const result = await wxUserLogin(code)
           console.log('result', result)
           if (result.code === 0) {
             const {
               loginSessionKey,
-              sessionKey
+              sessionKey,
+              token
             } = result.data
-            wx.setStorageSync('token', loginSessionKey)
+            wx.setStorageSync('loginSessionKey', loginSessionKey)
+            wx.setStorageSync('token', token)
             wx.setStorageSync('sessionKey', sessionKey)
-            if (sessionKey) {
-              const res = await getWxUserInfo(sessionKey)
-              const userInfo = wx.getStorageInfoSync('userInfo')
-              if (res.data) {
-                const mergeObj = {
-                  ...userInfo,
-                  ...res.data
-                }
-                wx.setStorageSync('userInfo', mergeObj)
+            const res = await getWxUserInfo(sessionKey)
+            const userInfo = wx.getStorageInfoSync('userInfo')
+            if (res.data) {
+              const mergeObj = {
+                ...userInfo,
+                ...res.data
               }
+              wx.setStorageSync('userInfo', mergeObj)
+              callback && callback(mergeObj);
             }
+
           }
         }
       }
@@ -170,7 +172,8 @@ App({
     isLogin: false,
     cookieIDs: [],
     currentUrl: '',
-    currentShareImg: ''
+    currentShareImg: '',
+    envVersion: "trial"
   }
 })
 

BIN
imgs/icon/comment_active.png


BIN
imgs/icon/half.png


BIN
imgs/icon/mapIcon.png


+ 1 - 1
pages/course/course.json

@@ -1,6 +1,6 @@
 {
   "disableScroll": true,
-  "navigationBarTitleText": "我的购买",
+  "navigationBarTitleText": "VR课堂",
   "usingComponents": {
     "t-pull-down-refresh": "tdesign-miniprogram/pull-down-refresh/pull-down-refresh",
     "t-back-top": "tdesign-miniprogram/back-top/back-top",

+ 27 - 0
pages/course_detail/course_detail.js

@@ -191,4 +191,31 @@ Page({
       }
     })
   },
+  openCouse() {
+    const {
+      roomId,
+      isCompere
+    } = this.data.detail
+    const userInfo = wx.getStorageSync('userInfo')
+    const role = isCompere === 1 ? 'leader' : "customer"
+    wx.showToast({
+      title: `role-${role}`,
+    })
+    wx.navigateToMiniProgram({
+      appId: 'wxd55ee54235e90359',
+      path: 'pages/paid-room/paid-room',
+      extraData: {
+        roomId: roomId,
+        role:role,
+        userId: userInfo.id,
+        nickname: userInfo.nickName,
+        avatar: userInfo.avatarUrl,
+        courseId: this.data.detail.id
+      },
+      envVersion: getApp().globalData.envVersion,
+      success(res) {
+        // 打开成功
+      }
+    })
+  },
 })

+ 17 - 7
pages/course_detail/course_detail.wxml

@@ -45,20 +45,30 @@
 
     <view class="right">
       <!-- <button class="btn">立即抢购</button> -->
-      <t-button class="btn" theme="danger" size="medium" shape="round" wx:if="{{courseStaus.status ===0}}"
-        bindtap="onFreeBuying">立即抢购
-      </t-button>
+      <!-- {{courseStaus.status}} -->
+      <block wx:if="{{courseStaus.status === 0 }}">
 
-      <t-button class="btn" theme="danger" size="medium" shape="round" bindtap="openHost"
-        wx:if="{{courseStaus.status ===1}}">进入课堂</t-button>
+        <t-button class="btn" theme="danger" size="medium" shape="round" wx:if="{{detail.isBuy=== 0}}"
+          bindtap="onFreeBuying">立即抢购
+        </t-button>
+        <t-button class="btn" theme="danger" size="medium" shape="round" bindtap="openCouse" wx:else>等待开课</t-button>
+      </block>
 
-      <t-button class="btn" size="medium" shape="round" bindtap="openHost" wx:if="{{courseStaus.status ===2}}" disabled>
+      <block wx:if="{{courseStaus.status === 1 }}">
+        <t-button class="btn" theme="danger" size="medium" shape="round" wx:if="{{detail.isBuy=== 0}}"
+          bindtap="onFreeBuying">立即抢购
+        </t-button>
+        <t-button class="btn" theme="danger" size="medium" shape="round" bindtap="openCouse" wx:else>进入课堂</t-button>
+      </block>
+
+      <t-button class="btn" size="medium" shape="round" wx:if="{{courseStaus.status ===2}}" disabled>
         课程结束</t-button>
     </view>
 
   </view>
   <t-dialog visible="{{imageOnTop}}" title="限时免费" content="当前课堂限时免费啦!!"
-    confirm-btn="{{ {content: '抢购', variant: 'base', theme: 'danger' } }}" cancel-btn="{{ {content: '取消', variant: 'base', theme: 'default' } }}" bind:confirm="confirmDialog"
+    confirm-btn="{{ {content: '抢购', variant: 'base', theme: 'danger' } }}"
+    cancel-btn="{{ {content: '取消', variant: 'base', theme: 'default' } }}" bind:confirm="confirmDialog"
     bind:cancel="closeDialog">
     <t-image slot="top" t-class="dialog-image" src="https://tdesign.gtimg.com/mobile/demos/dialog1.png" />
   </t-dialog>

+ 39 - 33
pages/user/index.js

@@ -70,8 +70,8 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    // this.isLongPolling()
-    this.newLogin();
+
+
 
   },
 
@@ -428,34 +428,35 @@ Page({
     })
   },
 
-  newLogin() {
-    wx.login({
-      success: async res => {
-        let {
-          code
-        } = res;
-
-        if (code) {
-          const result = await wxUserLogin(code)
-          console.log('result', result)
-          if (result.code === 0) {
-            const {
-              loginSessionKey,
-              sessionKey
-            } = result.data
-            wx.setStorageSync('token', loginSessionKey)
-            wx.setStorageSync('sessionKey', sessionKey)
-            this.setData({
-              isLogin: true
-            })
-            this.updateUserinfo();
-          }
-
-        }
-      }
-    })
-
-  },
+  // newLogin() {
+  //   wx.login({
+  //     success: async res => {
+  //       let {
+  //         code
+  //       } = res;
+
+  //       if (code) {
+  //         const result = await wxUserLogin(code)
+  //         console.log('result', result)
+  //         if (result.code === 0) {
+  //           const {
+  //             loginSessionKey,
+  //             sessionKey,
+  //             token
+  //           } = result.data
+  //           wx.setStorageSync('token', loginSessionKey)
+  //           wx.setStorageSync('sessionKey', sessionKey)
+  //           this.setData({
+  //             isLogin: true
+  //           })
+  //           this.updateUserinfo();
+  //         }
+
+  //       }
+  //     }
+  //   })
+
+  // },
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
@@ -467,9 +468,14 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: async function () {
-    if (!this.data.isLogin) {
-      this.newLogin();
-    }
+
+    app.autoLogin((data) => {
+      console.log('autoLogin', data)
+      this.setData({
+        userInfo: data,
+        isLogin: true
+      })
+    })
   },
 
   async updateUserinfo() {

+ 11 - 1
pages/user/my_course/my_course.js

@@ -42,7 +42,17 @@ Page({
       })
     }
   },
-
+  handleOpenDetail({
+    currentTarget
+  }) {
+    const {
+      detail
+    } = currentTarget.dataset;
+    console.log('detail', detail.id)
+    wx.navigateTo({
+      url:`/pages/course_detail/course_detail?id=${detail.id}`,
+    })
+  },
   /**
    * 生命周期函数--监听页面初次渲染完成
    */

+ 2 - 2
pages/user/my_course/my_course.wxml

@@ -4,8 +4,8 @@
   <!-- 包裹页面全部内容 -->
   <view class="container">
     <view class="list" wx:if="{{list.length > 0}}">
-      <view class="course_item " wx:for="{{list}}" wx:for-item="item" wx:key="index">
-
+      <view class="course_item " wx:for="{{list}}" wx:for-item="item" wx:key="index"  bindtap="handleOpenDetail"
+        data-detail="{{item}}">
         <t-image class="cover" src="https://sit-daikan.4dage.com/{{item.thumb}}" mode="aspectFill"
           aria-label="{{item.title}}" />
         <view class="content">

+ 27 - 0
pages/user/my_host_course/index.js

@@ -46,6 +46,33 @@ Page({
       })
     }
   },
+  openCouse({
+    currentTarget
+  }) {
+
+    const {
+      item
+    } = currentTarget.dataset;
+    console.log('item', item)
+    const userInfo = wx.getStorageSync('userInfo')
+
+    wx.navigateToMiniProgram({
+      appId: 'wxd55ee54235e90359',
+      path: 'pages/paid-room/paid-room',
+      extraData: {
+        roomId: item.roomId,
+        role: "leader",
+        userId: userInfo.id,
+        nickname: userInfo.nickName,
+        avatar: userInfo.avatarUrl,
+        courseId: item.id
+      },
+      envVersion: getApp().globalData.envVersion,
+      success(res) {
+        // 打开成功
+      }
+    })
+  },
   /**
    * 生命周期函数--监听页面初次渲染完成
    */

+ 5 - 3
pages/user/my_host_course/index.wxml

@@ -28,11 +28,13 @@
             format="HH:mm:ss:SSS" theme="square" millisecond> </t-count-down>
 
           <view class="btn">
-            <t-button theme="danger" size="extra-small" shape="round" wx:if="{{item.courseStaus.status ===0}}">开始课程
+            <t-button theme="danger" size="extra-small" shape="round" wx:if="{{item.courseStaus.status ===0}}"
+              bindtap="openCouse" data-item="{{item}}">开始课程
             </t-button>
-            <t-button theme="danger" size="extra-small" shape="round" wx:if="{{item.courseStaus.status ===1}}">课程已开始
+            <t-button theme="danger" size="extra-small" shape="round" bindtap="openCouse" data-item="{{item}}"
+              wx:if="{{item.courseStaus.status === 1}}"> 已开始
             </t-button>
-            <t-button size="extra-small" shape="round" wx:if="{{item.courseStaus.status ===1}}">已结束
+            <t-button size="extra-small" shape="round" wx:if="{{item.courseStaus.status ===2}}">已结束
             </t-button>
           </view>
 

+ 14 - 7
pages/user/personal/personal.js

@@ -149,7 +149,9 @@ Page({
           wx.showToast({
             title: '更新成功!',
           })
-          this.syncUserInfo(res.data);
+          this.syncUserInfo({
+            phone: res.data.phoneNumber
+          });
         }
       }
     }
@@ -181,7 +183,9 @@ Page({
         gender: Number(index) + 1
       })
       if (res.code === 0) {
-        this.syncUserInfo(res.data)
+        this.syncUserInfo({
+          gender: Number(index) + 1
+        })
       }
 
     }
@@ -201,7 +205,9 @@ Page({
       avatarUrl: url
     })
     if (res.code === 0) {
-      this.syncUserInfo(res.data)
+      this.syncUserInfo({
+        avatarUrl: url
+      })
     }
 
   },
@@ -216,10 +222,11 @@ Page({
         nickName: value
       })
       console.log('res', res)
-      // if (res.code === 0) {
-      //   this.syncUserInfo(res.data)
-      // }
-
+      if (res.code === 0) {
+        this.syncUserInfo({
+          nickName: value
+        })
+      }
     }
 
   },

+ 1 - 1
project.config.json

@@ -22,7 +22,7 @@
     "useApiHook": true,
     "useApiHostProcess": true,
     "packNpmRelationList": [],
-    "ignoreUploadUnusedFiles": false
+    "ignoreUploadUnusedFiles": true
   },
   "compileType": "miniprogram",
   "libVersion": "2.11.3",

+ 3 - 1
utils/courseTime.js

@@ -23,7 +23,9 @@ export function IsInTime(comingStartDate, comingEndDate) {
 export function getCourseStatus(comingStartDate, comingEndDate) {
   const now = dayjs();
   const isOn = now.isBetween(dayjs(comingStartDate), dayjs(comingEndDate));
-  console.log('isOn', isOn)
+
+  console.log('isOn', isOn, dayjs(comingStartDate).format('YYYY-MM-DD hh:mm:ss'), dayjs(comingEndDate).format('YYYY-MM-DD hh:mm:ss'))
+  
   const reMain = dayjs(comingEndDate).diff(now)
   if (isOn) {
     return {

+ 4 - 6
utils/request.js

@@ -17,7 +17,7 @@ const urls = {
 
   updateWxUser: '/api/wxUser/updateWxUser',
   // 新微信登录
-  wxLogin: "/api/wxUser/wxLogin/{code}",
+  wxLogin: "/api/show/wxLogin/{code}",
   //免费限时
   freeBuy: "/api/payment/freeBuy",
 }
@@ -26,6 +26,7 @@ wxRequest.defaults.baseURL = 'https://sit-daikan.4dage.com';
 wxRequest.defaults.headers['Token'] = wx.getStorageSync('token') || "";
 wxRequest.defaults.headers.post['Content-Type'] = 'application/json';
 
+
 export async function getVRCourseList(params) {
   return await (await wxRequest.post(urls.getVRCourseList, params)).data;
 }
@@ -59,11 +60,7 @@ export async function decrptPhone(code) {
 }
 
 export async function updateUserInfo(info) {
-  const sessionKey = wx.getStorageSync('sessionKey')
-  if (sessionKey) {
-    // const url = urls.updateWxUser.replace('{sessionKey}', sessionKey)
-    return await (await wxRequest.post(url + `?sessionKey=${sessionKey}`, info)).data;
-  }
+  return await (await wxRequest.post(urls.updateWxUser, info)).data;
 }
 export const updateAvatar = async (avatarUrl) => {
 
@@ -85,6 +82,7 @@ export const updateAvatar = async (avatarUrl) => {
 
 export async function wxUserLogin(code) {
   const url = urls.wxLogin.replace('{code}', code);
+
   return await (await wxRequest.get(url)).data;
 }
 

+ 1 - 1
utils/services.js

@@ -90,7 +90,7 @@ Object.keys(urls).forEach(function (key) {
   ) {
     console.log(`request ${urls[key]}`);
     let commonData = {
-      loginSessionKey: wx.getStorageSync('token') || ""
+      loginSessionKey: wx.getStorageSync('loginSessionKey') || ""
     };