|
|
@@ -0,0 +1,102 @@
|
|
|
+import {delUser, getUserList} from '@apis';
|
|
|
+import {
|
|
|
+ useFetchTableList,
|
|
|
+ useTableDeleteEvent,
|
|
|
+ useTableModalEvent,
|
|
|
+} from '@hooks';
|
|
|
+import {filterSymbol, pageSymbol, searchSymbol} from '../state';
|
|
|
+import {useI18n} from 'vue-i18n';
|
|
|
+import {computed, h} from 'vue';
|
|
|
+import {type DataTableColumn, NSpace} from 'naive-ui';
|
|
|
+import {UserListData} from '@models';
|
|
|
+import {TABLE_CELL_WIDTH} from '@utils';
|
|
|
+import {LDTableButton} from '@components';
|
|
|
+
|
|
|
+export function useTableData() {
|
|
|
+ return useFetchTableList({
|
|
|
+ queryFn: getUserList,
|
|
|
+ searchSymbol,
|
|
|
+ pageSymbol,
|
|
|
+ filterSymbol,
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+export function useColumns(refetch: () => void) {
|
|
|
+ const {t} = useI18n();
|
|
|
+ const [
|
|
|
+ {visible, editId},
|
|
|
+ {onEdit, onAdd},
|
|
|
+ ] = useTableModalEvent();
|
|
|
+ const [deleteId, onDelete] = useTableDeleteEvent(
|
|
|
+ delUser,
|
|
|
+ refetch,
|
|
|
+ {label: t('user.label')},
|
|
|
+ );
|
|
|
+
|
|
|
+ const columns = computed<DataTableColumn<UserListData>[]>(function() {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ title: t('user.table[0]'),
|
|
|
+ key: 'userName',
|
|
|
+ width: TABLE_CELL_WIDTH.normal,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: t('user.table[1]'),
|
|
|
+ key: 'realName',
|
|
|
+ width: TABLE_CELL_WIDTH.normal,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: t('user.table[4]'),
|
|
|
+ key: 'role',
|
|
|
+ width: TABLE_CELL_WIDTH.normal,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: t('user.table[2]'),
|
|
|
+ key: 'email',
|
|
|
+ width: TABLE_CELL_WIDTH.normal,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: t('user.table[3]'),
|
|
|
+ key: 'phone',
|
|
|
+ width: TABLE_CELL_WIDTH.normal,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: t('common.tableHeader.operation'),
|
|
|
+ width: TABLE_CELL_WIDTH.huge,
|
|
|
+ key: 'id',
|
|
|
+ fixed: 'right',
|
|
|
+ render({id}) {
|
|
|
+ const isDeleteing = String(id) === deleteId.value;
|
|
|
+
|
|
|
+ return h(
|
|
|
+ NSpace,
|
|
|
+ null,
|
|
|
+ [
|
|
|
+ h(
|
|
|
+ h(LDTableButton),
|
|
|
+ {
|
|
|
+ isDelete: false,
|
|
|
+ disabled: isDeleteing,
|
|
|
+ onClick: onEdit(String(id)),
|
|
|
+ text: t('common.tableTool.buttonGroup.edit'),
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ h(
|
|
|
+ h(LDTableButton),
|
|
|
+ {
|
|
|
+ isDelete: true,
|
|
|
+ loading: isDeleteing,
|
|
|
+ disabled: isDeleteing,
|
|
|
+ onClick: onDelete(String(id)),
|
|
|
+ text: t('common.tableTool.buttonGroup.delete'),
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ );
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ });
|
|
|
+
|
|
|
+ return [{columns, visible, editId}, {onAdd}] as const;
|
|
|
+}
|