吉安感知网项目-前端
张含笑
2026-01-29 32956b2e07d023f90e408d3ff905e5e67c8c0b20
feat:区划导出模板
2 files modified
49 ■■■■■ changed files
applications/task-work-order/src/views/orderView/organizational/zoningManagement/index.vue 40 ●●●●● patch | view | raw | blame | history
applications/task-work-order/src/views/orderView/organizational/zoningManagement/zoningApi.js 9 ●●●●● patch | view | raw | blame | history
applications/task-work-order/src/views/orderView/organizational/zoningManagement/index.vue
@@ -102,10 +102,20 @@
      @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>
@@ -135,6 +145,7 @@
  zoningRemoveApi,
  zoningImportApi,
  zoningExportApi,
  zoningExportTemplateApi,
  regionLazyTreeApi,
  zoningSubmitApi
} from './zoningApi'
@@ -174,6 +185,9 @@
// 导出加载状态
const exportLoading = ref(false)
// 模板导出加载状态
const templateExportLoading = ref(false)
provide('regionOptions', regionOptions)
provide('dictObj', dictObj)
@@ -267,8 +281,32 @@
  }
}
// 导出模板
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()
applications/task-work-order/src/views/orderView/organizational/zoningManagement/zoningApi.js
@@ -56,6 +56,15 @@
  })
}
// 导出模板
export const zoningExportTemplateApi = () => {
  return request({
    url: `/blade-system/region/export-template`,
    method: 'get',
    responseType: 'blob',
  })
}
// 懒加载列表
export const regionLazyTreeApi = params => {
  return request({