changePopup.js 2.08 KB
const IMG_URL =
  "https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/";

Component({
  properties: {
    show: {
      type: Boolean,
      value: false,
    },
    title: {
      type: String,
      value: "选择商品",
    },
    height: {
      type: String,
      value: "70%",
    },
    changes: {
      type: Array,
      value: [],
    },
    singleButton: {
      type: Boolean,
      value: false,
    },
    confirmText: {
      type: String,
      value: "确认",
    },
  },

  data: {
    IMG_URL,
    videoProcess: "?x-oss-process=video/snapshot,t_0,f_jpg",
  },

  methods: {
    onConfirm() {
      this.triggerEvent("confirm");
    },
    onCancel() {
      this.triggerEvent("cancel");
    },
    // 预览图片/视频
    onPreview(e) {
      const { url, type } = e.currentTarget.dataset;
      if (!url) return;
      if (type === "video") {
        wx.previewMedia({
          sources: [
            {
              url,
              type: "video",
            },
          ],
        });
      } else {
        wx.previewImage({
          current: url,
          urls: [url],
        });
      }
    },
    isVideo(url) {
      if (!url || typeof url !== "string") return false;
      const lower = url.toLowerCase();
      return (
        lower.includes("mp4") ||
        lower.includes("mov") ||
        lower.includes("video")
      );
    },
    isMedia(url) {
      if (!url || typeof url !== "string") return false;
      // 判断是否为URL(http/https开头)或图片/视频扩展名
      const lower = url.toLowerCase();
      return (
        url.startsWith("http://") ||
        url.startsWith("https://") ||
        lower.includes(".jpg") ||
        lower.includes(".jpeg") ||
        lower.includes(".png") ||
        lower.includes(".webp") ||
        lower.includes(".gif") ||
        lower.includes(".mp4") ||
        lower.includes(".mov")
      );
    },
    formatType(type) {
      console.log(type, "type");
      if (type === "image") return "图像变更";
      if (type === "video") return "视频变更";
      return "文本变更";
    },
  },
});