| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
- Page({
- behaviors: [PageContainerBehavior],
- data: {
- orderId: "",
- product: {} as { name: string; image: string; description?: string },
- score: 5,
- rateColor: "#F7BA2A",
- content: "描述相符,商品质量很好,包装完整,会回购。",
- mediaList: [] as { path: string; type: "image" | "video" }[],
- videoFullscreen: false,
- showMediaCarousel: false,
- mediaCarouselCurrent: 0,
- },
- onLoad(options: Record<string, string>) {
- const orderId = options.orderId || options.id || "";
- let product: { name: string; image: string; description?: string } = {
- name: "",
- image: "",
- description: "",
- };
- console.log(options, "options.goodsInfo===");
- if (options.goodsInfo) {
- try {
- const goods = JSON.parse(decodeURIComponent(options.goodsInfo));
- product = {
- name: goods.name || "",
- image: goods.image || "",
- description: goods.description || "",
- };
- } catch (_) {}
- }
- console.log(product, "product===");
- // 若传入评价详情数据则使用,否则用默认展示内容(含示例图片)
- let score = 5;
- let content = "描述相符,商品质量很好,包装完整,会回购。";
- let mediaList: { path: string; type: "image" | "video" }[] = [
- { path: "https://wx.hzliuzhi.com/media/healthManager/wx/share.jpg", type: "image" },
- { path: "https://www.bing.com/ck/a?!&&p=7a26e0938030f722bac8864df3c965e36cf2569da9cb49288cb379ee8c3a662eJmltdHM9MTc3MjY2ODgwMA&ptn=3&ver=2&hsh=4&fclid=0f40599a-c9c4-6515-0a75-4f28c8bc64d0&u=a1L3ZpZGVvcy9yaXZlcnZpZXcvcmVsYXRlZHZpZGVvP3E9MTBzJWU4JWE3JTg2JWU5JWEyJTkxJiZtaWQ9MTcxMjQxNTk0MzFFQ0Y3OTFDNEExNzEyNDE1OTQzMUVDRjc5MUM0QSZGT1JNPVZBTUdaQw", type: "video" },
- { path: "https://wx.hzliuzhi.com/media/healthManager/wx/share.jpg", type: "image" },
- { path: "https://www.bing.com/ck/a?!&&p=7a26e0938030f722bac8864df3c965e36cf2569da9cb49288cb379ee8c3a662eJmltdHM9MTc3MjY2ODgwMA&ptn=3&ver=2&hsh=4&fclid=0f40599a-c9c4-6515-0a75-4f28c8bc64d0&u=a1L3ZpZGVvcy9yaXZlcnZpZXcvcmVsYXRlZHZpZGVvP3E9MTBzJWU4JWE3JTg2JWU5JWEyJTkxJiZtaWQ9MTcxMjQxNTk0MzFFQ0Y3OTFDNEExNzEyNDE1OTQzMUVDRjc5MUM0QSZGT1JNPVZBTUdaQw", type: "video" },
- { path: "https://wx.hzliuzhi.com/media/healthManager/wx/share.jpg", type: "image" },
- { path: "https://www.bing.com/ck/a?!&&p=7a26e0938030f722bac8864df3c965e36cf2569da9cb49288cb379ee8c3a662eJmltdHM9MTc3MjY2ODgwMA&ptn=3&ver=2&hsh=4&fclid=0f40599a-c9c4-6515-0a75-4f28c8bc64d0&u=a1L3ZpZGVvcy9yaXZlcnZpZXcvcmVsYXRlZHZpZGVvP3E9MTBzJWU4JWE3JTg2JWU5JWEyJTkxJiZtaWQ9MTcxMjQxNTk0MzFFQ0Y3OTFDNEExNzEyNDE1OTQzMUVDRjc5MUM0QSZGT1JNPVZBTUdaQw", type: "video" },
- ];
- // if (options.evaluateInfo) {
- // try {
- // const info = JSON.parse(decodeURIComponent(options.evaluateInfo));
- // if (info.score != null) score = Number(info.score);
- // if (info.content != null) content = info.content;
- // if (Array.isArray(info.mediaList) && info.mediaList.length > 0) mediaList = info.mediaList;
- // } catch (_) {}
- // }
- this.setData({
- orderId,
- product,
- score,
- content,
- mediaList,
- });
- },
- onBack() {
- wx.navigateBack();
- },
- /** 打开图片/视频统一轮播,从指定下标开始;轮播到视频时自动播放 */
- onPreviewMedia(e: WechatMiniprogram.TouchEvent) {
- const index = e.currentTarget.dataset.index as number;
- const { mediaList } = this.data;
- if (index < 0 || index >= mediaList.length) return;
- this.setData(
- { showMediaCarousel: true, mediaCarouselCurrent: index },
- () => {
- this._playVideoAtCarouselIndex(index);
- }
- );
- },
- /** 轮播切换:暂停所有视频,若当前项是视频则播放 */
- onMediaCarouselChange(e: WechatMiniprogram.SwiperChange) {
- const current = e.detail?.current ?? 0;
- this.setData({ mediaCarouselCurrent: current });
- this._pauseAllCarouselVideos();
- this._playVideoAtCarouselIndex(current);
- },
- onCloseMediaCarousel() {
- this._pauseAllCarouselVideos();
- this.setData({ showMediaCarousel: false });
- },
- _playVideoAtCarouselIndex(index: number) {
- const list = this.data.mediaList;
- if (index < 0 || index >= list.length || list[index].type !== "video") return;
- const ctx = wx.createVideoContext("preview-video-" + index, this);
- ctx.play();
- },
- _pauseAllCarouselVideos() {
- this.data.mediaList.forEach((item, i) => {
- if (item.type === "video") {
- const ctx = wx.createVideoContext("preview-video-" + i, this);
- ctx.pause();
- }
- });
- },
- onVideoFullscreenChange(e: WechatMiniprogram.VideoFullScreenChange) {
- const fullScreen = !!(e.detail && e.detail.fullScreen);
- this.setData({ videoFullscreen: fullScreen });
- },
- });
|