日照项目的居民端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

112 lines
2.4 KiB

import {
wxPreviewImage,
wxPreviewMedia,
wxOpenDocument,
wxDownloadFile,
} from "@utils/promise-wx-api";
const app = getApp();
const sys = wx.getSystemInfoSync();
Component({
behaviors: [],
properties: {
list: {
type: Array,
value: [],
},
},
data: {
showList: [],
},
lifetimes: {
attached() {
this.init();
},
},
observers: {
list(val) {
this.getShowList(val);
},
},
methods: {
init() {},
getShowList(list) {
if (!Array.isArray(list)) return;
this.setData({
showList: list.map((item) => {
let nameArr = item.name.split(".");
if (nameArr.length > 1) {
nameArr.pop();
item.showName = nameArr.join(".");
} else {
item.showName = item.name;
}
return item;
}),
});
},
// 删除封面
async handleTapItem(e) {
const {
currentTarget: {
dataset: { index },
},
} = e;
console.log(index);
this.previewItem(index);
},
// 预览
async previewItem(index) {
const { showList } = this.data;
const item = showList[index];
if (item.type === "doc") {
if (!item.tempFilePath) {
wx.showLoading({
title: "加载中",
});
const { msg, data } = await wxDownloadFile({
url: item.url,
filePath: wx.env.USER_DATA_PATH + "/" + item.name,
});
wx.hideLoading();
if (msg === "success") {
item.tempFilePath = data.filePath;
}
this.setData({ showList });
}
wxOpenDocument({
filePath: item.tempFilePath,
showMenu: true,
});
} else if (item.type === "video") {
const res = await wxPreviewMedia({
sources: [
{
url: item.url,
type: item.type,
},
],
});
if (res.msg === "previewMedia:fail:not supported") {
return wx.showToast({
title: "当前环境不支持查看视频",
icon: "none",
duration: 2000,
});
}
} else if (item.type === "image") {
wxPreviewImage({
urls: [item.url],
});
}
},
},
});