index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <div class="cover-upload-row">
  3. <a-upload
  4. :show-upload-list="false"
  5. :before-upload="beforeUploadSrt"
  6. accept=".srt"
  7. @change="handleChange"
  8. :action="action"
  9. :headers="headers"
  10. >
  11. <a-button v-if="form.id ==''">
  12. <CloudUploadOutlined/>
  13. 上传文件
  14. </a-button>
  15. <span v-if="form.id !=''" style="cursor: pointer;">{{form.name}}</span>
  16. </a-upload>
  17. <span class="upload-tip">仅支持srt格式文件上传,文件大小不超过1MB</span>
  18. </div>
  19. </template>
  20. <script setup>
  21. import {ref, reactive, watch, defineProps, defineEmits} from 'vue'
  22. import {message} from 'ant-design-vue'
  23. import {PictureOutlined, CloudUploadOutlined} from '@ant-design/icons-vue'
  24. import tool from "@/utils/tool";
  25. import sysConfig from '@/config/index'
  26. const action = ref(sysConfig.API_URL+'/api/webapp/dev/file/uploadMinioReturnId')
  27. const headers = ref({
  28. token: tool.data.get('TOKEN')
  29. })
  30. //课程类型
  31. const props = defineProps({
  32. count: Number,
  33. default : () => 1
  34. })
  35. const emit = defineEmits(['update:visible', 'ok','handlerUpSelect','handlerNewSelect','handlerUpSrt'])
  36. const modalVisible = ref(props.visible)
  37. watch(
  38. () => props.visible,
  39. (v) => {
  40. modalVisible.value = v
  41. }
  42. )
  43. watch(modalVisible, (v) => {
  44. emit('update:visible', v)
  45. })
  46. const formRef = ref()
  47. const file = ref({
  48. id : '',
  49. name: '',
  50. })
  51. const form = reactive({
  52. id : '',
  53. title: '',
  54. video: '',
  55. coverUrl: '',
  56. docUrl: '',
  57. srtUrl: '',
  58. name : ''
  59. })
  60. const rules = {
  61. title: [{required: true, message: '请输入课时名称'}],
  62. video: [{required: true, message: '请选择或上传视频'}],
  63. coverUrl: [{required: true, message: '请上传封面'}]
  64. }
  65. // mock视频资源
  66. const videoList = ref([
  67. {id: 'v1', name: '示例视频1.mp4'},
  68. {id: 'v2', name: '示例视频2.mp4'}
  69. ])
  70. const beforeUploadSrt = (file) => {
  71. const isSrt = file.name.endsWith('.srt')
  72. const isLt1M = file.size / 1024 / 1024 < 1
  73. if (!isSrt) {
  74. message.error('仅支持srt格式')
  75. return false
  76. }
  77. if (!isLt1M) {
  78. message.error('文件不能超过1MB')
  79. return false
  80. }
  81. form.name = file.name
  82. return true
  83. }
  84. //回显用显示图片
  85. const setData = (data) => {
  86. form.id = data.id
  87. form.name = data.name
  88. emit('handlerUpSrt',form.id)
  89. }
  90. const dummyRequest = ({onSuccess}) => {
  91. }
  92. const handleChange = (res) => {
  93. console.log('上传完毕',res)
  94. if (res.file && res.file.response &&res.file.response.code == 200) {
  95. message.success('上传成功')
  96. form.id = res.file.response.data
  97. emit('handlerUpSrt',form.id)
  98. } else {
  99. // message.error('上传失败')
  100. }
  101. }
  102. const setFile = (fileData) => {
  103. console.log("设置了文件",fileData)
  104. file.value.id = fileData.id
  105. file.value.name = fileData.fileName
  106. }
  107. const handleOk = () =>{
  108. formRef.value.validate().then(() => {
  109. emit('ok', {...form})
  110. modalVisible.value = false
  111. })
  112. }
  113. const getData = (callBack) => {
  114. formRef.value.validate().then(() => {
  115. callBack({...form})
  116. })
  117. }
  118. const handleCancel = () => {
  119. modalVisible.value = false
  120. }
  121. defineExpose({
  122. getData,setFile,setData
  123. })
  124. </script>
  125. <style lang="less" scoped>
  126. .add-class-hours-modal {
  127. .ant-modal-content {
  128. border-radius: 10px;
  129. }
  130. .ant-modal-header {
  131. border-radius: 10px 10px 0 0;
  132. }
  133. .ant-form-item {
  134. margin-bottom: 24px;
  135. }
  136. .video-select-row {
  137. display: flex;
  138. align-items: center;
  139. }
  140. .cover-upload-row {
  141. display: flex;
  142. align-items: center;
  143. .cover-upload-box {
  144. width: 120px;
  145. height: 120px;
  146. background: #f7f8fa;
  147. border-radius: 8px;
  148. display: flex;
  149. align-items: center;
  150. justify-content: center;
  151. margin-right: 24px;
  152. border: 1px dashed #d9d9d9;
  153. cursor: pointer;
  154. .cover-img {
  155. width: 100%;
  156. height: 100%;
  157. object-fit: cover;
  158. border-radius: 8px;
  159. }
  160. .cover-placeholder {
  161. display: flex;
  162. align-items: center;
  163. justify-content: center;
  164. width: 100%;
  165. height: 100%;
  166. color: #bbb;
  167. font-size: 32px;
  168. }
  169. }
  170. .cover-tip {
  171. color: #888;
  172. font-size: 13px;
  173. }
  174. }
  175. .upload-tip {
  176. color: #888;
  177. font-size: 13px;
  178. margin-left: 12px;
  179. }
  180. .footer-btns {
  181. display: flex;
  182. justify-content: flex-end;
  183. gap: 16px;
  184. margin-top: 24px;
  185. }
  186. }
  187. </style>