员工花名册新增导入功能

pull/653/head
hky 2024-12-24 18:40:43 +08:00
parent 9df30e466a
commit dfb4ce965e
3 changed files with 209 additions and 51 deletions

View File

@ -1,51 +1,55 @@
import request from '@/config/axios'
// 员工花名册 VO
export interface EmployeeVO {
id: number // 唯一标识符
empName: string // 姓名
idNo: string // 身份证号
empNo: string // 工号
station: string // 岗位
bankNo: string // 银行卡号
orgNo: number // 所属机构
annuityNo: string // 企业年金帐号
socialSecurityNo: string // 社保账号
pensionNo: string // 养老金帐号
housingFundNo: string // 住房公积金账号
workTime: Date // 参加工作时间
empStatus: string // 员工状态
}
// 员工花名册 API
export const EmployeeApi = {
// 查询员工花名册分页
getEmployeePage: async (params: any) => {
return await request.get({ url: `/salary/employee/page`, params })
},
// 查询员工花名册详情
getEmployee: async (id: number) => {
return await request.get({ url: `/salary/employee/get?id=` + id })
},
// 新增员工花名册
createEmployee: async (data: EmployeeVO) => {
return await request.post({ url: `/salary/employee/create`, data })
},
// 修改员工花名册
updateEmployee: async (data: EmployeeVO) => {
return await request.put({ url: `/salary/employee/update`, data })
},
// 删除员工花名册
deleteEmployee: async (id: number) => {
return await request.delete({ url: `/salary/employee/delete?id=` + id })
},
// 导出员工花名册 Excel
exportEmployee: async (params) => {
return await request.download({ url: `/salary/employee/export-excel`, params })
},
}
import request from '@/config/axios'
// 员工花名册 VO
export interface EmployeeVO {
id: number // 唯一标识符
empName: string // 姓名
idNo: string // 身份证号
empNo: string // 工号
station: string // 岗位
bankNo: string // 银行卡号
orgNo: number // 所属机构
annuityNo: string // 企业年金帐号
socialSecurityNo: string // 社保账号
pensionNo: string // 养老金帐号
housingFundNo: string // 住房公积金账号
workTime: Date // 参加工作时间
empStatus: string // 员工状态
}
// 员工花名册 API
export const EmployeeApi = {
// 查询员工花名册分页
getEmployeePage: async (params: any) => {
return await request.get({ url: `/salary/employee/page`, params })
},
// 查询员工花名册详情
getEmployee: async (id: number) => {
return await request.get({ url: `/salary/employee/get?id=` + id })
},
// 新增员工花名册
createEmployee: async (data: EmployeeVO) => {
return await request.post({ url: `/salary/employee/create`, data })
},
// 修改员工花名册
updateEmployee: async (data: EmployeeVO) => {
return await request.put({ url: `/salary/employee/update`, data })
},
// 删除员工花名册
deleteEmployee: async (id: number) => {
return await request.delete({ url: `/salary/employee/delete?id=` + id })
},
// 导出员工花名册 Excel
exportEmployee: async (params) => {
return await request.download({ url: `/salary/employee/export-excel`, params })
},
importEmpTemplate: async () => {
return request.download({ url: '/salary/employee/get-import-template' })
}
}

View File

