吉安感知网项目-前端
张含笑
2026-01-30 6c4bd2467bb6651c6edcf8a9741dcd4e9b1aa6d3
applications/task-work-order/src/views/orderView/organizational/agenciesManagement/index.vue
@@ -105,17 +105,26 @@
      @close="handleImportClose"
    >
      <el-form class="gd-dialog-form" ref="importFormRef" :model="importParams" :rules="importRules" label-width="140px">
        <el-form-item label="导出模板">
          <el-button
            color="#F2F3F5"
            type="primary"
            @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>
      <template #footer>
        <el-button color="#F2F3F5" @click="isShowImportView = false">取消</el-button>
        <el-button
          class=""
          color="#4C34FF"
          :loading="importSubmitting"
          :disabled="importSubmitting"
@@ -138,6 +147,7 @@
  agenciesRemoveApi,
  agenciesImportApi,
  agenciesExportApi,
  agenciesExportTemplateApi,
  regionLazyTreeApi,
  agenciesSubmitApi
} from './agenciesApi'
@@ -186,6 +196,9 @@
// 导出加载状态
const exportLoading = ref(false)
// 模板导出加载状态
const templateExportLoading = ref(false)
provide('regionOptions', regionOptions)
provide('dictObj', dictObj)
@@ -220,9 +233,6 @@
    resolve([])
  }
}
// 获取列表
async function getList() {
  loading.value = true
@@ -305,8 +315,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()