form.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <xn-form-container
  3. :width="500"
  4. :get-container="false"
  5. :visible="visible"
  6. :destroy-on-close="true"
  7. @close="onClose"
  8. :mask="false"
  9. >
  10. <div v-if="itemObj.key == 2" style="height: 100%">
  11. <vue-office-pdf :src="itemObj.url" style="width: 100%; height: 100%" />
  12. </div>
  13. <div v-if="itemObj.key == 3" style="height: 100%">
  14. <div v-for="(item, idx) in itemObj.srtInfoList" :key="idx">
  15. <div>{{ item.startTime }}~{{ item.endTime }}</div>
  16. <div style="cursor: pointer; padding: 10px 0" @click="videoSpeed(item)">{{ item.text }}</div>
  17. </div>
  18. </div>
  19. <div v-if="itemObj.type == 2 || itemObj.type == 4">
  20. <a-card :bordered="false">
  21. <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
  22. <a-row :gutter="16">
  23. <a-col :span="24">
  24. <a-form-item name="noteContent" v-if="itemObj.type == 2">
  25. <a-textarea v-model:value="formData.noteContent" placeholder="请输入内容" :rows="4" />
  26. </a-form-item>
  27. <div v-if="itemObj.type == 4">
  28. <a-form-item name="info" label="问题">
  29. <a-textarea v-model:value="formData.info" placeholder="请输入问题" :rows="4" />
  30. </a-form-item>
  31. </div>
  32. </a-col>
  33. </a-row>
  34. </a-form>
  35. <div class="frc">
  36. <a-button type="primary" :loading="submitLoading" @click="onSubmit">保存</a-button>
  37. </div>
  38. <div class="noteBox">
  39. <note v-if="itemObj.type == 2" :idsObj="idsObj" ref="noteRef" @edit="editForm"></note>
  40. <askDiv v-if="itemObj.type == 4" :idsObj="idsObj" ref="noteRef" @edit="editForm"></askDiv>
  41. </div>
  42. </a-card>
  43. </div>
  44. </xn-form-container>
  45. </template>
  46. <script setup>
  47. import classCentre from '@/api/student/classCentre'
  48. import { required } from '@/utils/formRules'
  49. import note from './note.vue'
  50. import askDiv from './ask.vue'
  51. import VueOfficePdf from '@vue-office/pdf'
  52. import axios from 'axios'
  53. const props = defineProps({
  54. rightItem: {
  55. type: [Array, Object],
  56. required: () => {}
  57. },
  58. idsObj: {
  59. type: [Array, Object],
  60. required: () => {}
  61. }
  62. })
  63. const itemObj = computed(() => {
  64. if (props.rightItem?.url) {
  65. GetSrtInfo(props.rightItem.url)
  66. }
  67. return props.rightItem
  68. })
  69. const noteRef = ref()
  70. const submitLoading = ref(false)
  71. // 表单数据,也就是默认给一些数据
  72. const formData = ref({})
  73. const formRef = ref()
  74. //tabs
  75. const activeKey = ref('1')
  76. // 默认是关闭状态
  77. const visible = ref(false)
  78. const emit = defineEmits({ successful: null, videoSpeed: null })
  79. // 打开抽屉
  80. const onOpen = (edit) => {
  81. visible.value = true
  82. if (edit) {
  83. if (itemObj.value.type == 2) {
  84. formData.value.noteId = edit.noteId
  85. formData.value.noteContent = edit.noteContent
  86. } else {
  87. formData.value.info = edit.info
  88. formData.value.id = edit.id
  89. }
  90. }
  91. }
  92. // 关闭抽屉
  93. const onClose = () => {
  94. formRef.value?.resetFields()
  95. formData.value.id = null
  96. formData.value.noteId = null
  97. visible.value = false
  98. }
  99. // 默认要校验的
  100. const formRules = {
  101. noteContent: [required('请输入内容')],
  102. info: [required('请输入内容')]
  103. }
  104. // 提交数据
  105. const onSubmit = () => {
  106. formRef.value
  107. .validate()
  108. .then(() => {
  109. submitLoading.value = true
  110. classCentre[itemObj.value.type == 2 ? 'notesSubmitForm' : 'askSubmitForm'](
  111. {
  112. ...props.idsObj,
  113. ...formData.value
  114. },
  115. itemObj.value.type == 2 ? formData.value.noteId : formData.value.id
  116. ).then(() => {
  117. emit('successful')
  118. formRef.value.resetFields()
  119. noteRef.value.getList()
  120. })
  121. })
  122. .finally(() => {
  123. submitLoading.value = false
  124. })
  125. }
  126. const editForm = (e) => {
  127. onOpen(e)
  128. if (itemObj.value.type == 2) {
  129. formData.value.noteId = e.noteId
  130. formData.value.noteContent = e.noteContent
  131. } else {
  132. formData.value.info = e.info
  133. formData.value.id = e.id
  134. }
  135. }
  136. const videoSpeed = (e) => {
  137. emit('videoSpeed', e)
  138. }
  139. //获取字幕内容,发送一个get请求
  140. function GetSrtInfo(srtUrl) {
  141. axios
  142. .get(`${srtUrl}`)
  143. .then(function (response) {
  144. let textList = response.data
  145. .split(/\n\s\n/)
  146. .filter((item) => item != '')
  147. .map((item, index) => {
  148. let textItem = item.split(/\n/)
  149. return {
  150. index: index,
  151. sort: textItem[0],
  152. text: textItem[2],
  153. startTime: ToSeconds(textItem[1].split(' --> ')[0]),
  154. endTime: ToSeconds(textItem[1].split(' --> ')[1]),
  155. timeLine: textItem[1]
  156. }
  157. })
  158. itemObj.value.srtInfoList = textList
  159. console.log('解析之后的字幕内容', textList)
  160. })
  161. .catch(function (error) {
  162. console.log(error)
  163. })
  164. }
  165. //将时间转化为秒
  166. function ToSeconds(t) {
  167. var s = 0.0
  168. if (t) {
  169. var p = t.split(':')
  170. for (let i = 0; i < p.length; i++) {
  171. s = s * 60 + parseFloat(p[i].replace(',', '.'))
  172. }
  173. }
  174. return s
  175. }
  176. // 调用这个函数将子组件的一些数据和方法暴露出去
  177. defineExpose({
  178. onOpen
  179. })
  180. </script>
  181. <style scoped lang="less">
  182. .frc {
  183. display: flex;
  184. justify-content: flex-end;
  185. align-items: center;
  186. }
  187. .noteBox {
  188. height: 750px;
  189. overflow-y: auto;
  190. }
  191. </style>