"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_http = require("../../utils/http.js"); const apis_cast = require("../../apis/cast.js"); require("../../utils/Auth.js"); if (!Array) { const _easycom_up_upload2 = common_vendor.resolveComponent("up-upload"); const _easycom_up_notify2 = common_vendor.resolveComponent("up-notify"); (_easycom_up_upload2 + _easycom_up_notify2)(); } const _easycom_up_upload = () => "../../node-modules/uview-plus/components/u-upload/u-upload.js"; const _easycom_up_notify = () => "../../node-modules/uview-plus/components/u-notify/u-notify.js"; if (!Math) { (_easycom_up_upload + _easycom_up_notify)(); } const _sfc_main = { __name: "uploadNews", setup(__props) { const fileList1 = common_vendor.reactive([]); const uNotifyRef = common_vendor.ref(null); const deletePic = (event) => { fileList1.splice(event.index, 1); }; const afterRead = async (event) => { let lists = [].concat(event.file); for (let item of lists) { fileList1.push({ ...item, status: "uploading", message: "上传中" }); console.log("开始上传"); try { console.log(item); let res = await utils_http.uploadFile(item.url); res = JSON.parse(res); console.log("上传图片结果", res); fileList1[fileList1.length - 1].status = "done"; fileList1[fileList1.length - 1].url = res.url; state.imageUrl = res.url; } catch (error) { console.error("上传图片失败", error); fileList1[fileList1.length - 1].status = "failed"; fileList1[fileList1.length - 1].message = "上传失败"; } } }; const state = common_vendor.reactive({ title: "", description: "", content: "", imageUrl: "" }); const isCont = (e) => { if (e == "" || e == null) return false; return true; }; const publish = async () => { if (!isCont(state.title) || !isCont(state.description) || !isCont(state.content) || !isCont(state.imageUrl)) { common_vendor.index.showToast({ icon: "none", title: "请填写完整" }); return; } const data = { title: state.title, description: state.description, content: state.content, imageUrl: state.imageUrl }; console.log("发布内容:", data); let res = await apis_cast.saveCaseInfo(data); if (res.code == 200) { common_vendor.index.showToast({ icon: "none", title: "发表成功" }); common_vendor.index.navigateBack({ delta: 1 }); } resetForm(); }; const resetForm = () => { fileList1.splice(0, fileList1.length); state.title = ""; state.description = ""; state.content = ""; }; return (_ctx, _cache) => { return { a: common_vendor.o(afterRead), b: common_vendor.o(deletePic), c: common_vendor.p({ fileList: fileList1, name: "1", multiple: true, maxCount: 1, previewFullImage: true, width: "400rpx", height: "300rpx" }), d: state.title, e: common_vendor.o(($event) => state.title = $event.detail.value), f: state.description, g: common_vendor.o(($event) => state.description = $event.detail.value), h: state.content, i: common_vendor.o(($event) => state.content = $event.detail.value), j: common_vendor.o(publish), k: common_vendor.sr(uNotifyRef, "ddd2bb19-1", { "k": "uNotifyRef" }), l: common_vendor.p({ message: "Hi uview-plus" }) }; }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-ddd2bb19"], ["__file", "D:/uniapp1/gree_leran/pages/uploadNews/uploadNews.vue"]]); wx.createPage(MiniProgramPage);