view_page.hbs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <script lang="ts">
  2. export default { name: '{{pascalCase name}}List' };
  3. </script>
  4. <script setup lang="ts">
  5. import { computed, onMounted, ref } from 'vue';
  6. import { ElMessage } from 'element-plus';
  7. import { Plus, Delete } from '@element-plus/icons-vue';
  8. import { useI18n } from 'vue-i18n';
  9. import { perm } from '@/store/useCurrentUser';
  10. import { pageSizes, pageLayout, toParams, resetParams } from '@/utils/common';
  11. import { delete{{pascalCase name}}, query{{pascalCase name}}Page } from '@/api/{{kebabCase path}}';
  12. import { ColumnList, ColumnSetting } from '@/components/TableList';
  13. import { QueryForm, QueryItem } from '@/components/QueryForm';
  14. import {{pascalCase name}}Form from './{{pascalCase name}}Form.vue';
  15. const { t } = useI18n();
  16. const params = ref<Record<string, any>>({});
  17. const sort = ref();
  18. const currentPage = ref<number>(1);
  19. const pageSize = ref<number>(10);
  20. const total = ref<number>(0);
  21. const table = ref();
  22. const data = ref<any[]>([]);
  23. const selection = ref<any[]>([]);
  24. const loading = ref<boolean>(false);
  25. const formVisible = ref<boolean>(false);
  26. const beanId = ref<number>();
  27. const beanIds = computed(() => data.value.map((row) => row.id));
  28. const fetchData = async () => {
  29. loading.value = true;
  30. try {
  31. const { content, totalElements } = await query{{pascalCase name}}Page({ ...toParams(params.value), Q_OrderBy: sort.value, page: currentPage.value, pageSize: pageSize.value });
  32. data.value = content;
  33. total.value = totalElements;
  34. } finally {
  35. loading.value = false;
  36. }
  37. };
  38. onMounted(fetchData);
  39. const handleSort = ({ column, prop, order }: { column: any; prop: string; order: string }) => {
  40. if (prop) {
  41. sort.value = (column.sortBy ?? prop) + (order === 'descending' ? '_desc' : '');
  42. } else {
  43. sort.value = undefined;
  44. }
  45. fetchData();
  46. };
  47. const handleSearch = () => fetchData();
  48. const handleReset = () => {
  49. table.value.clearSort();
  50. resetParams(params.value);
  51. sort.value = undefined;
  52. fetchData();
  53. };
  54. const handleAdd = () => {
  55. beanId.value = undefined;
  56. formVisible.value = true;
  57. };
  58. const handleEdit = (id: number) => {
  59. beanId.value = id;
  60. formVisible.value = true;
  61. };
  62. const handleDelete = async (ids: number[]) => {
  63. await delete{{pascalCase name}}(ids);
  64. fetchData();
  65. ElMessage.success(t('success'));
  66. };
  67. </script>
  68. <template>
  69. <div>
  70. <div class="mb-3">
  71. <query-form :params="params" @search="handleSearch" @reset="() => handleReset()">
  72. <query-item :label="$t('{{camelCase name}}.name')" name="Q_Contains_name"></query-item>
  73. </query-form>
  74. </div>
  75. <div>
  76. <el-button type="primary" :disabled="perm('{{camelCase name}}:create')" :icon="Plus" @click="() => handleAdd()">\{{ $t('add') }}</el-button>
  77. <el-popconfirm :title="$t('confirmDelete')" @confirm="() => handleDelete(selection.map((row) => row.id))">
  78. <template #reference>
  79. <el-button :disabled="selection.length <= 0 || perm('{{camelCase name}}:delete')" :icon="Delete">\{{ $t('delete') }}</el-button>
  80. </template>
  81. </el-popconfirm>
  82. <column-setting name="{{camelCase name}}" class="ml-2" />
  83. </div>
  84. <div class="app-block mt-3">
  85. <el-table
  86. ref="table"
  87. v-loading="loading"
  88. :data="data"
  89. @selection-change="(rows) => (selection = rows)"
  90. @row-dblclick="(row) => handleEdit(row.id)"
  91. @sort-change="handleSort"
  92. >
  93. <column-list name="{{camelCase name}}">
  94. <el-table-column type="selection" width="45"></el-table-column>
  95. <el-table-column property="id" label="ID" width="64" sortable="custom"></el-table-column>
  96. <el-table-column property="name" :label="$t('{{camelCase name}}.name')" sortable="custom" show-overflow-tooltip></el-table-column>
  97. <el-table-column :label="$t('table.action')">
  98. <template #default="{row}">
  99. <el-button type="primary" :disabled="perm('{{camelCase name}}:update')" @click="() => handleEdit(row.id)" size="small" link>\{{ $t('edit') }}</el-button>
  100. <el-popconfirm :title="$t('confirmDelete')" @confirm="() => handleDelete([row.id])">
  101. <template #reference>
  102. <el-button type="primary" :disabled="perm('{{camelCase name}}:delete')" size="small" link>\{{ $t('delete') }}</el-button>
  103. </template>
  104. </el-popconfirm>
  105. </template>
  106. </el-table-column>
  107. </column-list>
  108. </el-table>
  109. <el-pagination
  110. v-model:currentPage="currentPage"
  111. v-model:pageSize="pageSize"
  112. :total="total"
  113. :page-sizes="pageSizes"
  114. :layout="pageLayout"
  115. class="px-3 py-2 justify-end"
  116. small
  117. background
  118. @size-change="() => fetchData()"
  119. @current-change="() => fetchData()"
  120. ></el-pagination>
  121. </div>
  122. <{{kebabCase name}}-form v-model="formVisible" :bean-id="beanId" :bean-ids="beanIds" @finished="fetchData" />
  123. </div>
  124. </template>