Skip to content

Commit

Permalink
style: 优化导入用户部分界面及接口路径
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Oct 30, 2024
1 parent 146637c commit 881c7e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/apis/system/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ export function resetUserPwd(data: any, id: string) {
}

/** @desc 下载用户导入模板 */
export function downloadImportUserTemplate() {
return http.download(`${BASE_URL}/downloadImportUserTemplate`)
export function downloadUserImportTemplate() {
return http.download(`${BASE_URL}/import/template`)
}

/** @desc 解析用户导入数据 */
export function parseImportUser(data: FormData) {
return http.post(`${BASE_URL}/parseImportUser`, data)
return http.post(`${BASE_URL}/import/parse`, data)
}

/** @desc 导入用户 */
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/modules/useDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Message, Notification } from '@arco-design/web-vue'
interface NavigatorWithMsSaveOrOpenBlob extends Navigator {
msSaveOrOpenBlob: (blob: Blob, fileName: string) => void
}
export const useDownload = async (api: () => Promise<any>, isNotify = true, tempName = '', fileType = '.xlsx') => {
export const useDownload = async (api: () => Promise<any>, isNotify = false, tempName = '', fileType = '.xlsx') => {
try {
const res = await api()
if (res.headers['content-disposition']) {
Expand Down
23 changes: 16 additions & 7 deletions src/views/system/user/UserImportDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
@close="reset"
>
<a-form ref="formRef" :model="form" size="large" auto-label-width>
<a-alert v-if="!form.disabled" :show-icon="false" style="margin-bottom: 15px">
数据导入请严格按照模板填写,格式要求和新增一致!
<a-alert v-if="!form.disabled" style="margin-bottom: 15px">
请按照模板要求填写数据,填写完毕后,请先上传并进行解析。
<template #action>
<a-button size="small" type="primary" @click="downloadTemplate">下载模板</a-button>
<a-link @click="downloadTemplate">
<template #icon><GiSvgIcon name="file-excel" :size="16" /></template>
<template #default>下载模板</template>
</a-link>
</template>
</a-alert>
<fieldset>
<legend>1.上传解析文件</legend>
<legend>1.解析数据</legend>
<div class="file-box">
<a-upload
draggable
Expand Down Expand Up @@ -85,7 +88,12 @@
<script setup lang="ts">
import { type FormInstance, Message, type RequestOption } from '@arco-design/web-vue'
import { useWindowSize } from '@vueuse/core'
import { type UserImportResp, downloadImportUserTemplate, importUser, parseImportUser } from '@/apis/system'
import {
type UserImportResp,
downloadUserImportTemplate,
importUser,
parseImportUser,
} from '@/apis/system/user'
import { useDownload, useForm } from '@/hooks'
const emit = defineEmits<{
Expand Down Expand Up @@ -129,7 +137,7 @@ const onImport = () => {
// 下载模板
const downloadTemplate = () => {
useDownload(() => downloadImportUserTemplate())
useDownload(() => downloadUserImportTemplate())
}
// 上传解析导入数据
Expand Down Expand Up @@ -160,11 +168,12 @@ const handleUpload = (options: RequestOption) => {
const save = async () => {
try {
if (!dataResult.value.importKey) {
Message.warning('请先上传文件,解析导入数据')
return false
}
form.importKey = dataResult.value.importKey
const res = await importUser(form)
Message.success(`导入成功新增${res.data.insertRows},修改${res.data.updateRows}`)
Message.success(`导入成功! 新增${res.data.insertRows}, 修改${res.data.updateRows}`)
emit('save-success')
return true
} catch (error) {
Expand Down

0 comments on commit 881c7e7

Please sign in to comment.