mirror of
https://github.com/PanJiaChen/vue-element-admin.git
synced 2025-08-12 22:29:59 +08:00
* chore: remove i18n (#1828) * [release] 4.1.0 * perf[Profile]: adapt the profile page to the mobile (#2020) * Revert "perf: optimize page scrolling when setting fixedHeader" This reverts commit e8e6c7e79c2488779090f00efc5f1bbfcb04bd5b. * perf[Style]: refine fixed-header style when open el-dialog * doc: add new article * chore: use mockjs in production environment * fix[sidebar.css]: remove redundant css * perf[style]: refine dashboard style in mobile (#2060) * feat[ErrorLog]: add a clear button in ErrorLog component (#2065) * fix[redirect]: fix redirect bug in vue-devtools (#2066) * perf[Tinymce]: update tinymce cdn version * fix[redirect]: fix redirect bug in vue-devtool again * docs: add support to readme for Spanish (#2070) * docs[es]: add some translation(#2080) * perf[Exapme]: set page title according to article id * perf[RightPanel]: tidy css (#2101) * feat[SvgIcon]: support import svg from url (#2052) * fix: fixed change roles bug (#2072) * perf[Breadcrumb]: do not update breadcrumbs when go to redirect page (#2086) * perf[store]: add support to sub-modules (#2047) * perf[Login]: support other query (#2013) * refactor[chore]: generate postcss.config.js instead of .postcssrc.js consistent with vue-cli * perf[Tinymce]: dynamic import tinymce(#2102) * [release] 4.2.0 * docs: add support to readme for Spanish (#2070) * docs[es]: add some translation(#2080) * perf[Exapme]: set page title according to article id * perf[RightPanel]: tidy css (#2101) * feat[SvgIcon]: support import svg from url (#2052) * fix: fixed change roles bug (#2072) * perf[Breadcrumb]: do not update breadcrumbs when go to redirect page (#2086) * perf[store]: add support to sub-modules (#2047) * perf[Login]: support other query (#2013) * refactor[chore]: generate postcss.config.js instead of .postcssrc.js consistent with vue-cli * perf[Tinymce]: dynamic import tinymce(#2102) * [release] 4.2.0 * perf[Style]: refine example css * fix[Chart]: fixed chart bug in keep-alive (#2119) * perf[Style]: refine example css * fix[Chart]: fixed chart bug in keep-alive (#2119) * Create FUNDING.yml * chore: set localhost => 127.0.0.1 (#2142) * update github ISSUE_TEMPLATE * chore: add autoprefixer to devDependencies * perf[Tinymce]: add language option (#2159) * fix[Tinymce]: fixed bug when init multiple tinymces at the same time (#2152) * feat: add tab url demo (#2114) * perf[request.js]: refine error reject (#2160) * [release] 4.2.1 * Create FUNDING.yml * chore: set localhost => 127.0.0.1 (#2142) * update github ISSUE_TEMPLATE * chore: add autoprefixer to devDependencies * fix[Tinymce]: fixed bug when init multiple tinymces at the same time (#2152) * feat: add tab url demo (#2114) * perf[request.js]: refine error reject (#2160) * [release] 4.2.1 * perf: default not set withCredentials * fix[ImageCropper]: removeEventListener when destroyed(#2169) * docs: fix typo (#2170) * fix: input attribute autocomplete error (#2191) * perf: default not set withCredentials * fix[ImageCropper]: removeEventListener when destroyed(#2169) * docs: fix typo (#2170) * fix: input attribute autocomplete error (#2191) * perf[PanThumb]: Replace the image tag with background-image to prevent the stretching (#2202) * docs: fix typo README.zh-CN.md (#2283) 修改错别字 * perf[clipboard.js]: remove redundant code (#2307) * bump: update axios for security vulnerability * bump: update @vue/cli-plugin-eslint version (#2327) FIx cannot find module '.../node_modules/eslint/lib/api.js/package.json' bug,see https://github.com/vuejs/vue-cli/issues/4231. * chore: allow dynamic set port * fix[complex-table]: form header sort icon is out of sync (#2382) * fix: fixed missing icons * fix: typos (#2532) Role Nmae => Role Name * docs: add awesome-project * fix[Dashboard]: fixed debounce bug (#2586) (#2597) To fixed https://github.com/PanJiaChen/vue-element-admin/issues/2586 * perf: VS Code support webpack alias file jump (#2609) * perf: optimize import file-saver way(#2347) * refactor[ImageCropper]: fix lint error (#2365) * fix: fixed numberFormatter bug https://github.com/PanJiaChen/vue-element-admin/issues/2568 * fix[example]: fixed create.vue cache error https://github.com/PanJiaChen/vue-element-admin/issues/2608 * perf[utils.js]: perf parseTime function (#2625) * perf[tagsView]: pref DEL_CACHED_VIEW and DEL_OTHERS_CACHED_VIEWS function (#2626) * fix[tagsView]: fixed DEL_OTHERS_CACHED_VIEWS bug * fix[logout]: empty tagsview when logout (#2632) * fix[TagsView]: fixed toLastView bug (#2634) * perf[SvgIcon]: change xlink:href to href(#2645) https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xlink:href * fix[TagsView]: fixed click.middle can close affixed tag bug (#2649) * docs: add job ad * perf[PanThumb]: Replace the image tag with background-image to prevent the stretching (#2202) * docs: fix typo README.zh-CN.md (#2283) 修改错别字 * perf[clipboard.js]: remove redundant code (#2307) * bump: update axios for security vulnerability * bump: update @vue/cli-plugin-eslint version (#2327) FIx cannot find module '.../node_modules/eslint/lib/api.js/package.json' bug,see https://github.com/vuejs/vue-cli/issues/4231. * chore: allow dynamic set port * fix[complex-table]: form header sort icon is out of sync (#2382) * fix: fixed missing icons * fix: typos (#2532) Role Nmae => Role Name * docs: add awesome-project * fix[Dashboard]: fixed debounce bug (#2586) (#2597) To fixed https://github.com/PanJiaChen/vue-element-admin/issues/2586 * perf: VS Code support webpack alias file jump (#2609) * perf: optimize import file-saver way(#2347) * refactor[ImageCropper]: fix lint error (#2365) * fix: fixed numberFormatter bug https://github.com/PanJiaChen/vue-element-admin/issues/2568 * fix[example]: fixed create.vue cache error https://github.com/PanJiaChen/vue-element-admin/issues/2608 * perf[utils.js]: perf parseTime function (#2625) * perf[tagsView]: pref DEL_CACHED_VIEW and DEL_OTHERS_CACHED_VIEWS function (#2626) * fix[tagsView]: fixed DEL_OTHERS_CACHED_VIEWS bug * fix[logout]: empty tagsview when logout (#2632) * fix[TagsView]: fixed toLastView bug (#2634) * perf[SvgIcon]: change xlink:href to href(#2645) https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xlink:href * fix[TagsView]: fixed click.middle can close affixed tag bug (#2649) * docs: add job ad * feat: add job * docs: improved README.md (#2656) * style: fix el-date-picker css style * perf: format dropdown menu code (#2720) * perf: format inline edit table (#2725) move one format `{row}` * perf: format drag table (#2733) move one format `{row}` * perf: complex table (#2732) * perf: text i18n (#2739) * update 'MarkdownEditor' components name * format: space in user card (#2744) * perf: format pdf download (#2791) * perf[views/icons]: use grid (#2803) * feat: plop new generate store (#2805) * fix[icons]:fixed eslint 1 error and 2 warnings (#2835) * perf[documentation]: refine css * fix[Logout]: click blank area of dropDown able to logout (#2896) * perf: import mockXHR only in production (#2910) * 自动排除mock 生产环境,使用webpack的条件编译自动排除mock数据 * perf: refine Co-authored-by: 花裤衩 <panfree23@gmail.com> * perf[Menu]: remove unused menu-wrapper (#2903) * perf[complex-table]:refine code (#2825) * perf: optimize checkCapslock method (#2635) * optimize checkCapslock method * update Co-authored-by: 花裤衩 <panfree23@gmail.com> * fix[Charts]: fix charts resize in keep-alive bug (#2922) * fix[Charts]: fix charts resize in keep-alive bug * refine * fix: fixed mock server (#2929) * init * refine * update * bump: update element-ui version * fix: fixed require mock bug in production * feat[Search]: route search supports pinyin (#2643) * fix: fixed redirect path regex (#2933) * perf[Mock]: set responseFake to mock-server.js(#2966) * modify 把mock/index.js中与mock-server相关的代码转移到mock-server.js中去,实现两则功能分割 * docs: improve Japanese translation (#2970) * perf: change script-loader to dependencies * fix[profile/UserCard]: fixed wrong key name (#3056) roles => role * fix:fixed parseTime bug in ie and safari(#3066) * /src/utils/index.js parseTime 添加IE浏览器(版本10以下,包括版本10)兼容。 * perf: update Co-authored-by: aisen60 <aisen60@qq.com> Co-authored-by: 花裤衩 <panfree23@gmail.com> * perf: format component names as PascalCase (#3074) format: component names should be PascalCase * docs: add smallsticker * Update README.zh-CN.md * fix: svg support old broswer (#3085) * fixed typo (#3091) * fix: use vue-cli default source-map (#3097) cheap-module-eval-source-map * perf[Tinymce]: editor try to keep these URLs intact (#3141) * fix[element-variables]: missing space in element-variables (#3144) * fix: compatibility with vetur (#1700) * feat: add option to try project on CodeSandbox (#2976) * docs: add tips * perf: when tags-view scroll close the right-menu * fix[parseTime]: fixed when pass null (#3038) * fix[css]: min btn width (#3164) * Add contributor into package.json file. * fixed before merge. Co-authored-by: 花裤衩 <panfree23@gmail.com> Co-authored-by: toruksmakto <42709228+toruksmakto@users.noreply.github.com> Co-authored-by: Yamel Senih <ysenih@erpya.com> Co-authored-by: Yamel Senih <yamelsenih@gmail.com> Co-authored-by: liugq <liugq5713@gmail.com> Co-authored-by: bpzhang <bpzhang@users.noreply.github.com> Co-authored-by: Serge <gaosj1993@foxmail.com> Co-authored-by: MaYuanhai <414199639@qq.com> Co-authored-by: Jessynt <xr5299@gmail.com> Co-authored-by: 肖敏 <392716797@qq.com> Co-authored-by: TinaryTree <mbdkhss@gmail.com> Co-authored-by: itsccn <chen.sun@itsccn.com> Co-authored-by: why <w.why@163.com> Co-authored-by: Baskerville* <wszdlm@gmail.com> Co-authored-by: Francis <31059354+FrancisSano@users.noreply.github.com> Co-authored-by: monkeycf <41945134+monkeycf@users.noreply.github.com> Co-authored-by: BradyBromley <51128276+BradyBromley@users.noreply.github.com> Co-authored-by: Phạm Ngọc Hòa <thaycacac@gmail.com> Co-authored-by: bbigcd <bbigcd@163.com> Co-authored-by: xuanzai <43233731+MikuBlog@users.noreply.github.com> Co-authored-by: flitrue <812863096@qq.com> Co-authored-by: 韬 <605682551@qq.com> Co-authored-by: 任羽飞 <ren12345@126.com> Co-authored-by: Kaitian Xie <xkaitian@gmail.com> Co-authored-by: AndyLZC/AndyLZC.github.io <34624589+AndyLZC@users.noreply.github.com> Co-authored-by: RussXD <shangtouWeb@foxmail.com> Co-authored-by: 李小斐 <623536309@qq.com> Co-authored-by: RoBlues <robluesmail@gmail.com> Co-authored-by: Shota Aratono <195194+artn@users.noreply.github.com> Co-authored-by: echofly <36875450+echofly@users.noreply.github.com> Co-authored-by: Aisen60 <1147319086@qq.com> Co-authored-by: aisen60 <aisen60@qq.com> Co-authored-by: Alex S <50220345+sabatale@users.noreply.github.com> Co-authored-by: Aisen <caixusheng60@gmail.com> Co-authored-by: ntnyq <ntnyq13@gmail.com> Co-authored-by: garethx <gareth.wilson@gmail.com> Co-authored-by: AiMe1991 <sxd.08@163.com> Co-authored-by: cooper <1322849632@qq.com> Co-authored-by: Nickbing Lao <giscafer@outlook.com>
221 lines
5.2 KiB
JavaScript
221 lines
5.2 KiB
JavaScript
/* eslint-disable */
|
|
import { saveAs } from 'file-saver'
|
|
import XLSX from 'xlsx'
|
|
|
|
function generateArray(table) {
|
|
var out = [];
|
|
var rows = table.querySelectorAll('tr');
|
|
var ranges = [];
|
|
for (var R = 0; R < rows.length; ++R) {
|
|
var outRow = [];
|
|
var row = rows[R];
|
|
var columns = row.querySelectorAll('td');
|
|
for (var C = 0; C < columns.length; ++C) {
|
|
var cell = columns[C];
|
|
var colspan = cell.getAttribute('colspan');
|
|
var rowspan = cell.getAttribute('rowspan');
|
|
var cellValue = cell.innerText;
|
|
if (cellValue !== "" && cellValue == +cellValue) cellValue = +cellValue;
|
|
|
|
//Skip ranges
|
|
ranges.forEach(function (range) {
|
|
if (R >= range.s.r && R <= range.e.r && outRow.length >= range.s.c && outRow.length <= range.e.c) {
|
|
for (var i = 0; i <= range.e.c - range.s.c; ++i) outRow.push(null);
|
|
}
|
|
});
|
|
|
|
//Handle Row Span
|
|
if (rowspan || colspan) {
|
|
rowspan = rowspan || 1;
|
|
colspan = colspan || 1;
|
|
ranges.push({
|
|
s: {
|
|
r: R,
|
|
c: outRow.length
|
|
},
|
|
e: {
|
|
r: R + rowspan - 1,
|
|
c: outRow.length + colspan - 1
|
|
}
|
|
});
|
|
};
|
|
|
|
//Handle Value
|
|
outRow.push(cellValue !== "" ? cellValue : null);
|
|
|
|
//Handle Colspan
|
|
if (colspan)
|
|
for (var k = 0; k < colspan - 1; ++k) outRow.push(null);
|
|
}
|
|
out.push(outRow);
|
|
}
|
|
return [out, ranges];
|
|
};
|
|
|
|
function datenum(v, date1904) {
|
|
if (date1904) v += 1462;
|
|
var epoch = Date.parse(v);
|
|
return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
|
|
}
|
|
|
|
function sheet_from_array_of_arrays(data, opts) {
|
|
var ws = {};
|
|
var range = {
|
|
s: {
|
|
c: 10000000,
|
|
r: 10000000
|
|
},
|
|
e: {
|
|
c: 0,
|
|
r: 0
|
|
}
|
|
};
|
|
for (var R = 0; R != data.length; ++R) {
|
|
for (var C = 0; C != data[R].length; ++C) {
|
|
if (range.s.r > R) range.s.r = R;
|
|
if (range.s.c > C) range.s.c = C;
|
|
if (range.e.r < R) range.e.r = R;
|
|
if (range.e.c < C) range.e.c = C;
|
|
var cell = {
|
|
v: data[R][C]
|
|
};
|
|
if (cell.v == null) continue;
|
|
var cell_ref = XLSX.utils.encode_cell({
|
|
c: C,
|
|
r: R
|
|
});
|
|
|
|
if (typeof cell.v === 'number') cell.t = 'n';
|
|
else if (typeof cell.v === 'boolean') cell.t = 'b';
|
|
else if (cell.v instanceof Date) {
|
|
cell.t = 'n';
|
|
cell.z = XLSX.SSF._table[14];
|
|
cell.v = datenum(cell.v);
|
|
} else cell.t = 's';
|
|
|
|
ws[cell_ref] = cell;
|
|
}
|
|
}
|
|
if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
|
|
return ws;
|
|
}
|
|
|
|
function Workbook() {
|
|
if (!(this instanceof Workbook)) return new Workbook();
|
|
this.SheetNames = [];
|
|
this.Sheets = {};
|
|
}
|
|
|
|
function s2ab(s) {
|
|
var buf = new ArrayBuffer(s.length);
|
|
var view = new Uint8Array(buf);
|
|
for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
|
|
return buf;
|
|
}
|
|
|
|
export function export_table_to_excel(id) {
|
|
var theTable = document.getElementById(id);
|
|
var oo = generateArray(theTable);
|
|
var ranges = oo[1];
|
|
|
|
/* original data */
|
|
var data = oo[0];
|
|
var ws_name = "SheetJS";
|
|
|
|
var wb = new Workbook(),
|
|
ws = sheet_from_array_of_arrays(data);
|
|
|
|
/* add ranges to worksheet */
|
|
// ws['!cols'] = ['apple', 'banan'];
|
|
ws['!merges'] = ranges;
|
|
|
|
/* add worksheet to workbook */
|
|
wb.SheetNames.push(ws_name);
|
|
wb.Sheets[ws_name] = ws;
|
|
|
|
var wbout = XLSX.write(wb, {
|
|
bookType: 'xlsx',
|
|
bookSST: false,
|
|
type: 'binary'
|
|
});
|
|
|
|
saveAs(new Blob([s2ab(wbout)], {
|
|
type: "application/octet-stream"
|
|
}), "test.xlsx")
|
|
}
|
|
|
|
export function export_json_to_excel({
|
|
multiHeader = [],
|
|
header,
|
|
data,
|
|
filename,
|
|
merges = [],
|
|
autoWidth = true,
|
|
bookType = 'xlsx'
|
|
} = {}) {
|
|
/* original data */
|
|
filename = filename || 'excel-list'
|
|
data = [...data]
|
|
data.unshift(header);
|
|
|
|
for (let i = multiHeader.length - 1; i > -1; i--) {
|
|
data.unshift(multiHeader[i])
|
|
}
|
|
|
|
var ws_name = "SheetJS";
|
|
var wb = new Workbook(),
|
|
ws = sheet_from_array_of_arrays(data);
|
|
|
|
if (merges.length > 0) {
|
|
if (!ws['!merges']) ws['!merges'] = [];
|
|
merges.forEach(item => {
|
|
ws['!merges'].push(XLSX.utils.decode_range(item))
|
|
})
|
|
}
|
|
|
|
if (autoWidth) {
|
|
/*设置worksheet每列的最大宽度*/
|
|
const colWidth = data.map(row => row.map(val => {
|
|
/*先判断是否为null/undefined*/
|
|
if (val == null) {
|
|
return {
|
|
'wch': 10
|
|
};
|
|
}
|
|
/*再判断是否为中文*/
|
|
else if (val.toString().charCodeAt(0) > 255) {
|
|
return {
|
|
'wch': val.toString().length * 2
|
|
};
|
|
} else {
|
|
return {
|
|
'wch': val.toString().length
|
|
};
|
|
}
|
|
}))
|
|
/*以第一行为初始值*/
|
|
let result = colWidth[0];
|
|
for (let i = 1; i < colWidth.length; i++) {
|
|
for (let j = 0; j < colWidth[i].length; j++) {
|
|
if (result[j]['wch'] < colWidth[i][j]['wch']) {
|
|
result[j]['wch'] = colWidth[i][j]['wch'];
|
|
}
|
|
}
|
|
}
|
|
ws['!cols'] = result;
|
|
}
|
|
|
|
/* add worksheet to workbook */
|
|
wb.SheetNames.push(ws_name);
|
|
wb.Sheets[ws_name] = ws;
|
|
|
|
var wbout = XLSX.write(wb, {
|
|
bookType: bookType,
|
|
bookSST: false,
|
|
type: 'binary'
|
|
});
|
|
saveAs(new Blob([s2ab(wbout)], {
|
|
type: "application/octet-stream"
|
|
}), `${filename}.${bookType}`);
|
|
}
|