瀏覽代碼

解决问题

Limengbo 5 年之前
父節點
當前提交
d8bbc37324

+ 20 - 12
src/app.wpy

@@ -1,11 +1,8 @@
 <style lang="less">
 page {
   width: 100%;
-  height: 100%;
 }
-
 .container {
-  height: 100%;
   box-sizing: border-box;
 }
 </style>
@@ -43,8 +40,16 @@ export default class extends wepy.app {
     scene: ''
   }
 
-  async onLaunch() {
-    await wepy.login({
+  getLogin (success, fail) {
+    console.log(1111, wepy.getStorageSync('scene'))
+    if (wepy.getStorageSync('user') && !wepy.getStorageSync('scene')) {
+      success(wepy.getStorageSync('user'))
+      return false
+    }
+    wepy.showLoading({
+      title: '加载中'
+    })
+    wepy.login({
       success (res) {
         console.log(res.code)
         const code = res.code
@@ -54,32 +59,35 @@ export default class extends wepy.app {
           console.log(JSON.parse(res.data))
           // console.log(this.globalData.session_key)
           const sessionKey = JSON.parse(res.data).session_key
-          this.getUserInfo(code, sessionKey)
+          this.getUserInfo(code, sessionKey, success, fail)
         }).send()
       }
     })
   }
 
-  getUserInfo (code, sessionKey) {
+  getUserInfo (code, sessionKey, success, fail) {
     console.log(this.globalData.scene)
+    const scene = wepy.getStorageSync('scene')
     wepy.getUserInfo({
       success (res) {
         RequestService.sendRequest().url(`${httpUrls.baseApi}wx/user`).header({
           'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
         }).method('POST').data({
-          scene: this.globalData.scene,
+          scene,
           sessionKey,
           iv: res.iv,
           encryptedData: res.encryptedData
         }).success(res => {
-          console.log('用户', res)
           wepy.setStorageSync('uid', res.data.data.id)
           wepy.setStorageSync('user', res.data.data)
+          wepy.setStorageSync('scene', '')
+          wx.hideLoading()
+          success(res)
         }).send()
       },
-      fail (res) {
-        console.log(res)
-        this.globalData.errMsg = false
+      fail: (res) => {
+        fail(res)
+        // this.globalData.errMsg = false
       }
     })
   }

+ 38 - 22
src/components/allFile.wpy

@@ -1,9 +1,11 @@
 <style lang="less">
 .all-file {
   width: 100%;
-  padding: 0 18rpx;
-  box-sizing:border-box;
 }
+.bg {
+  color: #ccc;
+}
+
 .file-item {
   width: 100%;
   height: 140rpx;
@@ -11,6 +13,8 @@
   display: flex;
   justify-content: space-between;
   align-items: center;
+  padding: 0 18rpx;
+  box-sizing:border-box;
   .dian {
     width:100rpx;
     height: 60rpx;
@@ -46,61 +50,73 @@
 <template>
   <view class="all-file">
       <repeat for="{{fileList}}" key="index" index="index" item="item">
-        <view class="file-item" wx:if="{{item.task}}" @tap="detail({{item.task}})">
+        <view class="file-item {{item.taskJoinUser.fileStatus === 'CLOSE' ? 'bg' : ''}}" wx:if="{{item.task}}" @tap="detail({{item.task}}, {{item.taskJoinUser.fileStatus}})">
           <view class="file">
-            <image src="../static/img/file.png"></image>
+            <image src="../static/img/file{{item.taskJoinUser.fileStatus === 'CLOSE' ? '_b' : ''}}.png"></image>
             <view class="file-explain">
               <text class="title">{{item.task.title}}</text>
               <text class="time">{{timeList[index]}}</text>
             </view>
           </view>
-          <view class="dian"  @tap.stop="operation({{index}})">
-            <image src="../static/img/dian.png"></image>
+          <view class="dian"  @tap.stop="operation({{index}}, {{item.taskJoinUser.fileStatus}})">
+            <image src="../static/img/dian{{item.taskJoinUser.fileStatus === 'CLOSE' ? '_b' : ''}}.png"></image>
           </view>
 
         </view>
       </repeat>
   </view>
-  <del :syncFlag.sync="flag" :index="index"/>
+  <del :syncFlag.sync="flag" :index.sync="index" :fileList.sync="fileList"/>
 </template>
 <script>
   import wepy from 'wepy'
   import Del from './del'
   import { httpRequestApi } from '../util/httpRequestApi'
+  import { formDate } from '../util/utils'
 
   export default class AllFile extends wepy.component {
     data = {
       fileList: [],
       flag: 'false',
       timeList: [],
-      index: 0
+      index: 0,
+      totalNo: 0
     }
     components = {
       del: Del
     }
     methods = {
-      detail (task) {
+      detail (task, fileStatus) {
+        if (fileStatus === 'CLOSE') {
+          return false
+        }
         const id = task.id ? task.id : ''
         const title = task.title ? task.title : ''
         this.$root.$navigate(`/pages/detail?id=${id}&title=${title}`)
       },
-      operation (ind) {
+      operation (ind, fileStatus) {
+        if (fileStatus === 'CLOSE') {
+          return false
+        }
         this.flag = 'true'
         this.index = ind
-      }
-    }
-
-    onLoad () {
-      httpRequestApi.getTaskList().success(res => {
-        console.log('任务列表', res)
-        this.fileList = res.data.data.list
-        res.data.data.list.forEach(item => {
-          if (item.task) {
-            this.timeList.push(new Date(item.task.gmtCreated).toLocaleString())
+      },
+      getTaskList: (pageNo, pageSize, type) => {
+        httpRequestApi.getTaskList(pageNo, pageSize).success(res => {
+          this.totalNo = res.data.data.totalNo
+          if (type) {
+            this.fileList = res.data.data.list
           }
+          res.data.data.list.forEach(item => {
+            if (!type) {
+              this.fileList.push(item)
+            }
+            if (item.task) {
+              this.timeList.push(formDate(item.task.gmtCreated))
+            }
+          })
+          this.$apply()
         })
-        this.$apply()
-      })
+      }
     }
   }
 </script>

+ 64 - 70
src/components/browse.wpy

@@ -17,6 +17,16 @@
     color: #848993;
     margin-left: 33rpx;
   }
+  .no-file {
+    position: absolute;
+    top: 50%;
+    left: 50%;
+    transform: translate(-50%, -50%);
+    text-align: center;
+    view {
+      white-space:nowrap;
+    }
+  }
   .file-item {
     width: 100%;
     height: 140rpx;
@@ -59,29 +69,20 @@
 </style>
 <template>
   <view class="log">
-    <view class="file-title">文档资料</view>
-    <view class="file-box">
-      <repeat for="{{localFile}}" key="index" index="index" item="item">
-        <view class="file-item" @tap="preview({{item.path}}, {{index}})">
-          <view class="file">
-            <image src="../static/img/{{listType[index]}}.png"></image>
-            <view class="file-explain">
-              <text class="title">{{item.fileName}}</text>
-              <text class="time">{{localFileTime[index]}}</text>
-            </view>
-          </view>
-        </view>
-      </repeat>
+    <view class="file-title" wx:if="{{lookFileList.length!==0}}">文档资料</view>
+    <view class="no-file" wx:else>
+      <image src="../static/img/liulan.png" style="width: 345rpx; height: 238rpx;"/>
+      <view style="font-size: 32rpx; color: #444444; ">您最近还没有浏览过,快去浏览吧。</view>
     </view>
-    <view class="file-title">白板截图</view>
     <view class="file-box">
-      <repeat for="{{screenshot}}" key="index" index="index" item="item">
-        <view class="file-item" @tap="previewImg({{item.path}}, {{index}})">
+      <repeat for="{{lookFileList}}" key="index" index="index" item="item">
+        <view class="file-item" @tap="preview({{item.taskFile.path}}, {{index}})">
           <view class="file">
-            <image src="{{item.path}}" style="width: 104rpx;height: 76rpx;"></image>
+            <image wx:if="{{listType[index] == 'jpg' || listType[index] == 'png' }}" src="{{item.taskFile.path}}"></image>
+            <image wx:else src="../static/img/{{listType[index]}}.png"></image>
             <view class="file-explain">
-              <text class="title">{{item.fileName}}</text>
-              <text class="time">{{screenshotTime[index]}}</text>
+              <text class="title">{{item.taskFile.fileName}}</text>
+              <text class="time">{{lookFileTime[index]}}</text>
             </view>
           </view>
         </view>
@@ -93,6 +94,7 @@
 <script>
   import wepy from 'wepy'
   import { httpRequestApi } from '../util/httpRequestApi'
+  import { formDate } from '../util/utils'
 
   export default class Detail extends wepy.page {
     components = {
@@ -100,11 +102,10 @@
     }
 
     data = {
-      localFile: [],
-      screenshot: [],
-      localFileTime: [],
-      screenshotTime: [],
-      listType: []
+      lookFileList: [],
+      lookFileTime: [],
+      listType: [],
+      totalNo: 0
     }
 
     computed = {
@@ -113,39 +114,46 @@
 
     methods = {
       preview (url, index) {
-        wx.showLoading({
-          title: '加载中'
-        })
-        wx.downloadFile({
-          url: url,
-          success: (res) => {
-            console.log(res.tempFilePath)
-            wx.openDocument({
-              filePath: res.tempFilePath,
-              success: (res) => {
-                wx.hideLoading()
-                console.log('打开文档成功')
-                const fileId = this.localFile[index].id
-                const taskId = this.localFile[index].taskId
-                httpRequestApi.addViewLog(fileId, taskId).success(res => {
-                  console.log('添加文档')
-                })
-              }
-            })
-          }
-        })
+        const type = this.listType[index]
+        if (type === 'jpg' || type === 'png') {
+          wx.previewImage({
+            current: 'url', // 当前显示图片的http链接
+            urls: [url], // 需要预览的图片http链接列表
+            success: res => {
+            }
+          })
+        } else {
+          wx.showLoading({
+            title: '加载中'
+          })
+          wx.downloadFile({
+            url: url,
+            success: (res) => {
+              console.log(res.tempFilePath)
+              wx.openDocument({
+                filePath: res.tempFilePath,
+                fileType: type,
+                success: (res) => {
+                  wx.hideLoading()
+                }
+              })
+            }
+          })
+        }
       },
-      previewImg (url, index) {
-        wx.previewImage({
-          current: 'url', // 当前显示图片的http链接
-          urls: [url], // 需要预览的图片http链接列表
-          success: res => {
-            const fileId = this.screenshot[index].id
-            const taskId = this.screenshot[index].taskId
-            httpRequestApi.addViewLog(fileId, taskId).success(res => {
-              console.log('添加文档')
+      getLogList: (pageNo, pageSize, type) => {
+        httpRequestApi.getLogList(pageNo, pageSize).success(res => {
+          this.totalNo = res.data.data.totalNo
+          if (!type) {
+            res.data.data.list.forEach(item => {
+              this.lookFileList.push(item)
             })
+          } else {
+            this.lookFileList = res.data.data.list
           }
+          this.CompileTime(res.data.data.list)
+          this.CompileTime(res.data.data.list, true)
+          this.$apply()
         })
       }
     }
@@ -154,27 +162,13 @@
     }
 
     CompileTime (list, type) {
-      let arr = []
       list.forEach(item => {
         if (type) {
-          arr.push(item.path.substr(item.path.lastIndexOf('.') + 1))
+          this.listType.push(item.taskFile.path.substr(item.taskFile.path.lastIndexOf('.') + 1))
         } else {
-          arr.push(new Date(item.gmtCreated).toLocaleString())
+          this.lookFileTime.push(formDate(item.viewLog.gmtCreated))
         }
       })
-      return arr
-    }
-
-    onLoad(params) {
-      httpRequestApi.getLogList().success(res => {
-        console.log('记录', res)
-        // this.screenshot = res.data.data.screenshot
-        // this.localFile = res.data.data.localFile
-        // this.localFileTime = this.CompileTime(res.data.data.localFile)
-        // this.screenshotTime = this.CompileTime(res.data.data.screenshot)
-        // this.listType = this.CompileTime(res.data.data.localFile, true)
-        // this.$apply()
-      })
     }
   }
 </script>

+ 9 - 1
src/components/del.wpy

@@ -52,6 +52,11 @@
       index: {
         type: Number,
         default: 'null'
+      },
+      fileList: {
+        type: Array,
+        default: 'null',
+        twoWay: true
       }
     }
 
@@ -59,10 +64,13 @@
       del () {
         this.slectFlag = !this.slectFlag
         this.syncFlag = 'false'
-        const taskJoinUser = this.$parent.$data.fileList[this.index].taskJoinUser
+        console.log(this.fileList)
+        const taskJoinUser = this.fileList[this.index].taskJoinUser
         const id = taskJoinUser.id ? taskJoinUser.id : ''
         httpRequestApi.delFile(id, 'CLOSE').success(res => {
           console.log(res)
+          this.fileList[this.index].taskJoinUser.fileStatus = 'CLOSE'
+          this.$apply()
           wx.showToast({
             title: '成功',
             icon: 'success',

+ 5 - 7
src/components/mys.wpy

@@ -159,13 +159,11 @@
     }
 
     methods = {
-
-    }
-
-    onLoad () {
-      this.avatar = wepy.getStorageSync('user').avatar
-      this.nickName = wepy.getStorageSync('user').nickName
-      this.$apply()
+      user: () => {
+        this.avatar = wepy.getStorageSync('user').avatar
+        this.nickName = wepy.getStorageSync('user').nickName
+        this.$apply()
+      }
     }
   }
 </script>

+ 9 - 3
src/pages/detail.wpy

@@ -60,7 +60,7 @@
 </style>
 <template>
   <view class="container">
-    <view class="file-title">文档资料</view>
+    <view class="file-title" wx:if="{{localFile.length!==0}}">文档资料</view>
     <view class="file-box">
       <repeat for="{{localFile}}" key="index" index="index" item="item">
         <view class="file-item" @tap="preview({{item.path}}, {{index}})">
@@ -74,7 +74,7 @@
         </view>
       </repeat>
     </view>
-    <view class="file-title">白板截图</view>
+    <view class="file-title" wx:if="{{screenshot.length!==0}}">白板截图</view>
     <view class="file-box">
       <repeat for="{{screenshot}}" key="index" index="index" item="item">
         <view class="file-item" @tap="previewImg({{item.path}}, {{index}})">
@@ -97,6 +97,7 @@
 <script>
   import wepy from 'wepy'
   import { httpRequestApi } from '../util/httpRequestApi'
+  import { formDate } from '../util/utils'
 
   export default class Detail extends wepy.page {
     components = {
@@ -122,6 +123,7 @@
         })
       },
       preview (url, index) {
+        const type = this.listType[index]
         wx.showLoading({
           title: '加载中'
         })
@@ -131,6 +133,7 @@
             console.log(res.tempFilePath)
             wx.openDocument({
               filePath: res.tempFilePath,
+              fileType: type,
               success: (res) => {
                 wx.hideLoading()
                 console.log('打开文档成功')
@@ -139,6 +142,9 @@
                 httpRequestApi.addViewLog(fileId, taskId).success(res => {
                   console.log('添加文档')
                 })
+              },
+              fail: () => {
+                console.log('失败')
               }
             })
           }
@@ -168,7 +174,7 @@
         if (type) {
           arr.push(item.path.substr(item.path.lastIndexOf('.') + 1))
         } else {
-          arr.push(new Date(item.gmtCreated).toLocaleString())
+          arr.push(formDate(item.gmtCreated))
         }
       })
       return arr

+ 161 - 8
src/pages/index.wpy

@@ -4,7 +4,7 @@
       box-sizing: border-box;
   }
   .tabar {
-    position: absolute;
+    position: fixed;
     left: 0;
     top: 0;
     display: flex;
@@ -13,6 +13,7 @@
     height: 110rpx;
     border-bottom: 2rpx solid #F0F0F0;
     font-size: 32rpx;
+    background: #fff;
     .tabar-list {
       flex:1;
       text-align: center;
@@ -32,11 +33,78 @@
   }
   .content {
     height: 100%;
-    overflow-y: scroll;
   }
   .content::-webkit-scrollbar{
     width: 0;
   }
+  .dialog {
+    position: fixed;
+    left: 0;
+    top: 0;
+    width: 100%;
+    height: 100%;
+    background: rgba(0, 0, 0, .4);
+    z-index:100;
+  }
+
+  .dialog-contain {
+    position: absolute;
+    left: 0;
+    top: -125rpx;
+    bottom: 0;
+    right: 0;
+    width: 70%;
+    height: 470rpx;
+    background: #fff;
+    margin: auto;
+    border-radius: 20rpx;
+    text-align: center;
+    box-sizing: border-box;
+    display: flex;
+    flex-direction: column;
+    justify-content: space-around;
+    align-items: center;
+    font-size: 32rpx;
+  }
+
+  .dialog-title {
+    font-size: 36rpx;
+    width: 100%;
+    border-bottom: 2rpx solid #ccc;
+    padding: 28rpx 0;
+  }
+
+  .head-bg {
+    width: 37rpx;
+    height: 59rpx;
+  }
+
+  .text {
+    font-size: 28rpx;
+    width: 95%;
+    /* border-bottom: 2rpx solid #ccc; */
+    padding: 14rpx 0;
+  }
+
+  .shuoming {
+    font-size: 28rpx;
+    width: 100%;
+    border-bottom: 2rpx solid #ccc;
+    padding: 14rpx 0 46rpx 0;
+  }
+
+  .btn {
+    margin: 0;
+    padding: 0;
+    font-size: 36rpx;
+    color: #16B016;
+    background: #fff;
+    width: 100%;
+  }
+
+  .btn::after {
+    border: none;
+  }
 </style>
 <template>
   <view class="container">
@@ -53,7 +121,15 @@
       <browse wx:if="{{selectInd == 1}}"/>
       <my wx:if="{{selectInd == 2}}"/>
     </view>
-    <!--<button open-type="getUserInfo">授权登录</button>-->
+    <view class="dialog" wx:if="{{!flag}}">
+      <view class="dialog-contain">
+        <view class="dialog-title">微信授权</view>
+        <image class="head-bg" src="../static/img/logo.png"/>
+        <view class="text">智能白板 申请获得以下权限</view>
+        <view class="shuoming">获得你的公开信(昵称、头像等)</view>
+        <button class="btn"  open-type="getUserInfo" @getuserinfo="getUser">允许</button>
+      </view>
+    </view>
   </view>
 </template>
 
@@ -69,7 +145,9 @@
 
   export default class Index extends wepy.page {
     config = {
-      navigationBarTitleText: '智能共享白板'
+      navigationBarTitleText: '智能共享白板',
+      enablePullDownRefresh: true,
+      backgroundTextStyle: 'dark'
     }
     components = {
       my: Mys,
@@ -81,7 +159,10 @@
 
     data = {
       tab: ['全部文件', '最近浏览', '我'],
-      selectInd: 0
+      selectInd: 0,
+      flag: true,
+      filePage: 1,
+      logPage: 1
     }
 
     computed = {
@@ -93,7 +174,22 @@
 
     methods = {
       select (ind) {
+        if (!this.flag) {
+          return false
+        }
         this.selectInd = ind
+        if (ind === 0 && this.$com.allFile.$data.fileList.length === 0) {
+          this.$com.allFile.methods.getTaskList(1, 10)
+        }
+        if (ind === 1 && this.$com.browse.$data.lookFileList.length === 0) {
+          this.$com.browse.methods.getLogList(1, 10)
+        }
+        if (ind === 2) {
+          this.$com.my.methods.user()
+        }
+      },
+      getUser () {
+        this.onLoad()
       }
     }
 
@@ -101,9 +197,66 @@
     }
 
     onLoad(params, data) {
-      console.log(params)
-      console.log(this.$parent.globalData.errMsg)
-      this.$parent.globalData.scene = params.scene
+      console.log('二维码参数', params)
+      if (params && params.scene) {
+        wepy.setStorageSync('scene', params.scene)
+      }
+      this.$parent.getLogin((res) => {
+        console.log('用户', res)
+        this.flag = true
+        this.$com.allFile.methods.getTaskList(1, 10)
+        this.$apply()
+      }, (error) => {
+        console.log(error)
+        this.flag = false
+        this.$apply()
+      })
+      // this.scene = params.scene
+      // this.$apply()
+      // this.$parent.globalData.scene = this.scene
+    }
+    onReachBottom() {
+      if (this.selectInd === 0) {
+        const totalNo = this.$com.allFile.$data.totalNo
+        this.filePage++
+        if (this.filePage > totalNo) {
+          return false
+        } else {
+          wx.showLoading({
+            title: '加载中'
+          })
+        }
+        setTimeout(() => {
+          this.$com.allFile.methods.getTaskList(this.filePage, 10)
+        }, 1000)
+      }
+      if (this.selectInd === 1) {
+        const totalNo = this.$com.browse.$data.totalNo
+        this.logPage++
+        if (this.logPage > totalNo) {
+          return false
+        } else {
+          wx.showLoading({
+            title: '加载中'
+          })
+        }
+        setTimeout(() => {
+          this.$com.browse.methods.getLogList(this.logPage, 10)
+        }, 1000)
+      }
+    }
+    onPullDownRefresh() {
+      if (this.selectInd === 0) {
+        this.$com.allFile.methods.getTaskList(1, 10, true)
+        this.filePage = 1
+      }
+      if (this.selectInd === 1) {
+        this.$com.browse.methods.getLogList(1, 10, true)
+        this.logPage = 1
+      }
+      setTimeout(() => {
+        wx.stopPullDownRefresh()
+      }, 1000)
     }
   }
 </script>

二進制
src/static/img/dian_b.png


二進制
src/static/img/file_b.png


二進制
src/static/img/liulan.png


二進制
src/static/img/logo.png


+ 4 - 1
src/util/consts.js

@@ -1,4 +1,7 @@
 const httpUrls = {
-  baseApi: 'http://schedule-test.api.efunbox.cn/'
+  // 测试环境
+  // baseApi: 'https://whiteboardtest.ai160.com/'
+  // 正式环境
+  baseApi: 'https://whiteboard.ai160.com/sharedWhiteBoard/'
 }
 export { httpUrls }

+ 1 - 1
src/util/httpRequest.js

@@ -74,7 +74,7 @@ export class RequestService {
             this._sucCallback(res)
           },
           fail: (res) => {
-            this._failCallback()
+            // this._failCallback()
           }
         })
         return this

+ 10 - 3
src/util/httpRequestApi.js

@@ -10,10 +10,14 @@ function genAPIUrl(action) {
 
 export class httpRequestApi {
   // 请求任务列表
-  static getTaskList () {
+  static getTaskList (pageNo, pageSize) {
     const url = genAPIUrl('wx/joinUser')
     return RequestService.sendRequest().url(url).header({
       uid: wepy.getStorageSync('uid')
+    }).data({
+      pageNo,
+      pageSize,
+      uid: wepy.getStorageSync('uid')
     }).send()
   }
   // 列表详情
@@ -28,7 +32,7 @@ export class httpRequestApi {
     const url = genAPIUrl('wx/joinUser')
     return RequestService.sendRequest().header({
       uid: wepy.getStorageSync('uid')
-    }).url(url).data({
+    }).url(url).method('PUT').data({
       id,
       fileStatus
     }).send()
@@ -44,10 +48,13 @@ export class httpRequestApi {
     }).send()
   }
   // 观看记录列表
-  static getLogList () {
+  static getLogList (pageNo, pageSize) {
     const url = genAPIUrl('wx/viewLog')
     return RequestService.sendRequest().header({
       uid: wepy.getStorageSync('uid')
+    }).data({
+      pageNo,
+      pageSize
     }).url(url).send()
   }
 }

+ 16 - 0
src/util/utils.js

@@ -0,0 +1,16 @@
+const formDate = (time) => {
+  console.log(time)
+  const date = new Date(time)
+  const year = date.getFullYear()
+  const month = date.getMonth() + 1
+  const day = date.getDate()
+  const hour = date.getHours()
+  const minute = date.getMinutes()
+
+  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute].map(formatNumber).join(':')
+}
+const formatNumber = n => {
+  n = n.toString()
+  return n[1] ? n : '0' + n
+}
+export {formDate}