Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
liweisheng committed Mar 8, 2022
1 parent 92498e3 commit 8d946ca
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 55 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
98 changes: 87 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
"url": "[email protected]: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"
},
"dependencies": {
"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",
Expand Down
44 changes: 36 additions & 8 deletions server/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

// 需要处理转发接口返回的数据的逻辑
Expand All @@ -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'
Expand Down Expand Up @@ -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',
Expand All @@ -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}
});
});
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<div id="app">
<img src="./assets/logo.png" alt="">
<router-view></router-view>
</div>
</template>
Expand All @@ -11,7 +10,6 @@ export default {
name: 'app'
}
</script>

<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
Expand Down
12 changes: 12 additions & 0 deletions src/components/Hello.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div class="hello" @click.self="$emit('click')">
<p>hello</p>
<p>hello</p>
<p>hello</p>
</div>
</template>
<style scoped>
.hello {
color: #000;
}
</style>
Loading

0 comments on commit 8d946ca

Please sign in to comment.