张延森 3 年前
父节点
当前提交
f2892f13b1
共有 11 个文件被更改,包括 203 次插入221 次删除
  1. 51
    41
      package-lock.json
  2. 2
    1
      package.json
  3. 7
    7
      src/main.js
  4. 10
    20
      src/pages/TopRulePage.vue
  5. 16
    17
      src/pages/game/game.js
  6. 72
    75
      src/pages/game/index.vue
  7. 1
    10
      src/pages/homePage.vue
  8. 26
    0
      src/utils/api.js
  9. 1
    44
      src/utils/initial.js
  10. 9
    5
      src/utils/request.js
  11. 8
    1
      yarn.lock

+ 51
- 41
package-lock.json 查看文件

@@ -1891,6 +1891,49 @@
1891 1891
         "webpack-merge": "^5.7.3",
1892 1892
         "webpack-virtual-modules": "^0.4.2",
1893 1893
         "whatwg-fetch": "^3.6.2"
1894
+      },
1895
+      "dependencies": {
1896
+        "@vue/vue-loader-v15": {
1897
+          "version": "npm:vue-loader@15.9.8",
1898
+          "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-15.9.8.tgz",
1899
+          "integrity": "sha512-GwSkxPrihfLR69/dSV3+5CdMQ0D+jXg8Ma1S4nQXKJAznYFX14vHdc/NetQc34Dw+rBbIJyP7JOuVb9Fhprvog==",
1900
+          "dev": true,
1901
+          "requires": {
1902
+            "@vue/component-compiler-utils": "^3.1.0",
1903
+            "hash-sum": "^1.0.2",
1904
+            "loader-utils": "^1.1.0",
1905
+            "vue-hot-reload-api": "^2.3.0",
1906
+            "vue-style-loader": "^4.1.0"
1907
+          },
1908
+          "dependencies": {
1909
+            "hash-sum": {
1910
+              "version": "1.0.2",
1911
+              "resolved": "https://registry.npmjs.org/hash-sum/-/hash-sum-1.0.2.tgz",
1912
+              "integrity": "sha1-M7QHd3VMZDJXPBIMw4CLvRDUfwQ=",
1913
+              "dev": true
1914
+            }
1915
+          }
1916
+        },
1917
+        "json5": {
1918
+          "version": "1.0.1",
1919
+          "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz",
1920
+          "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==",
1921
+          "dev": true,
1922
+          "requires": {
1923
+            "minimist": "^1.2.0"
1924
+          }
1925
+        },
1926
+        "loader-utils": {
1927
+          "version": "1.4.0",
1928
+          "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz",
1929
+          "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==",
1930
+          "dev": true,
1931
+          "requires": {
1932
+            "big.js": "^5.2.2",
1933
+            "emojis-list": "^3.0.0",
1934
+            "json5": "^1.0.1"
1935
+          }
1936
+        }
1894 1937
       }
1895 1938
     },
1896 1939
     "@vue/cli-shared-utils": {
@@ -2134,47 +2177,6 @@
2134 2177
       "resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.2.31.tgz",
2135 2178
       "integrity": "sha512-ymN2pj6zEjiKJZbrf98UM2pfDd6F2H7ksKw7NDt/ZZ1fh5Ei39X5tABugtT03ZRlWd9imccoK0hE8hpjpU7irQ=="
2136 2179
     },
