Skip to content

Commit e83f146

Browse files
author
BYSu
committed
新增排班資料 & 顯示
1 parent cfe38bf commit e83f146

File tree

6 files changed

+137
-8
lines changed

6 files changed

+137
-8
lines changed

src/components/Week/DatePicker.vue

+6-4
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,16 @@ export default {
218218
}
219219
&_weekday {
220220
display: flex;
221-
width: 90vw;
221+
width: calc(90vw - 15px);
222222
margin: auto;
223223
}
224224
&_weekday_label {
225-
width: calc(90vw / 7);
225+
font-weight: 550;
226+
width: calc((90vw - 15px) / 7);
226227
}
227228
&_body {
228229
height: calc(100vh - 112px);
230+
padding-bottom: 3.2rem;
229231
overflow: auto;
230232
&::-webkit-scrollbar {
231233
width: 0px;
@@ -237,11 +239,11 @@ export default {
237239
&_month {
238240
display: flex;
239241
flex-wrap: wrap;
240-
width: 90vw;
242+
width: calc(90vw - 15px);
241243
margin: auto;
242244
}
243245
&_date {
244-
width: calc(90vw / 7);
246+
width: calc((90vw - 15px) / 7);
245247
padding: 0.5rem 0.5rem;
246248
padding-top: 1rem;
247249
cursor: pointer;

src/components/Week/DayBody.vue

+43
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
:class="{ active: isToday }"
1818
:style="{ top: pinTop + 'px' }"
1919
/>
20+
<!-- 顯示排班 -->
21+
<div
22+
v-for="schedule in schedulesWithStyle"
23+
:key="schedule.id"
24+
class="dayBody_schedule"
25+
:style="schedule.style"
26+
/>
2027
<!-- 顯示預約事件 -->
2128
<div
2229
v-for="order in ordersWithStyle"
@@ -46,6 +53,7 @@ export default {
4653
props: {
4754
current: { type: Date, required: true },
4855
calendar: { type: Object, required: true },
56+
schedules: { type: Array, required: true },
4957
orders: { type: Array, required: true },
5058
use12Hour: { type: Boolean, default: true }
5159
},
@@ -91,6 +99,27 @@ export default {
9199
}
92100
}
93101
})
102+
},
103+
// 處理當日排班的樣式
104+
schedulesWithStyle () {
105+
const { schedules } = this
106+
const oneDay = 24 * 60 * 60
107+
const HeightPerHour = 70
108+
109+
return schedules
110+
.map(schedule => {
111+
const { from, to } = schedule.online
112+
const height = (to - from) * HeightPerHour / (60 * 60 * 1000)
113+
const totalSec = from.getSeconds() + 60 * from.getMinutes() + 60 * 60 * from.getHours()
114+
const top = (totalSec % oneDay) * HeightPerHour * 24 / oneDay
115+
return {
116+
...schedule,
117+
style: {
118+
height: height + 'px',
119+
top: top + 'px'
120+
}
121+
}
122+
})
94123
}
95124
}
96125
}
@@ -101,6 +130,7 @@ $border: #d4d5d6;
101130
$pinColor: #757575;
102131
$orderBg: #e5e5e5;
103132
$orderBg: rgba(229, 229, 229, 0.7);
133+
$scheduleBg: rgba(246, 246, 246, 0.5);
104134
105135
.dayBody {
106136
height: 100%;
@@ -145,6 +175,19 @@ $orderBg: rgba(229, 229, 229, 0.7);
145175
background-color: $orderBg;
146176
cursor: pointer;
147177
}
178+
&_schedule {
179+
position: absolute;
180+
display: flex;
181+
flex-direction: column;
182+
align-items: flex-start;
183+
z-index: 1;
184+
width: 100%;
185+
padding: 0.5rem;
186+
font-size: 0.8rem;
187+
text-align: left;
188+
background-color: $scheduleBg;
189+
cursor: pointer;
190+
}
148191
&_order_user {
149192
color: #98999a;
150193
}

src/components/Week/WeekBody.vue

