吉安感知网项目-前端
张含笑
2026-01-29 acfd3a73b5650788b875543d75749d9f93914f56
feat:导出模板
1 files modified
43 ■■■■■ changed files
applications/task-work-order/src/views/orderView/organizational/agenciesManagement/index.vue 43 ●●●●● patch | view | raw | blame | history
applications/task-work-order/src/views/orderView/organizational/agenciesManagement/index.vue
@@ -105,10 +105,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>
@@ -138,6 +148,7 @@
  agenciesRemoveApi,
  agenciesImportApi,
  agenciesExportApi,
  agenciesExportTemplateApi,
  regionLazyTreeApi,
  agenciesSubmitApi
} from './agenciesApi'
@@ -186,6 +197,9 @@
// 导出加载状态
const exportLoading = ref(false)
// 模板导出加载状态
const templateExportLoading = ref(false)
provide('regionOptions', regionOptions)
provide('dictObj', dictObj)
@@ -220,9 +234,6 @@
    resolve([])
  }
}
// 获取列表
async function getList() {
  loading.value = true
@@ -305,8 +316,32 @@
  }
}
// 导出模板
async function handleExportTemplate() {
  templateExportLoading.value = true
  try {
    const res = await agenciesExportTemplateApi()
    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()