gemercheung 11 ヶ月 前
コミット
dc69878d1c

+ 1 - 1
pages/user/index.js

@@ -312,7 +312,7 @@ Page({
             } = res;
 
             console.log(789, res);
-
+            debugger
             if (code) {
               wx.request({
                 url: serverName + '/wx/api/user/getLoginSessionKey',

+ 26 - 10
pages/user/my_course/my_course.js

@@ -1,15 +1,23 @@
 // pages/user/my_course/my_course.js
 import {
-  getMyPaidlesson
+  getMyPaidlesson,
+  getVRCourseList
 } from '../../../utils/request'
+
+import {
+  getCourseStatus
+} from '../../../utils/courseTime'
+const {
+  noExhibitionImg
+} = require('../../../utils/images');
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-    testData: 10,
-    list: []
+    noExhibitionImg,
+    list: [],
   },
 
   /**
@@ -17,13 +25,21 @@ Page({
    */
   async onLoad(options) {
     if (options.userId) {
-      const res = await getMyPaidlesson(options.userId);
-      console.log('res', res)
-      if (res.code === 0) {
-        this.setData({
-          list: res.data || []
-        })
-      }
+      this.getPaidList(options.userId);
+    }
+  },
+
+  async getPaidList(id) {
+    const res = await getMyPaidlesson(id);
+    // const res = await getVRCourseList();
+    console.log('res', res)
+    if (res.code === 0) {
+      this.setData({
+        list: res.data.records ? res.data.records.map(item => {
+          item.courseStaus = getCourseStatus(item.openRoomTime, item.endRoomTime)
+          return item
+        }) : []
+      })
     }
   },
 

+ 2 - 1
pages/user/my_course/my_course.json

@@ -4,6 +4,7 @@
     "t-pull-down-refresh": "tdesign-miniprogram/pull-down-refresh/pull-down-refresh",
     "t-skeleton": "tdesign-miniprogram/skeleton/skeleton",
     "t-back-top": "tdesign-miniprogram/back-top/back-top",
-    "t-image": "tdesign-miniprogram/image/image"
+    "t-image": "tdesign-miniprogram/image/image",
+    "t-empty": "tdesign-miniprogram/empty/empty"
   }
 }

+ 17 - 7
pages/user/my_course/my_course.wxml

@@ -3,27 +3,37 @@
   bind:scroll="onScroll">
   <!-- 包裹页面全部内容 -->
   <view class="container">
-    <view class="list">
-      <view class="course_item " wx:for="{{testData}}" wx:key="index">
-        <t-image class="cover" src="https://ossxiaoan.4dage.com/720yun_fd_manage/fodder/20230506_163327998.jpg" mode="aspectFill" aria-label="一个放置在墙角的黄色行李箱" />
+    <view class="list" wx:if="{{list.length > 0}}">
+      <view class="course_item " wx:for="{{list}}" wx:for-item="item" wx:key="index">
+
+        <t-image class="cover" src="https://sit-daikan.4dage.com/{{item.thumb}}" mode="aspectFill"
+          aria-label="{{item.title}}" />
         <view class="content">
           <view class="title">
-            天安门广场+明清皇家宫殿紫禁城+八达岭长城赏塞外风光+半部, 天安门广场+明清皇家宫殿紫禁城+八达岭长城赏塞外风光+半部, 天安门广场+明清皇家宫殿紫禁城+八达岭长城赏塞外风光+半部
+            {{item.title}}
           </view>
           <view class="sub_info">
             <view class="author">
-              余老师带你飞
+              {{item.organization}}
             </view>
-            <view class="status"  wx:if="{{index %2 ===0}}">
+
+            <view class="status" wx:if="{{item.courseStaus.status ===0}}">
               未开始
             </view>
-            <view class="status live" wx:else>
+            <view class="status live" wx:if="{{item.courseStaus.status ===1}}">
               直播中
             </view>
+            <view class="status live" wx:if="{{item.courseStaus.status ===2}}">
+              已结束
+            </view>
           </view>
         </view>
       </view>
     </view>
+    <view class="empty" wx:else>
+      <t-empty image="{{noExhibitionImg}}" t-class-image="t-empty__image" description="暂没数据" />
+    </view>
+
 
     <t-back-top text="顶部" scroll-top="{{scrollTop}}" visibility-height="{{100}}" />
   </view>

+ 11 - 0
pages/user/my_course/my_course.wxss

@@ -114,4 +114,15 @@
 
 .status.live {
   color: rgba(215, 95, 93, 1);
+}
+.empty {
+  min-height: 80vh;
+  width: 100%;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}
+.empty .t-empty__image {
+  width: 300rpx;
+  height: 200rpx;
 }

+ 26 - 9
pages/user/my_host_course/index.js

@@ -1,7 +1,14 @@
 // pages/user/my_course/my_course.js
 import {
-  getMyHostlesson
+  getMyHostlesson,
+  getVRCourseList
 } from '../../../utils/request'
+import {
+  getCourseStatus
+} from '../../../utils/courseTime'
+const {
+  noExhibitionImg
+} = require('../../../utils/images');
 Page({
 
   /**
@@ -10,6 +17,8 @@ Page({
   data: {
     testData: 10,
     time: 96 * 60 * 1000,
+    list: [],
+    noExhibitionImg
   },
 
   /**
@@ -17,17 +26,25 @@ Page({
    */
   async onLoad(options) {
     if (options.userId) {
-      const res = await getMyHostlesson(options.userId);
-      console.log('getMyHostlesson', res)
-      if (res.code === 0) {
-        this.setData({
-          list: res.data || []
-        })
-      }
+      // const res = await getMyHostlesson(options.userId);
+      
+    this.getCourseList(options.userId)
     }
   },
 
-
+  async getCourseList(id) {
+    // const res = await getMyPaidlesson(id);
+    const res = await getVRCourseList();
+    console.log('res', res)
+    if (res.code === 0) {
+      this.setData({
+        list: res.data.records ? res.data.records.map(item => {
+          item.courseStaus = getCourseStatus(item.openRoomTime, item.endRoomTime)
+          return item
+        }) : []
+      })
+    }
+  },
   /**
    * 生命周期函数--监听页面初次渲染完成
    */

+ 20 - 11
pages/user/my_host_course/index.wxml

@@ -3,38 +3,47 @@
   bind:scroll="onScroll">
   <!-- 包裹页面全部内容 -->
   <view class="container">
-    <view class="list">
-      <view class="course_item_container" wx:for="{{testData}}" wx:key="index">
+    <view class="list" wx:if="{{list.length >0}}">
+      <view class="course_item_container" wx:for="{{list}}" wx:for-item="item" wx:key="index">
         <view class="course_item ">
-          <t-image class="cover" src="https://ossxiaoan.4dage.com/720yun_fd_manage/fodder/20230506_163327998.jpg"
-            mode="aspectFill" aria-label="一个放置在墙角的黄色行李箱" />
+          <t-image class="cover" src="https://sit-daikan.4dage.com/{{item.thumb}}" mode="aspectFill"
+            aria-label="{{item.title}}" />
           <view class="content">
             <view class="title">
-              天安门广场+明清皇家宫殿紫禁城+八达岭长城赏塞外风光+半部, 天安门广场+明清皇家宫殿紫禁城+八达岭长城赏塞外风光+半部, 天安门广场+明清皇家宫殿紫禁城+八达岭长城赏塞外风光+半部
+              {{item.title}}
             </view>
             <view class="sub_info">
               <view class="author">
-                余老师带你飞
+                {{item.organization}}
               </view>
               <view class="status">
                 <image class="time" src="../../../imgs/time.png"></image>
-                <text>45分钟</text>
+                <text> {{item.duration}}分钟</text>
               </view>
             </view>
           </view>
         </view>
         <view class="entry">
-          <t-count-down class="count" size="small" content="default" time="{{ time }}" format="HH:mm:ss:SSS"
-            theme="square" millisecond> </t-count-down>
-          <!-- <text>xxxx</text> -->
+          <t-count-down class="count" size="small" content="default" time="{{ item.courseStaus.time }}"
+            format="HH:mm:ss:SSS" theme="square" millisecond> </t-count-down>
+
           <view class="btn">
-            <t-button theme="danger" size="extra-small" shape="round">开始课程</t-button>
+            <t-button theme="danger" size="extra-small" shape="round" wx:if="{{item.courseStaus.status ===0}}">开始课程
+            </t-button>
+            <t-button theme="danger" size="extra-small" shape="round" wx:if="{{item.courseStaus.status ===1}}">课程已开始
+            </t-button>
+            <t-button size="extra-small" shape="round" wx:if="{{item.courseStaus.status ===1}}">已结束
+            </t-button>
           </view>
 
         </view>
       </view>
 
     </view>
+    <view class="empty" wx:else>
+      <t-empty image="{{noExhibitionImg}}" t-class-image="t-empty__image" description="暂没数据" />
+    </view>
+
 
     <t-back-top text="顶部" scroll-top="{{scrollTop}}" visibility-height="{{100}}" />
   </view>

+ 12 - 0
pages/user/my_host_course/index.wxss

@@ -160,3 +160,15 @@
   /* background: rgba(0, 0, 0, 0.3); */
 }
 
+.empty {
+  min-height: 80vh;
+  width: 100%;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}
+
+.empty .t-empty__image {
+  width: 300rpx;
+  height: 200rpx;
+}

+ 52 - 0
pages/user/my_host_course/utils/courseTime.js

@@ -0,0 +1,52 @@
+import dayjs from 'dayjs'
+const isBetween = require('./dayjs/isBetween')
+dayjs.extend(isBetween);
+
+export function IsNotEnd(comingEndDate) {
+  const now = dayjs();
+  const isNotEnd = dayjs(comingEndDate).diff(now, 'second');
+  return isNotEnd > 0 ? false : true
+}
+
+export function IsNotStart(comingStartDate) {
+  const now = dayjs();
+  const IsNotStart = dayjs(comingStartDate).diff(now, 'second');
+  console.log('IsNotStart', IsNotStart)
+  return IsNotStart > 0 ? true : false
+}
+
+export function IsInTime(comingStartDate, comingEndDate) {
+  const now = dayjs();
+  return now.isBetween(dayjs(comingStartDate), dayjs(comingEndDate))
+}
+
+export function getCourseStatus(comingStartDate, comingEndDate) {
+  const now = dayjs();
+  const isOn = now.isBetween(dayjs(comingStartDate), dayjs(comingEndDate));
+  console.log('isOn', isOn)
+  const reMain = dayjs(comingEndDate).diff(now)
+  if (isOn) {
+    return {
+      status: 1,
+      time: 0,
+      showTime: dayjs(comingStartDate).format('YYYY-MM-DD hh:mm:ss')
+    }
+  } else {
+    if (reMain < 0) {
+      return {
+        status: 2,
+        time: 0,
+        showTime: dayjs(comingStartDate).format('YYYY-MM-DD hh:mm:ss')
+      }
+    } else {
+      const nearStart = dayjs(comingStartDate).diff(now)
+      return {
+        status: 0,
+        time: nearStart,
+        showTime: dayjs(comingStartDate).format('YYYY-MM-DD hh:mm:ss')
+      }
+    }
+
+  }
+
+}

ファイルの差分が大きいため隠しています
+ 1 - 0
pages/user/my_host_course/utils/dayjs/isBetween.js


ファイルの差分が大きいため隠しています
+ 14 - 0
pages/user/my_host_course/utils/images.js


+ 77 - 0
pages/user/my_host_course/utils/request.js

@@ -0,0 +1,77 @@
+import wxRequest from 'wechat-request';
+
+
+const urls = {
+  //VR课堂
+  getVRCourseList: '/api/show/lesson/pageList',
+  //VR课堂详情
+  getVRCourseDetail: '/api/show/lesson/detail/',
+  // 获取微信用户详情
+  getWxUserInfo: "/api/wxUser/getWxUserInfo/",
+  //微信用户-我的购买
+  getMylesson: "/api/show/lesson/getList/",
+  //主持人-我的课程
+  getMyHostlesson: "/api/show/compere/getLesson/",
+
+  getPhone: "/api/wxUser/getPhone",
+  updateWxUser: "/api/wxUser/updateWxUser/{sessionKey}",
+
+
+}
+
+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;
+}
+
+export async function getVRCourseDetail(id) {
+  return await (await wxRequest.get(urls.getVRCourseDetail + id)).data;
+}
+
+export async function getWxUserInfo(key) {
+  return await (await wxRequest.get(urls.getWxUserInfo + key)).data;
+}
+
+
+export async function getMyPaidlesson(wxUserId) {
+  return await (await wxRequest.get(urls.getMylesson + wxUserId)).data;
+}
+export async function getMyHostlesson(wxUserId) {
+  return await (await wxRequest.get(urls.getMyHostlesson + wxUserId)).data;
+}
+
+export async function decrptPhone(code) {
+  console.log('decrptPhone-params', code,)
+  const url = `${urls.getPhone}/${code}`
+  console.log('decrptPhone-url', url)
+  return await (await wxRequest.get(url)).data;
+}
+
+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, info)).data;
+  }
+}
+export const updateAvatar = async (avatarUrl) => {
+
+  const WX_UPLOAD_URL = ''
+  let url = ''
+  wx.uploadFile({
+    filePath: avatarUrl,
+    name: 'file',
+    url: WX_UPLOAD_URL,
+    success: async (res) => {
+      const data = JSON.parse(res.data)
+      console.log('data', data)
+      url = data.data
+    }
+  })
+  await sleep(1200)
+  return Promise.resolve(url)
+}

