addClassHours.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <a-form :model="form" :rules="rules" ref="formRef" layout="vertical">
  3. <a-form-item label="课时名称:" name="title" required>
  4. <a-input v-model:value="form.title" placeholder="输入内容"/>
  5. </a-form-item>
  6. <a-form-item label="选择视频:" required name="video">
  7. <div class="video-select-row">
  8. <a-button type="primary" @click="()=>{emit('handlerSelect')}">选择资源</a-button>
  9. <a-button type="primary" @click="()=>{emit('handlerUpSelect')}">新上传资源</a-button>
  10. </div>
  11. <!-- <span style="margin-top: 12px; margin-bottom: 12px">{{ file.name }}</span>-->
  12. <FileName ref="fileNameRef" v-model:value="form.video"></FileName>
  13. </a-form-item>
  14. <a-form-item label="上传封面:" required name="coverUrl">
  15. <div class="cover-upload-row">
  16. <UpLoadImg v-model:value="form.coverUrl" ref="upLoadImgRef"
  17. @handlerUpImage="handlerUpImage"></UpLoadImg>
  18. </div>
  19. </a-form-item>
  20. <a-form-item label="上传讲义:" name="docUrl">
  21. <UpLoadDoc v-model:value="form.docUrl" ref="upLoadDocRef" @handlerUpDoc="handlerUpDoc"></UpLoadDoc>
  22. </a-form-item>
  23. <a-form-item label="上传字幕:" name="srtUrl">
  24. <UpLoadSrt v-model:value="form.srtUrl" ref="UpLoadSrtRef" @handlerUpSrt="handlerUpSrt"></UpLoadSrt>
  25. </a-form-item>
  26. </a-form>
  27. </template>
  28. <script setup>
  29. import {ref, reactive, watch, defineProps, defineEmits} from 'vue'
  30. import {message} from 'ant-design-vue'
  31. import {PictureOutlined, CloudUploadOutlined} from '@ant-design/icons-vue'
  32. import UpLoadImg from '@/components/UpLoadImg/index.vue'
  33. import UpLoadDoc from '@/components/UpLoadDoc/index.vue'
  34. import UpLoadSrt from '@/components/UpLoadSrt/index.vue'
  35. import FileName from './fileName.vue'
  36. import {add, detail} from '@/api/hour/index'
  37. const props = defineProps({
  38. visible: Boolean
  39. })
  40. const emit = defineEmits(['update:visible', 'ok', 'handlerUpSelect', 'handlerNewSelect','handlerEx','handlerExs'])
  41. const fileNameRef = ref(null)
  42. const upLoadImgRef = ref(null)
  43. const upLoadDocRef = ref(null)
  44. const UpLoadSrtRef = ref(null)
  45. const modeTag = ref('add')
  46. const formRef = ref()
  47. const file = ref({
  48. id: '',
  49. name: '',
  50. })
  51. const form = reactive({
  52. title: '',
  53. video: '',
  54. coverUrl: '',
  55. docUrl: '',
  56. srtUrl: ''
  57. })
  58. const rules = {
  59. title: [{required: true, message: '请输入课时名称'}],
  60. video: [{required: true, message: '请选择或上传资源'}],
  61. coverUrl: [{required: true, message: '请上传封面'}],
  62. docUrl: [{required: true, message: '请上传讲义'}],
  63. srtUrl: [{required: true, message: '请上传字幕'}],
  64. }
  65. const handlerUpImage = (id) => {
  66. form.coverUrl = id
  67. }
  68. const handlerUpDoc = (id) => {
  69. form.docUrl = id
  70. }
  71. const handlerUpSrt = (id) => {
  72. form.srtUrl = id
  73. }
  74. const setFile = (fileData) => {
  75. console.log("设置了文件", fileData)
  76. file.value.id = fileData.id
  77. file.value.name = fileData.fileName
  78. form.video = fileData.id
  79. nextTick(() => {
  80. fileNameRef.value.setData({id : fileData.id, name :fileData.fileName })
  81. })
  82. }
  83. const getData = (callBack) => {
  84. formRef.value.validate().then(() => {
  85. let data = {}
  86. data.name = form.title
  87. data.courseRelates = []
  88. //todo :0封面 1视频资源,2讲义,3字幕,4作业,5测验
  89. data.courseRelates.push({funcType: 0, relateId: form.coverUrl})
  90. data.courseRelates.push({funcType: 1, relateId: form.video})
  91. data.courseRelates.push({funcType: 2, relateId: form.docUrl})
  92. data.courseRelates.push({funcType: 3, relateId: form.srtUrl})
  93. // {
  94. // "chapterId": "voluptate nostrud",
  95. // "name": "蒋霞",
  96. // "remark": "amet ut",
  97. // "courseRelates": [
  98. // {
  99. // "funcType": "anim dolore",
  100. // "relateId": "veniam enim"
  101. // },
  102. // {
  103. // "funcType": "cillum consequat",
  104. // "relateId": "et pariatur laborum nostrud"
  105. // }
  106. // ]
  107. // }
  108. callBack(data)
  109. }).catch((res)=>{
  110. console.log("错误内容",res)
  111. if(res.errorFields[0]){
  112. message.error(res.errorFields[0].errors[0])
  113. }
  114. })
  115. }
  116. const open = () => {
  117. modeTag.value = 'add'
  118. // reset()
  119. }
  120. const reset = () => {
  121. console.log("关掉吗")
  122. formRef.value.resetFields();
  123. nextTick(() => {
  124. form.title = ''
  125. form.video = ''
  126. form.coverUrl = ''
  127. form.docUrl = ''
  128. form.srtUrl = ''
  129. upLoadImgRef.value.setData({id: "", url: ""})
  130. fileNameRef.value.setData({id: "", name: ""})
  131. upLoadDocRef.value.setData({id: "", name: ""})
  132. UpLoadSrtRef.value.setData({id: "", name: ""})
  133. })
  134. }
  135. const edit = (item) => {
  136. // form.value.id = data.id
  137. modeTag.value = 'edit'
  138. // let data = {}
  139. //
  140. // data.name = form.title
  141. // data.courseRelates = []
  142. // //todo :1视频资源,2讲义,3字幕,4作业,5测验
  143. // data.courseRelates.push({funcType : 1,relateId:form.video})
  144. // data.courseRelates.push({funcType : 2,relateId:form.docUrl})
  145. // data.courseRelates.push({funcType : 3,relateId:form.srtUrl})
  146. console.log('修改什么', item)
  147. if(item){
  148. detail({id: item.id}).then((res) => {
  149. if (res.code == 200) {
  150. let data = res.data
  151. form.title = data.name
  152. for (let i = 0; i < data.courseRelates.length; i++) {
  153. let itemi = data.courseRelates[i]
  154. console.log('每条数据', itemi)
  155. switch (itemi.funcType) {
  156. case '0':
  157. upLoadImgRef.value.setData({id: itemi.relateId, url: itemi.url})
  158. break;
  159. case '1':
  160. // form.video = itemi.relateId
  161. // file.value.name = itemi.name
  162. form.video = itemi.relateId
  163. fileNameRef.value.setData({id: itemi.relateId, name: itemi.name})
  164. break;
  165. case '2':
  166. // form.docUrl = itemi.relateId
  167. upLoadDocRef.value.setData({id: itemi.relateId, name: itemi.name})
  168. break;
  169. case '3':
  170. // form.srtUrl = itemi.relateId
  171. UpLoadSrtRef.value.setData({id: itemi.relateId, name: itemi.name})
  172. break;
  173. case '4':
  174. // form.srtUrl = itemi.relateId
  175. // UpLoadSrtRef.value.setData({id: itemi.relateId, name: itemi.name})
  176. emit('handlerEx', [itemi])
  177. break;
  178. case '5':
  179. // form.srtUrl = itemi.relateId
  180. // UpLoadSrtRef.value.setData({id: itemi.relateId, name: itemi.name})
  181. emit('handlerExs', [itemi])
  182. break;
  183. }
  184. }
  185. }
  186. // {
  187. // "code": 200,
  188. // "msg": "操作成功",
  189. // "data": {
  190. // "chapterId": "1945821914740051969",
  191. // "courseRelates": [
  192. // {
  193. // "relateId": "1941793498696044545",
  194. // "chapterHourType": "1",
  195. // "name": "1940384168492494848",
  196. // "mainId": "1946118995975536642",
  197. // "url": "upload/20250705/3705fd26117d7e6653b13d60e8e0399d.mp4",
  198. // "funcType": "1"
  199. // },
  200. // {
  201. // "relateId": "1946118974324539394",
  202. // "chapterHourType": "1",
  203. // "name": "",
  204. // "mainId": "1946118995975536642",
  205. // "url": "",
  206. // "funcType": "2"
  207. // },
  208. // {
  209. // "relateId": "1946118987192664066",
  210. // "chapterHourType": "1",
  211. // "name": "",
  212. // "mainId": "1946118995975536642",
  213. // "url": "",
  214. // "funcType": "3"
  215. // }
  216. // ],
  217. // "name": "110",
  218. // "remark": "",
  219. // "id": "1946118995975536642"
  220. // }
  221. // }
  222. }).catch((err) => {
  223. })
  224. }
  225. // chapterId:"1945821914740051969"
  226. // createTime:"2025-07-18 16:05:00.444"
  227. // createUserName:"超管"
  228. // id:"1946118995975536642"
  229. // name:"110"
  230. // remark:""
  231. }
  232. defineExpose({
  233. getData, setFile, edit, open, reset
  234. })
  235. </script>
  236. <style lang="less" scoped>
  237. .add-class-hours-modal {
  238. .ant-modal-content {
  239. border-radius: 10px;
  240. }
  241. .ant-modal-header {
  242. border-radius: 10px 10px 0 0;
  243. }
  244. .ant-form-item {
  245. margin-bottom: 24px;
  246. }
  247. .video-select-row {
  248. display: flex;
  249. align-items: center;
  250. }
  251. .cover-upload-row {
  252. display: flex;
  253. align-items: center;
  254. .cover-upload-box {
  255. width: 120px;
  256. height: 120px;
  257. background: #f7f8fa;
  258. border-radius: 8px;
  259. display: flex;
  260. align-items: center;
  261. justify-content: center;
  262. margin-right: 24px;
  263. border: 1px dashed #d9d9d9;
  264. cursor: pointer;
  265. .cover-img {
  266. width: 100%;
  267. height: 100%;
  268. object-fit: cover;
  269. border-radius: 8px;
  270. }
  271. .cover-placeholder {
  272. display: flex;
  273. align-items: center;
  274. justify-content: center;
  275. width: 100%;
  276. height: 100%;
  277. color: #bbb;
  278. font-size: 32px;
  279. }
  280. }
  281. .cover-tip {
  282. color: #888;
  283. font-size: 13px;
  284. }
  285. }
  286. .upload-tip {
  287. color: #888;
  288. font-size: 13px;
  289. margin-left: 12px;
  290. }
  291. .footer-btns {
  292. display: flex;
  293. justify-content: flex-end;
  294. gap: 16px;
  295. margin-top: 24px;
  296. }
  297. }
  298. </style>