413 lines
13 KiB
JavaScript
413 lines
13 KiB
JavaScript
"use strict";
|
|
var __defProp = Object.defineProperty;
|
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
var __publicField = (obj, key, value) => {
|
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
return value;
|
|
};
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const common_js_util = require("../../common/js/util.js");
|
|
const api_index = require("../../api/index.js");
|
|
if (!Array) {
|
|
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
|
|
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
|
|
(_easycom_uni_icons2 + _easycom_uni_popup2)();
|
|
}
|
|
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
|
|
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
|
|
if (!Math) {
|
|
(_easycom_uni_icons + _easycom_uni_popup)();
|
|
}
|
|
const _sfc_main = {
|
|
__name: "video",
|
|
setup(__props) {
|
|
class Form {
|
|
constructor() {
|
|
__publicField(this, "videoId", "");
|
|
// 视频地址
|
|
__publicField(this, "videoUrl", "");
|
|
// 缩略图
|
|
__publicField(this, "imageUrl", "");
|
|
// 标题
|
|
__publicField(this, "title", "");
|
|
// 正文
|
|
__publicField(this, "content", "");
|
|
// 话题
|
|
__publicField(this, "talk", "");
|
|
// at用户
|
|
__publicField(this, "subscriber", "");
|
|
// 地点
|
|
__publicField(this, "locationName", "");
|
|
// 经纬度
|
|
__publicField(this, "location", "");
|
|
// 产品链接
|
|
__publicField(this, "productUrl", "");
|
|
// 产品id
|
|
__publicField(this, "productId", "");
|
|
// 第几秒展示
|
|
__publicField(this, "showTime", "");
|
|
// 0全部1仅自己可见
|
|
__publicField(this, "oneself", 0);
|
|
// 0正常1草稿
|
|
__publicField(this, "isDraft", "");
|
|
// 1个人2商户
|
|
__publicField(this, "type", "");
|
|
}
|
|
}
|
|
const form = common_vendor.reactive(new Form());
|
|
let labelList = common_vendor.reactive([]);
|
|
const labelKeyword = common_vendor.ref("");
|
|
const labelSelect = common_vendor.reactive([]);
|
|
const userList = common_vendor.reactive({
|
|
data: [],
|
|
pageNum: 1,
|
|
pageSize: 20,
|
|
total: 0
|
|
});
|
|
const userSelect = common_vendor.reactive([]);
|
|
const userKeyword = common_vendor.ref("");
|
|
common_vendor.onLoad((option) => {
|
|
if (option.videoId) {
|
|
form.videoId = option.videoId;
|
|
Promise.all([getVideoDetail(), getLabel()]).then((rs) => {
|
|
const detail = rs[0];
|
|
rs[1];
|
|
rs[2];
|
|
console.log("release getDetail", detail);
|
|
form.videoUrl = common_js_util.util.format_url(detail.videoUrl, "video");
|
|
form.imageUrl = common_js_util.util.format_url(detail.imageUrl, "img");
|
|
form.title = detail.title;
|
|
form.content = detail.content;
|
|
form.isDraft = detail.isDraft;
|
|
detail.talkId.split(",").forEach((node) => {
|
|
for (let i = 0; i < labelList.length; i++) {
|
|
const item = labelList[i];
|
|
if (node == item.id)
|
|
labelSelect.push(item);
|
|
}
|
|
});
|
|
detail.subscriber = detail.subscriber.split(",");
|
|
detail.subscriberId.split(",").forEach((item, index) => {
|
|
userSelect.push({
|
|
userId: item,
|
|
userNickname: detail.subscriber[index]
|
|
});
|
|
});
|
|
});
|
|
} else {
|
|
getLabel();
|
|
}
|
|
});
|
|
function getVideoDetail() {
|
|
return new Promise((resolve, reject) => {
|
|
api_index.api.video.getVideoById({
|
|
query: {
|
|
videoId: form.videoId
|
|
}
|
|
}).then((rs) => {
|
|
if (rs.code == 200) {
|
|
resolve(rs.data);
|
|
return;
|
|
}
|
|
common_js_util.util.alert({
|
|
content: rs.msg,
|
|
showCancel: false
|
|
});
|
|
});
|
|
});
|
|
}
|
|
function uploadImg() {
|
|
common_js_util.util.upload_image({
|
|
value: form.imageUrl,
|
|
type: 1,
|
|
success: (rs) => {
|
|
form.imageUrl = rs.value;
|
|
}
|
|
});
|
|
}
|
|
function uploadVideo() {
|
|
common_js_util.util.upload_video({
|
|
success: (rs) => {
|
|
form.videoUrl = rs.value;
|
|
}
|
|
});
|
|
}
|
|
function getLabel() {
|
|
return new Promise((resolve, reject) => {
|
|
api_index.api.video.getLabel({
|
|
query: {
|
|
parentId: 0,
|
|
search: labelKeyword.value
|
|
}
|
|
}).then((rs) => {
|
|
if (rs.code == 200) {
|
|
const result = rs.data;
|
|
labelList.length = 0;
|
|
labelList.push(...result);
|
|
resolve(labelList);
|
|
if (!result[0] && labelKeyword.value) {
|
|
common_js_util.util.alert({
|
|
content: `当前没有${labelKeyword.value}的话题,是否添加?`
|
|
}).then((rs2) => {
|
|
if (rs2.confirm)
|
|
addLabel();
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
common_js_util.util.alert({
|
|
content: rs.msg,
|
|
showCancel: false
|
|
});
|
|
});
|
|
});
|
|
}
|
|
function addLabel() {
|
|
api_index.api.video.setLabel({
|
|
data: {
|
|
parentId: 0,
|
|
name: labelKeyword.value
|
|
}
|
|
}).then((rs) => {
|
|
if (rs.code == 200) {
|
|
getLabel();
|
|
return;
|
|
}
|
|
common_js_util.util.alert({
|
|
content: rs.msg,
|
|
showCancel: false
|
|
});
|
|
});
|
|
}
|
|
function handleSelectLabel(ev, index) {
|
|
const findIndex = labelSelect.findIndex((item) => item.id == ev.id);
|
|
if (findIndex < 0)
|
|
labelSelect.push(ev);
|
|
}
|
|
function handleLabelSelectDel(item, index) {
|
|
labelSelect.splice(index, 1);
|
|
}
|
|
function getMoreUserList() {
|
|
if (userList.data.length >= userList.total)
|
|
return;
|
|
userList.pageNum++;
|
|
getUserList();
|
|
}
|
|
function getUserList() {
|
|
return new Promise((resolve, reject) => {
|
|
api_index.api.video.searchFriendByName({
|
|
path: [userKeyword.value],
|
|
query: {
|
|
pageNum: userList.pageNum,
|
|
pageSize: userList.pageSize
|
|
}
|
|
}).then((rs) => {
|
|
if (rs.code == 200) {
|
|
if (userList.pageNum)
|
|
userList.data.length = 0;
|
|
userList.data.push(...rs.rows);
|
|
userList.total = rs.total;
|
|
resolve(userList.data);
|
|
return;
|
|
}
|
|
common_js_util.util.alert({
|
|
content: rs.msg,
|
|
showCancel: false
|
|
});
|
|
});
|
|
});
|
|
}
|
|
function handleSelectUser(ev, index) {
|
|
const findIndex = userSelect.findIndex((item) => item.id == ev.id);
|
|
if (findIndex < 0)
|
|
userSelect.push(ev);
|
|
}
|
|
function handleUserSelectDel(item, index) {
|
|
userSelect.splice(index, 1);
|
|
}
|
|
function handleSubmit(isDraft) {
|
|
const data = {
|
|
...form
|
|
};
|
|
let fnName = "publishVideo";
|
|
if (form.videoId) {
|
|
fnName = "updateVideo";
|
|
}
|
|
data.isDraft = isDraft ? isDraft : 0;
|
|
if (!data.videoUrl) {
|
|
common_js_util.util.alert("视频不能为空");
|
|
return;
|
|
}
|
|
if (!data.imageUrl) {
|
|
common_js_util.util.alert("封面不能为空");
|
|
return;
|
|
}
|
|
if (data.isDraft == 0) {
|
|
if (!data.title) {
|
|
common_js_util.util.alert("标题不能为空");
|
|
return;
|
|
}
|
|
if (!data.content) {
|
|
common_js_util.util.alert("正文不能为空");
|
|
return;
|
|
}
|
|
}
|
|
if (labelSelect[0]) {
|
|
data.talkId = labelSelect.map((item) => item.id).join(",");
|
|
data.talk = labelSelect.map((item) => item.name).join(",");
|
|
}
|
|
if (userSelect[0]) {
|
|
data.subscriberId = userSelect.map((item) => item.userId).join(",");
|
|
data.subscriber = userSelect.map((item) => item.userNickname).join(",");
|
|
}
|
|
data.videoUrl = common_js_util.util.replace_url(data.videoUrl);
|
|
data.imageUrl = common_js_util.util.replace_url(data.imageUrl);
|
|
api_index.api.video[fnName]({
|
|
data
|
|
}).then((rs) => {
|
|
if (rs.code == 200) {
|
|
common_js_util.util.alert({
|
|
content: data.isDraft == 0 ? "视频发布成功,请等待后台审核" : "保存草稿成功",
|
|
showCancel: false,
|
|
confirmText: "我知道了"
|
|
}).then((rs2) => {
|
|
common_vendor.index.navigateBack();
|
|
});
|
|
return;
|
|
}
|
|
common_js_util.util.alert({
|
|
content: rs.msg,
|
|
showCancel: false
|
|
});
|
|
});
|
|
}
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: form.imageUrl
|
|
}, form.imageUrl ? {
|
|
b: form.imageUrl
|
|
} : {
|
|
c: common_vendor.p({
|
|
type: "plusempty",
|
|
color: "#E8E8E8",
|
|
size: "50rpx"
|
|
}),
|
|
d: common_vendor.o$1(uploadImg)
|
|
}, {
|
|
e: form.videoUrl
|
|
}, form.videoUrl ? {
|
|
f: form.videoUrl
|
|
} : {
|
|
g: common_vendor.p({
|
|
type: "plusempty",
|
|
color: "#E8E8E8",
|
|
size: "50rpx"
|
|
}),
|
|
h: common_vendor.o$1(uploadVideo)
|
|
}, {
|
|
i: form.title,
|
|
j: common_vendor.o$1(($event) => form.title = $event.detail.value),
|
|
k: form.content,
|
|
l: common_vendor.o$1(($event) => form.content = $event.detail.value),
|
|
m: labelSelect[0]
|
|
}, labelSelect[0] ? {
|
|
n: common_vendor.f(labelSelect, (item, index, i0) => {
|
|
return {
|
|
a: common_vendor.t(item.name),
|
|
b: common_vendor.o$1(($event) => handleLabelSelectDel(item, index), index),
|
|
c: "53de44d6-2-" + i0,
|
|
d: index
|
|
};
|
|
}),
|
|
o: common_vendor.p({
|
|
type: "closeempty",
|
|
size: "28rpx"
|
|
})
|
|
} : {}, {
|
|
p: userSelect[0]
|
|
}, userSelect[0] ? {
|
|
q: common_vendor.f(userSelect, (item, index, i0) => {
|
|
return {
|
|
a: common_vendor.t(item.userNickname),
|
|
b: common_vendor.o$1(($event) => handleLabelSelectDel(item, index), index),
|
|
c: "53de44d6-3-" + i0,
|
|
d: index
|
|
};
|
|
}),
|
|
r: common_vendor.p({
|
|
type: "closeempty",
|
|
size: "28rpx"
|
|
})
|
|
} : {}, {
|
|
s: common_vendor.o$1(($event) => _ctx.$refs.labelRef.open()),
|
|
t: common_vendor.o$1(($event) => _ctx.$refs.userRef.open())
|
|
}, {}, {}, {
|
|
x: common_vendor.o$1(($event) => handleSubmit(1)),
|
|
y: common_vendor.o$1(($event) => handleSubmit(0)),
|
|
z: common_vendor.f(common_vendor.unref(labelList), (item, index, i0) => {
|
|
return {
|
|
a: common_vendor.t(item.name),
|
|
b: index,
|
|
c: common_vendor.o$1(($event) => handleSelectLabel(item), index),
|
|
d: labelSelect.map((node) => node.id).includes(item.id) ? 1 : ""
|
|
};
|
|
}),
|
|
A: labelSelect[0]
|
|
}, labelSelect[0] ? {
|
|
B: common_vendor.f(labelSelect, (item, index, i0) => {
|
|
return {
|
|
a: common_vendor.t(item.name),
|
|
b: common_vendor.o$1(($event) => handleLabelSelectDel(item, index), index),
|
|
c: "53de44d6-6-" + i0 + ",53de44d6-5",
|
|
d: index
|
|
};
|
|
}),
|
|
C: common_vendor.p({
|
|
type: "closeempty",
|
|
size: "28rpx"
|
|
})
|
|
} : {}, {
|
|
D: labelKeyword.value,
|
|
E: common_vendor.o$1(($event) => labelKeyword.value = $event.detail.value),
|
|
F: common_vendor.o$1(getLabel),
|
|
G: common_vendor.sr("labelRef", "53de44d6-5"),
|
|
H: common_vendor.p({
|
|
type: "bottom"
|
|
}),
|
|
I: common_vendor.f(userList.data, (item, index, i0) => {
|
|
return {
|
|
a: common_vendor.t(item.userNickname),
|
|
b: index,
|
|
c: common_vendor.o$1(($event) => handleSelectUser(item), index),
|
|
d: userSelect.map((node) => node.userId).includes(item.userId) ? 1 : ""
|
|
};
|
|
}),
|
|
J: common_vendor.o$1(getMoreUserList),
|
|
K: userSelect[0]
|
|
}, userSelect[0] ? {
|
|
L: common_vendor.f(userSelect, (item, index, i0) => {
|
|
return {
|
|
a: common_vendor.t(item.userNickname),
|
|
b: common_vendor.o$1(($event) => handleUserSelectDel(item, index), index),
|
|
c: "53de44d6-8-" + i0 + ",53de44d6-7",
|
|
d: index
|
|
};
|
|
}),
|
|
M: common_vendor.p({
|
|
type: "closeempty",
|
|
size: "28rpx"
|
|
})
|
|
} : {}, {
|
|
N: userKeyword.value,
|
|
O: common_vendor.o$1(($event) => userKeyword.value = $event.detail.value),
|
|
P: common_vendor.o$1(getUserList),
|
|
Q: common_vendor.sr("userRef", "53de44d6-7"),
|
|
R: common_vendor.p({
|
|
type: "bottom"
|
|
})
|
|
});
|
|
};
|
|
}
|
|
};
|
|
wx.createPage(_sfc_main);
|