小区调整
parent
3e4feedc35
commit
25f79e9d61
|
|
@ -45,5 +45,9 @@ export const CommunityApi = {
|
|||
|
||||
exportCommunity: async (params) => {
|
||||
return await request.download({ url: `/community/community/export-excel`, params })
|
||||
},
|
||||
|
||||
importCommunityTemplate: async () => {
|
||||
return await request.download({ url: `/community/community/get-import-template` })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>仅允许导入 xls、xlsx 格式文件。</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>
|
||||
|
|
@ -57,6 +57,14 @@
|
|||
>
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||
</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
|
||||
type="primary"
|
||||
plain
|
||||
|
|
@ -145,14 +153,17 @@
|
|||
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<CommunityForm ref="formRef" @success="handleFormSuccess" />
|
||||
|
||||
<!-- 导入弹窗 -->
|
||||
<CommunityImportForm ref="importFormRef" @success="handleFormSuccess" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { isEmpty } from '@/utils/is'
|
||||
import download from '@/utils/download'
|
||||
import { CommunityApi, Community } from '@/api/community/community'
|
||||
import { DICT_TYPE } from '@/utils/dict'
|
||||
import CommunityForm from './CommunityForm.vue'
|
||||
import CommunityImportForm from './components/CommunityImportForm.vue'
|
||||
|
||||
/** 小区信息主表(comm_community) 列表 */
|
||||
defineOptions({ name: 'Community' })
|
||||
|
|
@ -203,6 +214,12 @@ const openForm = (type: string, id?: number) => {
|
|||
formRef.value.open(type, id)
|
||||
}
|
||||
|
||||
/** 导入操作 */
|
||||
const importFormRef = ref()
|
||||
const handleImport = () => {
|
||||
importFormRef.value.open()
|
||||
}
|
||||
|
||||
/** 表单提交成功回调 */
|
||||
const handleFormSuccess = async () => {
|
||||
await getList()
|
||||
|
|
|
|||
Loading…
Reference in New Issue