|
|
@@ -1,4 +1,4 @@
|
|
|
-import {delUser, getUserList} from '@apis';
|
|
|
+import {delUser, getUserList, resetPassword} from '@apis';
|
|
|
import {
|
|
|
useFetchTableList,
|
|
|
useTableDeleteEvent,
|
|
|
@@ -6,11 +6,12 @@ import {
|
|
|
} 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 {computed, h, ref} from 'vue';
|
|
|
+import {type DataTableColumn, NSpace, useMessage, useDialog} from 'naive-ui';
|
|
|
import {UserListData} from '@models';
|
|
|
-import {TABLE_CELL_WIDTH} from '@utils';
|
|
|
+import {TABLE_CELL_WIDTH, lightVariable} from '@utils';
|
|
|
import {LDTableButton} from '@components';
|
|
|
+import {useMutation} from '@tanstack/vue-query';
|
|
|
|
|
|
export function useTableData() {
|
|
|
return useFetchTableList({
|
|
|
@@ -21,18 +22,58 @@ export function useTableData() {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+function useResePassword() {
|
|
|
+ const message = useMessage();
|
|
|
+ const {t} = useI18n();
|
|
|
+ const resetId = ref('');
|
|
|
+
|
|
|
+ const {mutate} = useMutation({
|
|
|
+ mutationFn: resetPassword,
|
|
|
+ onSuccess({msg}) {
|
|
|
+ msg === '200' && message.success(t('user.resetSuccess'));
|
|
|
+ },
|
|
|
+ onSettled() {
|
|
|
+ resetId.value = '';
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const dialog = useDialog();
|
|
|
+ function onReset(id: string) {
|
|
|
+ return function() {
|
|
|
+ dialog.info({
|
|
|
+ title: t('user.tableOperation[0]'),
|
|
|
+ content: t('user.resetTips'),
|
|
|
+ positiveText: t('common.confirm'),
|
|
|
+ negativeText: t('common.cancel'),
|
|
|
+ positiveButtonProps: {
|
|
|
+ color: lightVariable.primaryColor,
|
|
|
+ },
|
|
|
+ onPositiveClick() {
|
|
|
+ mutate(id);
|
|
|
+ resetId.value = id;
|
|
|
+ },
|
|
|
+ });
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ return [resetId, onReset] as const;
|
|
|
+}
|
|
|
+
|
|
|
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 [resetId, onReset] = useResePassword();
|
|
|
+
|
|
|
const columns = computed<DataTableColumn<UserListData>[]>(function() {
|
|
|
return [
|
|
|
{
|
|
|
@@ -67,6 +108,7 @@ export function useColumns(refetch: () => void) {
|
|
|
fixed: 'right',
|
|
|
render({id}) {
|
|
|
const isDeleteing = String(id) === deleteId.value;
|
|
|
+ const isReseting = String(id) === resetId.value;
|
|
|
|
|
|
return h(
|
|
|
NSpace,
|
|
|
@@ -81,6 +123,16 @@ export function useColumns(refetch: () => void) {
|
|
|
text: t('common.tableTool.buttonGroup.edit'),
|
|
|
},
|
|
|
),
|
|
|
+ h(
|
|
|
+ h(LDTableButton),
|
|
|
+ {
|
|
|
+ isDelete: false,
|
|
|
+ disabled: isDeleteing || isReseting,
|
|
|
+ loading: isReseting,
|
|
|
+ onClick: onReset(String(id)),
|
|
|
+ text: t('user.tableOperation[0]'),
|
|
|
+ },
|
|
|
+ ),
|
|
|
h(
|
|
|
h(LDTableButton),
|
|
|
{
|