• 「实用场景教程」如何用日程控件DHTMLX Scheduler制作酒店预订日历?(一)


    dhtmlxScheduler是一个类似于Google日历的JavaScript日程安排控件,日历事件通过Ajax动态加载,支持通过拖放功能调整事件日期和时间,事件可以按天,周,月三个种视图显示。

    DHTMLX Scheduler正式版下载

    在本教程中,我们将使用两个强大的工具:DHTMLX Scheduler库和Angular框架来创建一个全面的酒店客房预订应用程序。在这篇文章中,我们的目标是创建一个看起来像这样的应用程序:

    何用日程控件DHTMLX Scheduler制作酒店预订日历?

    Angular酒店预订应用将能够显示酒店房间、房间类型、房间状态、特定日期的预订和预订状态,该应用程序还允许执行CRUD操作。

    如果您刚开始配置DHTMLX Scheduler来预订房间或将其集成到Angular应用程序中,我们还为您提供了专门的教程:

    Step 0 – 前提条件

    在开始之前,请确保您已经有了Node.jsAngular CLI

    Step 1 – 准备应用程序

    要创建应用程序,使用如下命令:

    ng new room-reservation-angular

    操作完成后,我们可以进入app目录并运行应用程序:

    cd room-reservation-angular
    ng serve

    现在如果打开打开http://127.0.0.1:4200,应该看到初始页面。ng serve命令将监视源文件,并在必要时修改和重建应用程序。

    何用日程控件DHTMLX Scheduler制作酒店预订日历?

    Step 2 – 创建数据模型

    让我们定义Reservation、Room、RoomType、CleaningStatus和BookingStatus模型,执行如下命令:

    1. ng generate interface models/reservation model
    2. ng generate interface models/room model
    3. ng generate interface models/roomType model
    4. ng generate interface models/cleaningStatus model
    5. ng generate interface models/bookingStatus model

    在models文件夹中新创建的reservation.model.ts文件中,我们将添加以下代码:

    1. export interface Reservation {
    2. id: number;
    3. start_date: string;
    4. end_date: string;
    5. text: string;
    6. room: string;
    7. booking_status: string;
    8. is_paid: string;
    9. }

    在room.model.ts、room-type.model.ts、cleaning-status.model.ts、booking-status.model.ts文件中,添加下面的代码行:

    1. export interface Room {
    2. id: number;
    3. value: string;
    4. label: string;
    5. type: string;
    6. cleaning_status: string;
    7. }
    8. export interface RoomType {
    9. id: string;
    10. value: string;
    11. label: string;
    12. }
    13. export interface CleaningStatus {
    14. id: string;
    15. value: string;
    16. label: string;
    17. color: string;
    18. }
    19. export interface BookingStatus {
    20. id: string;
    21. value: string;
    22. label: string;
    23. }
    Step 3 – 创建Scheduler组件

    下载DHTMLX Scheduler PRO版最新的试用版(直接戳这里>>),将下载的包解压缩到本地机器的项目根文件夹中。为了能够将Scheduler嵌入到应用程序中,您应该获得DHTMLX Scheduler代码。执行如下命令:

    npm install ./scheduler_6.0.5_trial

    创建一个新的组件,为此运行以下命令:

    ng generate component scheduler --skip-tests

    在scheduler文件夹中新创建的scheduler.component.html文件将包含调度器的模版,让我们添加下一行代码:

    1. <div #scheduler_here class='dhx_cal_container' style='width:100%; height:100vh'>
    2. <div class='dhx_cal_navline'>
    3. <div style='font-size:16px;padding:4px 20px;'>
    4. Show rooms:
    5. <select id='room_filter' [(ngModel)]='selectedRoomType' (ngModelChange)='filterRoomsByType($event)'>select>
    6. div>
    7. <div class='dhx_cal_prev_button'> div>
    8. <div class='dhx_cal_next_button'> div>
    9. <div class='dhx_cal_today_button'>div>
    10. <div class='dhx_cal_date'>div>
    11. div>
    12. <div class='dhx_cal_header'>div>
    13. <div class='dhx_cal_data'>div>
    14. div>

    使用ngModel和ngModelChange指令来建立组件中select元素和数据之间的交互,请将FormsModule模块添加到app.module.ts文件中。

    1. import { NgModule } from '@angular/core';
    2. import { BrowserModule } from '@angular/platform-browser';
    3. import { AppRoutingModule } from './app-routing.module';
    4. import { AppComponent } from './app.component';
    5. import { SchedulerComponent } from './scheduler/scheduler.component';
    6. import { FormsModule } from '@angular/forms';
    7. @NgModule({
    8. declarations: [
    9. AppComponent,
    10. SchedulerComponent
    11. ],
    12. imports: [
    13. BrowserModule,
    14. AppRoutingModule,
    15. FormsModule
    16. ],
    17. providers: [],
    18. bootstrap: [AppComponent]
    19. })
    20. export class AppModule { }

    将在名为scheduler.component.css的单独文件中声明scheduler样式,央视可以以下面的方式呈现:

    1. @import '~dhtmlx-scheduler/codebase/dhtmlxscheduler_flat.css';
    2. :host {
    3. display: block;
    4. position: relative;
    5. height: 100%;
    6. width: 100%;
    7. }
    8. html, body {
    9. margin: 0;
    10. padding: 0;
    11. height: 100%;
    12. overflow: hidden;
    13. }
    14. .dhx_cal_container #room_filter:focus {
    15. outline: 1px solid #52daff;
    16. }
    17. .timeline-cell-inner {
    18. height: 100%;
    19. width: 100%;
    20. table-layout: fixed;
    21. }
    22. .timeline-cell-inner td {
    23. border-left: 1px solid #cecece;
    24. }
    25. .dhx_section_time select {
    26. display: none;
    27. }
    28. .timeline_weekend {
    29. background-color: #FFF9C4;
    30. }
    31. .timeline_item_cell {
    32. width: 32%;
    33. height: 100% !important;
    34. font-size: 14px;
    35. text-align: center;
    36. line-height: 50px;
    37. }
    38. .cleaning_status {
    39. position: relative;
    40. }
    41. .timeline_item_separator {
    42. background-color: #CECECE;
    43. width: 1px;
    44. height: 100% !important;
    45. }
    46. .dhx_cal_event_line {
    47. background-color: #FFB74D !important;
    48. }
    49. .event_1 {
    50. background-color: #FFB74D !important;
    51. }
    52. .event_2 {
    53. background-color: #9CCC65 !important;
    54. }
    55. .event_3 {
    56. background-color: #40C4FF !important;
    57. }
    58. .event_4 {
    59. background-color: #BDBDBD !important;
    60. }
    61. .booking_status,
    62. .booking_paid {
    63. position: absolute;
    64. right: 5px;
    65. }
    66. .booking_status {
    67. top: 2px;
    68. }
    69. .booking_paid {
    70. bottom: 2px;
    71. }
    72. .dhx_cal_event_line:hover .booking-option {
    73. background: none !important;
    74. }
    75. .dhx_cal_header .dhx_scale_bar {
    76. line-height: 26px;
    77. color: black;
    78. }
    79. .dhx_section_time select {
    80. display: none
    81. }
    82. .dhx_mini_calendar .dhx_year_week,
    83. .dhx_mini_calendar .dhx_scale_bar {
    84. height: 30px !important;
    85. }
    86. .dhx_cal_light_wide .dhx_section_time {
    87. text-align: left;
    88. }
    89. .dhx_cal_light_wide .dhx_section_time > input:first-child {
    90. margin-left: 10px;
    91. }
    92. .dhx_cal_light_wide .dhx_section_time input {
    93. border: 1px solid #aeaeae;
    94. padding-left: 5px;
    95. }
    96. .dhx_cal_light_wide .dhx_readonly {
    97. padding: 3px;
    98. }
    99. .collection_label .timeline_item_cell {
    100. line-height: 60px;
    101. }
    102. .dhx_cal_radio label,
    103. .dhx_cal_radio input {
    104. vertical-align: middle;
    105. }
    106. .dhx_cal_radio input {
    107. margin-left: 10px;
    108. margin-right: 2px;
    109. }
    110. .dhx_cal_radio input:first-child {
    111. margin-left: 5px;
    112. }
    113. .dhx_cal_radio {
    114. line-height: 19px;
    115. }
    116. .dhtmlXTooltip.tooltip {
    117. color: #4d4d4d;
    118. font-size: 15px;
    119. line-height: 140%;
    120. }

    要使scheduler容器占据主体的整个空间,您需要在src文件夹下的styles.css文件中添加以下样式

    1. body,
    2. html {
    3. width: 100%;
    4. height: 100%;
    5. margin: unset;
    6. }

    要继续,我们需要导入所需的模块,并将必要的代码行添加到scheduler.component.ts文件中:

    请在GitHub上查看scheduler.component.ts 的完整代码。

    现在让我们将新组件添加到页面中,为此打开app.component.html(位于src/app中)并在其中插入scheduler标签:

    <scheduler>scheduler>

    在下文中,我们将为大家继续介绍如何加载和保存数据,记得持续关注哦~

  • 相关阅读:
    【算法】链表经典OJ
    【计算机网络】第三章 链路层
    pytest-yaml 测试平台-1.新增项目和用例(有平台体验地址)
    二元关系及关系代数中的象集、除运算
    mysql面试题34:Hash索引和B+树区别是什么?在设计索引怎么选择?
    [Azure - Security] Azure的多重身份验证(二):在Azure portal 登陆时候设置MFA/2FA验证
    CentOS7关闭SELinux
    Android 12.0 framework关于systemUI定制之导航栏透明背景的功能实现
    idea maven 构建本地jar包及pom文件
    day11 多级缓存
  • 原文地址:https://blog.csdn.net/AABBbaby/article/details/134392819