Skip to content

Commit

Permalink
优化部分相同代码
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Jan 7, 2022
1 parent 8ec1578 commit 9d007e6
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 230 deletions.
67 changes: 67 additions & 0 deletions resources/assets/js/functions/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,73 @@
}
},

/**
* 格式化时间
* @param date
* @returns {*|string}
*/
formatTime(date) {
let time = Math.round($A.Date(date).getTime() / 1000),
string = '';
if ($A.formatDate('Ymd') === $A.formatDate('Ymd', time)) {
string = $A.formatDate('H:i', time)
} else if ($A.formatDate('Y') === $A.formatDate('Y', time)) {
string = $A.formatDate('m-d', time)
} else {
string = $A.formatDate('Y-m-d', time)
}
return string || '';
},

/**
* 小于9补0
* @param val
* @returns {number|string}
*/
formatBit(val) {
val = +val
return val > 9 ? val : '0' + val
},

/**
* 秒转时间
* @param second
* @returns {string}
*/
formatSeconds(second) {
let duration
let days = Math.floor(second / 86400);
let hours = Math.floor((second % 86400) / 3600);
let minutes = Math.floor(((second % 86400) % 3600) / 60);
let seconds = Math.floor(((second % 86400) % 3600) % 60);
if (days > 0) {
if (hours > 0) duration = days + "d," + this.formatBit(hours) + "h";
else if (minutes > 0) duration = days + "d," + this.formatBit(minutes) + "min";
else if (seconds > 0) duration = days + "d," + this.formatBit(seconds) + "s";
else duration = days + "d";
}
else if (hours > 0) duration = this.formatBit(hours) + ":" + this.formatBit(minutes) + ":" + this.formatBit(seconds);
else if (minutes > 0) duration = this.formatBit(minutes) + ":" + this.formatBit(seconds);
else if (seconds > 0) duration = this.formatBit(seconds) + "s";
return duration;
},

/**
* 倒计时格式
* @param date
* @param nowTime
* @returns {string|*}
*/
countDownFormat(date, nowTime) {
let time = Math.round(this.Date(date).getTime() / 1000) - nowTime;
if (time < 86400 * 7 && time > 0 ) {
return this.formatSeconds(time);
} else if (time <= 0) {
return '-' + this.formatSeconds(time * -1);
}
return this.formatTime(date)
},

