小区调整

master
zzy 2026-04-20 16:45:14 +08:00
parent 3e4feedc35
commit 25f79e9d61
3 changed files with 167 additions and 1 deletions

View File

@ -45,5 +45,9 @@ export const CommunityApi = {
exportCommunity: async (params) => { exportCommunity: async (params) => {
return await request.download({ url: `/community/community/export-excel`, params }) return await request.download({ url: `/community/community/export-excel`, params })
},
importCommunityTemplate: async () => {
return await request.download({ url: `/community/community/get-import-template` })
} }
} }

View File

@ -0,0 +1,145 @@
<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 { CommunityApi } from '@/api/community/community'
import { getAccessToken, getTenantId } from '@/utils/auth'
import download from '@/utils/download'
defineOptions({ name: 'CommunityImportForm' })
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 + '/community/community/import'
const uploadHeaders = ref()
const fileList = ref([])
const updateSupport = ref(0)
/** 打开弹窗 */
const open = () => {
dialogVisible.value = true
updateSupport.value = 0
fileList.value = []
resetForm()
}
defineExpose({ 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)
resetForm()
return
}
const data = response.data
const createCount = data.createCommunityNames?.length || 0
const updateCount = data.updateCommunityNames?.length || 0
const failureCount = Object.keys(data.failureCommunities || {}).length
let text = `创建成功:${createCount} 条;`
if (createCount > 0) {
text += '\n创建的小区' + data.createCommunityNames.join('、')
}
text += `\n更新成功${updateCount} 条;`
if (updateCount > 0) {
text += '\n更新的小区' + data.updateCommunityNames.join('、')
}
text += `\n导入失败${failureCount} 条;`
if (failureCount > 0) {
text += '\n失败详情'
for (const [name, reason] of Object.entries(data.failureCommunities)) {
text += `\n - ${name}: ${reason}`
}
}
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 CommunityApi.importCommunityTemplate()
download.excel(res, '小区信息导入模版.xls')
}
</script>

View File

@ -57,6 +57,14 @@
> >
<Icon icon="ep:plus" class="mr-5px" /> 新增 <Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button> </el-button>
<el-button
type="primary"
plain
@click="handleImport"
v-hasPermi="['community:community:import']"
>
<Icon icon="ep:upload" class="mr-5px" /> 导入
</el-button>
<el-button <el-button
type="primary" type="primary"
plain plain
@ -145,14 +153,17 @@
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<CommunityForm ref="formRef" @success="handleFormSuccess" /> <CommunityForm ref="formRef" @success="handleFormSuccess" />
<!-- 导入弹窗 -->
<CommunityImportForm ref="importFormRef" @success="handleFormSuccess" />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { isEmpty } from '@/utils/is' import { isEmpty } from '@/utils/is'
import download from '@/utils/download' import download from '@/utils/download'
import { CommunityApi, Community } from '@/api/community/community' import { CommunityApi, Community } from '@/api/community/community'
import { DICT_TYPE } from '@/utils/dict'
import CommunityForm from './CommunityForm.vue' import CommunityForm from './CommunityForm.vue'
import CommunityImportForm from './components/CommunityImportForm.vue'
/** 小区信息主表comm_community 列表 */ /** 小区信息主表comm_community 列表 */
defineOptions({ name: 'Community' }) defineOptions({ name: 'Community' })
@ -203,6 +214,12 @@ const openForm = (type: string, id?: number) => {
formRef.value.open(type, id) formRef.value.open(type, id)
} }
/** 导入操作 */
const importFormRef = ref()
const handleImport = () => {
importFormRef.value.open()
}
/** 表单提交成功回调 */ /** 表单提交成功回调 */
const handleFormSuccess = async () => { const handleFormSuccess = async () => {
await getList() await getList()