Commit b8509c593a7ab3a04c5ed926e2ad825fd4c4f311
1 parent
7f9ea0dc
update Time
Showing
1 changed file
with
56 additions
and
2 deletions
Show diff stats
src/components/time/time.vue
| 1 | <template> | 1 | <template> |
| 2 | - <span>time</span> | 2 | + <span :class="classes" @click="handleClick">time</span> |
| 3 | </template> | 3 | </template> |
| 4 | <script> | 4 | <script> |
| 5 | - export default { | 5 | + import { oneOf } from '../../utils/assist'; |
| 6 | + | ||
| 7 | + const prefixCls = 'ivu-time'; | ||
| 6 | 8 | ||
| 9 | + export default { | ||
| 10 | + name: 'Time', | ||
| 11 | + props: { | ||
| 12 | + time: { | ||
| 13 | + type: [String, Number, Date], | ||
| 14 | + required: true | ||
| 15 | + }, | ||
| 16 | + type: { | ||
| 17 | + type: String, | ||
| 18 | + validator (value) { | ||
| 19 | + return oneOf(value, ['relative', 'date', 'datetime']); | ||
| 20 | + }, | ||
| 21 | + default: 'relative' | ||
| 22 | + }, | ||
| 23 | + hash: { | ||
| 24 | + type: String, | ||
| 25 | + default: '' | ||
| 26 | + }, | ||
| 27 | + interval: { | ||
| 28 | + type: Number, | ||
| 29 | + default: 60 | ||
| 30 | + } | ||
| 31 | + }, | ||
| 32 | + data () { | ||
| 33 | + return { | ||
| 34 | + date: '' | ||
| 35 | + }; | ||
| 36 | + }, | ||
| 37 | + computed: { | ||
| 38 | + classes () { | ||
| 39 | + return [ | ||
| 40 | + `${prefixCls}`, | ||
| 41 | + { | ||
| 42 | + [`${prefixCls}-with-hash`]: this.hash | ||
| 43 | + } | ||
| 44 | + ]; | ||
| 45 | + } | ||
| 46 | + }, | ||
| 47 | + methods: { | ||
| 48 | + handleClick () { | ||
| 49 | + if (this.hash !== '') window.location.hash = this.hash; | ||
| 50 | + } | ||
| 51 | + }, | ||
| 52 | + mounted () { | ||
| 53 | + this.setTime(); | ||
| 54 | + this.timer = setInterval(() => { | ||
| 55 | + this.setTime(); | ||
| 56 | + }, 1000 * this.interval); | ||
| 57 | + }, | ||
| 58 | + beforeDestroy () { | ||
| 59 | + if (this.timer) clearInterval(this.timer); | ||
| 60 | + } | ||
| 7 | }; | 61 | }; |
| 8 | </script> | 62 | </script> |
| 9 | \ No newline at end of file | 63 | \ No newline at end of file |