当前位置:首页 > 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>

排班编辑功能

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

vue实现医生排班

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>

冲突检测

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

vue实现医生排班

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)
    }
  }
}

响应式设计

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

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

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

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

相关文章

vue实现方法

vue实现方法

Vue 实现方法 Vue 是一种流行的前端框架,用于构建用户界面和单页应用。以下是几种常见的 Vue 实现方法: 创建 Vue 实例 通过 new Vue() 创建一个 Vue 实例,传入配置对象,…

vue实现滑块

vue实现滑块

Vue 实现滑块组件的方法 使用原生 HTML 和 Vue 指令 通过 Vue 的 v-model 和事件监听实现基础滑块功能。创建一个包含 input 元素的组件,类型设置为 range,并绑定到…

vue实现modal

vue实现modal

Vue 实现 Modal 弹窗组件 使用 Vue 实现 Modal 弹窗组件可以通过多种方式,包括原生 Vue 组件、第三方库或自定义指令。以下是几种常见方法: 原生 Vue 组件实现 创建一个基础…

vue实现radio

vue实现radio

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

vue实现网站

vue实现网站

Vue 实现网站的基本步骤 Vue.js 是一个渐进式 JavaScript 框架,适合构建现代化的单页应用(SPA)或动态网站。以下是使用 Vue 实现网站的基本方法。 初始化 Vue 项目 使用…

vue弹幕实现

vue弹幕实现

Vue弹幕实现方法 弹幕功能常见于视频直播或评论区,以下是基于Vue的实现方案,涵盖基础弹幕、动画控制及性能优化。 基础弹幕渲染 通过v-for动态渲染弹幕列表,结合CSS实现横向移动效果。…