+ 191 - 0
pages/user/my_host_course/utils/services.js

@@ -0,0 +1,191 @@
+const {
+  Toast
+} = require('./util');
+
+// const serverName = 'https://www.4dmuseum.cn/2.0'; // 正式
+const serverName = 'http://sit-kanzhan.4dkankan.com'; // 测试
+// const serverName = 'http://192.168.0.10:8081'; // 本地
+
+//const imgServer = 'https://www.4dmuseum.cn/'
+const imgServer = ''
+
+const urls = {
+  //用户API
+  getLoginSessionKey: '/wx/api/user/getLoginSessionKey',
+  // checkPaySessionKey:'/wx/api/user/checkLoginSessionKey',
+  checkLoginSessionKey: '/wx/api/user/getBrowsedExhibitions',
+
+  logout: '/wx/api/user/logout',
+  isCollect: '/wx/api/exhibition/like',
+  collectExhibitions: "/wx/api/user/getExhibitions",
+  getOrders: '/wx/api/user/getOrders',
+
+  //轮播图
+  getBannerList: '/wx/api/banner/list',
+  getBannerDetail: '/wx/api/banner/detail',
+
+  //展会
+  getExhibitionList: "/wx/api/exhibition/listByType",
+  getExhibitionListOffline: "/wx/api/exhibition/offline",
+  getExhibitionDetail: "/wx/api/exhibition/detail",
+  getExhibitionSearch: "/wx/api/exhibition/search",
+  getKeywordCode: "/wx/api/dataDictionary/keywordCode",
+
+  //展馆
+  getPavilionDetail: "/wx/api/pavilion/detail",
+  getPavilionSearch: "/wx/api/pavilion/search",
+
+  //同城
+  getDomesticCity: '/wx/api/exhibition/domesticCity',
+  getInternationalCity: '/wx/api/exhibition/internationalCity',
+  getNearByList: '/wx/api/exhibition/nearByList',
+  //支付
+  orderPay: '/wx/api/order/pay',
+  getPayParams: '/wx/api/order/getPayParams',
+  getProduct: '/wx/api/exhibition/getProduct',
+
+  //看过
+  getExhibitionsByIds: '/wx/api/exhibition/getExhibitionsByIds',
+
+  //评论
+  getComments: '/wx/api/user/getComments',
+
+  //保存浏览
+  saveBrowsedExhibitions: '/wx/api/user/saveBrowsedExhibitions',
+
+  //获取浏览记录id
+  getBrowsedExhibitions: 'wx/api/user/getBrowsedExhibitions',
+  //
+  getCommentslist: '/wx/api/comment/list',
+
+  //评论
+  writtenComments: '/wx/api/comment/written',
+
+  //点赞评论
+  commentLike: '/wx/api/comment/like',
+
+  //未读
+  longPolling: '/wx/api/user/longPolling',
+
+  //搜索的热门推荐
+  recommend: '/wx/api/exhibition/recommend',
+
+  //线下展讯热门推荐
+  offlineRecommend: '/wx/api/exhibition/offlineRecommend',
+
+
+};
+// 上传路径
+const uploadUrls = {};
+const requestFns = {};
+
+Object.keys(urls).forEach(function (key) {
+  // console.log(token)
+  requestFns[key] = function (
+    data = {},
+    method = "",
+    success = () => {},
+    fail = () => {},
+    complete = () => {}
+  ) {
+    console.log(`request ${urls[key]}`);
+    let commonData = {
+      loginSessionKey: wx.getStorageSync('token') || ""
+    };
+
+
+    const url = `${serverName}${urls[key]}`;
+    return wx.request({
+      method: method || 'get',
+      url,
+      data: {
+        ...data,
+        ...commonData
+      },
+      header: {
+        'content-type': 'application/x-www-form-urlencoded'
+      },
+      success: function (res) {
+        if (res.data.code == 0) {
+          // console.log(`request ${urls[key]}, success:`, res);
+          success(res);
+
+        } else if (res.data.code == 102) {
+          // 未登录
+          // Toast.showToast('warn', '请登录后进行下一步操作');
+          wx.showModal({
+            title: '提示',
+            content: '登录才能进行以上操作,确定登录吗?',
+            confirmColor: '#e83828',
+            success: function (res) {
+              if (res.confirm) {
+                wx.navigateTo({
+                  url: '/pages/login_page/index',
+                  success: function (res) {},
+                  fail: function (res) {},
+                  complete: function (res) {},
+                })
+              } else if (res.cancel) {
+                console.log('用户点击取消')
+              }
+            }
+          })
+
+
+          // Toast.showToast('tip', "登录才能进行以上操作", success => {
+
+
+          // })
+          fail(res);
+        } else if (res.data.code == 11) {
+          Toast.showToast('warn', '提交信息不完整');
+          fail(res);
+        } else if (res.data.code == 14) {
+          Toast.showToast('warn', '该展会异常,请联系管理员');
+          fail(res);
+        } else if (res.data.code == 15) {
+          Toast.showToast('warn', '该展会不需要支付');
+          fail(res);
+        } else if (res.data.code == 16) {
+          Toast.showToast('warn', '金额有误');
+          fail(res);
+        } else if (res.data.code == 101) {
+          Toast.showToast('warn', '网络超时,请重新登录');
+          fail(res);
+        } else if (res.data.code == 103) {
+          Toast.showToast('warn', '微信统一下单异常');
+          fail(res);
+        } else if (res.data.code == 104) {
+          Toast.showToast('warn', '获取参数失败,请重新下单');
+          fail(res);
+        } else if (res.data.code == 106) {
+          Toast.showToast('warn', '您已下单,请前往【我的-我的订单】完成支付');
+          fail(res);
+        } else if (res.data.code == 105) {
+          Toast.showToast('warn', '您已经发表过评论,不能重复评论');
+          fail(res);
+        } else if (res.data.code == 107) {
+          Toast.showToast('warn', '账号异常,请重新登录');
+          fail(res);
+        } else if (res.data.code == -1) {
+          Toast.showToast('warn', '请求发送失败');
+          fail(res);
+        } else {
+          Toast.showToast('warn', res.data.msg || '网络超时,请检查网络');
+          fail(res);
+        }
+      },
+      fail: function (res) {
+        fail(res);
+      },
+      complete: function () {
+        complete()
+      }
+    });
+  };
+});
+
+
+module.exports.request = requestFns;
+module.exports.serverName = serverName;
+module.exports.imgServer = imgServer;

