当前位置:首页 > VUE

vue实现医生排班

2026-01-18 18:23:48VUE

vue实现医生排班

数据结构设计

医生排班系统通常需要设计合理的数据结构来存储排班信息。可以采用以下格式:

data() {
  return {
    doctors: [
      { id: 1, name: '张医生', department: '内科' },
      { id: 2, name: '李医生', department: '外科' }
    ],
    schedules: [
      { doctorId: 1, date: '2023-06-01', shift: '上午' },
      { doctorId: 2, date: '2023-06-01', shift: '下午' }
    ],
    shifts: ['上午', '下午', '晚上']
  }
}

排班表格展示

使用表格组件展示排班信息,可以结合element-ui或ant-design-vue等UI框架:

<template>
  <table>
    <thead>
      <tr>
        <th>日期</th>
        <th v-for="doctor in doctors" :key="doctor.id">{{ doctor.name }}</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="day in weekDays" :key="day">
        <td>{{ day }}</td>
        <td v-for="doctor in doctors" :key="doctor.id">
          {{ getSchedule(doctor.id, day) }}
        </td>
      </tr>
    </tbody>
  </table>
</template>

排班编辑功能

实现排班编辑功能,可以通过下拉选择或模态框方式:

methods: {
  editSchedule(doctorId, date) {
    this.currentEdit = { doctorId, date }
    this.showDialog = true
  },
  saveSchedule() {
    // 更新或添加排班记录
    const index = this.schedules.findIndex(s => 
      s.doctorId === this.currentEdit.doctorId && 
      s.date === this.currentEdit.date
    )

    if(index >= 0) {
      this.schedules[index].shift = this.selectedShift
    } else {
      this.schedules.push({
        doctorId: this.currentEdit.doctorId,
        date: this.currentEdit.date,
        shift: this.selectedShift
      })
    }
    this.showDialog = false
  }
}

日历视图展示

对于更直观的展示,可以使用日历组件:

<template>
  <full-calendar
    :events="calendarEvents"
    @eventClick="handleEventClick"
  />
</template>

<script>
export default {
  computed: {
    calendarEvents() {
      return this.schedules.map(schedule => {
        const doctor = this.doctors.find(d => d.id === schedule.doctorId)
        return {
          title: `${doctor.name}(${schedule.shift})`,
          start: schedule.date,
          allDay: true
        }
      })
    }
  }
}
</script>

冲突检测

实现排班冲突检测功能,确保同一时段不会有重复排班:

methods: {
  checkConflict(doctorId, date, shift) {
    return this.schedules.some(s => 
      s.date === date && 
      s.shift === shift && 
      s.doctorId !== doctorId
    )
  }
}

数据持久化

将排班数据保存到后端API:

methods: {
  async saveToBackend() {
    try {
      const response = await axios.post('/api/schedules', {
        schedules: this.schedules
      })
      console.log('保存成功', response.data)
    } catch (error) {
      console.error('保存失败', error)
    }
  },
  async loadFromBackend() {
    try {
      const response = await axios.get('/api/schedules')
      this.schedules = response.data
    } catch (error) {
      console.error('加载失败', error)
    }
  }
}

响应式设计

确保排班系统在不同设备上都能良好显示:

vue实现医生排班

@media (max-width: 768px) {
  table {
    font-size: 12px;
  }
  th, td {
    padding: 4px;
  }
}

以上实现方案可以根据实际需求进行调整和扩展,例如添加批量排班、排班模板、医生休假管理等功能。

标签: 医生vue
分享给朋友:

相关文章

vue实现贴图

vue实现贴图

Vue 实现贴图功能 在Vue中实现贴图功能通常涉及将图片动态添加到指定位置或元素上。以下是几种常见实现方式: 使用v-bind动态绑定图片 通过数据驱动的方式动态更换图片源: <templ…

vue实现模块

vue实现模块

Vue 实现模块化的方法 Vue 支持多种模块化开发方式,可以根据项目需求选择适合的方案。 使用单文件组件(SFC) 单文件组件是 Vue 最常用的模块化方式,将模板、脚本和样式封装在一个 .vue…

vue实现radio

vue实现radio

Vue 实现 Radio 按钮 在 Vue 中实现 Radio 按钮可以通过 v-model 进行数据绑定,结合 input 元素的 type="radio" 属性。以下是一个基本示例: <t…

vue实现注册

vue实现注册

Vue 实现注册功能 注册功能通常涉及前端表单、数据验证、与后端 API 的交互等步骤。以下是一个完整的 Vue 实现注册功能的方案。 创建注册表单 使用 Vue 的模板语法创建注册表单,包含用户名…

vue jwt实现

vue jwt实现

Vue JWT 实现方法 安装依赖 确保项目中安装了 jsonwebtoken(后端)和 axios(前端)。若使用 Vue 3,可搭配 vue-router 和 pinia(或 vuex)管理状态。…

vue实现 treegrid

vue实现 treegrid

Vue 实现 TreeGrid 的方法 使用现成组件库 Element UI、Ant Design Vue 等流行组件库提供了现成的 TreeTable/TreeGrid 组件,可直接使用。 Ele…