newLiveClass.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <div class="m-container">
  3. <h2>
  4. <el-page-header @back="onCancel" :content="name"></el-page-header>
  5. </h2>
  6. <div class="m-core">
  7. <el-form
  8. :model="form"
  9. ref="form"
  10. label-width="300px"
  11. :inline="true"
  12. label-position="left"
  13. >
  14. <el-alert
  15. title="直播课信息"
  16. type="info"
  17. :closable="false"
  18. style="margin-bottom: 20px"
  19. ></el-alert>
  20. <el-row class="row">
  21. <el-form-item
  22. label="直播课标题"
  23. maxlength="12"
  24. show-word-limit
  25. prop="roomTitle"
  26. :rules="[{ required: true, message: '请输入直播课标题' }]"
  27. >
  28. <el-input
  29. placeholder="请输入直播课标题"
  30. v-model.trim="form.roomTitle"
  31. ></el-input>
  32. </el-form-item>
  33. <el-form-item
  34. label="主讲人"
  35. prop="speakerId"
  36. :rules="[{ required: true, message: '请输入主讲人' }]"
  37. >
  38. <el-select
  39. v-model.trim="form.speakerId"
  40. collapse-tags
  41. clearable
  42. placeholder="请输入主讲人"
  43. remote
  44. filterable
  45. :remote-method="remoteMethod"
  46. :loading="remoteLoading"
  47. @change="changeTeacher"
  48. >
  49. <el-option
  50. v-for="item in teacherList"
  51. :key="item.id"
  52. :label="item.realName"
  53. :value="item.id"
  54. >
  55. <span style="float: left">{{ item.realName }}</span>
  56. <span style="float: right; color: #8492a6; font-size: 13px">{{
  57. item.phone
  58. }}</span>
  59. </el-option>
  60. </el-select>
  61. </el-form-item>
  62. <el-form-item
  63. label="直播开始时间"
  64. prop="liveStartTime"
  65. :rules="[{ required: true, message: '请选择直播开始时间' }]"
  66. >
  67. <el-date-picker
  68. v-model="form.liveStartTime"
  69. type="datetime"
  70. format="yyyy-MM-dd HH:mm"
  71. value-format="yyyy-MM-dd HH:mm"
  72. placeholder="请选择直播开始时间"
  73. >
  74. </el-date-picker>
  75. </el-form-item>
  76. </el-row>
  77. <el-row class="row">
  78. <el-form-item
  79. label="直播课内容"
  80. prop="liveRemark"
  81. :rules="[{ required: true, message: '请输入直播课内容' }]"
  82. >
  83. <el-input
  84. :rows="3"
  85. placeholder="请输入直播课内容"
  86. v-model.trim="form.liveRemark"
  87. type="textarea"
  88. maxlength="200"
  89. show-word-limit
  90. ></el-input>
  91. </el-form-item>
  92. </el-row>
  93. <el-row class="row">
  94. <el-form-item
  95. label="预热模板(模板使用与分享宣传图片)"
  96. prop="preTemplate"
  97. :rules="[{ required: true, message: '请选择预热模板' }]"
  98. >
  99. <el-checkbox-group v-model="checkList" @change="bindCheckBox">
  100. <div class="chioseWrap">
  101. <div class="chioseItem" @click="setPreTemplate(1)">
  102. <img src="./images/img1.png" alt="" />
  103. <!-- v-model="form.preTemplate" -->
  104. <div class="remberBox">
  105. <div class="wrap"></div>
  106. <el-checkbox
  107. class="chioseBox"
  108. :label="1"
  109. :checked="form.preTemplate == 1"
  110. ><br
  111. /></el-checkbox>
  112. <!-- <div
  113. class="dotWrap"
  114. :class="[form.preTemplate == 1 ? 'checked' : '']"
  115. ></div> -->
  116. </div>
  117. </div>
  118. <div class="chioseItem" @click="setPreTemplate(2)">
  119. <img src="./images/img2.png" alt="" />
  120. <div class="remberBox">
  121. <!-- v-model="form.preTemplate" -->
  122. <div class="wrap"></div>
  123. <el-checkbox
  124. name="2"
  125. class="chioseBox"
  126. :label="2"
  127. :checked="form.preTemplate == 2"
  128. ><br
  129. /></el-checkbox>
  130. <!-- <div
  131. class="dotWrap"
  132. :class="[form.preTemplate == 2 ? 'checked' : '']"
  133. ></div> -->
  134. </div>
  135. </div>
  136. <div class="chioseItem" @click="setPreTemplate(3)">
  137. <img src="./images/img3.png" alt="" />
  138. <div class="remberBox">
  139. <div class="wrap"></div>
  140. <el-checkbox
  141. class="chioseBox"
  142. :label="3"
  143. :checked="form.preTemplate == 3"
  144. ><br
  145. /></el-checkbox>
  146. <!-- <div
  147. class="dotWrap"
  148. :class="[form.preTemplate == 3 ? 'checked' : '']"
  149. ></div> -->
  150. </div>
  151. </div>
  152. </div>
  153. </el-checkbox-group>
  154. </el-form-item>
  155. </el-row>
  156. <el-alert
  157. title="直播间信息"
  158. type="info"
  159. :closable="false"
  160. style="margin-bottom: 20px"
  161. ></el-alert>
  162. <el-row class="row">
  163. <el-form-item
  164. prop="roomConfig.whether_like"
  165. label-width="120px"
  166. class="mline"
  167. label="允许点赞"
  168. :rules="[{ required: true, message: '是否允许点赞' }]"
  169. >
  170. <el-radio-group v-model="form.roomConfig.whether_like">
  171. <el-radio :label="1">是</el-radio>
  172. <el-radio :label="0">否</el-radio>
  173. </el-radio-group>
  174. </el-form-item>
  175. </el-row>
  176. <el-row class="row">
  177. <el-form-item
  178. prop="roomConfig.whether_chat"
  179. label-width="120px"
  180. class="mline"
  181. label="允许聊天互动"
  182. :rules="[{ required: true, message: '是否允许聊天互动' }]"
  183. >
  184. <el-radio-group v-model="form.roomConfig.whether_chat">
  185. <el-radio :label="1">是</el-radio>
  186. <el-radio :label="0">否</el-radio>
  187. </el-radio-group>
  188. </el-form-item>
  189. </el-row>
  190. <el-row class="row">
  191. <el-form-item
  192. prop="roomConfig.whether_video"
  193. label-width="120px"
  194. class="mline"
  195. label="保存直播回放"
  196. :rules="[{ required: true, message: '是否保存直播回放' }]"
  197. >
  198. <el-radio-group v-model="form.roomConfig.whether_video">
  199. <el-radio :label="1">是</el-radio>
  200. <el-radio :label="0">否</el-radio>
  201. </el-radio-group>
  202. </el-form-item>
  203. </el-row>
  204. </el-form>
  205. <el-row class="row">
  206. <el-button type="primary" @click="preLook">预览</el-button>
  207. <el-button type="primary" @click="submit">提交</el-button>
  208. </el-row>
  209. </div>
  210. <el-dialog
  211. title="预览"
  212. width="415px"
  213. :close-on-click-modal="false"
  214. append-to-body
  215. :visible.sync="preLookVisible"
  216. >
  217. <preview :form="form" />
  218. </el-dialog>
  219. </div>
  220. </template>
  221. <script>
  222. import preview from "./modals/preview.vue";
  223. import axios from "axios";
  224. import { getToken, getTenantId } from "@/utils/auth";
  225. import { createLiveBroadcast,resetLiveBroadcastRoomList } from "./api";
  226. export default {
  227. components: { preview },
  228. data() {
  229. return {
  230. name: "新建直播课",
  231. preLookVisible: false,
  232. form: {
  233. roomTitle: "",
  234. speakerId: "",
  235. liveStartTime: "",
  236. liveRemark: "",
  237. preTemplate: null,
  238. roomConfig: { whether_like: 1, whether_chat: 1, whether_video: 1 },
  239. checkList: [],
  240. },
  241. remoteLoading: false,
  242. teacherList: [],
  243. checkList: [],
  244. };
  245. },
  246. mounted() {
  247. if (this.$route.query.id) {
  248. this.name = "修改直播间";
  249. // console.log()
  250. this.form = { ...this.$route.query };
  251. this.form.roomConfig = JSON.parse(this.$route.query.roomConfig);
  252. console.log(this.form.roomConfig)
  253. this.remoteMethod(this.$route.query.speakerName);
  254. this.checkList.push(this.form.preTemplate * 1);
  255. }
  256. },
  257. methods: {
  258. onCancel() {
  259. this.$store.dispatch("delVisitedViews", this.$route);
  260. this.$router.push("/liveClassManager");
  261. },
  262. changeTeacher(val){
  263. this.teacherList.forEach(item=>{
  264. if(val == item.id){
  265. this.form.speakerName = item.realName
  266. }
  267. })
  268. },
  269. preLook() {
  270. console.log(this.form);
  271. this.$refs.form.validate((flag) => {
  272. if (flag) {
  273. this.preLookVisible = true;
  274. console.log("预览", this.form);
  275. }
  276. });
  277. },
  278. setPreTemplate(index) {
  279. console.log('调用',index)
  280. this.$set(this.form, "preTemplate", index);
  281. if (this.checkList.indexOf(index) == -1) {
  282. this.checkList.push(index);
  283. } else {
  284. this.checkList.splice(this.checkList.indexOf(index), 1);
  285. }
  286. console.log('调用结束',index)
  287. this.bindCheckBox();
  288. },
  289. remoteMethod(query) {
  290. this.teacherList = [];
  291. if (query !== "") {
  292. this.remoteLoading = true;
  293. // 发请求搜索
  294. const url = "/api-auth/user/queryLike";
  295. const options = {
  296. method: "get",
  297. headers: {
  298. Authorization: getToken(),
  299. tenantId: getTenantId(),
  300. },
  301. params: {
  302. rows: 9999,
  303. search: query,
  304. },
  305. url,
  306. };
  307. this.remoteLoading = true;
  308. // this.studentList = []
  309. axios(options).then((res) => {
  310. this.remoteLoading = false;
  311. let result = res.data;
  312. if (result.code == 200) {
  313. // Array.prototype.splice.apply(this.studentList, result.data.rows);
  314. if (result.data && result.data.length > 0) {
  315. result.data.forEach((item) => {
  316. this.teacherList.unshift(item);
  317. });
  318. this.teacherList = this.deweight(this.teacherList, "phone");
  319. }
  320. // this.studentList = this.studentList.concat(result.data.rows);
  321. }
  322. });
  323. // queryStudentList({ rows: 100, search: query }).then(res => {
  324. // if (res.code == 200) {
  325. // this.remoteLoading = false;
  326. // this.studentList = this.studentList.concat(res.data.rows);
  327. // this.unique(this.studentList, "userId");
  328. // }
  329. // });
  330. }
  331. },
  332. deweight(arr, key) {
  333. let res = [];
  334. arr.forEach((item) => {
  335. let list = [];
  336. res.forEach((resitem) => {
  337. list.push(resitem[key]);
  338. });
  339. if (list.indexOf(item[key]) === -1) {
  340. res.push(item);
  341. }
  342. });
  343. return res;
  344. },
  345. bindCheckBox() {
  346. if (this.checkList.length > 1) {
  347. this.checkList.splice(0, 1);
  348. }
  349. this.$set(this.form, "preTemplate", this.checkList[0] || null);
  350. },
  351. async submit() {
  352. if (this.$route.query.id) {
  353. // 修改
  354. try {
  355. const res = await resetLiveBroadcastRoomList(this.form);
  356. this.$message.success("修改成功");
  357. this.$store.dispatch("delVisitedViews", this.$route);
  358. this.$router.push("/liveClassManager");
  359. } catch (e) {
  360. console.log(e);
  361. }
  362. } else {
  363. try {
  364. const res = await createLiveBroadcast(this.form);
  365. this.$message.success("创建成功");
  366. this.$store.dispatch("delVisitedViews", this.$route);
  367. this.$router.push("/liveClassManager");
  368. } catch (e) {
  369. console.log(e);
  370. }
  371. }
  372. // createLiveBroadcast
  373. },
  374. },
  375. };
  376. </script>
  377. <style lang="scss" scoped>
  378. /deep/.mline {
  379. .el-form-item__content {
  380. display: inline-block !important;
  381. }
  382. }
  383. /deep/.el-form--inline {
  384. .el-form-item__content {
  385. display: block;
  386. }
  387. }
  388. /deep/.el-select {
  389. width: 300px !important;
  390. }
  391. /deep/.el-date-editor {
  392. width: 300px !important;
  393. }
  394. /deep/.el-checkbox {
  395. margin-left: 15px !important;
  396. }
  397. /deep/.el-input {
  398. position: relative;
  399. font-size: 14px;
  400. display: inline-block;
  401. width: 300px;
  402. }
  403. .row {
  404. padding-left: 24px;
  405. }
  406. /deep/.el-textarea__inner {
  407. width: 600px;
  408. }
  409. .chioseWrap {
  410. display: flex;
  411. flex-direction: row;
  412. justify-content: flex-start;
  413. .chioseItem {
  414. border-radius: 4px;
  415. overflow: hidden;
  416. position: relative;
  417. margin-right: 10px;
  418. width: 188px;
  419. height: 188px;
  420. cursor: pointer;
  421. .remberBox {
  422. .wrap {
  423. width: 100px;
  424. height: 100px;
  425. z-index: 100;
  426. position: absolute;
  427. // background-color: red;
  428. }
  429. display: flex;
  430. flex-direction: row;
  431. justify-content: flex-start;
  432. margin-bottom: 30px;
  433. padding-top: 10px;
  434. align-items: center;
  435. position: relative;
  436. color: #6d7278;
  437. font-size: 16px;
  438. position: absolute;
  439. top: 1px;
  440. right: 1px;
  441. .chioseBox {
  442. /deep/.el-checkbox__inner {
  443. width: 20px;
  444. height: 20px;
  445. border-radius: 50%;
  446. &::after {
  447. height: 8px;
  448. left: 6px;
  449. position: absolute;
  450. top: 3px;
  451. width: 4px;
  452. }
  453. }
  454. }
  455. .dotWrap {
  456. width: 21px;
  457. height: 21px;
  458. background: url("../../assets/images/icon_checkbox_default.png")
  459. no-repeat center;
  460. background-size: contain;
  461. margin-right: 8px;
  462. position: relative;
  463. overflow: hidden;
  464. &.checked {
  465. background: url("../../assets/images/icon_checkbox.png") no-repeat
  466. center;
  467. background-size: contain;
  468. }
  469. }
  470. }
  471. }
  472. }
  473. </style>