doum
2025-09-26 9057e04efad1b7d61c77a72e5c37a504d0aee935
admin/src/components/common/ImportWindow.vue
@@ -9,33 +9,27 @@
    :close-on-press-escape="false"
    :show-close="false"
  >
    <el-form>
      <el-form-item>
        <el-upload
          drag
          :show-file-list="false"
          action="none"
          accept=".xlsx, .xls"
          :before-upload="handleBeforeUpload"
        >
          <template v-if="form.file == null">
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
          </template>
          <template v-else>
            <i class="el-icon-files"></i>
            <div class="el-upload__text">{{form.file.name}}<em></em></div>
          </template>
        </el-upload>
      </el-form-item>
    </el-form>
    <el-upload
      drag
      :show-file-list="false"
      action="none"
      accept=".xlsx"
      :before-upload="handleBeforeUpload"
    >
      <template v-if="form.file == null">
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
      </template>
      <template v-else>
        <i class="el-icon-files"></i>
        <div class="el-upload__text">{{form.file.name}}<em></em></div>
      </template>
    </el-upload>
    <div slot="footer" class="import-window__footer">
      <!-- <div class="sync-exists">
      <div class="sync-exists">
        <el-checkbox v-model="form.sync"/><span>同步已存在的数据</span>
      </div> -->
      </div>
      <div class="opera">
        <a href=""></a>
        <el-button type="text" icon="el-icon-download" @click="downloadTemplate">下载模版</el-button>
        <el-button @click="cancel">{{cancelText}}</el-button>
        <el-button type="primary" @click="confirm" :loading="isWorking">{{confirmText}}</el-button>
@@ -46,6 +40,7 @@
<script>
import request from '@/utils/request'
import { downloadLocalFile } from '@/api/system/common'
export default {
  name: 'ImportWindow',
  props: {
@@ -58,7 +53,6 @@
      type: String,
      default: '导入'
    },
    // 取消按钮文案
    cancelText: {
      type: String,
@@ -80,8 +74,7 @@
      title: '导入数据',
      form: {
        sync: false,
        file: false,
        categoryId: ''
        file: false
      }
    }
  },
@@ -108,18 +101,19 @@
      this.isWorking = true
      const param = new FormData()
      param.set('file', this.form.file)
      param.set('sync', this.form.sync)
      request.post(this.action, param, {
        headers: {
          'Content-Type': 'multipart/form-data;charset=UTF-8'
        }
      })
        .then(() => {
          this.$tip.success('导入成功')
        .then(data => {
          this.$tip.success('导入成功,共导入' + data + '条记录')
          this.visible = false
          this.$emit('success')
        })
        .catch(e => {
         //  this.$tip.apiFailed(e)
          this.$tip.apiFailed(e)
        })
        .finally(() => {
          this.isWorking = false
@@ -135,12 +129,16 @@
     * 下载模版
     */
    downloadTemplate () {
      const link = document.createElement('a')
      link.setAttribute('download', this.templateName) //下载的文件名
      console.log(`${window.location.origin}${process.env.VUE_APP_CONTEXT_PATH}${this.templatePath}`);
      link.href = `${window.location.origin}${process.env.VUE_APP_CONTEXT_PATH}${this.templatePath}`  //文件url
      link.click()
      // this.$emit('download')
      downloadLocalFile({
        path: this.templatePath,
        name: this.templateName
      })
        .then(data => {
          this.download(data)
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
    },
    /**
     * 文件上传前存储上传的文件