acdr-ui/dist/dev/mp-weixin/pages/push/share.js

152 lines
4.7 KiB
JavaScript
Raw Normal View History

2024-09-19 07:20:14 +08:00
"use strict";
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
const common_vendor = require("../../common/vendor.js");
const utils_http = require("../../utils/http.js");
const store_user = require("../../store/user.js");
if (!Array) {
const _easycom_wd_icon2 = common_vendor.resolveComponent("wd-icon");
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
(_easycom_wd_icon2 + _component_layout_default_uni)();
}
const _easycom_wd_icon = () => "../../node-modules/wot-design-uni/components/wd-icon/wd-icon.js";
if (!Math) {
_easycom_wd_icon();
}
const _sfc_main = {
__name: "share",
setup(__props) {
const images = common_vendor.ref([]);
const title = common_vendor.ref("");
const content = common_vendor.ref("");
const location = common_vendor.ref("");
const isPublic = common_vendor.ref(true);
const tags = common_vendor.ref(["#搞笑日常", "#快乐无限供应", "#生活随拍", "#日常碎片"]);
store_user.useUserStore();
const goBack = () => {
common_vendor.index.navigateBack();
};
const chooseImage = () => {
common_vendor.index.chooseImage({
count: 1,
success: (res) => {
images.value.push({ url: res.tempFilePaths[0] });
}
});
};
const togglePublic = (event) => {
isPublic.value = event.detail.value;
};
const uploadImage = (filePath) => __async(this, null, function* () {
try {
const response = yield utils_http.httpUploadFile("/file/upload", filePath);
if (response.code === 200) {
return response.data.url;
} else {
throw new Error("图片上传失败");
}
} catch (error) {
common_vendor.index.showToast({
title: "图片上传失败,请稍后重试",
icon: "none"
});
throw error;
}
});
const postNote = () => __async(this, null, function* () {
if (!title.value || !content.value) {
common_vendor.index.showToast({
icon: "none",
title: "请填写标题和内容"
});
return;
}
try {
const uploadedImages = [];
for (const image of images.value) {
const imageUrl = yield uploadImage(image.url);
uploadedImages.push(imageUrl);
}
const postData = {
title: title.value,
content: content.value,
location: location.value,
isPublic: isPublic.value,
images: uploadedImages
};
const postResponse = yield utils_http.httpPost("/posts/create", postData);
if (postResponse.code === 200) {
common_vendor.index.showToast({
title: "发布成功",
icon: "success"
});
goBack();
} else {
common_vendor.index.showToast({
title: postResponse.message || "发布失败,请稍后再试",
icon: "none"
});
}
} catch (error) {
common_vendor.index.showToast({
title: "发布失败,请检查网络",
icon: "none"
});
}
});
return (_ctx, _cache) => {
return {
a: common_vendor.o(goBack),
b: common_vendor.f(images.value, (image, index, i0) => {
return {
a: image.url,
b: index
};
}),
c: common_vendor.p({
name: "add",
size: "22px",
color: "#888"
}),
d: common_vendor.o(chooseImage),
e: title.value,
f: common_vendor.o(($event) => title.value = $event.detail.value),
g: content.value,
h: common_vendor.o(($event) => content.value = $event.detail.value),
i: common_vendor.f(tags.value, (tag, index, i0) => {
return {
a: common_vendor.t(tag),
b: index
};
}),
j: location.value,
k: common_vendor.o(($event) => location.value = $event.detail.value),
l: isPublic.value,
m: common_vendor.o(togglePublic),
n: common_vendor.o(postNote)
};
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b9a0737d"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=share.js.map