From 8d946ca118c471611d8976cca3b3988940c2aaee Mon Sep 17 00:00:00 2001 From: liweisheng Date: Tue, 8 Mar 2022 10:01:42 +0800 Subject: [PATCH] up --- index.js | 2 +- package-lock.json | 98 ++++++++++++++++++++++++++++++---- package.json | 4 +- server/router.js | 44 +++++++++++++--- src/App.vue | 2 - src/components/Hello.vue | 12 +++++ src/page/Home.vue | 111 ++++++++++++++++++++++++++++----------- 7 files changed, 218 insertions(+), 55 deletions(-) create mode 100644 src/components/Hello.vue diff --git a/index.js b/index.js index 6255a81..ba4b027 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,7 @@ app.use(static(path.resolve(__dirname, './dist'))); const router = require('./server/router') // 引入router模块 app.use(router.routes()); -autoC(1, 2, 3, 4, 5, 6, 7, 8, 9) + // 监听端口 let port = 3000; app.listen(port, function(){ diff --git a/package-lock.json b/package-lock.json index aa12bed..ba2859c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2243,6 +2243,11 @@ "integrity": "sha1-ZfCvOC9Xi83HQr2cKB6cstd2gyg=", "dev": true }, + "bignumber.js": { + "version": "9.0.0", + "resolved": "https://npm.zuoshouyisheng.com/bignumber.js/-/bignumber.js-9.0.0.tgz", + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==" + }, "binary-extensions": { "version": "1.13.1", "resolved": "https://registry.npm.taobao.org/binary-extensions/download/binary-extensions-1.13.1.tgz", @@ -2896,6 +2901,14 @@ "object-visit": "^1.0.0" } }, + "collections": { + "version": "3.0.0", + "resolved": "https://npm.zuoshouyisheng.com/collections/-/collections-3.0.0.tgz", + "integrity": "sha1-J+OJTfGyTO38VaG7sMDaEvaLqzE=", + "requires": { + "weak-map": "~1.0.x" + } + }, "color": { "version": "3.1.2", "resolved": "https://registry.npm.taobao.org/color/download/color-3.1.2.tgz", @@ -3281,8 +3294,7 @@ "core-util-is": { "version": "1.0.2", "resolved": "http://registry.npm.taobao.org/core-util-is/download/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "cosmiconfig": { "version": "5.2.1", @@ -4600,6 +4612,15 @@ "safe-buffer": "^5.1.1" } }, + "excel-export": { + "version": "0.5.1", + "resolved": "https://npm.zuoshouyisheng.com/excel-export/-/excel-export-0.5.1.tgz", + "integrity": "sha1-bQh4f5iy7JMeSz3P8YzJCDu7i3c=", + "requires": { + "collections": "^3.0.0", + "node-zip": "1.x" + } + }, "execa": { "version": "1.0.0", "resolved": "https://registry.npm.taobao.org/execa/download/execa-1.0.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fexeca%2Fdownload%2Fexeca-1.0.0.tgz", @@ -6376,8 +6397,7 @@ "inherits": { "version": "2.0.4", "resolved": "https://registry.npm.taobao.org/inherits/download/inherits-2.0.4.tgz?cache=0&sync_timestamp=1560975547815&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Finherits%2Fdownload%2Finherits-2.0.4.tgz", - "integrity": "sha1-D6LGT5MpF8NDOg3tVTY6rjdBa3w=", - "dev": true + "integrity": "sha1-D6LGT5MpF8NDOg3tVTY6rjdBa3w=" }, "inquirer": { "version": "3.3.0", @@ -6762,8 +6782,7 @@ "isarray": { "version": "1.0.0", "resolved": "https://registry.npm.taobao.org/isarray/download/isarray-1.0.0.tgz?cache=0&sync_timestamp=1562592125418&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fisarray%2Fdownload%2Fisarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, "isexe": { "version": "2.0.0", @@ -6910,6 +6929,21 @@ "verror": "1.10.0" } }, + "jszip": { + "version": "2.5.0", + "resolved": "https://npm.zuoshouyisheng.com/jszip/-/jszip-2.5.0.tgz", + "integrity": "sha1-dET9hVHd8+XacZj+oMkbyDCMwnQ=", + "requires": { + "pako": "~0.2.5" + }, + "dependencies": { + "pako": { + "version": "0.2.9", + "resolved": "https://npm.zuoshouyisheng.com/pako/-/pako-0.2.9.tgz", + "integrity": "sha1-8/dSL073gjSNqBYbrZ7P1Rv4OnU=" + } + } + }, "keygrip": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/keygrip/-/keygrip-1.0.3.tgz", @@ -7709,6 +7743,33 @@ "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", "dev": true }, + "mysql": { + "version": "2.18.1", + "resolved": "https://npm.zuoshouyisheng.com/mysql/-/mysql-2.18.1.tgz", + "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==", + "requires": { + "bignumber.js": "9.0.0", + "readable-stream": "2.3.7", + "safe-buffer": "5.1.2", + "sqlstring": "2.3.1" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://npm.zuoshouyisheng.com/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + } + } + }, "mz": { "version": "2.7.0", "resolved": "https://registry.npm.taobao.org/mz/download/mz-2.7.0.tgz", @@ -7842,6 +7903,14 @@ "semver": "^5.3.0" } }, + "node-zip": { + "version": "1.1.1", + "resolved": "https://npm.zuoshouyisheng.com/node-zip/-/node-zip-1.1.1.tgz", + "integrity": "sha1-lNGtZ0o81GoViN1zb0qaeMdX62I=", + "requires": { + "jszip": "2.5.0" + } + }, "normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npm.taobao.org/normalize-package-data/download/normalize-package-data-2.5.0.tgz", @@ -9048,8 +9117,7 @@ "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npm.taobao.org/process-nextick-args/download/process-nextick-args-2.0.1.tgz", - "integrity": "sha1-eCDZsWEgzFXKmud5JoCufbptf+I=", - "dev": true + "integrity": "sha1-eCDZsWEgzFXKmud5JoCufbptf+I=" }, "progress": { "version": "2.0.3", @@ -10306,6 +10374,11 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, + "sqlstring": { + "version": "2.3.1", + "resolved": "https://npm.zuoshouyisheng.com/sqlstring/-/sqlstring-2.3.1.tgz", + "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=" + }, "sshpk": { "version": "1.16.1", "resolved": "https://registry.npm.taobao.org/sshpk/download/sshpk-1.16.1.tgz", @@ -10473,7 +10546,6 @@ "version": "1.1.1", "resolved": "http://registry.npm.taobao.org/string_decoder/download/string_decoder-1.1.1.tgz", "integrity": "sha1-nPFhG6YmhdcDCunkujQUnDrwP8g=", - "dev": true, "requires": { "safe-buffer": "~5.1.0" } @@ -11228,8 +11300,7 @@ "util-deprecate": { "version": "1.0.2", "resolved": "http://registry.npm.taobao.org/util-deprecate/download/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "util.promisify": { "version": "1.0.0", @@ -11460,6 +11531,11 @@ "defaults": "^1.0.3" } }, + "weak-map": { + "version": "1.0.8", + "resolved": "https://npm.zuoshouyisheng.com/weak-map/-/weak-map-1.0.8.tgz", + "integrity": "sha512-lNR9aAefbGPpHO7AEnY0hCFjz1eTkWCXYvkTRrTHs9qv8zJp+SkVYpzfLIFXQQiG3tVvbNFQgVg2bQS8YGgxyw==" + }, "webpack": { "version": "4.28.4", "resolved": "https://registry.npm.taobao.org/webpack/download/webpack-4.28.4.tgz?cache=0&sync_timestamp=1564749195182&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fwebpack%2Fdownload%2Fwebpack-4.28.4.tgz", diff --git a/package.json b/package.json index 9028316..7254f07 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "url": "git@git.zuoshouyisheng.com:liweisheng/tongmei.git" }, "scripts": { - "start": "vue-cli-service serve", "serve": "vue-cli-service serve", + "server": "nodemon index.js", "build": "vue-cli-service build", "lint": "vue-cli-service lint" }, @@ -16,12 +16,14 @@ "color7log": "^1.6.4", "core-js": "^2.6.5", "crypto": "^1.0.1", + "excel-export": "^0.5.1", "koa": "^2.7.0", "koa-bodyparser": "^4.2.1", "koa-router": "^7.4.0", "koa-static": "^5.0.0", "koa2": "^2.0.0-alpha.7", "koa2-connect-history-api-fallback": "^0.1.2", + "mysql": "^2.18.1", "request-promise": "^4.2.4", "urlsafe-base64": "^1.0.0", "vue": "^2.6.10", diff --git a/server/router.js b/server/router.js index e4725aa..ee3dcee 100644 --- a/server/router.js +++ b/server/router.js @@ -3,21 +3,49 @@ const router = new Router(); // 实例化路由 const {autoC} = require('color7log'); // 实例化路由 const rp = require('request-promise'); const request = require( 'request' ); - // 加密模块 const crypto = require("crypto"); const URLSafeBase64 = require('urlsafe-base64'); +// const nodeExcel = require("excel-export"); + router.get('/api/getList', async (ctx, next) => { - greenFmt(ctx.query, '-') + autoC(ctx.query, '-') ctx.response.body = 22222 }); router.get('/api/getRegist', async (ctx, next) => { - // greenFmt(ctx.request, '=') + // autoC(ctx.request, '=') ctx.response.body = {msg: 2121} }); +router.get('/api/exportExcel', async (ctx, next) => { + res = ctx.res + var conf ={}; + conf.name = "mysheet"; + conf.cols = [{ + caption:'姓名', + type:'string' + },{ + caption:'性别', + type:'string' + }, { + caption:'年龄', + type:'number' + } + ]; + conf.rows = [['小名','男',24],['小红','女','20'],['小军','未知','33']]; + var result = nodeExcel.execute(conf);//将所有数据写入nodeExcel中 + res.setHeader('Access-Control-Allow-Origin', '*');//设置响应 + res.setHeader('Content-Type', 'application/vnd.openxmlformats'); + // res.setHeader('Content-Type', 'application/vnd.ms-execl'); + res.setHeader("Content-Disposition", "attachment; filename=user.xlsx"); + + let data = new Buffer(result,'binary'); // 关键代码 + + ctx.response.body = data +}); + router.get('/api/test', async (ctx, next) => { // 需要处理转发接口返回的数据的逻辑 @@ -36,7 +64,7 @@ router.get('/api/test', async (ctx, next) => { ctx.response.body = data }) - // 需要处理转发接口返回的数据的逻辑 + // 接口直接返回数据的逻辑 const res = request({ url: 'http://192.168.0.122:3000/api/getRegist', method: 'GET' @@ -71,7 +99,7 @@ router.post('/api/getList', async (ctx, next) => { 'Content-Type':'text/xml;charset=utf-8' } }; - // greenFmt(ctx.request.body, '=') + // autoC(ctx.request.body, '=') // ctx.request.body.app_id = '5d42ad9eb60c4845d88c7086'; // var options = { // method: 'POST', @@ -84,11 +112,11 @@ router.post('/api/getList', async (ctx, next) => { var xml2js = require('xml2js'); var parser = new xml2js.Parser({explicitArray: false, trim: true}); parser.parseString(data, (err, res) => { - greenFmt(res, '-') + autoC(res, '-') ctx.response.body = res['S:Envelope']['S:Body']['ns2:queryDepartInfoResponse']['return'] }); }).catch((err) => { - greenFmt(err, '+') + autoC(err, '+') ctx.response.body = {status: 1, msg: err} }); }); @@ -98,7 +126,7 @@ router.post('/api/getEnc', (ctx, next) => { const data = ctx.request.body data.timestamp = parseInt(new Date()/1000) - greenFmt(data, '=') + autoC(data, '=') var datajson = JSON.stringify(data); var cryptkey = crypto.createHash('sha256').update(app_secret, 'utf8').digest().slice(0, 16); diff --git a/src/App.vue b/src/App.vue index 9de0cfc..170559f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,5 @@ @@ -11,7 +10,6 @@ export default { name: 'app' } - diff --git a/src/page/Home.vue b/src/page/Home.vue index a4c798a..6c42861 100644 --- a/src/page/Home.vue +++ b/src/page/Home.vue @@ -1,43 +1,17 @@ -