ListView.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 === 'content'">
  14. <a-popover title="详细内容" trigger="hover">
  15. <template #content>
  16. {{ text }}
  17. </template>
  18. <template v-if="text.length > 10">
  19. <span>{{ text.slice(0, 10) }}...</span>
  20. </template>
  21. </a-popover>
  22. <template v-if="text.length <= 10">
  23. <span>{{ text }}</span>
  24. </template>
  25. </template>
  26. <template v-if="column.dataIndex === 'action'">
  27. <a-button size="small" @click="handleDetail(record)" style="margin-right: 5px">详情</a-button>
  28. <a-button size="small" @click="handleEdit(record)" style="margin-right: 5px">编辑</a-button>
  29. <a-popover v-model:visible="popoverVisibles[record.collegeId]" title="确定删除?" trigger="click">
  30. <template #content>
  31. <a-button style="margin-right: 10px" type="primary" @click="handleShelf(record, 1)">确定 </a-button>
  32. <a-button
  33. @click="
  34. () => {
  35. popoverVisibles[record.collegeId] = false
  36. }
  37. "
  38. >取消</a-button
  39. >
  40. </template>
  41. <!-- <a-button size="small" style="margin-right: 5px">选择</a-button>-->
  42. <a-button size="small" @click="handleDelete(record)" style="margin-right: 5px">删除</a-button>
  43. </a-popover>
  44. </template>
  45. </template>
  46. </a-table>
  47. <div style="display: flex; width: 100%; justify-content: flex-end; margin-top: 10px">
  48. <a-pagination
  49. v-model:current="pagination.current"
  50. v-model:pageSize="pagination.size"
  51. :total="total"
  52. show-less-items
  53. @change="handlerChange"
  54. />
  55. </div>
  56. </template>
  57. <script setup>
  58. import tool from '@/utils/tool'
  59. import { ref, onMounted } from 'vue'
  60. import { EyeOutlined, EditOutlined, SnippetsOutlined, DeleteOutlined } from '@ant-design/icons-vue'
  61. import { list } from '@/api/notice'
  62. import { useRouter } from 'vue-router'
  63. import collegeApi from '@/api/college'
  64. import { updateCourseStatus } from '@/api/course/courseDetail'
  65. const router = useRouter()
  66. const emit = defineEmits(['handleEdit'])
  67. //发布按钮状态
  68. const releaseVisible = ref(false)
  69. const loading = ref(false) // 列表loading
  70. const dataSources = ref([])
  71. const popoverVisible = ref({})
  72. const popoverVisibles = ref({})
  73. const formState = ref({
  74. name: '',
  75. loacl: ''
  76. }) // 列表loading
  77. const columns = [
  78. {
  79. title: '公告标题',
  80. dataIndex: 'title',
  81. sorter: true,
  82. width: '15%'
  83. },
  84. {
  85. title: '内容',
  86. dataIndex: 'content',
  87. sorter: true,
  88. width: '15%'
  89. },
  90. {
  91. title: '发布时间',
  92. dataIndex: 'createTime',
  93. sorter: true,
  94. width: '12%'
  95. },
  96. {
  97. title: '操作',
  98. dataIndex: 'action',
  99. sorter: true,
  100. width: '10%'
  101. }
  102. ]
  103. // tool.formatTimestamp()
  104. const formatTimestamp = (time) => {
  105. return tool.formatTimestamp(time)
  106. }
  107. const total = ref(0)
  108. const pagination = ref({
  109. size: 10,
  110. current: 1
  111. })
  112. const onChangeCurrent = (current) => {
  113. router.push({
  114. path: '/' + current
  115. })
  116. }
  117. const handlerChange = (page, pageSize) => {
  118. console.log('分页参数', page, pageSize)
  119. // pagination.value.size = pageSize
  120. // pagination.value.current = page
  121. getList()
  122. }
  123. const handleDetail = (record) => {
  124. console.log('查看详情', record)
  125. router.push({
  126. path: '/portal/courseDetails',
  127. query: {
  128. id: record.courseId
  129. }
  130. })
  131. // 在这里添加查看详情的逻辑
  132. }
  133. // 编辑按钮点击事件
  134. const handleEdit = (record) => {
  135. console.log('编辑记录', record)
  136. // 在这里添加编辑记录的逻辑
  137. emit('handleEdit', record)
  138. }
  139. // 上架按钮点击事件
  140. const handleShelf = (record, num) => {
  141. console.log('上架记录', record)
  142. popoverVisible.value[record.collegeId] = false
  143. // 在这里添加上架记录的逻辑
  144. // {
  145. // "courseId": "1948183431150227458",
  146. // "putawayStatus": 1
  147. // }
  148. // updateCourseStatus({courseId : record.courseId,putawayStatus : num}).then((res)=>{
  149. // getList()
  150. // })
  151. }
  152. // 删除按钮点击事件
  153. const handleDelete = (record) => {
  154. console.log('删除记录', record)
  155. // 在这里添加删除记录的逻辑
  156. }
  157. const getList = () => {
  158. list({ ...pagination.value }).then((data) => {
  159. if (data.code == 200) {
  160. dataSources.value = []
  161. dataSources.value = data.data.records
  162. pagination.value.current = data.data.current
  163. pagination.value.size = data.data.size
  164. total.value = data.data.total
  165. }
  166. // data.records
  167. })
  168. }
  169. const setList = (search) => {
  170. console.log('获取列表 setList', search)
  171. // courseName: '',
  172. // collegeId: '',
  173. // majorId: '',
  174. // courseType: '',
  175. // loacl: []
  176. formState.value = search
  177. pagination.value.current = 1
  178. list({ ...pagination.value, ...formState.value }).then((data) => {
  179. if (data.code == 200) {
  180. dataSources.value = data.data.records
  181. pagination.value.current = data.data.current
  182. pagination.value.size = data.data.size
  183. total.value = data.data.total
  184. }
  185. // data.records
  186. })
  187. }
  188. // 重置按钮点击事件
  189. onMounted(() => {
  190. // getListData()
  191. getList()
  192. })
  193. // watch(
  194. // () => dataSources.value,
  195. // (newVal, oldVal) => {
  196. // console.log('数据源变化了 ', ' 新的 ',newVal, ' 旧的 ',oldVal)
  197. // },
  198. // { deep: true, immediate: true }
  199. // )
  200. defineExpose({
  201. setList,
  202. getList
  203. })
  204. </script>
  205. <style scoped>
  206. .desc p {
  207. margin-bottom: 1em;
  208. }
  209. </style>