|  |  | 
 |  |  |     :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> | 
 |  |  | 
 |  |  |  | 
 |  |  | <script> | 
 |  |  | import request from '@/utils/request' | 
 |  |  | import { downloadLocalFile } from '@/api/system/common' | 
 |  |  | export default { | 
 |  |  |   name: 'ImportWindow', | 
 |  |  |   props: { | 
 |  |  | 
 |  |  |       type: String, | 
 |  |  |       default: '导入' | 
 |  |  |     }, | 
 |  |  |      | 
 |  |  |     // 取消按钮文案 | 
 |  |  |     cancelText: { | 
 |  |  |       type: String, | 
 |  |  | 
 |  |  |       title: '导入数据', | 
 |  |  |       form: { | 
 |  |  |         sync: false, | 
 |  |  |         file: false, | 
 |  |  |         categoryId: '' | 
 |  |  |         file: false | 
 |  |  |       } | 
 |  |  |     } | 
 |  |  |   }, | 
 |  |  | 
 |  |  |       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 | 
 |  |  | 
 |  |  |      * 下载模版 | 
 |  |  |      */ | 
 |  |  |     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) | 
 |  |  |         }) | 
 |  |  |     }, | 
 |  |  |     /** | 
 |  |  |      * 文件上传前存储上传的文件 |