chenlei 1 tuần trước cách đây
mục cha
commit
4b66e3bfa9

+ 4 - 0
src/index/api/home.ts

@@ -16,6 +16,10 @@ export const homeApi = {
     );
   },
 
+  saveSceneVisit(sceneCode: string) {
+    return service.get(`${SCENE_BASE_URL}/count/saveVisit/${sceneCode}`);
+  },
+
   /**
    * 点赞
    */

+ 23 - 5
src/index/views/home/components/menu/index.hq.tsx

@@ -1,28 +1,46 @@
-import { defineComponent, ref } from 'vue';
+import { defineComponent, onMounted, ref } from 'vue';
 import SharePopup from '../share-popup/index.vue';
+import { homeApi } from '@/api';
 import './index.hq.scss';
 
-const visitCount = localStorage.getItem('visitCount');
-
 export default defineComponent({
   name: 'HomeMenu',
   setup() {
     const shareVisible = ref(false);
     const animationThumb = ref(false);
+    const visitCount = ref(0);
+    const likeCount = ref(0);
+
+    const getSceneDetail = async () => {
+      const { data } = await homeApi.getSceneDetail(window.number);
+      if (!data) return;
+      visitCount.value = data.visitSum;
+      likeCount.value = data.starSum;
+    };
 
     const handleThumb = () => {
       if (animationThumb.value) return;
 
       animationThumb.value = true;
+      likeCount.value++;
+      homeApi.saveStar(window.number);
 
       setTimeout(() => {
         animationThumb.value = false;
       }, 200);
     };
 
+    onMounted(() => {
+      getSceneDetail();
+
+      homeApi.saveSceneVisit(window.number);
+    });
+
     return {
       shareVisible,
       animationThumb,
+      visitCount,
+      likeCount,
       handleThumb,
     };
   },
@@ -96,7 +114,7 @@ export default defineComponent({
         <div class="pinBottom right">
           <div id="thumb" class={{ active: this.animationThumb }} onClick={this.handleThumb}>
             <div class="icon icon-slot" />
-            <span>点赞</span>
+            <span>{this.likeCount > 0 ? `${this.likeCount} ` : ''}点赞</span>
           </div>
           <div id="sharing" onClick={() => (this.shareVisible = true)}>
             <img class="icon icon-inside" src="images/hq/share.png" title="分享" />
@@ -121,7 +139,7 @@ export default defineComponent({
           </div>
           <div id="viewer" class="ui-icon wide">
             <img class="icon icon-inside" src="images/hq/viewer.png" title="浏览量" />
-            <p>{visitCount}</p>
+            <p>{this.visitCount}</p>
           </div>
           <div
             id="gui-fullscreen"

+ 6 - 6
src/index/views/home/index.hq.tsx

@@ -10,8 +10,8 @@ import Menu from './components/menu';
 import GuiLoading from './components/gui-loading';
 import Popup from './components/popup';
 import HotSpotList from './components/hot-spot-list';
-import UnitIcon from '@/assets/images/unit-btn-min.png';
-import UnitDialog from './components/unit-dialog/index.vue';
+// import UnitIcon from '@/assets/images/unit-btn-min.png';
+// import UnitDialog from './components/unit-dialog/index.vue';
 import './index.hq.scss';
 
 // 自定义热点图标
@@ -21,7 +21,7 @@ import './index.hq.scss';
 //   higt: '/images/point2.png',
 // };
 
-const isMobile = judgeIsMobile();
+// const isMobile = judgeIsMobile();
 
 export default defineComponent({
   name: 'home',
@@ -48,14 +48,14 @@ export default defineComponent({
   render() {
     return (
       <div class="home">
-        {!isMobile && (
+        {/* {!isMobile && (
           <img
             class="home_unit-btn"
             src={UnitIcon}
             draggable="false"
             onClick={() => (this.unitVisible = true)}
           />
-        )}
+        )} */}
 
         {/* 进度条加载 */}
         <GuiLoading />
@@ -98,7 +98,7 @@ export default defineComponent({
           <Other />
         </div>
 
-        <UnitDialog visible={this.unitVisible} onUpdate:visible={(v) => (this.unitVisible = v)} />
+        {/* <UnitDialog visible={this.unitVisible} onUpdate:visible={(v) => (this.unitVisible = v)} /> */}
 
         {/* TODO: 没有控制权,耦合严重;放在此处为了防止元素未渲染导致报错 */}
         <JsScript src="./js/manage.js" onLoad={() => (this.manageJsLoaded = true)} />