note.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <a-form ref="formRefAdd" :model="formDataAdd" :rules="formRules" layout="vertical">
  3. <a-row :gutter="16">
  4. <a-col :span="24">
  5. <a-form-item name="noteContent" label="笔记">
  6. <xn-editor v-model="formDataAdd.noteContent" placeholder="请输入笔记" :height="400"></xn-editor>
  7. </a-form-item>
  8. </a-col>
  9. </a-row>
  10. </a-form>
  11. <div class="frc">
  12. <a-button type="primary" :loading="submitLoading" @click="submitForm">新增</a-button>
  13. </div>
  14. <a-divider />
  15. <a-list
  16. class="demo-loadmore-list"
  17. :loading="initLoading"
  18. item-layout="horizontal"
  19. :data-source="listData"
  20. :pagination="pagination"
  21. >
  22. <template #renderItem="{ item }">
  23. <a-list-item>
  24. <a-skeleton avatar :title="false" :loading="!!item.loading" active>
  25. <div style="width: 100%">
  26. <a-list-item-meta>
  27. <template #title>
  28. <div class="fcbc">
  29. <div>{{ item.courseName }}</div>
  30. <div @click="videoSpeed(item)" style="cursor: pointer">{{ item.videoStopTime }}</div>
  31. </div>
  32. </template>
  33. <template #avatar v-if="item.avatar">
  34. <a-avatar :src="item.avatar" />
  35. </template>
  36. </a-list-item-meta>
  37. <div v-html="item.noteContent"></div>
  38. <div class="frc">
  39. <div @click="editNote(item)">
  40. <a-tooltip title="编辑" :getPopupContainer="(trigger) => trigger.parentElement">
  41. <edit-outlined />
  42. </a-tooltip>
  43. </div>
  44. <div class="ml-2 mr-4" @click="delNote(item)">
  45. <a-tooltip title="删除" :getPopupContainer="(trigger) => trigger.parentElement">
  46. <delete-outlined />
  47. </a-tooltip>
  48. </div>
  49. </div>
  50. </div>
  51. </a-skeleton>
  52. </a-list-item>
  53. </template>
  54. </a-list>
  55. <a-modal v-model:visible="visible" title="编辑" @ok="handleOk" append-to-body width="800px" :zIndex="99999">
  56. <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
  57. <a-row :gutter="16">
  58. <a-col :span="24">
  59. <a-form-item name="noteContent" label="问题">
  60. <xn-editor v-model="formDataAdd.noteContent" placeholder="请输入笔记" :height="400"></xn-editor>
  61. </a-form-item>
  62. </a-col>
  63. </a-row>
  64. </a-form>
  65. </a-modal>
  66. </template>
  67. <script setup>
  68. import classCentre from '@/api/student/classCentre'
  69. import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
  70. import { createVNode } from 'vue'
  71. import { Modal } from 'ant-design-vue'
  72. import { required } from '@/utils/formRules'
  73. import XnEditor from '@/components/Editor/index.vue'
  74. // 表单数据,也就是默认给一些数据
  75. const visible = ref(false)
  76. const formData = ref({})
  77. const formRef = ref()
  78. const formDataAdd = ref({})
  79. const formRefAdd = ref()
  80. const submitLoading = ref(false)
  81. // 默认要校验的
  82. const formRules = {
  83. noteContent: [required('请输入笔记')]
  84. }
  85. const props = defineProps({
  86. idsObj: {
  87. type: [Array, Object],
  88. required: () => {}
  89. }
  90. })
  91. const count = 3
  92. const emit = defineEmits({ videoStopTime: null, videoSpeed: null })
  93. const initLoading = ref(true)
  94. const loading = ref(false)
  95. const data = ref([])
  96. const listData = ref([])
  97. const itemNote = ref({})
  98. onMounted(() => {
  99. loading.value = false
  100. initLoading.value = false
  101. getList()
  102. })
  103. const pagination = ref({
  104. current: 1,
  105. onChange: (page) => {
  106. pagination.value.current = page
  107. getList()
  108. },
  109. pageSize: 10
  110. })
  111. //毫秒转 00:00:00
  112. const formatTime = (milliseconds) => {
  113. let totalSeconds = Math.floor(milliseconds / 1000)
  114. const hours = Math.floor(totalSeconds / 3600)
  115. totalSeconds %= 3600
  116. const minutes = Math.floor(totalSeconds / 60)
  117. const seconds = totalSeconds % 60
  118. return [hours, minutes, seconds].map((val) => val.toString().padStart(2, '0')).join(':')
  119. }
  120. const getList = () => {
  121. delete props.idsObj.parent
  122. classCentre
  123. .notesList(
  124. {
  125. current: pagination.value.current,
  126. size: pagination.value.pageSize,
  127. ...props.idsObj
  128. },
  129. itemNote.value.noteId
  130. )
  131. .then((data) => {
  132. data.records = data.records.map((r) => {
  133. return {
  134. ...r,
  135. loading: false,
  136. startTime: r.recordTime ?? 0,
  137. videoStopTime: formatTime(r.recordTime ?? 0)
  138. }
  139. })
  140. listData.value = data.records
  141. pagination.value.total = data.total
  142. loading.value = false
  143. initLoading.value = false
  144. })
  145. }
  146. const editNote = (e) => {
  147. formData.value.noteId = e.noteId
  148. formData.value.noteContent = e.noteContent
  149. itemNote.value.noteId = e.noteId
  150. visible.value = true
  151. }
  152. const delNote = (e) => {
  153. Modal.confirm({
  154. title: '确定要删除笔记',
  155. icon: createVNode(ExclamationCircleOutlined),
  156. onOk() {
  157. classCentre.notesEdit([{ noteId: e.noteId }]).then((data) => {
  158. getList()
  159. })
  160. },
  161. onCancel() {
  162. console.log('Cancel')
  163. }
  164. })
  165. }
  166. // 修改
  167. const handleOk = (e) => {
  168. formRef.value.validate().then(() => {
  169. classCentre
  170. .notesSubmitForm(
  171. {
  172. ...formData.value
  173. },
  174. formData.value.noteId
  175. )
  176. .then(() => {
  177. visible.value = false
  178. formData.value.noteId = ''
  179. formRef.value.resetFields()
  180. getList()
  181. })
  182. })
  183. }
  184. //视频暂停的时间
  185. const videoStopTime = ref(0)
  186. //添加
  187. const submitForm = (e) => {
  188. formRefAdd.value
  189. .validate()
  190. .then(() => {
  191. submitLoading.value = true
  192. emit('videoStopTime', (e) => {
  193. videoStopTime.value = e * 1000
  194. classCentre
  195. .notesSubmitForm({
  196. ...props.idsObj,
  197. ...formDataAdd.value,
  198. recordTime: videoStopTime.value
  199. })
  200. .then(() => {
  201. formRefAdd.value.resetFields()
  202. getList()
  203. })
  204. })
  205. })
  206. .finally(() => {
  207. submitLoading.value = false
  208. })
  209. }
  210. const videoSpeed = (e) => {
  211. emit('videoSpeed', e)
  212. }
  213. // 调用这个函数将子组件的一些数据和方法暴露出去
  214. defineExpose({
  215. getList
  216. })
  217. </script>
  218. <style scoped lang="less">
  219. .flc {
  220. display: flex;
  221. align-items: center;
  222. }
  223. .fcbc {
  224. display: flex;
  225. justify-content: space-between;
  226. align-items: center;
  227. }
  228. .frc {
  229. display: flex;
  230. justify-content: flex-end;
  231. align-items: center;
  232. }
  233. </style>