+ 235 - 0
pages/user/my_host_course/utils/util.js

@@ -0,0 +1,235 @@
+const QQMapWX = require('../common/component/mapSDK/qqmap-wx-jssdk.min.js');
+const app = require('../app.js');
+
+var regChar = { //非特殊字符作为值
+  '?':'qweqwqjoijweq',
+  '&':'asdauihdasfsdas',
+  '=':'fqwebwfubwefqwf'
+}
+
+function formatTime(date) {
+  var year = date.getFullYear();
+  var month = date.getMonth() + 1;
+  var day = date.getDate();
+
+  var hour = date.getHours();
+  var minute = date.getMinutes();
+  var second = date.getSeconds();
+
+  return (
+    [year, month, day].map(formatNumber).join('/') +
+    ' ' +
+    [hour, minute, second].map(formatNumber).join(':')
+  );
+}
+function formatTimeTxt(year, month, day) {
+  return [year, month, day].map(formatNumber).join('');
+}
+function formatNumber(n) {
+  n = n.toString();
+  return n[1] ? n : '0' + n;
+}
+function makeNumToHour(n) {
+  return formatNumber(n) + ':00';
+}
+function makeHourToNum(t) {
+  return parseInt(t.toString().split(':')[0]);
+}
+function makeNumToDay(n) {
+  return '周' + '日一二三四五六'[n];
+}
+function makeNumToFullTimeArr(n) {
+  // 20171010
+  n = n.toString();
+  let year = n.substring(0, 4);
+  let month = n.substring(4, 6);
+  let date = n.substring(6, 8);
+  return [year, month, date];
+}
+function isPhoneNum(txt) {
+  return /^1[34578]\d{9}$/.test(txt);
+}
+function arrUniqueFilter(arr) {
+  return arr.filter((item, pos, array) => array.indexOf(item) === pos);
+}
+function bindInput(event) {
+  var obj = {},
+    key = event.target.dataset['key'];
+  // Toast.showToast('success', event.detail.value);
+  obj[key] = event.detail.value;
+  this.setData(obj);
+  // console.log(obj[key])
+}
+function encodeParam(str){
+  var encode = [];
+  var tempSwitch = false
+  for (let i = 0; i < str.length; i++) {
+    Object.keys(regChar).forEach(function(key){
+      if (str.charAt(i) === key){
+        encode.push(regChar[key]);
+        tempSwitch = true
+        return;
+      }
+    })
+    if (!tempSwitch){
+      encode.push(str.charAt(i))
+    }
+    tempSwitch = false
+  }
+  return encode.join('')
+}
+
+function decodeParam(str) {
+  var keyReg = ''
+  Object.keys(regChar).forEach(function (key) {
+    keyReg = new RegExp(regChar[key],'g')
+    // console.log(regChar[key])
+    str = str.replace(keyReg, key)
+  })
+  return str
+}
+function removeArrItem(arr, item) {
+  var newarr = [];
+  for (var i = 0; i < arr.length; i++) {
+    if (arr[i] != item) {
+      newarr.push(arr[i]);
+    }
+  }
+  return newarr;
+}
+class Timer {
+  constructor({ max, delay = 1000 }) {
+    console.log(max, delay);
+    this.timer = null;
+    this.max = max;
+    this.delay = delay;
+  }
+  run(cb) {
+    this.timer = setInterval(() => {
+      if (this.max >= 0) {
+        cb && cb(this.max--);
+      } else {
+        this.cancel();
+      }
+    }, this.delay);
+  }
+  cancel() {
+    this.timer && clearInterval(this.timer);
+  }
+}
+class Toast {
+  constructor() {
+    // this.successImage = 'images/icon-success.png';
+    // this.warnImage = '../../../images/icon-warn.png';
+    // this.loadingImage = 'images/icon-loading.png';
+    this.image = {
+      success: '../../../images/icon-success.png',
+      warn: '../../../images/icon-warn.png',
+      loading: '../../../images/icon-loading.png'
+    };
+  }
+  showToast(type = 'success', title, success = () => { }) {
+    let imgUrl = '';
+    let t = '';
+    switch (type) {
+      case 'success':
+      case 'tip':
+        wx.showModal({
+          title: '提示',
+          content: title,
+          showCancel: false,
+          confirmColor: '#e83828',
+          success
+        });
+        break;
+      case 'warn':
+        // imgUrl = this.warnImage;
+        t = type == 'success' ? '成功' : '提示';
+        wx.showModal({
+          title: t,
+          content: title,
+          showCancel: false,
+          confirmColor: '#e83828',
+          success
+        });
+        break;
+      case 'loading':
+        wx.showToast({
+          //title: '手机号码输入错误',
+          title: title || '加载中...',
+          icon: type,
+          mask: true
+        });
+        break;
+    }
+  }
+  showToast2(type = 'success', title = '') {
+    switch (type) {
+      case 'loading':
+        wx.showLoading({
+          mask: true,
+          title: title || '加载中...'
+        });
+        break;
+      case 'success':
+      case 'warn':
+      default:
+        wx.showToast({
+          //title: '手机号码输入错误',
+          title: title,
+          icon: type,
+          image: this.image[type],
+          mask: true
+        });
+        break;
+    }
+  }
+  hideLoading() {
+    wx.hideLoading();
+  }
+}
+//记录访问id 存储在全局
+function recordAccess(options){
+  if(!options.id)return;
+  let {
+    cookieIDs = []
+  } = app.default.globalData;
+  let id = options.id;
+
+  for (let i = 0; i < cookieIDs.length; i++) {
+    if (cookieIDs[i] && id == cookieIDs[i]) {
+      cookieIDs = removeArrItem(cookieIDs, cookieIDs[i])
+    }
+  }
+
+  if (id != undefined && (typeof (Number(id)) == 'number')) {
+    cookieIDs.unshift(id)
+  }
+  console.log(id)
+
+  app.default.globalData.cookieIDs = cookieIDs
+
+  console.log(app.default.globalData.cookieIDs)
+}
+
+module.exports = {
+  formatTime,
+  removeArrItem,
+  formatTimeTxt,
+  formatNumber,
+  isPhoneNum,
+  makeNumToHour,
+  makeHourToNum,
+  makeNumToDay,
+  makeNumToFullTimeArr,
+  arrUniqueFilter,
+  Timer,
+  bindInput,
+  encodeParam,
+  decodeParam,
+  recordAccess,
+  Toast: new Toast(),
+  qqmapsdk: new QQMapWX({
+    key: '2Z3BZ-H7EWO-F4YWX-SG5JF-2VOK2-S2FUB'
+  })
+};

