龚焕茏
2024-07-11 f7fba7469eb458c000bdad97a2c130a9e9ea212b
src/views/exam/question/list.vue
@@ -28,6 +28,18 @@
          </el-button>
          <el-button slot="reference" type="primary" class="link-left">添加</el-button>
        </el-popover>
        <el-button class="link-left" type="danger" @click="downloadImportTemplate">下载模板</el-button>
        <el-upload
          style="display: inline;"
          class="op-item link-left"
          action="/api/admin/question/import"
          :with-credentials="true"
          :on-success="handlePreview"
          accept=".xls,.xlsx"
          :show-file-list="false"
          :before-upload="beforeAvatarUpload">
          <el-button v-loading="importLoading" type="primary">导入</el-button>
        </el-upload>
      </el-form-item>
    </el-form>
    <el-table v-loading="listLoading" :data="tableData" border fit highlight-current-row style="width: 100%">
@@ -73,11 +85,13 @@
import Pagination from '@/components/Pagination'
import QuestionShow from './components/Show'
import questionApi from '@/api/question'
import { downloadExcel } from '@/utils/download'
export default {
  components: { Pagination, QuestionShow },
  data() {
    return {
      importLoading: '',
      queryParam: {
        id: null,
        questionType: null,
@@ -103,6 +117,33 @@
    this.search()
  },
  methods: {
    handlePreview (e) {
      this.importLoading = false
      if (e.code === 1) {
        this.search()
        this.$message.success(e.message)
      } else {
        this.$message.error(e.message)
      }
    },
    beforeAvatarUpload (file) {
      this.importLoading = true
      let legalName = ['xlsx', 'xls']
      // 拿到后缀名
      let name = file.name.substring(file.name.lastIndexOf('.') + 1, file.name.length)
      if (legalName.includes(name)) {
        // console.log(legalName.includes(name));
      } else {
        this.$message.warning('请上传xls、xlsx文件')
        return false
      }
    },
    // 下载导入模板
    downloadImportTemplate() {
      questionApi.downloadImportTemplate().then(res => {
        downloadExcel(res, '题目导入模板')
      })
    },
    statusQuestion(row) {
      let question = {
        id: row.id,