2137
-    "@vue/vue-loader-v15": {
2138
-      "version": "npm:vue-loader@15.9.8",
2139
-      "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-15.9.8.tgz",
2140
-      "integrity": "sha512-GwSkxPrihfLR69/dSV3+5CdMQ0D+jXg8Ma1S4nQXKJAznYFX14vHdc/NetQc34Dw+rBbIJyP7JOuVb9Fhprvog==",
2141
-      "dev": true,
2142
-      "requires": {
2143
-        "@vue/component-compiler-utils": "^3.1.0",
2144
-        "hash-sum": "^1.0.2",
2145
-        "loader-utils": "^1.1.0",
2146
-        "vue-hot-reload-api": "^2.3.0",
2147
-        "vue-style-loader": "^4.1.0"
2148
-      },
2149
-      "dependencies": {
2150
-        "hash-sum": {
2151
-          "version": "1.0.2",
2152
-          "resolved": "https://registry.npmjs.org/hash-sum/-/hash-sum-1.0.2.tgz",
2153
-          "integrity": "sha1-M7QHd3VMZDJXPBIMw4CLvRDUfwQ=",
2154
-          "dev": true
2155
-        },
2156
-        "json5": {
2157
-          "version": "1.0.1",
2158
-          "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz",
2159
-          "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==",
2160
-          "dev": true,
2161
-          "requires": {
2162
-            "minimist": "^1.2.0"
2163
-          }
2164
-        },
2165
-        "loader-utils": {
2166
-          "version": "1.4.0",
2167
-          "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz",
2168
-          "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==",
2169
-          "dev": true,
2170
-          "requires": {
2171
-            "big.js": "^5.2.2",
2172
-            "emojis-list": "^3.0.0",
2173
-            "json5": "^1.0.1"
2174
-          }
2175
-        }
2176
-      }
2177
-    },
2178 2180
     "@vue/web-component-wrapper": {
2179 2181
       "version": "1.3.0",
2180 2182
       "resolved": "https://registry.npmjs.org/@vue/web-component-wrapper/-/web-component-wrapper-1.3.0.tgz",
@@ -7905,6 +7907,14 @@
7905 7907
       "integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==",
7906 7908
       "dev": true
7907 7909
     },
7910
+    "vuex": {
7911
+      "version": "4.0.2",
7912
+      "resolved": "https://registry.npmjs.org/vuex/-/vuex-4.0.2.tgz",
7913
+      "integrity": "sha512-M6r8uxELjZIK8kTKDGgZTYX/ahzblnzC4isU1tpmEuOIIKmV+TRdc+H4s8ds2NuZ7wpUTdGRzJRtoj+lI+pc0Q==",
7914
+      "requires": {
7915
+        "@vue/devtools-api": "^6.0.0-beta.11"
7916
+      }
7917
+    },
7908 7918
     "watchpack": {
7909 7919
       "version": "2.3.1",
7910 7920
       "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.3.1.tgz",

+ 2
- 1
package.json 查看文件

@@ -12,7 +12,8 @@
12 12
     "core-js": "^3.8.3",
13 13
     "two.js": "^0.8.4",
14 14
     "vue": "^3.2.13",
15
-    "vue-router": "4"
15
+    "vue-router": "4",
16
+    "vuex": "^4.0.2"
16 17
   },
