gtsoft-snail-job-admin/src/views/user/manager/index.vue

169 lines
4.7 KiB
Vue
Raw Normal View History

2024-04-26 17:34:24 +08:00
<script setup lang="tsx">
2024-04-27 00:11:38 +08:00
import { NButton, NPopconfirm, NTag } from 'naive-ui';
2024-04-27 22:52:31 +08:00
import { fetchDelUser, fetchGetUserPageList } from '@/service/api';
2024-04-26 17:34:24 +08:00
import { $t } from '@/locales';
import { useAppStore } from '@/store/modules/app';
import { useTable, useTableOperate } from '@/hooks/common/table';
2024-04-27 00:11:38 +08:00
import { roleRecord } from '@/constants/business';
2024-04-27 22:52:31 +08:00
import UserManagerOperateDrawer from './modules/user-manager-operate-drawer.vue';
import UserManagerSearch from './modules/user-manager-search.vue';
2024-04-26 17:34:24 +08:00
const appStore = useAppStore();
const { columns, columnChecks, data, getData, loading, mobilePagination, searchParams, resetSearchParams } = useTable({
apiFn: fetchGetUserPageList,
apiParams: {
page: 1,
size: 10,
// if you want to use the searchParams in Form, you need to define the following properties, and the value is null
// the value can not be undefined, otherwise the property in Form will not be reactive
username: null,
role: null
},
columns: () => [
2024-04-27 22:52:31 +08:00
{
key: 'permissions',
// title: $t('page.userManager.permissions'),
align: 'left',
type: 'expand',
minWidth: 10,
renderExpand: row => {
if (!row.permissions) {
return <NTag type="info">ALL</NTag>;
}
return (
<div>
{
<n-h5 prefix="bar" type="warning">
<n-text type="warning">{$t('page.userManager.permissionList')}:</n-text>
</n-h5>
}
{row.permissions?.map(option => (
<span>
<NTag type="info">
<span style="font-weight: bolder;">{option.groupName}</span>({option.namespaceName})
</NTag>
{<n-divider vertical />}
</span>
))}
</div>
);
}
},
2024-04-26 17:34:24 +08:00
{
key: 'username',
title: $t('page.userManager.username'),
align: 'left',
minWidth: 120
},
{
key: 'role',
title: $t('page.userManager.role'),
align: 'left',
2024-04-27 00:11:38 +08:00
minWidth: 50,
render: row => {
if (row.role === null) {
return null;
}
const tagMap: Record<Api.UserManager.Role, NaiveUI.ThemeColor> = {
1: 'info',
2: 'warning'
};
const label = $t(roleRecord[row.role]);
return <NTag type={tagMap[row.role!]}>{label}</NTag>;
}
},
{
key: 'updateDt',
title: $t('common.updateDt'),
align: 'left',
minWidth: 50
2024-04-26 17:34:24 +08:00
},
{
key: 'operate',
title: $t('common.operate'),
align: 'center',
width: 130,
render: row => (
<div class="flex-center gap-8px">
<NButton type="primary" ghost size="small" onClick={() => edit(row.id!)}>
{$t('common.edit')}
</NButton>
2024-04-27 22:52:31 +08:00
<NPopconfirm onPositiveClick={() => handleDelete(row.id!)}>
2024-04-26 17:34:24 +08:00
{{
default: () => $t('common.confirmDelete'),
trigger: () => (
<NButton type="error" ghost size="small">
{$t('common.delete')}
</NButton>
)
}}
</NPopconfirm>
</div>
)
}
]
});
2024-04-27 22:52:31 +08:00
const { drawerVisible, operateType, editingData, handleAdd, handleEdit, checkedRowKeys } = useTableOperate(
data,
getData
);
2024-04-26 17:34:24 +08:00
2024-04-27 22:52:31 +08:00
async function handleDelete(id: string) {
const { error } = await fetchDelUser(id as any);
if (error) return;
getData();
window.$message?.success($t('common.deleteSuccess'));
2024-04-26 17:34:24 +08:00
}
function edit(id: string) {
handleEdit(id);
}
</script>
<template>
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
2024-04-27 22:52:31 +08:00
<UserManagerSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getData" />
2024-04-26 17:34:24 +08:00
<NCard
:title="$t('page.userManager.title')"
:bordered="false"
size="small"
class="sm:flex-1-hidden card-wrapper"
header-class="view-card-header"
>
<template #header-extra>
<TableHeaderOperation
v-model:columns="columnChecks"
:disabled-delete="checkedRowKeys.length === 0"
:loading="loading"
2024-04-27 22:52:31 +08:00
:show-delete="false"
2024-04-26 17:34:24 +08:00
@add="handleAdd"
@refresh="getData"
/>
</template>
<NDataTable
v-model:checked-row-keys="checkedRowKeys"
:columns="columns"
:data="data"
:flex-height="!appStore.isMobile"
:scroll-x="962"
:loading="loading"
remote
:row-key="row => row.id"
:pagination="mobilePagination"
class="sm:h-full"
/>
2024-04-27 22:52:31 +08:00
<UserManagerOperateDrawer
2024-04-26 17:34:24 +08:00
v-model:visible="drawerVisible"
:operate-type="operateType"
:row-data="editingData"
@submitted="getData"
/>
</NCard>
</div>
</template>
<style scoped></style>