ListView.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <a-table
  3. ref="table"
  4. :columns="columns"
  5. :data-source="dataSource"
  6. :row-key="(record) => record.collegeId"
  7. bordered
  8. :expand-row-by-click="true"
  9. :pagination="false"
  10. size="small"
  11. >
  12. <template #bodyCell="{ column, text, record }">
  13. <template v-if="column.dataIndex === 'publishTime'">{{ formatTimestamp(text) }}</template>
  14. <template v-if="column.dataIndex === 'action'">
  15. <a-button size="small" @click="handleDetail(record)" style="margin-right: 5px">详情</a-button>
  16. <a-button size="small" @click="handleEdit(record)" style="margin-right: 5px">编辑</a-button>
  17. <a-button size="small" @click="handleShelf(record)" style="margin-right: 5px">上架</a-button>
  18. <a-button size="small" @click="handleDelete(record)" style="margin-right: 5px">删除</a-button>
  19. </template>
  20. </template>
  21. </a-table>
  22. <div style="display: flex; width: 100%; justify-content: flex-end; margin-top: 10px">
  23. <a-pagination
  24. v-model:current="pagination.current"
  25. v-model:pageSize="pagination.size"
  26. :total="pagination.total"
  27. show-less-items
  28. @change="handlerChange"
  29. />
  30. </div>
  31. </template>
  32. <script setup>
  33. import tool from '@/utils/tool'
  34. import { ref, onMounted } from 'vue'
  35. import { EyeOutlined, EditOutlined, SnippetsOutlined, DeleteOutlined } from '@ant-design/icons-vue'
  36. import { list } from '@/api/courseinfo'
  37. import { useRouter } from 'vue-router'
  38. import collegeApi from '@/api/college'
  39. const router = useRouter()
  40. const emit = defineEmits(['handleEdit'])
  41. //发布按钮状态
  42. const releaseVisible = ref(false)
  43. const loading = ref(false) // 列表loading
  44. const dataSource = ref([])
  45. const formState = ref({
  46. name: '',
  47. loacl: ''
  48. }) // 列表loading
  49. const columns = [
  50. {
  51. title: '课程名称',
  52. dataIndex: 'courseName',
  53. sorter: true,
  54. width: '20%'
  55. },
  56. {
  57. title: '状态',
  58. dataIndex: 'courseType',
  59. sorter: true,
  60. width: '10%'
  61. },
  62. {
  63. title: '课程类型',
  64. dataIndex: 'isCreaterName',
  65. sorter: true,
  66. width: '20%'
  67. },
  68. {
  69. title: '课时数量',
  70. dataIndex: 'majorId',
  71. sorter: true,
  72. width: '10%'
  73. },
  74. {
  75. title: '更新时间',
  76. dataIndex: 'publishTime',
  77. sorter: true,
  78. width: '20%'
  79. },
  80. {
  81. title: '操作',
  82. dataIndex: 'action',
  83. sorter: true,
  84. width: '20%'
  85. }
  86. ]
  87. // tool.formatTimestamp()
  88. const formatTimestamp = (time) => {
  89. return tool.formatTimestamp(time)
  90. }
  91. const pagination = reactive({
  92. size: 10,
  93. current: 1,
  94. total: 0
  95. })
  96. const onChangeCurrent = (current) => {
  97. router.push({
  98. path: '/' + current
  99. })
  100. }
  101. const handlerChange = (page, pageSize) => {
  102. pagination.size = pageSize
  103. pagination.current = page
  104. getList()
  105. }
  106. const publishedData = ref()
  107. //发布确定
  108. // 上传资源模态框
  109. const uploadModalVisible = ref(false)
  110. // 详情按钮点击事件
  111. const handleDetail = (record) => {
  112. console.log('查看详情', record)
  113. router.push({
  114. path: '/portal/courseDetails',
  115. query: {
  116. id: record.courseId
  117. }
  118. })
  119. // 在这里添加查看详情的逻辑
  120. }
  121. // 编辑按钮点击事件
  122. const handleEdit = (record) => {
  123. console.log('编辑记录', record)
  124. // 在这里添加编辑记录的逻辑
  125. emit('handleEdit', record)
  126. }
  127. // 上架按钮点击事件
  128. const handleShelf = (record) => {
  129. console.log('上架记录', record)
  130. // 在这里添加上架记录的逻辑
  131. }
  132. // 删除按钮点击事件
  133. const handleDelete = (record) => {
  134. console.log('删除记录', record)
  135. // 在这里添加删除记录的逻辑
  136. }
  137. const getList = () => {
  138. console.log('获取列表', list)
  139. list({ ...pagination }).then((data) => {
  140. if (data.code == 200) {
  141. dataSource.value = data.data.records
  142. pagination.current = data.data.current
  143. pagination.size = data.data.size
  144. pagination.total = data.data.total
  145. }
  146. // data.records
  147. })
  148. }
  149. const setList = (search) => {
  150. console.log('获取列表', list)
  151. formState.value = search
  152. pagination.current = 1
  153. list({ ...pagination, ...search }).then((data) => {
  154. if (data.code == 200) {
  155. dataSource.value = data.data.records
  156. pagination.current = data.data.current
  157. pagination.size = data.data.size
  158. pagination.total = data.data.total
  159. }
  160. // data.records
  161. })
  162. }
  163. // 重置按钮点击事件
  164. onMounted(() => {
  165. // getListData()
  166. getList()
  167. })
  168. defineExpose({
  169. setList
  170. })
  171. </script>
  172. <style scoped>
  173. .desc p {
  174. margin-bottom: 1em;
  175. }
  176. </style>