ListView.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <a-table
  3. ref="table"
  4. :columns="columns"
  5. :data-source="dataSources"
  6. :row-key="(record) => record.courseId"
  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="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 dataSources = 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: '15%'
  55. },
  56. {
  57. title: '状态',
  58. dataIndex: 'putawayStatusName',
  59. sorter: true,
  60. width: '10%'
  61. },
  62. {
  63. title: '院系类型',
  64. dataIndex: 'collegeAllIdName',
  65. sorter: true,
  66. width: '25%'
  67. },
  68. {
  69. title: '课程类型',
  70. dataIndex: 'courseTypeName',
  71. sorter: true,
  72. width: '8%'
  73. },
  74. {
  75. title: '课时数量',
  76. dataIndex: 'hourCount',
  77. sorter: true,
  78. width: '7%'
  79. },
  80. {
  81. title: '发布时间',
  82. dataIndex: 'publishTime',
  83. sorter: true,
  84. width: '12%'
  85. },
  86. {
  87. title: '操作',
  88. dataIndex: 'action',
  89. sorter: true,
  90. width: '20%'
  91. }
  92. ]
  93. // tool.formatTimestamp()
  94. const formatTimestamp = (time) => {
  95. return tool.formatTimestamp(time)
  96. }
  97. const total = ref(0)
  98. const pagination = ref({
  99. size: 10,
  100. current: 1,
  101. })
  102. const onChangeCurrent = (current) => {
  103. router.push({
  104. path: '/' + current
  105. })
  106. }
  107. const handlerChange = (page, pageSize) => {
  108. console.log('分页参数', page, pageSize)
  109. // pagination.value.size = pageSize
  110. // pagination.value.current = page
  111. getList()
  112. }
  113. const handleDetail = (record) => {
  114. console.log('查看详情', record)
  115. router.push({
  116. path: '/portal/courseDetails',
  117. query: {
  118. id: record.courseId
  119. }
  120. })
  121. // 在这里添加查看详情的逻辑
  122. }
  123. // 编辑按钮点击事件
  124. const handleEdit = (record) => {
  125. console.log('编辑记录', record)
  126. // 在这里添加编辑记录的逻辑
  127. emit('handleEdit', record)
  128. }
  129. // 上架按钮点击事件
  130. const handleShelf = (record) => {
  131. console.log('上架记录', record)
  132. // 在这里添加上架记录的逻辑
  133. }
  134. // 删除按钮点击事件
  135. const handleDelete = (record) => {
  136. console.log('删除记录', record)
  137. // 在这里添加删除记录的逻辑
  138. }
  139. const getList = () => {
  140. console.log('获取列表 getList')
  141. list({...pagination.value}).then((data) => {
  142. if (data.code == 200) {
  143. console.log('获取列表 新数组', data.data.records)
  144. dataSources.value = []
  145. dataSources.value = data.data.records
  146. console.log('获取列表 最新数组', dataSources.value)
  147. pagination.value.current = data.data.current
  148. pagination.value.size = data.data.size
  149. total.value = data.data.total
  150. }
  151. // data.records
  152. })
  153. }
  154. const setList = (search) => {
  155. console.log('获取列表 setList',search)
  156. // courseName: '',
  157. // collegeId: '',
  158. // majorId: '',
  159. // courseType: '',
  160. // loacl: []
  161. formState.value = search
  162. pagination.value.current = 1
  163. list({...pagination.value, ...formState.value}).then((data) => {
  164. if (data.code == 200) {
  165. dataSources.value = data.data.records
  166. pagination.value.current = data.data.current
  167. pagination.value.size = data.data.size
  168. total.value = data.data.total
  169. }
  170. // data.records
  171. })
  172. }
  173. // 重置按钮点击事件
  174. onMounted(() => {
  175. // getListData()
  176. getList()
  177. })
  178. // watch(
  179. // () => dataSources.value,
  180. // (newVal, oldVal) => {
  181. // console.log('数据源变化了 ', ' 新的 ',newVal, ' 旧的 ',oldVal)
  182. // },
  183. // { deep: true, immediate: true }
  184. // )
  185. defineExpose({
  186. setList
  187. })
  188. </script>
  189. <style scoped>
  190. .desc p {
  191. margin-bottom: 1em;
  192. }
  193. </style>