You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
4.7 KiB
125 lines
4.7 KiB
<template> |
|
<div> |
|
<div class="mb-3"> |
|
<query-form :params="params" @search="handleSearch" @reset="handleReset"> |
|
<query-item :label="$t('{{camelCase name}}.name')" name="Q_Contains_name"></query-item> |
|
</query-form> |
|
</div> |
|
<div> |
|
<el-button type="primary" :disabled="perm('{{camelCase name}}:create')" :icon="Plus" @click="handleAdd()">\{{ $t('add') }}</el-button> |
|
<el-popconfirm :title="$t('confirmDelete')" @confirm="handleDelete(selection.map((row) => row.id))"> |
|
<template #reference> |
|
<el-button :disabled="selection.length <= 0 || perm('{{camelCase name}}:delete')" :icon="Delete">\{{ $t('delete') }}</el-button> |
|
</template> |
|
</el-popconfirm> |
|
<column-setting name="{{camelCase name}}" class="ml-2" /> |
|
</div> |
|
<div class="app-block mt-3"> |
|
<el-table |
|
ref="table" |
|
v-loading="loading" |
|
:data="data" |
|
@selection-change="(rows) => (selection = rows)" |
|
@row-dblclick="(row) => handleEdit(row.id)" |
|
@sort-change="handleSort" |
|
> |
|
<column-list name="{{camelCase name}}"> |
|
<el-table-column type="selection" width="45"></el-table-column> |
|
<el-table-column property="id" label="ID" width="64" sortable="custom"></el-table-column> |
|
<el-table-column property="name" :label="$t('{{camelCase name}}.name')" sortable="custom" show-overflow-tooltip></el-table-column> |
|
<el-table-column :label="$t('table.action')"> |
|
<template #default="{row}"> |
|
<el-button type="text" :disabled="perm('{{camelCase name}}:update')" @click="handleEdit(row.id)" size="small">\{{ $t('edit') }}</el-button> |
|
<el-popconfirm :title="$t('confirmDelete')" @confirm="handleDelete([row.id])"> |
|
<template #reference> |
|
<el-button type="text" :disabled="perm('{{camelCase name}}:delete')" size="small">\{{ $t('delete') }}</el-button> |
|
</template> |
|
</el-popconfirm> |
|
</template> |
|
</el-table-column> |
|
</column-list> |
|
</el-table> |
|
<el-pagination |
|
v-model:currentPage="currentPage" |
|
v-model:pageSize="pageSize" |
|
:total="total" |
|
:page-sizes="pageSizes" |
|
:layout="pageLayout" |
|
@size-change="fetchData()" |
|
@current-change="fetchData()" |
|
small |
|
background |
|
class="px-3 py-2 justify-end" |
|
></el-pagination> |
|
</div> |
|
<{{kebabCase name}}-form v-model="formVisible" :beanId="beanId" :beanIds="beanIds" @finished="fetchData" /> |
|
</div> |
|
</template> |
|
|
|
<script setup lang="ts"> |
|
import { computed, onMounted, ref } from 'vue'; |
|
import { ElMessage } from 'element-plus'; |
|
import { Plus, Delete } from '@element-plus/icons-vue'; |
|
import { useI18n } from 'vue-i18n'; |
|
import { perm } from '@/store/useCurrentUser'; |
|
import { pageSizes, pageLayout, toParams, resetParams } from '@/utils/common'; |
|
import { delete{{pascalCase name}}, query{{pascalCase name}}Page } from '@/api/{{kebabCase path}}'; |
|
import { ColumnList, ColumnSetting } from '@/components/TableList'; |
|
import { QueryForm, QueryItem } from '@/components/QueryForm'; |
|
import {{pascalCase name}}Form from './{{pascalCase name}}Form.vue'; |
|
|
|
const { t } = useI18n(); |
|
const params = ref<any>({}); |
|
const sort = ref<any>(); |
|
const currentPage = ref<number>(1); |
|
const pageSize = ref<number>(10); |
|
const total = ref<number>(0); |
|
const table = ref<any>(); |
|
const data = ref<any[]>([]); |
|
const selection = ref<any[]>([]); |
|
const loading = ref<boolean>(false); |
|
const formVisible = ref<boolean>(false); |
|
const beanId = ref<number>(); |
|
const beanIds = computed(() => data.value.map((row) => row.id)); |
|
const fetchData = async () => { |
|
loading.value = true; |
|
try { |
|
const { content, totalElements } = await query{{pascalCase name}}Page({ ...toParams(params.value), Q_OrderBy: sort.value, page: currentPage.value, pageSize: pageSize.value }); |
|
data.value = content; |
|
total.value = totalElements; |
|
} finally { |
|
loading.value = false; |
|
} |
|
}; |
|
onMounted(fetchData); |
|
|
|
const handleSort = ({ column, prop, order }: { column: any; prop: string; order: string }) => { |
|
if (prop) { |
|
sort.value = (column.sortBy ?? prop) + (order === 'descending' ? '_desc' : ''); |
|
} else { |
|
sort.value = undefined; |
|
} |
|
fetchData(); |
|
}; |
|
const handleSearch = () => fetchData(); |
|
const handleReset = () => { |
|
table.value.clearSort(); |
|
resetParams(params.value); |
|
sort.value = undefined; |
|
fetchData(); |
|
}; |
|
|
|
const handleAdd = () => { |
|
beanId.value = undefined; |
|
formVisible.value = true; |
|
}; |
|
const handleEdit = (id: number) => { |
|
beanId.value = id; |
|
formVisible.value = true; |
|
}; |
|
const handleDelete = async (ids: number[]) => { |
|
await delete{{pascalCase name}}(ids); |
|
fetchData(); |
|
ElMessage.success(t('success')); |
|
}; |
|
</script>
|
|
|