<|start_filename|>src/model/teacher.js<|end_filename|>
import axios from '@/utils/request'

class Teacher {
  // 注册
  static async register(userInfo) {
    return axios.post('/teacher/register', {
      ...userInfo
    })
  }
  // 查询课程详情
  static async getCourseDetail(cno) {
    return await axios.get(`/student/getCourse?cnos=${cno}`)
  }
}

export {
  Teacher
}


<|start_filename|>src/model/admin.js<|end_filename|>
import axios from '@/utils/request'

class Admin {
  static async getCountData() {
    return await axios.get(`/admin/public`)
  }

  // 获取所有课程列表
  static async getCourseList(page, size) {
    return await axios.get(`/admin/getAllCourse?page=${page}&size=${size}`)
  }

  // 添加一门课程
  static async addCourse(couseInfo) {
    return await axios.post('/admin/addCourse', {
      ...couseInfo
    })
  }

  // 修改课程信息
  static async modifycourse(couseInfo) {
    return await axios.post('/admin/modifyCourse', {
      ...couseInfo
    })
  }

  // 删除一门课程
  static async deleteCouse(cno) {
    return await axios.post(`/admin/deleteCourse?cno=${cno}`)
  }

  // 获取教师列表
  static async getTeacherList(page, size) {
    return await axios.get(`/admin/getAllTeacher?page=${page}&size=${size}`)
  }

  // 修改一名教师信息

  static async modifyTeacher(userInfo) {
    return await axios.post('/teacher/modify', {
      ...userInfo
    })
  }

  // 删除一名教师
  static async deleteTeacher(id) {
    return await axios.post(`/teacher/delete?id=${id}`)
  }

  // 获取教师密码
  static async getPassword(name) {
    return await axios.post(`/teacher/getPassword?name=${name}`)
  }
}

export {
  Admin
}


<|start_filename|>src/model/course.js<|end_filename|>
import axios from '@/utils/request'

class Course {
  // 注册
  static async register(userInfo) {
    return axios.post('/teacher/register', {
      ...userInfo
    })
  }
}

export {
  Course
}


<|start_filename|>src/model/student.js<|end_filename|>
import axios from '@/utils/request'
class Student {
  // 获取成绩清单
  static async getScoreList(sno) {
    if (!sno) {
      return
    }
    return await axios.get(`/student/detail/${sno}`)
  }

  // 获取学生成绩分布数据
  static async getScoreDistribute(sno) {
    if (!sno) {
      return
    }
    return await axios.get(`/student/getState/${sno}`)
  }

  // 学生注册
  static async register(userInfo) {
    return await axios.post('/student/register', { ...userInfo })
  }

  // 返回学生列表
  static async getList(page, size) {
    return await axios.get(`/student/getAll?page=${page}&size=${size}`)
  }

  // 修改学生信息 教师不允许修改密码
  static async modifyInfo(userInfo) {
    return await axios.post('/student/modify', {
      ...userInfo
    })
  }
  // 删除一名学生信息
  static async deleteInfo(sno) {
    return await axios.post(`/student/delete?sno=${sno}`)
  }

  // 录入或者修改成绩
  static async modifyScore(options) {
    return await axios.post('/student/score/addOrModify', {
      ...options
    })
  }

  // 搜索学生列表
  static async searchKeyword(keywrod, page, size) {
    return await axios.get(`/student/search?keyword=${keywrod}&page=${page}&size=${size}`)
  }

  // 传入成绩id 删除成绩
  static async deleteScore(id) {
    return await axios.post(`/student/score/delete?id=${id}`)
  }
}
export {
  Student
}


<|start_filename|>src/config/enum.js<|end_filename|>
export const collegeOptions =
  [
    {
      value: '软件学院',
      label: '软件学院'
    },
    {
      value: '计算机学院',
      label: '计算机学院'
    },
    {
      value: '理学院',
      label: '理学院'
    },
    {
      value: '文法学院',
      label: '文法学院'
    },
    {
      value: '机械学院',
      label: '机械学院'
    },
    {
      value: '艺术学院',
      label: '艺术学院'
    },
    {
      value: '体育学院',
      label: '体育学院'
    },
    {
      'value': '大数据学院',
      label: '大数据学院'
    }
  ]

export const subjectOptions =
  [
    {
      value: '软件工程',
      label: '软件工程'
    },
    {
      value: '计算机技术与科学',
      label: '计算机技术与科学'
    },
    {
      value: '物理学',
      label: '物理学'
    },
    {
      value: '语文',
      label: '语文'
    },
    {
      value: '机械工程',
      label: '机械工程'
    },
    {
      value: '英语',
      label: '英语'
    },
    {
      value: '数学',
      label: '数学'
    },
    {
      'value': '大数据',
      label: '大数据'
    },
    {
      value: '核工业科学',
      label: '和工业科学'
    },
    {
      value: '法学',
      label: '法学'
    },
    {
      value: '会计学',
      label: '会计学'
    },
    {
      'value': '金融学',
      label: '金融学'
    }
  ]

export const genderOptions = [
  {
    label: '男',
    value: 0
  },
  {
    label: '女',
    value: 1
  }
]