/**
* 获取一些指定时间
* @param str
Expand Down
2 changes: 1 addition & 1 deletion resources/assets/js/pages/manage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@on-visible-change="menuVisibleChange">
<div :class="['manage-box-title', visibleMenu ? 'menu-visible' : '']">
<div class="manage-box-avatar">
<UserAvatar :userid="userId" :size="36" tooltip-disabled/>
<UserAvatar :userid="userId" :size="36" tooltipDisabled/>
</div>
<span>{{userInfo.nickname}}</span>
<div class="manage-box-arrow">
Expand Down
19 changes: 3 additions & 16 deletions resources/assets/js/pages/manage/components/DialogView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<!--时间/阅读-->
<div v-if="msgData.created_at" class="dialog-foot">
<div class="time">{{formatTime(msgData.created_at)}}</div>
<div class="time">{{$A.formatTime(msgData.created_at)}}</div>
<Poptip
v-if="msgData.send > 1 || dialogType == 'group'"
class="percent"
Expand All @@ -35,11 +35,11 @@
<div slot="content" class="dialog-wrapper-read-poptip-content">
<ul class="read">
<li class="read-title"><em>{{readList.length}}</em>{{$L('已读')}}</li>
<li v-for="item in readList"><UserAvatar :userid="item.userid" :size="26" show-name/></li>
<li v-for="item in readList"><UserAvatar :userid="item.userid" :size="26" showName/></li>
</ul>
<ul class="unread">
<li class="read-title"><em>{{unreadList.length}}</em>{{$L('未读')}}</li>
<li v-for="item in unreadList"><UserAvatar :userid="item.userid" :size="26" show-name/></li>
<li v-for="item in unreadList"><UserAvatar :userid="item.userid" :size="26" showName/></li>
</ul>
</div>
<WCircle :percent="msgData.percentage" :size="14"/>
Expand Down Expand Up @@ -129,19 +129,6 @@ export default {
});
},
formatTime(date) {
let time = Math.round($A.Date(date).getTime() / 1000),
string = '';
if ($A.formatDate('Ymd') === $A.formatDate('Ymd', time)) {
string = $A.formatDate('H:i', time)
} else if ($A.formatDate('Y') === $A.formatDate('Y', time)) {
string = $A.formatDate('m-d', time)
} else {
string = $A.formatDate('Y-m-d', time)
}
return string || '';
},
textMsg(text) {
if (!text) {
return ""
Expand Down
17 changes: 2 additions & 15 deletions resources/assets/js/pages/manage/components/DialogWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
:class="{self:item.userid == userId, 'history-tip': topId == item.id}">
<em v-if="topId == item.id" class="history-text">{{$L('历史消息')}}</em>
<div class="dialog-avatar">
<UserAvatar :userid="item.userid" :tooltip-disabled="item.userid == userId" :size="30"/>
<UserAvatar :userid="item.userid" :tooltipDisabled="item.userid == userId" :size="30"/>
</div>
<DialogView :msg-data="item" :dialog-type="dialogData.type"/>
</li>
Expand All @@ -49,7 +49,7 @@
:key="'tmp_' + item.id"
:class="{self:item.userid == userId}">
<div class="dialog-avatar">
<UserAvatar :userid="item.userid" :tooltip-disabled="item.userid == userId" :size="30"/>
<UserAvatar :userid="item.userid" :tooltipDisabled="item.userid == userId" :size="30"/>
</div>
<DialogView :msg-data="item" :dialog-type="dialogData.type"/>
</li>
Expand Down Expand Up @@ -358,19 +358,6 @@ export default {
this.$emit("on-active");
},
formatTime(date) {
let time = Math.round($A.Date(date).getTime() / 1000),
string = '';
if ($A.formatDate('Ymd') === $A.formatDate('Ymd', time)) {
string = $A.formatDate('H:i', time)
} else if ($A.formatDate('Y') === $A.formatDate('Y', time)) {
string = $A.formatDate('m-d', time)
} else {
string = $A.formatDate('Y-m-d', time)
}
return string || '';
},
openProject() {
if (!this.dialogData.group_info) {
return;
Expand Down
46 changes: 2 additions & 44 deletions resources/assets/js/pages/manage/components/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1298,51 +1298,9 @@ export default {
this.tempShowTasks = [];
},
formatTime(date) {
let time = Math.round($A.Date(date).getTime() / 1000),
string = '';
if ($A.formatDate('Ymd') === $A.formatDate('Ymd', time)) {
string = $A.formatDate('H:i', time)
} else if ($A.formatDate('Y') === $A.formatDate('Y', time)) {
string = $A.formatDate('m-d', time)
} else {
string = $A.formatDate('Y-m-d', time)
}
return string || '';
},
formatBit(val) {
val = +val
return val > 9 ? val : '0' + val
},
formatSeconds(second) {
let duration
let days = Math.floor(second / 86400);
let hours = Math.floor((second % 86400) / 3600);
let minutes = Math.floor(((second % 86400) % 3600) / 60);
let seconds = Math.floor(((second % 86400) % 3600) % 60);
if (days > 0) {
if (hours > 0) duration = days + "d," + this.formatBit(hours) + "h";
else if (minutes > 0) duration = days + "d," + this.formatBit(minutes) + "min";
else if (seconds > 0) duration = days + "d," + this.formatBit(seconds) + "s";
else duration = days + "d";
}
else if (hours > 0) duration = this.formatBit(hours) + ":" + this.formatBit(minutes) + ":" + this.formatBit(seconds);
else if (minutes > 0) duration = this.formatBit(minutes) + ":" + this.formatBit(seconds);
else if (seconds > 0) duration = this.formatBit(seconds) + "s";
return duration;
},
expiresFormat(date) {
let time = Math.round($A.Date(date).getTime() / 1000) - this.nowTime;
if (time < 86400 * 7 && time > 0 ) {
return this.formatSeconds(time);
} else if (time <= 0) {
return '-' + this.formatSeconds(time * -1);
}
return this.formatTime(date)
}
return $A.countDownFormat(date, this.nowTime)
},
}
}
</script>
6 changes: 3 additions & 3 deletions resources/assets/js/pages/manage/components/TaskAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,21 @@ export default {
text: this.$L('3天'),
value() {
let e = new Date();
e.setDate(e.getDate() + 3);
e.setDate(e.getDate() + 2);
return [new Date(), lastSecond(e.getTime())];
}
}, {
text: this.$L('5天'),
value() {
let e = new Date();
e.setDate(e.getDate() + 5);
e.setDate(e.getDate() + 4);
return [new Date(), lastSecond(e.getTime())];
}
}, {
text: this.$L('7天'),
value() {
let e = new Date();
e.setDate(e.getDate() + 7);
e.setDate(e.getDate() + 6);
return [new Date(), lastSecond(e.getTime())];
}
}]
Expand Down
56 changes: 7 additions & 49 deletions resources/assets/js/pages/manage/components/TaskDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
</div>
</div>
<template v-if="getOwner.length > 0">
<UserAvatar v-for="item in getOwner" :key="item.userid" :userid="item.userid" :size="20" tooltip-disabled/>
<UserAvatar v-for="item in getOwner" :key="item.userid" :userid="item.userid" :size="20" tooltipDisabled/>
</template>
<div v-else>--</div>
</Poptip>
Expand Down Expand Up @@ -219,7 +219,7 @@
</div>
</div>
<div class="user-list">
<UserAvatar v-for="item in getOwner" :key="item.userid" :userid="item.userid" :size="28" :show-name="getOwner.length === 1" tooltip-disabled/>
<UserAvatar v-for="item in getOwner" :key="item.userid" :userid="item.userid" :size="28" :showName="getOwner.length === 1" tooltipDisabled/>
</div>
</Poptip>
</FormItem>
Expand Down Expand Up @@ -250,7 +250,7 @@
</div>
</div>
<div v-if="getAssist.length > 0" class="user-list">
<UserAvatar v-for="item in getAssist" :key="item.userid" :userid="item.userid" :size="28" :show-name="getAssist.length === 1"/>
<UserAvatar v-for="item in getAssist" :key="item.userid" :userid="item.userid" :size="28" :showName="getAssist.length === 1" tooltipDisabled/>
</div>
<div v-else>--</div>
</Poptip>
Expand Down Expand Up @@ -727,21 +727,21 @@ export default {
text: this.$L('3天'),
value() {
let e = new Date();
e.setDate(e.getDate() + 3);
e.setDate(e.getDate() + 2);
return [new Date(), lastSecond(e.getTime())];
}
}, {
text: this.$L('5天'),
value() {
let e = new Date();
e.setDate(e.getDate() + 5);
e.setDate(e.getDate() + 4);
return [new Date(), lastSecond(e.getTime())];
}
}, {
text: this.$L('7天'),
value() {
let e = new Date();
e.setDate(e.getDate() + 7);
e.setDate(e.getDate() + 6);
return [new Date(), lastSecond(e.getTime())];
}
}]
Expand All @@ -752,50 +752,8 @@ export default {
this.innerHeight = Math.min(1100, window.innerHeight);
},
formatTime(date) {
let time = Math.round($A.Date(date).getTime() / 1000),
string = '';
if ($A.formatDate('Ymd') === $A.formatDate('Ymd', time)) {
string = $A.formatDate('H:i', time)
} else if ($A.formatDate('Y') === $A.formatDate('Y', time)) {
string = $A.formatDate('m-d', time)
} else {
string = $A.formatDate('Y-m-d', time)
}
return string || '';
},
formatBit(val) {
val = +val
return val > 9 ? val : '0' + val
},
formatSeconds(second) {
let duration
let days = Math.floor(second / 86400);
let hours = Math.floor((second % 86400) / 3600);
let minutes = Math.floor(((second % 86400) % 3600) / 60);
let seconds = Math.floor(((second % 86400) % 3600) % 60);
if (days > 0) {
if (hours > 0) duration = days + "d," + this.formatBit(hours) + "h";
else if (minutes > 0) duration = days + "d," + this.formatBit(minutes) + "min";
else if (seconds > 0) duration = days + "d," + this.formatBit(seconds) + "s";
else duration = days + "d";
}
else if (hours > 0) duration = this.formatBit(hours) + ":" + this.formatBit(minutes) + ":" + this.formatBit(seconds);
else if (minutes > 0) duration = this.formatBit(minutes) + ":" + this.formatBit(seconds);
else if (seconds > 0) duration = this.formatBit(seconds) + "s";
return duration;
},
expiresFormat(date) {
let time = Math.round($A.Date(date).getTime() / 1000) - this.nowTime;
if (time < 86400 * 7 && time > 0 ) {
return this.formatSeconds(time);
} else if (time <= 0) {
return '-' + this.formatSeconds(time * -1);
}
return this.formatTime(date)
return $A.countDownFormat(date, this.nowTime)
},
onNameKeydown(e) {
Expand Down
44 changes: 1 addition & 43 deletions resources/assets/js/pages/manage/components/TaskRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,50 +262,8 @@ export default {
});
},
formatTime(date) {
let time = Math.round($A.Date(date).getTime() / 1000),
string = '';
if ($A.formatDate('Ymd') === $A.formatDate('Ymd', time)) {
string = $A.formatDate('H:i', time)
} else if ($A.formatDate('Y') === $A.formatDate('Y', time)) {
string = $A.formatDate('m-d', time)
} else {
string = $A.formatDate('Y-m-d', time)
}
return string || '';
},
formatBit(val) {
val = +val
return val > 9 ? val : '0' + val
},
formatSeconds(second) {
let duration
let days = Math.floor(second / 86400);
let hours = Math.floor((second % 86400) / 3600);
let minutes = Math.floor(((second % 86400) % 3600) / 60);
let seconds = Math.floor(((second % 86400) % 3600) % 60);
if (days > 0) {
if (hours > 0) duration = days + "d," + this.formatBit(hours) + "h";
else if (minutes > 0) duration = days + "d," + this.formatBit(minutes) + "min";
else if (seconds > 0) duration = days + "d," + this.formatBit(seconds) + "s";
else duration = days + "d";
}
else if (hours > 0) duration = this.formatBit(hours) + ":" + this.formatBit(minutes) + ":" + this.formatBit(seconds);
else if (minutes > 0) duration = this.formatBit(minutes) + ":" + this.formatBit(seconds);
else if (seconds > 0) duration = this.formatBit(seconds) + "s";
return duration;
},
expiresFormat(date) {
let time = Math.round($A.Date(date).getTime() / 1000) - this.nowTime;
if (time < 86400 * 7 && time > 0 ) {
return this.formatSeconds(time);
} else if (time <= 0) {
return '-' + this.formatSeconds(time * -1);
}
return this.formatTime(date)
return $A.countDownFormat(date, this.nowTime)
},
completeAtFormat(date) {
Expand Down
Loading

0 comments on commit 9d007e6

Please sign in to comment.