feat:添加外链接口对接 完善添加直播

This commit is contained in:
songwc
2022-11-01 12:21:18 +08:00
parent 2c3edeaf24
commit 06633222be
4 changed files with 1167 additions and 912 deletions

View File

@@ -65,7 +65,6 @@
<a-range-picker
style="width: 424px"
v-model:value="time"
format="YYYY-MM-DD HH:MM"
:placeholder="[' 开始时间', ' 结束时间']"
/>
</div>
@@ -110,7 +109,7 @@
<div class="signbox">
<span style="margin-right: 3px">直播封面</span>
</div>
<div class="textarea">
<div class="textarea" style="overflow: hidden">
<a-upload
v-model:file-list="fileList"
name="avatar"
@@ -279,7 +278,7 @@
</div>
</div>
<div class="main_btns">
<button class="btn1">取消</button>
<button class="btn1" @click="closeDrawer">取消</button>
<button class="btn2" @click="createLiveBroadcast">确定</button>
</div>
</div>
@@ -289,6 +288,13 @@
import { reactive, toRefs, ref } from "vue";
import { message } from "ant-design-vue";
import * as api from "../../api/indexLiveBroadcast";
import { toDate } from "@/api/method";
function getBase64(img, callback) {
const reader = new FileReader();
reader.addEventListener("load", () => callback(reader.result));
reader.readAsDataURL(img);
}
const options1 = ref([
{
value: "value1",
@@ -465,6 +471,8 @@ export default {
inputV8: "", //结束前多少分钟开始签退
textV1: "",
radioV1: "", //标准设置的单选
imageUrl: "", //上传图片地址
loading: false,
switchC1: "",
checkedC1: "",
checkedC2: true,
@@ -474,6 +482,18 @@ export default {
ctx.emit("update:addliveVisible", false);
state.radioV1 = "";
state.playback = false;
state.inputV6 = "";
state.inputV7 = "";
state.inputV2 = "";
state.inputV3 = "";
state.inputV1 = "";
state.inputV4 = "";
state.inputV5 = "";
state.inputV8 = "";
state.time = "";
state.textV1 = "";
state.switchC1 = "";
state.imageUrl = "";
};
const afterVisibleChange = (bool) => {
console.log("state", bool);
@@ -487,23 +507,66 @@ export default {
state.radioV1 = "";
}
};
const handleChange = (info) => {
if (info.file.status === "uploading") {
state.loading = true;
return;
}
if (info.file.status === "done") {
// Get this url from response in real world.
getBase64(info.file.originFileObj, (base64Url) => {
state.imageUrl = base64Url;
state.loading = false;
});
}
if (info.file.status === "error") {
state.loading = false;
message.error("upload error");
}
};
const beforeUpload = (file) => {
const isJpgOrPng =
file.type === "image/jpeg" || file.type === "image/png";
if (!isJpgOrPng) {
message.error("You can only upload JPG file!");
}
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
message.error("Image must smaller than 2MB!");
}
return isJpgOrPng && isLt2M;
};
//创建直播
const createLiveBroadcast = () => {
if (!state.inputV1) return message.info("请输入直播名称");
if (!state.time) return message.info("请输入直播时间");
if (!state.inputV2) return message.info("请输入直播时长");
if (!state.inputV1) return message.warning("请输入直播名称");
if (!state.time) return message.warning("请输入直播时间");
if (!state.inputV2) return message.warning("请输入直播时长");
const regular = /^[+]{0,1}(\d+)$/;
if (!regular.test(state.inputV2)) {
return message.info("直播时长需大于0");
return message.warning("直播时长需大于0");
}
// if (!state.inputV3) return message.info("请输入授课老师");
let check = state.checkedC2 * 1;
let startTime = state.time[0].$d;
let endTime = state.time[1].$d;
console.log(startTime); //时间需要处理
console.log(endTime);
// let startTime = state.time[0].$d;
// let endTime = state.time[1].$d;
// console.log(startTime); //时间需要处理
// console.log(endTime);
let startTime = toDate(
new Date(state.time[0].$d).getTime() / 1000,
"Y-M-D"
);
let endTime = toDate(
new Date(state.time[1].$d).getTime() / 1000,
"Y-M-D"
);
let obj = {
afterSignIn: state.inputV6,
beforeSignIn: state.inputV7,
@@ -511,8 +574,8 @@ export default {
createUser: 0,
// liveCover: state.fileList,//直播封面
liveDuration: state.inputV2,
// liveEndTime: endTime,
// liveStartTime: startTime,
liveEndTime: endTime,
liveStartTime: startTime,
liveExplain: state.textV1,
liveFlag: "",
liveId: 0,
@@ -532,6 +595,11 @@ export default {
.createLiveBroadcast(obj)
.then((res) => {
console.log(res.data.data, 1111);
console.log(state, 2222);
message.success("提交成功");
closeDrawer();
// state = {}
})
.catch((err) => {
console.log(err, 2222);
@@ -548,6 +616,8 @@ export default {
rowSelection,
cloradio1,
createLiveBroadcast,
handleChange,
beforeUpload,
};
},
};