xiangpei
2024-08-06 e6df5a867a614e257558f0ce549c1083ed22d5bc
点位导入导出
2个文件已修改
100 ■■■■■ 已修改文件
src/api/platform/point.js 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/system/point/index.vue 78 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/platform/point.js
@@ -70,3 +70,25 @@
    params: param
  })
}
// 导出
export function exportData(param) {
  return request({
    url: '/yw-point/export',
    method: 'get',
    params: param,
    responseType: 'blob'
  })
}
// 导入
export function importData(data, unitId) {
  return request({
    url: '/yw-point/import/' + unitId,
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
src/views/system/point/index.vue
@@ -29,8 +29,36 @@
          v-hasPermi="['point:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-top" size="mini" @click="handleImportPoint"
          v-hasPermi="['point:import']">导入点位</el-button>
        <el-button type="primary" plain icon="el-icon-bottom" v-loading="download" size="mini" @click="handleExport"
                   v-hasPermi="['point:export']">导出点位</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-popover>
          <div>
            <el-select v-model="importUnitId" size="small" placeholder="负责单位">
              <el-option v-for="unit in unitList" :key="unit.id" :label="unit.value" :value="unit.id"></el-option>
            </el-select>
          </div>
          <div>
            <el-upload
              ref="upload"
              class="upload-demo"
              drag
              :action="importUrl"
              :file-list="fileList"
              :before-upload="beforeUpload"
              >
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
              <div class="el-upload__tip" slot="tip">只能上传xls/xlsx文件</div>
            </el-upload>
          </div>
          <div>
            <el-button type="primary" size="small" v-model="upload" :disabled="! importUnitId || ! importFile"  @click="handleImport" style="width: 100%; margin-top: 5px"
                       v-hasPermi="['point:import']">导入</el-button>
          </div>
          <el-button type="primary" size="mini" plain icon="el-icon-top" slot="reference">导入点位</el-button>
        </el-popover>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-receiving" size="mini" @click="handleEditBatch"
@@ -156,7 +184,7 @@
</template>
<script>
import { listPoint, getPoint, delPoint, addPoint, batchEdit, updatePoint } from "@/api/platform/point";
import { listPoint, getPoint, delPoint, addPoint, batchEdit, updatePoint, exportData, importData } from "@/api/platform/point";
import { unitSelect } from "@/api/platform/unit";
import { getCascader } from '@/api/platform/region'
import { cascader } from '@/api/system/dept'
@@ -166,6 +194,12 @@
  dicts: ['point_tag'],
  data() {
    return {
      fileList: [],
      importFile: null,
      importUrl: '',
      importUnitId: null,
      download: false,
      upload: false,
      deptOptions: [],
      // 批量修改表单
      batchEditForm: {
@@ -240,9 +274,39 @@
    this.getDeptCascader();
  },
  methods: {
    beforeUpload(file) {
      this.importFile = file
      this.fileList = [file]
      return false
    },
    // 点位导入
    handleImportPoint() {
    handleImport() {
      this.upload =true;
      let formData = new FormData()
      formData.append("file", this.importFile)
      importData(formData, this.importUnitId).then(res => {
        this.$message.success("导入成功")
        this.upload = false
      })
    },
    // 点位导出
    handleExport() {
      this.download = true
      exportData(this.queryParams).then(res => {
        // 将二进制数据转换为 Blob 对象
        let blob = new Blob([res], { type: 'application/octet-stream' });
        // 创建下载链接
        let downloadLink = document.createElement('a');
        downloadLink.href = URL.createObjectURL(blob);
        downloadLink.setAttribute('download', "点位更换运维单位.xlsx"); // 设置下载文件的文件名
        downloadLink.style.display = 'none';
        // 添加到页面并触发下载
        document.body.appendChild(downloadLink);
        downloadLink.click();
        document.body.removeChild(downloadLink);
        this.download = false
      })
    },
    cos(value) {
      console.log(value)
@@ -394,12 +458,6 @@
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('x/point/export', {
        ...this.queryParams
      }, `point_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>