import.vue 3.65 KB
<template>
  <el-dialog v-model="show" title="人员上传" width="400px" append-to-body draggable>
    <el-upload
      ref="uploadRef"
      :limit="1"
      accept=".xlsx, .xls"
      :headers="upload.headers"
      :action="upload.url"
      :disabled="upload.isUploading"
      :on-progress="handleFileUploadProgress"
      :on-success="handleFileSuccess"
      :auto-upload="false"
      drag
      name="file"
    >
      <el-icon class="el-icon--upload"><upload-filled /></el-icon>
      <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
      <template #tip>
        <div class="el-upload__tip text-center">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <!-- 会员 -->
          <el-link v-if="type==1" href="/file/member.xlsx" type="primary" target="_blank">下载模板</el-link>
          <!-- 教练 -->
          <el-link v-if="type==2" href="/file/coach.xlsx" type="primary" target="_blank">下载模板</el-link>
          <!-- 考官晋级 -->
          <el-link v-if="type==5" href="/file/examiner.xlsx" type="primary" target="_blank">下载模板</el-link>
          <!-- 考官晋段 -->
          <el-link v-if="type==3" href="/file/examiner.xlsx" type="primary" target="_blank">下载模板</el-link>
          <!-- 裁判 -->
          <el-link v-if="type==4" href="/file/umpire.xlsx" type="primary" target="_blank">下载模板</el-link>

        </div>
      </template>
    </el-upload>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="show = false">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { reactive } from '@vue/runtime-core'
import { getToken } from '@/utils/auth'
import { getCurrentInstance, ref } from 'vue'

const { proxy } = getCurrentInstance()
const emit = defineEmits(['uploaded'])
const type = ref()
const show = ref(false)

const upload = reactive({
  // 是否禁用上传
  isUploading: false,
  // 设置上传的请求头部
  headers: { Authorization: 'Bearer ' + getToken() },
  // 上传的地址
  url: ''
})

function submitFileForm() {
  proxy.$refs['uploadRef'].submit()
}

const handleFileUploadProgress = (event, file, fileList) => {
  upload.isUploading = true
}

const handleFileSuccess = (response, file, fileList) => {
  show.value = false
  upload.isUploading = false
  proxy.$refs['uploadRef'].handleRemove(file)
  emit('uploaded')
  // if (response == '全部导入成功。\r\n') {
  //   proxy.$modal.msgSuccess('导入成功!')
  //   emit('uploaded')
  // } else {
  //   proxy.$modal.msgError('导入失败!')
  //   emit('uploaded')
  // }
  proxy.$alert(
    "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
      response +
      '</div>',
    '导入结果',
    { dangerouslyUseHTMLString: true }
  ).then(() => {
    emit('uploaded')
  })
}

function open(row) {
  type.value = row
  console.log(row)
  
  // 会员
  if (row == 1) {
    upload.url = `${import.meta.env.VITE_APP_BASE_API}/person/info/importPersonMember`
  }
  // 教练
  if (row == 2) {
    upload.url = `${import.meta.env.VITE_APP_BASE_API}/person/info/importCoach`
  }
  // 晋级考官
  if (row == 3) {
    upload.url = `${import.meta.env.VITE_APP_BASE_API}/person/info/importJiExaminer`
  }
  // 晋段考官
  if (row == 5) {
    upload.url = `${import.meta.env.VITE_APP_BASE_API}/person/info/importDuanExaminer`
  }
  // 裁判
  if (row == 4) {
    upload.url = `${import.meta.env.VITE_APP_BASE_API}/person/info/importReferee`
  }
  show.value = true
}

defineExpose({
  open
})

</script>
<style scoped>

</style>