ArtList.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <route lang="yaml">
  2. meta:
  3. enabled: false
  4. </route>
  5. <script lang="ts" setup>
  6. import { ElMessage, ElMessageBox } from 'element-plus'
  7. import { deleteArtById, getArtByPage } from '@/api/system/artApi'
  8. import useSettingsStore from '@/store/modules/settings'
  9. const settingsStore = useSettingsStore()
  10. const router = useRouter()
  11. const tabbar = useTabbar()
  12. const state = reactive({
  13. loading: false,
  14. dataList: [],
  15. search: {
  16. artCatId: -1,
  17. keywords: '',
  18. },
  19. })
  20. // 获取数据
  21. const getData = async () => {
  22. if (state.search.artCatId > 0) {
  23. state.loading = true
  24. const { data } = await getArtByPage(state.search)
  25. state.loading = false
  26. state.dataList = data
  27. state.loading = false
  28. }
  29. }
  30. const artTableRef = ref()
  31. // 查询
  32. const onSearch = () => {
  33. getData()
  34. }
  35. // 新增
  36. const onArtAdd = () => {
  37. if (settingsStore.settings.tabbar.enable && settingsStore.settings.tabbar.mergeTabsBy !== 'activeMenu') {
  38. tabbar.open({
  39. name: 'article_add',
  40. params: {
  41. artCatId: state.search.artCatId,
  42. },
  43. })
  44. }
  45. else {
  46. router.push({
  47. name: 'article_add',
  48. params: {
  49. artCatId: state.search.artCatId,
  50. },
  51. })
  52. }
  53. }
  54. // 编辑对象
  55. const onArtEdit = (row: { artId: number }) => {
  56. if (settingsStore.settings.tabbar.enable && settingsStore.settings.tabbar.mergeTabsBy !== 'activeMenu') {
  57. tabbar.open({
  58. name: 'article_edit',
  59. params: {
  60. artId: row.artId,
  61. },
  62. })
  63. }
  64. else {
  65. router.push({
  66. name: 'article_edit',
  67. params: {
  68. artId: row.artId,
  69. },
  70. })
  71. }
  72. }
  73. const onArtView = (row: { art: number }) => {}
  74. // 删除
  75. const onArtDelete = (row: any) => {
  76. const { artId, artTitle } = row
  77. ElMessageBox.confirm(`确认删除「${artTitle}」吗?`, '确认信息').then(async () => {
  78. const { msg } = await deleteArtById(artId)
  79. ElMessage.success(msg)
  80. await getData()
  81. })
  82. }
  83. defineExpose({
  84. loadData(artCatId: number) {
  85. state.search.artCatId = artCatId
  86. getData()
  87. },
  88. })
  89. </script>
  90. <template>
  91. <div class="container">
  92. <tool-bar>
  93. <template #left>
  94. <span />
  95. </template>
  96. <template #right>
  97. <el-input v-model="state.search.keywords" placeholder="请输入名称,支持模糊查询" style="padding-right: 10px;" clearable />
  98. <el-button type="primary" @click="onSearch">
  99. <template #icon>
  100. <el-icon>
  101. <svg-icon name="i-ep:search" />
  102. </el-icon>
  103. </template>
  104. </el-button>
  105. <el-button type="primary" @click="onArtAdd">
  106. <template #icon>
  107. <el-icon>
  108. <svg-icon name="i-ep:plus" />
  109. </el-icon>
  110. </template>
  111. 发布文章
  112. </el-button>
  113. </template>
  114. </tool-bar>
  115. <el-table ref="artTableRef" v-loading="state.loading" class="list-table" size="small" :data="state.dataList" border stripe highlight-current-row>
  116. <el-table-column type="selection" width="50" align="center" />
  117. <el-table-column type="index" align="center" label="序号" width="70" />
  118. <el-table-column prop="artTitle" width="250px" label="标题" align="center" header-align="center">
  119. <template #default="scope">
  120. <span>{{ scope.row.artTitle }}</span>
  121. </template>
  122. </el-table-column>
  123. <el-table-column prop="artCatTitle" width="150px" label="分类" align="center" header-align="center">
  124. <template #default="scope">
  125. <span>{{ scope.row.artCatTitle }}</span>
  126. </template>
  127. </el-table-column>
  128. <el-table-column prop="editorName" width="150px" label="发布人" align="center" header-align="center">
  129. <template #default="scope">
  130. <span>{{ scope.row.editorName }}</span>
  131. </template>
  132. </el-table-column>
  133. <el-table-column prop="issuedAt" label="发布时间" align="left" header-align="center">
  134. <template #default="scope">
  135. <span>{{ scope.row.issuedAt }}</span>
  136. </template>
  137. </el-table-column>
  138. <el-table-column label="操作" width="200" align="center" fixed="right">
  139. <template #default="scope">
  140. <div>
  141. <el-button type="primary" size="small" plain @click="onArtView(scope.row)">
  142. 查看
  143. </el-button>
  144. <el-button type="primary" size="small" plain @click="onArtEdit(scope.row)">
  145. 编辑
  146. </el-button>
  147. <el-button v-if="!scope.row.isFixed" type="danger" size="small" plain @click="onArtDelete(scope.row)">
  148. 删除
  149. </el-button>
  150. </div>
  151. </template>
  152. </el-table-column>
  153. </el-table>
  154. </div>
  155. </template>