当前位置:首页 > 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 中实现视频开场动画可以通过结合 HTML5 的 <video> 标签和 Vue 的过渡效果或生命周期钩子来完成。以下是具体实现方法: 安装依…

vue实现自动翻译

vue实现自动翻译

Vue 实现自动翻译的方法 在 Vue 项目中实现自动翻译功能可以通过多种方式完成,以下是几种常见的方法: 使用第三方翻译 API 注册并获取翻译 API 的密钥(如 Google Translat…

vue实现适老化样式

vue实现适老化样式

Vue 实现适老化样式的关键方法 全局字体与字号调整 通过 CSS 变量或主题配置统一放大基础字号,建议正文不小于 18px,标题更大。在 App.vue 中设置全局样式: :root { -…

vue实现继承语法糖

vue实现继承语法糖

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

vue实现签约合作弹窗

vue实现签约合作弹窗

实现签约合作弹窗的步骤 使用Vue实现签约合作弹窗可以通过组件化方式完成,结合模态框和表单交互逻辑。以下是具体实现方法: 1. 创建弹窗组件 新建一个Vue组件文件(如SignContractDi…

vue里实现增删改查

vue里实现增删改查

在Vue中实现增删改查 数据初始化 在Vue组件的data中定义初始数据和表单绑定的变量: data() { return { items: [ { id: 1, name:…