更新商机更新时间的显示效果

This commit is contained in:
weipengfei 2023-08-10 16:34:15 +08:00
parent 8776f8e1fb
commit effded7ac0
3 changed files with 51 additions and 3 deletions

View File

@ -256,6 +256,11 @@
let arr = oaHomeData.filter(item => !item.captain); //
this.oaHomeData = arr;
}
if(this.$store.state.app.userInfo?.company?.company_type_name=='平台公司'){
this.oaHomeData = this.oaHomeData.filter(item => {
return item.text=='人员管理'?false:true;
})
}
//
if (this.oaHomeData >= 8) {
this.oaHomeData[7] = this.oaHomeData[this.oaHomeData.length - 1];

View File

@ -79,7 +79,8 @@
<view v-show="current==1">
<block v-for="(item, index) in formData.datas" :key="'demand'+index+item.id">
<view class="update_time">
更新时间:{{item.update_time}}
<view>更新时间:{{item.update_time}}</view>
<view class="right">{{updateTo(item.update_time)}}</view>
</view>
<block>
<breeding v-if="item.id==32" ref="demandRef32" :datas="item.datas" :readonly="true"></breeding>
@ -112,6 +113,7 @@
import { Toast } from "../../libs/uniApi"
import { informationAdd, informationDetails } from "@/api/information.js"
import { comonentList } from '@/static/server/archives.js'
import { getTimeAgo } from "@/utils/time.js"
import districtSelector from "@/components/districtSelector/districtSelector.vue" //
import residents from "@/components/newArchives/residents.vue" //
import breeding from "@/components/newArchives/breeding.vue" //
@ -214,6 +216,9 @@
},
changeCurrent(e) {
this.current = e.index;
},
updateTo(time){
return getTimeAgo(time)
}
},
onPullDownRefresh() {
@ -247,8 +252,12 @@
}
.update_time {
padding-left: 28rpx;
padding-top: 28rpx;
padding: 32rpx 28rpx 0 28rpx;
display: flex;
justify-content: space-between;
.right{
color: $theme-oa-color;
}
}
.card {

34
utils/time.js Normal file
View File

@ -0,0 +1,34 @@
// 格式化:50分钟前,1小时前.20天前
export const getTimeAgo = (timestamp) => {
const now = Date.now();
const diff = now - new Date(timestamp);
// 计算时间差的毫秒数
const milliseconds = Math.abs(diff);
// 定义时间单位与对应的毫秒数
const timeUnits = [
{ unit: '年', ms: 1000 * 60 * 60 * 24 * 365 },
{ unit: '个月', ms: 1000 * 60 * 60 * 24 * 30 },
{ unit: '周', ms: 1000 * 60 * 60 * 24 * 7 },
{ unit: '天', ms: 1000 * 60 * 60 * 24 },
{ unit: '小时', ms: 1000 * 60 * 60 },
{ unit: '分钟', ms: 1000 * 60 },
];
let str = ''
// 循环遍历时间单位,并计算时间差所对应的单位
for (let i = 0; i < timeUnits.length; i++) {
const { unit, ms } = timeUnits[i];
if (milliseconds >= ms) {
const count = Math.floor(milliseconds / ms);
str = `${count}${unit}`;
break;
}
}
// 如果时间差过小,可以自定义返回结果
return str||'刚刚';
}