From f8cc7072aa2c9f8adc030f7139593e31be90fc39 Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Sat, 15 Dec 2018 09:40:54 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: b792f259a85060bc427414a1451d7218e8e099f7 [formerly b792f259a85060bc427414a1451d7218e8e099f7 [formerly b792f259a85060bc427414a1451d7218e8e099f7 [formerly b792f259a85060bc427414a1451d7218e8e099f7 [formerly 6a9e02c169cc62ae7f62e1f479aa2fc1eb7759b7 [formerly 7524303cc8515da2de88d785b38eae96a3cc501e]]]]] Former-commit-id: cc0082f2dddee9629e13a66d8458132f4c1529fb Former-commit-id: 1e88751bbe455a8ecf939f0c3745bd6005d3b549 Former-commit-id: 93b5b7cd4d80da8f81c4985e302ba317c3b8ef30 [formerly 6d5ef8bec31f4fa776f9d797f381e57722a0db10] Former-commit-id: e4001eea6899889fe9f50194e23e320c0480dcfb Former-commit-id: 249fd0bd5ccf93dc4a22fc0cc6951dd039151349 Former-commit-id: f35cdabda6780556b92d236ff7e8d359249203c5 Former-commit-id: 4593038573e235b2eb9032d858409e020b7ee667 Former-commit-id: 37b953c1c1657ac5582759f7e8bb63efdb8d90d0 --- src/pages/demo/business/issues/142/edit.vue | 3 +-- src/pages/demo/business/issues/142/index.vue | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pages/demo/business/issues/142/edit.vue b/src/pages/demo/business/issues/142/edit.vue index a2d6c709..36b310fa 100644 --- a/src/pages/demo/business/issues/142/edit.vue +++ b/src/pages/demo/business/issues/142/edit.vue @@ -40,8 +40,7 @@ export default { vm.resetFormData() vm.getFormData(id) }) - } - else { + } else { next(new Error('未指定ID')) } }, diff --git a/src/pages/demo/business/issues/142/index.vue b/src/pages/demo/business/issues/142/index.vue index b8f777b1..5c33e558 100644 --- a/src/pages/demo/business/issues/142/index.vue +++ b/src/pages/demo/business/issues/142/index.vue @@ -59,7 +59,9 @@ export default { // 请求表格数据 getTableData () { fetch() - .then(res => this.crud.data = res.list) + .then(res => { + this.crud.data = res.list + }) .catch(err => console.log(err)) }, // 跳转到编辑页面 From 5e16818f73f6d5a9e1be14e3bdca5ce4a19f04be Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Sat, 15 Dec 2018 09:42:16 +0800 Subject: [PATCH 02/10] util.db Former-commit-id: 85a4564a9c26d25680e068390a9dce8081ff8301 [formerly 85a4564a9c26d25680e068390a9dce8081ff8301 [formerly 85a4564a9c26d25680e068390a9dce8081ff8301 [formerly 85a4564a9c26d25680e068390a9dce8081ff8301 [formerly 0c90f29ccfaf0af85cfee68a37e127969e1f403b [formerly 81d2e7a8b5e7b94b6707f2f7165948c23cb8fe97]]]]] Former-commit-id: 4be8876f52078af7d2f09d5be200e14c4b103b9d Former-commit-id: 0206f4b4d31c60ce01c43ceead230b7a242d6671 Former-commit-id: ca9b786629bc220dc77090732ec55ef682a65749 [formerly edc8fe2a03ccb155face81d2caa41898ffcc43da] Former-commit-id: 9bcb79d27c3671cdf2efa9bc8bb3bc746b536f76 Former-commit-id: ca8fa5fae99b3c2f29982295366d3b57dbd69ea8 Former-commit-id: ada47bd1e953a2977d08741b07f6dfa7a43a4c0f Former-commit-id: f7ae61fb796145f9e7cdc39c161876e4b1a70c3c Former-commit-id: eba7ec27792eebd4cc8cde53318b952a92f86a06 --- package-lock.json.REMOVED.git-id | 2 +- src/libs/{db.js => util.db.js} | 0 src/libs/util.js | 12 ++++++----- src/pages/demo/playground/db/all/index.vue | 4 ++-- src/store/modules/d2admin/modules/db.js | 25 +++++++++++----------- 5 files changed, 22 insertions(+), 21 deletions(-) rename src/libs/{db.js => util.db.js} (100%) diff --git a/package-lock.json.REMOVED.git-id b/package-lock.json.REMOVED.git-id index 7347e8cb..cc2a0b82 100644 --- a/package-lock.json.REMOVED.git-id +++ b/package-lock.json.REMOVED.git-id @@ -1 +1 @@ -14be1e768a4e072ad8ea5ff5bfec5535088a3e4b \ No newline at end of file +71c7a0f0efd0c1c51288f45b81f5c519d81068cb \ No newline at end of file diff --git a/src/libs/db.js b/src/libs/util.db.js similarity index 100% rename from src/libs/db.js rename to src/libs/util.db.js diff --git a/src/libs/util.js b/src/libs/util.js index af73d10e..9711c6a9 100644 --- a/src/libs/util.js +++ b/src/libs/util.js @@ -1,8 +1,10 @@ -import log from './util.log.js' -import cookies from './util.cookies.js' +import cookies from './util.cookies' +import db from './util.db' +import log from './util.log' -let util = { +const util = { cookies, + db, log } @@ -23,10 +25,10 @@ util.open = function (url) { var a = document.createElement('a') a.setAttribute('href', url) a.setAttribute('target', '_blank') - a.setAttribute('id', 'd2admin-menu-link') + a.setAttribute('id', 'd2admin-link-temp') document.body.appendChild(a) a.click() - document.body.removeChild(document.getElementById('d2admin-menu-link')) + document.body.removeChild(document.getElementById('d2admin-link-temp')) } export default util diff --git a/src/pages/demo/playground/db/all/index.vue b/src/pages/demo/playground/db/all/index.vue index 02d7a711..e1de19c4 100644 --- a/src/pages/demo/playground/db/all/index.vue +++ b/src/pages/demo/playground/db/all/index.vue @@ -16,7 +16,7 @@ + + diff --git a/src/pages/demo/filters/day/components/code-title.vue b/src/pages/demo/filters/day/components/code-title.vue new file mode 100644 index 00000000..48eeec21 --- /dev/null +++ b/src/pages/demo/filters/day/components/code-title.vue @@ -0,0 +1,41 @@ + + + + + diff --git a/src/pages/demo/filters/day/index.vue b/src/pages/demo/filters/day/index.vue new file mode 100644 index 00000000..a58ab53f --- /dev/null +++ b/src/pages/demo/filters/day/index.vue @@ -0,0 +1,95 @@ + + + diff --git a/src/pages/demo/filters/index/index.vue b/src/pages/demo/filters/index/index.vue new file mode 100644 index 00000000..659102ec --- /dev/null +++ b/src/pages/demo/filters/index/index.vue @@ -0,0 +1,22 @@ + + + diff --git a/src/plugin/d2admin/index.js b/src/plugin/d2admin/index.js index d7a9e5c2..3e9724c7 100644 --- a/src/plugin/d2admin/index.js +++ b/src/plugin/d2admin/index.js @@ -7,6 +7,8 @@ import 'flex.css' import '@/components' // svg 图标 import '@/assets/svg-icons' +// 过滤器 +import d2VueFiltersDateModule from '@/filters/module.date' // 功能插件 import pluginError from '@/plugin/error' import pluginExport from '@/plugin/export' @@ -29,6 +31,8 @@ export default { Vue.prototype.$buildTime = process.env.VUE_APP_BUILD_TIME // Element Vue.use(ElementUI) + // 过滤器 日期模块 + Vue.use(d2VueFiltersDateModule) // 插件 Vue.use(pluginError) Vue.use(pluginExport) diff --git a/src/router/modules/filters.js b/src/router/modules/filters.js new file mode 100644 index 00000000..8d0cb4b1 --- /dev/null +++ b/src/router/modules/filters.js @@ -0,0 +1,25 @@ +import layoutHeaderAside from '@/layout/header-aside' + +const meta = { auth: true } + +export default { + path: '/demo/filters', + name: 'demo-filters', + meta, + redirect: { name: 'demo-filters-index' }, + component: layoutHeaderAside, + children: (pre => [ + { + path: 'index', + name: `${pre}index`, + component: () => import('@/pages/demo/filters/index'), + meta: { ...meta, title: '过滤器首页' } + }, + { + path: 'day', + name: `${pre}day`, + component: () => import('@/pages/demo/filters/day'), + meta: { ...meta, title: '日期和时间' } + } + ])('demo-filters-') +} diff --git a/src/router/routes.js b/src/router/routes.js index 097e75f0..544380a4 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -5,6 +5,7 @@ import plugins from './modules/plugins' import charts from './modules/charts' import components from './modules/components' import element from './modules/element' +import filters from './modules/filters' import business from './modules/business' import layoutHeaderAside from '@/layout/header-aside' @@ -60,6 +61,7 @@ const frameIn = [ charts, components, element, + filters, business ] From 459af89c7e3c56519a6850909ef4c41927710e35 Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Sun, 16 Dec 2018 12:29:48 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 3c68169e206863118588f20f40686bddc145144d [formerly 3c68169e206863118588f20f40686bddc145144d [formerly 3c68169e206863118588f20f40686bddc145144d [formerly 3c68169e206863118588f20f40686bddc145144d [formerly 1ccb1cee8b8fc74bd7f9aa0727390328b3564c12 [formerly fe0b39553f7125305a719395025854f9001858fa]]]]] Former-commit-id: 7bb7976992e4ceed5882b58c925357a02385d61b Former-commit-id: 2f66a885969adb564d488aea7310c41602b1804b Former-commit-id: e0fdecc9c473163bb03a51f8bc0dd15f8325eea3 [formerly facdffc996dac5e9a2fb837c1b589a7720cafb9c] Former-commit-id: 9cbacea58e103d30bb838052127c4f59feda348d Former-commit-id: 2e686a4d7d2cc0c8476053471de0efdf9cd60f99 Former-commit-id: 1588e96c18ada37cfbf7475019725bbdd9f4a9ee Former-commit-id: bc0a9d1d153ab2e8e1e2d9066fccda9921b8a131 Former-commit-id: 0a05d3db7a263084170beea3ee47cd7efa7dc027 --- src/pages/demo/filters/day/index.vue | 120 +++++++++++++-------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/src/pages/demo/filters/day/index.vue b/src/pages/demo/filters/day/index.vue index a58ab53f..7c6ce7ee 100644 --- a/src/pages/demo/filters/day/index.vue +++ b/src/pages/demo/filters/day/index.vue @@ -2,79 +2,79 @@
- value = {{value}} + 原值 value : {{value}}
- - - - - - - - + + + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - + + + + + - - - - - + + + + + - - - - + + + + - - - - - - + + + + + + - - + + - + - - - - - - + + + + + + - - - - + + + +
From d14672667fbf97a729b86a3813c46092abb7f474 Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Sun, 16 Dec 2018 12:40:01 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=BC=94=E7=A4=BA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=98=BE=E7=A4=BA=EF=BC=8C=E5=B8=AE=E5=8A=A9?= =?UTF-8?q?=E7=90=86=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 1dfab754fe77b7a8f6fa1d053c7f2df52a72fb3d [formerly 1dfab754fe77b7a8f6fa1d053c7f2df52a72fb3d [formerly 1dfab754fe77b7a8f6fa1d053c7f2df52a72fb3d [formerly 1dfab754fe77b7a8f6fa1d053c7f2df52a72fb3d [formerly c126939c14dfc1f4de83826542d25b6742a0efba [formerly 0feb4c994c1b1ec96b04e19165d22f3d9b9798b5]]]]] Former-commit-id: b86edf90b0d5a101666f974c0870383d4bddf4d4 Former-commit-id: 1fff3f00778fdc111a1afe6b510c2aaf9eaa90a6 Former-commit-id: c493552f0eec495528ad7fce12850accce9faef7 [formerly d269ed5b45a082222ecc68712255f8496c817f2e] Former-commit-id: 5ee1efa4e3fbf9355d9715cf5ba0521934320503 Former-commit-id: f5ad3a4b65fcaef1387fe5ca7acf77ff7b10f15c Former-commit-id: 079eebf234456b8b466d44f7513f2da9e43d4bce Former-commit-id: 544e86957c428321a8461a2bba43494fa2cf00ba Former-commit-id: 0505b45caaf091d3fad13337a13be7f612619f47 --- .../day/components/code-and-result.vue | 36 +++--- src/pages/demo/filters/day/index.vue | 118 +++++++++--------- 2 files changed, 73 insertions(+), 81 deletions(-) diff --git a/src/pages/demo/filters/day/components/code-and-result.vue b/src/pages/demo/filters/day/components/code-and-result.vue index 67463d06..b3c1fb50 100644 --- a/src/pages/demo/filters/day/components/code-and-result.vue +++ b/src/pages/demo/filters/day/components/code-and-result.vue @@ -1,18 +1,26 @@ @@ -33,15 +41,6 @@ export default { } }, methods: { - buttonClass (index) { - if (index === 0) { - return 'code-and-result--button__first' - } else if (index === this.labelList.length - 1) { - return 'code-and-result--button__last' - } else { - return 'code-and-result--button' - } - }, handleClip (value) { clipboard.writeText(value) this.$notify({ @@ -56,22 +55,15 @@ export default { diff --git a/src/pages/demo/filters/day/index.vue b/src/pages/demo/filters/day/index.vue index 7c6ce7ee..1044b18d 100644 --- a/src/pages/demo/filters/day/index.vue +++ b/src/pages/demo/filters/day/index.vue @@ -5,76 +5,76 @@ 原值 value : {{value}} - - - - - - - - + + + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - + + + + + - - - - - + + + + + - - - - + + + + - - - - - - + + + + + + - - + + - + - - - - - - + + + + + + - - - - + + + + From 6ec88a9b24e0d30604c6330990de7c727d66e554 Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Sun, 16 Dec 2018 12:41:26 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E7=BC=A9=E5=B0=8F=E6=BC=94=E7=A4=BA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=20header=20=E6=8E=A7=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E5=B0=BA=E5=AF=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 5237db4b69ba38f3ba2c8e203e2e67ff9c2d0761 [formerly 5237db4b69ba38f3ba2c8e203e2e67ff9c2d0761 [formerly 5237db4b69ba38f3ba2c8e203e2e67ff9c2d0761 [formerly 5237db4b69ba38f3ba2c8e203e2e67ff9c2d0761 [formerly 29428b595d8efb7f2185d7b43508e9c8721ea971 [formerly 87faeb740c4f1a5d06668fa1eef4558b2359ef80]]]]] Former-commit-id: c75865f24e8368763671cf33dfa6808b143052d0 Former-commit-id: 000e5bbff56fd311467a03fd6099ca21e019588f Former-commit-id: c173c57f21f0211f98cd0b4dff43e719016fe410 [formerly d5c1bb320c744a0e713ef29965346dc8aa839d62] Former-commit-id: b434b37cd43b3c6f4a23463271aa193e7fd855ca Former-commit-id: 8e205e4f34577aab58185eae9a4a7b9f9b551eab Former-commit-id: 22a89ced15888a9873ccc3d13ba69270d50b80d5 Former-commit-id: 77318db0931779b07d75f20e203ccfbc67bd61db Former-commit-id: e187f04073b290ca24c26f192ab5a3e381a7638a --- src/pages/demo/filters/day/index.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/demo/filters/day/index.vue b/src/pages/demo/filters/day/index.vue index 1044b18d..67d7a0a4 100644 --- a/src/pages/demo/filters/day/index.vue +++ b/src/pages/demo/filters/day/index.vue @@ -1,8 +1,8 @@ From 67bbc7725b734588f40875010fc487bfa9135fb6 Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Sun, 16 Dec 2018 14:21:36 +0800 Subject: [PATCH 08/10] @d2-projects/vue-filters-date Former-commit-id: 4f10378208aa67a5072be74c24da3d74ff327af2 [formerly 4f10378208aa67a5072be74c24da3d74ff327af2 [formerly 4f10378208aa67a5072be74c24da3d74ff327af2 [formerly 4f10378208aa67a5072be74c24da3d74ff327af2 [formerly c07c0f99b4a31dfc1a686002ad6b82976e26eefc [formerly 1a4246217c1cd6931ad915b546740c2e4f3ecf7d]]]]] Former-commit-id: 76c50d24a2feab3f5e5711a7287e20ef5c767b8f Former-commit-id: e77efd8622d1c0effdc47f385a700c37d1be7734 Former-commit-id: 95fc10c83c6de1956eb0d81fa7cc604016777bda [formerly 5cb0b573e2b6976e7ce8a2b3335a043828bb09d7] Former-commit-id: 0918c2b1d4ca59dcb561888b8afa3c88e299a3c5 Former-commit-id: 39dad34618d230a9386de15046d013bcc0774d1d Former-commit-id: 3c5ca48402581d7eb080843111b5906e6817425a Former-commit-id: 7865ae783991f2df19684c58d6fd55f132383588 Former-commit-id: 87e4572ff7182eb2480f746c9e98f514c2f4fc05 --- package-lock.json.REMOVED.git-id | 2 +- package.json | 1 + src/filters/module.date.js | 98 -------------------------------- src/plugin/d2admin/index.js | 4 +- 4 files changed, 4 insertions(+), 101 deletions(-) delete mode 100644 src/filters/module.date.js diff --git a/package-lock.json.REMOVED.git-id b/package-lock.json.REMOVED.git-id index cc2a0b82..a8602ab8 100644 --- a/package-lock.json.REMOVED.git-id +++ b/package-lock.json.REMOVED.git-id @@ -1 +1 @@ -71c7a0f0efd0c1c51288f45b81f5c519d81068cb \ No newline at end of file +94d0ae90880c3276771b5f95da03cb7b4ac7effe \ No newline at end of file diff --git a/package.json b/package.json index a0ec1396..82de57b7 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ }, "dependencies": { "@d2-projects/d2-crud": "^1.3.4", + "@d2-projects/vue-filters-date": "^1.0.0", "axios": "^0.17.1", "babel-polyfill": "^6.26.0", "better-scroll": "^1.12.1", diff --git a/src/filters/module.date.js b/src/filters/module.date.js deleted file mode 100644 index 35352ce6..00000000 --- a/src/filters/module.date.js +++ /dev/null @@ -1,98 +0,0 @@ -// 日期时间相关 filter -// https://github.com/iamkun/dayjs/blob/master/docs/zh-cn/API-reference.md - -import dayjs from 'dayjs' - -// 对象代理 -const P = Day => { - return new Proxy(Day, { - get (target, key) { - if (dayjs.isDayjs(target)) { - // 是 Dayjs 对象,正常返回 - return target[key] - } else { - // 不是 Dayjs 对象 - if (dayjs(target).isValid()) { - // 尝试帮用户解析成 Dayjs 对象 - return dayjs(target)[key] - } else { - // 无法解析 - return function () { - return '无效日期' - } - } - } - }, - set (target, key, value) { - target[key] = value - } - }) -} - -const filters = { - // ---------- [ dayjs 解析 ] ---------- - // 时间字符串 | Date 对象 | Unix 时间戳 (毫秒) - day: value => dayjs(value), - // Unix 时间戳 (秒) - date_unix: value => dayjs.unix(value), - // ---------- [ 获取 ] ---------- - date_year: Day => P(Day).year(), - date_month: Day => P(Day).month(), - date_date: Day => P(Day).date(), - date_day: Day => P(Day).day(), - date_hour: Day => P(Day).hour(), - date_minute: Day => P(Day).minute(), - date_second: Day => P(Day).second(), - date_millisecond: Day => P(Day).millisecond(), - // ---------- [ 设置 ] ---------- - // date | day | month | year | hour | minute | second | millisecond - // 对大小写不敏感 - date_set: (Day, unit, value) => P(Day).set(unit, value), - // ---------- [ 操作 ] ---------- - // 增加 - date_add: (Day, value, unit) => P(Day).add(value, unit), - // 减少 - date_subtract: (Day, value, unit) => P(Day).subtract(value, unit), - // 开头时间 - date_startof: (Day, unit) => P(Day).startOf(unit), - // 末尾时间 - date_endof: (Day, unit) => P(Day).endOf(unit), - // ---------- [ 显示 ] ---------- - // 格式化 - date_format: (Day, setting = 'YYYY-MM-DD HH:mm:ss') => P(Day).format(setting), - // 时间差 - date_diff: (Day, Day2 = '', unit = 'millisecond', accurate = false) => P(Day).diff(dayjs(Day2), unit, accurate), - // Unix 时间戳 (毫秒) - date_value_millisecond: Day => P(Day).valueOf(), - // Unix 时间戳 (秒) - date_value_second: Day => P(Day).unix(), - // 月份的天数 - date_days_in_month: Day => P(Day).daysInMonth(), - // Date 对象 - date_to_date: Day => P(Day).toDate(), - // 数组 - date_to_array: Day => P(Day).toArray(), - // JSON - date_to_json: Day => P(Day).toJSON(), - // ISO8601 格式 - date_to_iso: Day => P(Day).toISOString(), - // 对象 - date_to_object: Day => P(Day).toObject(), - // 字符 - date_to_string: Day => P(Day).toString(), - // ---------- [ 查询 ] ---------- - // 是否之前 - date_is_before: (Day, Day2, unit = 'millisecond') => P(Day).isBefore(dayjs(Day2), unit), - // 是否之后 - date_is_after: (Day, Day2, unit = 'millisecond') => P(Day).isAfter(dayjs(Day2), unit), - // 是否相同 - date_is_same: (Day, Day2, unit = 'millisecond') => P(Day).isSame(dayjs(Day2), unit) -} - -export default { - install: function (Vue) { - Object.keys(filters).forEach(name => { - Vue.filter(name, filters[name]) - }) - } -} diff --git a/src/plugin/d2admin/index.js b/src/plugin/d2admin/index.js index 3e9724c7..a552f8ec 100644 --- a/src/plugin/d2admin/index.js +++ b/src/plugin/d2admin/index.js @@ -8,7 +8,7 @@ import '@/components' // svg 图标 import '@/assets/svg-icons' // 过滤器 -import d2VueFiltersDateModule from '@/filters/module.date' +import d2VueFiltersDate from '@d2-projects/vue-filters-date' // 功能插件 import pluginError from '@/plugin/error' import pluginExport from '@/plugin/export' @@ -32,7 +32,7 @@ export default { // Element Vue.use(ElementUI) // 过滤器 日期模块 - Vue.use(d2VueFiltersDateModule) + Vue.use(d2VueFiltersDate) // 插件 Vue.use(pluginError) Vue.use(pluginExport) From 20dcc667788278439cc728727a0a4962905fed82 Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Sun, 16 Dec 2018 14:32:50 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: a12171da79bf5de664283e6d4597563775c1f287 [formerly a12171da79bf5de664283e6d4597563775c1f287 [formerly a12171da79bf5de664283e6d4597563775c1f287 [formerly a12171da79bf5de664283e6d4597563775c1f287 [formerly 119b3a9dade5a4b0f0ae6a5f704208ecb4c78de3 [formerly 10239e8af2895132fa0fd71ab108847891c2178e]]]]] Former-commit-id: e828ec18eae34256635931d1580ac9ad958fb704 Former-commit-id: c2ce864268f597cdb782d9b79b5755dd690d0773 Former-commit-id: 4c194d2f66f978006074346ffde4689317f01bae [formerly 810262e1ffb2c5c25ab00aa10377a3f428b31409] Former-commit-id: b036173ce83075de020627bca3621d95473b150f Former-commit-id: 38f0fb0dfd70d32ec2979e14e41eb2f29b5fd7e5 Former-commit-id: 98bb3486e63e997551c57fe0787732815f5bff50 Former-commit-id: cb26de635e0af16a26e8c96b8a278ffacaaf0b36 Former-commit-id: fd8164c83f1530d511915629db8d831088f1a6fe --- package-lock.json.REMOVED.git-id | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json.REMOVED.git-id b/package-lock.json.REMOVED.git-id index a8602ab8..3e323edb 100644 --- a/package-lock.json.REMOVED.git-id +++ b/package-lock.json.REMOVED.git-id @@ -1 +1 @@ -94d0ae90880c3276771b5f95da03cb7b4ac7effe \ No newline at end of file +6c7225791d502ed1e41cead2c43f6f321f5ab485 \ No newline at end of file diff --git a/package.json b/package.json index 82de57b7..27b58c95 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ }, "dependencies": { "@d2-projects/d2-crud": "^1.3.4", - "@d2-projects/vue-filters-date": "^1.0.0", + "@d2-projects/vue-filters-date": "^1.0.2", "axios": "^0.17.1", "babel-polyfill": "^6.26.0", "better-scroll": "^1.12.1", From d039a6438fbd51db46e98afd35765b743b5dfa24 Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Sun, 16 Dec 2018 15:39:29 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E5=B0=86=E8=A1=A8=E6=A0=BC=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=AF=BC=E5=87=BA=E6=8F=90=E5=8F=96=E4=B8=BA=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E7=9A=84=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 022d07c06618417af8e2895dd00fcac3e0238c09 [formerly 022d07c06618417af8e2895dd00fcac3e0238c09 [formerly 022d07c06618417af8e2895dd00fcac3e0238c09 [formerly 022d07c06618417af8e2895dd00fcac3e0238c09 [formerly 3a6388bd7e36b1bbd3d22767b2dc3a4e462402b7 [formerly 15059226e8bd77dcbe7212699c6bab6b6ff9d385]]]]] Former-commit-id: bfa445ba0136208e94ef7244f8bf127d2b186bfd Former-commit-id: d9e3059e625371a01176c7fdcb34a25a5ea247d5 Former-commit-id: f543910387e755b14d40eec2b42eaed43c500d53 [formerly 4d3007385ebb14bf7ec659c68251af6358cc5982] Former-commit-id: 19d3ef449fa36d92f5799987d6cda668c9b3534e Former-commit-id: 91a0cb0497884cd435ff29d6b714e35b22eb9f4d Former-commit-id: 0edac75e2cf32f0001191c3b3e9829bcd081ed66 Former-commit-id: b3cfe8d5c3432d308dad9437de878f4e22008ca7 Former-commit-id: 94ec0467d510f8506c5d5e6da7aa5f377c350cb3 --- package-lock.json.REMOVED.git-id | 2 +- package.json | 7 +- src/plugin/d2admin/index.js | 4 +- src/plugin/export/_blob.js | 179 ----------------------------- src/plugin/export/_csv.js | 62 ---------- src/plugin/export/_export-csv.js | 83 ------------- src/plugin/export/_export2Excel.js | 151 ------------------------ src/plugin/export/index.js | 73 ------------ src/plugin/import/index.js | 62 ---------- 9 files changed, 6 insertions(+), 617 deletions(-) delete mode 100644 src/plugin/export/_blob.js delete mode 100755 src/plugin/export/_csv.js delete mode 100755 src/plugin/export/_export-csv.js delete mode 100644 src/plugin/export/_export2Excel.js delete mode 100644 src/plugin/export/index.js delete mode 100644 src/plugin/import/index.js diff --git a/package-lock.json.REMOVED.git-id b/package-lock.json.REMOVED.git-id index 3e323edb..97098837 100644 --- a/package-lock.json.REMOVED.git-id +++ b/package-lock.json.REMOVED.git-id @@ -1 +1 @@ -6c7225791d502ed1e41cead2c43f6f321f5ab485 \ No newline at end of file +2b614609fc8311fc059d290422304b490e9a3abc \ No newline at end of file diff --git a/package.json b/package.json index 27b58c95..96d39b4c 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ "dependencies": { "@d2-projects/d2-crud": "^1.3.4", "@d2-projects/vue-filters-date": "^1.0.2", + "@d2-projects/vue-table-export": "^1.0.1", + "@d2-projects/vue-table-import": "^1.0.0", "axios": "^0.17.1", "babel-polyfill": "^6.26.0", "better-scroll": "^1.12.1", @@ -23,7 +25,6 @@ "dayjs": "^1.6.7", "echarts": "^4.1.0", "element-ui": "^2.4.4", - "file-saver": "^1.3.3", "flex.css": "^1.1.7", "fuse.js": "^3.2.1", "github-markdown-css": "^2.10.0", @@ -35,7 +36,6 @@ "marked": "^0.3.9", "mockjs": "^1.0.1-beta3", "nprogress": "^0.2.0", - "papaparse": "^4.3.6", "qs": "^6.6.0", "quill": "^1.3.4", "screenfull": "^3.3.2", @@ -50,8 +50,7 @@ "vue-router": "^3.0.1", "vue-splitpane": "^1.0.2", "vue-ueditor-wrap": "^1.5.0", - "vuex": "^3.0.1", - "xlsx": "^0.12.0" + "vuex": "^3.0.1" }, "devDependencies": { "@kazupon/vue-i18n-loader": "^0.3.0", diff --git a/src/plugin/d2admin/index.js b/src/plugin/d2admin/index.js index a552f8ec..329d2ebf 100644 --- a/src/plugin/d2admin/index.js +++ b/src/plugin/d2admin/index.js @@ -11,8 +11,8 @@ import '@/assets/svg-icons' import d2VueFiltersDate from '@d2-projects/vue-filters-date' // 功能插件 import pluginError from '@/plugin/error' -import pluginExport from '@/plugin/export' -import pluginImport from '@/plugin/import' +import pluginExport from '@d2-projects/vue-table-export' +import pluginImport from '@d2-projects/vue-table-import' import pluginLog from '@/plugin/log' import pluginOpen from '@/plugin/open' diff --git a/src/plugin/export/_blob.js b/src/plugin/export/_blob.js deleted file mode 100644 index 26382ccd..00000000 --- a/src/plugin/export/_blob.js +++ /dev/null @@ -1,179 +0,0 @@ -/* eslint-disable */ -/* Blob.js - * A Blob implementation. - * 2014-05-27 - * - * By Eli Grey, http://eligrey.com - * By Devin Samarin, https://github.com/eboyjr - * License: X11/MIT - * See LICENSE.md - */ - -/*global self, unescape */ -/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true, - plusplus: true */ - -/*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */ - -(function (view) { - "use strict"; - - view.URL = view.URL || view.webkitURL; - - if (view.Blob && view.URL) { - try { - new Blob; - return; - } catch (e) {} - } - - // Internally we use a BlobBuilder implementation to base Blob off of - // in order to support older browsers that only have BlobBuilder - var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function(view) { - var - get_class = function(object) { - return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1]; - } - , FakeBlobBuilder = function BlobBuilder() { - this.data = []; - } - , FakeBlob = function Blob(data, type, encoding) { - this.data = data; - this.size = data.length; - this.type = type; - this.encoding = encoding; - } - , FBB_proto = FakeBlobBuilder.prototype - , FB_proto = FakeBlob.prototype - , FileReaderSync = view.FileReaderSync - , FileException = function(type) { - this.code = this[this.name = type]; - } - , file_ex_codes = ( - "NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR " - + "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR" - ).split(" ") - , file_ex_code = file_ex_codes.length - , real_URL = view.URL || view.webkitURL || view - , real_create_object_URL = real_URL.createObjectURL - , real_revoke_object_URL = real_URL.revokeObjectURL - , URL = real_URL - , btoa = view.btoa - , atob = view.atob - - , ArrayBuffer = view.ArrayBuffer - , Uint8Array = view.Uint8Array - ; - FakeBlob.fake = FB_proto.fake = true; - while (file_ex_code--) { - FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1; - } - if (!real_URL.createObjectURL) { - URL = view.URL = {}; - } - URL.createObjectURL = function(blob) { - var - type = blob.type - , data_URI_header - ; - if (type === null) { - type = "application/octet-stream"; - } - if (blob instanceof FakeBlob) { - data_URI_header = "data:" + type; - if (blob.encoding === "base64") { - return data_URI_header + ";base64," + blob.data; - } else if (blob.encoding === "URI") { - return data_URI_header + "," + decodeURIComponent(blob.data); - } if (btoa) { - return data_URI_header + ";base64," + btoa(blob.data); - } else { - return data_URI_header + "," + encodeURIComponent(blob.data); - } - } else if (real_create_object_URL) { - return real_create_object_URL.call(real_URL, blob); - } - }; - URL.revokeObjectURL = function(object_URL) { - if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) { - real_revoke_object_URL.call(real_URL, object_URL); - } - }; - FBB_proto.append = function(data/*, endings*/) { - var bb = this.data; - // decode data to a binary string - if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) { - var - str = "" - , buf = new Uint8Array(data) - , i = 0 - , buf_len = buf.length - ; - for (; i < buf_len; i++) { - str += String.fromCharCode(buf[i]); - } - bb.push(str); - } else if (get_class(data) === "Blob" || get_class(data) === "File") { - if (FileReaderSync) { - var fr = new FileReaderSync; - bb.push(fr.readAsBinaryString(data)); - } else { - // async FileReader won't work as BlobBuilder is sync - throw new FileException("NOT_READABLE_ERR"); - } - } else if (data instanceof FakeBlob) { - if (data.encoding === "base64" && atob) { - bb.push(atob(data.data)); - } else if (data.encoding === "URI") { - bb.push(decodeURIComponent(data.data)); - } else if (data.encoding === "raw") { - bb.push(data.data); - } - } else { - if (typeof data !== "string") { - data += ""; // convert unsupported types to strings - } - // decode UTF-16 to binary string - bb.push(unescape(encodeURIComponent(data))); - } - }; - FBB_proto.getBlob = function(type) { - if (!arguments.length) { - type = null; - } - return new FakeBlob(this.data.join(""), type, "raw"); - }; - FBB_proto.toString = function() { - return "[object BlobBuilder]"; - }; - FB_proto.slice = function(start, end, type) { - var args = arguments.length; - if (args < 3) { - type = null; - } - return new FakeBlob( - this.data.slice(start, args > 1 ? end : this.data.length) - , type - , this.encoding - ); - }; - FB_proto.toString = function() { - return "[object Blob]"; - }; - FB_proto.close = function() { - this.size = this.data.length = 0; - }; - return FakeBlobBuilder; - }(view)); - - view.Blob = function Blob(blobParts, options) { - var type = options ? (options.type || "") : ""; - var builder = new BlobBuilder(); - if (blobParts) { - for (var i = 0, len = blobParts.length; i < len; i++) { - builder.append(blobParts[i]); - } - } - return builder.getBlob(type); - }; -}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this)); diff --git a/src/plugin/export/_csv.js b/src/plugin/export/_csv.js deleted file mode 100755 index de2796cb..00000000 --- a/src/plugin/export/_csv.js +++ /dev/null @@ -1,62 +0,0 @@ -/* - 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.label !== 'undefined' ? v.label : v.prop); - } - return v.prop; - }); - 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); -} diff --git a/src/plugin/export/_export-csv.js b/src/plugin/export/_export-csv.js deleted file mode 100755 index 50caf2af..00000000 --- a/src/plugin/export/_export-csv.js +++ /dev/null @@ -1,83 +0,0 @@ -/* eslint-disable */ - -/* - 此代码来源于iview表格组件的CSV导出部分 - https://github.com/iview/iview -*/ - -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 + '.csv'); - 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 + '.csv'); - } else { - const link = document.createElement('a'); - link.download = filename + '.csv'; - link.href = this._getDownloadUrl(text); - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - } - } -}; - -export default csv; \ No newline at end of file diff --git a/src/plugin/export/_export2Excel.js b/src/plugin/export/_export2Excel.js deleted file mode 100644 index 0efa20ef..00000000 --- a/src/plugin/export/_export2Excel.js +++ /dev/null @@ -1,151 +0,0 @@ -/* eslint-disable */ - -// 来源于网络 有细微改动 - -import './_blob' -import FileSaver 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); - console.log('a') - var oo = generateArray(theTable); - var ranges = oo[1]; - - /* original data */ - var data = oo[0]; - var ws_name = "SheetJS"; - console.log(data); - - 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'}); - - FileSaver.saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), "test.xlsx") -} - -function formatJson(jsonData) { - console.log(jsonData) -} -export function export_json_to_excel(th, jsonData, defaultTitle, options = { merges: [], header: null }) { - - /* original data */ - - var data = jsonData; - data.unshift(th); - if (options.header) data.unshift([options.header]); - var ws_name = "SheetJS"; - - var wb = new Workbook(), ws = sheet_from_array_of_arrays(data); - - /* add merges area to worksheet */ - let { merges } = options; - if (typeof merges[0] == 'string' && merges.length == 2) merges = [merges] // just one # ['A1', 'C1'] = > [['A1', 'C1']] - merges = merges.map(i => i instanceof Array ? { s: i[0], e: i[1] } : i); // be sort :) # ['A1', 'C1'] => { s: 'A1', e: 'C3' } - ws['!merges'] = merges; - - /* 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'}); - var title = defaultTitle || '列表' - FileSaver.saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx") -} diff --git a/src/plugin/export/index.js b/src/plugin/export/index.js deleted file mode 100644 index 3449897b..00000000 --- a/src/plugin/export/index.js +++ /dev/null @@ -1,73 +0,0 @@ -/* eslint-disable */ - -// 库 -import Csv from './_csv' -import ExportCsv from './_export-csv' -import FileSaver from 'file-saver' -import * as Excel from './_export2Excel' - -export default { - install (Vue, options) { - Vue.prototype.$export = { - // 导出 csv - csv (params) { - return new Promise((resolve, reject) => { - // 默认值 - const paramsDefault = { - columns: [], - data: [], - title: 'table', - noHeader: false - } - // 合并参数 - const _params = Object.assign({}, paramsDefault, params) - // 生成数据 - const data = Csv(_params.columns, _params.data, params, _params.noHeader) - // 下载数据 - ExportCsv.download(_params.title, data) - // 完成 - resolve() - }) - }, - // 导出 excel - excel (params) { - return new Promise((resolve, reject) => { - // 默认值 - const paramsDefault = { - columns: [], - data: [], - title: 'table', - header: null, - merges: [] - } - // 合并参数 - const _params = Object.assign({}, paramsDefault, params) - // 从参数中派生数据 - const header = _params.columns.map(e => e.label) - const data = _params.data.map(row => _params.columns.map(col => row[col.prop])) - // 导出 - Excel.export_json_to_excel(header, data, _params.title, { merges: _params.merges, header: _params.header }) - // 完成 - resolve() - }) - }, - // 导出 文本文档 - txt (params) { - return new Promise((resolve, reject) => { - // 默认值 - const paramsDefault = { - text: '', - title: '文本' - } - // 合并参数 - const _params = Object.assign({}, paramsDefault, params) - // 导出 - const blob = new Blob([_params.text], {type: 'text/plain;charset=utf-8'}) - FileSaver.saveAs(blob, _params.title + '.txt') - // 完成 - resolve() - }) - } - } - } -} diff --git a/src/plugin/import/index.js b/src/plugin/import/index.js deleted file mode 100644 index 467e4eaa..00000000 --- a/src/plugin/import/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/* eslint-disable */ - -// 库 -import papa from 'papaparse' -import xlsx from 'xlsx' - -export default { - install (Vue, options) { - Vue.prototype.$import = { - // 导入 csv - csv (file) { - return new Promise((resolve, reject) => { - papa.parse(file, { - header: true, - skipEmptyLines: true, - complete: (results, file) => { - resolve(results) - } - }) - }) - }, - // 导入 xlsx - xlsx (file) { - return new Promise((resolve, reject) => { - const reader = new FileReader() - const fixdata = data => { - let o = '' - let l = 0 - const w = 10240 - for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w))) - o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w))) - return o - } - const getHeaderRow = sheet => { - const headers = [] - const range = xlsx.utils.decode_range(sheet['!ref']) - let C - const R = range.s.r - for (C = range.s.c; C <= range.e.c; ++C) { - var cell = sheet[xlsx.utils.encode_cell({ c: C, r: R })] - var hdr = 'UNKNOWN ' + C - if (cell && cell.t) hdr = xlsx.utils.format_cell(cell) - headers.push(hdr) - } - return headers - } - reader.onload = e => { - const data = e.target.result - const fixedData = fixdata(data) - const workbook = xlsx.read(btoa(fixedData), { type: 'base64' }) - const firstSheetName = workbook.SheetNames[0] - const worksheet = workbook.Sheets[firstSheetName] - const header = getHeaderRow(worksheet) - const results = xlsx.utils.sheet_to_json(worksheet) - resolve({header, results}) - } - reader.readAsArrayBuffer(file) - }) - } - } - } -}