mirror of
https://github.com/wangyuan389/mall-cook.git
synced 2026-09-21 04:26:41 +08:00
feat: 新增mall-cook-service 子项目
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-12-20 14:20:57
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2022-02-14 09:44:58
|
||||
* @LastEditTime: 2022-03-02 16:01:41
|
||||
-->
|
||||
<!-- [English](./README.md) | 简体中文 -->
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<p align="center">
|
||||
<img style='margin:0 5px' src='https://badgen.net/github/stars/wangyuan389/mall-cook'>
|
||||
<img style='margin:0 5px' src='https://badgen.net/github/forks/wangyuan389/mall-cook'>
|
||||
<img style='margin:0 5px' src='https://img.shields.io/badge/version-1.1-686480.svg'>
|
||||
<img style='margin:0 5px' src='https://img.shields.io/badge/version-1.1.1-686480.svg'>
|
||||
<img style='margin:0 5px' src='https://img.shields.io/badge/code%20style-standard-7986d0.svg'>
|
||||
</p>
|
||||
|
||||
@@ -35,6 +35,10 @@ Mall-Cook 是一个基于 vue 开发的可视化商城搭建平台,包括多
|
||||
- 利用 uni-app 重构物料库与模板项目
|
||||
- 修改为 Monorepo 风格项目结构,支持多个子项目独立存在
|
||||
|
||||
## 1.1.1 增加 service 子项目
|
||||
|
||||
- 后端使用 node 开发,mall-cook-service 项目已公布
|
||||
|
||||
## 体验
|
||||
|
||||
<p data-tool="mdnice编辑器" style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black;">预览地址:<a href="http://110.42.184.128:8000/#/login" style="text-decoration: none; color: #1e6bb8; word-wrap: break-word; font-weight: bold; border-bottom: 1px solid #1e6bb8;">传送门</a></p>
|
||||
@@ -91,8 +95,7 @@ root 项目选择需运行的子项目
|
||||
```bash
|
||||
$ npm run dev # 开发
|
||||
```
|
||||
|
||||
<img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/30d2081c1dcd42b0ab2d0edc09ffb748~tplv-k3u1fbpfcp-watermark.image" alt style="display: block; width: 32%;">
|
||||
<img src="./static/MallCook-Start.png" alt style="display: block;">
|
||||
|
||||
## 结构
|
||||
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2022-02-11 10:08:57
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2022-02-11 10:58:16
|
||||
* @LastEditTime: 2022-03-02 16:02:26
|
||||
*/
|
||||
export default {
|
||||
baseApi: 'https://www.lanshan-h5.cn',
|
||||
// baseApi: 'http://192.168.10.70:3000',
|
||||
baseApi:'http://110.42.184.128:1443/node',
|
||||
viewUrl: 'http://110.42.184.128:9000/#/'
|
||||
// viewUrl: 'http://192.168.10.70:8081/#/'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* @Description:初始化
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2022-03-02 14:27:50
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2022-03-02 15:08:22
|
||||
*/
|
||||
const Koa = require('koa')
|
||||
const app = new Koa()
|
||||
const views = require('koa-views')
|
||||
const json = require('koa-json')
|
||||
const onerror = require('koa-onerror')
|
||||
const bodyparser = require('koa-bodyparser')
|
||||
const koaBody = require('koa-body')
|
||||
const logger = require('koa-logger')
|
||||
const cors = require('koa2-cors')
|
||||
const Router = require('koa-router')
|
||||
const router = new Router()
|
||||
const registerRouter = require('./routes')
|
||||
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
// 链接mongodb数据库
|
||||
require('./utils/mongodb')
|
||||
|
||||
// error handler
|
||||
onerror(app)
|
||||
|
||||
// middlewares
|
||||
app.use(
|
||||
cors({
|
||||
credentials: true,
|
||||
exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],
|
||||
allowMethods: ['GET', 'POST', 'DELETE'],
|
||||
allowHeaders: ['Content-Type', 'Authorization', 'Accept']
|
||||
})
|
||||
)
|
||||
|
||||
app.use(json())
|
||||
app.use(logger())
|
||||
app.use(
|
||||
koaBody({
|
||||
formLimit: '15mb',
|
||||
jsonLimit: '15mb',
|
||||
textLimit: '15mb'
|
||||
})
|
||||
)
|
||||
app.use(require('koa-static')(__dirname + '/public'))
|
||||
|
||||
app.use(
|
||||
views(__dirname + '/views', {
|
||||
extension: 'pug'
|
||||
})
|
||||
)
|
||||
|
||||
/**
|
||||
* 错误捕捉中间件
|
||||
*/
|
||||
app.use(async (ctx, next) => {
|
||||
try {
|
||||
ctx.error = (code, message) => {
|
||||
if (typeof code === 'string') {
|
||||
message = code
|
||||
code = 500
|
||||
}
|
||||
ctx.throw(code || 500, message || '服务器错误')
|
||||
}
|
||||
await next()
|
||||
} catch (e) {
|
||||
let status = e.status || 500
|
||||
let message = e.message || '服务器错误'
|
||||
ctx.response.body = { status, message }
|
||||
}
|
||||
})
|
||||
|
||||
// logger
|
||||
app.use(async (ctx, next) => {
|
||||
const start = new Date()
|
||||
await next()
|
||||
const ms = new Date() - start
|
||||
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`)
|
||||
})
|
||||
|
||||
// routes
|
||||
app.use(registerRouter())
|
||||
app.use(router.routes()) // 中间件中使用router
|
||||
|
||||
// error-handling
|
||||
app.on('error', (err, ctx) => {
|
||||
console.error('server error', err, ctx)
|
||||
})
|
||||
|
||||
module.exports = app
|
||||
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var app = require('../app');
|
||||
var debug = require('debug')('demo:server');
|
||||
var http = require('http');
|
||||
|
||||
/**
|
||||
* Get port from environment and store in Express.
|
||||
*/
|
||||
|
||||
var port = normalizePort(process.env.PORT || '3000');
|
||||
// app.set('port', port);
|
||||
|
||||
/**
|
||||
* Create HTTP server.
|
||||
*/
|
||||
|
||||
var server = http.createServer(app.callback());
|
||||
|
||||
/**
|
||||
* Listen on provided port, on all network interfaces.
|
||||
*/
|
||||
|
||||
server.listen(port);
|
||||
server.on('error', onError);
|
||||
server.on('listening', onListening);
|
||||
|
||||
/**
|
||||
* Normalize a port into a number, string, or false.
|
||||
*/
|
||||
|
||||
function normalizePort(val) {
|
||||
var port = parseInt(val, 10);
|
||||
|
||||
if (isNaN(port)) {
|
||||
// named pipe
|
||||
return val;
|
||||
}
|
||||
|
||||
if (port >= 0) {
|
||||
// port number
|
||||
return port;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "error" event.
|
||||
*/
|
||||
|
||||
function onError(error) {
|
||||
if (error.syscall !== 'listen') {
|
||||
throw error;
|
||||
}
|
||||
|
||||
var bind = typeof port === 'string'
|
||||
? 'Pipe ' + port
|
||||
: 'Port ' + port;
|
||||
|
||||
// handle specific listen errors with friendly messages
|
||||
switch (error.code) {
|
||||
case 'EACCES':
|
||||
console.error(bind + ' requires elevated privileges');
|
||||
process.exit(1);
|
||||
break;
|
||||
case 'EADDRINUSE':
|
||||
console.error(bind + ' is already in use');
|
||||
process.exit(1);
|
||||
break;
|
||||
default:
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "listening" event.
|
||||
*/
|
||||
|
||||
function onListening() {
|
||||
var addr = server.address();
|
||||
var bind = typeof addr === 'string'
|
||||
? 'pipe ' + addr
|
||||
: 'port ' + addr.port;
|
||||
debug('Listening on ' + bind);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* @Description: 配置信息
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2022-02-10 19:20:33
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2022-03-02 15:32:46
|
||||
*/
|
||||
config = {
|
||||
appid: 'xxx', // 小程序appId
|
||||
secret: 'xxx', // 小程序secret
|
||||
serviceApi: 'xxx', // 服务器地址
|
||||
mongodbUrl: 'xxx' // mongodb数据库地址 格式:mongodb://username:password@host:port/name
|
||||
}
|
||||
|
||||
module.exports = config
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* @Description: What's this for
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-08-17 15:33:27
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2021-09-16 20:06:33
|
||||
*/
|
||||
const mongoose = require('mongoose')
|
||||
const goodsModel = mongoose.model('goods')
|
||||
const channel = require('../utils/channel')
|
||||
|
||||
const helper = {
|
||||
// 根据商城id查询所属商品,筛选掉richText字段
|
||||
findAll: (params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
goodsModel.find({ projectId: { $eq: params.projectId }, name: { $regex: params.name } }, { richText: 0 }, (err, data) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
// 根据商城id和商品id集合查询对应商品,筛选掉richText字段
|
||||
findIds: (id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
goodsModel.find({ projectId: { $eq: id } }, { richText: 0 }, (err, data) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
// 根据id查询详情
|
||||
findById: (id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
goodsModel.findById(id, (err, data) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
channel.mappingId(data)
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
// 编辑
|
||||
edit: (data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
goodsModel.updateOne({ _id: data.id }, data, (err, d) => {
|
||||
if (err) {
|
||||
reject({ message: '编辑失败', status: 10001 })
|
||||
} else {
|
||||
resolve({ message: '编辑成功', status: 10000, id: data.id })
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = helper
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* @Description: What's this for
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-08-17 14:46:28
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2021-12-16 16:22:37
|
||||
*/
|
||||
const mongoose = require('mongoose')
|
||||
const projectModel = mongoose.model('project')
|
||||
const channel = require('../utils/channel')
|
||||
|
||||
const helper = {
|
||||
// 根据用户id查询所属商城
|
||||
findAll: id => {
|
||||
return new Promise((resolve, reject) => {
|
||||
projectModel.find({ userId: { $eq: id } }, (err, data) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
channel.mappingId(data)
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
// 根据id查询详情
|
||||
findById: id => {
|
||||
return new Promise((resolve, reject) => {
|
||||
projectModel.findById(id, (err, data) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
channel.mappingId(data)
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
// 编辑
|
||||
edit: data => {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(data);
|
||||
|
||||
projectModel.updateOne({ _id: data.id }, data, (err, d) => {
|
||||
if (err) {
|
||||
reject({ message: d, status: 10001 })
|
||||
} else {
|
||||
resolve({ message: '编辑成功', status: 10000, id: data.id })
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
// 删除
|
||||
delete: data => {
|
||||
return new Promise((resolve, reject) => {
|
||||
projectModel.remove({ _id: data.id }, data, (err, d) => {
|
||||
if (err) {
|
||||
reject({ message: '删除失败', status: 10001 })
|
||||
} else {
|
||||
resolve({ message: '删除成功', status: 10000, id: data.id })
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
findModel: industry => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let query = {
|
||||
type: { $eq: 'model' }
|
||||
}
|
||||
|
||||
if (industry) {
|
||||
query.industry = { $eq: industry }
|
||||
}
|
||||
|
||||
projectModel.find(query, (err, data) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
channel.mappingId(data)
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = helper
|
||||
@@ -0,0 +1,49 @@
|
||||
const mongoose = require('mongoose')
|
||||
const RemoteModel = mongoose.model('remote')
|
||||
const channel = require('../utils/channel')
|
||||
|
||||
const helper = {
|
||||
// 查询所有
|
||||
findAll: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
RemoteModel.find({}, (err, data) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
channel.mappingId(data)
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
// 根据id查询详情
|
||||
findById: (id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
RemoteModel.findById(id, (err, data) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
channel.mappingId(data)
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
// 编辑
|
||||
edit: (data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
RemoteModel.updateOne({ _id: data.id }, data, (err, data) => {
|
||||
if (err) {
|
||||
reject({ message: '编辑失败', status: 10001 })
|
||||
} else {
|
||||
resolve({ message: '编辑成功', status: 10000 })
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = helper
|
||||
@@ -0,0 +1,46 @@
|
||||
const mongoose = require('mongoose')
|
||||
const UserMedel = mongoose.model('user')
|
||||
const channel = require('../utils/channel')
|
||||
|
||||
const helper = {
|
||||
// 查询所有
|
||||
findAll: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
UserMedel.find({}, (err, data) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
channel.mappingId(data)
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
// 根据id查询详情
|
||||
findById: (id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
UserMedel.findById(id, (err, data) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
channel.mappingId(data)
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
// 编辑
|
||||
edit: (data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
UserMedel.updateOne({ _id: data.id }, data, (err, d) => {
|
||||
if (err) {
|
||||
reject({ message: '编辑失败', status: 10001 })
|
||||
} else {
|
||||
resolve({ message: '编辑成功', status: 10000, id: data.id })
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = helper
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* @Description: What's this for
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-08-17 14:42:04
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2021-08-18 10:23:04
|
||||
*/
|
||||
/* 定义 goods Schema */
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const prijectSchema = new mongoose.Schema({
|
||||
id: { type: String }, // id
|
||||
projectId: { type: String }, // 项目id
|
||||
name: { type: String }, // 商品名
|
||||
describe: { type: String }, // 商品描述
|
||||
cover: { type: String }, // 商品封面
|
||||
imgList: { type: Array }, // 商品图
|
||||
price: { type: Number }, // 价格
|
||||
originalPrice: { type: Number }, // 划线价
|
||||
inventory: { type: Number }, // 库存
|
||||
richText: { type: String }, // 商品详情
|
||||
});
|
||||
|
||||
// 创建Model
|
||||
const GoodsModel = mongoose.model("goods", prijectSchema, 'goods');
|
||||
module.exports = GoodsModel
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/* 定义 remote Schema */
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const PoolSchema = new mongoose.Schema({
|
||||
id: { type: String },
|
||||
list: { type: String },
|
||||
});
|
||||
|
||||
// 创建Model
|
||||
const PoolModel = mongoose.model("pool", PoolSchema,'pool');
|
||||
module.exports = PoolModel
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* @Description: What's this for
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-08-17 14:42:04
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2021-09-28 20:01:03
|
||||
*/
|
||||
/* 定义 page Schema */
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const prijectSchema = new mongoose.Schema({
|
||||
id: { type: String }, // 项目id
|
||||
userId: { type: String }, // 用户id
|
||||
name: { type: String }, // 项目名字
|
||||
type: { type: String }, // 项目类型
|
||||
industry: { type: String }, // 所属行业
|
||||
config: { type: Object }, // 项目配置
|
||||
logo: { type: String }, // 项目logo
|
||||
cover: { type: String }, // 项目封面
|
||||
pages: { type: Array }, // 页面集合
|
||||
});
|
||||
|
||||
// 创建Model
|
||||
const ProjectModel = mongoose.model("project", prijectSchema, 'project');
|
||||
module.exports = ProjectModel
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/* 定义 remote Schema */
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const RemoteSchema = new mongoose.Schema({
|
||||
id: { type: String },
|
||||
name: { type: String },
|
||||
method: { type: String },
|
||||
params: { type: Array },
|
||||
url: { type: String },
|
||||
code: { type: String }
|
||||
});
|
||||
|
||||
// 创建Model
|
||||
const RemoteModel = mongoose.model("remote", RemoteSchema, 'remote');
|
||||
module.exports = RemoteModel
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/* 定义 user Schema */
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const UserSchema = new mongoose.Schema({
|
||||
id: { type: String },
|
||||
account: { type: String },
|
||||
password: { type: String },
|
||||
userName: { type: String },
|
||||
portrait: { type: String },
|
||||
});
|
||||
|
||||
// 创建Model
|
||||
const UserMedel = mongoose.model("user", UserSchema, 'user');
|
||||
module.exports = UserMedel
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
|
||||
#user nobody;
|
||||
worker_processes 1;
|
||||
|
||||
#error_log logs/error.log;
|
||||
#error_log logs/error.log notice;
|
||||
#error_log logs/error.log info;
|
||||
|
||||
#pid logs/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
# '$status $body_bytes_sent "$http_referer" '
|
||||
# '"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
#access_log logs/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
#keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
#charset koi8-r;
|
||||
|
||||
#access_log logs/host.access.log main;
|
||||
|
||||
location / {
|
||||
root html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
#error_page 404 /404.html;
|
||||
|
||||
# redirect server error pages to the static page /50x.html
|
||||
#
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root html;
|
||||
}
|
||||
|
||||
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# proxy_pass http://127.0.0.1;
|
||||
#}
|
||||
|
||||
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# root html;
|
||||
# fastcgi_pass 127.0.0.1:9000;
|
||||
# fastcgi_index index.php;
|
||||
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
||||
# include fastcgi_params;
|
||||
#}
|
||||
|
||||
# deny access to .htaccess files, if Apache's document root
|
||||
# concurs with nginx's one
|
||||
#
|
||||
#location ~ /\.ht {
|
||||
# deny all;
|
||||
#}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 8081;
|
||||
server_name resources;
|
||||
|
||||
location / {
|
||||
root /baseImg;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 8090;
|
||||
server_name resources;
|
||||
|
||||
location / {
|
||||
root /opt/nginx-1.7.0/static;
|
||||
}
|
||||
}
|
||||
|
||||
# another virtual host using mix of IP-, name-, and port-based configuration
|
||||
#
|
||||
#server {
|
||||
# listen 8000;
|
||||
# listen somename:8080;
|
||||
# server_name somename alias another.alias;
|
||||
|
||||
# location / {
|
||||
# root html;
|
||||
# index index.html index.htm;
|
||||
# }
|
||||
#}
|
||||
|
||||
|
||||
# HTTPS server
|
||||
#
|
||||
#server {
|
||||
# listen 443 ssl;
|
||||
# server_name localhost;
|
||||
|
||||
# ssl_certificate cert.pem;
|
||||
# ssl_certificate_key cert.key;
|
||||
|
||||
# ssl_session_cache shared:SSL:1m;
|
||||
# ssl_session_timeout 5m;
|
||||
|
||||
# ssl_ciphers HIGH:!aNULL:!MD5;
|
||||
# ssl_prefer_server_ciphers on;
|
||||
|
||||
# location / {
|
||||
# root html;
|
||||
# index index.html index.htm;
|
||||
# }
|
||||
#}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "dooring-sevice",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "node bin/www",
|
||||
"dev": "./node_modules/.bin/nodemon bin/www",
|
||||
"prod": "pm2 start bin/www",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.21.0",
|
||||
"debug": "^4.1.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"koa": "^2.7.0",
|
||||
"koa-body": "^4.2.0",
|
||||
"koa-bodyparser": "^4.2.1",
|
||||
"koa-convert": "^1.2.0",
|
||||
"koa-json": "^2.0.2",
|
||||
"koa-logger": "^3.2.0",
|
||||
"koa-multer": "^1.0.2",
|
||||
"koa-onerror": "^4.1.0",
|
||||
"koa-router": "^7.4.0",
|
||||
"koa-static": "^5.0.0",
|
||||
"koa-views": "^6.2.0",
|
||||
"koa2-cors": "^2.0.6",
|
||||
"koa2-request": "^1.0.4",
|
||||
"mongodb": "^3.6.3",
|
||||
"mongoose": "^5.5.11",
|
||||
"pug": "^2.0.3",
|
||||
"puppeteer": "^5.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^1.19.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
body {
|
||||
padding: 50px;
|
||||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #00B7FF;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* @Description: What's this for
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-08-17 14:28:29
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2022-03-02 15:13:58
|
||||
*/
|
||||
/**
|
||||
* base64 转图片
|
||||
*/
|
||||
const Router = require('koa-router')
|
||||
const tools = require('../utils/tools')
|
||||
const fs = require('fs')
|
||||
const config = require('../config')
|
||||
const router = new Router()
|
||||
|
||||
router.post('/base64ToImg', async (ctx, next) => {
|
||||
let data = ctx.request.body.data
|
||||
|
||||
let name = tools.getRandomCode(6) + Date.now() + '.png'
|
||||
|
||||
// 图片地址 服务器地址+图片名称
|
||||
let imgPath = `${config.serviceApi}/img/${name}`
|
||||
let base64 = data.replace(/^data:image\/\w+;base64,/, '')
|
||||
var dataBuffer = new Buffer(base64, 'base64') //把base64码转成buffer对象,
|
||||
|
||||
fs.writeFile('/img/' + name, dataBuffer, function (err) {
|
||||
//用fs写入文件
|
||||
if (err) {
|
||||
console.log(err)
|
||||
} else {
|
||||
}
|
||||
})
|
||||
ctx.body = {
|
||||
status: 10000,
|
||||
data: imgPath,
|
||||
messsage: '图片加载成功!'
|
||||
}
|
||||
ctx.status = 200
|
||||
await next()
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* @Description: What's this for
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-08-17 15:33:55
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2021-09-16 20:04:16
|
||||
*/
|
||||
/**
|
||||
* 页面管理接口
|
||||
*/
|
||||
|
||||
const Router = require('koa-router')
|
||||
const goodsModel = require('../models/goods')
|
||||
const helper = require('../dbhelper/goodsDbhelper')
|
||||
const channel = require('../utils/channel')
|
||||
const tools = require('../utils/tools')
|
||||
|
||||
const router = new Router()
|
||||
|
||||
router.prefix('/goods')
|
||||
|
||||
// 新增商品
|
||||
router.post('/add', async (ctx, next) => {
|
||||
let data = ctx.request.body
|
||||
let goods = new goodsModel(data)
|
||||
|
||||
try {
|
||||
goods = await goods.save()
|
||||
ctx.body = { message: '新增成功', status: '10000', id: goods._id }
|
||||
} catch (e) {
|
||||
ctx.body = { message: '新增失败', status: '10001' }
|
||||
}
|
||||
|
||||
await next()
|
||||
})
|
||||
|
||||
// 复制商品
|
||||
router.post('/copy', async (ctx, next) => {
|
||||
let data = ctx.request.body
|
||||
|
||||
let name = data.name.split('-')[0]
|
||||
name += '-' + tools.getRandomCode(6)
|
||||
data.name = name
|
||||
|
||||
delete data.id
|
||||
delete data._id
|
||||
|
||||
let goods = new goodsModel(data)
|
||||
|
||||
try {
|
||||
goods = await goods.save()
|
||||
ctx.body = { message: '新增成功', status: '10000', id: goods._id }
|
||||
} catch (e) {
|
||||
ctx.body = { message: '新增失败', status: '10001' }
|
||||
}
|
||||
|
||||
await next()
|
||||
})
|
||||
|
||||
// 编辑商品
|
||||
router.post('/edit', async (ctx, next) => {
|
||||
let data = ctx.request.body
|
||||
let body = await helper.edit(data)
|
||||
ctx.body = body
|
||||
await next()
|
||||
})
|
||||
|
||||
// 根据id查询商品
|
||||
router.post('/getById', async (ctx, next) => {
|
||||
console.log(ctx.request.body);
|
||||
|
||||
let id = ctx.request.body.id
|
||||
|
||||
if (!id) {
|
||||
ctx.error('id not found!');
|
||||
}
|
||||
|
||||
let res = await helper.findById(id)
|
||||
ctx.body = { message: '查询成功', status: '10000', data: res }
|
||||
await next()
|
||||
})
|
||||
|
||||
// 根据id集合顺序查询商品列表
|
||||
router.post('/getByIds', async (ctx, next) => {
|
||||
let projectId = ctx.request.body.projectId
|
||||
let ids = ctx.request.body.ids
|
||||
|
||||
let data = await helper.findIds(projectId)
|
||||
|
||||
channel.mappingId(data)
|
||||
|
||||
let filterList = data.filter(item => ids.includes(item.id))
|
||||
let result = []
|
||||
ids.map(id => {
|
||||
let temp = filterList.find(item => item.id == id)
|
||||
if (temp) {
|
||||
result.push(temp)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
ctx.body = {
|
||||
list: result,
|
||||
messsage: '查询成功',
|
||||
status: '10000'
|
||||
}
|
||||
await next()
|
||||
})
|
||||
|
||||
// 根据商城查询对应商品列表
|
||||
router.post('/getByList', async (ctx, next) => {
|
||||
let projectId = ctx.request.body.projectId
|
||||
let name = ctx.request.body.name || ''
|
||||
|
||||
let data = await helper.findAll({ projectId, name })
|
||||
|
||||
channel.mappingId(data)
|
||||
|
||||
ctx.body = {
|
||||
list: data,
|
||||
messsage: '查询成功',
|
||||
status: '10000'
|
||||
}
|
||||
await next()
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,16 @@
|
||||
const compose = require('koa-compose')
|
||||
const glob = require('glob')
|
||||
const { resolve } = require('path')
|
||||
|
||||
registerRouter = () => {
|
||||
let routers = [];
|
||||
glob.sync(resolve(__dirname, './', '**/*.js'))
|
||||
.filter(value => (value.indexOf('index.js') === -1))
|
||||
.map(router => {
|
||||
routers.push(require(router).routes())
|
||||
routers.push(require(router).allowedMethods())
|
||||
})
|
||||
return compose(routers)
|
||||
}
|
||||
|
||||
module.exports = registerRouter
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* @Description: What's this for
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-08-17 14:46:58
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2022-03-02 15:12:28
|
||||
*/
|
||||
/**
|
||||
* 页面管理接口
|
||||
*/
|
||||
|
||||
const Router = require('koa-router')
|
||||
const axios = require('axios')
|
||||
const fs = require('fs')
|
||||
const projectModel = require('../models/project')
|
||||
const helper = require('../dbhelper/projectDbhelper')
|
||||
const channel = require('../utils/channel')
|
||||
const tools = require('../utils/tools')
|
||||
const config = require('../config')
|
||||
|
||||
const router = new Router()
|
||||
|
||||
router.prefix('/project')
|
||||
|
||||
// 新增商城
|
||||
router.post('/add', async (ctx, next) => {
|
||||
let user = channel.getTokenInfo(ctx)
|
||||
if (user) {
|
||||
let data = ctx.request.body
|
||||
data.view = true
|
||||
data.userId = user.id
|
||||
let project = new projectModel(data)
|
||||
|
||||
try {
|
||||
project = await project.save()
|
||||
ctx.body = { message: '新增成功', status: '10000', id: project._id }
|
||||
} catch (e) {
|
||||
ctx.body = { message: '新增失败', status: '10001' }
|
||||
}
|
||||
} else {
|
||||
ctx.body = { message: 'token不能为空', status: '10002' }
|
||||
}
|
||||
|
||||
await next()
|
||||
})
|
||||
|
||||
// 编辑商城
|
||||
router.post('/edit', async (ctx, next) => {
|
||||
console.log('编辑页面')
|
||||
|
||||
let data = ctx.request.body
|
||||
let body = await helper.edit(data)
|
||||
ctx.body = body
|
||||
await next()
|
||||
})
|
||||
|
||||
// 删除商城
|
||||
router.post('/delete', async (ctx, next) => {
|
||||
let data = ctx.request.body
|
||||
let body = await helper.delete(data)
|
||||
ctx.body = body
|
||||
await next()
|
||||
})
|
||||
|
||||
// 根据id查询商城
|
||||
router.post('/getById', async (ctx, next) => {
|
||||
console.log(ctx.request.body)
|
||||
|
||||
let id = ctx.request.body.id
|
||||
|
||||
if (!id) {
|
||||
ctx.error('id not found!')
|
||||
}
|
||||
|
||||
let res = await helper.findById(id)
|
||||
ctx.body = { message: '查询成功', status: '10000', data: res }
|
||||
await next()
|
||||
})
|
||||
|
||||
// 查询用户所属商城列表
|
||||
router.post('/getByList', async (ctx, next) => {
|
||||
let name = ctx.query.name
|
||||
let userId = ctx.request.body.userId
|
||||
|
||||
let data = await helper.findAll(userId)
|
||||
|
||||
data.map(item => {
|
||||
item.id = item._id
|
||||
})
|
||||
|
||||
ctx.body = {
|
||||
list: data,
|
||||
messsage: '查询成功',
|
||||
status: '10000'
|
||||
}
|
||||
await next()
|
||||
})
|
||||
|
||||
// 查询商城模板列表
|
||||
router.post('/getModelList', async (ctx, next) => {
|
||||
let industry = ctx.request.body.industry
|
||||
|
||||
let data = await helper.findModel(industry)
|
||||
|
||||
data.map(item => {
|
||||
item.id = item._id
|
||||
})
|
||||
|
||||
ctx.body = {
|
||||
list: data,
|
||||
messsage: '查询成功',
|
||||
status: '10000'
|
||||
}
|
||||
await next()
|
||||
})
|
||||
|
||||
// 生成小程序二维码
|
||||
router.post('/getWXQr', async (ctx, next) => {
|
||||
let id = ctx.request.body.id
|
||||
|
||||
let url = `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${config.appid}&secret=${config.secret}`
|
||||
|
||||
// 获取微信token
|
||||
let res = await axios({
|
||||
url,
|
||||
method: 'GET'
|
||||
})
|
||||
|
||||
let token = res.data.access_token
|
||||
|
||||
let buffer = await getQr(token, id)
|
||||
|
||||
let fileName = `/img/${Date.now()}${tools.getRandomCode(6)}.jpg`
|
||||
|
||||
fs.writeFile(fileName, buffer, err => {
|
||||
if (!err) {
|
||||
console.log('图片生成成功!')
|
||||
}
|
||||
})
|
||||
|
||||
ctx.body = {
|
||||
data: `${config.serviceApi}${fileName}`,
|
||||
messsage: '生成成功',
|
||||
status: '10000'
|
||||
}
|
||||
await next()
|
||||
})
|
||||
|
||||
// 生成小程序二维码
|
||||
async function getQr (token, id) {
|
||||
console.log('comme')
|
||||
let { data } = await axios({
|
||||
url: `https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=${token}`,
|
||||
method: 'POST',
|
||||
responseType: 'arraybuffer',
|
||||
data: {
|
||||
page: 'pages/index/tabbar/home',
|
||||
scene: `id=${id}`
|
||||
}
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* @Description: What's this for
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-08-17 14:28:29
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2022-03-02 14:33:13
|
||||
*/
|
||||
/**
|
||||
* 调用远程接口(利用服务端调用解决跨域)
|
||||
*/
|
||||
const Router = require('koa-router')
|
||||
const koa2Req = require('koa2-request')
|
||||
const axios = require('axios')
|
||||
|
||||
const router = new Router()
|
||||
|
||||
router.prefix('/source')
|
||||
|
||||
// node调用第三方接口,解决web端调用第三方接口跨域问题
|
||||
router.post('/cross', async (ctx, next) => {
|
||||
let options = {
|
||||
url: ctx.request.body.url,
|
||||
method: ctx.request.body.method,
|
||||
params: ctx.request.body.params
|
||||
}
|
||||
|
||||
res = await httpRequest(options)
|
||||
|
||||
ctx.body = res.data
|
||||
ctx.status = 200
|
||||
await next()
|
||||
})
|
||||
|
||||
// http 调用远程请求
|
||||
const httpRequest = async options => {
|
||||
let result = {}
|
||||
|
||||
if (options.method == 'post') {
|
||||
result = await axios({
|
||||
url: options.url,
|
||||
method: options.method,
|
||||
data: options.params,
|
||||
responseType: 'arraybuffer'
|
||||
})
|
||||
}
|
||||
|
||||
if (options.method == 'get') {
|
||||
result = await axios.get(options.url, {
|
||||
params: options.params
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* @Description: What's this for
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-08-17 14:28:29
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2022-03-02 15:13:34
|
||||
*/
|
||||
const tools = require('../utils/tools')
|
||||
const multer = require('koa-multer');
|
||||
const Router = require('koa-router')
|
||||
const config = require('../config')
|
||||
|
||||
const router = new Router()
|
||||
|
||||
|
||||
//文件上传
|
||||
var storage = multer.diskStorage({
|
||||
//文件保存路径
|
||||
destination: function (req, file, cb) {
|
||||
cb(null, '/img/')
|
||||
},
|
||||
//修改文件名称
|
||||
filename: function (req, file, cb) {
|
||||
var fileFormat = (file.originalname).split(".");
|
||||
cb(null, Date.now() + "." + fileFormat[fileFormat.length - 1]);
|
||||
}
|
||||
})
|
||||
//加载配置
|
||||
var upload = multer({ storage: storage });
|
||||
|
||||
|
||||
//路由
|
||||
router.post('/upload', upload.single('file'), async (ctx, next) => {
|
||||
ctx.body = {
|
||||
data: `${config.serviceApi}/img/${ctx.req.file.filename}`,
|
||||
errorCode: "00000",
|
||||
message: "请求成功",
|
||||
}
|
||||
ctx.status = 200
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* @Description: What's this for
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-08-17 14:28:29
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2021-08-18 15:49:45
|
||||
*/
|
||||
/**
|
||||
* 页面管理接口
|
||||
*/
|
||||
|
||||
const Router = require('koa-router')
|
||||
const tools = require('../utils/tools')
|
||||
const channel = require('../utils/channel')
|
||||
const { addToken, provingToken } = require('../utils/token')
|
||||
const UserModel = require('../models/user')
|
||||
const helper = require('../dbhelper/userDbhelper')
|
||||
|
||||
const router = new Router()
|
||||
|
||||
// router.prefix('/user')
|
||||
|
||||
// 注册
|
||||
router.post('/register', async (ctx, next) => {
|
||||
let data = ctx.request.body
|
||||
let list = await helper.findAll()
|
||||
let page = new UserModel(data)
|
||||
|
||||
if (list.find(item => item.account == data.account)) {
|
||||
ctx.body = { message: '账户名已注册', status: '10003' }
|
||||
} else {
|
||||
try {
|
||||
page = await page.save()
|
||||
ctx.body = { message: '注册成功', status: '10000' }
|
||||
} catch (e) {
|
||||
ctx.body = { message: '注册失败', status: '10001' }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await next()
|
||||
})
|
||||
|
||||
// 登录
|
||||
router.post('/login', async (ctx, next) => {
|
||||
let data = ctx.request.body
|
||||
let list = await helper.findAll()
|
||||
|
||||
let user = list.find(item => item.account == data.account && item.password == data.password)
|
||||
if (user) {
|
||||
console.log(user);
|
||||
|
||||
let token = addToken({ id: user.id, account: user.account })
|
||||
let { _id, account, userName, portrait } = user
|
||||
let userInfo = { userId:_id, account, userName, portrait }
|
||||
ctx.body = { message: '登录成功', status: '10000', token, userInfo }
|
||||
} else {
|
||||
ctx.body = { message: '账户或密码不正确', status: '10001' }
|
||||
}
|
||||
|
||||
await next()
|
||||
})
|
||||
|
||||
// 测试
|
||||
router.post('/test', async (ctx, next) => {
|
||||
let token = ctx.request.header.authorization;
|
||||
|
||||
if (token) {
|
||||
// 获取到token
|
||||
console.log(token);
|
||||
|
||||
let res = provingToken(token);
|
||||
if (res && res.exp <= new Date() / 1000) {
|
||||
ctx.body = {
|
||||
message: 'token过期',
|
||||
code: 3
|
||||
};
|
||||
} else {
|
||||
ctx.body = {
|
||||
message: '解析成功',
|
||||
code: 1
|
||||
}
|
||||
}
|
||||
} else { // 没有取到token
|
||||
ctx.body = {
|
||||
msg: '没有token',
|
||||
code: 0
|
||||
}
|
||||
}
|
||||
|
||||
await next()
|
||||
})
|
||||
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,35 @@
|
||||
const { addToken, provingToken } = require('./token')
|
||||
|
||||
const resultChannel = function (ctx, result) {
|
||||
if (result) {
|
||||
ctx.body = {
|
||||
data: result
|
||||
}
|
||||
ctx.status = 200
|
||||
} else {
|
||||
ctx.throw(200, '未找到数据');
|
||||
}
|
||||
}
|
||||
|
||||
const mappingId = function (data) {
|
||||
// 数组
|
||||
if (data instanceof Array) {
|
||||
data.map(item => item.id = item._id)
|
||||
}
|
||||
|
||||
// 对象
|
||||
if (data instanceof Object) {
|
||||
data.id = data._id
|
||||
}
|
||||
}
|
||||
|
||||
const getTokenInfo = function (ctx) {
|
||||
let token = ctx.request.header.authorization;
|
||||
return token ? provingToken(token):null
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
resultChannel,
|
||||
mappingId,
|
||||
getTokenInfo
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* @Description: What's this for
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2021-08-17 14:28:29
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2022-03-02 15:16:14
|
||||
*/
|
||||
|
||||
//引入模块
|
||||
const mongoose = require('mongoose')
|
||||
const config = require('../config')
|
||||
|
||||
//连接数据库
|
||||
mongoose.connect(`${config.mongodbUrl}`, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true
|
||||
})
|
||||
//得到数据库连接句柄
|
||||
const db = mongoose.connection
|
||||
//通过数据库连接句柄,监听mongoose数据库成功的事件
|
||||
db.on('open', function (err) {
|
||||
if (err) {
|
||||
console.log('数据库连接失败')
|
||||
throw err
|
||||
}
|
||||
console.log('数据库连接成功')
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
db
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
const jwt = require('jsonwebtoken');
|
||||
const serect = 'token'; //密钥,不能丢
|
||||
|
||||
const addToken = (userinfo) => { //创建token并导出
|
||||
const token = jwt.sign({
|
||||
id: userinfo.id,
|
||||
account: userinfo.account,
|
||||
}, serect, { expiresIn: '1h' });
|
||||
return token;
|
||||
};
|
||||
|
||||
const provingToken = (token) => {
|
||||
|
||||
if (token) {
|
||||
|
||||
// 解析
|
||||
let decoded = jwt.decode(token, serect);
|
||||
|
||||
console.log('解析token');
|
||||
console.log(decoded);
|
||||
|
||||
return decoded;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
addToken,
|
||||
provingToken
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// 生成不重复的随机id
|
||||
function getRandomCode(num) {
|
||||
var data = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
|
||||
var nums = "";
|
||||
for (var i = 0; i < num; i++) {
|
||||
var r = parseInt(Math.random() * 61);
|
||||
nums += data[r];
|
||||
}
|
||||
return nums;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getRandomCode
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
extends layout
|
||||
|
||||
block content
|
||||
h1= message
|
||||
h2= error.status
|
||||
pre #{error.stack}
|
||||
@@ -0,0 +1,5 @@
|
||||
extends layout
|
||||
|
||||
block content
|
||||
h1= title
|
||||
p Welcome to #{title}
|
||||
@@ -0,0 +1,7 @@
|
||||
doctype html
|
||||
html
|
||||
head
|
||||
title= title
|
||||
link(rel='stylesheet', href='/stylesheets/style.css')
|
||||
body
|
||||
block content
|
||||
File diff suppressed because it is too large
Load Diff
+13
-3
@@ -3,7 +3,7 @@
|
||||
* @Autor: WangYuan
|
||||
* @Date: 2022-01-06 16:13:31
|
||||
* @LastEditors: WangYuan
|
||||
* @LastEditTime: 2022-01-08 11:17:37
|
||||
* @LastEditTime: 2022-03-02 15:28:18
|
||||
*/
|
||||
const execa = require('execa')
|
||||
const { resolve } = require('path')
|
||||
@@ -12,11 +12,12 @@ const inquirer = require('inquirer')
|
||||
const CWD = process.cwd()
|
||||
let PKG_PLATFORM = resolve(CWD, './packages/mall-cook-platform')
|
||||
let PKG_TEMPLATE = resolve(CWD, './packages/mall-cook-template')
|
||||
let PKG_SERVICE = resolve(CWD, './packages/mall-cook-service')
|
||||
|
||||
const run = (bin, args, opts = {}) =>
|
||||
execa(bin, args, { stdio: 'inherit', ...opts })
|
||||
|
||||
async function create() {
|
||||
async function create () {
|
||||
const { fruit } = await inquirer.prompt([
|
||||
{
|
||||
type: 'list',
|
||||
@@ -34,9 +35,15 @@ async function create() {
|
||||
value: 'h5'
|
||||
},
|
||||
{
|
||||
key: '1',
|
||||
key: '2',
|
||||
name: 'Mall-Cook 微信小程序',
|
||||
value: 'mp-weixin'
|
||||
},
|
||||
{
|
||||
key: '3',
|
||||
name:
|
||||
'Mall-Cook node 服务 (请在config.js中修改真实配置数据,否则无法启动)',
|
||||
value: 'service'
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -52,6 +59,9 @@ async function create() {
|
||||
case 'mp-weixin':
|
||||
run('yarn', ['dev:mp-weixin'], { cwd: PKG_TEMPLATE })
|
||||
break
|
||||
case 'service':
|
||||
run('yarn', ['start'], { cwd: PKG_SERVICE })
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.7 KiB |
Reference in New Issue
Block a user