@ -0,0 +1,138 @@
<template>
<Dialog v-model="dialogVisible" title="员工花名册导入" width="400">
<el-upload
ref="uploadRef"
v-model:file-list="fileList"
:action="importUrl + '?updateSupport=' + updateSupport"
:auto-upload="false"
:disabled="formLoading"
:headers="uploadHeaders"
:limit="1"
:on-error="submitFormError"
:on-exceed="handleExceed"
:on-success="submitFormSuccess"
accept=".xlsx, .xls"
drag
>
<Icon icon="ep:upload" />
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
<template #tip>
<div class="el-upload__tip text-center">
<div class="el-upload__tip">
<el-checkbox v-model="updateSupport" />
是否更新已经存在的员工数据
</div>
<span>仅允许导入 xlsxlsx 格式文件</span>
<el-link
:underline="false"
style="font-size: 12px; vertical-align: baseline"
type="primary"
@click="importTemplate"
>
下载模板
</el-link>
</div>
</template>
</el-upload>
<template #footer>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script lang="ts" setup>
import * as EmpApi from '@/api/arcb/salary/employee'
import { getAccessToken, getTenantId } from '@/utils/auth'
import download from '@/utils/download'
defineOptions({ name: 'EmployeeImportForm' })
const message = useMessage() //
const dialogVisible = ref(false) //
const formLoading = ref(false) //
const uploadRef = ref()
const importUrl =
import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/salary/employee/import'
const uploadHeaders = ref() // Header
const fileList = ref([]) //
const updateSupport = ref(0) //
/** 打开弹窗 */
const open = () => {
dialogVisible.value = true
updateSupport.value = 0
fileList.value = []
resetForm()
}
defineExpose({ open }) // open
/** 提交表单 */
const submitForm = async () => {
if (fileList.value.length == 0) {
message.error('请上传文件')
return
}
//
uploadHeaders.value = {
Authorization: 'Bearer ' + getAccessToken(),
'tenant-id': getTenantId()
}
formLoading.value = true
uploadRef.value!.submit()
}
/** 文件上传成功 */
const emits = defineEmits(['success'])
const submitFormSuccess = (response: any) => {
if (response.code !== 0) {
message.error(response.msg)
formLoading.value = false
return
}
//
const data = response.data
let text = '上传成功数量:' + data.createUsernames.length + ';'
for (let username of data.createUsernames) {
text += '< ' + username + ' >'
}
text += '更新成功数量:' + data.updateUsernames.length + ';'
for (const username of data.updateUsernames) {
text += '< ' + username + ' >'
}
text += '更新失败数量:' + Object.keys(data.failureUsernames).length + ';'
for (const username in data.failureUsernames) {
text += '< ' + username + ': ' + data.failureUsernames[username] + ' >'
}
message.alert(text)
formLoading.value = false
dialogVisible.value = false
//
emits('success')
}
/** 上传错误提示 */
const submitFormError = (): void => {
message.error('上传失败,请您重新上传!')
formLoading.value = false
}
/** 重置表单 */
const resetForm = async (): Promise<void> => {
//
formLoading.value = false
await nextTick()
uploadRef.value?.clearFiles()
}
/** 文件数超出提示 */
const handleExceed = (): void => {
message.error('最多只能上传一个文件!')
}
/** 下载模板操作 */
const importTemplate = async () => {
const res = await EmpApi.EmployeeApi.importEmpTemplate()
download.excel(res, '员工花名册导入模版.xls')
}
</script>

View File

@ -135,6 +135,14 @@
>
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button
type="warning"
plain
@click="handleImport"
v-hasPermi="['salary:employee:import']"
>
<Icon icon="ep:upload" /> 导入
</el-button>
<el-button
type="success"
plain
@ -200,6 +208,8 @@
<!-- 表单弹窗添加/修改 -->
<EmployeeForm ref="formRef" @success="getList" />
<!-- 用户导入对话框 -->
<EmpImportForm ref="importFormRef" @success="getList" />
</template>
<script setup lang="ts">
@ -207,6 +217,7 @@ import { getStrDictOptions, DICT_TYPE } from '@/utils/dict'
import download from '@/utils/download'
import { EmployeeApi, EmployeeVO } from '@/api/arcb/salary/employee'
import EmployeeForm from './EmployeeForm.vue'
import EmpImportForm from './EmployeeImportForm.vue'
/** 员工花名册 列表 */
defineOptions({ name: 'Employee' })
@ -260,6 +271,11 @@ const resetQuery = () => {
handleQuery()
}
const importFormRef = ref()
const handleImport = () => {
importFormRef.value.open()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {