wms-antdvue/.svn/pristine/0f/0fb710a3dddb75b72a4e83b291d0b177d6a160ab.svn-base
2024-11-07 16:33:03 +08:00

254 lines
7.0 KiB
Plaintext

<template>
<PageWrapper>
<a-card :bordered="false" class="pt-3 mb-3 proCard">
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset">
<template #statusSlot="{ model, field }">
<a-input v-model="model[field]" />
</template>
</BasicForm>
</a-card>
<a-card :bordered="false" class="proCard">
<BasicTable
:columns="columns"
:request="loadDataTable"
:row-key="(row) => row.id"
ref="tableRef"
scroll-x="1200"
:row-selection="{ onChange: onSelectionChange }"
virtual-scroll
>
<template #tableTitle>
<a-space>
<a-button type="primary" @click="addUser" v-perm="['sys:user:add']">
<template #icon>
<PlusOutlined />
</template>
新建
</a-button>
<a-button
type="danger"
@click="handleDelete()"
:disabled="!selectionData.length"
v-perm="['sys:user:batchDelete']"
>
<template #icon>
<DeleteOutlined />
</template>
删除
</a-button>
<a-button type="primary" @click="importVisible = true" v-perm="['sys:user:import']">
<template #icon>
<UploadOutlined />
</template>
导入
</a-button>
<!-- <a-upload
ref="upload"
action="/api/user/import"
:headers="uploadHeaders"
:on-error="onError"
:on-success="onSuccess"
:before-upload="beforeUpload"
:show-file-list="false"
:limit="1"
v-perm="['sys:user:import']"
>
<a-button type="primary">
<template #icon>
<a-icon class="a-input__icon">
<Upload />
</a-icon>
</template>
导入
</a-button>
</a-upload> -->
<a-button
type="primary"
@click="handleExport"
:loading="exportLoading"
:disabled="exportLoading"
v-perm="['sys:user:export']"
>
<template #icon>
<DownloadOutlined />
</template>
导出
</a-button>
</a-space>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'">
<a-space>
<a-button type="primary" @click="handleEdit(record.id)" v-perm="['sys:user:update']">
<template #icon><EditOutlined /></template>
编辑
</a-button>
<a-button
type="primary"
danger
@click="handleDelete(record.id)"
v-perm="['sys:user:delete']"
>
<template #icon><DeleteOutlined /></template>
删除
</a-button>
<a-button
type="primary"
v-if="record.type !== 1"
@click="handleResetPassWord(record.id)"
v-perm="['sys:user:resetPwd']"
>
<template #icon><PlusOutlined /></template>
重置密码</a-button
>
<a-button type="primary" @click="handlePrint(record.id)">
<template #icon><PrinterOutlined /></template>
打印</a-button
>
</a-space>
</template>
</template>
</BasicTable>
</a-card>
<editDialog
v-if="editVisible"
:userId="userId"
v-model:visible="editVisible"
@success="reloadTable('noRefresh')"
/>
<userUpload v-if="importVisible" v-model:visible="importVisible" @success="reloadTable()" />
</PageWrapper>
</template>
<script lang="ts" setup>
import { nextTick, reactive, ref, defineAsyncComponent } from 'vue';
import {
PlusOutlined,
EditOutlined,
DeleteOutlined,
DownloadOutlined,
UploadOutlined,
PrinterOutlined,
} from '@ant-design/icons-vue';
import { useForm } from '@/components/Form/index';
import {
getUserList,
userDelete,
userBatchDelete,
userExport,
resetPwd,
getUserDocument,
} from '@/api/system/user';
import { columns } from './columns';
import { schemas } from './querySchemas';
import { downloadByData } from '@/utils/file/download';
import { Modal, message } from 'ant-design-vue';
import printJS from 'print-js';
const userId = ref(0);
const tableRef = ref();
const editVisible = ref(false);
const importVisible = ref(false);
const selectionData = ref([]);
const exportLoading = ref(false);
const editDialog = defineAsyncComponent(() => import('./edit.vue'));
const userUpload = defineAsyncComponent(() => import('./userUpload.vue'));
const formParams = reactive({
realname: '',
role: '',
status: '',
});
const loadDataTable = async (res) => {
const result = await getUserList({ ...formParams, ...res });
return result;
};
function reloadTable(noRefresh = '') {
tableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
}
async function handleEdit(id) {
userId.value = id;
await nextTick();
editVisible.value = true;
}
async function handleResetPassWord(id) {
Modal.confirm({
title: '提示',
content: '确定重置密码?',
onOk: async () => {
await resetPwd({ userId: id });
message.success('重置成功');
},
});
}
async function handleDelete(id) {
Modal.confirm({
title: '提示',
content: '确定要删除?',
onOk: async () => {
id ? await userDelete(id) : await userBatchDelete(selectionData.value);
message.success('删除成功');
reloadTable();
},
});
}
function handleSubmit(values) {
for (const key in formParams) {
formParams[key] = '';
}
for (const key in values) {
formParams[key] = values[key];
}
reloadTable();
}
function handleReset() {
for (const key in formParams) {
formParams[key] = '';
}
reloadTable();
}
function onSelectionChange(value) {
selectionData.value = value;
}
const [register, {}] = useForm({
rowProps: { gutter: [16, 0] },
colProps: {
xs: 24,
sm: 24,
md: 12,
lg: 8,
xl: 6,
},
labelCol: { span: 6, offset: 0 },
schemas,
});
//添加
const addUser = async () => {
userId.value = 0;
await nextTick();
editVisible.value = true;
};
//导出
const handleExport = async () => {
exportLoading.value = true;
const data = await userExport();
downloadByData(data, '用户信息.xlsx');
exportLoading.value = false;
message.success('导出成功');
};
const handlePrint = async (id) => {
const res = await getUserDocument(id);
printJS({
printable: res.fileUrl,
type: 'pdf',
showModal: true,
});
};
</script>