lanxin 3 天之前
父節點
當前提交
e088e02160
共有 4 個文件被更改,包括 110 次插入31 次删除
  1. 9 9
      hot/src/views/Home.vue
  2. 5 5
      scene/public/js/manage.js
  3. 3 3
      scene/public/showa/js/myShow.js
  4. 93 14
      scene/src/pages/A2main/index.tsx

+ 9 - 9
hot/src/views/Home.vue

@@ -152,13 +152,13 @@ export default {
   methods: {
     // 本地化 url 适配
     urlToFitFu(url) {
-      return url;
-      // const resUrl = url;
-      // if (url.includes("https://super.4dage.com")) {
-      //   return url.replace("https://super.4dage.com", "../");
-      // } else if (url.includes("http://super.4dage.com")) {
-      //   return url.replace("http://super.4dage.com", "../");
-      // } else return resUrl;
+      // return url;
+      const resUrl = url;
+      if (url.includes("https://super.4dage.com")) {
+        return url.replace("https://super.4dage.com", "../");
+      } else if (url.includes("http://super.4dage.com")) {
+        return url.replace("http://super.4dage.com", "../");
+      } else return resUrl;
     },
 
     // 点击左右箭头
@@ -176,10 +176,10 @@ export default {
     async getData() {
       // https://www.4dmodel.com/
 
-      let url = `https://super.4dage.com/data/${
+      // let url = `https://super.4dage.com/data/${
       // 线上数据
 
-      // let url = `../data/${
+      let url = `../data/${
         //本地化部署
         this.id
       }/hot/js/data.js?time=${Math.random()}`;

+ 5 - 5
scene/public/js/manage.js

@@ -1,9 +1,9 @@
 var g_ProjectName = window.location.pathname.substring(window.location.pathname.indexOf('/') + 1, window.location.pathname.lastIndexOf('/'))
-var g_Prefix = 'https://super.4dage.com/'
-// var g_Prefix = window.location.href.substring(0, window.location.href.indexOf('/index.html') + 1)
+// var g_Prefix = 'https://super.4dage.com/'
+var g_Prefix = window.location.href.substring(0, window.location.href.indexOf('/index.html') + 1)
 var s = window.location.href.split('/')
 s.pop()
-// window.isLocal = true
+window.isLocal = true
 //var g_Prefix = s.join('/');
 var g_index = null
 var g_modeldata = null
@@ -133,7 +133,7 @@ var settings = {
   hotFastTran: false,
   transparentBg: false,
   bgImg: null,
-  // localPrefix: '',
+  localPrefix: '',
   tileClass: {
     //默认全景贴图加载的清晰度
     pc: {
@@ -751,7 +751,7 @@ window.expandMath = function (math) {
 var Manage = function () {
   ;((this.weixinURL = 'https://res.wx.qq.com/open/js/jweixin-1.2.0.js'), (this.time = '?' + new Date().getTime()))
   this.loadAudio()
-  this.loadWeixin()
+  // this.loadWeixin()
 }
 //动态加载js文件
 Manage.prototype.LoadJs = function (_files, succes) {

+ 3 - 3
scene/public/showa/js/myShow.js

@@ -1,9 +1,9 @@
 var g_ProjectName = window.location.pathname.substring(window.location.pathname.indexOf('/') + 1, window.location.pathname.lastIndexOf('/'))
-var g_Prefix="https://super.4dage.com/";
-// var g_Prefix = window.location.href.substring(0, window.location.href.indexOf('/index.html') + 1)
+// var g_Prefix="https://super.4dage.com/";
+var g_Prefix = window.location.href.substring(0, window.location.href.indexOf('/index.html') + 1)
 var s = window.location.href.split('/')
 s.pop()
-// window.isLocal = true
+window.isLocal = true
 //var g_Prefix = s.join('/');
 var g_index = null
 var g_modeldata = null

+ 93 - 14
scene/src/pages/A2main/index.tsx

@@ -9,29 +9,92 @@ import { RootState } from '@/store'
 import classNames from 'classnames'
 import A3hotList from '../A3hotList'
 import { message } from 'antd'
-import http from '@/utils/http'
 // import isMobile from '@/utils/isMobile'
 const imgArrTemp = ['like.png', 'likeAc.png']
 const imgArr = imgArrTemp.map(item => require(`@/assets/img/${item}`))
 
+const SCENE_CODE = 'SG-WVqbTpbkApi_96'
+const LIKE_STORAGE_KEY = `count_like_${SCENE_CODE}`
+const VIEW_STORAGE_KEY = `count_view_${SCENE_CODE}`
+const DEFAULT_LIKE_NUM = 100
+const DEFAULT_VIEW_NUM = 300
+
+const getLocalCount = (key: string, fallback: number) => {
+  try {
+    const raw = window.localStorage.getItem(key)
+    if (raw == null) return fallback
+    const n = Number(raw)
+    return Number.isFinite(n) ? n : fallback
+  } catch {
+    return fallback
+  }
+}
+
+const setLocalCount = (key: string, value: number) => {
+  try {
+    window.localStorage.setItem(key, String(value))
+  } catch {
+    // 隐私模式等无法写入时忽略
+  }
+}
+
+const pickCount = (value: unknown) => (typeof value === 'number' && Number.isFinite(value) ? value : null)
+
+const fetchCountApi = async (url: string) => {
+  const response = await fetch(url)
+  if (!response.ok) throw new Error('count api failed')
+  return response.json()
+}
+
+const bumpLocalView = () => {
+  try {
+    const stored = window.localStorage.getItem(VIEW_STORAGE_KEY)
+    const next = stored == null ? DEFAULT_VIEW_NUM : getLocalCount(VIEW_STORAGE_KEY, DEFAULT_VIEW_NUM) + 1
+    setLocalCount(VIEW_STORAGE_KEY, next)
+    return next
+  } catch {
+    return DEFAULT_VIEW_NUM
+  }
+}
+
 function A2main() {
-  const SCENE_CODE = 'SG-WVqbTpbkApi_96'
   // 漫游的状态
   const { state3d } = useSelector((state: RootState) => state.three)
 
   // 点赞
   const [like, setLike] = useState(false)
-  const [likeNum, setLikeNum] = useState(1)
-  const [viewNum, setViewNum] = useState(1)
+  const [likeNum, setLikeNum] = useState(DEFAULT_LIKE_NUM)
+  const [viewNum, setViewNum] = useState(DEFAULT_VIEW_NUM)
   const [isShowSection, setIsShowSection] = useState(false)
 
   useEffect(() => {
-    http.get(`https://count.4dage.com/api/count/detail/${SCENE_CODE}`).then(res => {
-      setLikeNum(res.data.starSum!)
-    })
-    http.get(`https://count.4dage.com/api/count/saveVisit/${SCENE_CODE}`).then(res => {
-      setViewNum(res.data.visitSum!)
-    })
+    fetchCountApi(`https://count.4dage.com/api/count/detail/${SCENE_CODE}`)
+      .then(res => {
+        const num = pickCount(res.data?.starSum)
+        if (num != null) {
+          setLikeNum(num)
+          setLocalCount(LIKE_STORAGE_KEY, num)
+          return
+        }
+        setLikeNum(getLocalCount(LIKE_STORAGE_KEY, DEFAULT_LIKE_NUM))
+      })
+      .catch(() => {
+        setLikeNum(getLocalCount(LIKE_STORAGE_KEY, DEFAULT_LIKE_NUM))
+      })
+
+    fetchCountApi(`https://count.4dage.com/api/count/saveVisit/${SCENE_CODE}`)
+      .then(res => {
+        const num = pickCount(res.data?.visitSum)
+        if (num != null) {
+          setViewNum(num)
+          setLocalCount(VIEW_STORAGE_KEY, num)
+          return
+        }
+        setViewNum(bumpLocalView())
+      })
+      .catch(() => {
+        setViewNum(bumpLocalView())
+      })
   }, [])
 
   // 点击点赞
@@ -39,12 +102,28 @@ function A2main() {
     if (like) return
     setLike(true)
     setTimeout(() => {
-      http.get(`https://count.4dage.com/api/count/saveStar/${SCENE_CODE}`).then(res => {
-        setLikeNum(likeNum + 1)
+      const applyLocalLike = () => {
+        setLikeNum(n => {
+          const next = n + 1
+          setLocalCount(LIKE_STORAGE_KEY, next)
+          return next
+        })
         setLike(false)
-      })
+      }
+      fetchCountApi(`https://count.4dage.com/api/count/saveStar/${SCENE_CODE}`)
+        .then(res => {
+          if (pickCount(res.data?.starSum) != null) {
+            const num = pickCount(res.data.starSum)!
+            setLikeNum(num)
+            setLocalCount(LIKE_STORAGE_KEY, num)
+            setLike(false)
+            return
+          }
+          applyLocalLike()
+        })
+        .catch(applyLocalLike)
     }, 2000)
-  }, [like, likeNum])
+  }, [like])
 
   // 点击热点列表
   const [hotListShow, setHotListShow] = useState(false)