├── 6 位数密码输入框(仿照支付宝) └── pwd │ ├── img │ └── blink.gif │ ├── api.js │ └── index.vue ├── Vue2.0 实现上拉加载下拉刷新 ├── components │ ├── img │ │ ├── down-logo.png │ │ └── refresh-logo.gif │ ├── less │ │ └── index.less │ └── index.vue └── index.vue └── Vue2.x 导出Excel格式 ├── src ├── app.js ├── index.ejs └── views │ ├── json │ └── data.json │ ├── excel │ ├── Export2Excel.js │ └── Blob.js │ └── App.vue ├── Vue2.x 将页面中表格数据导出excel.md ├── package.json └── webpack.config.js /6 位数密码输入框(仿照支付宝)/pwd/img/blink.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rkatsiteli/Vue-archive/HEAD/6 位数密码输入框(仿照支付宝)/pwd/img/blink.gif -------------------------------------------------------------------------------- /Vue2.0 实现上拉加载下拉刷新/components/img/down-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rkatsiteli/Vue-archive/HEAD/Vue2.0 实现上拉加载下拉刷新/components/img/down-logo.png -------------------------------------------------------------------------------- /Vue2.0 实现上拉加载下拉刷新/components/img/refresh-logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rkatsiteli/Vue-archive/HEAD/Vue2.0 实现上拉加载下拉刷新/components/img/refresh-logo.gif -------------------------------------------------------------------------------- /Vue2.x 导出Excel格式/src/app.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | import Vue from 'vue'; 4 | 5 | import App from 'views/App.vue'; 6 | const app = new Vue({ 7 | render: h => h(App), 8 | }).$mount('#app') -------------------------------------------------------------------------------- /Vue2.x 导出Excel格式/src/index.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /6 位数密码输入框(仿照支付宝)/pwd/api.js: -------------------------------------------------------------------------------- 1 | import "@/js/utils"; //公共方法 2 | import '@/js/utils/ajax'; 3 | export default { 4 | getMobile(cb) { 5 | /*$.ajax({ 6 | type: "POST", 7 | async: false, 8 | url: "/pub/sylla/phr-p/phr/second-auth/get-mobile", 9 | success: response => { 10 | debugger 11 | cb && cb(response); 12 | }, 13 | error: error => { 14 | utils.toast(error); 15 | } 16 | });*/ 17 | 18 | /*** 19 | * libUtils.ajax 20 | */ 21 | /*ajax.ajax({ 22 | url: "/pub/sylla/phr-p/phr/second-auth/get-mobile", 23 | success: response => { 24 | debugger 25 | cb && cb(response); 26 | }, 27 | error: error => { 28 | utils.toast(error); 29 | }, 30 | data: { 31 | name1: 'value1', 32 | name2: 'value2' 33 | }, 34 | method: "get" 35 | });*/ 36 | 37 | ajax.post({ 38 | async: false, 39 | url: "/pub/sylla/phr-p/phr/second-auth/get-mobile", 40 | success: response => { 41 | cb && cb(response); 42 | }, 43 | error: error => { 44 | utils.toast(error); 45 | }, 46 | data: { 47 | name1: 'value1', 48 | name2: 'value2' 49 | }, 50 | method: "get" 51 | }); 52 | 53 | 54 | console.log(1111) 55 | 56 | } 57 | 58 | }; -------------------------------------------------------------------------------- /Vue2.x 导出Excel格式/Vue2.x 将页面中表格数据导出excel.md: -------------------------------------------------------------------------------- 1 | #### Vue2.x 将页面中表格数据导出excel 2 | 3 | 第一步:安装依赖 4 | ``` 5 | npm install -S file-saver xlsx 6 | 7 | npm install -D script-loader 8 | ``` 9 | 10 | 二、项目中新建一个文件夹:(excel---名字任取) 11 | 12 | >里面放置两个文件**Blob.js**和 **Export2Excel.js**,文件 [ 在这里](https://github.com/Rkatsiteli/Vue-archive/tree/master/Vue2.x%20%E5%AF%BC%E5%87%BAExcel%E6%A0%BC%E5%BC%8F)。 13 | 14 | 15 | 三、在.vue文件中,写这两个方法:其中list是表格的内容 16 | 17 | 18 | ``` 19 | export2Excel() { 20 |   require.ensure([], () => { 21 |     const { export_json_to_excel } = require('../../vendor/Export2Excel'); 22 |     const tHeader = ['序号', 'IMSI', 'MSISDN', '证件号码', '姓名']; 23 |     const filterVal = ['ID', 'imsi', 'msisdn', 'address', 'name']; 24 |     const list = this.tableData; 25 |     const data = this.formatJson(filterVal, list); 26 |     export_json_to_excel(tHeader, data, '列表excel'); 27 |   }) 28 | }, 29 | formatJson(filterVal, jsonData) { 30 | return jsonData.map(v => filterVal.map(j => v[j])) 31 | } 32 | ``` 33 | 34 | [GitHub 在这里](https://github.com/Rkatsiteli/Vue-archive/tree/master/Vue2.x%20%E5%AF%BC%E5%87%BAExcel%E6%A0%BC%E5%BC%8F) 35 | 36 | --- 37 | 38 | [参考地址,在这里](https://www.cnblogs.com/Mrfan217/p/6944238.html) 39 | 40 | -------------------------------------------------------------------------------- /Vue2.x 导出Excel格式/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eoiHome", 3 | "version": "1.0.1", 4 | "description": "", 5 | "main": "gulpfile.js", 6 | "scripts": { 7 | "test1": "echo \"Error: no test specified\" && exit 1", 8 | "dev": "webpack-dev-server --devtool eval --progress --colors --content-base build --mode development", 9 | "build": "set NODE_ENV=prod&&webpack --hide-modules --mode production" 10 | }, 11 | "author": "", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "babel-core": "^6.26.3", 15 | "babel-loader": "^7.1.4", 16 | "babel-plugin-transform-runtime": "^6.23.0", 17 | "babel-polyfill": "^6.26.0", 18 | "babel-preset-es2015": "^6.24.1", 19 | "babel-preset-stage-0": "^6.24.1", 20 | "babel-runtime": "^6.26.0", 21 | "css-loader": "^0.28.11", 22 | "html-webpack-plugin": "^3.2.0", 23 | "json-loader": "^0.5.7", 24 | "less": "^3.0.4", 25 | "less-loader": "^4.1.0", 26 | "script-loader": "^0.7.2", 27 | "style-loader": "^0.21.0", 28 | "vue": "^2.5.16", 29 | "vue-hot-reload-api": "^2.3.0", 30 | "vue-html-loader": "^1.2.4", 31 | "vue-loader": "^14.2.2", 32 | "vue-router": "^3.0.1", 33 | "vue-style-loader": "^4.1.0", 34 | "vue-template-compiler": "^2.5.16", 35 | "vuex": "^3.0.1", 36 | "webpack": "^4.8.3", 37 | "webpack-cli": "^2.1.3", 38 | "webpack-dev-server": "^3.1.4" 39 | }, 40 | "dependencies": { 41 | "file-saver": "^1.3.8", 42 | "xlsx": "^0.12.12" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Vue2.0 实现上拉加载下拉刷新/index.vue: -------------------------------------------------------------------------------- 1 | 11 | 19 | -------------------------------------------------------------------------------- /Vue2.0 实现上拉加载下拉刷新/components/less/index.less: -------------------------------------------------------------------------------- 1 | .yo-scroll { 2 | font-size: 24px; 3 | position: absolute; 4 | top: 0; 5 | right: 0; 6 | bottom: 0; 7 | left: 0; 8 | overflow: auto; 9 | z-index: 100; 10 | height: auto; 11 | -webkit-overflow-scrolling: touch; 12 | .inner { 13 | position: absolute; 14 | top: -5rem; 15 | width: 100%; 16 | height: auto; 17 | transition-duration: 300ms; 18 | .pull-refresh { 19 | position: relative; 20 | left: 0; 21 | top: 0; 22 | width: 100%; 23 | height: 5rem; 24 | display: flex; 25 | display: -webkit-flex; 26 | align-items: center; 27 | justify-content: center; 28 | } 29 | .load-more { 30 | height: 5rem; 31 | line-height: 5rem; 32 | display: flex; 33 | text-align: center; 34 | align-items: center; 35 | justify-content: center; 36 | display: none; 37 | } 38 | .nullData {//暂无更多数据样式 39 | font-size: 26px; 40 | color: #999999; 41 | height: 100px; 42 | line-height: 100px; 43 | text-align: center; 44 | } 45 | .down-tip, 46 | .refresh-tip, 47 | .up-tip { 48 | display: none; 49 | } 50 | .up-tip:before, 51 | .refresh-tip:before { 52 | content: ''; 53 | display: inline-block; 54 | width: 160px; 55 | height: 70px; 56 | background-size: 70% !important; 57 | position: absolute; 58 | top: 0; 59 | left: 20%; 60 | } 61 | .up-tip:before { 62 | background: url(../img/down-logo.png) no-repeat center; 63 | } 64 | .refresh-tip:before { 65 | background: url(../img/refresh-logo.gif) no-repeat center; 66 | } 67 | } 68 | } 69 | 70 | .yo-scroll.touch .inner { 71 | transition-duration: 0; 72 | } 73 | 74 | .yo-scroll.down .down-tip { 75 | display: block; 76 | } 77 | 78 | .yo-scroll.up .up-tip { 79 | display: block; 80 | } 81 | 82 | .yo-scroll.refresh .refresh-tip { 83 | display: block; 84 | } -------------------------------------------------------------------------------- /Vue2.x 导出Excel格式/webpack.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'), 2 | path = require('path'), 3 | HtmlWebpackPlugin = require('html-webpack-plugin'), 4 | ip = require('ip'); 5 | 6 | const env = process.env.NODE_ENV == "prod"; 7 | const resolve = dir => { 8 | return path.join(__dirname, "./src", dir) 9 | } 10 | 11 | var webpackConfig = { 12 | entry: { 13 | app: [resolve("./app.js")], 14 | }, 15 | output: { 16 | path: resolve("./dist"), 17 | publicPath: '', 18 | filename: "assets/js/[name].js", 19 | chunkFilename: "chunk/[name].js", 20 | }, 21 | devServer: { 22 | inline: true, //开启页面自动刷新 23 | lazy: false, //不启动懒加载 24 | quiet: false, //控制台中不输出打包的信息 25 | progress: true, //显示打包的进度 26 | open: true, 27 | port: 9000, 28 | compress: true, 29 | host: ip.address(), 30 | historyApiFallback: true, 31 | contentBase: "./", 32 | https: false, //先不启动 33 | }, 34 | //4.0配置 35 | optimization: { 36 | runtimeChunk: { 37 | name: "manifest" 38 | }, 39 | splitChunks: { 40 | cacheGroups: { 41 | commons: { 42 | test: /[\\/]node_modules[\\/]/, 43 | name: "../assets/js/vendor", 44 | chunks: "all", 45 | } 46 | } 47 | }, 48 | occurrenceOrder: true // 在不同的模式之间保持文件名一致(例如只构建) 49 | }, 50 | resolve: { 51 | alias: { 52 | 'vue': 'vue/dist/vue.min', 53 | 'vue-router': 'vue-router/dist/vue-router.min', 54 | 'vuex': 'vuex/dist/vuex.min', 55 | "views": resolve("./views") 56 | }, 57 | extensions: ['.js', '.less', '.css', '.vue', '.jsx', '.txt', '.json'], //2.0的配置 58 | }, 59 | resolveLoader: { 60 | moduleExtensions: ['-loader'] 61 | }, 62 | externals: {}, 63 | module: { 64 | //4.0之前是 loaders,现在修改为 rules 65 | rules: [{ 66 | test: /\.js$/, 67 | include: resolve("/"), 68 | loader: 'babel', 69 | }, { 70 | test: /\.vue$/, 71 | loader: 'vue', 72 | }, { 73 | test: /\.(css|less)$/, 74 | include: resolve("/"), 75 | loader: "style!css!less" 76 | }, { 77 | test: /\.(html|tpl)$/, 78 | include: resolve("/"), 79 | loader: 'html' 80 | }, { 81 | test: /\.json$/, 82 | loader: "json" 83 | }, { 84 | test: /\.xml$/, 85 | include: resolve("/"), 86 | loader: "xml" 87 | }, { 88 | test: /\.(png|jpg|jpeg|gif|icon|ico|webp)$/, 89 | include: resolve("/"), 90 | loader: 'url?limit=4192&name=assets/img/[name].[hash:5].[ext]' 91 | }, { 92 | test: /\.(woff|woff2|svg|eot|ttf)\??.*$/, 93 | include: resolve("/"), 94 | loader: "file?&name=assets/fonts/[name].[ext]" 95 | }, { 96 | test: /\.(swf|mp4)?$/, 97 | include: resolve("/"), 98 | loader: 'file?name=assets/video/[name].[hash:5].[ext]', 99 | }, { 100 | test: /\.txt$/, 101 | include: resolve("/"), 102 | loader: "text" 103 | }], 104 | 105 | }, 106 | plugins: [ 107 | new HtmlWebpackPlugin({ 108 | template: resolve('/index.ejs') 109 | }), 110 | ] 111 | }; 112 | 113 | 114 | 115 | module.exports = webpackConfig; -------------------------------------------------------------------------------- /6 位数密码输入框(仿照支付宝)/pwd/index.vue: -------------------------------------------------------------------------------- 1 | 16 | 54 | -------------------------------------------------------------------------------- /Vue2.x 导出Excel格式/src/views/json/data.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "id": "1", 3 | "name": "DAU(日均)", 4 | "value": null, 5 | "order": 1, 6 | "isEdit": false, 7 | "remark": null, 8 | "value0": 333.3827, 9 | "isEdit0": false, 10 | "value3": 445.2123, 11 | "isEdit3": false, 12 | "value1": 0, 13 | "isEdit1": false, 14 | "value2": 55.877, 15 | "isEdit2": false, 16 | "value5": 36001.156, 17 | "isEdit5": false, 18 | "value4": 457.167, 19 | "isEdit4": false, 20 | "value6": 351.8943, 21 | "isEdit6": false 22 | }, { 23 | "id": "6", 24 | "name": "新增7日留存", 25 | "value": null, 26 | "order": 30, 27 | "isEdit": false, 28 | "remark": null, 29 | "value0": 12.01, 30 | "isEdit0": false, 31 | "value3": 0, 32 | "isEdit3": false, 33 | "value1": 0, 34 | "isEdit1": false, 35 | "value2": 0.1104, 36 | "isEdit2": false, 37 | "value5": 0.6417, 38 | "isEdit5": false, 39 | "value4": 0.071, 40 | "isEdit4": false, 41 | "value6": 0.2069, 42 | "isEdit6": false 43 | }, { 44 | "id": "7", 45 | "name": "新增7日留存-外购", 46 | "value": null, 47 | "order": 31, 48 | "isEdit": false, 49 | "remark": null, 50 | "value0": 0, 51 | "isEdit0": false, 52 | "value3": 0, 53 | "isEdit3": false, 54 | "value1": 0, 55 | "isEdit1": false, 56 | "value2": 0, 57 | "isEdit2": false, 58 | "value5": 0.6417, 59 | "isEdit5": false, 60 | "value4": 0, 61 | "isEdit4": false, 62 | "value6": 0.1903, 63 | "isEdit6": false 64 | }, { 65 | "id": "16", 66 | "name": "单DAU收入", 67 | "value": null, 68 | "order": 120, 69 | "isEdit": false, 70 | "remark": null, 71 | "value0": 0, 72 | "isEdit0": false, 73 | "value3": 0, 74 | "isEdit3": false, 75 | "value1": 0, 76 | "isEdit1": false, 77 | "value2": 0, 78 | "isEdit2": false, 79 | "value5": 0, 80 | "isEdit5": false, 81 | "value4": 0, 82 | "isEdit4": false, 83 | "value6": 0, 84 | "isEdit6": false 85 | }, { 86 | "id": "17", 87 | "name": "单个DAU成本", 88 | "value": null, 89 | "order": 130, 90 | "isEdit": false, 91 | "remark": null, 92 | "value0": 0, 93 | "isEdit0": false, 94 | "value3": 0, 95 | "isEdit3": false, 96 | "value1": 0, 97 | "isEdit1": false, 98 | "value2": 0, 99 | "isEdit2": false, 100 | "value5": 62.69, 101 | "isEdit5": false, 102 | "value4": 0, 103 | "isEdit4": false, 104 | "value6": 0, 105 | "isEdit6": false 106 | }, { 107 | "id": "18", 108 | "name": "单个DAU成本-外购", 109 | "value": null, 110 | "order": 131, 111 | "isEdit": false, 112 | "remark": null, 113 | "value0": 58.9, 114 | "isEdit0": false, 115 | "value3": 0, 116 | "isEdit3": false, 117 | "value1": 0, 118 | "isEdit1": false, 119 | "value2": 38131.95, 120 | "isEdit2": false, 121 | "value5": 655.89, 122 | "isEdit5": false, 123 | "value4": 0, 124 | "isEdit4": false, 125 | "value6": 0, 126 | "isEdit6": false 127 | }, { 128 | "id": "19", 129 | "name": "LTV/CPA", 130 | "value": null, 131 | "order": 140, 132 | "isEdit": true, 133 | "remark": null, 134 | "value0": 600, 135 | "isEdit0": false, 136 | "value3": 50, 137 | "isEdit3": false, 138 | "value1": 0, 139 | "isEdit1": false, 140 | "value2": 30, 141 | "isEdit2": false, 142 | "value5": 888, 143 | "isEdit5": false, 144 | "value4": 8888888, 145 | "isEdit4": false, 146 | "value6": 0, 147 | "isEdit6": false 148 | }, { 149 | "id": "20", 150 | "name": "总收入", 151 | "value": null, 152 | "order": 150, 153 | "isEdit": false, 154 | "remark": null, 155 | "value0": 0, 156 | "isEdit0": false, 157 | "value3": 0, 158 | "isEdit3": false, 159 | "value1": 0, 160 | "isEdit1": false, 161 | "value2": 0, 162 | "isEdit2": false, 163 | "value5": 0, 164 | "isEdit5": false, 165 | "value4": 0, 166 | "isEdit4": false, 167 | "value6": 0, 168 | "isEdit6": false 169 | }, { 170 | "id": "21", 171 | "name": "总推广成本【EOI取数】", 172 | "value": null, 173 | "order": 160, 174 | "isEdit": false, 175 | "remark": null, 176 | "value0": 0, 177 | "isEdit0": false, 178 | "value3": 0, 179 | "isEdit3": false, 180 | "value1": 0, 181 | "isEdit1": false, 182 | "value2": 0, 183 | "isEdit2": false, 184 | "value5": 0, 185 | "isEdit5": false, 186 | "value4": 0, 187 | "isEdit4": false, 188 | "value6": 0, 189 | "isEdit6": false 190 | }, { 191 | "id": "22", 192 | "name": "总推广成本(调整项)", 193 | "value": null, 194 | "order": 170, 195 | "isEdit": true, 196 | "remark": null, 197 | "value0": 900, 198 | "isEdit0": false, 199 | "value3": 0, 200 | "isEdit3": false, 201 | "value1": 100, 202 | "isEdit1": false, 203 | "value2": 123456, 204 | "isEdit2": false, 205 | "value5": 6666, 206 | "isEdit5": false, 207 | "value4": 0, 208 | "isEdit4": false, 209 | "value6": 0, 210 | "isEdit6": false 211 | }, { 212 | "id": "23", 213 | "name": "总推广成本", 214 | "value": null, 215 | "order": 180, 216 | "isEdit": false, 217 | "remark": null, 218 | "value0": 900, 219 | "isEdit0": false, 220 | "value3": 0, 221 | "isEdit3": false, 222 | "value1": 100, 223 | "isEdit1": false, 224 | "value2": 123456, 225 | "isEdit2": false, 226 | "value5": 6666, 227 | "isEdit5": false, 228 | "value4": 0, 229 | "isEdit4": false, 230 | "value6": 0, 231 | "isEdit6": false 232 | }] -------------------------------------------------------------------------------- /Vue2.0 实现上拉加载下拉刷新/components/index.vue: -------------------------------------------------------------------------------- 1 | 23 | 26 | -------------------------------------------------------------------------------- /Vue2.x 导出Excel格式/src/views/excel/Export2Excel.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | require('script-loader!file-saver'); 3 | require('script-loader!views/excel/Blob'); 4 | require('script-loader!xlsx/dist/xlsx.core.min'); 5 | function generateArray(table) { 6 | var out = []; 7 | var rows = table.querySelectorAll('tr'); 8 | var ranges = []; 9 | for (var R = 0; R < rows.length; ++R) { 10 | var outRow = []; 11 | var row = rows[R]; 12 | var columns = row.querySelectorAll('td'); 13 | for (var C = 0; C < columns.length; ++C) { 14 | var cell = columns[C]; 15 | var colspan = cell.getAttribute('colspan'); 16 | var rowspan = cell.getAttribute('rowspan'); 17 | var cellValue = cell.innerText; 18 | if (cellValue !== "" && cellValue == +cellValue) cellValue = +cellValue; 19 | 20 | //Skip ranges 21 | ranges.forEach(function (range) { 22 | if (R >= range.s.r && R <= range.e.r && outRow.length >= range.s.c && outRow.length <= range.e.c) { 23 | for (var i = 0; i <= range.e.c - range.s.c; ++i) outRow.push(null); 24 | } 25 | }); 26 | 27 | //Handle Row Span 28 | if (rowspan || colspan) { 29 | rowspan = rowspan || 1; 30 | colspan = colspan || 1; 31 | ranges.push({s: {r: R, c: outRow.length}, e: {r: R + rowspan - 1, c: outRow.length + colspan - 1}}); 32 | } 33 | ; 34 | 35 | //Handle Value 36 | outRow.push(cellValue !== "" ? cellValue : null); 37 | 38 | //Handle Colspan 39 | if (colspan) for (var k = 0; k < colspan - 1; ++k) outRow.push(null); 40 | } 41 | out.push(outRow); 42 | } 43 | return [out, ranges]; 44 | }; 45 | 46 | function datenum(v, date1904) { 47 | if (date1904) v += 1462; 48 | var epoch = Date.parse(v); 49 | return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000); 50 | } 51 | 52 | function sheet_from_array_of_arrays(data, opts) { 53 | var ws = {}; 54 | var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}}; 55 | for (var R = 0; R != data.length; ++R) { 56 | for (var C = 0; C != data[R].length; ++C) { 57 | if (range.s.r > R) range.s.r = R; 58 | if (range.s.c > C) range.s.c = C; 59 | if (range.e.r < R) range.e.r = R; 60 | if (range.e.c < C) range.e.c = C; 61 | var cell = {v: data[R][C]}; 62 | if (cell.v == null) continue; 63 | var cell_ref = XLSX.utils.encode_cell({c: C, r: R}); 64 | 65 | if (typeof cell.v === 'number') cell.t = 'n'; 66 | else if (typeof cell.v === 'boolean') cell.t = 'b'; 67 | else if (cell.v instanceof Date) { 68 | cell.t = 'n'; 69 | cell.z = XLSX.SSF._table[14]; 70 | cell.v = datenum(cell.v); 71 | } 72 | else cell.t = 's'; 73 | 74 | ws[cell_ref] = cell; 75 | } 76 | } 77 | if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); 78 | return ws; 79 | } 80 | 81 | function Workbook() { 82 | if (!(this instanceof Workbook)) return new Workbook(); 83 | this.SheetNames = []; 84 | this.Sheets = {}; 85 | } 86 | 87 | function s2ab(s) { 88 | var buf = new ArrayBuffer(s.length); 89 | var view = new Uint8Array(buf); 90 | for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; 91 | return buf; 92 | } 93 | 94 | export function export_table_to_excel(id) { 95 | var theTable = document.getElementById(id); 96 | console.log('a') 97 | var oo = generateArray(theTable); 98 | var ranges = oo[1]; 99 | 100 | /* original data */ 101 | var data = oo[0]; 102 | var ws_name = "SheetJS"; 103 | console.log(data); 104 | 105 | var wb = new Workbook(), ws = sheet_from_array_of_arrays(data); 106 | 107 | /* add ranges to worksheet */ 108 | // ws['!cols'] = ['apple', 'banan']; 109 | ws['!merges'] = ranges; 110 | 111 | /* add worksheet to workbook */ 112 | wb.SheetNames.push(ws_name); 113 | wb.Sheets[ws_name] = ws; 114 | 115 | var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'}); 116 | 117 | saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), "test.xlsx") 118 | } 119 | 120 | function formatJson(jsonData) { 121 | console.log(jsonData) 122 | } 123 | export function export_json_to_excel(th, jsonData, defaultTitle) { 124 | 125 | /* original data */ 126 | 127 | var data = jsonData; 128 | data.unshift(th); 129 | var ws_name = "SheetJS"; 130 | 131 | var wb = new Workbook(), ws = sheet_from_array_of_arrays(data); 132 | 133 | 134 | /* add worksheet to workbook */ 135 | wb.SheetNames.push(ws_name); 136 | wb.Sheets[ws_name] = ws; 137 | 138 | var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'}); 139 | var title = defaultTitle || '列表' 140 | saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx") 141 | } 142 | -------------------------------------------------------------------------------- /Vue2.x 导出Excel格式/src/views/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | -------------------------------------------------------------------------------- /Vue2.x 导出Excel格式/src/views/excel/Blob.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* Blob.js 3 | * A Blob implementation. 4 | * 2014-05-27 5 | * 6 | * By Eli Grey, http://eligrey.com 7 | * By Devin Samarin, https://github.com/eboyjr 8 | * License: X11/MIT 9 | * See LICENSE.md 10 | */ 11 | 12 | /*global self, unescape */ 13 | /*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true, 14 | plusplus: true */ 15 | 16 | /*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */ 17 | 18 | (function (view) { 19 | "use strict"; 20 | 21 | view.URL = view.URL || view.webkitURL; 22 | 23 | if (view.Blob && view.URL) { 24 | try { 25 | new Blob; 26 | return; 27 | } catch (e) {} 28 | } 29 | 30 | // Internally we use a BlobBuilder implementation to base Blob off of 31 | // in order to support older browsers that only have BlobBuilder 32 | var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function(view) { 33 | var 34 | get_class = function(object) { 35 | return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1]; 36 | } 37 | , FakeBlobBuilder = function BlobBuilder() { 38 | this.data = []; 39 | } 40 | , FakeBlob = function Blob(data, type, encoding) { 41 | this.data = data; 42 | this.size = data.length; 43 | this.type = type; 44 | this.encoding = encoding; 45 | } 46 | , FBB_proto = FakeBlobBuilder.prototype 47 | , FB_proto = FakeBlob.prototype 48 | , FileReaderSync = view.FileReaderSync 49 | , FileException = function(type) { 50 | this.code = this[this.name = type]; 51 | } 52 | , file_ex_codes = ( 53 | "NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR " 54 | + "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR" 55 | ).split(" ") 56 | , file_ex_code = file_ex_codes.length 57 | , real_URL = view.URL || view.webkitURL || view 58 | , real_create_object_URL = real_URL.createObjectURL 59 | , real_revoke_object_URL = real_URL.revokeObjectURL 60 | , URL = real_URL 61 | , btoa = view.btoa 62 | , atob = view.atob 63 | 64 | , ArrayBuffer = view.ArrayBuffer 65 | , Uint8Array = view.Uint8Array 66 | ; 67 | FakeBlob.fake = FB_proto.fake = true; 68 | while (file_ex_code--) { 69 | FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1; 70 | } 71 | if (!real_URL.createObjectURL) { 72 | URL = view.URL = {}; 73 | } 74 | URL.createObjectURL = function(blob) { 75 | var 76 | type = blob.type 77 | , data_URI_header 78 | ; 79 | if (type === null) { 80 | type = "application/octet-stream"; 81 | } 82 | if (blob instanceof FakeBlob) { 83 | data_URI_header = "data:" + type; 84 | if (blob.encoding === "base64") { 85 | return data_URI_header + ";base64," + blob.data; 86 | } else if (blob.encoding === "URI") { 87 | return data_URI_header + "," + decodeURIComponent(blob.data); 88 | } if (btoa) { 89 | return data_URI_header + ";base64," + btoa(blob.data); 90 | } else { 91 | return data_URI_header + "," + encodeURIComponent(blob.data); 92 | } 93 | } else if (real_create_object_URL) { 94 | return real_create_object_URL.call(real_URL, blob); 95 | } 96 | }; 97 | URL.revokeObjectURL = function(object_URL) { 98 | if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) { 99 | real_revoke_object_URL.call(real_URL, object_URL); 100 | } 101 | }; 102 | FBB_proto.append = function(data/*, endings*/) { 103 | var bb = this.data; 104 | // decode data to a binary string 105 | if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) { 106 | var 107 | str = "" 108 | , buf = new Uint8Array(data) 109 | , i = 0 110 | , buf_len = buf.length 111 | ; 112 | for (; i < buf_len; i++) { 113 | str += String.fromCharCode(buf[i]); 114 | } 115 | bb.push(str); 116 | } else if (get_class(data) === "Blob" || get_class(data) === "File") { 117 | if (FileReaderSync) { 118 | var fr = new FileReaderSync; 119 | bb.push(fr.readAsBinaryString(data)); 120 | } else { 121 | // async FileReader won't work as BlobBuilder is sync 122 | throw new FileException("NOT_READABLE_ERR"); 123 | } 124 | } else if (data instanceof FakeBlob) { 125 | if (data.encoding === "base64" && atob) { 126 | bb.push(atob(data.data)); 127 | } else if (data.encoding === "URI") { 128 | bb.push(decodeURIComponent(data.data)); 129 | } else if (data.encoding === "raw") { 130 | bb.push(data.data); 131 | } 132 | } else { 133 | if (typeof data !== "string") { 134 | data += ""; // convert unsupported types to strings 135 | } 136 | // decode UTF-16 to binary string 137 | bb.push(unescape(encodeURIComponent(data))); 138 | } 139 | }; 140 | FBB_proto.getBlob = function(type) { 141 | if (!arguments.length) { 142 | type = null; 143 | } 144 | return new FakeBlob(this.data.join(""), type, "raw"); 145 | }; 146 | FBB_proto.toString = function() { 147 | return "[object BlobBuilder]"; 148 | }; 149 | FB_proto.slice = function(start, end, type) { 150 | var args = arguments.length; 151 | if (args < 3) { 152 | type = null; 153 | } 154 | return new FakeBlob( 155 | this.data.slice(start, args > 1 ? end : this.data.length) 156 | , type 157 | , this.encoding 158 | ); 159 | }; 160 | FB_proto.toString = function() { 161 | return "[object Blob]"; 162 | }; 163 | FB_proto.close = function() { 164 | this.size = this.data.length = 0; 165 | }; 166 | return FakeBlobBuilder; 167 | }(view)); 168 | 169 | view.Blob = function Blob(blobParts, options) { 170 | var type = options ? (options.type || "") : ""; 171 | var builder = new BlobBuilder(); 172 | if (blobParts) { 173 | for (var i = 0, len = blobParts.length; i < len; i++) { 174 | builder.append(blobParts[i]); 175 | } 176 | } 177 | return builder.getBlob(type); 178 | }; 179 | }(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this)); 180 | --------------------------------------------------------------------------------