当前位置:首页 > 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 实现多层评论回复 数据结构设计 多层评论通常采用嵌套结构,每个评论对象包含子评论数组。示例数据结构如下: comments: [ { id: 1, content: '父…

vue实现人脸识别比对

vue实现人脸识别比对

Vue 实现人脸识别比对的方法 使用现成的人脸识别 API 通过调用第三方人脸识别 API(如 Face++、百度 AI、腾讯云等)实现比对功能。注册开发者账号获取 API Key 和 Secret,…

vue实现横向导航

vue实现横向导航

vue实现横向导航的方法 使用Flex布局实现横向导航 在Vue中可以通过Flex布局快速实现横向导航。创建一个组件,使用display: flex和flex-direction: row属性使导航项…

vue怎么实现数据检测

vue怎么实现数据检测

Vue 数据检测的实现方式 Vue 通过响应式系统实现数据检测,核心机制基于 Object.defineProperty(Vue 2)或 Proxy(Vue 3)。以下是具体实现方法: 基于 Vu…

vue实现列表显示

vue实现列表显示

Vue 实现列表显示的方法 在 Vue 中实现列表显示通常使用 v-for 指令,结合数组或对象数据渲染动态列表。以下是几种常见的实现方式。 基本列表渲染 通过 v-for 指令遍历数组,动态生成列…

vue实现继承语法糖

vue实现继承语法糖

在Vue中实现继承可以通过多种方式模拟类继承的效果,以下是常见的几种方法: 使用mixins实现逻辑复用 通过Vue的mixins机制共享组件选项,达到类似继承的效果: const BaseC…