4.x 就绪

This commit is contained in:
啊平 2021-11-28 21:39:42 +08:00
parent d503108cb6
commit 2dd8a1954b
3 changed files with 23 additions and 184 deletions

View File

@ -4,43 +4,43 @@
"description": "",
"private": true,
"dependencies": {
"@midwayjs/decorator": "^2.12.3",
"@midwayjs/orm": "^2.12.5",
"@midwayjs/web": "^2.12.6",
"egg": "^2.30.0",
"egg-scripts": "^2.14.0",
"@midwayjs/bootstrap": "^2.13.4",
"@midwayjs/core": "^2.13.4",
"@midwayjs/decorator": "^2.13.2",
"@midwayjs/orm": "^2.13.4",
"@midwayjs/web": "^2.13.4",
"egg": "^2.32.0",
"egg-scripts": "^2.15.2",
"egg-view-nunjucks": "^2.3.0",
"ipip-ipdb": "^0.6.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"md5": "^2.3.0",
"midwayjs-cool-alipay": "^1.0.8",
"midwayjs-cool-core": "/Users/mac/Documents/src/cool/admin/midway-core/core/dist/",
"midwayjs-cool-core": "D:\\src\\cool\\admin\\midway-core\\core\\dist",
"midwayjs-cool-oss": "^1.0.12",
"midwayjs-cool-queue": "^1.0.8",
"midwayjs-cool-redis": "^1.1.6",
"midwayjs-cool-socket": "^1.0.8",
"midwayjs-cool-wxpay": "^1.0.12",
"mini-svg-data-uri": "^1.4.3",
"mysql2": "^2.3.0",
"mysql2": "^2.3.3",
"svg-captcha": "^1.4.0",
"typeorm": "^0.2.37"
"typeorm": "^0.2.41"
},
"devDependencies": {
"@midwayjs/cli": "^1.2.80",
"@midwayjs/cli-plugin-faas": "^1.2.81",
"@midwayjs/egg-ts-helper": "^1.2.0",
"@midwayjs/fcli-plugin-fc": "^1.2.81",
"@midwayjs/luckyeye": "^1.0.2",
"@midwayjs/mock": "^2.12.5",
"@types/jest": "^27.0.1",
"@types/jsonwebtoken": "^8.5.5",
"@midwayjs/cli": "^1.2.91",
"@midwayjs/egg-ts-helper": "^1.2.1",
"@midwayjs/luckyeye": "^1.0.3",
"@midwayjs/mock": "^2.13.4",
"@types/jest": "^27.0.3",
"@types/jsonwebtoken": "^8.5.6",
"@types/node": "16",
"cross-env": "^7.0.3",
"jest": "^27.0.6",
"jest": "^27.3.1",
"mwts": "^1.2.2",
"ts-jest": "^27.0.5",
"typescript": "^4.3.5"
"ts-jest": "^27.0.7",
"typescript": "^4.5.2"
},
"engines": {
"node": ">=12.0.0"
@ -57,8 +57,7 @@
"lint:fix": "mwts fix",
"ci": "npm run cov",
"build": "midway-bin build -c",
"check": "luckyeye",
"deploy": "midway-bin deploy"
"check": "luckyeye"
},
"midway-bin-clean": [
".vscode/.tsbuildinfo",
@ -69,14 +68,6 @@
"midway_v2"
]
},
"midway-integration": {
"lifecycle": {
"before:package:cleanup": "npm run build"
}
},
"egg": {
"framework": "@midwayjs/web"
},
"repository": {
"type": "git",
"url": ""

View File

@ -10,7 +10,7 @@ export default (appInfo: EggAppInfo) => {
host: '127.0.0.1',
port: 3306,
username: 'root',
password: '123123',
password: '123456',
database: 'cool',
// 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失
synchronize: true,
@ -18,6 +18,8 @@ export default (appInfo: EggAppInfo) => {
logging: true,
// 字符集
charset: 'utf8mb4',
// 驱动
driver: require("mysql2")
};
config.logger = {

154
uni.md
View File

@ -1,154 +0,0 @@
![LOGO](https://cool-show.oss-cn-shanghai.aliyuncs.com/admin/logo.png)
![](https://img.shields.io/badge/license-MIT-green?style=flat-square) ![](https://img.shields.io/github/package-json/v/cool-team-official/cool-admin-midway?style=flat-square) ![](https://img.shields.io/github/last-commit/cool-team-official/cool-admin-midway?style=flat-square)
## 技术栈
* 后端:**`node.js``midway.js``egg.js``mysql``typescript`**
* 前端:**`vue.js``element-ui``jsx``vuex``vue-router`**
如果你是前端,后端的这些技术选型对你是特别友好的,前端开发者可以较快速地上手。
如果你是后端Typescript的语法又跟java、php等特别类似一切看起来也是那么得熟悉。
<!-- 在此次添加使用文档 -->
## 演示
[https://show.cool-admin.com](https://show.cool-admin.com)
* 账户admin
* 密码123456
![](https://cool-show.oss-cn-shanghai.aliyuncs.com/admin/home-mini.png)
#### 文档
[https://admin.cool-js.com](https://admin.cool-js.com)
#### 项目前端
[https://github.com/cool-team-official/cool-admin-vue](https://github.com/cool-team-official/cool-admin-vue)
## QQ群
2群539478405
## 微信群
![](https://cool-show.oss-cn-shanghai.aliyuncs.com/admin/wechat.jpeg?x-oss-process=image/resize,h_260,m_lfit)
## 微信公众号
![](https://cool-show.oss-cn-shanghai.aliyuncs.com/admin/mp.jpg?x-oss-process=image/resize,h_260,m_lfit)
## 运行
#### 修改数据库配置,配置文件位于`src/config/config.local.ts`
数据库为mysql(`>=5.7版本`),首次启动会自动初始化并导入数据
```js
config.orm = {
type: 'mysql',
host: '127.0.0.1',
port: 3306,
username: 'root',
password: '',
database: 'cool-admin',
synchronize: true,
logging: true,
}
```
#### 安装依赖并运行
```bash
$ npm i
$ npm run dev
$ open http://localhost:8001/
```
注: 如果你的网络不佳可以尝试使用[cnpm](https://developer.aliyun.com/mirror/NPM?from=tnpm),或者切换您的镜像源
## CURD(快速增删改查)
大部分的后台管理系统或者API服务都是对数据进行管理所以可以看到大量的CRUD场景(增删改查)cool-admin对此进行了大量地封装让这块的编码量变得极其地少。
#### 新建一个数据表
`src/modules/demo/entity/goods.ts`,项目启动数据库会自动创建该表,无需手动创建
```ts
import { EntityModel } from '@midwayjs/orm';
import { BaseEntity } from 'midwayjs-cool-core';
import { Column } from 'typeorm';
/**
* 商品
*/
@EntityModel('demo_app_goods')
export class DemoAppGoodsEntity extends BaseEntity {
@Column({ comment: '标题' })
title: string;
@Column({ comment: '图片' })
pic: string;
@Column({ comment: '价格', type: 'decimal', precision: 5, scale: 2 })
price: number;
}
```
#### 编写api接口
`src/modules/demo/controller/app/goods.ts`快速编写6个api接口
```ts
import { Provide } from '@midwayjs/decorator';
import { CoolController, BaseController } from 'midwayjs-cool-core';
import { DemoAppGoodsEntity } from '../../entity/goods';
/**
* 商品
*/
@Provide()
@CoolController({
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
entity: DemoAppGoodsEntity
})
export class DemoAppGoodsController extends BaseController {
/**
* 其他接口
*/
@Get('/other')
async other() {
return this.ok('hello, cool-admin!!!');
}
}
```
这样我们就完成了6个接口的编写对应的接口如下
- `POST /app/demo/goods/add` 新增
- `POST /app/demo/goods/delete` 删除
- `POST /app/demo/goods/update` 更新
- `GET /app/demo/goods/info` 单个信息
- `POST /app/demo/goods/list` 列表信息
- `POST /app/demo/goods/page` 分页查询(包含模糊查询、字段全匹配等)
### 部署
```bash
$ npm start
$ npm stop
```
### 内置指令
- 使用 `npm run lint` 来做代码风格检查。
- 使用 `npm test` 来执行单元测试。
[midway]: https://midwayjs.org