浏览代码

feat(core): 新增格式化时长函数并优化浏览时长显示

- 在 common.ts 中添加 formatDuration 函数,用于格式化时长
- 在 designer detail 页面中使用 formatDuration 函数格式化浏览时长
- 优化 case-shooting 和 wx-agent-operation 页面中产品价格的显示逻辑
EvilDragon 1 月之前
父节点
当前提交
df924bfc31

+ 15 - 0
packages/app/src/core/utils/common.ts

@@ -178,3 +178,18 @@ export const validate = (
   }
   return true
 }
+
+// 浏览时长 小于60秒,显示秒 大于60秒小于1小时,显示分钟 大于1小时小于1天,显示x小时x分钟 大于1天,显示x天x小时x分钟
+export const formatDuration = (duration: number) => {
+  if (duration < 60) {
+    return `${duration}秒`
+  } else if (duration < 3600) {
+    return `${Math.floor(duration / 60)}分钟`
+  } else if (duration < 86400) {
+    return `${Math.floor(duration / 3600)}小时${Math.floor((duration % 3600) / 60)}分钟`
+  } else {
+    return `${Math.floor(duration / 86400)}天${Math.floor((duration % 86400) / 3600)}小时${Math.floor(
+      (duration % 3600) / 60,
+    )}分钟`
+  }
+}

+ 1 - 1
packages/app/src/pages/home/spread/case-shooting/index.vue

@@ -63,7 +63,7 @@ onShareTimeline(() => ({
                 <div class="flex-1"></div>
                 <div
                   class="w-[53px] text-black/30 text-xs font-normal font-['PingFang_SC'] line-through leading-normal"
-                  v-if="it.productPrice"
+                  v-if="Number(data?.productPrice)"
                 >
                   ¥{{ it.productPrice }}
                 </div>

+ 1 - 0
packages/app/src/pages/home/spread/wx-agent-operation/index.vue

@@ -58,6 +58,7 @@ onShareTimeline(() => ({
               </div>
               <div class="flex-1"></div>
               <div
+                v-if="Number(data?.productPrice)"
                 class="w-[53px] text-black/30 text-xs font-normal font-['PingFang_SC'] line-through leading-normal"
               >
                 ¥{{it.productPrice}}

+ 17 - 2
packages/merchant/src/pages/agent/designer/detail.vue

@@ -36,6 +36,7 @@ import { useUserStore } from '@/store'
 import { storeToRefs } from 'pinia'
 import Card from '@designer-hub/app/src/components/card.vue'
 import ListHelperEvo from '@/components/list-helper-evo.vue'
+// import { formatDuration } from '@designer-hub/app/src/core/utils/common'
 
 const userStore = useUserStore()
 const { userInfo } = storeToRefs(userStore)
@@ -69,8 +70,9 @@ const browseRecordCountItems = computed(() => [
   {
     title: '浏览时长',
     subTitle: '本年',
-    value: browseRecordCount.value?.duration ?? 0,
-    subValue: browseRecordCount.value?.durationYear ?? 0,
+    // 浏览时长 小于60秒,显示秒 大于60秒小于1小时,显示分钟 大于1小时小于1天,显示x小时x分钟 大于1天,显示x天x小时x分钟
+    value: formatDuration(browseRecordCount.value?.duration ?? 0),
+    subValue: formatDuration(browseRecordCount.value?.durationYear ?? 0),
   },
   {
     title: '发圈次数',
@@ -113,6 +115,19 @@ const toOrderDetails = (it: any) => {
 const toArchives = () => {
   uni.navigateTo({ url: '/pages/agent/designer/archives/index?id=' + id.value })
 }
+const formatDuration = (duration: number) => {
+  if (duration < 60) {
+    return `${duration}秒`
+  } else if (duration < 3600) {
+    return `${Math.floor(duration / 60)}分钟`
+  } else if (duration < 86400) {
+    return `${Math.floor(duration / 3600)}小时${Math.floor((duration % 3600) / 60)}分钟`
+  } else {
+    return `${Math.floor(duration / 86400)}天${Math.floor((duration % 86400) / 3600)}小时${Math.floor(
+      (duration % 3600) / 60,
+    )}分钟`
+  }
+}
 onLoad(async (query) => {
   id.value = query?.id
   await setData()