教務系統(tǒng)實訓四

實訓(實訓四)

projectName文件,在models目錄下創(chuàng)建classs.js文件

const mongoose = require('mongoose') const Schema= mongoose.Schema const feld={ name: String, //人物標簽 level:String, renshu: Number, school : { type: Schema.Types.ObjectId, ref: 'School' }, academy : { type: Schema.Types.ObjectId, ref: 'Academy' } } //自動添加更新時間創(chuàng)建時間: let personSchema = new mongoose.Schema(feld, {timestamps: {createdAt: 'created', updatedAt: 'updated'}}) module.exports= mongoose.model('Classs',personSchema)

projectName下的routes目錄们镜,創(chuàng)建classs.js

const router = require('koa-router')() let Model = require("../db/models/classs"); router.prefix('/classs') router.get('/', function (ctx, next) { ctx.body = 'this is a users response!' }) router.post('/add', async function (ctx, next) { console.log(ctx.request.body) let model = new Model(ctx.request.body); model = await model.save(); console.log('user',model) ctx.body = model }) router.post('/find', async function (ctx, next) { let models = await Model. find({}).populate('academy').populate('school') ctx.body = models }) router.post('/get', async function (ctx, next) { // let users = await User. // find({}) console.log(ctx.request.body) let model = await Model.find(ctx.request.body) console.log(model) ctx.body = model }) router.post('/update', async function (ctx, next) { console.log(ctx.request.body) let pbj = await Model.update({ _id: ctx.request.body._id }, ctx.request.body); ctx.body = pbj }) router.post('/delete', async function (ctx, next) { console.log(ctx.request.body) await Model.remove({ _id: ctx.request.body._id }); ctx.body = 'shibai ' }) module.exports = router

app.js中掛載路由

const classs= require('./routes/classs') app.use(classs.routes(), classs.allowedMethods())

vue-admin-template-master文件,在src/views目錄下創(chuàng)建一個classs模塊阳堕,并創(chuàng)建academy.vue文件

import { mapGetters } from 'vuex' export default { name: 'classs', computed: { ...mapGetters([ 'name' ]) }, data(){ return{ schools:[], academys:[], //列表內容 options: [ ], apiModel:'classs', form:{} } }, methods:{ onSubmit(){ if(this.form._id){ this.$http.post(`/api/${this.apiModel}/update`,this.form).then(res => { console.log('bar:', res) this.$router.push({path:this.apiModel}) this.form={} }) }else { this.$http.post('/api/'+this.apiModel+'/add',this.form).then(res => { console.log('bar:', res) this.$router.push({path:this.apiModel}) this.form={} }) } }, schoolChange(val1){ //顯示學院選擇欄目 this.$http.post('/api/academy/get',{school:val1}).then(res => { if(res&&res.length>0){ this.academys = res console.log('res:', res) } }) } }, mounted() { if(this.$route.query._id){ this.$http.post('/api/'+this.apiModel+'/get',{_id:this.$route.query._id}).then(res => { if(res&&res.length>0){ this.form = res[0] this.schoolChange(this.form.school) } }) } //顯示學校選擇欄目 this.$http.post('/api/school/find').then(res => { if(res&&res.length>0){ this.schools = res console.log('res:', res) } }) } } .dashboard { &-container { margin: 30px; } &-text { font-size: 30px; line-height: 46px; } }
立即創(chuàng)建 取消
import { mapGetters } from 'vuex' export default { name: 'classs', computed: { ...mapGetters([ 'name' ]) }, data(){ return{ schools:[], academys:[], //列表內容 options: [ ], apiModel:'classs', form:{} } }, methods:{ onSubmit(){ if(this.form._id){ this.$http.post(`/api/${this.apiModel}/update`,this.form).then(res => { console.log('bar:', res) this.$router.push({path:this.apiModel}) this.form={} }) }else { this.$http.post('/api/'+this.apiModel+'/add',this.form).then(res => { console.log('bar:', res) this.$router.push({path:this.apiModel}) this.form={} }) } }, schoolChange(val1){ //顯示學院選擇欄目 this.$http.post('/api/academy/get',{school:val1}).then(res => { if(res&&res.length>0){ this.academys = res console.log('res:', res) } }) } }, mounted() { if(this.$route.query._id){ this.$http.post('/api/'+this.apiModel+'/get',{_id:this.$route.query._id}).then(res => { if(res&&res.length>0){ this.form = res[0] this.schoolChange(this.form.school) } }) } //顯示學校選擇欄目 this.$http.post('/api/school/find').then(res => { if(res&&res.length>0){ this.schools = res console.log('res:', res) } }) } } .dashboard { &-container { margin: 30px; } &-text { font-size: 30px; line-height: 46px; } }
立即創(chuàng)建 取消
import { mapGetters } from 'vuex' export default { name: 'classs', computed: { ...mapGetters([ 'name' ]) }, data(){ return{ schools:[], academys:[], //列表內容 options: [ ], apiModel:'classs', form:{} } }, methods:{ onSubmit(){ if(this.form._id){ this.$http.post(`/api/${this.apiModel}/update`,this.form).then(res => { console.log('bar:', res) this.$router.push({path:this.apiModel}) this.form={} }) }else { this.$http.post('/api/'+this.apiModel+'/add',this.form).then(res => { console.log('bar:', res) this.$router.push({path:this.apiModel}) this.form={} }) } }, schoolChange(val1){ //顯示學院選擇欄目 this.$http.post('/api/academy/get',{school:val1}).then(res => { if(res&&res.length>0){ this.academys = res console.log('res:', res) } }) } }, mounted() { if(this.$route.query._id){ this.$http.post('/api/'+this.apiModel+'/get',{_id:this.$route.query._id}).then(res => { if(res&&res.length>0){ this.form = res[0] this.schoolChange(this.form.school) } }) } //顯示學校選擇欄目 this.$http.post('/api/school/find').then(res => { if(res&&res.length>0){ this.schools = res console.log('res:', res) } }) } } .dashboard { &-container { margin: 30px; } &-text { font-size: 30px; line-height: 46px; } }
<template><divclass="dashboard-container"><el-formref="form":model="form"label-width="80px"><el-form-itemlabel="所屬學校"><el-selectv-model="form.school"placeholder="請選擇"@change="schoolChange"><el-optionv-for="item in schools":key="item._id":label="item.name":value="item._id"></el-option></el-select></el-form-item><!-- 編輯框:學院選擇列表--><el-form-itemlabel="所屬學院"><el-selectv-model="form.academy"placeholder="請選擇"><el-optionv-for="item in academys":key="item._id":label="item.name":value="item._id"></el-option></el-select></el-form-item><el-form-itemlabel="班級名稱"><el-inputv-model="form.name"></el-input></el-form-item><el-form-itemlabel="專業(yè)"><el-inputv-model="form.level"></el-input></el-form-item><el-form-itemlabel="人數"><el-inputv-model="form.renshu"></el-input></el-form-item><el-form-item><el-buttontype="primary"@click="onSubmit">立即創(chuàng)建</el-button><el-button>取消</el-button></el-form-item></el-form></div></template><script>import { mapGetters } from 'vuex' export default { name: 'classs', computed: { ...mapGetters([ 'name' ]) }, data(){ return{ schools:[], academys:[], //列表內容 options: [ ], apiModel:'classs', form:{} } }, methods:{ onSubmit(){ if(this.form._id){ this.$http.post(`/api/${this.apiModel}/update`,this.form).then(res => { console.log('bar:', res) this.$router.push({path:this.apiModel}) this.form={} }) }else { this.$http.post('/api/'+this.apiModel+'/add',this.form).then(res => { console.log('bar:', res) this.$router.push({path:this.apiModel}) this.form={} }) } }, schoolChange(val1){ //顯示學院選擇欄目 this.$http.post('/api/academy/get',{school:val1}).then(res => { if(res&&res.length>0){ this.academys = res console.log('res:', res) } }) } }, mounted() { if(this.$route.query._id){ this.$http.post('/api/'+this.apiModel+'/get',{_id:this.$route.query._id}).then(res => { if(res&&res.length>0){ this.form = res[0] this.schoolChange(this.form.school) } }) } //顯示學校選擇欄目 this.$http.post('/api/school/find').then(res => { if(res&&res.length>0){ this.schools = res console.log('res:', res) } }) } }</script><stylelang="scss"scoped>.dashboard { &-container { margin: 30px; } &-text { font-size: 30px; line-height: 46px; } }</style>

index.vue文件

import { mapGetters } from 'vuex' export default { name: 'classs', computed: { ...mapGetters([ 'name' ]) }, data() { return { apiModel:'classs', users: {} } }, methods: { onSubmit() { console.log(123434) }, handleEdit(index, item) { this.$router.push({ path: '/'+this.apiModel+'/editor', query: {_id:item._id} }) }, handleDelete(index, item) { this.$http.post('/api/'+this.apiModel+'/delete', item).then(res => { console.log('res:', res) this.findUser() }) }, findUser(){ this.$http.post('/api/'+this.apiModel+'/find', this.user).then(res => { console.log('res:', res) this.users = res }) } }, mounted() { this.findUser() } } .dashboard { &-container { margin: 30px; } &-text { font-size: 30px; line-height: 46px; } } <template>

??<div?class="dashboard-container">

????<el-table

??????:data="users"

??????style="width:?100%"

??????:row-class-name="tableRowClassName">

??????<el-table-column

????????prop="name"

????????label="班級名稱"

????????width="180">

??????</el-table-column>

??????<el-table-column

????????prop="level"

????????label="專業(yè)"

????????width="180">

??????</el-table-column>

??????<el-table-column

????????prop="renshu"

????????label="人數">

??????</el-table-column>

<!--??????列表添加項目

-->

??????<el-table-column

????????prop="school"

????????label="學校名稱"

????????width="180">

????????<template?slot-scope="scope"?>

??????????<span?class=""?v-if="scope.row.school">

????????????<el-tag

??????????????:type="scope.row.school.name?===?'深圳信息職業(yè)技術學院'???'primary'?:?'success'"

??????????????disable-transitions>{{scope.row.school.name}}</el-tag>

??????????</span>

????????</template>

??????</el-table-column>

??????<el-table-column

????????prop="academy"

????????label="學院名稱"

????????width="180">

????????<template?slot-scope="scope"?>

??????????<span?class=""?v-if="scope.row.academy">

????????????<el-tag

??????????????:type="scope.row.academy.name?===?'軟件學院'???'primary'?:?'success'"

??????????????disable-transitions>{{scope.row.academy.name}}</el-tag>

??????????</span>

????????</template>

??????</el-table-column>

??????<el-table-column?label="操作">

????????<template?slot-scope="scope">

??????????<el-button

????????????size="mini"

????????????@click="handleEdit(scope.$index,?scope.row)">編輯

??????????</el-button>

??????????<el-button

????????????size="mini"

????????????type="danger"

????????????@click="handleDelete(scope.$index,?scope.row)">刪除

??????????</el-button>

????????</template>

??????</el-table-column>

????</el-table>

??</div>

</template>

<script>

??import?{?mapGetters?}?from?'vuex'

??export?default?{

????name:?'classs',

????computed:?{

??????...mapGetters([

????????'name'

??????])

????},

????data()?{

??????return?{

????????apiModel:'classs',

????????users:?{}

??????}

????},

????methods:?{

??????onSubmit()?{

????????console.log(123434)

??????},

??????handleEdit(index,?item)?{

????????this.$router.push({?path:?'/'+this.apiModel+'/editor',?query:?{_id:item._id}?})

??????},

??????handleDelete(index,?item)?{

????????this.$http.post('/api/'+this.apiModel+'/delete',?item).then(res?=>?{

??????????console.log('res:',?res)

??????????this.findUser()

????????})

??????},

??????findUser(){

????????this.$http.post('/api/'+this.apiModel+'/find',?this.user).then(res?=>?{

??????????console.log('res:',?res)

??????????this.users?=?res

????????})

??????}

????},

????mounted()?{

??????this.findUser()

????}

??}

</script>

<style?lang="scss"?scoped>

??.dashboard?{

????&-container?{

??????margin:?30px;

????}

????&-text?{

??????font-size:?30px;

??????line-height:?46px;

????}

??}

</style>



index.js中添加路由:

{ ????path:?'/classs', ????component:?Layout, ????meta:?{?title:?'班級管理',?icon:?'example'?}, ????redirect:?'/classs', ????children:?[{ ??????path:?'classs', ??????name:?'classs', ??????component:?()?=>?import('@/views/classs'), ??????meta:?{?title:?'班級管理',?icon:?'classs'?} ????}, ??????{ ????????path:?'editor', ????????name:?'editor', ????????component:?()?=>?import('@/views/classs/editor'), ????????meta:?{?title:?'添加班級',?icon:?'classs'?} ??????}] ??}, ??{ ????path:?'/student', ????component:?Layout, ????meta:?{?title:?'學生管理',?icon:?'example'?}, ????redirect:?'/student', ????children:?[{ ??????path:?'student', ??????name:?'student', ??????component:?()?=>?import('@/views/student/index'), ??????meta:?{?title:?'學生管理',?icon:?'user'?} ????}, ??????{ ????????path:?'editor', ????????name:?'editor', ????????component:?()?=>?import('@/views/student/editor'), ????????meta:?{?title:?'添加學生',?icon:?'user'?} ??????}] ??},

?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子码倦,更是在濱河造成了極大的恐慌鸦致,老刑警劉巖潮剪,帶你破解...
    沈念sama閱讀 221,695評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現場離奇詭異分唾,居然都是意外死亡抗碰,警方通過查閱死者的電腦和手機,發(fā)現死者居然都...
    沈念sama閱讀 94,569評論 3 399
  • 文/潘曉璐 我一進店門绽乔,熙熙樓的掌柜王于貴愁眉苦臉地迎上來弧蝇,“玉大人,你說我怎么就攤上這事『慈溃” “怎么了骤视?”我有些...
    開封第一講書人閱讀 168,130評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長鹃觉。 經常有香客問我专酗,道長,這世上最難降的妖魔是什么盗扇? 我笑而不...
    開封第一講書人閱讀 59,648評論 1 297
  • 正文 為了忘掉前任祷肯,我火速辦了婚禮,結果婚禮上疗隶,老公的妹妹穿的比我還像新娘佑笋。我一直安慰自己,他們只是感情好斑鼻,可當我...
    茶點故事閱讀 68,655評論 6 397
  • 文/花漫 我一把揭開白布蒋纬。 她就那樣靜靜地躺著,像睡著了一般坚弱。 火紅的嫁衣襯著肌膚如雪蜀备。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,268評論 1 309
  • 那天荒叶,我揣著相機與錄音碾阁,去河邊找鬼。 笑死些楣,一個胖子當著我的面吹牛脂凶,可吹牛的內容都是我干的。 我是一名探鬼主播愁茁,決...
    沈念sama閱讀 40,835評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼蚕钦,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了埋市?” 一聲冷哼從身側響起冠桃,我...
    開封第一講書人閱讀 39,740評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎道宅,沒想到半個月后食听,有當地人在樹林里發(fā)現了一具尸體,經...
    沈念sama閱讀 46,286評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡污茵,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,375評論 3 340
  • 正文 我和宋清朗相戀三年樱报,在試婚紗的時候發(fā)現自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片泞当。...
    茶點故事閱讀 40,505評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡迹蛤,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情盗飒,我是刑警寧澤嚷量,帶...
    沈念sama閱讀 36,185評論 5 350
  • 正文 年R本政府宣布,位于F島的核電站逆趣,受9級特大地震影響蝶溶,放射性物質發(fā)生泄漏。R本人自食惡果不足惜宣渗,卻給世界環(huán)境...
    茶點故事閱讀 41,873評論 3 333
  • 文/蒙蒙 一抖所、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧痕囱,春花似錦田轧、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,357評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至有序,卻和暖如春抹腿,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背旭寿。 一陣腳步聲響...
    開封第一講書人閱讀 33,466評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留崇败,地道東北人盅称。 一個月前我還...
    沈念sama閱讀 48,921評論 3 376
  • 正文 我出身青樓,卻偏偏與公主長得像后室,于是被迫代替她去往敵國和親缩膝。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,515評論 2 359

推薦閱讀更多精彩內容

  • 實訓(二) 打開projectName文件岸霹,在models目錄下創(chuàng)建school.js文件 constmongoo...
    蘇芷婷閱讀 297評論 0 0
  • 目標:創(chuàng)建班級管理模塊(班級和學院疾层、學校關聯起來) 一、后臺三步驟: 1贡避、在db->models目錄下創(chuàng)建clas...
    小甜甜甜甜椒閱讀 362評論 0 0
  • 目標:創(chuàng)建班級管理模塊(班級和學院痛黎、學校關聯起來) 一、后臺三步驟: 1刮吧、打開projectName文件湖饱,在mod...
    不留遺憾_dd5b閱讀 120評論 0 0
  • 目標:創(chuàng)建學生管理模塊(學生和班級、學院杀捻、學校關聯起來) 一井厌、后臺三步驟: 1、在db->models目錄下創(chuàng)建s...
    小甜甜甜甜椒閱讀 217評論 0 0
  • ### 1.安裝 nodejs ### 2.安裝 git ### 3.下載 [vue-element-admin]...
    gogogo_e6cf閱讀 366評論 0 0