工具方法

将table导出为xlsx

import FileSaver from 'file-saver'
import XLSX from 'xlsx'

        // /* generate workbook object from table */
        // // 转换成excel时,使用原始的格式
        let xlsxParam = {raw: true};
        // el-table的fixed属性来让某一列固定,但elementui的实现方式是:创建了两个tabledom,通过一个隐藏一个显示来实现交互效果。
        // 当导出整个el-table 就会将两个div内的table都导出,导致数据重复。移除重复table
        let fix = document.querySelector('.el-table__fixed');
        let wb;
        if (fix) {
          wb = XLSX.utils.table_to_book(document.querySelector('.el-table').removeChild(fix), xlsxParam);
          document.querySelector('.el-table').appendChild(fix);
        } else {
          wb = XLSX.utils.table_to_book(document.querySelector('.el-table'), xlsxParam);
        }

        /* get binary string as output */
        let wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: true, type: 'array'});
        try {
          FileSaver.saveAs(new Blob([wbout], {type: 'application/octet-stream'}), '差评查询-' + (moment(new Date()).format('YYYYMMDD')) + '.xlsx');
        } catch (e) {
          if (typeof console !== 'undefined') {
            console.log(e, wbout)
          }
        } finally {
          this.isExport = false;
          this.pageSize = pageSize
        }
        return wbout;

数组对象去重

// 数组对象去重
        let hash = {};
        this.targetList = this.targetList.reduce(function (item, next) {
          hash[next.name] ? '' : hash[next.name] = true && item.push(next);
          return item
        }, [])

 正则搜索文本

      let re = /wwww.badu.com\/p\/(.*?).html/
      let str = 'https://wwww.badu.com/p/121212.html'
      // 121212
      console.log(str.match(re)[1])
      
      let re = /wwww.badu.com\/p\/(.*?).html/
      let str = 'https://wwww.badu.com/p/121212.html'
      // 121212
      console.log(re.exec(str)[1])

猜你喜欢

转载自www.cnblogs.com/ronle/p/11357464.html