cbma_expert/ce_app/pages/library/timeFrom/index.vue

63 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="u-demo">
<view class="u-demo-wrap">
<view class="u-demo-title">演示效果</view>
<view class="u-demo-area">
<u-toast ref="uToast"></u-toast>
<view class="u-no-demo-here" style="text-align: left;">
根据当前时间返回类似"刚刚5分钟前8小时前3天前"等字样
</view>
<view class="u-demo-result-line">
{{result}}
</view>
</view>
</view>
<view class="u-config-wrap">
<view class="u-config-title u-border-bottom">
参数配置
</view>
<view class="u-config-item">
<view class="u-item-title">时间</view>
<u-subsection vibrateShort :list="timeArr1" @change="timeArr1Change"></u-subsection>
<u-gap></u-gap>
<u-subsection vibrateShort style="margin-top: 40rpx;" :list="timeArr2" @change="timeArr2Change"></u-subsection>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
// 微信小程序无法动态修改u-subsection的list参数导致onLoad中赋值timeArr1timeArr2无效故在data中直接赋值
let nowTime = Number(+ new Date());
let threeDayAgo = nowTime - 2 * 86400000;
let arr1 = [0, 0], arr2 = [0, 0];
[0, 0].map((val, index) => {
arr1[index] = this.$u.timeFormat(this.$u.random(threeDayAgo, nowTime), 'yyyy/mm/dd hh:MM:ss');
arr2[index] = this.$u.timeFormat(this.$u.random(threeDayAgo, nowTime), 'yyyy/mm/dd hh:MM:ss');
})
return {
timeArr1: arr1,
timeArr2: arr2,
result: null
}
},
onLoad() {
this.timeArr1Change(0);
},
methods: {
timeArr1Change(index) {
this.result = this.$u.timeFrom((new Date(this.timeArr1[index])).getTime());
},
timeArr2Change(index) {
this.result = this.$u.timeFrom((new Date(this.timeArr2[index])).getTime());
}
}
}
</script>
<style lang="scss" scoped>
.u-demo {}
</style>