liyongli il y a 2 ans
Parent
commit
8b58750766

+ 1 - 0
.cloudbase/container/debug.json

@@ -0,0 +1 @@
+{"containers":[],"config":{}}

+ 12 - 89
cloudfunctions/server/controller/media/index.js

@@ -1,100 +1,23 @@
 const { formmat } = require("../../utils/http");
-function MediaController(data) {
-  console.log('参数------------>', data)
-  let list = [
-    {
-      location: "西安",
-      date: "2022-11-22",
-      icon: "",
-      id: 0,
-      child: [
-        {
-          url: "https://cxzx.smcic.net/topic/activity/img/upbg.ab3a4dc7.jpg",
-          title: "走进文物"
-        },
-        {
-          url: "https://cxzx.smcic.net/topic/activity/img/upbg.ab3a4dc7.jpg",
-          title: "走进文物"
-        },
-        {
-          url: "https://cxzx.smcic.net/topic/activity/img/upbg.ab3a4dc7.jpg",
-          title: "走进文物"
-        },
-      ]
-    },
-  ];
-  if (data.typeMedia === 'video') list = [
-    {
-      location: "西安",
-      date: "2022-11-22",
-      icon: "",
-      id: 0,
-      child: [
-        {
-          url: "https://cxzx.smcic.net/operate/worldCup/works/10086/20221119113805/97ba6b60662ab4f31ef06cdf5a5f8e94_preview.mp4",
-          title: "走进文物"
-        },
-        {
-          url: "https://cxzx.smcic.net/operate/worldCup/works/10086/20221119113805/97ba6b60662ab4f31ef06cdf5a5f8e94_preview.mp4",
-          title: "走进文物"
-        },
-        {
-          url: "https://cxzx.smcic.net/operate/worldCup/works/10086/20221119113805/97ba6b60662ab4f31ef06cdf5a5f8e94_preview.mp4",
-          title: "走进文物"
-        },
-      ]
-    },
-  ]
+const { MediaService, MediaOnceService, ArticleService } = require("../../service/media/index");
+async function MediaController(data) {
+  let list = await MediaService(data);
   return formmat(list, 0, "ok");
 }
 
-function MediaControllerOnce(data) {
-  console.log('参数------------>', data)
-  let once = {
-    location: "西安",
-    date: "2022-11-22",
-    icon: "",
-    id: 0,
-    child: [
-      {
-        url: "https://cxzx.smcic.net/topic/activity/img/upbg.ab3a4dc7.jpg",
-        title: "走进文物"
-      },
-      {
-        url: "https://cxzx.smcic.net/topic/activity/img/upbg.ab3a4dc7.jpg",
-        title: "走进文物"
-      },
-      {
-        url: "https://cxzx.smcic.net/topic/activity/img/upbg.ab3a4dc7.jpg",
-        title: "走进文物"
-      },
-    ]
-  };
-  if (data.typeMedia === 'video') once = {
-    location: "西安",
-    date: "2022-11-22",
-    icon: "",
-    id: 0,
-    child: [
-      {
-        url: "https://cxzx.smcic.net/operate/worldCup/works/10086/20221119113805/97ba6b60662ab4f31ef06cdf5a5f8e94_preview.mp4",
-        title: "走进文物"
-      },
-      {
-        url: "https://cxzx.smcic.net/operate/worldCup/works/10086/20221119113805/97ba6b60662ab4f31ef06cdf5a5f8e94_preview.mp4",
-        title: "走进文物"
-      },
-      {
-        url: "https://cxzx.smcic.net/operate/worldCup/works/10086/20221119113805/97ba6b60662ab4f31ef06cdf5a5f8e94_preview.mp4",
-        title: "走进文物"
-      },
-    ]
-  }
+async function MediaOnceController(data) {
+  let once = await MediaOnceService(data);
   return formmat(once, 0, "ok");
 }
 
+async function getArticleController(data) {
+  let article = await ArticleService(data);
+  return formmat(article, 0, "ok");
+}
+
 
 module.exports = {
   MediaController,
-  MediaControllerOnce
+  MediaOnceController,
+  getArticleController
 }

+ 10 - 5
cloudfunctions/server/index.js

@@ -3,22 +3,27 @@
  * 初始化数据库
  */
 const cloud = require('wx-server-sdk');
-const { Home, MediaController, MediaControllerOnce } = require("./controller/index");
+const { MediaController, MediaOnceController,getArticleController } = require("./controller/index");
 cloud.init({
-  env: cloud.DYNAMIC_CURRENT_ENV
+  env: 'serverless-env-7gkaeuji38488831'
 })
 // 云函数入口函数
 exports.main = async (event, context) => {
-  console.log(event)
   switch (event.type) {
     case "getMediaController": {
       delete event.type;
       return MediaController(event);
     }
 
-    case "getMediaControllerOnce": {
+    case "getMediaOnceController": {
       delete event.type
-      return MediaControllerOnce(event)
+      return MediaOnceController(event)
+    }
+
+    case "getArticle": {
+      delete event.type;
+      return getArticleController(event)
+
     }
 
     default: {

+ 5 - 4
cloudfunctions/server/package-lock.json

@@ -5,6 +5,7 @@
   "requires": true,
   "packages": {
     "": {
+      "name": "server",
       "version": "1.0.0",
       "license": "ISC",
       "dependencies": {
@@ -1024,8 +1025,8 @@
     },
     "node_modules/wx-server-sdk": {
       "version": "2.4.0",
-      "resolved": "https://registry.nlark.com/wx-server-sdk/download/wx-server-sdk-2.4.0.tgz",
-      "integrity": "sha1-XhRDK6DvHJVIXPcsk1lEbqs5K94=",
+      "resolved": "https://registry.npmmirror.com/wx-server-sdk/-/wx-server-sdk-2.4.0.tgz",
+      "integrity": "sha512-+d/OAUgt3LVlIwC/EEd9oHK2VltMqvoSa3Z797sgZ/hBm/Z+bhYBX3PfrRgn41fprzNk49jdbmw8Rkwa4JryIQ==",
       "dependencies": {
         "@cloudbase/node-sdk": "2.4.7",
         "protobufjs": "6.8.8",
@@ -1913,8 +1914,8 @@
     },
     "wx-server-sdk": {
       "version": "2.4.0",
-      "resolved": "https://registry.nlark.com/wx-server-sdk/download/wx-server-sdk-2.4.0.tgz",
-      "integrity": "sha1-XhRDK6DvHJVIXPcsk1lEbqs5K94=",
+      "resolved": "https://registry.npmmirror.com/wx-server-sdk/-/wx-server-sdk-2.4.0.tgz",
+      "integrity": "sha512-+d/OAUgt3LVlIwC/EEd9oHK2VltMqvoSa3Z797sgZ/hBm/Z+bhYBX3PfrRgn41fprzNk49jdbmw8Rkwa4JryIQ==",
       "requires": {
         "@cloudbase/node-sdk": "2.4.7",
         "protobufjs": "6.8.8",

+ 85 - 0
cloudfunctions/server/service/media/index.js

@@ -0,0 +1,85 @@
+const { db, _ } = require("../../utils/http");
+async function MediaService(data) {
+  const list = [];
+  const orilist = await db.collection('AudioAndVideo').where({
+    type: _.eq(data.typeMedia)
+  }).get();
+  const keysOir = {};
+  for (let i = 0; i < orilist.data.length; i++) {
+    const v = orilist.data[i];
+    if (keysOir[v.localtion] !== undefined) {
+      // 已经存在
+      list[keysOir[v.localtion]].child.push({
+        url: v.url,
+        title: v.title,
+        cover: v.cover,
+        id: v._id
+      })
+    } else {
+      // push
+      keysOir[v.localtion] = list.length;
+      list.push({
+        location: v.localtion,
+        date: v.uptime,
+        id: v._id,
+        child: [
+          {
+            url: v.url,
+            title: v.title,
+            cover: v.cover,
+            id: v._id
+          }
+        ]
+      })
+    }
+  }
+  return list
+}
+
+async function MediaOnceService(data) {
+  const list = [];
+  const orilist = await db.collection('AudioAndVideo').where({
+    type: _.eq(data.typeMedia),
+    localtion: _.eq(data.group)
+  }).get();
+  const keysOir = {};
+  for (let i = 0; i < orilist.data.length; i++) {
+    const v = orilist.data[i];
+    if (keysOir[v.localtion] !== undefined) {
+      // 已经存在
+      list[keysOir[v.localtion]].child.push({
+        url: v.url,
+        title: v.title,
+        cover: v.cover,
+        id: v._id
+      })
+    } else {
+      // push
+      keysOir[v.localtion] = list.length;
+      list.push({
+        location: v.localtion,
+        date: v.uptime,
+        id: v._id,
+        child: [
+          {
+            url: v.url,
+            title: v.title,
+            cover: v.cover,
+            id: v._id
+          }
+        ]
+      })
+    }
+  }
+  return list
+}
+
+async function ArticleService(data) {
+  const orilist = await db.collection('article').doc(data.id).get();
+  return orilist.data || {}
+}
+module.exports = {
+  MediaService,
+  MediaOnceService,
+  ArticleService
+}

+ 12 - 3
cloudfunctions/server/utils/http.js

@@ -1,9 +1,18 @@
+const cloud = require('wx-server-sdk')
+cloud.init({
+  env: 'serverless-env-7gkaeuji38488831'
+})
+const db = cloud.database();
+
 module.exports = {
-  formmat(data, code, msg){
+  formmat(data, code, msg) {
     return {
       code,
       data,
       msg
     }
-  }
-}
+  },
+  db,
+  _: db.command
+}
+

+ 1 - 1
miniprogram/app.js

@@ -10,7 +10,7 @@ App({
         //   env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源
         //   此处请填入环境 ID, 环境 ID 可打开云控制台查看
         //   如不填则使用默认环境(第一个创建的环境)
-        // env: 'my-env-id',
+        env: 'serverless-env-7gkaeuji38488831',
         traceUser: true,
       })
     }

+ 1 - 1
miniprogram/components/dayList/components/videoComponents/index.wxml

@@ -1,5 +1,5 @@
 <template name="mediaVideo">
   <view class="col-3" wx:for="{{list}}" wx:for-index="i" wx:for-item="itemSon" wx:key="i" data-index="{{index + '-' + i}}" bindtap="showMedia">
-    <image style="width: 100%;height: 100%" src="{{itemSon.url + '?x-oss-process=video/snapshot,t_100,f_jpg,m_fast'}}" mode="aspectFit" />
+    <image style="width: 100%;height: 100%" src="{{itemSon.cover}}" mode="aspectFit" />
   </view>
 </template>

+ 5 - 5
miniprogram/components/dayList/index.js

@@ -1,6 +1,5 @@
 // components/dayList/index.js
-const urlList = [];
-const titleList = [];
+let urlList = [];
 Component({
   /**
    * 组件的属性列表
@@ -10,6 +9,7 @@ Component({
       type: Array,
       observer: function (n) {
         if (!n.length) return;
+        urlList = [];
         let y = -1;
         for (let i = 0; i < n.length; i++) {
           const v = n[i];
@@ -19,9 +19,9 @@ Component({
             urlList.push({
               url: item.url,
               type: item.mediaType,
-              poster: item.poster || ""
+              poster: item.poster || "",
+              title: item.title
             });
-            titleList.push(item.title);
           }
         }
       }
@@ -48,7 +48,7 @@ Component({
         return
       }
       wx.navigateTo({
-        url: "/pages/videoDetail/index?id=" + row.id + '&index=' + indexs[1]
+        url: "/pages/videoDetail/index?id=" + item.id + '&group=' + row.location
       })
     }
   }

+ 1 - 1
miniprogram/components/dayList/index.wxml

@@ -5,6 +5,6 @@
   <mp-cell title="{{item.date}}" footer="{{item.location}}"></mp-cell>
   <view class="Allmedia">
     <template wx:if="{{item.mediaType === 'image'}}" is="mediaImage" data="{{list: item.child || [], index}}"></template>
-    <template wx:if="{{item.mediaType === 'video'}}" is="mediaVideo" data="{{list: item.child || [], index}}"></template>
+    <template wx:if="{{item.mediaType === 'video' || item.mediaType === 'live'}}" is="mediaVideo" data="{{list: item.child || [], index}}"></template>
   </view>
 </view>

+ 16 - 13
miniprogram/pages/detail/detail.js

@@ -1,4 +1,5 @@
 // miniprogram/pages/detail/detail.js
+import { httpCloud } from "../../utils/httpFunc";
 Page({
 
   /**
@@ -13,23 +14,25 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: async function (options) {
+    const _this = this;
     this.nameText = decodeURIComponent(options.title || "详情");
     this.idText = options.id || "";
     wx.setNavigationBarTitle({
-      title:  this.nameText
+      title: this.nameText
+    })
+
+    httpCloud({
+      name: "server",
+      type: "getArticle",
+      data: {
+        id: options.id,
+      },
+      call(res) {
+        _this.setData({
+          detail: res || {}
+        })
+      }
     })
-    // const db = wx.cloud.database();
-    // const _ = db.command;
-    // let list = await db.collection('data_news').where({
-    //   _id: _.eq(options.id)
-    // }).get();
-    
-    // let D = list.data[0] || {};
-    // D.content = D.content.replace(/style=\"([a-z|A-Z|-|:|;|0-9|\.]*)\"/g, "").replace(/width=\"([a-z|A-Z|-|:|;|0-9|\.]*)\"/g, "").replace(/height=\"([a-z|A-Z|-|:|;|0-9|\.]*)\"/g, "").replace(/<img/g, "<img style='width: 100%'").replace(/<p/gi, '<p style="text-indent: 2em;min-height: 1em"')
-    // if (D.creat_time) D.creat_time = this.format(D.creat_time);
-    // _this.setData({
-    //   detail: D,
-    // })
     wx.showShareMenu({
       withShareTicket: true,
     });

+ 1 - 5
miniprogram/pages/detail/detail.wxml

@@ -1,9 +1,5 @@
 <!--miniprogram/pages/detail/detail.wxml-->
 <import src="./template/sysDetail/index.wxml"></import>
-<import src="./template/pdfDetail/index.wxml"></import>
-<import src="./template/defaultDetail/index.wxml"></import>
 <view class="detail">
-  <template wx:if="{{detail.type === 0}}" is="sysDetail" data="{{...detail}}"></template>
-  <template wx:if="{{detail.type === 2}}" is="pdfDetail" data="{{...detail}}"></template>
-  <template wx:if="{{detail.type === 1}}" is="defaultDetail" data="{{...detail}}"></template>
+  <template wx:if="{{detail.type === '1'}}" is="sysDetail" data="{{...detail}}"></template>
 </view>

+ 0 - 2
miniprogram/pages/detail/detail.wxss

@@ -1,7 +1,5 @@
 /* miniprogram/pages/detail/detail.wxss */
 @import "./template/sysDetail/index.wxss";
-@import "./template/pdfDetail/index.wxss";
-@import "./template/defaultDetail/index.wxss";
 
 .detail{
   width: 750rpx;

+ 0 - 6
miniprogram/pages/detail/template/defaultDetail/index.wxml

@@ -1,6 +0,0 @@
-<!--miniprogram/pages/detail/template/pdfDetail/index.wxml-->
-<template name="defaultDetail">
-  <video custom-cache="{{false}}" class="video" wx:if="{{headUrl}}" src="{{headUrl}}"></video>
-  <view style="width:730rpx;margin: 10rpx auto;display:block" wx:if="{{creat_time}}"> 发表日期:{{creat_time}}</view>
-  <rich-text wx:if="{{content}}" style="width:730rpx;margin: 10rpx auto;display:block" nodes="{{content}}"></rich-text>
-</template>

+ 0 - 4
miniprogram/pages/detail/template/defaultDetail/index.wxss

@@ -1,4 +0,0 @@
-/* miniprogram/pages/detail/template/pdfDetail/index.wxss */
-.video{
-  width: 750rpx;
-}

+ 0 - 5
miniprogram/pages/detail/template/pdfDetail/index.wxml

@@ -1,5 +0,0 @@
-<!--miniprogram/pages/detail/template/pdfDetail/index.wxml-->
-<template name="pdfDetail">
-  <image class="headImg" mode="aspectFit" src="{{headUrl}}"></image>
-  <image class="bodyImg" mode="aspectFit" wx:for="{{content}}" src="{{item}}" wx:key="index"></image>
-</template>

+ 0 - 5
miniprogram/pages/detail/template/pdfDetail/index.wxss

@@ -1,5 +0,0 @@
-/* miniprogram/pages/detail/template/pdfDetail/index.wxss */
-.bodyImg{
-  width: 750rpx;
-  height: 1060rpx;
-}

+ 1 - 2
miniprogram/pages/detail/template/sysDetail/index.wxml

@@ -1,4 +1,3 @@
 <template name="sysDetail">
-  <image class="headImg" mode="aspectFit" wx:if="{{headUrl}}" src="{{headUrl}}"></image>
-  <rich-text wx:if="{{content}}" style="width:730rpx;margin: 10rpx auto;display:block" nodes="{{content}}"></rich-text>
+  <rich-text wx:if="{{article_detail}}" style="width:730rpx;margin: 10rpx auto;display:block" nodes="{{article_detail}}"></rich-text>
 </template>

+ 3 - 0
miniprogram/pages/detail/template/sysDetail/index.wxss

@@ -1 +1,4 @@
 /* miniprogram/pages/detail/template/sysDetail/index.wxss */
+rich-text .image-wrap{
+  max-width: 100%;
+}

+ 1 - 0
miniprogram/pages/home/index.js

@@ -17,6 +17,7 @@ Page({
     switch (item.type) {
       case 'image':
       case 'video':
+      case 'live':
         url = '/pages/mediaController/index?title=' + item.text + "&mediaType=" + item.type;
         break;
       default:

+ 3 - 0
miniprogram/pages/mediaController/index.js

@@ -1,5 +1,6 @@
 // pages/imgController/index.js
 import { httpCloud } from "../../utils/httpFunc";
+import {dateFormmat} from "../../utils/tool"
 
 Page({
 
@@ -29,8 +30,10 @@ Page({
       call(res) {
         _this.setData({
           mediaList: (res || []).map(v=>{
+            const date = dateFormmat(v.date);
             return {
               ...v,
+              date: [date.year, date.month, date.day].join("-"),
               mediaType: _this.mediaType,
             }
           })

+ 17 - 7
miniprogram/pages/videoDetail/index.js

@@ -14,8 +14,9 @@ Page({
   },
 
   toNext(e) {
+    const item =this.data.media.child[e.currentTarget.dataset.index];
     wx.redirectTo({
-      url: "/pages/videoDetail/index?id=" + this.data.media.id + '&index=' + e.currentTarget.dataset.index
+      url:  "/pages/videoDetail/index?id=" + item.id + '&group=' + this.data.media.location
     })
   },
 
@@ -23,7 +24,7 @@ Page({
     const { width, height } = e.detail || {};
     this.setData({
       videoWidth: app.globalData.client.windowWidth,
-      videoHeight: app.globalData.client.windowWidth/width * height
+      videoHeight: app.globalData.client.windowWidth / width * height
     })
   },
 
@@ -34,19 +35,28 @@ Page({
     const _this = this;
     httpCloud({
       name: "server",
-      type: "getMediaControllerOnce",
+      type: "getMediaOnceController",
       data: {
         typeMedia: 'video',
-        id: options.id
+        id: options.id,
+        group: options.group
       },
       call(res) {
-        const ori = res || { child: [] };
+        const ori = res[0] || { child: [] };
+        let indexItem = {};
+        for (let i = 0; i < ori.child.length; i++) {
+          const v = ori.child[i];
+          if (v.id === options.id) {
+            indexItem = v
+            break
+          } else continue
+        }
         _this.setData({
           media: ori,
-          indexItem: ori.child[options.index]
+          indexItem
         })
         wx.setNavigationBarTitle({
-          title: ori.child[options.index].title
+          title: indexItem.title
         })
       }
     })

+ 7 - 5
miniprogram/pages/videoDetail/index.wxml

@@ -1,8 +1,10 @@
 <!--pages/videoDetail/index.wxml-->
-<video bindloadedmetadata="loadedmetadata" style="{{'width: '+ videoWidth +'px;height: '+ videoHeight +'px'}}" class="video" src="{{indexItem.url}}" controls poster="{{indexItem.url + '?x-oss-process=video/snapshot,t_100,f_jpg,m_fast'}}" />
+<video bindloadedmetadata="loadedmetadata" style="{{'width: '+ videoWidth +'px;height: '+ videoHeight +'px'}}" class="video" src="{{indexItem.url}}" controls poster="{{indexItem.cover}}" />
 <mp-cell title="{{indexItem.title}}"></mp-cell>
 
-<view class="list" wx:for="{{media.child || []}}" wx:key="index" bindtap="toNext" data-index="{{index}}">
-  <image class="imgage" src="{{item.url + '?x-oss-process=video/snapshot,t_100,f_jpg,m_fast'}}" mode="aspectFit" />
-  <view class="title">{{item.title}}</view>
-</view>
+<block wx:for="{{media.child || []}}" wx:key="index">
+  <view class="list" wx:if="{{item.id !== indexItem.id}}" bindtap="toNext" data-index="{{index}}">
+    <image class="imgage" src="{{item.cover}}" mode="aspectFit" />
+    <view class="title">{{item.title}}</view>
+  </view>
+</block>

+ 3 - 0
miniprogram/utils/httpFunc.js

@@ -5,6 +5,7 @@ function httpError(err) {
   wx.hideLoading();
   wx.showToast({
     title: '请稍后再试!',
+    icon: 'none'
   })
 }
 
@@ -24,6 +25,7 @@ export function httpCloud(params) {
       if (!/ok/g.test(res.errMsg)) return httpError(res);
       if (res.result.code != 0) return wx.showToast({
         title: '请稍后再试!',
+        icon: 'none'
       })
       par.call && par.call(res.result.data);
     },
@@ -42,6 +44,7 @@ export function httpOrther(params) {
     success(res) {
       if (res.statusCode !== 200 || res.data.code != 0 )return wx.showToast({
         title: '请稍后再试!',
+        icon: 'none'
       })
       if (!/ok/g.test(res.errMsg)) return httpError(res);
       

+ 11 - 0
miniprogram/utils/tool.js

@@ -0,0 +1,11 @@
+export function dateFormmat(date) {
+  const T = new Date(date);
+  return {
+    year: T.getFullYear(),
+    month: T.getMonth(),
+    day: T.getDate(),
+    hour: T.getHours(),
+    min: T.getMinutes(),
+    s: T.getSeconds()
+  }
+}

+ 1 - 13
project.private.config.json

@@ -3,19 +3,7 @@
     "compileHotReLoad": false,
     "urlCheck": true
   },
-  "condition": {
-    "miniprogram": {
-      "list": [
-        {
-          "name": "",
-          "pathName": "pages/videoDetail/index",
-          "query": "id=0&index=1",
-          "launchMode": "default",
-          "scene": null
-        }
-      ]
-    }
-  },
+  "condition": {},
   "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
   "libVersion": "2.14.1"
 }