Bläddra i källkod

每日一签列表页

xiaohaizhao 1 år sedan
förälder
incheckning
d3f9ee174b
5 ändrade filer med 521 tillägg och 98 borttagningar
  1. 1 1
      packageA/affiche/detail.vue
  2. 217 8
      packageA/dailyYttendance/index.vue
  3. 0 83
      utils/previewFile.js
  4. 286 0
      utils/settleFiles.js
  5. 17 6
      utils/tool.js

+ 1 - 1
packageA/affiche/detail.vue

@@ -45,7 +45,7 @@
 </template>
 
 <script>
-import { viewMedias, viewFlies, formattedFiles } from "../../utils/previewFile"
+import { viewMedias, viewFlies, formattedFiles } from "../../utils/settleFiles"
 export default {
     data() {
         return {

+ 217 - 8
packageA/dailyYttendance/index.vue

@@ -1,34 +1,243 @@
 <template>
     <view>
-        <My_listbox ref="List" @getlist="getList(true)">
-        </My_listbox>
+        <calendar :date="date" showShrink shrinkState="week" weekType="" :signList="signList" @dayChange="dayChange" />
+        <view v-if="dates[viewDate] && dates[viewDate].attinfos.length">
+            <swiper class="poster" :current="current" circular v-if="dates[viewDate].attinfos.length" indicator-dots
+                indicator-active-color="#fff" @change="swiperChange">
+                <swiper-item v-for="item in dates[viewDate].attinfos" :key="item.attachmentid">
+                    <image class="image" v-if="item.fileType == 'image'" :src="item.url" mode="aspectFit" lazy-load="true"
+                        @click="previewImage(item.url)" />
+                    <video class="video" :id="'Video' + item.attachmentid" v-if="item.fileType == 'video'"
+                        :poster="item.subfiles[0].url" :src="item.url" />
+                </swiper-item>
+            </swiper>
+
+            <view class="text-box">
+                <view class="title">分享海报宣传文本,例如:</view>
+                <textarea class="textarea" :value="dates[viewDate].notes" @input="notesSava" maxlength="499"
+                    placeholder="分享海报宣传文本" />
+            </view>
+        </view>
+        <view v-else style="padding-top: 50px;">
+            <u-empty mode="data" text="暂无数据" />
+        </view>
+        <view style="height: 80px;" />
+        <view class="bottom" v-if="dates[viewDate] && dates[viewDate].attinfos.length">
+            <view class="but up" @click="copyNotes(dates[viewDate].notes)" hover-class="navigator-hover">
+                复制文本
+            </view>
+            <view v-if="dates[viewDate].attinfos[current].fileType == 'image'" class="but submit"
+                hover-class="navigator-hover">
+                自定义海报及保存
+            </view>
+            <view v-else class="but submit" hover-class="navigator-hover"
+                @click="saveVideo(dates[viewDate].attinfos[current])">
+                保存视频
+            </view>
+        </view>
     </view>
 </template>
 
 <script>
+import calendar from "../../uni_modules/lunc-calendar/components/lunc-calendar/lunc-calendar.vue";
+import { formattedFiles, viewImage, wxSaveFile } from "../../utils/settleFiles";
 export default {
+    components: { calendar },
     data() {
         return {
-
+            current: 0,
+            date: new Date(),
+            signList: [],
+            "content": {
+                "pageNumber": 1,
+                "pageSize": 9999,
+                "where": {
+                    "condition": "",
+                    "year": "",
+                    "month": ""
+                }
+            },
+            viewDate: "",
+            dates: {}
         }
     },
     onLoad() {
         wx.setNavigationBarTitle({
             title: this.getApps('资料库', '/packageA/dailyYttendance/index').remark || '每日一签',
         });
+        this.viewDate = this.formatTime().split(" ")[0]
+        const time = this.viewDate.split("-")
+        this.content.where.year = time[0];
+        this.content.where.month = time[1];
+        this.getList(true)
     },
     onShow() {
-        this.updateList()
+        if (this.content.pageNumber && this.content.pageNumber >= 2) this.getList(true)
     },
     methods: {
         getList(init = false) {
-
+            if (this.paging(this.content, init)) return;
+            this.$Http.basic({
+                "id": "20240319104102",
+                content: this.content
+            }).then(res => {
+                console.log("获取每日一签列表", res)
+                if (this.cutoff(res.msg)) return;
+                let dates = {};
+                this.signList = res.data.map(v => {
+                    v.attinfos = formattedFiles(v.attinfos)
+                    v.videoIds = v.attinfos.filter(v => v.fileType == 'video').map(v => `Video${v.attachmentid}`)
+                    dates[v.ondate] = v;
+                    return { date: v.ondate }
+                })
+                this.dates = dates;
+                this.record();
+                console.log("date", this.dates[this.viewDate])
+            })
         },
-        updateList() {
-
+        dayChange(e) {
+            this.viewDate = e.date;
+            this.current = 0;
+            const {
+                year, month
+            } = this.content.where;
+            if (year != e.year || month != e.month) {
+                this.content.where.year = e.year;
+                this.content.where.month = e.month;
+                this.getList(true)
+            }
+            console.log("date", this.dates[this.viewDate])
+            this.record();
+        },
+        swiperChange(e) {
+            this.current = e.detail.current;
+            this.dates[this.viewDate].videoIds.forEach(v => uni.createVideoContext(v).pause())
+        },
+        previewImage(url) {
+            viewImage(url)
+        },
+        saveVideo(file) {
+            wxSaveFile(file)
+            this.record(1)
+        },
+        notesSava(e) {
+            this.dates[this.viewDate].notes = e.detail.value;
+        },
+        copyNotes(notes) {
+            if (!notes.length) uni.showToast({
+                title: '还未输入宣传文本',
+                duration: 2000,
+                icon: "none"
+            });
+            uni.setClipboardData({
+                data: notes,
+            })
+        },
+        //0:阅读记录 1:下载记录:2:发送邮件
+        record(type = 0, sat_sharematerialid = 0) {
+            try {
+                if (sat_sharematerialid == 0) this.dates[this.viewDate].sat_sharematerialid;
+                this.$Http.basic({
+                    "id": 20240319142702,
+                    "content": {
+                        sat_sharematerialid, type
+                    }
+                }).then(res => {
+                    console.log(type, '记录', res)
+                })
+            } catch (error) {
+            }
         }
     },
 }
 </script>
 
-<style lang="scss"></style>
+<style lang="scss">
+.poster {
+    height: 356px;
+    width: 100vw;
+    margin: 20px 0;
+    box-sizing: border-box;
+
+    .image,
+    .video {
+        width: 100%;
+        height: 100%;
+    }
+}
+
+.text-box {
+    width: 100vw;
+    background: #fff;
+    border-radius: 8px;
+    padding: 10px;
+    box-sizing: border-box;
+
+    .title {
+        height: 20px;
+        line-height: 20px;
+        font-family: Source Han Sans SC, Source Han Sans SC;
+        font-size: 14px;
+        color: #333333;
+    }
+
+    .textarea {
+        width: 100%;
+        height: 100px;
+        background: #FFFFFF;
+        border-radius: 8px;
+        border: 1px solid #CCCCCC;
+        padding: 10px;
+        margin-top: 10px;
+        box-sizing: border-box;
+    }
+}
+
+
+.bottom {
+    display: flex;
+    position: fixed;
+    bottom: 0;
+    width: 375px;
+    height: 64px;
+    background: #FFFFFF;
+    box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
+    padding-right: 10px;
+    box-sizing: border-box;
+    z-index: 9999999;
+
+    .but {
+        display: flex;
+        align-items: center;
+        justify-content: center;
+        margin-left: 10px;
+        width: 168px;
+        height: 45px;
+        border-radius: 5px;
+        margin-top: 4px;
+        box-sizing: border-box;
+    }
+
+    .up {
+        background: #FFFFFF;
+        border: 1px solid #999999;
+        font-size: 16px;
+        color: #666666;
+        width: 82px;
+    }
+
+    .down,
+    .submit {
+        background: #095DE0;
+        font-family: PingFang SC, PingFang SC;
+        font-size: 16px;
+        color: #FFFFFF;
+    }
+
+    .submit {
+        flex: 1;
+        background: #C30D23;
+        width: 263px;
+    }
+}
+</style>

+ 0 - 83
utils/previewFile.js

@@ -1,83 +0,0 @@
-function formattedFiles(list) {
-    if (list.length == 0) return [];
-    let suffixList = {
-            image: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'svg', 'tiff'],
-            video: ['mp4', 'ogg', 'webm'],
-            word: ['doc', 'docx'],
-            excel: ['xls', 'xlsx'],
-            ppt: ['ppt', 'pptx'],
-            txt: ['txt', 'md', 'js', 'json'],
-            pdf: ['pdf'],
-            rar: ['7z', 'zip', 'rar', 'kz', 'ace', 'arj', 'bz2', 'cab', 'gz', 'iso', 'jar', 'lzh', 'tar', 'z'],
-            folder: ['folder']
-        },
-        typeList = [];
-    for (let key in suffixList) typeList.push(key);
-    for (let i = 0; i < list.length; i++) {
-        list[i].fileType = 'unknown';
-        const suffix = list[i].postfix.toLowerCase();
-        if (suffix != "folder") {
-            for (var key in suffixList) {
-                if (suffixList[key].some(value => value == suffix)) list[i].fileType = key;
-            }
-        } else {
-            list[i].fileType = "folder";
-        }
-    }
-    return list;
-}
-
-/* 预览媒体 */
-function viewMedias(files, index, type) {
-    // #ifndef MP
-    if (type == 'image') {
-        uni.previewImage({
-            current: index,
-            urls: files,
-            loop: true,
-        })
-    } else {
-        window.open(files[index].url)
-    }
-    // #endif
-    // #ifdef MP-WEIXIN
-    wx.previewMedia({
-        current: index,
-        sources: files,
-    })
-    // #endif       
-}
-/* 预览文档 */
-function viewFlies(item) {
-    uni.showLoading({
-        title: '加载中...',
-    })
-    uni.downloadFile({
-        url: item.url,
-        complete({
-            statusCode,
-            tempFilePath
-        }) {
-            if (statusCode != 200) return;
-            uni.openDocument({
-                filePath: tempFilePath,
-                fileType: item.postfix,
-                showMenu: true,
-                complete({
-                    errMsg
-                }) {
-                    uni.hideLoading();
-                    if (errMsg != "openDocument:ok") uni.showToast({
-                        title: '打开失败',
-                        icon: "none"
-                    })
-                }
-            })
-        }
-    })
-}
-module.exports = {
-    viewMedias,
-    viewFlies,
-    formattedFiles
-}

+ 286 - 0
utils/settleFiles.js

@@ -0,0 +1,286 @@
+function formattedFiles(list) {
+    if (list.length == 0) return [];
+    let suffixList = {
+            image: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'svg', 'tiff'],
+            video: ['mp4', 'ogg', 'webm'],
+            word: ['doc', 'docx'],
+            excel: ['xls', 'xlsx'],
+            ppt: ['ppt', 'pptx'],
+            txt: ['txt', 'md', 'js', 'json'],
+            pdf: ['pdf'],
+            rar: ['7z', 'zip', 'rar', 'kz', 'ace', 'arj', 'bz2', 'cab', 'gz', 'iso', 'jar', 'lzh', 'tar', 'z'],
+            folder: ['folder']
+        },
+        typeList = [];
+    for (let key in suffixList) typeList.push(key);
+    for (let i = 0; i < list.length; i++) {
+        list[i].fileType = 'unknown';
+        const suffix = list[i].postfix.toLowerCase();
+        if (suffix != "folder") {
+            for (var key in suffixList) {
+                if (suffixList[key].some(value => value == suffix)) list[i].fileType = key;
+            }
+        } else {
+            list[i].fileType = "folder";
+        }
+    }
+    return list;
+}
+
+/* 预览媒体 */
+function viewMedias(files, index, type) {
+    // #ifndef MP
+    if (type == 'image') {
+        uni.previewImage({
+            current: index,
+            urls: files,
+            loop: true,
+        })
+    } else {
+        window.open(files[index].url)
+    }
+    // #endif
+    // #ifdef MP-WEIXIN
+    uni.previewMedia({
+        current: index,
+        sources: files,
+    })
+    // #endif       
+}
+
+/* 预览图片 */
+function viewImage(url) {
+    // #ifndef MP
+    uni.previewImage({
+        current: 0,
+        urls: [url],
+        loop: true,
+    })
+    // #endif
+    // #ifdef MP-WEIXIN
+    uni.previewImage({
+        urls: [url]
+    })
+    // #endif       
+}
+
+/* 预览文档 */
+function viewFlies(item) {
+    uni.showLoading({
+        title: '加载中...',
+    })
+    uni.downloadFile({
+        url: item.url,
+        complete({
+            statusCode,
+            tempFilePath
+        }) {
+            if (statusCode != 200) return;
+            uni.openDocument({
+                filePath: tempFilePath,
+                fileType: item.postfix,
+                showMenu: true,
+                complete({
+                    errMsg
+                }) {
+                    uni.hideLoading();
+                    if (errMsg != "openDocument:ok") uni.showToast({
+                        title: '打开失败',
+                        icon: "none"
+                    })
+                }
+            })
+        }
+    })
+}
+
+function wxSaveFile(file) {
+    const fs = uni.getFileSystemManager(),
+        basePath = String(`${uni.env.USER_DATA_PATH}/${file.postfix}`);
+    fs.access({
+        path: basePath,
+        success(res) {
+            fs.getSavedFileList({
+                success: res => {
+                    console.log("临时文件列表", res)
+                }
+            })
+        },
+        fail(res) {
+            fs.mkdir({
+                dirPath: basePath,
+                recursive: true,
+                success(res) {
+                    console.log("创建目录", res)
+                },
+                fail(res) {
+                    console.error("创建目录", res)
+                }
+            })
+        }
+    })
+    const downloadTask = uni.downloadFile({
+        url: file.url,
+        filePath: basePath + '/' + file.document,
+        timeout: 6000000,
+        success(res) {
+            console.log("下载文件", res)
+            if (file.fileType == "video") {
+                saveVideo(res.filePath)
+            } else {
+                saveImage(res.filePath)
+            }
+
+            function shareVideo() {
+                uni.shareVideoMessage({
+                    videoPath: res.tempFilePath,
+                    complete(res) {
+                        console.log("转发", res)
+                        clearFile(filePath)
+                        /* uni.showToast({
+                            title: `转发失败:${err.errMsg}`,
+                            icon: "none"
+                        }) */
+                    }
+                })
+            }
+
+            function saveImage(filePath) {
+                uni.saveImageToPhotosAlbum({
+                    filePath,
+                    success(res) {
+                        console.log("保存图片", res)
+                        uni.showModal({
+                            title: '提示',
+                            content: '图片已保存到系统相册',
+                            showCancel: false
+                        })
+                        uni.hideLoading()
+                        clearFile(filePath)
+                    },
+                    fail(err) {
+                        console.log("保存失败", err)
+                        if (err.errno == 103) {
+                            uni.showModal({
+                                title: '提示',
+                                content: '未获取保存相册权限,无法保存!',
+                                confirmText: "前去授权",
+                                success({
+                                    confirm
+                                }) {
+                                    if (confirm) uni.openSetting({
+                                        success(res) {
+                                            console.log(res.authSetting["scope.writePhotosAlbum"])
+                                            if (res.authSetting["scope.writePhotosAlbum"]) {
+                                                saveVideo(filePath)
+                                            } else {
+                                                uni.showToast({
+                                                    title: '未获得授权',
+                                                    icon: "none"
+                                                })
+                                            }
+                                        }
+                                    })
+                                }
+                            })
+                        } else {
+                            clearFile(filePath)
+                            uni.showToast({
+                                title: err,
+                                icon: "none"
+                            })
+                        }
+                    }
+                })
+            }
+
+            function saveVideo(filePath) {
+                uni.saveVideoToPhotosAlbum({
+                    filePath,
+                    success(res) {
+                        console.log("保存商品", res)
+                        uni.showModal({
+                            title: '提示',
+                            content: '视频已保存到系统相册',
+                            showCancel: false
+                        })
+                        uni.hideLoading()
+                        clearFile(filePath)
+                    },
+                    fail(err) {
+                        console.log("保存失败", err)
+                        if (err.errno == 103) {
+                            uni.showModal({
+                                title: '提示',
+                                content: '未获取保存相册权限,无法保存!',
+                                confirmText: "前去授权",
+                                success({
+                                    confirm
+                                }) {
+                                    if (confirm) uni.openSetting({
+                                        success(res) {
+                                            console.log(res.authSetting["scope.writePhotosAlbum"])
+                                            if (res.authSetting["scope.writePhotosAlbum"]) {
+                                                saveVideo(filePath)
+                                            } else {
+                                                uni.showToast({
+                                                    title: '未获得授权',
+                                                    icon: "none"
+                                                })
+                                            }
+                                        }
+                                    })
+                                }
+                            })
+                        } else {
+                            clearFile(filePath)
+                            uni.showToast({
+                                title: err,
+                                icon: "none"
+                            })
+                        }
+                    }
+                })
+            }
+
+            function clearFile(filePath) {
+                let fs = uni.getFileSystemManager()
+                fs.unlink({
+                    filePath,
+                    success(res) {
+                        console.log("文件删除", res)
+                    },
+                    fail(res) {
+                        console.log("删除失败", res)
+                    }
+                })
+            }
+
+        },
+        fail(err) {
+            console.log("下载失败", err)
+            uni.showToast({
+                title: `下载失败:${err.errMsg}`,
+                icon: "none"
+            })
+            if (err.errMsg == 'downloadFile:fail exceed max file size') uni.showToast({
+                title: '视频体积超大,无法保存!请尝试打开视频长按保存下载',
+                icon: "none"
+            })
+        }
+    })
+    downloadTask.onProgressUpdate((res) => {
+        uni.showLoading({
+            title: res.progress + `%`,
+            mask: true
+        })
+        if (res.progress == 100) uni.hideLoading()
+    })
+}
+module.exports = {
+    viewMedias,
+    viewFlies,
+    formattedFiles,
+    viewImage,
+    wxSaveFile
+}

+ 17 - 6
utils/tool.js

@@ -114,16 +114,27 @@ function mount() {
             }
         })
     };
-    //得到缩略图或者压缩图  getType默认得到缩略图传true得到压缩图
-    /**
-     * 
-     * @param {string} type compressed压缩图;thumbnail缩略图,hls转码视频,cover封面
-     * @returns 
-     */
+    //compressed压缩图;thumbnail缩略图,hls转码视频,cover封面
     Vue.prototype.getSpecifiedImage = (item, type = 'thumbnail') => {
         let v = item.subfiles.find(v => v.type == type);
         return v ? v.url : item.url;
     }
+
+    Vue.prototype.formatTime = (date = new Date(), j1 = '-', j2 = ':') => {
+        const year = date.getFullYear()
+        const month = date.getMonth() + 1
+        const day = date.getDate()
+        const hour = date.getHours()
+        const minute = date.getMinutes()
+        const second = date.getSeconds()
+
+        const formatNumber = n => {
+            n = n.toString()
+            return n[1] ? n : `0${n}`
+        }
+
+        return `${[year, month, day].map(formatNumber).join(j1)} ${[hour, minute, second].map(formatNumber).join(j2)}`
+    }
 }
 
 module.exports = {