note.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. <a-textarea v-model:value="formDataAdd.noteContent" placeholder="请输入笔记" :rows="4" />
  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>{{ item.courseName }}</template>
  28. <template #avatar v-if="item.avatar">
  29. <a-avatar :src="item.avatar" />
  30. </template>
  31. </a-list-item-meta>
  32. {{ item.noteContent }}
  33. <div class="flc">
  34. <div @click="editNote(item)">
  35. <a-tooltip title="编辑" :getPopupContainer="(trigger) => trigger.parentElement">
  36. <edit-outlined />
  37. </a-tooltip>
  38. </div>
  39. <div class="ml-2" @click="delNote(item)">
  40. <a-tooltip title="删除" :getPopupContainer="(trigger) => trigger.parentElement">
  41. <delete-outlined />
  42. </a-tooltip>
  43. </div>
  44. </div>
  45. </div>
  46. </a-skeleton>
  47. </a-list-item>
  48. </template>
  49. </a-list>
  50. <a-modal v-model:visible="visible" title="编辑" @ok="handleOk" append-to-body>
  51. <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
  52. <a-row :gutter="16">
  53. <a-col :span="24">
  54. <a-form-item name="noteContent" label="问题">
  55. <a-textarea v-model:value="formData.noteContent" placeholder="请输入问题" :rows="4" />
  56. </a-form-item>
  57. </a-col>
  58. </a-row>
  59. </a-form>
  60. </a-modal>
  61. </template>
  62. <script setup>
  63. import classCentre from '@/api/student/classCentre'
  64. import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
  65. import { createVNode } from 'vue'
  66. import { Modal } from 'ant-design-vue'
  67. import { required } from '@/utils/formRules'
  68. // 表单数据,也就是默认给一些数据
  69. const visible = ref(false)
  70. const formData = ref({})
  71. const formRef = ref()
  72. const formDataAdd = ref({})
  73. const formRefAdd = ref()
  74. const submitLoading = ref(false)
  75. // 默认要校验的
  76. const formRules = {
  77. noteContent: [required('请输入笔记')]
  78. }
  79. const props = defineProps({
  80. idsObj: {
  81. type: [Array, Object],
  82. required: () => {}
  83. }
  84. })
  85. const count = 3
  86. const emit = defineEmits({ edit: null })
  87. const initLoading = ref(true)
  88. const loading = ref(false)
  89. const data = ref([])
  90. const listData = ref([])
  91. const itemNote = ref({})
  92. onMounted(() => {
  93. loading.value = false
  94. initLoading.value = false
  95. getList()
  96. })
  97. const pagination = ref({
  98. current: 1,
  99. onChange: (page) => {
  100. pagination.value.current = page
  101. getList()
  102. },
  103. pageSize: 10
  104. })
  105. const getList = () => {
  106. delete props.idsObj.parent
  107. classCentre
  108. .notesList(
  109. {
  110. current: pagination.value.current,
  111. size: pagination.value.pageSize,
  112. ...props.idsObj
  113. },
  114. itemNote.value.noteId
  115. )
  116. .then((data) => {
  117. data.records = data.records.map((r) => {
  118. return {
  119. ...r,
  120. loading: false
  121. }
  122. })
  123. listData.value = data.records
  124. pagination.value.total = data.total
  125. loading.value = false
  126. initLoading.value = false
  127. })
  128. }
  129. const editNote = (e) => {
  130. formData.value.noteId = e.noteId
  131. formData.value.noteContent = e.noteContent
  132. itemNote.value.noteId = e.noteId
  133. visible.value = true
  134. }
  135. const delNote = (e) => {
  136. Modal.confirm({
  137. title: '确定要删除笔记',
  138. icon: createVNode(ExclamationCircleOutlined),
  139. onOk() {
  140. classCentre.notesEdit([{ noteId: e.noteId }]).then((data) => {
  141. getList()
  142. })
  143. },
  144. onCancel() {
  145. console.log('Cancel')
  146. }
  147. })
  148. }
  149. // 修改
  150. const handleOk = (e) => {
  151. formRef.value.validate().then(() => {
  152. classCentre
  153. .notesSubmitForm(
  154. {
  155. ...formData.value
  156. },
  157. formData.value.noteId
  158. )
  159. .then(() => {
  160. visible.value = false
  161. formData.value.noteId = ''
  162. formRef.value.resetFields()
  163. getList()
  164. })
  165. })
  166. }
  167. //添加
  168. const submitForm = (e) => {
  169. formRefAdd.value
  170. .validate()
  171. .then(() => {
  172. submitLoading.value = true
  173. classCentre
  174. .notesSubmitForm({
  175. ...props.idsObj,
  176. ...formDataAdd.value
  177. })
  178. .then(() => {
  179. formRefAdd.value.resetFields()
  180. getList()
  181. })
  182. })
  183. .finally(() => {
  184. submitLoading.value = false
  185. })
  186. }
  187. // 调用这个函数将子组件的一些数据和方法暴露出去
  188. defineExpose({
  189. getList
  190. })
  191. </script>
  192. <style scoped lang="less">
  193. .flc {
  194. display: flex;
  195. align-items: center;
  196. }
  197. .fcbc {
  198. display: flex;
  199. justify-content: space-between;
  200. align-items: center;
  201. }
  202. .frc {
  203. display: flex;
  204. justify-content: flex-end;
  205. align-items: center;
  206. }
  207. </style>