17 18
   "devDependencies": {
18 19
     "@babel/core": "^7.12.16",

+ 7
- 7
src/main.js 查看文件

@@ -1,9 +1,9 @@
1 1
 import { createApp } from 'vue'
2 2
 import App from './App.vue'
3
-
4 3
 import router from './router'
5 4
 import BackPage from './components/BackPage.vue'
6 5
 import GrassGIF from './components/GrassGIF.vue'
6
+import { Login, redirect } from './utils/initial'
7 7
 import MusicOnce from './components/MusicOnce.vue'
8 8
 
9 9
 // 创建 App实例
@@ -11,13 +11,13 @@ const app = createApp(App)
11 11
 
12 12
 // redirect()
13 13
 
14
-// Login().then(e => {
14
+Login().then(e => {
15 15
 
16
-// }).catch(e => {
17
-//   console.error(e)
18
-//   alert('系统错误, 请刷新重试')
19
-//   redirect(true)
20
-// })
16
+}).catch(e => {
17
+  console.error(e)
18
+  // alert('系统错误, 请刷新重试')
19
+  redirect(true)
20
+})
21 21
 
22 22
 // 让整个App应用支持路由
23 23
 app.use(router)

+ 10
- 20
src/pages/TopRulePage.vue 查看文件

@@ -13,12 +13,10 @@
13 13
         <img :src="TopImage" />
14 14
         <div class="Scroll-box">
15 15
           <div v-for="(item,index) in Toplist" :key="index" class="Scroll-box-Content">
16
-            <div class="Scroll-box-Content-sum">{{ item.sum }}</div>
16
+            <div class="Scroll-box-Content-sum">{{ index+1 }}</div>
17 17
             <div class="Scroll-box-Content-name">{{ item.name }}</div>
18
-            <img
19
-              src="https://cn.bing.com/th?id=OVFT.JaWQdfSE_pzTsHLmGjbsgS&pid=News&w=197&h=112&c=14&rs=2&qlt=90"
20
-            />
21
-            <div class="Scroll-box-Content-time">{{ item.tiem }}</div>
18
+            <img :src="item.avatar" />
19
+            <div class="Scroll-box-Content-time">{{ item.totalMillsec/1000 }}s</div>
22 20
           </div>
23 21
         </div>
24 22
       </div>
@@ -31,11 +29,12 @@
31 29
 
32 30
 <script>
33 31
 import { useRoute, useRouter } from 'vue-router'
34
-import { onMounted } from 'vue'
32
+import { onMounted, ref } from 'vue'
35 33
 import ruleImage from '@/assets/TipsImage/3-3.png'
36 34
 import IKnow from '@/assets/ButtonImage/我知道了.png'
37 35
 import TopImage from '@/assets/TipsImage/3-2.png'
38 36
 import GoHome from '@/assets/ButtonImage/返回首页.png'
37
+import { gameTop } from '@/utils/api'
39 38
 
40 39
 export default {
41 40
   setup() {
@@ -51,28 +50,19 @@ export default {
51 50
       // 字符串路径
52 51
       router.push('/')
53 52
     }
53
+    let Toplist = ref([])
54 54
 
55 55
     onMounted(() => {
56 56
       if (route.query.type == 'top') {
57
+        gameTop().then((e) => {
58
+          Toplist.value = e
59
+          console.log(e)
60
+        })
57 61
       }
58 62
       console.log(router)
59 63
       // 打印
60 64
     })
61 65
 
62
-    const Toplist = [
63
-      { sum: 2, name: '陈一狗', tiem: '10s' },
64
-      { sum: 45, name: '陈二狗', tiem: '10s' },
65
-      { sum: 5, name: '陈三狗', tiem: '10s' },
66
-      { sum: 4, name: '陈四狗', tiem: '26s' },
67
-      { sum: 2, name: '陈五狗', tiem: '10s' },
68
-      { sum: 1, name: '陈六狗', tiem: '10s' },
69
-      { sum: 2, name: '陈七狗', tiem: '6s' },
70
-      { sum: 2, name: '陈八狗', tiem: '10s' },
71
-      { sum: 2, name: '陈九个狗', tiem: '10s' },
72
-      { sum: 2, name: '陈十狗', tiem: '10m6s' },
73
-      { sum: 2, name: '山二猫', tiem: '10s' },
74
-      { sum: 2, name: '陈把饭狗', tiem: '1h12m33s' }
75
-    ]
76 66
     return {
77 67
       goBack,
78 68
       gohomePage,

+ 16
- 17
src/pages/game/game.js 查看文件

@@ -36,7 +36,7 @@ const ropeImageList = [
36 36
   ropeImage9,
37 37
 ];
38 38
 
39
-export default function game({ el, center, onError, onSuccess, onBingo }) {
39
+export default function game ({ el, center, onError, onSuccess, onBingo }) {
40 40
 
41 41
   // 是否游戏结束
42 42
   let isFinished = false;
@@ -61,10 +61,10 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
61 61
 
62 62
   // 轿厢 - 子弹
63 63
   const bullets = []
64
-  
64
+
65 65
   // 子弹是否在射击状态, 如果是, 不能进行其他操作
66 66
   let isShooting = false
67
-  
67
+
68 68
   // 子弹飞行速度, 因为是向上飞, y 值是不端减小的过程
69 69
   const speed = -5;
70 70
 
@@ -73,7 +73,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
73 73
 
74 74
   // 轿厢的初始旋转弧度
75 75
   let rotateAngle = 0
76
-  
76
+
77 77
   // 轿厢的旋转速度 - 单位弧度
78 78
   const rotateSpeed = 0.015
79 79
 
@@ -91,8 +91,8 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
91 91
   }).appendTo(el);
92 92
 
93 93
   // 绘制背景
94
-  makeBg({two, center});
95
-  
94
+  makeBg({ two, center });
95
+
96 96
   // 绘制转盘
97 97
   const wheelArc = two.makeCircle(center.x, center.y, 0);
98 98
   const lightArc = two.makeCircle(center.x, center.y, 0);
@@ -173,7 +173,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
173 173
     wheelArc.rotation = rotateAngle
174 174
     roundAbout.forEach((x, inx) => {
175 175
       x.rotation = rotateAngle
176
-            
176
+
177 177
       // 计算旋转后的轿厢坐标
178 178
       const cage = cageList[inx]
179 179
       const angle = cage.__$angle + rotateAngle + perAngle / 2
@@ -230,7 +230,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
230 230
 
231 231
       return arc
232 232
     })
233
-    
233
+
234 234
     cageTexture.bind('load', () => {
235 235
       const r = cageTexture.image.naturalWidth / 2;
236 236
       list.forEach(it => {
@@ -241,10 +241,10 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
241 241
 
242 242
     bullets.push(...list)
243 243
   }
244
-  drawBullets(center.x, center.y + pedestalDistance * scale)  
244
+  drawBullets(center.x, center.y + pedestalDistance * scale)
245 245
   // 待发射子弹
246 246
   const clip = bullets.slice()
247
-  
247
+
248 248
   // 绘制计数器
249 249
   const drawCounter = (x, y) => {
250 250
     const counterTexture = two.makeTexture(countImage);
@@ -270,7 +270,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
270 270
     // 写入映射表
271 271
     mntMap[cage.id] = targ
272 272
   }
273
-  
273
+
274 274
   // 当前子弹
275 275
   let currentBullet = null;
276 276
   // 射击
@@ -333,7 +333,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
333 333
       const rect1 = it.getBoundingClientRect();
334 334
 
335 335
       // 校验范围为轿厢内部一半的地方
336
-      const left = rect1.left  + rect1.width / 3
336
+      const left = rect1.left + rect1.width / 3
337 337
       const right = rect1.right - rect1.width / 3
338 338
       const top = rect1.top
339 339
       const bottom = rect1.bottom
@@ -341,7 +341,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
341 341
       // 如果当前子弹的中心点位于目标轿厢矩形范围内
342 342
       // 则代表击中
343 343
       return x >= left && x <= right &&
344
-          y >= top && y <= bottom;
344
+        y >= top && y <= bottom;
345 345
     })[0]
346 346
 
347 347
     if (!cage) return false;  // 未找到对应的目标轿厢
@@ -349,9 +349,9 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
349 349
 
350 350
     return cage
351 351
   }
352
-  
352
+
353 353
   // 重复绘制内容
354
-  two.bind('update', () => {    
354
+  two.bind('update', () => {
355 355
     rotate()
356 356
     if (!isFinished) {
357 357
       if (isShooting) {
@@ -379,7 +379,6 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
379 379
 
380 380
   two.update();
381 381
   two.play();
382
-  console.log('-------twotwotwo--------')
383 382
 
384 383
   return {
385 384
     two,
@@ -400,7 +399,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
400 399
   }
401 400
 }
402 401
 
403
-function makeBg({two, center}) {
402
+function makeBg ({ two, center }) {
404 403
   const bgTexture = two.makeTexture(backImage);
405 404
 
406 405
   const bgBox = two.makeRectangle(center.x, center.y, 0, 0);

+ 72
- 75
src/pages/game/index.vue 查看文件

@@ -1,94 +1,91 @@
1 1
 <template>
2 2
   <div ref="el" />
3
-  <FireWorkListVue
4
-    ref="firesRef"
5
-    :center="center"
6
-    :raduis="raduis"
7
-  />
8
-  <MusicOnce
9
-    ref="bingoRef"
10
-    :src="bingoMusic"
11
-  />
12
-  <MusicOnce
13
-    ref="failRef"
14
-    :src="failMusic"
15
-  />
16
-  <MusicOnce
17
-    ref="successRef"
18
-    :src="successMusic"
19
-  />
3
+  <FireWorkListVue ref="firesRef" :center="center" :raduis="raduis" />
4
+  <MusicOnce ref="bingoRef" :src="bingoMusic" />
5
+  <MusicOnce ref="failRef" :src="failMusic" />
6
+  <MusicOnce ref="successRef" :src="successMusic" />
20 7
 </template>
21 8
 
22 9
 <script setup>
23
-  import { onBeforeUnmount, onMounted, ref } from 'vue';
24
-  import { useRouter } from 'vue-router';
25
-  import FireWorkListVue from '@/components/FireWorkList.vue';
26
-  import game from "./game.js";
10
+import { onBeforeUnmount, onMounted, ref } from 'vue'
11
+import { useRouter } from 'vue-router'
12
+import FireWorkListVue from '@/components/FireWorkList.vue'
13
+import game from './game.js'
14
+import { gameOver, gameStart } from '@/utils/api.js'
27 15
 
28
-  const path = window.location.origin + window.location.pathname
29
-  const bingoMusic = `${path}/music/bingo.mp3`
30
-  const failMusic = `${path}/music/fail.mp3`
31
-  const successMusic = `${path}/music/bingo.mp3`
16
+// // 修复一个 two-js bug ,当页面返回的时候, 不能正常渲染
17
+// // 所以这边判断如果第二次进入页面就强制刷新
18
+// const loadSign = localStorage.getItem('loadSign');
19
+// if (loadSign) {
20
+//   localStorage.removeItem('loadSign');
21
+//   window.location.href = window.location.href;
22
+// }
32 23
 
33
-  const el = ref()
34
-  const bingoRef = ref()
35
-  const failRef = ref()
36
-  const successRef = ref()
37
-  const destroyRef = ref()
38
-  const firesRef = ref()
39
-  const router = useRouter()
40
-  const raduis = ref(150)
24
+const el = ref()
25
+const destroyRef = ref()
26
+const firesRef = ref()
27
+const router = useRouter()
28
+const raduis = ref(150)
29
+const path = window.location.origin + window.location.pathname
30
+const bingoMusic = `${path}/music/bingo.mp3`
31
+const failMusic = `${path}/music/fail.mp3`
32
+const successMusic = `${path}/music/bingo.mp3`
41 33
 
42
-  const center = {
43
-        x: document.body.offsetWidth / 2,
44
-        y: document.body.offsetHeight / 2,
45
-      }
34
+const bingoRef = ref()
35
+const failRef = ref()
36
+const successRef = ref()
46 37
 
47
-  const gameInit = () => {
48
-    destroyRef.value = game({
49
-      el: el.value,
50
-      center,
51
-      onError: () => {
52
-        failRef.value.play()
53
-        const t = setTimeout(() => {
54
-          localStorage.setItem('loadSign', '1');
55
-          router.push('/OverPage?type=lose')
56
-          clearTimeout(t)
57
-        }, 1000)
58
-      },
59
-      onSuccess: () => {
60
-        successRef.value.play()
61
-        firesRef.value.toggle()
62
-        // alert('你真牛逼')
63
-        const t = setTimeout(() => {
64
-          localStorage.setItem('loadSign', '1');
65
-          router.push('/OverPage?type=win')
66
-          clearTimeout(t)
67
-        }, 2000)
68
-      },
69
-      onBingo: () => {
70
-        bingoRef.value.play()
71
-      }
72
-    })
73
-
74
-    raduis.value = destroyRef.value.raduis
75
-  }
76
-
77
-
78
-  onMounted(() => {
79
-    gameInit()
80
-  })
38
+const center = {
39
+  x: document.body.offsetWidth / 2,
40
+  y: document.body.offsetHeight / 2
41
+}
81 42
 
82
-  onBeforeUnmount(() => {
83
-    if (destroyRef.value) {
84
-      destroyRef.value.destroy();
43
+const gameInit = () => {
44
+  destroyRef.value = game({
45
+    el: el.value,
46
+    center,
47
+    onError: () => {
48
+      failRef.value.play()
49
+      const t = setTimeout(() => {
50
+        localStorage.setItem('loadSign', '1')
51
+        router.push('/OverPage?type=lose')
52
+        clearTimeout(t)
53
+      }, 1000)
54
+    },
55
+    onSuccess: () => {
56
+      successRef.value.play()
57
+      firesRef.value.toggle()
58
+      // alert('你真牛逼')
59
+      const t = setTimeout(() => {
60
+        localStorage.setItem('loadSign', '1')
61
+        router.push('/OverPage?type=win')
62
+        clearTimeout(t)
63
+      }, 2000)
64
+    },
65
+    onBingo: () => {
66
+      bingoRef.value.play()
85 67
     }
86 68
   })
87 69
 
70
+  raduis.value = destroyRef.value.raduis
71
+}
72
+
73
+onMounted(() => {
74
+  gameStart()
75
+  gameInit()
76
+})
77
+
78
+onBeforeUnmount(() => {
79
+  if (destroyRef.value) {
80
+    destroyRef.value.destroy()
81
+  }
82
+})
88 83
 </script>
89 84
 
90 85
 <style>
91
-html, body, #app {
86
+html,
87
+body,
88
+#app {
92 89
   height: 100%;
93 90
   margin: 0;
94 91
   padding: 0;

+ 1
- 10
src/pages/homePage.vue 查看文件

@@ -21,17 +21,13 @@ import gameTitle from '@/assets/BackImage/首页大标.png'
21 21
 import gameSatrt from '@/assets/ButtonImage/开始游戏.png'
22 22
 import gameRule from '@/assets/ButtonImage/游戏规则.png'
23 23
 import BgMusic from '@/components/BackPage.vue'
24
+import { gameStart } from '@/utils/api.js'
24 25
 
25 26
 export default {
26 27
   setup() {
27 28
     const router = useRouter()
28 29
 
29 30
     const linkTo = () => {
30
-      // 字符串路径
31
-
32
-      // router.push('/about')
33
-
34
-      // 带有路径的对象
35 31
       router.push({
36 32
         path: '/game'
37 33
         // query: {
@@ -40,14 +36,9 @@ export default {
40 36
       })
41 37
     }
42 38
     const goRule = () => {
43
-      // 字符串路径
44
-      // router.push('/about')
45
-
46
-      // 带有路径的对象
47 39
       router.push({
48 40
         path: '/TopRulePage',
49 41
         query: {
50
-          // type: 'top'
51 42
           type: 'rule'
52 43
         }
53 44
       })

+ 26
- 0
src/utils/api.js 查看文件

@@ -9,3 +9,29 @@ import request from "./request";
9 9
 //
10 10
 export const LoginUser = (params, data,) => request(`/api/wx/login?code=${params}`, { method: 'post' })
11 11
 
12
+
13
+
14
+/**
15
+ * @游戏开始
16
+ *
17
+ */
18
+//
19
+export const gameStart = () => request(`/api/wx/game/start`, { method: 'post' })
20
+
21
+/**
22
+ * @游戏结束
23
+ *
24
+ */
25
+//
26
+export const gameOver = () => request(`/api/wx/game/over`, { method: 'post' })
27
+
28
+
29
+
30
+/**
31
+ * @游戏排行榜
32
+ *
33
+ */
34
+//
35
+export const gameTop = () => request(`/api/wx/top`, { method: 'get' })
36
+
37
+

+ 1
- 44
src/utils/initial.js 查看文件

@@ -61,40 +61,9 @@ export function Login () {
61 61
   console.log(1);
62 62
   const code = process.env.NODE_ENV === 'development' ? '123' : getCode()
63 63
 
64
-  let isLoaded = false; //定义变量
65
-
66
-
67
-  //执行Timeout 如果一秒内登陆成功,由LoginUser改变isLoaded状态,Timeout 一秒后发现isLoaded为true,则关闭。
68
-  const t = setTimeout(() => {
69
-    console.log(2);
70
-
71
-    if (isLoaded) {
72
-      console.log(isLoaded);
73
-
74
-      hideLoading()
75
-    } else {
76
-      console.log('isLoaded=true');
77
-
78
-      isLoaded = true
79
-    }
80
-    clearTimeout(t);
81
-  }, 2000);
82
-
83 64
 
84 65
   return LoginUser(code).then(e => {
85
-    console.log("🚀 ~ file: initial.js ~ line 85 ~ returnLoginUser ~ code", code)
86
-    // PVsum
87
-    console.log(e);
88
-    let userInfo = {
89
-      token: e.token,
90
-      name: e.person.name,
91
-      phone: e.person.phone,
92
-      personId: e.person.personId,
93
-    }
94
-
95
-    console.log(3, isLoaded);
96
-
97
-
66
+    window.localStorage.setItem("token", e.token);//保存数据
98 67
 
99 68
     try {
100 69
       share({
@@ -115,18 +84,6 @@ export function Login () {
115 84
       console.log(4, isLoaded);
116 85
 
117 86
     }
118
-    // setTimeout(() => {
119
-    //   console.log("🚀 ~ file: initial.js ~ line 110 ~ setTimeout ~ isLoaded", isLoaded)
120
-
121
-    //   if (isLoaded) {
122
-    //     hideLoading()
123
-    //   } else {
124
-
125
-    //     isLoaded = true
126
-    //   }
127
-    // }, 5000)
128
-
129
-
130 87
     return;
131 88
   })
132 89
 }

+ 9
- 5
src/utils/request.js 查看文件

@@ -1,16 +1,18 @@
1 1
 
2 2
 import axios from 'axios'
3
-
3
+import { LoginUser, } from './api'
4
+import { getCode } from './initial'
4 5
 export const domain = process.env.NODE_ENV === 'development' ? '' : 'http://colmo-service.dianyang.njyunzhi.com'
5 6
 
7
+let token = ''
6 8
 export default function (url, options) {
7 9
   const { params, header, ...leftOptions } = options || {}
8 10
 
9 11
   return new Promise((resolve, reject) => {
10
-    // const { code, token } = store.state.user
11
-    // let header = {
12
-    //   'X-Authorization-JWT': token,
13
-    // }
12
+    const token = window.localStorage.getItem('token')
13
+    let header = {
14
+      'X-Authorization-JWT': token,//读取数据,
15
+    }
14 16
     axios.request({
15 17
       ...leftOptions,
16 18
       url: `${domain}${url}`,
@@ -36,3 +38,5 @@ export default function (url, options) {
36 38
     })
37 39
   })
38 40
 }
41
+
42
+

+ 8
- 1
yarn.lock 查看文件

@@ -1554,7 +1554,7 @@
1554 1554
   optionalDependencies:
1555 1555
     prettier "^1.18.2 || ^2.0.0"
1556 1556
 
1557
-"@vue/devtools-api@^6.0.0":
1557
+"@vue/devtools-api@^6.0.0", "@vue/devtools-api@^6.0.0-beta.11":
1558 1558
   version "6.1.4"
1559 1559
   resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.1.4.tgz#b4aec2f4b4599e11ba774a50c67fa378c9824e53"
1560 1560
   integrity sha512-IiA0SvDrJEgXvVxjNkHPFfDx6SXw0b/TUkqMcDZWNg9fnCAHbTpoo59YfJ9QLFkwa3raau5vSlRVzMSLDnfdtQ==
@@ -5850,6 +5850,13 @@ vue@^3.2.13:
5850 5850
     "@vue/server-renderer" "3.2.31"
5851 5851
     "@vue/shared" "3.2.31"
5852 5852
 
5853
+vuex@^4.0.2:
5854
+  version "4.0.2"
5855
+  resolved "https://registry.yarnpkg.com/vuex/-/vuex-4.0.2.tgz#f896dbd5bf2a0e963f00c67e9b610de749ccacc9"
5856
+  integrity sha512-M6r8uxELjZIK8kTKDGgZTYX/ahzblnzC4isU1tpmEuOIIKmV+TRdc+H4s8ds2NuZ7wpUTdGRzJRtoj+lI+pc0Q==
5857
+  dependencies:
5858
+    "@vue/devtools-api" "^6.0.0-beta.11"
5859
+
5853 5860
 watchpack@^2.3.1:
5854 5861
   version "2.3.1"
5855 5862
   resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.3.1.tgz#4200d9447b401156eeca7767ee610f8809bc9d25"