2025-07-15 16:18:34 +08:00

149 lines
5.5 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_libraries_watermark = require("../../common/libraries/watermark.js");
const common_libraries_upload = require("../../common/libraries/upload.js");
require("../../gen/Apis.js");
require("../../common/libraries/request.js");
require("../../common/store/useWeAppAuthStore.js");
require("../../common/libraries/apiLoading.js");
if (!Array) {
const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
_easycom_up_icon2();
}
const _easycom_up_icon = () => "../../node-modules/uview-plus/components/u-icon/u-icon.js";
if (!Math) {
_easycom_up_icon();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
__name: "hs-upload",
props: [
"valueModel",
"size",
"display",
"length",
"mediaType",
"labelTitle",
"count",
"styles",
"hasCover",
"iconName",
"iconSize",
"required",
"title"
],
emits: ["update:valueModel"],
setup(__props, { emit }) {
const props = __props;
const list = common_vendor.ref([]);
const handleUpload = async () => {
const res = await common_libraries_upload.upload(props.count || 1, props == null ? void 0 : props.size, (props == null ? void 0 : props.mediaType) || ["image"]);
console.log(res, "res");
list.value = [...list.value, ...res];
emit("update:valueModel", list.value);
};
const onDelete = (idx) => {
if (props == null ? void 0 : props.display) {
return false;
}
list.value.splice(idx, 1);
};
common_vendor.watch(
() => props == null ? void 0 : props.valueModel,
() => {
if (props.valueModel) {
list.value = props.valueModel || [];
}
}
);
const onPreviewMedia = (url) => {
console.log(url, "url1");
if (url) {
common_vendor.index.showLoading({
title: "获取图片中...",
mask: true
});
console.log(url, "url2");
common_vendor.index.downloadFile({
url,
success: (res) => {
const imagePath = res.tempFilePath;
console.log(imagePath, "imagePath");
common_libraries_watermark.watermark.addWatermark(imagePath, "仅用于内部查看,请勿外传");
},
fail: (err) => {
common_vendor.index.showToast({
title: "获取失败",
duration: 1e3
});
console.error("下载图片失败:", err);
}
});
}
};
common_vendor.onMounted(() => {
if (props.valueModel) {
list.value = props.valueModel || [];
}
});
return (_ctx, _cache) => {
var _a, _b, _c, _d;
return common_vendor.e({
a: common_vendor.t((props == null ? void 0 : props.title) || "上传"),
b: props == null ? void 0 : props.required
}, (props == null ? void 0 : props.required) ? {} : {}, {
c: common_vendor.f(list.value, (i, index, i0) => {
var _a2, _b2;
return common_vendor.e({
a: (_a2 = i == null ? void 0 : i.type) == null ? void 0 : _a2.includes("video")
}, ((_b2 = i == null ? void 0 : i.type) == null ? void 0 : _b2.includes("video")) ? {
b: "eb3a1d92-0-" + i0,
c: common_vendor.p({
name: "play-circle-fill",
size: "30"
})
} : {
d: i == null ? void 0 : i.url,
e: common_vendor.o(($event) => onPreviewMedia(i == null ? void 0 : i.url), index)
}, {
f: common_vendor.o(($event) => onDelete(index), index),
g: index === 0 && (props == null ? void 0 : props.hasCover)
}, index === 0 && (props == null ? void 0 : props.hasCover) ? {
h: common_vendor.o(($event) => onDelete(index), index)
} : {}, {
i: index
});
}),
d: common_vendor.s(props == null ? void 0 : props.styles),
e: !(props == null ? void 0 : props.display) && ((_a = list.value) == null ? void 0 : _a.length) < ((props == null ? void 0 : props.count) || 1)
}, !(props == null ? void 0 : props.display) && ((_b = list.value) == null ? void 0 : _b.length) < ((props == null ? void 0 : props.count) || 1) ? common_vendor.e({
f: props == null ? void 0 : props.iconName
}, (props == null ? void 0 : props.iconName) ? {
g: common_vendor.p({
name: props == null ? void 0 : props.iconName,
label: props.labelTitle || "",
color: "#333",
size: (props == null ? void 0 : props.iconSize) || 50
})
} : {
h: common_vendor.p({
name: (props == null ? void 0 : props.iconName) || "plus",
label: props.labelTitle || "",
labelPos: "bottom",
labelSize: "20rpx",
lableColor: "#666",
color: "#333",
size: "20",
space: "6px"
})
}, {
i: common_vendor.o(handleUpload),
j: common_vendor.s(props == null ? void 0 : props.styles)
}) : {}, {
k: (props == null ? void 0 : props.display) && !((_c = list.value) == null ? void 0 : _c.length)
}, (props == null ? void 0 : props.display) && !((_d = list.value) == null ? void 0 : _d.length) ? {} : {});
};
}
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-eb3a1d92"], ["__file", "/Users/zsq/Sources/github/2025property-pay/pay-customer/src/components/hs-upload/hs-upload.vue"]]);
wx.createComponent(Component);