gree_leran/unpackage/dist/dev/mp-weixin/pages/uploadVideo/uploadVideo.js

124 lines
3.9 KiB
JavaScript
Raw Normal View History

2024-06-20 15:36:19 +00:00
"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_http = require("../../utils/http.js");
const apis_videos = require("../../apis/videos.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: "uploadVideo",
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: ""
});
2024-06-22 07:20:39 +00:00
const isCont = (e) => {
if (e == "" || e == null)
return false;
return true;
};
2024-06-20 15:36:19 +00:00
const publish = async () => {
2024-06-22 07:20:39 +00:00
console.log("上传数据", state);
if (!isCont(state.title) || !isCont(state.description) || !isCont(state.imageUrl)) {
common_vendor.index.showToast({
icon: "none",
title: "请填写完整"
});
return;
}
2024-06-20 15:36:19 +00:00
const data = {
title: state.title,
description: state.description,
// content: state.content,
videoUrl: state.imageUrl
};
console.log("发布内容:", data);
let res = await apis_videos.saveVideosInfo(data);
if (res.code == 200) {
2024-06-22 07:20:39 +00:00
common_vendor.index.showToast({
icon: "none",
title: "发表成功"
});
common_vendor.index.navigateBack({
delta: 1
2024-06-20 15:36:19 +00:00
});
}
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",
accept: "video"
}),
d: state.title,
e: common_vendor.o(($event) => state.title = $event.detail.value),
2024-06-22 07:20:39 +00:00
f: state.description,
g: common_vendor.o(($event) => state.description = $event.detail.value),
2024-06-20 15:36:19 +00:00
h: common_vendor.o(publish),
i: common_vendor.sr(uNotifyRef, "4f3ecb6a-1", {
"k": "uNotifyRef"
}),
j: common_vendor.p({
message: "Hi uview-plus"
})
};
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4f3ecb6a"], ["__file", "D:/uniapp1/gree_leran/pages/uploadVideo/uploadVideo.vue"]]);
wx.createPage(MiniProgramPage);