Explorar el Código

考勤增加导入功能

chenjun hace 1 año
padre
commit
e80393db28

+ 99 - 0
client/src/views/OaSystem/attendanceCenter/components/attendanceSheetImportForm.vue

@@ -0,0 +1,99 @@
+<template>
+  <Dialog v-model="dialogVisible" title="考勤表导入" width="400">
+    <el-upload
+      ref="uploadRef"
+      v-model:file-list="fileList"
+      :action="importUrl"
+      :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">
+          <span>仅允许导入 xls、xlsx 格式文件。</span>
+        </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 { getAccessToken, getTenantId } from '@/utils/auth'
+
+defineOptions({ name: 'AttendanceSheetImportForm' })
+
+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 + '/adm/attendance-sheet/import'
+const uploadHeaders = ref() // 上传 Header 头
+const fileList = ref([]) // 文件列表
+
+/** 打开弹窗 */
+const open = () => {
+  dialogVisible.value = true
+  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
+  }
+  message.alert('导入成功')
+  dialogVisible.value = false
+  // 发送操作成功的事件
+  emits('success')
+}
+
+/** 上传错误提示 */
+const submitFormError = (): void => {
+  message.error('上传失败,请您重新上传!')
+  formLoading.value = false
+}
+
+/** 重置表单 */
+const resetForm = () => {
+  // 重置上传状态和文件
+  formLoading.value = false
+  uploadRef.value?.clearFiles()
+}
+
+/** 文件数超出提示 */
+const handleExceed = (): void => {
+  message.error('最多只能上传一个文件!')
+}
+</script>

+ 24 - 1
client/src/views/OaSystem/attendanceCenter/dep.vue

@@ -36,6 +36,15 @@
             :colsWidth="colsWidth"
             :title="`${moment(fromParams.month).format('YYYY年MM月')}-考勤数据表`"
           />
+          <el-button
+            v-if="porps.deptsName == '公司'"
+            type="warning"
+            plain
+            @click="handleImport"
+            v-hasPermi="['adm:attendance-sheet:import']"
+          >
+            <Icon icon="ep:upload" /> 导入
+          </el-button>
           <el-button type="success" style="background-color: #05ce9e" v-if="false">
             <img src="@/assets/imgs/OA/kq/kqqrIcon.png" class="mr-8px" alt="" />
             考勤确认</el-button
@@ -143,6 +152,8 @@
 
     <DepsUpdataDetail ref="depsDetailRef" @updataInit="updataInit" />
   </div>
+  <!-- 用户导入对话框 -->
+  <AttendanceSheetImportForm ref="importFormRef" @success="init" />
 </template>
 <script setup lang="ts">
 defineOptions({ name: 'AttendanceDep' })
@@ -155,6 +166,7 @@ import moment from 'moment'
 import { depsState } from './depsState'
 import ExportToExcel from '@/components/ExportToExcel/index.vue'
 import { getUserInfo } from '@/utils/tool'
+import AttendanceSheetImportForm from './components/attendanceSheetImportForm.vue'
 const userInfo = getUserInfo()
 
 const porps = defineProps(['deptsName'])
@@ -358,7 +370,14 @@ const getExcelTable = (attendanceData) => {
   return [...tableHead, ...tableBody]
 }
 
-onMounted(() => {
+/** 考勤导入 */
+const importFormRef = ref()
+const handleImport = () => {
+  importFormRef.value.open()
+}
+
+/** 初始化 */
+const init = () => {
   let toMonth = moment().format('YYYY-MM')
   fromParams.value.month = toMonth
   // 加载部门树
@@ -367,6 +386,10 @@ onMounted(() => {
   toMoseMonths[0] = moment().startOf('months').format('YYYY-MM-DD') + ' 00:00:00'
   toMoseMonths[1] = moment().endOf('months').format('YYYY-MM-DD') + ' 23:59:59'
   initInsMouth(toMoseMonths)
+}
+
+onMounted(() => {
+  init()
 })
 </script>
 <style lang="scss" scoped>