index.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. <template>
  2. <div class="training-camp-root">
  3. <!-- 训练营列表:左侧 30% + 营期 70% -->
  4. <div v-show="!periodWorkspace.periodId" class="app-container training-camp-page">
  5. <el-alert
  6. title="总后台:可维护各企业的训练营与营期;企业端创建的营期直播间需经「营期直播间审核」通过(is_audit=1)后才会对用户端展示。普通直播仍在「直播管理」中维护。"
  7. type="info"
  8. :closable="false"
  9. show-icon
  10. class="mb12"
  11. />
  12. <el-row :gutter="16">
  13. <el-col :span="7">
  14. <el-card shadow="never" class="box-card">
  15. <div slot="header" class="clearfix">
  16. <span>训练营</span>
  17. <el-input
  18. v-model="campSearchName"
  19. placeholder="按名称筛选"
  20. size="mini"
  21. clearable
  22. style="width: 120px; margin-left: 8px"
  23. @keyup.enter.native="loadCamps"
  24. />
  25. <el-button
  26. v-hasPermi="['live:trainingCampAdmin:add']"
  27. style="float: right; padding: 3px 0"
  28. type="text"
  29. icon="el-icon-plus"
  30. @click="openCampForm()"
  31. >新建</el-button>
  32. </div>
  33. <el-table
  34. ref="campTable"
  35. v-loading="campLoading"
  36. :data="campList"
  37. highlight-current-row
  38. border
  39. size="small"
  40. @current-change="onCampChange"
  41. >
  42. <el-table-column label="企业" prop="companyName" min-width="120" show-overflow-tooltip />
  43. <el-table-column label="名称" prop="campName" min-width="100" show-overflow-tooltip />
  44. <el-table-column label="排序" prop="sortOrder" width="56" align="center" />
  45. <el-table-column label="状态" width="68" align="center">
  46. <template slot-scope="scope">
  47. <el-tag v-if="scope.row.status === 0" size="mini" type="success">正常</el-tag>
  48. <el-tag v-else size="mini" type="info">停用</el-tag>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="操作" width="96" align="center" fixed="right">
  52. <template slot-scope="scope">
  53. <el-button
  54. v-hasPermi="['live:trainingCampAdmin:edit']"
  55. type="text"
  56. size="mini"
  57. @click.stop="openCampForm(scope.row)"
  58. >编辑</el-button>
  59. <el-button
  60. v-hasPermi="['live:trainingCampAdmin:remove']"
  61. type="text"
  62. size="mini"
  63. @click.stop="removeCamp(scope.row)"
  64. >删除</el-button>
  65. </template>
  66. </el-table-column>
  67. </el-table>
  68. </el-card>
  69. </el-col>
  70. <el-col :span="17">
  71. <el-card shadow="never" class="box-card box-card-period">
  72. <div slot="header" class="period-header">
  73. <div class="period-header-left">
  74. <span>营期</span>
  75. <span v-if="currentCamp" class="sub-hint">({{ currentCamp.campName }})</span>
  76. </div>
  77. <div class="period-header-actions">
  78. <el-button
  79. type="primary"
  80. plain
  81. size="small"
  82. icon="el-icon-right"
  83. :disabled="!currentPeriod"
  84. @click="enterPeriodWorkspace(currentPeriod)"
  85. >进入营期</el-button>
  86. <el-button
  87. v-hasPermi="['live:trainingCampAdmin:add']"
  88. type="primary"
  89. size="small"
  90. icon="el-icon-plus"
  91. :disabled="!currentCamp"
  92. @click="openPeriodForm()"
  93. >新建营期</el-button>
  94. </div>
  95. </div>
  96. <el-empty v-if="!currentCamp" description="请先选择训练营" :image-size="64" />
  97. <el-table
  98. v-else
  99. ref="periodTable"
  100. v-loading="periodLoading"
  101. :data="periodList"
  102. highlight-current-row
  103. border
  104. size="small"
  105. @current-change="onPeriodChange"
  106. >
  107. <el-table-column label="营期名称" prop="periodName" min-width="120" show-overflow-tooltip />
  108. <el-table-column label="营期图" width="76" align="center">
  109. <template slot-scope="scope">
  110. <el-image
  111. v-if="scope.row.periodImgUrl"
  112. class="period-thumb"
  113. :src="scope.row.periodImgUrl"
  114. fit="cover"
  115. :preview-src-list="[scope.row.periodImgUrl]"
  116. />
  117. <span v-else class="period-thumb-empty">—</span>
  118. </template>
  119. </el-table-column>
  120. <el-table-column label="开始" prop="startTime" width="100" show-overflow-tooltip>
  121. <template slot-scope="scope">{{ formatDt(scope.row.startTime) }}</template>
  122. </el-table-column>
  123. <el-table-column label="结束" prop="endTime" width="100" show-overflow-tooltip>
  124. <template slot-scope="scope">{{ formatDt(scope.row.endTime) }}</template>
  125. </el-table-column>
  126. <el-table-column label="操作" width="168" align="center" fixed="right">
  127. <template slot-scope="scope">
  128. <el-button
  129. type="text"
  130. size="mini"
  131. icon="el-icon-right"
  132. @click.stop="enterPeriodWorkspace(scope.row)"
  133. >进入营期</el-button>
  134. <el-button
  135. v-hasPermi="['live:trainingCampAdmin:edit']"
  136. type="text"
  137. size="mini"
  138. @click.stop="openPeriodForm(scope.row)"
  139. >编辑</el-button>
  140. <el-button
  141. v-hasPermi="['live:trainingCampAdmin:remove']"
  142. type="text"
  143. size="mini"
  144. @click.stop="removePeriod(scope.row)"
  145. >删除</el-button>
  146. </template>
  147. </el-table-column>
  148. </el-table>
  149. </el-card>
  150. </el-col>
  151. </el-row>
  152. </div>
  153. <period-workspace
  154. v-show="periodWorkspace.periodId"
  155. ref="periodWorkspaceRef"
  156. :workspace="periodWorkspace"
  157. :company-id="periodWorkspace.companyId"
  158. @back="closePeriodWorkspace"
  159. @add-live="openLiveForm"
  160. @edit-live="openLiveFormEdit"
  161. />
  162. <!-- 训练营表单 -->
  163. <el-dialog :title="campForm.campId ? '编辑训练营' : '新建训练营'" :visible.sync="campOpen" width="480px" append-to-body>
  164. <el-form ref="campFormRef" :model="campForm" :rules="campRules" label-width="88px">
  165. <el-form-item v-if="!campForm.campId" label="所属企业" prop="companyId">
  166. <el-select
  167. v-model="campForm.companyId"
  168. filterable
  169. placeholder="请选择企业"
  170. style="width: 100%"
  171. >
  172. <el-option
  173. v-for="co in companyOptions"
  174. :key="co.companyId"
  175. :label="co.companyName"
  176. :value="co.companyId"
  177. />
  178. </el-select>
  179. </el-form-item>
  180. <el-form-item v-else label="所属企业">
  181. <el-input :value="campForm.companyName || campForm.companyId" disabled />
  182. </el-form-item>
  183. <el-form-item label="名称" prop="campName">
  184. <el-input v-model="campForm.campName" maxlength="128" show-word-limit placeholder="训练营名称" />
  185. </el-form-item>
  186. <el-form-item label="排序" prop="sortOrder">
  187. <el-input-number v-model="campForm.sortOrder" :min="0" :max="9999" controls-position="right" />
  188. </el-form-item>
  189. <el-form-item label="状态" prop="status">
  190. <el-radio-group v-model="campForm.status">
  191. <el-radio :label="0">正常</el-radio>
  192. <el-radio :label="1">停用</el-radio>
  193. </el-radio-group>
  194. </el-form-item>
  195. <el-form-item label="说明" prop="description">
  196. <el-input v-model="campForm.description" type="textarea" rows="3" maxlength="512" show-word-limit />
  197. </el-form-item>
  198. </el-form>
  199. <div slot="footer" class="dialog-footer">
  200. <el-button @click="campOpen = false">取 消</el-button>
  201. <el-button type="primary" @click="submitCamp">确 定</el-button>
  202. </div>
  203. </el-dialog>
  204. <!-- 营期表单 -->
  205. <el-dialog :title="periodForm.periodId ? '编辑营期' : '新建营期'" :visible.sync="periodOpen" width="520px" append-to-body>
  206. <el-form ref="periodFormRef" :model="periodForm" :rules="periodRules" label-width="88px">
  207. <el-form-item label="营期名称" prop="periodName">
  208. <el-input v-model="periodForm.periodName" maxlength="128" show-word-limit />
  209. </el-form-item>
  210. <el-form-item label="营期图片" prop="periodImgUrl">
  211. <image-upload v-model="periodForm.periodImgUrl" :limit="1" />
  212. </el-form-item>
  213. <el-form-item label="开始时间" prop="startTime">
  214. <el-date-picker
  215. v-model="periodForm.startTime"
  216. type="datetime"
  217. value-format="yyyy-MM-dd HH:mm:ss"
  218. placeholder="选择开始时间"
  219. style="width: 100%"
  220. />
  221. </el-form-item>
  222. <el-form-item label="结束时间" prop="endTime">
  223. <el-date-picker
  224. v-model="periodForm.endTime"
  225. type="datetime"
  226. value-format="yyyy-MM-dd HH:mm:ss"
  227. placeholder="选择结束时间"
  228. style="width: 100%"
  229. />
  230. </el-form-item>
  231. <el-form-item label="排序" prop="sortOrder">
  232. <el-input-number v-model="periodForm.sortOrder" :min="0" :max="9999" controls-position="right" />
  233. </el-form-item>
  234. <el-form-item label="状态" prop="status">
  235. <el-radio-group v-model="periodForm.status">
  236. <el-radio :label="0">正常</el-radio>
  237. <el-radio :label="1">停用</el-radio>
  238. </el-radio-group>
  239. </el-form-item>
  240. <el-form-item label="说明" prop="description">
  241. <el-input v-model="periodForm.description" type="textarea" rows="3" maxlength="512" show-word-limit />
  242. </el-form-item>
  243. </el-form>
  244. <div slot="footer" class="dialog-footer">
  245. <el-button @click="periodOpen = false">取 消</el-button>
  246. <el-button type="primary" @click="submitPeriod">确 定</el-button>
  247. </div>
  248. </el-dialog>
  249. <!-- 新增/修改直播间(与「直播管理」表单一致;新增走营期接口,修改走直播更新接口) -->
  250. <el-dialog :title="liveUpsertMode === 'edit' ? '修改直播间' : '添加直播间'" :visible.sync="liveOpen" width="900px" append-to-body>
  251. <el-form ref="liveUpsertFormRef" :model="liveUpsertForm" :rules="liveUpsertRules" label-width="80px">
  252. <el-form-item label="直播名称" prop="liveName">
  253. <el-input v-model="liveUpsertForm.liveName" placeholder="请输入直播名称" />
  254. </el-form-item>
  255. <el-form-item label="显示类型" prop="showType">
  256. <el-radio-group v-model="liveUpsertForm.showType">
  257. <el-radio :label="1">横屏</el-radio>
  258. <el-radio :label="2">竖屏</el-radio>
  259. </el-radio-group>
  260. </el-form-item>
  261. <el-form-item label="直播类型" prop="liveType">
  262. <el-radio-group v-model="liveUpsertForm.liveType">
  263. <el-radio
  264. v-for="item in liveTypeDictList"
  265. :key="item.dictValue"
  266. :label="parseInt(item.dictValue)"
  267. >
  268. {{ item.dictLabel }}
  269. </el-radio>
  270. </el-radio-group>
  271. </el-form-item>
  272. <el-form-item label="直播描述" prop="liveDesc">
  273. <Editor ref="liveUpsertEditor" :height="300" @on-text-change="onLiveDescChange" />
  274. </el-form-item>
  275. <el-form-item label="录播视屏" prop="videoUrl" v-if="liveUpsertForm.liveType == 2">
  276. <video-upload
  277. :fileKey.sync="liveUpsertForm.fileKey"
  278. :fileSize.sync="liveUpsertForm.fileSize"
  279. :videoUrl.sync="liveUpsertForm.videoUrl"
  280. :fileName.sync="liveUpsertForm.fileName"
  281. :line_1.sync="liveUpsertForm.lineOne"
  282. :uploadType.sync="liveUpsertForm.uploadType"
  283. :isTranscode.sync="liveUpsertForm.isTranscode"
  284. ref="liveUpsertVideoUpload"
  285. :transcodeFileKey.sync="liveUpsertForm.transcodeFileKey"
  286. @video-duration="onLiveVideoDuration"
  287. @change="onLiveVideoChange"
  288. />
  289. </el-form-item>
  290. <el-form-item label="开始时间" prop="startTime">
  291. <el-date-picker
  292. size="small"
  293. v-model="liveUpsertForm.startTime"
  294. @change="onLiveStartTimeChange"
  295. type="datetime"
  296. format="yyyy-MM-dd HH:mm:ss"
  297. value-format="yyyy-MM-dd HH:mm:ss"
  298. :picker-options="{
  299. timePickerOptions: {
  300. selectableRange: '00:00:00 - 23:59:59',
  301. format: 'HH:mm:ss'
  302. }
  303. }"
  304. placeholder="选择开始时间"
  305. />
  306. </el-form-item>
  307. <el-form-item label="结束时间" prop="finishTime" v-loading="liveTimeLoading">
  308. <el-date-picker
  309. size="small"
  310. v-model="liveUpsertForm.finishTime"
  311. type="datetime"
  312. format="yyyy-MM-dd HH:mm:ss"
  313. value-format="yyyy-MM-dd HH:mm:ss"
  314. :picker-options="{
  315. timePickerOptions: {
  316. selectableRange: '00:00:00 - 23:59:59',
  317. format: 'HH:mm:ss'
  318. }
  319. }"
  320. placeholder="视屏播放结束"
  321. />
  322. </el-form-item>
  323. <el-form-item label="直播封面" prop="liveImgUrl">
  324. <image-upload v-model="liveUpsertForm.liveImgUrl" :limit="1" />
  325. </el-form-item>
  326. <el-form-item label="上下架" prop="isShow">
  327. <el-radio-group v-model="liveUpsertForm.isShow">
  328. <el-radio :label="1">上架</el-radio>
  329. <el-radio :label="2">下架</el-radio>
  330. </el-radio-group>
  331. </el-form-item>
  332. </el-form>
  333. <div slot="footer" class="dialog-footer">
  334. <el-button type="primary" @click="submitLive">确 定</el-button>
  335. <el-button @click="cancelLiveDialog">取 消</el-button>
  336. </div>
  337. </el-dialog>
  338. </div>
  339. </template>
  340. <script>
  341. import {
  342. listTrainingCamp,
  343. addTrainingCamp,
  344. updateTrainingCamp,
  345. delTrainingCamp,
  346. listTrainingPeriod,
  347. addTrainingPeriod,
  348. updateTrainingPeriod,
  349. delTrainingPeriod,
  350. addTrainingLive,
  351. getTrainingPeriod
  352. } from '@/api/live/trainingCampAdmin'
  353. import { listCompany } from '@/api/company/company'
  354. import { getLive, updateLive } from '@/api/live/live'
  355. import PeriodWorkspace from './PeriodWorkspace.vue'
  356. import Editor from '@/components/Editor/wang'
  357. import VideoUpload from '@/components/LiveVideoUpload/single.vue'
  358. export default {
  359. name: 'LiveTrainingCampAdmin',
  360. components: { PeriodWorkspace, Editor, VideoUpload },
  361. data() {
  362. return {
  363. campLoading: false,
  364. periodLoading: false,
  365. campList: [],
  366. periodList: [],
  367. currentCamp: null,
  368. currentPeriod: null,
  369. campOpen: false,
  370. periodOpen: false,
  371. liveOpen: false,
  372. /** add | edit */
  373. liveUpsertMode: 'add',
  374. campForm: {},
  375. periodForm: {},
  376. liveTypeDictList: [],
  377. liveUpsertForm: {
  378. uploadType: 1,
  379. isTranscode: 0,
  380. transcodeFileKey: null,
  381. videoUrl: null,
  382. fileKey: null,
  383. fileName: null,
  384. fileSize: null,
  385. lineOne: null
  386. },
  387. liveVideoUrl: '',
  388. liveTimeLoading: false,
  389. campSearchName: '',
  390. companyOptions: [],
  391. periodWorkspace: {
  392. periodId: null,
  393. periodName: '',
  394. campName: '',
  395. companyId: null,
  396. periodImgUrl: '',
  397. startTime: null,
  398. endTime: null
  399. },
  400. campRules: {
  401. campName: [{ required: true, message: '请输入训练营名称', trigger: 'blur' }]
  402. },
  403. periodRules: {
  404. periodName: [{ required: true, message: '请输入营期名称', trigger: 'blur' }]
  405. },
  406. liveUpsertRules: {
  407. liveName: [{ required: true, message: '不能为空', trigger: 'blur' }],
  408. showType: [{ required: true, message: '不能为空', trigger: 'blur' }],
  409. liveType: [{ required: true, message: '不能为空', trigger: 'blur' }],
  410. startTime: [{ required: true, message: '不能为空', trigger: 'blur' }],
  411. liveImgUrl: [{ required: true, message: '不能为空', trigger: 'blur' }],
  412. isShow: [{ required: true, message: '不能为空', trigger: 'change' }]
  413. }
  414. }
  415. },
  416. watch: {
  417. 'liveUpsertForm.startTime': {
  418. handler(newVal) {
  419. if (!newVal) return
  420. const timeObj = new Date(newVal)
  421. if (isNaN(timeObj.getTime())) return
  422. timeObj.setSeconds(1)
  423. const formattedSeconds = this.padTime(timeObj.getSeconds())
  424. const year = timeObj.getFullYear()
  425. const month = this.padTime(timeObj.getMonth() + 1)
  426. const day = this.padTime(timeObj.getDate())
  427. const hours = this.padTime(timeObj.getHours())
  428. const minutes = this.padTime(timeObj.getMinutes())
  429. this.liveUpsertForm.startTime = `${year}-${month}-${day} ${hours}:${minutes}:${formattedSeconds}`
  430. },
  431. immediate: true,
  432. deep: false
  433. },
  434. '$route.query.periodId'(val) {
  435. if (!val) {
  436. this.resetWorkspaceState(false)
  437. return
  438. }
  439. const id = Number(val)
  440. if (Number.isNaN(id)) return
  441. if (this.periodWorkspace.periodId === id) return
  442. this.restoreWorkspaceFromRoute(id)
  443. }
  444. },
  445. created() {
  446. this.loadCompanyOptions()
  447. this.loadCamps()
  448. this.getDicts('live_type').then(response => {
  449. this.liveTypeDictList = response.data
  450. })
  451. const pid = this.$route.query.periodId
  452. if (pid) {
  453. const id = Number(pid)
  454. if (!Number.isNaN(id)) {
  455. this.$nextTick(() => this.restoreWorkspaceFromRoute(id))
  456. }
  457. }
  458. },
  459. methods: {
  460. formatDt(val) {
  461. if (!val) return '—'
  462. const s = String(val).replace('T', ' ')
  463. return s.length >= 16 ? s.slice(0, 16) : s
  464. },
  465. resetWorkspaceState(updateRoute) {
  466. this.periodWorkspace = {
  467. periodId: null,
  468. periodName: '',
  469. campName: '',
  470. companyId: null,
  471. periodImgUrl: '',
  472. startTime: null,
  473. endTime: null
  474. }
  475. if (updateRoute !== false) {
  476. const q = { ...this.$route.query }
  477. delete q.periodId
  478. delete q.companyId
  479. this.$router.replace({ path: this.$route.path, query: q }).catch(() => {})
  480. }
  481. },
  482. enterPeriodWorkspace(row) {
  483. if (!row || !row.periodId) {
  484. this.$message.warning('请先选中一行营期,或点击操作栏「进入营期」')
  485. return
  486. }
  487. const campName = (this.currentCamp && this.currentCamp.campName) || row.campName || ''
  488. const companyId = (this.currentCamp && this.currentCamp.companyId) || null
  489. this.periodWorkspace = {
  490. periodId: row.periodId,
  491. periodName: row.periodName || '',
  492. campName,
  493. companyId,
  494. periodImgUrl: row.periodImgUrl || '',
  495. startTime: row.startTime || null,
  496. endTime: row.endTime || null
  497. }
  498. this.$router.replace({
  499. path: this.$route.path,
  500. query: {
  501. ...this.$route.query,
  502. periodId: String(row.periodId),
  503. ...(companyId != null ? { companyId: String(companyId) } : {})
  504. }
  505. }).catch(() => {})
  506. },
  507. restoreWorkspaceFromRoute(periodId) {
  508. const qcid = this.$route.query.companyId
  509. const companyId = qcid != null && qcid !== '' ? Number(qcid) : undefined
  510. getTrainingPeriod(periodId, companyId).then(res => {
  511. const data = res.data
  512. if (!data) {
  513. this.$message.error('营期不存在或无权限')
  514. this.resetWorkspaceState()
  515. return
  516. }
  517. this.periodWorkspace = {
  518. periodId: data.periodId,
  519. periodName: data.periodName || '',
  520. campName: data.campName || '',
  521. companyId: data.companyId != null ? data.companyId : companyId,
  522. periodImgUrl: data.periodImgUrl || '',
  523. startTime: data.startTime || null,
  524. endTime: data.endTime || null
  525. }
  526. }).catch(() => {
  527. this.resetWorkspaceState()
  528. })
  529. },
  530. closePeriodWorkspace() {
  531. this.resetWorkspaceState(true)
  532. },
  533. loadCompanyOptions() {
  534. listCompany({ pageNum: 1, pageSize: 2000 }).then(res => {
  535. this.companyOptions = res.rows || []
  536. }).catch(() => {})
  537. },
  538. loadCamps() {
  539. this.campLoading = true
  540. const q = { pageNum: 1, pageSize: 500 }
  541. if (this.campSearchName) {
  542. q.campName = this.campSearchName
  543. }
  544. listTrainingCamp(q).then(res => {
  545. this.campList = res.rows || []
  546. this.campLoading = false
  547. this.$nextTick(() => {
  548. if (this.currentCamp) {
  549. const hit = this.campList.find(c => c.campId === this.currentCamp.campId)
  550. if (hit) {
  551. this.$refs.campTable && this.$refs.campTable.setCurrentRow(hit)
  552. } else {
  553. this.currentCamp = null
  554. this.currentPeriod = null
  555. this.periodList = []
  556. }
  557. }
  558. })
  559. }).catch(() => { this.campLoading = false })
  560. },
  561. onCampChange(row) {
  562. this.currentCamp = row || null
  563. this.currentPeriod = null
  564. this.periodList = []
  565. if (!row) return
  566. this.loadPeriods()
  567. },
  568. loadPeriods() {
  569. if (!this.currentCamp) return
  570. this.periodLoading = true
  571. listTrainingPeriod({
  572. campId: this.currentCamp.campId,
  573. companyId: this.currentCamp.companyId,
  574. pageNum: 1,
  575. pageSize: 500
  576. }).then(res => {
  577. this.periodList = res.rows || []
  578. this.periodLoading = false
  579. }).catch(() => { this.periodLoading = false })
  580. },
  581. onPeriodChange(row) {
  582. this.currentPeriod = row || null
  583. },
  584. openCampForm(row) {
  585. this.campForm = row
  586. ? { ...row }
  587. : { companyId: null, campName: '', sortOrder: 0, status: 0, description: '' }
  588. this.campOpen = true
  589. this.$nextTick(() => this.$refs.campFormRef && this.$refs.campFormRef.clearValidate())
  590. },
  591. submitCamp() {
  592. this.$refs.campFormRef.validate(valid => {
  593. if (!valid) return
  594. if (!this.campForm.campId && !this.campForm.companyId) {
  595. this.$message.warning('请选择所属企业')
  596. return
  597. }
  598. const req = this.campForm.campId ? updateTrainingCamp(this.campForm) : addTrainingCamp(this.campForm)
  599. req.then(res => {
  600. this.$message.success((res && res.msg) || '保存成功')
  601. this.campOpen = false
  602. this.loadCamps()
  603. })
  604. })
  605. },
  606. removeCamp(row) {
  607. this.$confirm('确认删除训练营「' + row.campName + '」?须先清空营期。').then(() => {
  608. return delTrainingCamp(row.campId, row.companyId)
  609. }).then(res => {
  610. this.$message.success((res && res.msg) || '已删除')
  611. if (this.currentCamp && this.currentCamp.campId === row.campId) {
  612. this.currentCamp = null
  613. this.currentPeriod = null
  614. this.periodList = []
  615. }
  616. this.loadCamps()
  617. }).catch(() => {})
  618. },
  619. openPeriodForm(row) {
  620. if (!this.currentCamp) return
  621. this.periodForm = row
  622. ? { ...row, campId: row.campId, companyId: this.currentCamp.companyId }
  623. : {
  624. campId: this.currentCamp.campId,
  625. companyId: this.currentCamp.companyId,
  626. periodName: '',
  627. periodImgUrl: '',
  628. startTime: null,
  629. endTime: null,
  630. sortOrder: 0,
  631. status: 0,
  632. description: ''
  633. }
  634. this.periodOpen = true
  635. this.$nextTick(() => this.$refs.periodFormRef && this.$refs.periodFormRef.clearValidate())
  636. },
  637. submitPeriod() {
  638. this.$refs.periodFormRef.validate(valid => {
  639. if (!valid) return
  640. if (this.currentCamp && this.currentCamp.companyId != null) {
  641. this.periodForm.companyId = this.currentCamp.companyId
  642. }
  643. const req = this.periodForm.periodId ? updateTrainingPeriod(this.periodForm) : addTrainingPeriod(this.periodForm)
  644. req.then(res => {
  645. this.$message.success((res && res.msg) || '保存成功')
  646. this.periodOpen = false
  647. if (this.periodWorkspace.periodId && this.periodForm.periodId === this.periodWorkspace.periodId) {
  648. this.periodWorkspace = {
  649. ...this.periodWorkspace,
  650. periodName: this.periodForm.periodName || '',
  651. periodImgUrl: this.periodForm.periodImgUrl || '',
  652. startTime: this.periodForm.startTime || null,
  653. endTime: this.periodForm.endTime || null
  654. }
  655. }
  656. this.loadPeriods()
  657. })
  658. })
  659. },
  660. removePeriod(row) {
  661. if (!this.currentCamp || !this.currentCamp.companyId) {
  662. this.$message.warning('缺少企业信息')
  663. return
  664. }
  665. this.$confirm('确认删除营期「' + row.periodName + '」?须先删除营期下直播间。').then(() => {
  666. return delTrainingPeriod(row.periodId, this.currentCamp.companyId)
  667. }).then(res => {
  668. this.$message.success((res && res.msg) || '已删除')
  669. if (this.currentPeriod && this.currentPeriod.periodId === row.periodId) {
  670. this.currentPeriod = null
  671. }
  672. if (this.periodWorkspace.periodId === row.periodId) {
  673. this.closePeriodWorkspace()
  674. }
  675. this.loadPeriods()
  676. }).catch(() => {})
  677. },
  678. initLiveUpsertDefaults() {
  679. this.liveUpsertForm = {
  680. showType: 1,
  681. liveType: 2,
  682. isShow: 1,
  683. isTranscode: 0,
  684. uploadType: 1,
  685. transcodeFileKey: null
  686. }
  687. this.liveVideoUrl = ''
  688. },
  689. cancelLiveDialog() {
  690. this.liveOpen = false
  691. this.liveUpsertMode = 'add'
  692. this.initLiveUpsertDefaults()
  693. },
  694. padTime(n) {
  695. return n < 10 ? `0${n}` : String(n)
  696. },
  697. formatLiveEndDate(date) {
  698. const y = date.getFullYear()
  699. const m = (date.getMonth() + 1).toString().padStart(2, '0')
  700. const d = date.getDate().toString().padStart(2, '0')
  701. const h = date.getHours().toString().padStart(2, '0')
  702. const min = date.getMinutes().toString().padStart(2, '0')
  703. const s = date.getSeconds().toString().padStart(2, '0')
  704. return `${y}-${m}-${d} ${h}:${min}:${s}`
  705. },
  706. onLiveStartTimeChange() {
  707. if (!this.liveUpsertForm.startTime) return
  708. if (!this.liveUpsertForm.duration) return
  709. const startDateTime = new Date(this.liveUpsertForm.startTime)
  710. const endDateTime = new Date(startDateTime.getTime() + this.liveUpsertForm.duration * 1000)
  711. this.liveUpsertForm.finishTime = this.formatLiveEndDate(endDateTime)
  712. },
  713. onLiveVideoDuration(duration) {
  714. this.liveUpsertForm.duration = duration
  715. },
  716. onLiveVideoChange(videoUrl) {
  717. this.liveVideoUrl = videoUrl
  718. this.liveUpsertForm.videoUrl = videoUrl
  719. },
  720. onLiveDescChange(text) {
  721. setTimeout(() => {
  722. this.liveUpsertForm.liveDesc = text
  723. }, 1)
  724. },
  725. openLiveForm() {
  726. if (!this.periodWorkspace.periodId) {
  727. this.$message.warning('请先进入营期')
  728. return
  729. }
  730. this.liveUpsertMode = 'add'
  731. this.initLiveUpsertDefaults()
  732. this.liveOpen = true
  733. this.$nextTick(() => {
  734. if (this.$refs.liveUpsertFormRef) {
  735. this.$refs.liveUpsertFormRef.clearValidate()
  736. }
  737. setTimeout(() => {
  738. if (this.$refs.liveUpsertEditor) {
  739. this.$refs.liveUpsertEditor.setText('')
  740. }
  741. if (this.$refs.liveUpsertVideoUpload) {
  742. this.$refs.liveUpsertVideoUpload.reset()
  743. }
  744. }, 100)
  745. })
  746. },
  747. openLiveFormEdit(row) {
  748. if (!this.periodWorkspace.periodId) {
  749. this.$message.warning('请先进入营期')
  750. return
  751. }
  752. if (!row || !row.liveId) {
  753. this.$message.warning('直播间信息无效')
  754. return
  755. }
  756. this.liveUpsertMode = 'edit'
  757. getLive(row.liveId).then(res => {
  758. const d = res.data
  759. if (!d) {
  760. this.$message.error('获取直播间失败')
  761. this.liveUpsertMode = 'add'
  762. return
  763. }
  764. this.liveUpsertForm = { ...d }
  765. this.liveVideoUrl = d.videoUrl || ''
  766. this.liveOpen = true
  767. this.$nextTick(() => {
  768. if (this.$refs.liveUpsertFormRef) {
  769. this.$refs.liveUpsertFormRef.clearValidate()
  770. }
  771. setTimeout(() => {
  772. if (this.$refs.liveUpsertEditor) {
  773. this.$refs.liveUpsertEditor.setText(d.liveDesc || '')
  774. }
  775. if (d.videoUrl) {
  776. this.liveUpsertForm.videoUrl = d.videoUrl
  777. }
  778. }, 100)
  779. })
  780. }).catch(() => {
  781. this.liveUpsertMode = 'add'
  782. })
  783. },
  784. submitLive() {
  785. if (this.liveUpsertForm.liveType === 2 && (!this.liveVideoUrl || this.liveVideoUrl.length === 0)) {
  786. this.$message.error('请上传视频')
  787. return
  788. }
  789. this.$refs.liveUpsertFormRef.validate(valid => {
  790. if (!valid) return
  791. if (!this.periodWorkspace.periodId) {
  792. this.$message.warning('营期已失效,请返回列表重新进入')
  793. return
  794. }
  795. const body = { ...this.liveUpsertForm }
  796. body.videoUrl = this.liveVideoUrl
  797. body.trainingPeriodId = this.periodWorkspace.periodId
  798. if (this.liveUpsertMode === 'add') {
  799. delete body.liveId
  800. const cid = this.periodWorkspace.companyId || (this.currentCamp && this.currentCamp.companyId)
  801. if (!cid) {
  802. this.$message.error('缺少企业ID,无法创建直播间')
  803. return
  804. }
  805. addTrainingLive(body, cid).then(res => {
  806. this.$message.success((res && res.msg) || '新增成功')
  807. this.liveOpen = false
  808. this.liveUpsertMode = 'add'
  809. this.initLiveUpsertDefaults()
  810. this.$refs.periodWorkspaceRef && this.$refs.periodWorkspaceRef.refreshLiveList()
  811. })
  812. } else {
  813. if (!body.liveId) {
  814. this.$message.error('缺少直播间ID')
  815. return
  816. }
  817. updateLive(body).then(res => {
  818. this.$message.success((res && res.msg) || '修改成功')
  819. this.liveOpen = false
  820. this.liveUpsertMode = 'add'
  821. this.initLiveUpsertDefaults()
  822. this.$refs.periodWorkspaceRef && this.$refs.periodWorkspaceRef.refreshLiveList()
  823. })
  824. }
  825. })
  826. },
  827. }
  828. }
  829. </script>
  830. <style scoped>
  831. .training-camp-root {
  832. min-height: 100%;
  833. }
  834. .training-camp-page .mb12 {
  835. margin-bottom: 12px;
  836. }
  837. .box-card {
  838. min-height: 420px;
  839. }
  840. .box-card-period {
  841. min-height: 420px;
  842. }
  843. .period-header {
  844. display: flex;
  845. align-items: center;
  846. justify-content: space-between;
  847. flex-wrap: wrap;
  848. gap: 8px;
  849. }
  850. .period-header-left {
  851. flex: 1;
  852. min-width: 0;
  853. }
  854. .period-header-actions {
  855. display: flex;
  856. align-items: center;
  857. gap: 8px;
  858. flex-shrink: 0;
  859. }
  860. .sub-hint {
  861. color: #909399;
  862. font-size: 12px;
  863. margin-left: 6px;
  864. }
  865. .period-thumb {
  866. width: 48px;
  867. height: 48px;
  868. border-radius: 4px;
  869. vertical-align: middle;
  870. }
  871. .period-thumb-empty {
  872. color: #c0c4cc;
  873. font-size: 12px;
  874. }
  875. </style>