import { getDocumentList, packDownload, resetFileName, batchDelete, trash, recovery, trashDelete, folderTree, folderMove, addFolder, shareFolder, shareFolderList, shareTome, shareUser, shareAdjustment, cancelShare, fileDetail } from "@/api/workFlow/document"; import resources from "@/libs/resources.js"; import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js"; import jnpf from '@/utils/jnpf' const wordTypeList = ['doc', 'docx']; const excelTypeList = ['xls', 'xlsx']; const pptTypeList = ['ppt', 'pptx']; const pdfTypeList = ['pdf']; const zipTypeList = ['rar', 'zip', 'arj', 'z', '7z']; const txtTypeList = ['txt', 'log']; const codeTypeList = ['html', 'cs', 'xml']; const imgTypeList = ['png', 'jpg', 'jpeg', 'bmp', 'gif']; const videoTypeList = ['avi', 'wmv', 'mpg', 'mpeg', 'mov', 'rm', 'ram', 'swf', 'flv', 'mp4', 'mp3', 'wma', 'avi', 'rm', 'rmvb', 'flv', 'mpg', 'mkv' ]; const previewTypeList = [...wordTypeList, ...excelTypeList, ...pptTypeList, ...pdfTypeList]; export default { mixins: [MescrollMixin], data() { return { usersSelectValue: '', isDetail: true, showApply: false, folderTreeList: [], modalValue: '', keyword: '', current: 0, show: false, slide: '', slide2: '', changeStyle: true, checkedAll: false, parentId: 0, wordImg: resources.document.wordImg, excelImg: resources.document.excelImg, pptImg: resources.document.pptImg, pdfImg: resources.document.pdfImg, rarImg: resources.document.rarImg, txtImg: resources.document.txtImg, codeImg: resources.document.codeImg, imageImg: resources.document.imageImg, audioImg: resources.document.audioImg, blankImg: resources.document.blankImg, folderImg: resources.document.folderImg, downOption: { use: true, auto: true, }, upOption: { page: { num: 0, size: 50, time: null, }, empty: { use: true, icon: resources.message.nodata, tip: this.$t('common.noData'), fixed: false, top: "560rpx", }, textNoMore: this.$t('app.apply.noMoreData'), toTop: { bottom: 200, right: 80 } }, selectFolder: {}, moveId: '', selectFiles: [], modalType: 'restName', showAddSelect: false, selector: [{ fullName: '新建文件夹', id: 1, icon: 'icon-ym icon-ym-add-folder' }, { fullName: '上传文件', id: 2, icon: 'icon-ym icon-ym-generator-menu' } ], isDetail: false } }, computed: { baseURL() { return this.define.baseURL }, modalTitle() { return this.modalType === 'restName' ? '重命名文件' : '新建文件夹' } }, methods: { onCallback(e) { this.$u.toast(e.msg) setTimeout(() => { this.showAddSelect = false this.resetList() }, 1000) }, addSelect(item) { if (item == 'add') { this.showAddSelect = false this.$refs.inputDialog.open('center') this.modalType = 'addFolder' } }, addFolder() { this.modalValue = '' this.showAddSelect = true }, shareSubmit(e) { let method = this.current === 1 ? shareAdjustment : shareFolder; let data = { ids: this.selectFiles, userIds: e } method(data).then(res => { this.resetList() }) }, upCallback(page) { let method; switch (this.current) { case 1: method = shareFolderList break; case 3: method = trash break; case 2: method = shareTome break; default: method = getDocumentList break; } let query = { keyword: this.keyword, parentId: this.parentId }; method(query).then(res => { this.documentList = []; this.selectFiles = [] const timeMap = ['creatorTime', 'shareTime', 'shareTime', 'deleteTime']; const useTime = timeMap[this.current] ?? 'creatorTime'; // 添加默认值 const list = res.data.list.map(o => ({ ...o, time: o[useTime] })); this.documentList = this.documentList.concat(list); this.mescroll.endSuccess(list.length); }) }, downLoad(id) { let data = { ids: id ? id : this.selectFiles } packDownload(JSON.stringify(data)).then(res => { // #ifdef H5 const fileUrl = this.baseURL + res.data.url + '&name=' + encodeURI(res.data.name); window.location.href = fileUrl; // #endif // #ifdef MP-WEIXIN this.previewFile(res.data) // #endif // #ifndef H5 || MP this.downloadFile(res.data); // #endif }) }, handelClick(item) { this.moveId = item.id == '-1' ? 0 : item.id }, downloadFile(data) { const { url, name } = data; const fileExt = name.split('.').pop().toLowerCase(); const handleDownload = () => { uni.downloadFile({ url: `${this.baseURL}${url}&name=${name}`, success: (res) => { if (res.statusCode !== 200) return this.$u.toast('文件下载失败'); // #ifdef APP-HARMONY openDocument(res.tempFilePath) // #endif // #ifndef APP-HARMONY if (plus.os.name == 'iOS') { openDocument(res.tempFilePath) return } /* 安卓 */ uni.saveFile({ tempFilePath: res.tempFilePath, success: red => { uni.showToast({ icon: 'none', mask: true, title: '文件已保存:' + red.savedFilePath, //保存路径 duration: 3000, }); }, fail(err) { console.log(err, 547); } }); // #endif }, fail: (err) => { this.$u.toast('文件下载失败'); } }) } const openDocument = (filePath) => { uni.openDocument({ filePath, showMenu: true, success: () => {}, fail: (err) => { console.error('打开文档失败:', err); this.$u.toast('文件打开失败'); } }); } handleDownload(); }, previewFile(item) { let fileTypes = ['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx', 'txt'] let fileType = item.name.split('.')[1] if (fileTypes.includes(fileType)) { uni.downloadFile({ url: `${this.baseURL}${ item.url}&name=${item.name}`, success: (res) => { let filePath = res.tempFilePath; uni.openDocument({ filePath, showMenu: true, success: (res) => {} }); } }); } else { this.$u.toast('该文件类型无法打开') } }, checkboxChange(e) { if (e.length) { this.slide = 'slide-up' this.slide2 = 'slide-up2' const { platform } = uni.getSystemInfoSync() if (platform === 'ios' && this.current == 2) return this.show = false this.show = true } else { this.slide = 'slide-down' this.slide2 = 'slide-down2' } this.selectOperation(e) }, change(e) { this.current = e this.parentId = 0 this.resetList() }, bottomfun(type) { if (type === 'down') this.downLoad() if (type === 'restName') { fileDetail(this.selectFiles[0]).then(res => { this.modalValue = res?.data?.fullName || '' this.modalType = 'restName' this.$refs.inputDialog.open() }) } if (type === 'checkAll') this.checkedAllFun() if (type === 'revert') this.recoveryOrDelete(type) if (type === 'delete') this.recoveryOrDelete(type) if (type === 'share') { if (this.current == 1) return this.shareUser() this.usersSelectValue = '' this.$nextTick(() => { this.$refs.JnpfUsersSelect.openSelect() }) } if (type === 'shareCancel') return this.cancelShare() if (type === 'move') this.getFolderTree() if (type === 'cancel') { this.selectFiles = [] this.selectOperation(this.selectFiles) } }, cancelShare() { uni.showModal({ title: '提示', content: '您确定要取消共享, 是否继续?', success: (res) => { if (res.confirm) { cancelShare({ ids: this.selectFiles }).then(res => { this.$u.toast(res.msg) this.resetList() }) } } }); }, shareUser() { shareUser(this.selectFiles[0]).then(res => { let list = res.data.list || [] const ids = list.map(item => item.shareUserId); this.usersSelectValue = ids this.$nextTick(() => { this.$refs.JnpfUsersSelect.openSelect() }) }) }, folderMove() { let data = { ids: this.selectFiles, id: this.moveId } folderMove(data).then(res => { this.selectFiles = [] this.close() this.resetList() }) }, iconClick() { if (this.documentList.length) this.changeStyle = !this.changeStyle }, close() { this.showApply = false }, checkedAllFun() { this.checkedAll = !this.checkedAll this.selectFiles = []; this.documentList.forEach(o => { if (this.checkedAll) { this.$set(o, 'checked', true) this.selectFiles.push(o.id); } else { this.$set(o, 'checked', false) this.selectFiles = []; } }) }, goDetail(e) { if (e.type == 0 && this.current != 3) { if (!this.isDetail) { let item = { current: this.current, changeStyle: this.changeStyle, ...e } this.selectFiles = [] this.selectOperation() uni.navigateTo({ url: './detail?config=' + JSON.stringify(item), }); } else { this.parentId = e.id this.setTitle(e.fullName) this.pushTreeStack(e); this.resetList() } } else { if (imgTypeList.includes(e.fileExtension)) { const images = jnpf.getAuthImgUrl(e.uploaderUrl, false); uni.previewImage({ urls: [images], success: (res) => {}, fail: (err) => { uni.showToast({ title: '预览图片失败', icon: 'none' }); } }); return } if (this.current !== 3) this.downLoad([e.id]) } }, selectOperation(value) { let items = this.documentList; this.selectFiles = value || []; for (let i = 0, lenI = items.length; i < lenI; ++i) { const item = items[i] if (this.selectFiles.includes(item.id)) { this.$set(item, 'checked', true) } else { this.$set(item, 'checked', false) } } }, getRecordImg(ext) { if (!ext) return this.folderImg; if (ext) ext = ext.replace('.', ''); if (wordTypeList.includes(ext)) return this.wordImg; if (excelTypeList.includes(ext)) return this.excelImg; if (pptTypeList.includes(ext)) return this.pptImg; if (pdfTypeList.includes(ext)) return this.pdfImg; if (zipTypeList.includes(ext)) return this.rarImg; if (txtTypeList.includes(ext)) return this.txtImg; if (codeTypeList.includes(ext)) return this.codeImg; if (imgTypeList.includes(ext)) return this.imageImg; if (videoTypeList.includes(ext)) return this.audioImg; return this.blankImg; }, getFolderTree() { let data = { ids: this.selectFiles } folderTree(data).then(res => { this.showApply = true this.folderTreeList = JSON.parse(JSON.stringify(res.data.list)) || [] const loop = (list, parent) => { list.forEach(o => { o.icon = 'icon-ym icon-ym-folder'; if (o && o.children && Array.isArray(o.children)) { loop(o.children, o) } }) } loop(this.folderTreeList) }) }, recoveryOrDelete(type) { let data = { ids: this.selectFiles } let content = '确定要还原选中的文件吗' let method = recovery if (type !== 'revert') { content = '删除后,放入回收站!' method = batchDelete if (type === 'delete' && this.current == 3) { content = '删除后数据无法恢复' method = trashDelete } } uni.showModal({ title: '提示', content, success: (res) => { if (res.confirm) { this.$nextTick(() => { method(JSON.stringify(data)).then(res => { this.$u.toast(res.msg) setTimeout(() => { this.$nextTick(() => { this.documentList = []; this.selectFiles = [] this.mescroll.resetUpScroll(); }) }, 1000) }) }) } } }); }, /* 新建文件 */ handleAddFolder() { let item = { id: '', parentId: this.parentId, type: 0, fullName: this.modalValue } addFolder(item).then(res => { this.modalType = 'restName' this.closeDialog() this.resetList() }) }, /* 重命名 */ closeDialog() { this.$refs.inputDialog.close() }, restName(e) { let txt = this.modalType === 'addFolder' ? '文件夹名称不能为空' : '文件名不能为空' if (!this.modalValue) return this.$u.toast(txt) if (this.modalType === 'addFolder') return this.handleAddFolder() if (this.modalType === 'restName') return this.handleRestName() }, handleRestName() { let item = {} this.documentList.forEach(o => { if (o.id === this.selectFiles[0]) item = { id: o.id, parentId: this.parentId, type: o.type, fullName: this.modalValue } }) resetFileName(item).then(res => { this.selectFiles = [] this.closeDialog() this.resetList() }) }, resetList() { this.$nextTick(() => { this.selectFiles = [] this.documentList = []; this.mescroll.resetUpScroll(); }) }, } }