後臺搭建操作流程
後臺搭建操作流程
環境準備
1.node。下載
2. mysql。下載
3. 遠程連接ssh 客戶端termius。下載
4. redis
- 下載地址
- 客戶端下載地址:鏈接。提取碼:2zho
項目準備
1.新建項目文件夾 mkdir test。cd test
5. 修改全局的npm命令爲cnpm。npm i -g cnpm。(過程有點慢,大概5分鐘)
6. 安裝 skyjt
7. 初始化項目 jt init -f (有點慢)
8. 創建項目 如 test 。cd test
9. cnpm i
10.nodemon index.js
12.config中配置數據庫、redis。
開發階段
api創建
module.exports = {
__swagger__: {
name: 'helloworld',
description: ''
},
add: { // 接口函數名
name: '增加', // 接口名稱
desc: '接口開始', //接口介紹
method: 'all', // 可 get/post
controller: 'test/test.add',// 具體實現的方法路徑
param: { // 參數對象
name:{ // 參數命名
name: '名字',
desc: '用戶名',
type: 'string',
req: 0
}
},
token: false,
needSign: false,
err_code: {},
test: {},
front: true
}
}
方法實現
// 插入數據
async add (ctx) { // ctx 全局對象
let name = ctx.checkedData.data //參數對象
const data = await global.db.t1.C(name).run()
ctx.ok(data)
},
// 刪除
async del (ctx) {
let id = ctx.checkedData.data
const data = await global.db.t1.D(id).run()
ctx.ok(data)
},
// 更新
async change (ctx) {
const data = await global.db.t1.U({id:2},{name:"xueyan"}).run()
ctx.ok(data)
},
// 查詢
async query (ctx) {
const data = await global.db.t1.R().run()
ctx.ok(data)
}