network-speed-js 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/App.vue ADDED
@@ -0,0 +1,118 @@
1
+ <template>
2
+ <div>
3
+ <ElButton type="primary" @click="handleClick">点击测速</ElButton>
4
+ <div class="loading" v-if="isLoading">
5
+ <p>正在检测您当前的网络速度</p>
6
+ <span></span>
7
+ <span></span>
8
+ <span></span>
9
+ <span></span>
10
+ <span></span>
11
+ </div>
12
+ </div>
13
+ </template>
14
+
15
+ <script setup lang="ts">
16
+ import { ElButton, ElMessage } from 'element-plus'
17
+ import io from "./api";
18
+ import { ref } from 'vue';
19
+ const isLoading = ref(false);
20
+ const handleClick = async () => {
21
+ isLoading.value = true;
22
+
23
+ try {
24
+ const res: any = await io.get(
25
+ "https://s3-gzpu-inter.didistatic.com/ese-feedback/kefu-workbench/hashiqi.webp"
26
+ );
27
+ const time = res.time.end - res.time.start;
28
+ const speed = (10.63 * 1000) / time;
29
+ let standard = "";
30
+ if (speed > 10) {
31
+ standard = "fast 3g";
32
+ } else if (speed > 0 && speed <= 10) {
33
+ standard = "slow 3g";
34
+ }
35
+ isLoading.value = false;
36
+ ElMessage({
37
+ message: `当前网速:${parseInt(`${speed}`)}kb/s ${standard} 已连接内网,当前网速情况 内网speed ${speed} "kb" `,
38
+ type: 'success',
39
+ offset: 100
40
+ });
41
+ } catch (error) {
42
+ console.log("当前网络环境为外网");
43
+ console.log("===========正在使用外网图片测试您的网速===========");
44
+ try {
45
+ const res: any = await io.get(
46
+ "https://s3-gz01.didistatic.com/ese-feedback/kefu-workbench/hashiqi.webp"
47
+ );
48
+ const time = res.time.end - res.time.start;
49
+ // console.log(time);
50
+ const speed = (10.63 * 1000) / time;
51
+ let standard = "";
52
+ if (speed > 4) {
53
+ standard = "fast 3g";
54
+ } else if (speed > 0 && speed <= 4) {
55
+ standard = "slow 3g";
56
+ }
57
+ isLoading.value = false;
58
+ ElMessage({
59
+ message: `当前网速:${parseInt(`${speed}`)}kb/s ${standard} 未连接内网,当前网速情况:外网speed ${speed} + "kb"`,
60
+ type: 'success',
61
+ offset: 100,
62
+ duration: 2000
63
+ });
64
+ } catch (error) {
65
+ console.log("未知错误");
66
+ }
67
+ }
68
+ }
69
+ </script>
70
+
71
+ <style>
72
+ .loading {
73
+ width: 200px;
74
+ height: 40px;
75
+ margin: 0 auto;
76
+ margin-top: 100px;
77
+ }
78
+
79
+ .loading span {
80
+ display: inline-block;
81
+ width: 8px;
82
+ height: 100%;
83
+ border-radius: 4px;
84
+ background: lightgreen;
85
+ -webkit-animation: load 1s ease infinite;
86
+ }
87
+
88
+ @-webkit-keyframes load {
89
+
90
+ 0%,
91
+ 100% {
92
+ height: 40px;
93
+ background: lightgreen;
94
+ }
95
+
96
+ 50% {
97
+ height: 70px;
98
+ margin: -15px 0;
99
+ background: lightblue;
100
+ }
101
+ }
102
+
103
+ .loading span:nth-child(2) {
104
+ -webkit-animation-delay: 0.2s;
105
+ }
106
+
107
+ .loading span:nth-child(3) {
108
+ -webkit-animation-delay: 0.4s;
109
+ }
110
+
111
+ .loading span:nth-child(4) {
112
+ -webkit-animation-delay: 0.6s;
113
+ }
114
+
115
+ .loading span:nth-child(5) {
116
+ -webkit-animation-delay: 0.8s;
117
+ }
118
+ </style>
package/src/api.ts ADDED
@@ -0,0 +1,23 @@
1
+ import axios from "axios";
2
+
3
+ const io = axios.create({
4
+ timeout: 3000,
5
+ headers: { "cache-control": "no-cache" },
6
+ });
7
+
8
+ let start: number, end: number;
9
+ io.interceptors.request.use((request) => {
10
+ start = new Date().getTime();
11
+ return request;
12
+ });
13
+
14
+ io.interceptors.response.use((resp: any) => {
15
+ end = new Date().getTime();
16
+ resp.time = {
17
+ start: start,
18
+ end: end,
19
+ };
20
+ return resp;
21
+ });
22
+
23
+ export default io;
package/src/main.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { createApp } from 'vue'
2
+ import 'element-plus/dist/index.css'
3
+
4
+ import App from './App.vue'
5
+ createApp(App).mount('#app')
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+ "jsx": "preserve",
16
+
17
+ /* Linting */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noFallthroughCasesInSwitch": true
22
+ },
23
+ "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
24
+ "references": [{ "path": "./tsconfig.node.json" }]
25
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true
8
+ },
9
+ "include": ["vite.config.ts"]
10
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from 'vite'
2
+ import vue from '@vitejs/plugin-vue'
3
+
4
+ // https://vitejs.dev/config/
5
+ export default defineConfig({
6
+ plugins: [vue()],
7
+ })