pan-mini/unpackage/dist/dev/mp-weixin/pages/detail/detail.js

156 lines
4.4 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_media = require("../../utils/media.js");
const _sfc_main = {
data() {
return {
url: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4",
id: 0,
pattern: {
color: "#19c324",
backgroundColor: "#fff",
selectedColor: "#19c324",
buttonColor: "#19c324",
iconColor: "#fff"
},
isDownload: false,
content: [
{
iconPath: "/static/vip_download.png",
selectedIconPath: "/static/vip_download_active.png",
text: "会员下载",
active: false
},
{
iconPath: "/static/download.png",
selectedIconPath: "/static/download_ok.png",
text: "看视频免费下载",
active: false
}
]
};
},
onLoad(options) {
if (options.id) {
this.id = options.id;
this.$http.get("/resource/detail/" + this.id).then((resp) => {
var _a;
console.log("detail:", resp.data);
this.url = (_a = resp.data) == null ? void 0 : _a.item.android_src;
console.log("detail-url:", this.url);
}).catch((err) => {
console.log("请求异常");
});
} else {
console.log("获取id异常");
}
},
methods: {
trigger(e) {
console.log(e);
this.content[e.index].active = !e.item.active;
common_vendor.index.showModal({
title: "提示",
content: `${this.content[e.index].active ? "选中了" : "取消了"}${e.item.text}`,
success: function(res) {
if (res.confirm) {
console.log("用户点击确定");
} else if (res.cancel) {
console.log("用户点击取消");
}
}
});
},
fabClick() {
common_vendor.index.showToast({
title: "点击了悬浮按钮",
icon: "none"
});
},
switchBtn(hor, ver) {
if (hor === 0) {
this.direction = this.direction === "horizontal" ? "vertical" : "horizontal";
this.directionStr = this.direction === "horizontal" ? "垂直" : "水平";
} else {
this.horizontal = hor;
this.vertical = ver;
}
this.$forceUpdate();
},
switchColor() {
this.is_color_type = !this.is_color_type;
if (this.is_color_type) {
this.pattern.iconColor = "#aaa";
this.pattern.buttonColor = "#fff";
} else {
this.pattern.iconColor = "#fff";
this.pattern.buttonColor = "#007AFF";
}
},
async downloadAction() {
let userInfo = null;
common_vendor.index.getStorage({
key: "user-info",
success: function(res) {
userInfo = res;
},
fail: (err) => {
this.$refs.adRewardedVideo.show();
}
});
if (userInfo != null && userInfo.is_vip) {
try {
const url = "/resource/" + this.id;
const result = await utils_media.downloadAndSaveVideo(url);
if (result) {
this.isDownload = true;
this.pattern.iconColor = this.isDownload ? "#19c324" : "#fff";
this.$http.post("/resource/" + this.id + "/download");
}
} catch (error) {
console.error("下载失败:", error);
}
}
},
onadload(e) {
console.log("广告数据加载成功");
},
onadclose(e) {
const detail = e.detail;
if (detail && detail.isEnded) {
console.log("onadclose " + detail.isEnded);
} else {
console.log("onadclose " + detail.isEnded);
}
},
onaderror(e) {
console.log("onaderror: ", e.detail);
}
}
};
if (!Array) {
const _easycom_uni_fab2 = common_vendor.resolveComponent("uni-fab");
_easycom_uni_fab2();
}
const _easycom_uni_fab = () => "../../uni_modules/uni-fab/components/uni-fab/uni-fab.js";
if (!Math) {
_easycom_uni_fab();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return {
a: $data.url,
b: common_vendor.sr("fab", "5a95e9e6-0"),
c: common_vendor.o($options.trigger),
d: common_vendor.o($options.fabClick),
e: common_vendor.p({
pattern: $data.pattern,
content: $data.content,
horizontal: "right",
vertical: "bottom",
popMenu: true
})
};
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);