• 导入,导出


    <el-button type="primary" @click="exportData">
          <svg-icon class="svg-icon-btn" icon-class="asset_export_excel" />
          导出
        </el-button>
     
     
     
     
    import download from '@/base/utils/download'
    // 导出
        exportData() {
          const formInline = this.$refs.TableArea.formInline
          exportData(formInline).then(res => {
            download(res, '单位会计科目')
          })
        }
     
    download.js
    /**
     * @default 导出
     */
    import { parseTime } from './index'

    export default function download(response, name) {
      const blob = new Blob([response], { type: 'application/vnd.ms-excel;charset=utf-8' })
      const downloadElement = document.createElement('a')
      const href = window.URL.createObjectURL(blob)
      downloadElement.href = href
      downloadElement.download = name + parseTime(+new Date()) + '.xls'
      document.body.appendChild(downloadElement)
      downloadElement.click()
      document.body.removeChild(downloadElement)
      window.URL.revokeObjectURL(href)
    }
     
     
     
    <ImportFile
          :file-name="'财政会计科目'"
          :http-url="'http://39.104.108.253:9909/account/importData'"
          :is-import="false"
          @refresh="refreshEvent"
        />
     
     
    ImportFile组件
    <el-upload
          v-if="isOutput && !isChoice"
          action=""
          :http-request="importOutitem"
          :show-file-list="false"
          :file-list="fileList"
          :limit="1"
          accept=".xlsx"
          style="display: inline-block; margin:0 10px;"
          @on-exceed="fileExceed"
        >
          <el-button type="primary" :loading="loading"><svg-icon class="svg-icon-btn" icon-class="Import" />{{ buttonText }}</el-button>
        </el-upload>
     
    importOutitem(val) {
          this.loading = true
          const form = new FormData()
          form.append('fileName', val.file)
          request({
            url: this.isChoice ? `/${this.httpUrl}/${this.intRemind}` : `${this.httpUrl}`,
            method: 'post',
            data: form,
            timeout: Infinity,
            'Content-Type': 'multipart/form-data'
          }).then(res => {
            if (res.code === 20000) {
              const temp = {}
              const arr = []
              for (var p in res.data.columnlist) {
                if (p === 'strreason') {
                  temp.label = res.data.columnlist[p]
                  temp.prop = p
                } else {
                  arr.push({
                    label: res.data.columnlist[p],
                    prop: p
                  })
                }
              }
              this.head = arr.sort((a, b) => { return a.prop.match(/\d+/g) - b.prop.match(/\d+/g) })
              this.head.unshift(temp)
              this.list = res.data.importtemplatelist
              this.dialog.isShow = true
              this.$emit('refresh')
            }
            this.loading = false
            this.fileList = []
          }).catch(err => {
            this.loading = false
            console.log('catch ' + err) // catch error
            this.fileList = []
          })
        }
     
     
     
    //普通的导入
    <el-upload
          action=""
          :http-request="uploadFile"
          :show-file-list="false"
          accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
        >
          <el-button type="primary" :loading="importLoading"><svg-icon class="svg-icon-btn" icon-class="Import" />导入</el-button>
        </el-upload>
     
     
    //  导入数据
        uploadFile(item) {
          this.importLoading = true
          const form = new FormData()
          form.append('file', item.file)
          importAccount(form).then(res => {
            this.importLoading = false
            if (res.code === 20000) {
              this.$message.success(res.message)
            }
            this.refreshEvent()
          })
        }
  • 相关阅读:
    Pyinstaller打包多个py文件
    Oracle 数据库基础教程之用户管理
    Navicat连接Oracle报错ORA-28547
    Oracle 激活用户及重置密码
    coding公钥配置教程
    关于联想笔记本小新自动关机解决方法
    PIP镜像像源
    Bugku——Web——web基础$_POST
    Bugku——Web——web基础$_GET
    Bugku——Web——计算器
  • 原文地址:https://www.cnblogs.com/hellofangfang/p/15528857.html
Copyright © 2020-2023  润新知