LiuShu_0203 1 kuukausi sitten
vanhempi
commit
5e8e16a184

+ 5 - 2
app.json

@@ -12,15 +12,18 @@
     "pages/me/me",
     "pages/login/login",
     "pages/logins/logins",
-    "components/float/float"
+    "components/float/float",
+    "custom-tab-bar/index"
   ],
   "window": {
     "navigationBarTextStyle": "black",
     "navigationBarTitleText": "红孩儿智慧教育",
     "navigationBarBackgroundColor": "#ffffff"
   },
+  "custom-tab-bar": "custom-tab-bar",
   "tabBar": {
-    "custom": false,
+    "custom": true,
+    "color": "#7A7E83",
     "selectedColor": "#409eff",
     "list": [
       {

+ 91 - 0
custom-tab-bar/index.js

@@ -0,0 +1,91 @@
+const app = getApp();
+
+Component({
+  data: {
+    selected: 0,
+    list: [
+      {
+        pagePath: "/pages/index/index",
+        text: "教学",
+        iconPath: "/image/shouye.png",
+        selectedIconPath: "/image/shouye_1.png"
+      },
+      {
+        pagePath: "/pages/groupbuying/groupbuying",
+        text: "团购",
+        iconPath: "/image/tuangou.png",
+        selectedIconPath: "/image/tuangou_1.png"
+      },
+      {
+        pagePath: "/pages/shoppingcart/shoppingcart",
+        text: "购物车",
+        iconPath: "/image/gouwuche.png",
+        selectedIconPath: "/image/gouwuche_1.png"
+      },
+      {
+        pagePath: "/pages/me/me",
+        text: "我的",
+        iconPath: "/image/me.png",
+        selectedIconPath: "/image/my_1.png"
+      }
+    ]
+  },
+  methods: {
+    onTabTap(e) {
+      const index = e.currentTarget.dataset.index;
+      const target = this.data.list[index];
+
+      // 判断登录状态
+      const isLoggedIn = wx.getStorageSync('userInfo');
+      if (!isLoggedIn && index !== 0) {
+        wx.showModal({
+          title: '登录身份选择',
+          content: '请选择您的身份以完成登录',
+          confirmText: '我是老师',
+          cancelText: '我是家长',
+          success: (res) => {
+            if (res.confirm) {
+              wx.navigateTo({
+                url: '/pages/logins/logins'
+              });
+            } else if (res.cancel) {
+              wx.navigateToMiniProgram({
+                appId: 'wx06f2b1b09ac5684f',
+                path: 'pages/logins/logins',
+              });
+            }
+          }
+        });
+        return;
+      }
+      // if (!isLoggedIn && index !== 0) {
+      //   // 非首页才拦截
+      //   wx.showModal({
+      //     title: '绑定手机号',
+      //     content: '防止账号丢失以及方便找回,建议您绑定手机号码',
+      //     confirmText: '去绑定',
+      //     cancelText: '取消',
+      //     success(res) {
+      //       if (res.confirm) {
+      //         wx.navigateTo({
+      //           url: '/pages/logins/logins'
+      //         });
+      //       }
+      //     }
+      //   });
+      //   return;
+      // }
+
+      // 切换 tab 页
+      wx.switchTab({
+        url: target.pagePath
+      });
+      this.setData({ selected: index });
+    },
+
+    // 支持外部更新选中项
+    setSelected(index) {
+      this.setData({ selected: index });
+    }
+  }
+});

+ 3 - 0
custom-tab-bar/index.json

@@ -0,0 +1,3 @@
+{
+  "component": true
+}

+ 8 - 0
custom-tab-bar/index.wxml

@@ -0,0 +1,8 @@
+<view class="tab-bar">
+  <block wx:for="{{list}}" wx:key="index">
+    <view class="tab-item {{selected === index ? 'active' : ''}}" bindtap="onTabTap" data-index="{{index}}">
+      <image class="tab-icon" src="{{selected === index ? item.selectedIconPath : item.iconPath}}" />
+      <text class="tab-text">{{item.text}}</text>
+    </view>
+  </block>
+</view>

+ 33 - 0
custom-tab-bar/index.wxss

@@ -0,0 +1,33 @@
+.tab-bar {
+  position: fixed;
+  bottom: 0;
+  left: 0;
+  right: 0;
+  height: 100rpx;
+  background-color: #ffffff;
+  display: flex;
+  justify-content: space-around;
+  align-items: center;
+  border-top: 1rpx solid #e5e5e5;
+  z-index: 1000;
+}
+
+.tab-item {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: center;
+  flex: 1;
+  padding: 10rpx 0;
+  color: #7A7E83;
+  font-size: 24rpx;
+}
+
+.tab-item.active {
+  color: #409eff; /* 可自定义为 app.json 中配置的 selectedColor */
+}
+
+.tab-icon {
+  width: 54rpx;
+  height: 54rpx;
+}

+ 31 - 2
pages/groupbuying/groupbuying.js

@@ -11,10 +11,18 @@ Page({
     hasMore: true, // 是否还有更多数据
     isLoading: false, // 防止多次触发
     types_ids: null, // 当前选中的分类 tag_id
+    searchText: '', // 搜索关键词
   },
-  onLoad(options) {
+
+  onShow() {
+    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
+      this.getTabBar().setSelected(1); // 比如首页就是 0
+    }
     // 获取tab数据
     this.getTabdata();
+  },
+
+  onLoad(options) {
 
     const fileIDs = [
       'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/sou.png',
@@ -73,6 +81,19 @@ Page({
     this.getDatalist(this.data.types_ids, true);
   },
 
+  // 模糊搜索
+  onSearchInput(e) {
+    const keyword = e.detail.value.trim();
+    this.setData({
+      searchText: keyword,
+      pageNumber: 1,
+      hasMore: true,
+      goods: []
+    }, () => {
+      this.getDatalist(this.data.types_ids); // 重新加载
+    });
+  },
+
   // 列表数据
   async getDatalist(tag_id = null, isLoadMore = false) {
   
@@ -87,7 +108,15 @@ Page({
       where.tag_id = tag_id; // 仅在 tag_id 有值时添加
     }
 
-    const { pageNumber, pageSize } = this.data;
+    const { pageNumber, pageSize, searchText } = this.data;
+
+    // 模糊搜索关键字
+    if (searchText) {
+      where.name = {
+        $regex_ci: searchText
+      };
+    }
+
     const { data } = await models.wx_merchandise.list({
       filter: { where },
       pageSize,

+ 1 - 1
pages/groupbuying/groupbuying.wxml

@@ -1,7 +1,7 @@
 <view style="background: #f5f5f5; padding: 20rpx 0;">
   <view class="goodslist_boxs">
     <view class="search-bar">
-      <input class="search-input" placeholder="搜索商品" />
+      <input class="search-input" placeholder="搜索商品" bindinput="onSearchInput" value="{{searchText}}" />
       <image class="search-icon" src="{{souimg}}" />
     </view>
     <view class="title_1">商品分类</view>

+ 17 - 2
pages/index/index.js

@@ -16,8 +16,13 @@ Page({
   },
 
   onShow() {
-    // 检查登录状态
-    app.checkLoginStatus();
+
+    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
+      this.getTabBar().setSelected(0); // 首页索引是0
+    }
+
+    // // 检查登录状态
+    // app.checkLoginStatus();
     // 获取轮播图数据
     this.getBanner();
     // 获取图片
@@ -72,6 +77,9 @@ Page({
 
   // 页面跳转  二级页面
   selectGroupOption(e) {
+    const isLoggedIn = app.checkLoginStatus(); // 检查是否登录
+    if (!isLoggedIn) return; // 未登录已跳转,不继续
+    
     const option = e.currentTarget.dataset.option;
     let url = '';
   
@@ -97,6 +105,13 @@ Page({
     });
   },
 
+  // 搜索框跳转
+  goSearchPage() {
+    wx.navigateTo({
+      url: '/subpackagestow/course/course?type=1&autofocus=1'
+    });
+  },  
+
   // async 
   getData() {
     // const { data } = await models.login.list({

+ 2 - 2
pages/index/index.wxml

@@ -1,8 +1,8 @@
 <view style="background: #f5f5f5; padding: 20rpx 0;">
   <view class="container">
     <!-- 搜索 -->
-    <view class="search-bar">
-      <input class="search-input" placeholder="搜索课件" />
+    <view class="search-bar" bindtap="goSearchPage">
+      <input class="search-input" placeholder="搜索课件" disabled />
       <image class="search-icon" src="{{souimg}}" />
     </view>
     

+ 4 - 0
pages/me/me.js

@@ -14,6 +14,10 @@ Page({
   },
 
   onShow() {
+    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
+      this.getTabBar().setSelected(3); // 比如首页就是 0
+    }
+
     // 每次进入页面都会触发
     this.getUserInfo();
     this.getcollect();

+ 6 - 0
pages/shoppingcart/shoppingcart.js

@@ -23,6 +23,12 @@ Page({
     souimg: '',
   },
 
+  onShow() {
+    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
+      this.getTabBar().setSelected(2); // 比如首页就是 0
+    }
+  },
+
   onLoad() {
     this.updateTotalPrice();
 

+ 110 - 22
subpackages/productdetails/productdetails.js

@@ -1,22 +1,29 @@
+import { models, db, _ } from '../../utils/cloudbase.js'
 Page({
   data: {
     item: {},
-    selectedSpec: '基础款(50粒)',
     quantity: 1,
     showimg: '',
     gouwucimg: '',
     gaoliao: 0,
+    fenxiangljimg: '',
+    shareType: '' // 用于区分是老师还是家长
   },
   onLoad(options) {
+    const from = options.from || '';
     console.log('进了');
     const itemData = decodeURIComponent(options.data);
     const item = JSON.parse(itemData);
     this.setData({
-      item: item
+      item: item,
+      from
+    }, () => {
+      this.getbrowse()
     });
 
     const fileIDs = [
       'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/show.png',
+      'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/fenxianglj.png'
       // 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/gouwuc_img.png'
     ];
     
@@ -29,6 +36,7 @@ Page({
       console.log('全部下载成功:', tempFilePaths);
       this.setData({
         showimg: tempFilePaths[0],
+        fenxiangljimg: tempFilePaths[1]
         // gouwucimg: tempFilePaths[1]
       });
     }).catch(err => {
@@ -36,29 +44,109 @@ Page({
     });
   },
 
-  handleSpecSelect(e) {
-    const spec = e.currentTarget.dataset.spec;
-    this.setData({ selectedSpec: spec });
+  // 新增浏览量
+  async getbrowse() {
+    const { data } = await models.wx_merchandise.update({
+      data: {
+          browse: this.data.item.browse + 1,  // 浏览数
+        },
+      filter: {
+        where: {
+          $and: [
+            {
+              _id: {
+                $eq: this.data.item._id, // 推荐传入_id数据标识进行操作
+              },
+            },
+          ]
+        }
+      },
+      // envType: pre 体验环境, prod 正式环境
+      envType: "prod",
+    });
+    
+    // 返回更新成功的条数
+    console.log(data, 'datadata');
+    this.setData({
+      'item.browse': this.data.item.browse + 1
+    })
   },
-  
-  handleQuantityChange(e) {
-    const action = e.currentTarget.dataset.action;
-    let quantity = this.data.quantity;
-    if (action === 'plus') {
-      quantity++;
-    } else if (action === 'minus' && quantity > 1) {
-      quantity--;
+
+  previewImage(e) {
+    const index = e.currentTarget.dataset.index;
+    const images = this.data.item.detail_images;
+    wx.previewImage({
+      current: images[index],  // 当前预览的图片
+      urls: images             // 所有可预览的图片列表
+    });
+  },
+
+  // 点击分享图标
+  onShareTap() {
+    wx.showActionSheet({
+      itemList: ['分享给老师', '分享给家长'],
+      success: (res) => {
+        const shareType = res.tapIndex === 0 ? 'teacher' : 'parent';
+        this.setData({ shareType });
+
+        wx.showModal({
+          title: '提示',
+          content: '请点击右上角“···”按钮,选择“发送给朋友”进行分享',
+          showCancel: false
+        });
+      },
+      fail: (err) => {
+        console.log('取消选择', err);
+      }
+    });
+  },
+
+  // 配置微信分享信息
+  onShareAppMessage() {
+    const { item, shareType } = this.data;
+
+    let title = '';
+    let path = '';
+
+    if (shareType === 'teacher') {
+      title = '老师推荐的优质商品,快来看!';
+      path = `/subpackages/productdetails/productdetails?data=${encodeURIComponent(JSON.stringify(item))}&from=teacher`;
+    } else {
+      title = '家长推荐的宝藏商品,别错过!';
+      path = `/subpackages/productdetails/productdetails?data=${encodeURIComponent(JSON.stringify(item))}&from=parent`;
     }
-    this.setData({ quantity });
+
+    return {
+      title,
+      path,
+      imageUrl: item.detail_images?.[0] || ''
+    };
   },
   
-  addToCart() {
-    // 加入购物车逻辑
-    console.log('加入购物车');
-  },
+
+  // handleSpecSelect(e) {
+  //   const spec = e.currentTarget.dataset.spec;
+  //   this.setData({ selectedSpec: spec });
+  // },
+  
+  // handleQuantityChange(e) {
+  //   const action = e.currentTarget.dataset.action;
+  //   let quantity = this.data.quantity;
+  //   if (action === 'plus') {
+  //     quantity++;
+  //   } else if (action === 'minus' && quantity > 1) {
+  //     quantity--;
+  //   }
+  //   this.setData({ quantity });
+  // },
+  
+  // addToCart() {
+  //   // 加入购物车逻辑
+  //   console.log('加入购物车');
+  // },
   
-  buyNow() {
-    // 立即购买逻辑
-    console.log('立即购买');
-  }
+  // buyNow() {
+  //   // 立即购买逻辑
+  //   console.log('立即购买');
+  // }
 });

+ 5 - 4
subpackages/productdetails/productdetails.wxml

@@ -5,10 +5,12 @@
       <swiper style="width: 100%; height: 100%;" autoplay="true" interval="3000" circular>
         <block wx:for="{{item.detail_images}}" wx:key="index">
           <swiper-item>
-            <image style="width: 100%; height: 100%;" src="{{item}}" mode="aspectFill" />
+            <image style="width: 100%; height: 100%;" src="{{item}}" mode="aspectFill"
+            bindtap="previewImage" data-index="{{index}}" />
           </swiper-item>
         </block>
       </swiper>
+      <image bindtap="onShareTap" class="fenxiangljimg" src="{{fenxiangljimg}}" mode=""/>
     </view>
     
     <!-- 商品价格和浏览量 -->
@@ -30,7 +32,7 @@
     <view class="specifications">
       <text style="font-size: 38rpx;">选择规格</text>
       <view class="specifications_boxs">
-        <button wx:for="{{item.specs}}" class="spec-btn {{gaoliao === index ? 'active' : ''}}">{{item}}</button>
+        <button wx:for="{{item.specs}}" wx:key="index" class="spec-btn {{gaoliao === index ? 'active' : ''}}">{{item}}</button>
       </view>
     </view>
     
@@ -48,8 +50,7 @@
     <view class="product-details">
       <text style="font-size: 38rpx;">产品详情</text>
       <view class="details-list">
-        <text wx:for="{{item.details}}">• {{item}}</text>
-        
+        <text wx:for="{{item.details}}" wx:key="index">• {{item}}</text>
       </view>
     </view>
     

+ 9 - 0
subpackages/productdetails/productdetails.wxss

@@ -10,6 +10,15 @@
   background-color: #e0e0e0;
   margin-top: 20rpx;
   border-radius: 12rpx;
+  position: relative;
+}
+
+.fenxiangljimg {
+  position: absolute;
+  right: 20rpx;
+  top: 20rpx;
+  width: 55rpx;
+  height: 55rpx;
 }
 
 .goods-image {

+ 40 - 7
subpackagestow/course/course.js

@@ -19,11 +19,21 @@ Page({
     pageSize: 10,
     hasMore: true, // 是否还有更多数据
     isLoading: false, // 防止多次触发
+    searchText: '', // 搜索关键词
+    inputFocus: false,
   },
 
   onLoad(options) {
-    // 存储 options 到 this 中
+     // 存储 options 到 this 中
     this.options = options;
+    if (options.autofocus === '1') {
+      // 延迟设置 focus,让页面完成渲染
+      setTimeout(() => {
+        this.setData({
+          inputFocus: true
+        });
+      }, 300); // 300ms 通常足够
+    }
 
     // 获取tab数据
     this.getTabdata();
@@ -106,17 +116,40 @@ Page({
     console.log('加载更多');
     this.getdatalist(true);
   },
+
+    // 模糊搜索
+    onSearchInput(e) {
+      const keyword = e.detail.value.trim();
+      this.setData({
+        searchText: keyword,
+        pageNumber: 1,
+        hasMore: true,
+        goods: []
+      }, () => {
+        this.getdatalist(this.data.types_ids); // 重新加载
+      });
+    },
+
   // 列表数据
   async getdatalist(isLoadMore = false) {
     if (!this.data.categorieslist._id) return; // 防止 _id 为 undefined
   
-    const { pageNumber, pageSize } = this.data;
+     const { pageNumber, pageSize, searchText } = this.data;
+
+     // 构造 where 条件
+    const where = {
+      tag_id: this.data.categorieslist._id,
+    };
+
+    // 模糊搜索关键字
+    if (searchText) {
+      where.name = {
+        $regex_ci: searchText
+      };
+    }
+
     const { data } = await models.file_manage.list({
-      filter: {
-        where: {
-          tag_id: this.data.categorieslist._id,
-        }
-      },
+      filter: { where },
       pageSize,
       pageNumber,
       getCount: true,

+ 7 - 1
subpackagestow/course/course.wxml

@@ -4,7 +4,13 @@
     <!-- <view class="containers"> -->
       <!-- 搜索框 -->
       <view class="search-bar">
-        <input class="search-input" placeholder="搜索" />
+        <input
+          class="search-input"
+          placeholder="搜索"
+          bindinput="onSearchInput"
+          value="{{searchText}}"
+          focus="{{inputFocus}}"
+        />
         <image class="search-icon" src="{{sou}}" />
       </view>
     <!-- </view> -->

+ 143 - 8
subpackagestow/details/details.js

@@ -28,10 +28,29 @@ Page({
     this.setData({
       itemlist: item
     }, () => {
+      // 转换云文件ID为临时链接
+    if (item.url && item.url.length > 0) {
+      wx.cloud.getTempFileURL({
+        fileList: [item.url[0]],
+        success: res => {
+          if (res.fileList && res.fileList.length > 0) {
+            this.setData({
+              'itemlist.playUrl': res.fileList[0].tempFileURL
+            });
+          }
+        },
+        fail: err => {
+          console.error('获取临时链接失败', err);
+        }
+      });
+    }
+
       // 收藏
       this.getcollect()
       // 相关推荐
       this.getcourseList()
+      // 加访问量
+      this.getvisits()
     });
     
     // 获取图片
@@ -195,7 +214,7 @@ Page({
           });
         } else if (['mp3', 'aac', 'wav'].includes(extension)) {
           console.log('这是一个音频文件,可以跳转到播放页面或使用音频组件');
-          // this.toggleAudio()
+          this.toggleAudio()
         } else if (['mp4', 'mov'].includes(extension)) {
           console.log('这是一个视频文件,可以跳转到视频播放页');
           this.toggleVideo()
@@ -225,14 +244,130 @@ Page({
   },
   // 音频的播放暂停
   toggleAudio() {
-    const audioContext = wx.createAudioContext('myAudio');
-  
+    // 如果已经有临时播放链接,直接用它
+    if (this.data.itemlist.playUrl) {
+      this._playAudio(this.data.itemlist.playUrl);
+    } else {
+      // 否则判断 url 是否是 cloud:// 开头,需要转临时链接
+      const cloudUrl = this.data.itemlist.url[0];
+      if (cloudUrl && cloudUrl.startsWith('cloud://')) {
+        wx.cloud.getTempFileURL({
+          fileList: [cloudUrl],
+          success: res => {
+            if (res.fileList && res.fileList.length > 0) {
+              const tempUrl = res.fileList[0].tempFileURL;
+              this.setData({ 'itemlist.playUrl': tempUrl }, () => {
+                this._playAudio(tempUrl);
+              });
+            }
+          },
+          fail: err => {
+            wx.showToast({ title: '获取播放链接失败', icon: 'none' });
+            console.error('获取临时链接失败', err);
+          }
+        });
+      } else {
+        // 不是 cloud:// 开头,直接播放原链接
+        this._playAudio(cloudUrl);
+      }
+    }
+  },
+
+  _playAudio(url) {
+    if (!this.audioContext) {
+      this.audioContext = wx.createInnerAudioContext();
+      this.audioContext.onPlay(() => this.setData({ isAudioPlaying: true }));
+      this.audioContext.onPause(() => this.setData({ isAudioPlaying: false }));
+      this.audioContext.onStop(() => this.setData({ isAudioPlaying: false }));
+      this.audioContext.onEnded(() => this.setData({ isAudioPlaying: false }));
+      this.audioContext.onError((res) => {
+        wx.showToast({ title: '音频播放错误', icon: 'none' });
+        this.setData({ isAudioPlaying: false });
+        console.error('音频播放错误', res);
+      });
+    }
+    
     if (this.data.isAudioPlaying) {
-      audioContext.pause();
-      this.setData({ isAudioPlaying: false });
+      this.audioContext.pause();
     } else {
-      audioContext.play();
-      this.setData({ isAudioPlaying: true });
+      this.audioContext.src = url;
+      this.audioContext.play();
     }
-  }
+  },
+
+  onUnload() {
+    if (this.audioContext) {
+      this.audioContext.stop();
+      this.audioContext.destroy();
+      this.audioContext = null;
+    }
+  },
+
+  onHide() {
+    if (this.audioContext) {
+      this.audioContext.pause();
+    }
+  },
+
+  // 新增浏览量
+  async getvisits() {
+    const userInfo = wx.getStorageSync('userInfo');
+    const userId = userInfo && userInfo._id ? userInfo._id : '';
+    const schoolId = userInfo && userInfo.school_id ? userInfo.school_id : '';
+    const fileId = this.data.itemlist._id;
+  
+    // 先查是否存在
+    const { data } = await models.microcode.list({
+      filter: {
+        where: {
+          school_id: schoolId,
+          user_id: userId,
+          file_id: fileId
+        }
+      },
+      envType: "prod",
+    });
+
+    console.log(data,'datadatadata');
+    const datalist = data.records || []
+  
+    if (datalist.length > 0) {
+      // 已存在 → 更新 visits + 1
+      const existItem = datalist[0];
+      const recordId = String(existItem._id);
+      console.log(existItem, 'existItem');
+      await models.microcode.update({
+        data: {
+            visits: existItem.visits + 1 ,  // 访问量
+          },
+        filter: {
+          where: {
+            $and: [
+              {
+                _id: {
+                  $eq: recordId, // 推荐传入_id数据标识进行操作
+                },
+              },
+            ]
+          }
+        },
+        // envType: pre 体验环境, prod 正式环境
+        envType: "prod",
+      });
+      console.log("更新成功:visits + 1");
+    } else {
+      // 不存在 → 创建新记录
+      const { data: newData } = await models.microcode.create({
+        data: {
+          visits: 1,
+          download: 1,
+          school_id: schoolId,
+          user_id: userId,
+          file_id: fileId,
+        },
+        envType: "prod",
+      });
+      console.log("创建成功", newData);
+    }
+  },
 })

+ 5 - 12
subpackagestow/details/details.wxml

@@ -6,21 +6,14 @@
       <text>{{itemlist.type === 0 ? '视频' : itemlist.type === 1 ? '音频' : itemlist.type === 2 ? 'PDF' : itemlist.type === 3 ? 'PPT' : '图文'}} 适用于 {{ itemlist.range }}</text>
     </view>
     <!-- 预览 -->
-    <view class="{{itemlist.type === 1 ? '' : 'file-preview'}}">
+    <view class="{{itemlist.type === 1 ? 'file-preview' : 'file-preview'}}">
       <view class="file-preview" wx:if="{{itemlist.type === 0}}">
         <video id="myVideo" class="course-videos" src="{{itemlist.url}}" controls></video>
       </view>
-      <view class="file-previews" wx:elif="{{itemlist.type === 1}}">
-        <audio
-          class="course-videos"
-          src="{{itemlist.url}}"
-          controls
-          autoplay
-          loop
-          poster="{{itemlist.cover}}"
-          name="{{itemlist.name}}"
-          author="作者"
-        />
+      <view class="file-preview" wx:elif="{{itemlist.type === 1}}">
+        <image style="width: 100%; height: 100%;" src="{{itemlist.cover}}" alt="" class="file-placeholder"/>
+        <!-- <web-view src="{{itemlist.url}}"/> -->
+        <view class="play-button">点击下方按钮预览课件</view>
       </view>
       <view class="file-preview" wx:elif="{{itemlist.type === 2}}">
         <image style="width: 100%; height: 100%;" src="{{itemlist.cover}}" alt="" class="file-placeholder"/>

+ 56 - 11
subpackagestow/down/down.js

@@ -277,19 +277,64 @@ Page({
 
   // 新增下载历史
   async getaddlishi() {
-    const userInfo = wx.getStorageSync('userInfo')
-    const { data } = await models.download_history.create({
-      data: {
-          user_id: userInfo._id,  // 用户id
-          delete: 0,  // 逻辑删除
-          file_manage_id: this.data.itemlist._id,  // 课件id
-        },
-      // envType: pre 体验环境, prod 正式环境
+    const userInfo = wx.getStorageSync('userInfo');
+    const userId = userInfo && userInfo._id ? userInfo._id : '';
+    const schoolId = userInfo && userInfo.school_id ? userInfo.school_id : '';
+    const fileId = this.data.itemlist._id;
+
+    // 先查是否存在
+    const { data } = await models.microcode.list({
+      filter: {
+        where: {
+          school_id: schoolId,
+          user_id: userId,
+          file_id: fileId
+        }
+      },
       envType: "prod",
     });
-    
-    // 返回更新成功的条数
-    console.log(this.data.itemlist._id, 'this.data.itemlist._id');    
+
+    console.log(data,'datadatadata');
+    const datalist = data.records || []
+  
+    if (datalist.length > 0) {
+      // 已存在 → 更新 visits + 1
+      const existItem = datalist[0];
+      const recordId = String(existItem._id);
+      console.log(existItem, 'existItem');
+      await models.microcode.update({
+        data: {
+          download: existItem.download + 1 ,  // 访问量
+          },
+        filter: {
+          where: {
+            $and: [
+              {
+                _id: {
+                  $eq: recordId, // 推荐传入_id数据标识进行操作
+                },
+              },
+            ]
+          }
+        },
+        // envType: pre 体验环境, prod 正式环境
+        envType: "prod",
+      });
+      console.log("更新成功:visits + 1");
+    } else {
+      // 不存在 → 创建新记录
+      const { data: newData } = await models.microcode.create({
+        data: {
+          visits: 1,
+          download: 1,
+          school_id: schoolId,
+          user_id: userId,
+          file_id: fileId,
+        },
+        envType: "prod",
+      });
+      console.log("创建成功", newData);
+    }  
   },
 
   // 清除定时器

+ 29 - 7
subpackagestow/show/show.js

@@ -18,6 +18,7 @@ Page({
     pageSize: 10,
     hasMore: true, // 是否还有更多数据
     isLoading: false, // 防止多次触发
+    searchText: '', // 搜索关键词
     // url: '',
     // pdfurl: '',
     // ppturl: '',
@@ -113,17 +114,38 @@ Page({
     console.log('加载更多');
     this.getdatalist(true);
   },
+
+  // 模糊搜索
+  onSearchInput(e) {
+    const keyword = e.detail.value.trim();
+    this.setData({
+      searchText: keyword,
+      pageNumber: 1,
+      hasMore: true,
+      goods: []
+    }, () => {
+      this.getdatalist(this.data.types_ids); // 重新加载
+    });
+  },
+
   // 列表数据
   async getdatalist(isLoadMore = false) {
     if (!this.data.categorieslist._id) return; // 防止 _id 为 undefined
-    const { pageNumber, pageSize } = this.data;
-    const { data } = await models.file_manage.list({
-      filter: {
-        where: {
-          tag_id: this.data.categorieslist._id,
+    const { pageNumber, pageSize, searchText } = this.data;
 
-        }
-      },
+     // 构造 where 条件
+    const where = {
+      tag_id: this.data.categorieslist._id,
+    };
+
+    // 模糊搜索关键字
+    if (searchText) {
+      where.name = {
+        $regex_ci: searchText
+      };
+    }
+    const { data } = await models.file_manage.list({
+      filter: { where },
       pageSize,
       pageNumber,
       getCount: true,

+ 1 - 1
subpackagestow/show/show.wxml

@@ -4,7 +4,7 @@
 
     <!-- 搜索框 -->
     <view class="search-bar">
-      <input class="search-input" placeholder="搜索" />
+      <input class="search-input" placeholder="搜索" bindinput="onSearchInput" value="{{searchText}}" />
       <image class="search-icon" src="{{sou}}" />
     </view>
 

+ 29 - 7
subpackagestow/teaching/teaching.js

@@ -18,6 +18,7 @@ Page({
     pageSize: 10,
     hasMore: true, // 是否还有更多数据
     isLoading: false, // 防止多次触发
+    searchText: '', // 搜索关键词
   },
 
   onLoad(options) {
@@ -98,17 +99,38 @@ Page({
     console.log('加载更多');
     this.getdatalist(true);
   },
+
+  // 模糊搜索
+  onSearchInput(e) {
+    const keyword = e.detail.value.trim();
+    this.setData({
+      searchText: keyword,
+      pageNumber: 1,
+      hasMore: true,
+      goods: []
+    }, () => {
+      this.getdatalist(this.data.types_ids); // 重新加载
+    });
+  },
+
   // 列表数据
   async getdatalist(isLoadMore = false) {
     if (!this.data.categorieslist._id) return; // 防止 _id 为 undefined
-    const { pageNumber, pageSize } = this.data;
-    const { data } = await models.file_manage.list({
-      filter: {
-        where: {
-          tag_id: this.data.categorieslist._id,
+    const { pageNumber, pageSize, searchText } = this.data;
 
-        }
-      },
+     // 构造 where 条件
+    const where = {
+      tag_id: this.data.categorieslist._id,
+    };
+
+    // 模糊搜索关键字
+    if (searchText) {
+      where.name = {
+        $regex_ci: searchText
+      };
+    }
+    const { data } = await models.file_manage.list({
+      filter: { where },
       pageSize,
       pageNumber,
       getCount: true,

+ 1 - 1
subpackagestow/teaching/teaching.wxml

@@ -4,7 +4,7 @@
     <!-- <view class="container"> -->
       <!-- 搜索框 -->
       <view class="search-bar">
-        <input class="search-input" placeholder="搜索" />
+        <input class="search-input" placeholder="搜索" bindinput="onSearchInput" value="{{searchText}}" />
         <image class="search-icon" src="{{sou}}" />
       </view>
     <!-- </view> -->

+ 30 - 7
subpackagestow/training/training.js

@@ -18,6 +18,7 @@ Page({
     pageSize: 10,
     hasMore: true, // 是否还有更多数据
     isLoading: false, // 防止多次触发
+    searchText: '', // 搜索关键词
   },
 
   onLoad(options) {
@@ -100,17 +101,39 @@ Page({
     console.log('加载更多');
     this.getdatalist(true);
   },
+
+  // 模糊搜索
+  onSearchInput(e) {
+    const keyword = e.detail.value.trim();
+    this.setData({
+      searchText: keyword,
+      pageNumber: 1,
+      hasMore: true,
+      goods: []
+    }, () => {
+      this.getdatalist(this.data.types_ids); // 重新加载
+    });
+  },
+
   // 列表数据
   async getdatalist(isLoadMore = false) {
     if (!this.data.categorieslist._id) return; // 防止 _id 为 undefined
-    const { pageNumber, pageSize } = this.data;
-    const { data } = await models.file_manage.list({
-      filter: {
-        where: {
-          tag_id: this.data.categorieslist._id,
+    const { pageNumber, pageSize, searchText } = this.data;
 
-        }
-      },
+     // 构造 where 条件
+    const where = {
+      tag_id: this.data.categorieslist._id,
+    };
+
+    // 模糊搜索关键字
+    if (searchText) {
+      where.name = {
+        $regex_ci: searchText
+      };
+    }
+
+    const { data } = await models.file_manage.list({
+      filter: { where },
       pageSize,
       pageNumber,
       getCount: true, // 开启用来获取总数

+ 1 - 1
subpackagestow/training/training.wxml

@@ -4,7 +4,7 @@
     <!-- <view class="container"> -->
       <!-- 搜索框 -->
       <view class="search-bar">
-        <input class="search-input" placeholder="搜索" />
+        <input class="search-input" placeholder="搜索" bindinput="onSearchInput" value="{{searchText}}" />
         <image class="search-icon" src="{{sou}}" />
       </view>
     <!-- </view> -->