+53-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
:class="{ active: isToday(d-1) }"
2323
:style="{ top: pinTop + 'px' }"
2424
/>
25+
<!-- 顯示排班 -->
26+
<div
27+
v-for="schedule in weekDaySchedules(d-1)"
28+
:key="schedule.id"
29+
class="weekBody_schedule"
30+
:style="schedule.style"
31+
/>
2532
<!-- 顯示預約事件 -->
2633
<div
2734
v-for="order in weekDayOrders(d-1)"
@@ -49,6 +56,7 @@ export default {
4956
current: { type: Date, required: true },
5057
today: { type: Object, required: true },
5158
orders: { type: Array, required: true },
59+
schedules: { type: Array, required: true },
5260
daysOfWeek: { type: Array, required: true },
5361
use12Hour: { type: Boolean, default: true }
5462
},
@@ -100,6 +108,37 @@ export default {
100108
})
101109
}
102110
},
111+
// 處理當日排班的樣式
112+
schedulesWithStyle () {
113+
const { schedules } = this
114+
const oneDay = 24 * 60 * 60
115+
const HeightPerHour = 70
116+
117+
return schedules
118+
.map(schedule => {
119+
const { from, to } = schedule.online
120+
const height = (to - from) * HeightPerHour / (60 * 60 * 1000)
121+
const totalSec = from.getSeconds() + 60 * from.getMinutes() + 60 * 60 * from.getHours()
122+
const top = (totalSec % oneDay) * HeightPerHour * 24 / oneDay
123+
return {
124+
...schedule,
125+
style: {
126+
height: height + 'px',
127+
top: top + 'px'
128+
}
129+
}
130+
})
131+
},
132+
// 取得當日的排班
133+
weekDaySchedules () {
134+
const { schedulesWithStyle, daysOfWeek } = this
135+
return (d) => {
136+
const day = daysOfWeek[d]
137+
return schedulesWithStyle.filter(order => {
138+
return order.online.from.getDay() === day.weekDay
139+
})
140+
}
141+
},
103142
isToday () {
104143
const { today, daysOfWeek } = this
105144
return d => {
@@ -117,7 +156,7 @@ $border: #d4d5d6;
117156
$pinColor: #757575;
118157
$orderBg: #e5e5e5;
119158
$orderBg: rgba(229, 229, 229, 0.7);
120-
159+
$scheduleBg: rgba(246, 246, 246, 0.5);
121160
.weekBody {
122161
height: 100%;
123162
overflow: auto;
@@ -164,6 +203,19 @@ $orderBg: rgba(229, 229, 229, 0.7);
164203
&_order_name {
165204
font-weight: 550;
166205
}
206+
&_schedule {
207+
position: absolute;
208+
background-color: $scheduleBg;
209+
width: 100%;
210+
z-index: 1;
211+
text-align: left;
212+
padding: 0.5rem;
213+
font-size: 0.8rem;
214+
cursor: pointer;
215+
overflow: hidden;
216+
text-overflow: ellipsis;
217+
word-wrap: break-word;
218+
}
167219
.pin {
168220
width: 100%;
169221
height: 1px;

src/components/Week/index.vue

+28
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
:today="today"
2323
:orders="filtOrders"
2424
:days-of-week="daysOfWeek"
25+
:schedules="filtSchedules"
2526
/>
2627
<DayBody
2728
v-if="bodyComponent === 'DayBody'"
2829
key="DayBody"
2930
:current="current"
3031
:calendar="observeCanlendar"
3132
:orders="filtSingleDateOrders"
33+
:schedules="filtSingleDateSchedules"
3234
/>
3335
</transition-group>
3436
<transition name="fade">
@@ -250,6 +252,32 @@ export default {
250252
const orderDate = order.reserve.from
251253
return orderDate > singleDateStart && orderDate < singleDateEnd
252254
})
255+
},
256+
// 過濾當週排班
257+
filtSchedules () {
258+
const { firstDateOfWeek, lastDateOfWeek } = this
259+
const first = new Date(firstDateOfWeek.year, firstDateOfWeek.month, firstDateOfWeek.date)
260+
const last = new Date(lastDateOfWeek.year, lastDateOfWeek.month, lastDateOfWeek.date)
261+
262+
const { schedules } = this
263+
return schedules
264+
.filter(schedule => {
265+
const scheduleDate = schedule.online.from
266+
return scheduleDate > first && scheduleDate < last
267+
})
268+
},
269+
// 過濾當日排班
270+
filtSingleDateSchedules () {
271+
const { year, month, date } = this.observeCanlendar
272+
const singleDateStart = new Date(year, month, date)
273+
const singleDateEnd = new Date(year, month, date + 1)
274+
275+
const { schedules } = this
276+
return schedules
277+
.filter(schedule => {
278+
const scheduleDate = schedule.online.from
279+
return scheduleDate > singleDateStart && scheduleDate < singleDateEnd
280+
})
253281
}
254282
},
255283
created () {

src/pages/OhBot/OhBot.scss

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ $secondary: #dedaf4;
5858
font-size: 0.8rem;
5959
}
6060
}
61+
&_switch_btn {
62+
border-radius: 50%;
63+
}
6164
&_body {
6265
height: 100%;
6366
}
@@ -67,7 +70,7 @@ $secondary: #dedaf4;
6770
width: 100%;
6871
height: 4.2rem;
6972
padding-top: 1rem;
70-
background-image: linear-gradient(to bottom, rgba(255,255,255, 0) 0%, #f2f2f2 100%);
73+
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, #f2f2f2 100%);
7174
z-index: 1;
7275
> button {
7376
width: 9rem;

src/pages/OhBot/index.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<b-dropdown
2727
:text="mode+'檢視'"
2828
class="mr-3"
29+
toggle-class="text-primary rounded-pill"
2930
>
3031
<b-dropdown-item @click="setMode('週')">
3132
@@ -36,7 +37,7 @@
3637
</b-dropdown>
3738
<b-dropdown
3839
text="測試"
39-
pill
40+
toggle-class="text-primary rounded-pill"
4041
>
4142
<b-dropdown-item>測試</b-dropdown-item>
4243
</b-dropdown>
@@ -87,7 +88,7 @@ export default {
8788
user: '王大美',
8889
reserve: {
8990
from: new Date(2021, 3, 1, 15, 30),
90-
to: new Date(2021, 3, 1, 19, 30)
91+
to: new Date(2021, 3, 1, 16, 30)
9192
}
9293
},
9394
{

0 commit comments

Comments
 (0)