feat: useTable 支持 “无分页” 列表

This commit is contained in:
2024-05-11 22:26:33 +08:00
parent fe656af1aa
commit 1421412d67
13 changed files with 154 additions and 193 deletions

View File

@@ -13,17 +13,17 @@
@refresh="search"
>
<template #custom-left>
<a-button v-permission="['system:dict:add']" type="primary" @click="onAdd">
<template #icon><icon-plus /></template>
<span>新增</span>
</a-button>
</template>
<template #custom-right>
<a-input v-model="queryForm.description" placeholder="请输入关键词" allow-clear @change="search">
<template #prefix><icon-search /></template>
</a-input>
<a-button @click="reset">重置</a-button>
</template>
<template #custom-right>
<a-button v-permission="['system:dict:add']" type="primary" @click="onAdd">
<template #icon><icon-plus /></template>
<span>新增</span>
</a-button>
</template>
<template #isSystem="{ record }">
<a-tag v-if="record.isSystem" color="red"></a-tag>
<a-tag v-else color="arcoblue"></a-tag>
@@ -74,12 +74,6 @@ const {
handleDelete
} = useTable((p) => listDict({ ...queryForm, page: p.page, size: p.size }), { immediate: true })
// 重置
const reset = () => {
queryForm.description = undefined
search()
}
const columns: TableInstanceColumns[] = [
{
title: '序号',
@@ -105,6 +99,12 @@ const columns: TableInstanceColumns[] = [
}
]
// 重置
const reset = () => {
queryForm.description = undefined
search()
}
// 删除
const onDelete = (item: DictResp) => {
return handleDelete(() => deleteDict(item.id), { content: `是否确定删除字典 [${item.name}]`, showModal: true })

View File

@@ -22,17 +22,17 @@
@refresh="search"
>
<template #custom-left>
<a-button type="primary" @click="onAdd">
<template #icon><icon-plus /></template>
<span>新增</span>
</a-button>
</template>
<template #custom-right>
<a-input v-model="queryForm.description" placeholder="请输入关键词" allow-clear @change="search">
<template #prefix><icon-search /></template>
</a-input>
<a-button @click="reset">重置</a-button>
</template>
<template #custom-right>
<a-button v-permission="['system:dict:item:add']" type="primary" @click="onAdd">
<template #icon><icon-plus /></template>
<span>新增</span>
</a-button>
</template>
<template #label="{ record }">
<a-tag :color="record.color">{{ record.label }}</a-tag>
</template>
@@ -41,17 +41,14 @@
</template>
<template #action="{ record }">
<a-space>
<template #split>
<a-divider direction="vertical" :margin="0" />
</template>
<a-link @click="onUpdate(record)">修改</a-link>
<a-link v-permission="['system:dict:item:update']" @click="onUpdate(record)">修改</a-link>
<a-popconfirm
type="warning"
content="是否确定删除该条数据?"
:ok-button-props="{ status: 'danger' }"
@ok="onDelete(record)"
>
<a-link status="danger">删除</a-link>
<a-link v-permission="['system:dict:item:delete']" status="danger">删除</a-link>
</a-popconfirm>
</a-space>
</template>
@@ -68,12 +65,12 @@ import { type DictItemQuery, type DictItemResp, deleteDictItem, listDictItem } f
import type { TableInstanceColumns } from '@/components/GiTable/type'
import { useTable } from '@/hooks'
import { isMobile } from '@/utils'
import has from '@/utils/has'
const { width } = useWindowSize()
const dictId = ref('')
const queryForm = reactive<DictItemQuery>({
dictId: '',
sort: ['createTime,desc']
})
@@ -83,16 +80,7 @@ const {
pagination,
search,
handleDelete
} = useTable((p) => listDictItem({ ...queryForm, dictId: dictId.value, page: p.page, size: p.size }), {
immediate: true
})
// 重置
const reset = () => {
queryForm.description = undefined
queryForm.status = undefined
search()
}
} = useTable((p) => listDictItem({ ...queryForm, page: p.page, size: p.size }), { immediate: true })
const columns: TableInstanceColumns[] = [
{
@@ -119,15 +107,29 @@ const columns: TableInstanceColumns[] = [
{ title: '创建时间', dataIndex: 'createTime', width: 180 },
{ title: '修改人', dataIndex: 'updateUserString', ellipsis: true, tooltip: true, show: false },
{ title: '修改时间', dataIndex: 'updateTime', width: 180, show: false },
{ title: '操作', slotName: 'action', width: 130, align: 'center', fixed: !isMobile() ? 'right' : undefined }
{
title: '操作',
slotName: 'action',
width: 130,
align: 'center',
fixed: !isMobile() ? 'right' : undefined,
show: has.hasPermOr(['system:dict:item:update', 'system:dict:item:delete'])
}
]
// 重置
const reset = () => {
queryForm.description = undefined
queryForm.status = undefined
search()
}
const dictCode = ref('')
const visible = ref(false)
// 打开
const open = (id: string, code: string) => {
dataList.value = []
dictId.value = id
queryForm.dictId = id
dictCode.value = code
visible.value = true
search()
@@ -142,7 +144,7 @@ const onDelete = (item: DictItemResp) => {
const DictItemAddModalRef = ref<InstanceType<typeof DictItemAddModal>>()
// 新增
const onAdd = () => {
DictItemAddModalRef.value?.onAdd(dictId.value)
DictItemAddModalRef.value?.onAdd(queryForm.dictId)
}
// 修改