[baozhangchao] преди 3 години
родител
ревизия
8b782b2110
променени са 10 файла, в които са добавени 186 реда и са изтрити 187 реда
  1. 51
    41
      package-lock.json
  2. 2
    1
      package.json
  3. 8
    7
      src/main.js
  4. 10
    20
      src/pages/TopRulePage.vue
  5. 17
    17
      src/pages/game/game.js
  6. 54
    51
      src/pages/game/index.vue
  7. 26
    0
      src/utils/api.js
  8. 1
    44
      src/utils/initial.js
  9. 9
    5
      src/utils/request.js
  10. 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",

+ 8
- 7
src/main.js Целия файл

@@ -1,21 +1,22 @@
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 8
 // 创建 App实例
8 9
 const app = createApp(App)
9 10
 
10 11
 // redirect()
11 12
 
12
-// Login().then(e => {
13
+Login().then(e => {
13 14
 
14
-// }).catch(e => {
15
-//   console.error(e)
16
-//   alert('系统错误, 请刷新重试')
17
-//   redirect(true)
18
-// })
15
+}).catch(e => {
16
+  console.error(e)
17
+  // alert('系统错误, 请刷新重试')
18
+  redirect(true)
19
+})
19 20
 
20 21
 // 让整个App应用支持路由
21 22
 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,

+ 17
- 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
 
@@ -87,8 +87,8 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
87 87
   }).appendTo(el);
88 88
 
89 89
   // 绘制背景
90
-  makeBg({two, center});
91
-  
90
+  makeBg({ two, center });
91
+
92 92
   // 绘制转盘
93 93
   const wheelArc = two.makeCircle(center.x, center.y, 0);
94 94
   const lightArc = two.makeCircle(center.x, center.y, 0);
@@ -169,7 +169,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
169 169
     wheelArc.rotation = rotateAngle
170 170
     roundAbout.forEach((x, inx) => {
171 171
       x.rotation = rotateAngle
172
-            
172
+
173 173
       // 计算旋转后的轿厢坐标
174 174
       const cage = cageList[inx]
175 175
       const angle = cage.__$angle + rotateAngle + perAngle / 2
@@ -226,7 +226,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
226 226
 
227 227
       return arc
228 228
     })
229
-    
229
+
230 230
     cageTexture.bind('load', () => {
231 231
       const r = cageTexture.image.naturalWidth / 2;
232 232
       list.forEach(it => {
@@ -237,10 +237,10 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
237 237
 
238 238
     bullets.push(...list)
239 239
   }
240
-  drawBullets(center.x, center.y + pedestalDistance * scale)  
240
+  drawBullets(center.x, center.y + pedestalDistance * scale)
241 241
   // 待发射子弹
242 242
   const clip = bullets.slice()
243
-  
243
+
244 244
   // 绘制计数器
245 245
   const drawCounter = (x, y) => {
246 246
     const counterTexture = two.makeTexture(countImage);
@@ -266,7 +266,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
266 266
     // 写入映射表
267 267
     mntMap[cage.id] = targ
268 268
   }
269
-  
269
+
270 270
   // 当前子弹
271 271
   let currentBullet = null;
272 272
   // 射击
@@ -329,7 +329,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
329 329
       const rect1 = it.getBoundingClientRect();
330 330
 
331 331
       // 校验范围为轿厢内部一半的地方
332
-      const left = rect1.left  + rect1.width / 3
332
+      const left = rect1.left + rect1.width / 3
333 333
       const right = rect1.right - rect1.width / 3
334 334
       const top = rect1.top
335 335
       const bottom = rect1.bottom
@@ -337,7 +337,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
337 337
       // 如果当前子弹的中心点位于目标轿厢矩形范围内
338 338
       // 则代表击中
339 339
       return x >= left && x <= right &&
340
-          y >= top && y <= bottom;
340
+        y >= top && y <= bottom;
341 341
     })[0]
342 342
 
343 343
     if (!cage) return false;  // 未找到对应的目标轿厢
@@ -345,9 +345,9 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
345 345
 
346 346
     return cage
347 347
   }
348
-  
348
+
349 349
   // 重复绘制内容
350
-  two.bind('update', () => {    
350
+  two.bind('update', () => {
351 351
     rotate()
352 352
     if (!isFinished) {
353 353
       if (isShooting) {
@@ -381,7 +381,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
381 381
     stop: () => {
382 382
       isFinished = true;
383 383
     },
384
-    destroy: () => {    
384
+    destroy: () => {
385 385
       two.unbind('update');
386 386
       two.pause();
387 387
       two.clear();
@@ -393,7 +393,7 @@ export default function game({ el, center, onError, onSuccess, onBingo }) {
393 393
   }
394 394
 }
395 395
 
396
-function makeBg({two, center}) {
396
+function makeBg ({ two, center }) {
397 397
   const bgTexture = two.makeTexture(backImage);
398 398
 
399 399
   const bgBox = two.makeRectangle(center.x, center.y, 0, 0);

+ 54
- 51
src/pages/game/index.vue Целия файл

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

+ 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"