index.hbs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <div class="{{ dashCase name }}-container auto-height-container">
  3. <vab-query-form>
  4. <vab-query-form-top-panel>
  5. <el-form inline :model="queryForm" @submit.prevent>
  6. <el-form-item label="标题">
  7. <el-input v-model="queryForm.title" clearable placeholder="请输入标题" />
  8. </el-form-item>
  9. <el-form-item v-show="!fold" label="标题">
  10. <el-input v-model="queryForm.title" clearable placeholder="请输入标题" />
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button :icon="Search" :loading="listLoading" native-type="submit" type="primary" @click="queryData">查询</el-button>
  14. <el-button class="hidden-xs-only" text type="primary" @click="handleFold">
  15. <span v-if="fold">展开</span>
  16. <span v-else>合并</span>
  17. <vab-icon class="vab-dropdown" :class="{ 'vab-dropdown-active': fold }" icon="arrow-up-s-line" />
  18. </el-button>
  19. </el-form-item>
  20. </el-form>
  21. </vab-query-form-top-panel>
  22. <vab-query-form-left-panel :span="24">
  23. <el-button :icon="Plus" type="primary" @click="handleAdd">添加</el-button>
  24. <el-button :icon="Delete" type="danger" @click="handleDelete">删除</el-button>
  25. </vab-query-form-left-panel>
  26. </vab-query-form>
  27. <el-table ref="tableRef" v-loading="listLoading" border :data="list" @selection-change="setSelectRows">
  28. <el-table-column type="selection" width="38" />
  29. <el-table-column align="center" label="标题" prop="title" />
  30. <el-table-column align="center" label="作者" prop="author" />
  31. <el-table-column align="center" label="操作" width="150">
  32. <template #default="{ row }">
  33. <el-button text type="primary" @click="handleEdit(row)">编辑</el-button>
  34. <el-button text type="danger" @click="handleDelete(row)">删除</el-button>
  35. </template>
  36. </el-table-column>
  37. <template #empty>
  38. <el-empty class="vab-data-empty" description="暂无数据" />
  39. </template>
  40. </el-table>
  41. <vab-pagination
  42. :current-page="queryForm.pageNo"
  43. :page-size="queryForm.pageSize"
  44. :total="total"
  45. @current-change="handleCurrentChange"
  46. @size-change="handleSizeChange"
  47. />
  48. <{{ dashCase name }}-edit ref="editRef" @fetch-data="fetchData" />
  49. </div>
  50. </template>
  51. <script lang="ts" setup>
  52. import { Delete, Plus, Search } from '@element-plus/icons-vue'
  53. import type { TableInstance } from 'element-plus'
  54. import { doDelete, getList } from '/@/api/{{ camelCase name }}'
  55. defineOptions({
  56. name: '{{ properCase name }}',
  57. })
  58. const editRef = ref<any>(null)
  59. const tableRef = ref<TableInstance>()
  60. const fold = ref<boolean>(true)
  61. const list = ref<any>([])
  62. const listLoading = ref<boolean>(true)
  63. const total = ref<number>(0)
  64. const selectRows = ref<any>([])
  65. const queryForm = reactive<any>({
  66. pageNo: 1,
  67. pageSize: 20,
  68. })
  69. const fetchData = async () => {
  70. listLoading.value = true
  71. const { data } = await getList(queryForm)
  72. list.value = data.list
  73. total.value = data.total
  74. listLoading.value = false
  75. }
  76. const handleSizeChange = (value: number) => {
  77. queryForm.pageNo = 1
  78. queryForm.pageSize = value
  79. fetchData()
  80. }
  81. const handleCurrentChange = (value: number) => {
  82. queryForm.pageNo = value
  83. fetchData()
  84. }
  85. const queryData = () => {
  86. queryForm.pageNo = 1
  87. fetchData()
  88. }
  89. const handleFold = () => {
  90. fold.value = !fold.value
  91. }
  92. const setSelectRows = (value: string) => {
  93. selectRows.value = value
  94. }
  95. const handleAdd = () => {
  96. editRef.value.showEdit()
  97. }
  98. const handleEdit = (row = {}) => {
  99. editRef.value.showEdit(row)
  100. }
  101. const handleDelete = (row: any) => {
  102. if (row.id) {
  103. $baseConfirm('您确定要删除当前项吗', null, async () => {
  104. const { msg }: any = await doDelete({ ids: row.id })
  105. $baseMessage(msg, 'success', 'hey')
  106. await fetchData()
  107. })
  108. } else {
  109. if (selectRows.value.length > 0) {
  110. const ids = selectRows.value.map((item: { id: any }) => item.id).join()
  111. $baseConfirm('您确定要删除选中项吗', null, async () => {
  112. const { msg }: any = await doDelete({ ids: ids })
  113. $baseMessage(msg, 'success', 'hey')
  114. await fetchData()
  115. })
  116. } else {
  117. $baseMessage('您未选中任何行', 'warning', 'hey')
  118. }
  119. }
  120. }
  121. onActivated(() => {
  122. tableRef.value?.doLayout()
  123. })
  124. onBeforeMount(() => {
  125. fetchData()
  126. })
  127. </script>