LiuShu_0203 1 kuukausi sitten
vanhempi
commit
f981a63a41

+ 1 - 1
app.js

@@ -23,7 +23,7 @@ App({
           } else if (res.cancel) {
             // 老师:跳转到老师端小程序 
             wx.navigateToMiniProgram({
-              appId: 'wx06f2b1b09ac5684f', // ⚠️ 替换成实际 appId 
+              appId: 'wx1ee76fb4846f8901', // ⚠️ 替换成实际 appId 
               path: 'pages/logins/logins',
             });
           }

+ 15 - 0
pages/index/index.js

@@ -125,6 +125,21 @@ Page({
     });
   }, 
 
+  onShareAppMessage() {
+    return {
+      title: '红孩儿智慧教育',
+      path: '/pages/index/index', // 分享落地页
+      // imageUrl: // 可以自定义封面图
+    }
+  },
+  // 分享到朋友圈
+  onShareTimeline() {
+    return {
+      title: '红孩儿智慧教育',
+      query: 'from=timeline'
+    }
+  },
+
   // 上传轮播图  存储轮播图图片地址 和展示位置  后续需要存一个上传的图片名字
   // async getData() {
   //   try {

+ 67 - 27
pages/login/login.js

@@ -152,38 +152,78 @@ Page({
         return
       }
 
+      let models = await getModels()
 
-      const models = await getModels()
-      const { data } = await models.wx_user.create({
-        data: {
-          img: "",  // 头像
-          gender: 1,  // 性别
-          teacher_id: "",  // 老师id
-          user_name: this.data.contactsname,  // 用户名
-          remark: "",  // 备注
-          delete: 0,  // 逻辑删除
-          school_id: this.data.selected._id,  // 学校id
-          phone: this.data.phone,  // 手机号
-          grade: this.data.selectedLevelIndex,  // 班级
-          log_off: "",  // 注销原因
-          name: this.data.contactsname,  // 姓名
+      const { data } = await models.wx_user.get({
+        filter: {
+          where: {
+            $and: [
+              {
+                delete: {
+                  $eq: 0, // 推荐传入_id数据标识进行操作
+                },
+                phone: {
+                  $eq: this.data.phone,
+                }
+              },
+            ]
+          }
         },
+        // envType: pre 体验环境, prod 正式环境
         envType: "prod",
       });
-  
-      // 注册成功提示
-      wx.showToast({
-        title: '注册成功,去登录',
-        icon: 'success',
-        duration: 1500, // 提示显示 1.5 秒
-      });
-  
-      // 提示消失后跳转到登录页面
-      setTimeout(() => {
-        wx.reLaunch({
-          url: '/pages/logins/logins', // 替换为你的登录页面路径
+      
+      // 返回查询到的数据
+      console.log(data, '69+++++++++++++');
+      if(data && Object.keys(data).length > 0) {
+
+        // 注册成功提示
+        wx.showToast({
+          title: '账号已存在,跳转登录',
+          icon: 'success',
+          duration: 1500, // 提示显示 1.5 秒
+        });
+
+        setTimeout(() => {
+          wx.reLaunch({
+            url: `/pages/logins/logins`,
+          });
+        }, 1500);
+
+      } else {
+
+        const res= await models.wx_user.create({
+          data: {
+            img: "",  // 头像
+            gender: 1,  // 性别
+            teacher_id: "",  // 老师id
+            user_name: this.data.contactsname,  // 用户名
+            remark: "",  // 备注
+            delete: 0,  // 逻辑删除
+            school_id: this.data.selected._id,  // 学校id
+            phone: this.data.phone,  // 手机号
+            grade: this.data.selectedLevelIndex,  // 班级
+            log_off: "",  // 注销原因
+            name: this.data.contactsname,  // 姓名
+          },
+          envType: "prod",
         });
-      }, 1500);
+    
+        // 注册成功提示
+        wx.showModal({
+          title: '注册成功,去登录',
+          icon: 'success',
+          duration: 1500, // 提示显示 1.5 秒
+        });
+  
+        // 提示消失后跳转到登录页面,并把手机号带过去
+        setTimeout(() => {
+          wx.reLaunch({
+            url: `/pages/logins/logins?phone=${this.data.phone}`,
+          });
+        }, 1500);
+
+      }
   
     } catch (error) {
       console.error('注册失败:', error);

+ 64 - 0
pages/logins/logins.js

@@ -3,6 +3,19 @@ import { getDB, getModels, getCommand, getTempFileURLs } from '../../utils/cloud
 Page({
   data: {
     phone: '', // 用户输入的手机号码
+    logins: true
+  },
+
+  async onLoad(options) {
+    if (options.phone) {
+      console.log('注册跳转手机号:', options.phone);
+      this.setData({ 
+        phone: options.phone, 
+        logins: false // 隐藏验证码
+      });
+      // 自动登录
+      await this.autoLogin(options.phone);
+    }
   },
 
   // 监听手机号码输入
@@ -88,5 +101,56 @@ Page({
     wx.switchTab({
       url: '/pages/index/index'
     });
+  },
+
+  // 自动登录逻辑
+  async autoLogin(phone) {
+    try {
+      if (!/^1[3-9]\d{9}$/.test(phone)) {
+        wx.showToast({
+          title: '手机号格式错误',
+          icon: 'none'
+        });
+        return;
+      }
+
+      const models = await getModels();
+      const { data } = await models.wx_user.list({
+        filter: { where: { phone } },
+        pageSize: 100,
+        pageNumber: 1,
+        getCount: true,
+        envType: "prod",
+      });
+
+      const users = data.records || [];
+
+      if (users.length === 0 || users.every(user => user.delete === 1)) {
+        wx.showToast({
+          title: '该手机号未注册,请重新注册',
+          icon: 'none'
+        });
+        return;
+      }
+
+      // 找到有效账号
+      const validUser = users.find(user => user.delete === 0);
+      wx.setStorageSync('userInfo', validUser);
+
+      wx.showToast({
+        title: '登录成功',
+        icon: 'success'
+      });
+
+      wx.switchTab({
+        url: '/pages/index/index'
+      });
+    } catch (err) {
+      console.error('自动登录失败:', err);
+      wx.showToast({
+        title: '登录失败,请稍后重试',
+        icon: 'none'
+      });
+    }
   }
 })

+ 2 - 2
pages/logins/logins.wxml

@@ -13,10 +13,10 @@
     <view class="input-group">
       <label>手机号码</label>
       <view>
-        <input bindinput="onInputPhone" type="text" placeholder="请输入常用的手机号码" />
+        <input bindinput="onInputPhone" type="text" value="{{phone}}" placeholder="请输入常用的手机号码" />
       </view>
     </view>
-    <captcha id="loginCaptcha" phone="{{phone}}" />
+    <captcha wx:if="{{logins === true}}" id="loginCaptcha" phone="{{phone}}" />
     <navigator url="/pages/login/login" open-type="navigate">您还没有账号,去注册</navigator>
     <button bindtap="onConfirm" class="confirm-btn">登录</button>
   </view>

+ 33 - 0
pages/me/me.js

@@ -381,5 +381,38 @@ Page({
       });
     }
 
+  },
+
+  // 退出登录
+  handleTuichu() {
+    wx.showModal({
+      title: '提示',
+      content: '确定要退出登录吗?',
+      success: (res) => {
+        if (res.confirm) {
+          // 1. 清空本地缓存
+          wx.removeStorageSync('userInfo');
+
+          // 2. 给全局 app.js 里也同步清除(如果有保存全局数据)
+          const app = getApp();
+          if (app.globalData) {
+            app.globalData.userInfo = null;
+          }
+
+          // 3. 提示退出成功
+          wx.showToast({
+            title: '已退出登录',
+            icon: 'success'
+          });
+
+          // 4. 跳转回登录页(比如你的小程序登录页是 /pages/login/login)
+          setTimeout(() => {
+            wx.reLaunch({
+              url: '/pages/logins/logins'
+            });
+          }, 800);
+        }
+      }
+    });
   }
 });

+ 4 - 1
pages/me/me.wxml

@@ -62,7 +62,10 @@
     </view>
 
     <!-- 用户注销 -->
-    <button class="logout-btn" size="default" bindtap="handleLogout">用户注销</button>
+    <view style="display: flex; justify-content: space-between;">
+      <button class="logout-btn logout-btnons" size="default" bindtap="handleTuichu">退出登录</button>
+      <button class="logout-btn logout-btns" size="default" bindtap="handleLogout">用户注销</button>
+    </view>
 
     <!-- <custom-tabbar role="{{role}}" selected="{{2}}" /> -->
 </view>

+ 14 - 3
pages/me/me.wxss

@@ -151,14 +151,25 @@ margin-top: 30rpx;
 }
 
 .logout-btn {
-  width: 100%;
+  margin: 0 20rpx !important;
+  /* width: 100% !important; */
   height: 80rpx;
-  background-color: #007aff;
-  color: #fff;
   font-size: 32rpx;
   border-radius: 40rpx;
 }
 
+.logout-btns {
+  background-color: #007aff;
+  border: 1rpx solid #007aff;
+  color: #fff;
+}
+
+.logout-btnons {
+  border: 1rpx solid #007aff;
+  background-color: #fff;
+  color: #007aff;
+}
+
 .xiazai_img {
   width: 45rpx;
   height: 40rpx;

+ 6 - 1
project.config.json

@@ -3,7 +3,12 @@
   "cloudfunctionRoot": "cloud/",
   "libVersion": "3.8.10",
   "packOptions": {
-    "ignore": [],
+    "ignore": [
+      {
+        "type": "folder",
+        "value": "cloud"
+      }
+    ],
     "include": []
   },
   "setting": {

+ 59 - 2
subpackages/details/details.js

@@ -18,9 +18,17 @@ Page({
     isCollected: false,
     isPlaying: false,
     isAudioPlaying: false,
+    enterTime: null, // 进入时间
   },
 
   async onLoad(options) {
+
+    // 进入时间
+    const now = new Date();
+    this.setData({
+      enterTime: now
+    });
+
     // 获取传递过来的数据
     const itemStr = decodeURIComponent(options.item);
     const item = JSON.parse(itemStr);
@@ -294,7 +302,7 @@ Page({
   const extension = fileUrl.substring(fileUrl.lastIndexOf('.') + 1).toLowerCase();
 
   // 文档类文件需要下载
-  if (['pdf', 'ppt', 'pptx'].includes(extension)) {
+  if (['pdf', 'ppt', 'pptx', 'xls', 'xlsx'].includes(extension)) {
     try {
       let downloadUrl = fileUrl;
       
@@ -458,10 +466,59 @@ Page({
     }
   },
 
-  onHide() {
+  async onUnload() {
+    await this.saveUserBehavior();
+    if (this.audioContext) {
+      this.audioContext.stop();
+      this.audioContext.destroy();
+      this.audioContext = null;
+    }
+  },
+
+  async onHide() {
+    await this.saveUserBehavior();
     if (this.audioContext) {
       this.audioContext.pause();
     }
   },
 
+  async saveUserBehavior() {
+    try {
+      const userInfo = wx.getStorageSync('userInfo');
+      const userId = userInfo && userInfo._id ? userInfo._id : '';
+      
+      const startTime = this.data.enterTime;
+      if (!startTime) return; // 如果没进入过,不存
+
+      const endTime = new Date();
+      // 转换为时间戳(毫秒 → 秒)
+      const startTimestamp = new Date(startTime).getTime();
+      const endTimestamp = new Date().getTime();
+
+      const duration = endTimestamp - startTimestamp;
+
+      const models = await getModels()
+      await models.monitor_behavior.create({
+        data: {
+          start_time: startTimestamp, // 数字
+          end_time: endTimestamp,     // 数字
+          duration: duration,         // 数字
+          type: 1,                    // 固定 0
+          user_id: userId || 'guest'
+        },
+        envType: "prod",
+      });
+  
+      console.log("监控数据保存成功:", {
+        start_time: startTimestamp,
+        end_time: endTimestamp,
+        duration,
+        type: 0,
+        user_id: userId || 'guest'
+      });
+    } catch (err) {
+      console.error("监控数据保存失败", err);
+    }
+  }
+
 })

+ 1 - 1
subpackages/details/details.wxml

@@ -49,7 +49,7 @@
         <view class="card"  bindtap="goToGoodsList" data-item="{{item}}">
           <view class="cardimg">
             <image style="width: 100%; height: 100%;" src="{{item.coverUrl}}" />
-            <view class="label {{item.type === 0 ? 'shipin' : item.type === 1 ? 'yinpin' : item.type === 2 ? 'PDF' : item.type === 3 ? 'PPT' : '图文'}} labelwg" >{{item.type === 0 ? '视频' : item.type === 1 ? '音频' : item.type === 2 ? 'PDF' : item.type === 3 ? 'PPT' : '图文'}}</view>
+            <view class="label {{item.type === 0 ? 'shipin' : item.type === 1 ? 'yinpin' : item.type === 2 ? 'PDF' : item.type === 3 ? 'PPT' : '图文'}} labelwg" >{{item.type === 0 ? '视频' : item.type === 1 ? '音频' : item.type === 2 ? 'PDF' : item.type === 3 ? 'PPT' : item.type === 4 ? '图文' : 'Excel'}}</view>
           </view>
           <view class="item-content">
             <view class="item-title">{{item.name}}</view>