【VUE】 导出excel,Export2Excel样式修改,复杂表头,多级表头

Continue Read..
<el-form-item>
<el-button size="small" type="success" @click="outExe()"><i class="el-icon-search"/>导出</el-button>
</el-form-item>

outExe() {
  this.$confirm('此操作将导出excel文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
  }).then(() => {
this.listLoading = true
getList({ actiontype: 'order_count_exp',ctype:this.search.ctype,counttime:this.search.counttime}, this.listQuery).then(response => {
  if (response.resultCode == 200) {
import('@/vendor/Export2ExcelStyle').then(excel => {
  const multiHeader = response.data.multiHeader
  const tHeader = response.data.headArr
  const filterVal = response.data.filterVal
  const list = response.data.list
  if (list.length == 0) {
this.$message.error('没有数据,不能导出');
return;
  }
  const merges = ['A1:A2', 'B1:B2', 'C1:C2', 'D1:D2', 'E1:E2', 'F1:F2', 'G1:G2', 'H1:K1', 'L1:P1']
  // const title = 'titile'
  // console.log(filterVal, list);
  const data = this.formatJson(filterVal, list)
  excel.export_json_to_excel({
// title,
multiHeader,
header: tHeader, 
data: data,
filename: response.data.fileName,
merges, 
autoWidth: false,
bookType: 'xlsx',
  })
})
  }else{
this.$message({
  message: response.data,
  type: 'error'
})
  }
  this.listLoading = false
}).catch(error => {
  console.log(error)
})
  }).catch(() => {

  });
},
formatJson(filterVal, jsonData) {
  return jsonData.map(v => filterVal.map(j => {
if (j === 'timestamp') {
  return parseTime(v[j])
} else {
  return v[j]
}
  }))
},



$data['fileName'] = 'love_order_count_exp_' . date("Y-m-d");
$data['filterVal'] = ['id', 'ctype_name', 'counttime', 'orderfee', 'payfee', 'refundfee', 'truefee', 'otype_1', 'otype_2', 'otype_3', 'otype_4', 'ptype_1', 'ptype_2', 'ptype_3', 'ptype_4', 'ptype_5'];
$data['multiHeader'] = [['序号', '类型', '日期', '订单总额', '实收', '退款', '净收入', '类型', '',  '',  '', '来源']];
$data['headArr'] = ['', '', '', '', '', '', '', '活动', '会员', '认证', '一周CP', '微信', '小程序', '后台', '触屏', 'APP'];

这里要注意multiHeader数组中,类型后面空了3个,是因为类型这栏合并了4列,下面子类有4列,如果不空的话,会吧来源覆盖
headArr前面空了7列,是因为前7个不需要多级表头


点击查看原图

 

参考网址 

https://blog.csdn.net/weixin_43965143/article/details/106572755

https://www.jianshu.com/p/06521a9c75d8

 

js附件

Export2ExcelStyle.zip



声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【nginx】得到IP地址

Continue Read..

nginx 

  proxy_set_header X-Real-IP $remote_addr;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  proxy_set_header Host $host;

  real_ip_header    X-Forwarded-For;

  real_ip_recursive on;

 

php 

<?php

echo long2ip(_get_ip());

function _get_ip($full = false) {

        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {

            if ($full == true)

                return sprintf("%u\n", ip2long($_SERVER["HTTP_X_FORWARDED_FOR"]));

            $tmp_ips = explode(',', $_SERVER["HTTP_X_FORWARDED_FOR"]);

            $ip = array_shift($tmp_ips);

        }

        else if (isset($_SERVER["HTTP_CLIENT_IP"]))

            $ip = $_SERVER["HTTP_CLIENT_IP"];

        else if (isset($_SERVER["REMOTE_ADDR"]))

            $ip = $_SERVER["REMOTE_ADDR"];

        else if (getenv("HTTP_X_FORWARDED_FOR"))

            $ip = getenv("HTTP_X_FORWARDED_FOR");

        else if (getenv("HTTP_CLIENT_IP"))

            $ip = getenv("HTTP_CLIENT_IP");

        else if (getenv("REMOTE_ADDR"))

            $ip = getenv("REMOTE_ADDR");

        else

            $ip = "Unknown";

        return sprintf("%u\n", ip2long($ip));

    }


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权