form.vue 4.7 KB

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