+ 16 - 24
pages/user/personal/personal.js

@@ -43,22 +43,13 @@ Page({
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
-  onReady() {
-
-
-  },
+  onReady() {},
 
   /**
    * 生命周期函数--监听页面显示
    */
   async onShow() {
-    // const isLogin = wx.getStorageSync('isLogin')
-    // const app = getApp();
-    // this.setData({
-    //   isLogin: isLogin
-    // })
-    // app.globalData.isLogin = isLogin
-    // await getUserInfo();
+
   },
 
   /**
@@ -147,20 +138,18 @@ Page({
         //   encryptedData: encryptedData
         // })
         const userInfo = wx.getStorageSync('userInfo')
-        console.log('decrptPhone', code, userInfo.id)
-        const res = await decrptPhone(code, userInfo.id)
-        console.log('res', res)
+        console.log('decrptPhone', code)
+        const res = await decrptPhone(code)
+        console.log('手机号', res.data.phoneNumber)
         if (res.code === 0) {
-          const result = await updateUserInfo({
-            phoneNumber: res.phoneNumber
+          const res = await updateUserInfo({
+            phone: res.data.phoneNumber
+          })
+          console.log('更新后', res)
+          wx.showToast({
+            title: '更新成功!',
           })
-          if (result.code === 0) {
-            await getUserInfo();
-          } else {
-            wx.showToast({
-              title: result.message
-            });
-          }
+          this.syncUserInfo(res.data);
         }
       }
     }
@@ -189,7 +178,7 @@ Page({
       console.log('index', index)
 
       const res = await updateUserInfo({
-        gender: index + 1
+        gender: Number(index) + 1
       })
       if (res.code === 0) {
         this.syncUserInfo(res.data)
@@ -243,6 +232,9 @@ Page({
       }
       console.log('syncUserInfo', mergeObj)
       wx.setStorageSync('userInfo', mergeObj)
+      this.setData({
+        userInfo: mergeObj
+      })
     }
   },
   handleCancel() {

+ 3 - 1
pages/user/personal/personal.wxml

@@ -1,5 +1,6 @@
 <!--pages/personal/personal.wxml-->
 <view class="personal-view">
+
   <!-- {{userInfo.avatarUrl}} -->
   <t-cell title="头像" arrow hover>
 
@@ -22,6 +23,7 @@
   </t-cell>
 
   <t-cell title="性别" hover arrow>
+
     <view slot='note'>
       <text wx:if="{{userInfo.gender == 1}}" bind:tap="handleSexSelectShow">男</text>
       <text wx:if="{{userInfo.gender == 2}}" bind:tap="handleSexSelectShow">女</text>
@@ -32,7 +34,7 @@
 
   <t-cell title="绑定手机" hover arrow>
     <view slot='note'>
-      <text wx:if="{{userInfo.phoneNumber}}">{{userInfo.phoneNumber}}</text>
+      <text wx:if="{{userInfo.phone}}">{{userInfo.phone}}</text>
       <t-button wx:else class="phone" variant="text" size="small" open-type="getPhoneNumber"
         bindgetphonenumber="handleGetPhoneNumber">点击绑定</t-button>
     </view>

+ 3 - 3
utils/request.js

@@ -44,9 +44,9 @@ export async function getMyHostlesson(wxUserId) {
   return await (await wxRequest.get(urls.getMyHostlesson + wxUserId)).data;
 }
 
-export async function decrptPhone(code, wxUserId) {
-  console.log('decrptPhone-params', code, wxUserId)
-  const url = `${urls.getPhone}/${code}/${wxUserId}`
+export async function decrptPhone(code) {
+  console.log('decrptPhone-params', code,)
+  const url = `${urls.getPhone}/${code}`
   console.log('decrptPhone-url', url)
   return await (await wxRequest.get(url)).data;
 }