Files
biz-pc-cloud-zax/src/views/admin/system/user/components/user-import-excel.vue
T
2026-07-28 11:32:52 +08:00

73 lines
2.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- 用户导入组件:按所选用户类型同步切换导入接口和模板。 -->
<template>
<upload-excel ref="uploadExcelRef" title="用户导入" :temp-url="currentImportOption.tempUrl"
:url="currentImportOption.url" @refreshDataList="handleRefreshDataList">
<template #before-upload="{ uploading }">
<el-form class="mb20" :model="form" label-width="90px">
<el-form-item label="导入类型" prop="importType" required class="mb20">
<el-select v-model="form.importType" placeholder="请选择导入类型" class="w100" :disabled="uploading">
<el-option v-for="item in importOptions" :key="item.value" :label="item.label"
:value="item.value" :disabled="!auth(item.permission)" />
</el-select>
</el-form-item>
</el-form>
</template>
</upload-excel>
</template>
<script setup lang="ts" name="user-import-excel">
import UploadExcel from "/@/components/Upload/Excel.vue"
import { auth } from "/@/utils/authFunction"
type UserImportType = "backend" | "student"
interface UserImportOption {
value: UserImportType
label: string
url: string
tempUrl: string
permission: string
}
const emit = defineEmits(["refreshDataList"])
// 接口和模板保持在同一份配置中,避免切换导入类型时二者不一致。
const importOptions: UserImportOption[] = [
{
value: "backend",
label: "后台用户",
url: "/admin/user/import-face",
tempUrl: "/admin/sys-file/local/file/user.xlsx",
permission: "sys_user_export",
},
{
value: "student",
label: "学生用户",
url: "/admin/user/import-student",
tempUrl: "/admin/sys-file/local/file/student_user_import.xlsx",
permission: "sys_student_user_export",
},
]
const uploadExcelRef = ref()
const form = reactive({
importType: "backend" as UserImportType,
})
const currentImportOption = computed(() => importOptions.find((item) => item.value === form.importType) ?? importOptions[0])
const handleRefreshDataList = () => {
emit("refreshDataList")
}
/** 每次打开优先恢复为后台用户导入;仅有学生导入权限时自动选中学生用户。 */
const show = () => {
form.importType = auth(importOptions[0].permission) ? "backend" : "student"
uploadExcelRef.value?.show()
}
defineExpose({
show,
})
</script>