|
|
@@ -30,15 +30,15 @@
|
|
|
/>
|
|
|
</el-select>
|
|
|
<el-date-picker
|
|
|
- v-model="deviceOptions.params.time"
|
|
|
+ v-model="timestamp"
|
|
|
class="l-flex__none c-sibling-item u-pointer"
|
|
|
type="date"
|
|
|
placeholder="选择日期"
|
|
|
- value-format="yyyy-MM-dd"
|
|
|
+ value-format="timestamp"
|
|
|
:picker-options="pickerOptions"
|
|
|
:editable="false"
|
|
|
:clearable="false"
|
|
|
- @change="search"
|
|
|
+ @change="onTimeChange"
|
|
|
/>
|
|
|
<search-input
|
|
|
v-model.trim="deviceOptions.params.name"
|
|
|
@@ -97,13 +97,13 @@
|
|
|
<el-link
|
|
|
class="u-pointer"
|
|
|
type="warning"
|
|
|
- @click.stop="getPrograms(item)"
|
|
|
+ @click.stop="getTimeline(item)"
|
|
|
>
|
|
|
出错了,点击重试
|
|
|
</el-link>
|
|
|
</div>
|
|
|
</template>
|
|
|
- <template v-else>
|
|
|
+ <template v-else-if="item.options.list.length">
|
|
|
<div
|
|
|
v-for="(target, index) in item.options.list"
|
|
|
:key="index"
|
|
|
@@ -115,12 +115,28 @@
|
|
|
<template v-if="target.id">
|
|
|
<i class="l-flex__none c-program__img o-program" />
|
|
|
<div class="l-flex__auto">
|
|
|
- <div class="c-program__time u-ellipsis">{{ target.time }}</div>
|
|
|
- <div class="c-program__name u-ellipsis">{{ target.name }}</div>
|
|
|
+ <auto-text
|
|
|
+ class="c-program__time"
|
|
|
+ :text="target.time"
|
|
|
+ :tag="target.style.width"
|
|
|
+ />
|
|
|
+ <auto-text
|
|
|
+ class="c-program__name"
|
|
|
+ :text="target.name"
|
|
|
+ :tag="target.style.width"
|
|
|
+ />
|
|
|
+ <!-- <div class="c-program__time u-ellipsis">{{ target.time }}</div>
|
|
|
+ <div class="c-program__name u-ellipsis">{{ target.name }}</div> -->
|
|
|
</div>
|
|
|
</template>
|
|
|
</div>
|
|
|
</template>
|
|
|
+ <div
|
|
|
+ v-else
|
|
|
+ class="has-padding--h"
|
|
|
+ >
|
|
|
+ 当前时段暂无节目
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div
|
|
|
@@ -154,14 +170,17 @@ import {
|
|
|
getProducts,
|
|
|
getDevices
|
|
|
} from '@/api/device'
|
|
|
+import { getTimeline } from '@/api/calendar'
|
|
|
import {
|
|
|
createListOptions,
|
|
|
parseTime
|
|
|
} from '@/utils'
|
|
|
+import AutoText from '@/components/AutoText'
|
|
|
|
|
|
export default {
|
|
|
name: 'ScheduleTimeline',
|
|
|
components: {
|
|
|
+ AutoText
|
|
|
},
|
|
|
data () {
|
|
|
return {
|
|
|
@@ -173,7 +192,6 @@ export default {
|
|
|
firstLoadSize: 999,
|
|
|
deviceOptions: createListOptions({
|
|
|
productId: '',
|
|
|
- time: parseTime(new Date(), '{y}-{m}-{d}'),
|
|
|
name: '',
|
|
|
pageSize: 4
|
|
|
}),
|
|
|
@@ -184,6 +202,7 @@ export default {
|
|
|
canPresent: false,
|
|
|
canNext: false
|
|
|
},
|
|
|
+ timestamp: 0,
|
|
|
device: null,
|
|
|
program: null
|
|
|
}
|
|
|
@@ -216,7 +235,7 @@ export default {
|
|
|
},
|
|
|
created () {
|
|
|
this.$timer = -1
|
|
|
- this.initTimes(new Date())
|
|
|
+ this.initTimes(new Date(parseTime(new Date(), '{y}/{m}/{d}')).getTime())
|
|
|
this.getProducts()
|
|
|
this.getDevices()
|
|
|
},
|
|
|
@@ -230,17 +249,16 @@ export default {
|
|
|
const max = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 30)
|
|
|
return date < min || date > max
|
|
|
},
|
|
|
- initTimes (date) {
|
|
|
- this.$date = date
|
|
|
- if (parseTime(new Date(), '{y}-{m}-{d}') === parseTime(date, '{y}-{m}-{d}')) {
|
|
|
+ initTimes (timestamp) {
|
|
|
+ this.timestamp = timestamp
|
|
|
+ if (parseTime(new Date(), '{y}-{m}-{d}') === parseTime(timestamp, '{y}-{m}-{d}')) {
|
|
|
this.controlOptions.start = Math.min(20, new Date().getHours())
|
|
|
} else {
|
|
|
this.controlOptions.start = 0
|
|
|
}
|
|
|
- this._createTimes()
|
|
|
- this._checkTime()
|
|
|
+ this._refreshTimes()
|
|
|
},
|
|
|
- _createTimes () {
|
|
|
+ _refreshTimes () {
|
|
|
const start = this.controlOptions.start
|
|
|
const times = []
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
@@ -249,8 +267,11 @@ export default {
|
|
|
this.controlOptions.times = times
|
|
|
this.controlOptions.canPresent = start > 0
|
|
|
this.controlOptions.canNext = start < 20
|
|
|
- this.$startDateTime = new Date(this.$date.getFullYear(), this.$date.getMonth(), this.$date.getDate(), start)
|
|
|
- this.$endDateTime = new Date(this.$date.getFullYear(), this.$date.getMonth(), this.$date.getDate(), start + 4)
|
|
|
+ this.$startDateTime = this.timestamp + start * 3600000
|
|
|
+ this.$endDateTime = this.timestamp + (start + 4) * 3600000
|
|
|
+
|
|
|
+ this._calc()
|
|
|
+ this.$timer = setInterval(this._calc, 1000)
|
|
|
},
|
|
|
_calc () {
|
|
|
const now = Date.now()
|
|
|
@@ -262,21 +283,18 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- offsetTime (offset) {
|
|
|
- this.controlOptions.start += offset
|
|
|
- this._createTimes()
|
|
|
- this._checkTime()
|
|
|
+ _refreshTimeline () {
|
|
|
this.deviceOptions.list.forEach(device => {
|
|
|
this._calcPrograms(device.options)
|
|
|
})
|
|
|
- if (this.programId && (this.program.startDateTime >= this.$endDateTime || this.program.endDateTime <= this.$startDateTime)) {
|
|
|
+ if (this.programId && (this.program.startDateTime >= this.$endDateTime || this.program.endDateTime && this.program.endDateTime <= this.$startDateTime)) {
|
|
|
this.program = null
|
|
|
}
|
|
|
},
|
|
|
- _checkTime () {
|
|
|
- clearInterval(this.$timer)
|
|
|
- this._calc()
|
|
|
- this.$timer = setInterval(this._calc, 1000)
|
|
|
+ offsetTime (offset) {
|
|
|
+ this.controlOptions.start += offset
|
|
|
+ this._refreshTimes()
|
|
|
+ this._refreshTimeline()
|
|
|
},
|
|
|
_getProducts () {
|
|
|
this.fetching = true
|
|
|
@@ -328,7 +346,7 @@ export default {
|
|
|
getDevices(options.params).then(({ data, totalCount }) => {
|
|
|
options.list = data.map(this.transform)
|
|
|
options.totalCount = totalCount
|
|
|
- options.list.forEach(this.getPrograms)
|
|
|
+ options.list.forEach(this.getTimeline)
|
|
|
}, () => {
|
|
|
options.error = true
|
|
|
options.list = []
|
|
|
@@ -336,40 +354,29 @@ export default {
|
|
|
options.loading = false
|
|
|
})
|
|
|
},
|
|
|
- getPrograms (device) {
|
|
|
+ getTimeline (device) {
|
|
|
const options = device.options
|
|
|
options.error = false
|
|
|
options.loading = true
|
|
|
- new Promise((resolve, reject) => {
|
|
|
- Math.random() > 0.7 ? reject() : setTimeout(() => resolve({
|
|
|
- data: this.createPrograms()
|
|
|
- }), 2000)
|
|
|
- }).finally(() => {
|
|
|
+ getTimeline(device.id).finally(() => {
|
|
|
options.loading = false
|
|
|
}).then(({ data }) => {
|
|
|
- options.programs = data
|
|
|
+ options.programs = (JSON.parse(data.eventDetail) || []).map(this.createProgram)
|
|
|
this._calcPrograms(options)
|
|
|
}, () => {
|
|
|
options.error = true
|
|
|
options.list = []
|
|
|
})
|
|
|
},
|
|
|
- createPrograms () {
|
|
|
- const programs = []
|
|
|
- let startDateTime = new Date(Date.now() + ((0.5 - Math.random()) * 30 | 0) * 60000)
|
|
|
- let endDateTime
|
|
|
- for (let i = 0; i < 4; i++) {
|
|
|
- endDateTime = new Date(startDateTime.getTime() + (30 + Math.random() * 180 | 0) * 60000)
|
|
|
- programs.push({
|
|
|
- id: Math.random().toString().slice(2),
|
|
|
- name: startDateTime,
|
|
|
- time: `${parseTime(startDateTime, '{h}:{i}')}-${parseTime(endDateTime, '{h}:{i}')}`,
|
|
|
- startDateTime,
|
|
|
- endDateTime
|
|
|
- })
|
|
|
- startDateTime = new Date(endDateTime.getTime() + (Math.random() * 60 | 0) * 60000)
|
|
|
+ createProgram ({ programCalendarId, type, startTimestamp, endTimestamp }) {
|
|
|
+ const startDateTime = new Date(Number(startTimestamp))
|
|
|
+ const endDateTime = endTimestamp ? new Date(Number(endTimestamp)) : null
|
|
|
+ return {
|
|
|
+ type, startDateTime, endDateTime,
|
|
|
+ id: programCalendarId || Math.random(),
|
|
|
+ name: `${parseTime(startDateTime, '{h}:{i}:{s}')}-${endDateTime ? parseTime(endDateTime, '{h}:{i}:{s}') : ''}`,
|
|
|
+ time: `${parseTime(startDateTime, '{y}.{m}.{d} {h}:{i}:{s}')} - ${endDateTime ? parseTime(endDateTime, '{y}.{m}.{d} {h}:{i}:{s}') : '未知'}`
|
|
|
}
|
|
|
- return programs
|
|
|
},
|
|
|
_calcPrograms (options) {
|
|
|
if (options.loading || options.error) {
|
|
|
@@ -382,33 +389,43 @@ export default {
|
|
|
let comparison = this.$startDateTime
|
|
|
let i = 0
|
|
|
while (remaining && i < programs.length) {
|
|
|
- const { startDateTime, endDateTime } = programs[i]
|
|
|
- if (startDateTime >= this.$endDateTime) {
|
|
|
- break
|
|
|
+ const program = programs[i]
|
|
|
+ const { startDateTime, endDateTime } = program
|
|
|
+ i += 1
|
|
|
+ if (startDateTime >= this.$endDateTime || endDateTime && endDateTime <= this.$startDateTime) {
|
|
|
+ continue
|
|
|
}
|
|
|
- if (endDateTime > this.$startDateTime) {
|
|
|
- if (startDateTime > comparison) {
|
|
|
- arr.push({
|
|
|
- style: { width: `${(startDateTime - comparison) / total}%` }
|
|
|
- })
|
|
|
- remaining -= startDateTime - comparison
|
|
|
- comparison = startDateTime
|
|
|
- }
|
|
|
- const duration = Math.min(remaining, endDateTime - comparison)
|
|
|
+ if (startDateTime > comparison) {
|
|
|
arr.push({
|
|
|
- ...programs[i],
|
|
|
- style: { width: `${duration / total}%` }
|
|
|
+ style: { width: `${(startDateTime - comparison) / total}%` }
|
|
|
})
|
|
|
- remaining -= duration
|
|
|
- comparison = endDateTime
|
|
|
+ remaining -= startDateTime - comparison
|
|
|
+ comparison = startDateTime
|
|
|
}
|
|
|
- i += 1
|
|
|
+ if (!endDateTime) {
|
|
|
+ arr.push({
|
|
|
+ ...program,
|
|
|
+ style: { width: `${remaining / total}%` }
|
|
|
+ })
|
|
|
+ break
|
|
|
+ }
|
|
|
+ const duration = Math.min(remaining, endDateTime - comparison)
|
|
|
+ arr.push({
|
|
|
+ ...program,
|
|
|
+ style: { width: `${duration / total}%` }
|
|
|
+ })
|
|
|
+ remaining -= duration
|
|
|
+ comparison = endDateTime
|
|
|
}
|
|
|
options.list = arr
|
|
|
},
|
|
|
chooseProgram (device, program) {
|
|
|
this.device = device
|
|
|
this.program = program
|
|
|
+ },
|
|
|
+ onTimeChange (val) {
|
|
|
+ this.initTimes(val)
|
|
|
+ this._refreshTimeline()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -474,7 +491,7 @@ export default {
|
|
|
}
|
|
|
|
|
|
&__row.selected &__left::after {
|
|
|
- content: '';
|
|
|
+ content: "";
|
|
|
position: absolute;
|
|
|
top: 0;
|
|
|
left: 0;
|
|
|
@@ -529,7 +546,6 @@ export default {
|
|
|
right: 0;
|
|
|
bottom: 0;
|
|
|
pointer-events: none;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
&__mask {
|
|
|
@@ -539,10 +555,14 @@ export default {
|
|
|
bottom: 0;
|
|
|
color: #e51414;
|
|
|
border-right: 1px solid currentColor;
|
|
|
- background-image: linear-gradient(-90deg, rgba(#ff8a8a, .33) 0%, rgba(#fff, 0) 100%);
|
|
|
+ background-image: linear-gradient(
|
|
|
+ -90deg,
|
|
|
+ rgba(#ff8a8a, 0.33) 0%,
|
|
|
+ rgba(#fff, 0) 100%
|
|
|
+ );
|
|
|
|
|
|
&::after {
|
|
|
- content: '';
|
|
|
+ content: "";
|
|
|
position: absolute;
|
|
|
top: 0;
|
|
|
right: -5px;
|
|
|
@@ -583,6 +603,6 @@ export default {
|
|
|
}
|
|
|
|
|
|
.o-program {
|
|
|
- background: url('~@/assets/program_bg.png') 0 0 / 100% 100% no-repeat;
|
|
|
+ background: url("~@/assets/program_bg.png") 0 0 / 100% 100% no-repeat;
|
|
|
}
|
|
|
</style>
|