chenrui
2025-03-28 5692bc829ac5cb1b1fbd113a89c44d2d3c3a41ee
插回损功能开发
已修改1个文件
已添加2个文件
318 ■■■■■ 文件已修改
src/api/equipment/lossRecord.js 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/util/fileTransform.js 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/equipment/lossrecord/index.vue 245 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/equipment/lossRecord.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,51 @@
/*
 * @Descripttion:
 * @version:
 * @Author: zt_lc
 * @Date: 2022-02-10 14:24:32
 * @LastEditors: zt_lc
 * @LastEditTime: 2022-05-31 17:30:32
 */
/*
 *    Copyright (c) 2018-2025, ztt All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: ztt
 */
import request from '@/router/axios'
export function syncLossRecordFile(query) {
  return request({
    url: '/mes/lossRecordController/syncLossRecordFile',
    method: 'get',
    params: query
  })
}
export function recordList(query) {
  return request({
    url: '/mes/lossRecordController/page',
    method: 'get',
    params: query
  })
}
export function downloadLossWord(query) {
  return request({
    url: '/mes/lossRecordController/downloadLossWord',
    method: 'get',
    responseType: 'blob',
    params: query
  })
}
src/util/fileTransform.js
@@ -36,4 +36,24 @@
    URL.revokeObjectURL(elink.href) // é‡Šæ”¾URL å¯¹è±¡
    document.body.removeChild(elink)
  }
}
}
export function transformDoc(response) {
    const relType = ['application/vnd.openxmlformats-officedocument.wordprocessingml.document']
    let type = response.data.type
    if (relType.includes(type)) {
        const blob = new Blob([response.data], {type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'})
        const disposition = response.headers["content-disposition"]
        let temp = disposition.substring(disposition.lastIndexOf('=') + 1)
        let filename = decodeURI(temp)
        // åˆ›å»ºä¸€ä¸ªè¶…链接,将文件流赋进去,然后实现这个超链接的单击事件
        const elink = document.createElement('a')
        elink.download = filename
        elink.style.display = 'none'
        elink.href = URL.createObjectURL(blob)
        document.body.appendChild(elink)
        elink.click()
        URL.revokeObjectURL(elink.href) // é‡Šæ”¾URL å¯¹è±¡
        document.body.removeChild(elink)
    }
}
src/views/equipment/lossrecord/index.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,245 @@
<template>
  <div class="mod-config">
    <basic-container>
      <ttable
        :table="table"
        @handleSelectionChange="handleSelectionChange"
        :uploadInfo="uploadInfo"
        :prelang="prelang"
        :options="options"
        :ajaxFun="ajaxFun"
        ref="equipmentTable"
      >
        <template #toolbar></template>
      </ttable>
    </basic-container>
  </div>
</template>
<script>
import {
  downloadLossWord,
  recordList,
  syncLossRecordFile
} from '@/api/equipment/lossRecord'
import { mapGetters } from 'vuex'
import ttable from '@/views/common/ztt-table.vue'
import { transformDoc} from '@/util/fileTransform'
export default {
  data() {
    return {
      ajaxFun: recordList,
      multipleSelection: [],
      uploadInfo: {
        // æ˜¯å¦å±•示上传EXCEL以及对应的url
        isShow: false,
        url: '/mes/equipment/upload'
      },
      diaPrintTab: false,
      prelang: 'workstation',
      options: {
        height: 300, // é»˜è®¤é«˜åº¦-为了表头固定
        stripe: true, // æ˜¯å¦ä¸ºæ–‘马纹 table
        highlightCurrentRow: false, // æ˜¯å¦è¦é«˜äº®å½“前行
        border: true, // æ˜¯å¦æœ‰çºµå‘边框
        lazy: false, // æ˜¯å¦éœ€è¦æ‡’加载
        fit: true, // åˆ—的宽度是否自撑开
        multiSelect: true, //
        seqNo: true,
        isRefresh: true, // æ˜¯å¦æ˜¾ç¤ºåˆ·æ–°æŒ‰é’®
        isShowHide: true, // æ˜¯å¦æ˜¾ç¤ºæ˜¾å½±æŒ‰é’®
        isSearch: false, // é«˜çº§æŸ¥è¯¢æŒ‰é’®
        defaultOrderBy: { column: 'createTime', direction: 'desc' }
      },
      table: {
        total: 0,
        currentPage: 1,
        pageSize: 20,
        data: [],
        // æ ‡é¢˜
        column: [
          {
            minWidth: '150',
            width: '100',
            prop: 'sourceFile',
            label: '数据来源',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'productNum1',
            label: '产品编号1',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'productNum2',
            label: '产品编号2',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'batchNum1',
            label: '批次编号1',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'batchNum2',
            label: '批次编号2',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'specification1',
            label: '规格',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'channel1',
            label: '频道',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'insertionLoss1',
            label: '插入损耗',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'returnLoss1',
            label: '回波损耗',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'specification2',
            label: '规格',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'channel2',
            label: '频道',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'insertionLoss2',
            label: '插入损耗',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'returnLoss2',
            label: '回波损耗',
            sort: false,
            isTrue: true,
            isSearch: true
          },
          {
            minWidth: '150',
            width: '100',
            prop: 'createTime',
            label: '创建时间',
            sort: true,
            isTrue: true,
            isSearch: true,
            formatter: this.formatReceiveTime,
            searchInfoType: 'datetimerange'
          }
        ],
        toolbar: [],
        operator: null,
        operatorConfig: {
          fixed: 'right',
          label: '操作',
          width: 130,
          minWidth: 130
        }
      },
      addOrUpdateVisible: false,
      workshopList: []
    }
  },
  components: {
    ttable
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  created() {
    this.table.toolbar.push({
      text: '同步',
      type: 'primary',
      loading: false,
      fun: this.syncFile
    })
    const arr = []
    arr.push({
      text: '导出',
      icon: 'el-icon-download',
      type: 'text',
      size: 'small',
      fun: this.downloadFile
    })
    this.table.operator = arr.length > 0 ? arr : null
  },
  methods: {
    // åŒæ­¥æ–‡ä»¶
    syncFile() {
      syncLossRecordFile().then((res) => {})
    },
    // æ–‡ä»¶ä¸‹è½½
    downloadFile(row) {
      console.log('row', row)
      downloadLossWord({ id: row.id }).then((res) => {
        transformDoc(res)
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  }
}
</script>