Ver Fonte

fix: 首页、搜索列表模块中格式化浏览量展示

wenxingxing há 16 horas atrás
pai
commit
15231a90d8
6 ficheiros alterados com 44 adições e 9 exclusões
  1. 2 1
      main.js
  2. 1 1
      pages/course/info.vue
  3. 2 2
      pages/index/course.vue
  4. 2 2
      pages/index/homePageSearch.vue
  5. 5 3
      pages/index/index.vue
  6. 32 0
      utils/common.js

+ 2 - 1
main.js

@@ -8,7 +8,7 @@ import uView from "@/node_modules/uview-ui";
 
 import {parseIDCardInfo,logout,checkCompanyUserLoginState,parseText,getDictLabelName,parseIdCard,getAge,parsePhone,isEmpty,getDict,
 isLogin,navBack,navTo,getUserInfo,formatHour,dateFormatStr,registerIdCode,updateMsgDot,handleBindCompanyFsUser,
-setSource,companyUserIsLogin,checkWechatInstalled,isIos,isAndroid,isAgreePrivacy,getDictLabel2Name,urlToObj,loginOut} from './utils/common.js'
+setSource,companyUserIsLogin,checkWechatInstalled,isIos,isAndroid,isAgreePrivacy,getDictLabel2Name,urlToObj,loginOut,formattedViewCount} from './utils/common.js'
 
 import { showLoginPage,getRegistrationID } from './utils/login.js'
 import { formatSeconds,formatDate } from './utils/tools.js'
@@ -26,6 +26,7 @@ App.mpType = 'app'
 Vue.use(Vuex)
 Vue.use(uView);
 Vue.prototype.$loginOut = loginOut;
+Vue.prototype.$formattedViewCount = formattedViewCount;
 Vue.prototype.$urlToObj = urlToObj;
 Vue.prototype.$getDict = getDict;
 Vue.prototype.$getDictLabel2Name = getDictLabel2Name;

+ 1 - 1
pages/course/info.vue

@@ -147,7 +147,7 @@
 				</view>
 				<view>
 					<view class="video-info-voicebox2">
-						<text class="boTextClass">{{ data.views }}次播放</text>
+						<text class="boTextClass">{{ $formattedViewCount(data.views) }}次播放</text>
 						<!-- 						<text>{{data.views}}次播放 · 总时长:{{data.totalDuration}}</text> -->
 						<view class="x-c" @click="isExpand = !isExpand" v-if="showExpandText">
 							<text>{{ isExpand ? '收起简介' : '展开简介' }}</text>

+ 2 - 2
pages/index/course.vue

@@ -41,7 +41,7 @@
 						<view class="x-end" style="justify-content: space-between;">
 							<view class="course-meta">
 								<image class="courseMetaIcon" src="@/static/images/new/renshu.png"></image>
-								<text class="meta-count">{{ course.watchUserCount }}</text>
+								<text class="meta-count">{{ $formattedViewCount(course.watchUserCount) }}</text>
 							</view>
 							<view class="btn-watch" @click.stop="onCourseClick(course)">立即观看</view>
 						</view>
@@ -102,7 +102,7 @@
 								<view class="x-end" style="justify-content: space-between;">
 									<view class="course-meta">
 										<image class="courseMetaIcon" src="@/static/images/new/renshu.png"></image>
-										<text class="meta-count">{{ course.watchUserCount }}</text>
+										<text class="meta-count">{{ $formattedViewCount(course.watchUserCount) }}</text>
 									</view>
 									<view class="btn-watch" @click.stop="onCourseClick(course)">立即观看</view>
 								</view>

+ 2 - 2
pages/index/homePageSearch.vue

@@ -48,7 +48,7 @@
 								<view class="x-end" style="justify-content: space-between;">
 									<view class="course-meta">
 										<image src="@/static/images/new/renshu.png"></image>
-										<text class="meta-count">{{ course.watchUserCount }}</text>
+										<text class="meta-count">{{ $formattedViewCount(course.watchUserCount) }}</text>
 									</view>
 									<view class="btn-watch" @click.stop="onCourseClick(course)">立即观看</view>
 								</view>
@@ -76,7 +76,7 @@
 							<view class="x-end" style="justify-content: space-between;">
 								<view class="course-meta">
 									<image src="@/static/images/new/renshu.png"></image>
-									<text class="meta-count">{{ course.watchUserCount }}</text>
+									<text class="meta-count">{{ $formattedViewCount(course.watchUserCount) }}</text>
 								</view>
 								<view class="btn-watch" @click.stop="onCourseClick(course)">立即观看</view>
 							</view>

+ 5 - 3
pages/index/index.vue

@@ -108,7 +108,7 @@
 							<view class="x-end" style="justify-content: space-between;">
 								<view class="course-meta">
 									<image src="@/static/images/new/renshu.png"></image>
-									<text class="meta-count">{{ course.watchUserCount }}</text>
+									<text class="meta-count">{{ $formattedViewCount(course.watchUserCount) }}</text>
 								</view>
 								<view class="btn-watch2" @click.stop="onWatchLive(course)">立即观看</view>
 							</view>
@@ -187,7 +187,8 @@ export default {
 				pageSize: 4,
 				isShow: 1,
 				cateType: 1,
-				yxxTag: 1
+				yxxTag: 1,
+				homePage: 1
 			};
 			const res = await courseTypeDataApi(params);
 			if (res.code === 200) {
@@ -207,7 +208,8 @@ export default {
 				pageSize: 10,
 				isShow: 1,
 				cateType: 1,
-				yxxTag: 0
+				yxxTag: 0,
+				homePage: 1
 			};
 			const res = await courseTypeDataApi(params);
 			if (res.code === 200) {

+ 32 - 0
utils/common.js

@@ -850,4 +850,36 @@ export function isAgreePrivacy(){
 	// #endif
 	
 	return true;
+}
+
+/**
+ * 格式化浏览量
+ * @param {Number} views - 原始浏览量数字
+ * @returns {String} 格式化后的字符串
+ */
+export function formattedViewCount(views) {
+  // 先做非数字/空值判断,防止报错
+  if (views === undefined || views === null || isNaN(views)) {
+    return '0';
+  }
+
+  const num = Number(views);
+
+  // 规则1:小于10万 → 直接返回数字
+  if (num < 100000) {
+    return num.toString();
+  }
+
+  // 规则2:大于等于10万 且 小于100万 → 保留1位小数 + w
+  if (num >= 100000 && num < 1000000) {
+    const wNum = (num / 10000).toFixed(1);
+    return `${wNum}w`;
+  }
+
+  // 规则3:大于等于100万 → 100w+
+  if (num >= 1000000) {
+    return '100w+';
+  }
+
+  return '0';
 }