no message
Former-commit-id: 408058fab164d62f8a60dcb3abbac19a0464dec1 Former-commit-id: ec41a7db6766d29a89679ed3769fad5ead12058a Former-commit-id: 0f4d0fbaa32e40973b79ad12a1a90c3035106a68
This commit is contained in:
15
src/components/core/Icon/index.vue
Normal file
15
src/components/core/Icon/index.vue
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<template>
|
||||||
|
<i class="fa" :class="`fa-${name}`" aria-hidden="true"></i>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
required: false,
|
||||||
|
default: 'font-awesome'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -3,6 +3,7 @@ import Vue from 'vue'
|
|||||||
Vue.component('Container', resolve => { require(['@/components/core/Container'], resolve) })
|
Vue.component('Container', resolve => { require(['@/components/core/Container'], resolve) })
|
||||||
Vue.component('CountUp', resolve => { require(['@/components/core/CountUp'], resolve) })
|
Vue.component('CountUp', resolve => { require(['@/components/core/CountUp'], resolve) })
|
||||||
Vue.component('Highlight', resolve => { require(['@/components/core/Highlight'], resolve) })
|
Vue.component('Highlight', resolve => { require(['@/components/core/Highlight'], resolve) })
|
||||||
|
Vue.component('Icon', resolve => { require(['@/components/core/Icon'], resolve) })
|
||||||
Vue.component('IconSelect', resolve => { require(['@/components/core/IconSelect/index.vue'], resolve) })
|
Vue.component('IconSelect', resolve => { require(['@/components/core/IconSelect/index.vue'], resolve) })
|
||||||
Vue.component('Markdown', resolve => { require(['@/components/core/Markdown'], resolve) })
|
Vue.component('Markdown', resolve => { require(['@/components/core/Markdown'], resolve) })
|
||||||
Vue.component('QuillEditor', resolve => { require(['@/components/core/QuillEditor'], resolve) })
|
Vue.component('QuillEditor', resolve => { require(['@/components/core/QuillEditor'], resolve) })
|
||||||
|
|||||||
@@ -4,6 +4,12 @@
|
|||||||
slot="header"
|
slot="header"
|
||||||
title="基本示例">
|
title="基本示例">
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
|
<div>
|
||||||
|
<el-button @click="exportCsv">
|
||||||
|
<Icon name="download"></Icon>
|
||||||
|
exportCsv
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
<el-table v-bind="table" style="width: 100%" class="dd-mb">
|
<el-table v-bind="table" style="width: 100%" class="dd-mb">
|
||||||
<el-table-column
|
<el-table-column
|
||||||
v-for="(item, index) in table.columns"
|
v-for="(item, index) in table.columns"
|
||||||
@@ -16,7 +22,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// 假数据
|
||||||
import table from './data'
|
import table from './data'
|
||||||
|
// 库
|
||||||
|
// import Csv from '@/utils/csv.js'
|
||||||
|
// import ExportCsv from '@/utils/export-csv.js'
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
@@ -28,6 +38,14 @@ export default {
|
|||||||
border: true
|
border: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
exportCsv (params) {
|
||||||
|
let _params = Object.assign({}, params, {
|
||||||
|
filename: 'table'
|
||||||
|
})
|
||||||
|
console.log(_params)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
62
src/utils/csv.js
Executable file
62
src/utils/csv.js
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
inspired by https://www.npmjs.com/package/react-csv-downloader
|
||||||
|
now removed from Github
|
||||||
|
inspired by https://github.com/iview/iview
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
|
const newLine = '\r\n';
|
||||||
|
const appendLine = (content, row, { separator, quoted }) => {
|
||||||
|
const line = row.map(data => {
|
||||||
|
if (!quoted) return data;
|
||||||
|
// quote data
|
||||||
|
data = typeof data === 'string' ? data.replace(/"/g, '"') : data;
|
||||||
|
return `"${data}"`;
|
||||||
|
});
|
||||||
|
content.push(line.join(separator));
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaults = {
|
||||||
|
separator: ',',
|
||||||
|
quoted: false
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function csv(columns, datas, options, noHeader = false) {
|
||||||
|
options = Object.assign({}, defaults, options);
|
||||||
|
let columnOrder;
|
||||||
|
const content = [];
|
||||||
|
const column = [];
|
||||||
|
|
||||||
|
if (columns) {
|
||||||
|
columnOrder = columns.map(v => {
|
||||||
|
if (typeof v === 'string') return v;
|
||||||
|
if (!noHeader) {
|
||||||
|
column.push(typeof v.title !== 'undefined' ? v.title : v.key);
|
||||||
|
}
|
||||||
|
return v.key;
|
||||||
|
});
|
||||||
|
if (column.length > 0) appendLine(content, column, options);
|
||||||
|
} else {
|
||||||
|
columnOrder = [];
|
||||||
|
datas.forEach(v => {
|
||||||
|
if (!Array.isArray(v)) {
|
||||||
|
columnOrder = columnOrder.concat(Object.keys(v));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (columnOrder.length > 0) {
|
||||||
|
columnOrder = columnOrder.filter((value, index, self) => self.indexOf(value) === index);
|
||||||
|
if (!noHeader) appendLine(content, columnOrder, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(datas)) {
|
||||||
|
datas.forEach(row => {
|
||||||
|
if (!Array.isArray(row)) {
|
||||||
|
row = columnOrder.map(k => (typeof row[k] !== 'undefined' ? row[k] : ''));
|
||||||
|
}
|
||||||
|
appendLine(content, row, options);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return content.join(newLine);
|
||||||
|
}
|
||||||
82
src/utils/export-csv.js
Executable file
82
src/utils/export-csv.js
Executable file
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
https://github.com/iview/iview
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
|
function has (browser) {
|
||||||
|
const ua = navigator.userAgent;
|
||||||
|
if (browser === 'ie') {
|
||||||
|
const isIE = ua.indexOf('compatible') > -1 && ua.indexOf('MSIE') > -1;
|
||||||
|
if (isIE) {
|
||||||
|
const reIE = new RegExp('MSIE (\\d+\\.\\d+);');
|
||||||
|
reIE.test(ua);
|
||||||
|
return parseFloat(RegExp['$1']);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ua.indexOf(browser) > -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const csv = {
|
||||||
|
_isIE11 () {
|
||||||
|
let iev = 0;
|
||||||
|
const ieold = (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
|
||||||
|
const trident = !!navigator.userAgent.match(/Trident\/7.0/);
|
||||||
|
const rv = navigator.userAgent.indexOf('rv:11.0');
|
||||||
|
|
||||||
|
if (ieold) {
|
||||||
|
iev = Number(RegExp.$1);
|
||||||
|
}
|
||||||
|
if (navigator.appVersion.indexOf('MSIE 10') !== -1) {
|
||||||
|
iev = 10;
|
||||||
|
}
|
||||||
|
if (trident && rv !== -1) {
|
||||||
|
iev = 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
return iev === 11;
|
||||||
|
},
|
||||||
|
|
||||||
|
_isEdge () {
|
||||||
|
return /Edge/.test(navigator.userAgent);
|
||||||
|
},
|
||||||
|
|
||||||
|
_getDownloadUrl (text) {
|
||||||
|
const BOM = '\uFEFF';
|
||||||
|
// Add BOM to text for open in excel correctly
|
||||||
|
if (window.Blob && window.URL && window.URL.createObjectURL) {
|
||||||
|
const csvData = new Blob([BOM + text], { type: 'text/csv' });
|
||||||
|
return URL.createObjectURL(csvData);
|
||||||
|
} else {
|
||||||
|
return 'data:attachment/csv;charset=utf-8,' + BOM + encodeURIComponent(text);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
download (filename, text) {
|
||||||
|
if (has('ie') && has('ie') < 10) {
|
||||||
|
// has module unable identify ie11 and Edge
|
||||||
|
const oWin = window.top.open('about:blank', '_blank');
|
||||||
|
oWin.document.charset = 'utf-8';
|
||||||
|
oWin.document.write(text);
|
||||||
|
oWin.document.close();
|
||||||
|
oWin.document.execCommand('SaveAs', filename);
|
||||||
|
oWin.close();
|
||||||
|
} else if (has('ie') === 10 || this._isIE11() || this._isEdge()) {
|
||||||
|
const BOM = '\uFEFF';
|
||||||
|
const csvData = new Blob([BOM + text], { type: 'text/csv' });
|
||||||
|
navigator.msSaveBlob(csvData, filename);
|
||||||
|
} else {
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.download = filename;
|
||||||
|
link.href = this._getDownloadUrl(text);
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default csv;
|
||||||
Reference in New Issue
Block a user