adonis adminify
1.0.0
基於AdonisJs和Adminify(基於Vuetify)的管理儀表板應用程序,請參閱Adonis China以了解更多資訊。關鍵字:NodeJs、VueJs、AdonisJs、ORM、關係、SQLite、MySQL、中介軟體、Restful、CRUD、材質設計
git clone https://github.com/adonis-china/adonis-admin.gitcd adonis-admincp .env.example .envnpm install && npm run serve:dev啟動 api 伺服器./ace migration:refresh --seed fill 資料庫(在 Windows 上使用node ace )git submodule update --recursive --remote --init拉取子模組cd adminifycp src/config.sample.js src/config.js在 Windows 上使用copysrc/config.js中將debug.mock更改為falsenpm install && npm run dev啟動客戶端http://localhost:8080 (或其他連接埠)。在中國使用
cnpm代替npm
./ace make:model -m Page ,建立Page模型並進行頁面管理遷移。/database/migrations/1496388160682_create_page_table.js ,新增一些欄位: table . increments ( )
table . integer ( 'type_id' ) . unsigned ( ) . nullable ( )
table . foreign ( 'type_id' ) . references ( 'types.id' )
table . string ( 'title' ) . notNullable ( )
table . text ( 'body' )
table . timestamps ( )./ace migration:run創建表/app/Model/Page.js ,加入belongsTo關係: class Page extends Lucid {
type ( ) {
return this . belongsTo ( 'App/Model/Type' )
}
}/app/Http/Controllers/Admin/Api/EmptyController.js複製到PageController.js ,然後改為: 'use strict'
const RestController = require ( './RestController' )
const Page = use ( 'App/Model/Page' )
const Type = use ( 'App/Model/Type' )
class PageController extends RestController {
get resource ( ) {
return 'pages'
}
get expand ( ) {
return [ 'type' ]
}
* gridData ( ) {
//change the fields
return {
options : {
sort : 'id' , //or '-id' as desc
create : true ,
update : true ,
delete : true
} ,
// filters: false,
filters : {
model : {
title : '' ,
created_at : ''
} ,
fields : {
title : { label : 'Title' } ,
created_at : { label : t ( 'fields.Page.created_at' ) , Page : 'date' }
} ,
rules : { } ,
} ,
columns : [
{ text : t ( 'fields.Page.id' ) , value : 'id' } ,
{ text : t ( 'fields.Page.title' ) , value : 'title' }
]
}
}
* formData ( request , response ) {
let model = {
title : '' ,
type_id : null ,
body : '' ,
}
let id
if ( request ) {
id = request . input ( 'id' )
if ( id ) {
model = yield Page . query ( ) . where ( 'id' , id ) . first ( )
}
}
let typeOptions = yield Type . query ( ) . select ( 'id' , 'name' ) . fetch ( )
for ( let type of typeOptions ) {
type . text = type . name
type . value = type . id
}
return {
model : model ,
fields : {
title : { label : 'Title' , hint : 'Page Title' , required : true } ,
type_id : {
label : 'Type' , type : 'select' , options : typeOptions , required : true ,
} ,
body : { label : 'Body' , type : 'html' , required : false } ,
} ,
rules : model . rules ,
messages : model . messages
}
}
}
module . exports = PageController/app/Http/routes.js:26中新增路由 const resources = [ 'posts' , 'users' , 'types' , 'comments' , 'settings' , 'pages' ]/adminify/src/menu.js中新增選單,然後您可以看到它顯示在左側選單中{ "href" : " /crud/pages " , "title" : " Pages " , "icon" : " view_list " },http://localhost:8080/#/crud/pages您將獲得所有頁面的網格清單檢視。plus按鈕新增頁面,新增後也可以進行編輯。