index.stub 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div>
  3. <el-card class="!border-none mb-4" shadow="never">
  4. <el-form
  5. class="mb-[-16px]"
  6. :model="queryParams"
  7. inline
  8. >
  9. {SEARCH_VIEW}
  10. <el-form-item>
  11. <el-button type="primary" @click="resetPage">查询</el-button>
  12. <el-button @click="resetParams">重置</el-button>
  13. </el-form-item>
  14. </el-form>
  15. </el-card>
  16. <el-card class="!border-none" v-loading="pager.loading" shadow="never">
  17. <el-button v-perms="['{PERMS_ADD}']" type="primary" @click="handleAdd">
  18. <template #icon>
  19. <icon name="el-icon-Plus" />
  20. </template>
  21. 新增
  22. </el-button>
  23. <el-button
  24. v-perms="['{PERMS_DELETE}']"
  25. :disabled="!selectData.length"
  26. @click="handleDelete(selectData)"
  27. >
  28. 删除
  29. </el-button>
  30. <div class="mt-4">
  31. <el-table :data="pager.lists" @selection-change="handleSelectionChange">
  32. <el-table-column type="selection" width="55" />
  33. {LISTS_VIEW}
  34. <el-table-column label="操作" width="120" fixed="right">
  35. <template #default="{ row }">
  36. <el-button
  37. v-perms="['{PERMS_EDIT}']"
  38. type="primary"
  39. link
  40. @click="handleEdit(row)"
  41. >
  42. 编辑
  43. </el-button>
  44. <el-button
  45. v-perms="['{PERMS_DELETE}']"
  46. type="danger"
  47. link
  48. @click="handleDelete(row.{PK})"
  49. >
  50. 删除
  51. </el-button>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. </div>
  56. <div class="flex mt-4 justify-end">
  57. <pagination v-model="pager" @change="getLists" />
  58. </div>
  59. </el-card>
  60. <edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
  61. </div>
  62. </template>
  63. <script lang="ts" setup name="{SETUP_NAME}Lists">
  64. import { usePaging } from '@/hooks/usePaging'
  65. import { useDictData } from '@/hooks/useDictOptions'
  66. import { api{UPPER_CAMEL_NAME}Lists, api{UPPER_CAMEL_NAME}Delete } from '@/api/{API_DIR}'
  67. import { timeFormat } from '@/utils/util'
  68. import feedback from '@/utils/feedback'
  69. import EditPopup from './edit.vue'
  70. const editRef = shallowRef<InstanceType<typeof EditPopup>>()
  71. // 是否显示编辑框
  72. const showEdit = ref(false)
  73. // 查询条件
  74. const queryParams = reactive({
  75. {QUERY_PARAMS}
  76. })
  77. // 选中数据
  78. const selectData = ref<any[]>([])
  79. // 表格选择后回调事件
  80. const handleSelectionChange = (val: any[]) => {
  81. selectData.value = val.map(({ {PK} }) => {PK})
  82. }
  83. // 获取字典数据
  84. const { dictData } = useDictData('{DICT_DATA}')
  85. // 分页相关
  86. const { pager, getLists, resetParams, resetPage } = usePaging({
  87. fetchFun: api{UPPER_CAMEL_NAME}Lists,
  88. params: queryParams
  89. })
  90. // 添加
  91. const handleAdd = async () => {
  92. showEdit.value = true
  93. await nextTick()
  94. editRef.value?.open('add')
  95. }
  96. // 编辑
  97. const handleEdit = async (data: any) => {
  98. showEdit.value = true
  99. await nextTick()
  100. editRef.value?.open('edit')
  101. editRef.value?.setFormData(data)
  102. }
  103. // 删除
  104. const handleDelete = async ({PK}: number | any[]) => {
  105. await feedback.confirm('确定要删除?')
  106. await api{UPPER_CAMEL_NAME}Delete({ {PK} })
  107. getLists()
  108. }
  109. getLists()
  110. </script>