| | |
| | | @close="handleImportClose" |
| | | > |
| | | <el-form class="gd-dialog-form" ref="importFormRef" :model="importParams" :rules="importRules" label-width="140px"> |
| | | <el-form-item label="导出模板"> |
| | | <el-button |
| | | type="primary" |
| | | :loading="templateExportLoading" |
| | | :disabled="templateExportLoading" |
| | | @click="handleExportTemplate" |
| | | > |
| | | 点击导出 |
| | | </el-button> |
| | | </el-form-item> |
| | | <el-form-item label="上传文件" prop="file"> |
| | | {{ importFileName }} |
| | | <el-upload class="avatar-uploader" action="" :show-file-list="false" :before-upload="onImportFileBefore"> |
| | | <el-button size="small" type="primary">点击上传</el-button> |
| | | <el-button type="primary">点击上传</el-button> |
| | | </el-upload> |
| | | </el-form-item> |
| | | </el-form> |
| | |
| | | zoningRemoveApi, |
| | | zoningImportApi, |
| | | zoningExportApi, |
| | | zoningExportTemplateApi, |
| | | regionLazyTreeApi, |
| | | zoningSubmitApi |
| | | } from './zoningApi' |
| | |
| | | |
| | | // 导出加载状态 |
| | | const exportLoading = ref(false) |
| | | |
| | | // 模板导出加载状态 |
| | | const templateExportLoading = ref(false) |
| | | |
| | | provide('regionOptions', regionOptions) |
| | | provide('dictObj', dictObj) |
| | |
| | | } |
| | | } |
| | | |
| | | // 导出模板 |
| | | async function handleExportTemplate() { |
| | | templateExportLoading.value = true |
| | | try { |
| | | const res = await zoningExportTemplateApi() |
| | | const blob = new Blob([res.data]) |
| | | const url = URL.createObjectURL(blob) |
| | | const a = document.createElement('a') |
| | | a.href = url |
| | | a.download = `区划导入模板.xlsx` |
| | | document.body.appendChild(a) |
| | | a.click() |
| | | document.body.removeChild(a) |
| | | URL.revokeObjectURL(url) |
| | | } catch (error) { |
| | | console.error('导出模板失败:', error) |
| | | } finally { |
| | | templateExportLoading.value = false |
| | | } |
| | | } |
| | | |
| | | // 上传文件前处理 |
| | | function onImportFileBefore(file) { |
| | | // 提示请先导出模板 |
| | | // ElMessage.warning('请先导出模板并按模板格式填写数据') |
| | | |
| | | // 检查文件类型 |
| | | const allowedTypes = ['.xlsx', '.xls'] |
| | | const fileExtension = file.name.substring(file.name.lastIndexOf('.')).toLowerCase() |