From 6aa352cc47ee002f68dffe493a0ab324ad8e4934 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=86=8A=E7=8C=AB?=
<13581431+xiongmao1988@user.noreply.gitee.com>
Date: Sun, 18 Feb 2024 09:09:09 +0800
Subject: [PATCH] =?UTF-8?q?=E9=A1=B5=E7=9C=89=E6=96=87=E5=AD=97+=E8=87=AA?=
=?UTF-8?q?=E5=8A=A8=E6=89=93=E5=BC=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 2 +-
package.json | 2 +-
src/axios/ws.ts | 46 +++++++++++++++++++++++++++++++++++++++++++++
src/views/index.vue | 10 ++++++++++
4 files changed, 58 insertions(+), 2 deletions(-)
create mode 100644 src/axios/ws.ts
diff --git a/index.html b/index.html
index 6cb0bdd..f09437d 100644
--- a/index.html
+++ b/index.html
@@ -3,7 +3,7 @@
-
+ 瑞鞍星医疗科技
diff --git a/package.json b/package.json
index 64bfc92..e76120e 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"scripts": {
- "serve": "vite",
+ "serve": "vite --open",
"build": "run-p type-check build-only",
"preview": "vite preview",
"build-only": "vite build",
diff --git a/src/axios/ws.ts b/src/axios/ws.ts
new file mode 100644
index 0000000..07a0189
--- /dev/null
+++ b/src/axios/ws.ts
@@ -0,0 +1,46 @@
+let ws: WebSocket;
+
+function init(url: string | URL, protocols?: string | string[]) {
+ return new Promise(resolve => {
+ try {
+ ws = new WebSocket(url);
+ resolve(true)
+ } catch (e) {
+ console.log(e)
+ }
+ })
+}
+
+function close(code?: number, reason?: string) {
+ ws.close(code, reason)
+}
+
+function send(data: string | ArrayBufferLike | Blob | ArrayBufferView) {
+ ws.send(data)
+}
+
+function closeListener(cb: any) {
+ ws.onclose = cb
+}
+
+function openListener(cb: any) {
+ ws.onopen = cb
+}
+
+function errorListener(cb: any) {
+ ws.onerror = cb
+}
+
+function messageListener(cb: any) {
+ ws.onmessage = cb
+}
+
+export const wsApi= {
+ init,
+ close,
+ send,
+ closeListener,
+ openListener,
+ errorListener,
+ messageListener
+}
\ No newline at end of file
diff --git a/src/views/index.vue b/src/views/index.vue
index beaaa2b..ad13498 100644
--- a/src/views/index.vue
+++ b/src/views/index.vue
@@ -65,6 +65,7 @@ import { ElMessage, ElMessageBox } from 'element-plus'
import { useLoginStore } from '@/stores/user-info-store'
import { getHospitalsData } from '@/static-data/core'
import userInfoForm from '@/components/user-info.vue'
+import {wsApi} from "@/axios/ws";
const router = useRouter()
const route = useRoute()
@@ -161,6 +162,15 @@ const userCommand = (e: string) => {
break;
}
}
+
+/*wsApi.init("").then(() => {
+ wsApi.openListener(fn1);
+})
+
+
+function fn1(res:any) {
+ console.log(res);
+}*/