<|start_filename|>src/router/index.js<|end_filename|>
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 公共路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    },
    {
      path: 'teacher/student/score/detail',
      component: () => import('@/views/teacher/score/score-detail'),
      meta: { title: '成绩详情' },
      hidden: true
    }
    ]
  },
  {
    path: '/chat',
    name: 'chat',
    component: Layout,
    children: [{
      path: '',
      name: 'chat',
      component: () => import('@/views/chat/index'),
      meta: { title: '在线交流平台', icon: 'wechat' }
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]
// 权限控制路由
export const asyncRoutes = [
  // 学生角色路由 大屏数据和成绩查询
  {
    path: '/student',
    name: 'student',
    component: Layout,
    meta: { title: '学生信息查询', icon: 'documentation', roles: ['student'] },
    children: [
      {
        path: 'info',
        component: () => import('@/views/student/info'),
        name: 'studentInfo',
        meta: { title: '信息查询', icon: 'form' }
      },
      {
        path: 'score',
        component: () => import('@/views/student/score'),
        name: 'studentScore',
        meta: { title: '成绩查询', icon: 'score' }
      }
    ]
  },
  // 教师路由分配
  {
    path: '/teacher/student',
    name: 'teacherStudent',
    component: Layout,
    meta: { title: '学生管理', icon: 'form', roles: ['teacher'] },
    children: [
      {
        path: 'info',
        component: () => import('@/views/teacher/student/index'),
        meta: { title: '学生信息管理', icon: 'student' },
        children: [
          {
            path: '',
            component: () => import('@/views/teacher/student/student'),
            meta: { title: '学生列表', icon: 'list' }
          },
          {
            path: 'add',
            component: () => import('@/views/teacher/student/addStudent'),
            meta: { title: '添加学生', icon: 'edit' }
          }
        ]
      },
      {
        path: 'score',
        component: () => import('@/views/teacher/score/index'),
        meta: { title: '学生成绩管理', icon: 'score' },
        children: [
          {
            path: '',
            component: () => import('@/views/teacher/score/studentScore'),
            meta: { title: '学生成绩列表', icon: 'list' }
          },
          {
            path: 'add',
            component: () => import('@/views/teacher/score/addScore'),
            meta: { title: '录入成绩', icon: 'edit' }
          }
        ]
      }
    ]
  },
  // 管理员额外路由
  {
    path: '/admin/course',
    component: Layout,
    meta: { title: '课程管理', icon: 'course', roles: ['admin'] },
    children: [
      {
        path: 'list',
        name: 'adminCourse',
        component: () => import('@/views/admin/course/course'),
        meta: { title: '课程列表', icon: 'list' }
      },
      {
        path: 'add',
        name: 'adminaddCourse',
        component: () => import('@/views/admin/course/addCourse'),
        meta: { title: '添加课程', icon: 'edit' }
      }
    ]
  },
  {
    path: '/admin/teacher',
    component: Layout,
    meta: { title: '教师管理', icon: 'teacher', roles: ['admin'] },
    children: [
      {
        path: 'list',
        name: 'adminTeacher',
        component: () => import('@/views/admin/teacher/teacher'),
        meta: { title: '教师列表', icon: 'list' }
      },
      {
        path: 'add',
        name: 'adminaddTeacher',
        component: () => import('@/views/admin/teacher/addTeacher'),
        meta: { title: '添加教师', icon: 'edit' }
      }
    ]
  },
  {
    'path': 'external-link',
    'component': Layout,
    'children': [
      {
        'path': 'https://github.com/251205668/student-admin-template',
        'meta': { 'title': '项目地址', 'icon': 'guide' }
      }
    ]
  },
  {
    'path': 'external-link',
    'component': Layout,
    'children': [
      {
        'path': 'https://documenter.getpostman.com/view/10611320/T17Ge7JB?version=latest',
        'meta': { 'title': '接口文档', 'icon': 'skill' }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router


<|start_filename|>socket.js<|end_filename|>
const WebSocket = require('ws')
const http = require('http')
// const jwt = require('jsonwebtoken')

const wss = new WebSocket.Server({ noServer: true })
const server = http.createServer()

const group = {} // 记录每个房间号的人数

// roomid -> 对应相同的roomid进行广播消息
wss.on('connection', function connection(ws) {
  // ws代表当前收到消息的客户端
  // 接收客户端消息
  ws.on('message', function(msg) {
    const msgObj = JSON.parse(msg)
    if (msgObj.event === 'enter') {
      // 用户信息
      ws.name = msgObj.name
      ws.avatar = msgObj.avatar
      ws.roomid = msgObj.roomid
      // 首次进入房间判断 房间人数置为1
      if (typeof group[ws.roomid] === 'undefined') {
        group[ws.roomid] = 1
      } else {
        group[ws.roomid] += 1
      }
    }
    // 接收到信息后 发送广播消息(即获取所有的客户端)
    wss.clients.forEach(client => {
      // 补充：如何判断非自己的客户端：ws !== client
      if (client.readyState === WebSocket.OPEN && client.roomid === ws.roomid) {
        // 同一个房间 进行广播
        msgObj.name = ws.name
        msgObj.avatar = ws.avatar
        // 房间人数
        msgObj.num = group[ws.roomid]
        // 发送广播消息 附带消息
        client.send(JSON.stringify(msgObj))
      }
    })
  })

  // 当ws客户端断开链接的时候
  ws.on('close', function(msg) {
    if (ws.name) {
      group[ws.roomid] -= 1
    }

    const msgObj = {}
    wss.clients.forEach(client => {
      if (client.readyState === WebSocket.OPEN && ws.roomid === client.roomid) {
        msgObj.name = ws.name
        msgObj.avatar = ws.avatar
        msgObj.num = group[ws.roomid] // 聊天室的人数
        msgObj.event = 'out'
        client.send(JSON.stringify(msgObj))
      }
    })
  })
})

server.on('upgrade', function upgrade(request, socket, head) {
  wss.handleUpgrade(request, socket, head, function done(ws) {
    wss.emit('connection', ws, request)
  })
})

server.listen(3000)
