123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- // const fs = wx.getFileSystemManager();
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- list: {
- type: Array,
- value: []
- },
- checkedId: {
- type: String,
- value: 0
- },
- changeId: {
- type: Function
- }
- },
- options: {
- addGlobalClass: true
- },
- /**
- * 组件的初始数据
- */
- data: {
- show: false,
- fileSelected: {},
- },
- /**
- * 组件的方法列表
- */
- methods: {
- /* 打开文件 */
- openFile(e) {
- const {
- item
- } = e.currentTarget.dataset;
- if (item.fileType == 'folder') {
- wx.navigateTo({
- url: '/pages/tabbar/smartStore/folder?item=' + JSON.stringify(item),
- })
- } else if (['image', 'video'].includes(item.fileType)) {
- this.preViewMedia(item)
- } else if (['word', 'excel', 'ppt', 'pdf'].includes(item.fileType)) {
- this.openDocument(item)
- } else {
- wx.setClipboardData({
- data: item.url,
- success: function () {
- wx.showToast({
- title: '当前文件类型不支持在线浏览,已将文件下载地址复制到剪切板,您可在浏览器中打开链接下载到本地浏览',
- icon: "none",
- duration: 5000
- });
- }
- })
- }
- },
- preViewMedia(item) {
- wx.previewMedia({
- sources: [{
- url: item.url,
- type: item.fileType,
- }],
- current: 0,
- showmenu: true
- })
- },
- openDocument(item) {
- wx.downloadFile({
- url: item.url,
- success: function (res) {
- console.log(res.tempFilePath)
- wx.openDocument({
- filePath: res.tempFilePath,
- fileType: item.postfix,
- showMenu: true,
- success: function (res) {
- console.log(res)
- console.log('打开文档成功')
- },
- fail: (err) => {
- wx.showToast({
- title: '打开失败',
- icon: "none"
- })
- }
- })
- }
- })
- },
- changeChecked(e) {
- this.triggerEvent("changeId", e.target.dataset.item)
- }
- }
- })
|