2022-03-27 10:35:46 +08:00
|
|
|
|
<p align="center">
|
|
|
|
|
<a href="https://midwayjs.org/" target="blank"><img src="https://cool-show.oss-cn-shanghai.aliyuncs.com/admin/logo.png" width="200" alt="Midway Logo" /></a>
|
|
|
|
|
</p>
|
2022-03-14 14:46:21 +08:00
|
|
|
|
|
2022-03-27 10:35:46 +08:00
|
|
|
|
<p align="center">cool-admin(midway版)一个很酷的后台权限管理系统,开源免费,模块化、插件化、极速开发CRUD,方便快速构建迭代后台管理系统,支持serverless、docker、普通服务器等多种方式部署
|
2024-01-13 16:28:45 +08:00
|
|
|
|
到 <a href="https://cool-js.com" target="_blank">官网</a> 进一步了解。
|
2022-03-27 10:35:46 +08:00
|
|
|
|
<p align="center">
|
|
|
|
|
<a href="https://github.com/cool-team-official/cool-admin-midway/blob/master/LICENSE" target="_blank"><img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="GitHub license" />
|
|
|
|
|
<a href=""><img src="https://img.shields.io/github/package-json/v/cool-team-official/cool-admin-midway?style=flat-square" alt="GitHub tag"></a>
|
|
|
|
|
<img src="https://img.shields.io/github/last-commit/cool-team-official/cool-admin-midway?style=flat-square" alt="GitHub tag"></a>
|
|
|
|
|
</p>
|
2022-03-14 14:46:21 +08:00
|
|
|
|
|
2022-03-27 10:35:46 +08:00
|
|
|
|
## 技术栈
|
2022-03-14 14:46:21 +08:00
|
|
|
|
|
2024-01-13 16:28:45 +08:00
|
|
|
|
- 后端:**`node.js` `midway.js` `koa.js` `typescript`**
|
2023-05-22 23:03:44 +08:00
|
|
|
|
- 前端:**`vue.js` `element-plus` `jsx` `pinia` `vue-router`**
|
2024-01-13 16:28:45 +08:00
|
|
|
|
- 数据库:**`mysql` `postgresql` `sqlite`**
|
2022-03-14 14:46:21 +08:00
|
|
|
|
|
2022-03-27 10:35:46 +08:00
|
|
|
|
如果你是前端,后端的这些技术选型对你是特别友好的,前端开发者可以较快速地上手。
|
2022-10-09 16:55:49 +08:00
|
|
|
|
如果你是后端,Typescript 的语法又跟 java、php 等特别类似,一切看起来也是那么得熟悉。
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
2024-01-13 16:28:45 +08:00
|
|
|
|
如果你想使用java版本后端,请移步[cool-admin-java](https://cool-js.com/admin/java/introduce.html)
|
|
|
|
|
|
|
|
|
|
#### 官网
|
|
|
|
|
|
|
|
|
|
[https://cool-js.com](https://cool-js.com)
|
|
|
|
|
|
2022-03-27 10:35:46 +08:00
|
|
|
|
<!-- 在此次添加使用文档 -->
|
|
|
|
|
## 演示
|
2022-10-09 16:55:49 +08:00
|
|
|
|
|
2024-01-13 16:31:57 +08:00
|
|
|
|
[AI极速编码](https://cool-js.com/ai/introduce.html)
|
2024-01-13 16:28:45 +08:00
|
|
|
|
|
2022-03-27 10:35:46 +08:00
|
|
|
|
[https://show.cool-admin.com](https://show.cool-admin.com)
|
|
|
|
|
|
2022-10-09 16:55:49 +08:00
|
|
|
|
- 账户:admin
|
|
|
|
|
- 密码:123456
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
|
|
|
|
<img src="https://cool-show.oss-cn-shanghai.aliyuncs.com/admin/home-mini.png" alt="Admin Home"></a>
|
2022-10-09 16:55:49 +08:00
|
|
|
|
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
|
|
|
|
#### 项目前端
|
|
|
|
|
|
|
|
|
|
[https://github.com/cool-team-official/cool-admin-vue](https://github.com/cool-team-official/cool-admin-vue)
|
|
|
|
|
|
|
|
|
|
## 微信群
|
|
|
|
|
|
|
|
|
|
<img width="260" src="https://cool-show.oss-cn-shanghai.aliyuncs.com/admin/wechat.jpeg?v=1" alt="Admin Wechat"></a>
|
|
|
|
|
|
|
|
|
|
## 运行
|
|
|
|
|
|
|
|
|
|
#### 修改数据库配置,配置文件位于`src/config/config.local.ts`
|
|
|
|
|
|
2024-01-13 16:28:45 +08:00
|
|
|
|
以Mysql为例,其他数据库请参考[数据库配置文档](https://cool-js.com/admin/node/quick.html#%E6%95%B0%E6%8D%AE%E5%BA%93%E9%85%8D%E7%BD%AE)
|
|
|
|
|
|
|
|
|
|
Mysql(`>=5.7版本`),建议 8.0,node 版本(`>=16.x`),建议 18.x,首次启动会自动初始化并导入数据
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
|
|
|
|
```ts
|
2024-01-13 16:28:45 +08:00
|
|
|
|
// mysql,驱动已经内置,无需安装
|
2023-03-08 17:10:57 +08:00
|
|
|
|
typeorm: {
|
|
|
|
|
dataSource: {
|
|
|
|
|
default: {
|
|
|
|
|
type: 'mysql',
|
|
|
|
|
host: '127.0.0.1',
|
|
|
|
|
port: 3306,
|
|
|
|
|
username: 'root',
|
|
|
|
|
password: '123456',
|
|
|
|
|
database: 'cool',
|
|
|
|
|
// 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失
|
|
|
|
|
synchronize: true,
|
|
|
|
|
// 打印日志
|
|
|
|
|
logging: false,
|
|
|
|
|
// 字符集
|
|
|
|
|
charset: 'utf8mb4',
|
|
|
|
|
// 是否开启缓存
|
|
|
|
|
cache: true,
|
|
|
|
|
// 实体路径
|
|
|
|
|
entities: ['**/modules/*/entity'],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-03-27 10:35:46 +08:00
|
|
|
|
},
|
|
|
|
|
```
|
|
|
|
|
#### 安装依赖并运行
|
2022-03-14 14:46:21 +08:00
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
$ npm i
|
|
|
|
|
$ npm run dev
|
2022-03-27 10:35:46 +08:00
|
|
|
|
$ open http://localhost:8001/
|
2022-03-14 14:46:21 +08:00
|
|
|
|
```
|
|
|
|
|
|
2024-01-13 16:28:45 +08:00
|
|
|
|
注: `npm i`如果安装失败可以尝试使用[cnpm](https://developer.aliyun.com/mirror/NPM?from=tnpm),或者切换您的镜像源,推荐使用[pnpm](https://pnpm.io/)
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
|
|
|
|
## CURD(快速增删改查)
|
|
|
|
|
|
2022-10-09 16:55:49 +08:00
|
|
|
|
大部分的后台管理系统,或者 API 服务都是对数据进行管理,所以可以看到大量的 CRUD 场景(增删改查),cool-admin 对此进行了大量地封装,让这块的编码量变得极其地少。
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
|
|
|
|
#### 新建一个数据表
|
|
|
|
|
|
|
|
|
|
`src/modules/demo/entity/goods.ts`,项目启动数据库会自动创建该表,无需手动创建
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
import { BaseEntity } from '@cool-midway/core';
|
2023-03-08 17:10:57 +08:00
|
|
|
|
import { Column, Entity, Index } from 'typeorm';
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 商品
|
|
|
|
|
*/
|
2023-03-08 17:10:57 +08:00
|
|
|
|
@Entity('demo_app_goods')
|
2022-03-27 10:35:46 +08:00
|
|
|
|
export class DemoAppGoodsEntity extends BaseEntity {
|
2022-10-09 16:55:49 +08:00
|
|
|
|
@Column({ comment: '标题' })
|
|
|
|
|
title: string;
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
2022-10-09 16:55:49 +08:00
|
|
|
|
@Column({ comment: '图片' })
|
|
|
|
|
pic: string;
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
2022-10-09 16:55:49 +08:00
|
|
|
|
@Column({ comment: '价格', type: 'decimal', precision: 5, scale: 2 })
|
|
|
|
|
price: number;
|
2022-03-27 10:35:46 +08:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-10-09 16:55:49 +08:00
|
|
|
|
#### 编写 api 接口
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
2022-10-09 16:55:49 +08:00
|
|
|
|
`src/modules/demo/controller/app/goods.ts`,快速编写 6 个 api 接口
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
import { CoolController, BaseController } from '@cool-midway/core';
|
|
|
|
|
import { DemoAppGoodsEntity } from '../../entity/goods';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 商品
|
|
|
|
|
*/
|
|
|
|
|
@CoolController({
|
|
|
|
|
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
|
2022-10-09 16:55:49 +08:00
|
|
|
|
entity: DemoAppGoodsEntity,
|
2022-03-27 10:35:46 +08:00
|
|
|
|
})
|
|
|
|
|
export class DemoAppGoodsController extends BaseController {
|
|
|
|
|
/**
|
|
|
|
|
* 其他接口
|
|
|
|
|
*/
|
|
|
|
|
@Get('/other')
|
|
|
|
|
async other() {
|
|
|
|
|
return this.ok('hello, cool-admin!!!');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-10-09 16:55:49 +08:00
|
|
|
|
这样我们就完成了 6 个接口的编写,对应的接口如下:
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
|
|
|
|
- `POST /app/demo/goods/add` 新增
|
|
|
|
|
- `POST /app/demo/goods/delete` 删除
|
|
|
|
|
- `POST /app/demo/goods/update` 更新
|
2022-10-09 16:55:49 +08:00
|
|
|
|
- `GET /app/demo/goods/info` 单个信息
|
2022-03-27 10:35:46 +08:00
|
|
|
|
- `POST /app/demo/goods/list` 列表信息
|
|
|
|
|
- `POST /app/demo/goods/page` 分页查询(包含模糊查询、字段全匹配等)
|
|
|
|
|
|
|
|
|
|
### 部署
|
2022-03-14 14:46:21 +08:00
|
|
|
|
|
2023-10-09 11:21:50 +08:00
|
|
|
|
[部署教程](https://cool-js.com/admin/node/other/deploy.html)
|
2022-03-14 14:46:21 +08:00
|
|
|
|
|
2022-03-27 10:35:46 +08:00
|
|
|
|
### 内置指令
|
2022-03-14 14:46:21 +08:00
|
|
|
|
|
2022-03-27 10:35:46 +08:00
|
|
|
|
- 使用 `npm run lint` 来做代码风格检查。
|
2022-03-14 14:46:21 +08:00
|
|
|
|
|
|
|
|
|
[midway]: https://midwayjs.org
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
2022-10-09 16:55:49 +08:00
|
|
|
|
### 低价服务器
|
2022-03-27 10:35:46 +08:00
|
|
|
|
|
2022-10-09 16:55:49 +08:00
|
|
|
|
[阿里云、腾讯云、华为云低价云服务器,不限新老](https://cool-js.com/ad/server.html)
|