mirror of
https://github.com/wmn1525/grasscutterTools.git
synced 2024-11-25 17:35:25 +00:00
:add wss send
This commit is contained in:
parent
7e20c25607
commit
45d44f6cc6
@ -1,13 +1,27 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref } from 'vue'
|
import { reactive, ref, watch } from 'vue'
|
||||||
import Header from '@/components/Header/index.vue'
|
import Header from '@/components/Header/index.vue'
|
||||||
import commuse from './components/commuse.vue'
|
import commuse from './components/commuse.vue'
|
||||||
import { useWebSocket } from '@vueuse/core'
|
import { Message } from '@arco-design/web-vue'
|
||||||
|
import { useAppStore, useUserStore } from '@/store'
|
||||||
|
const appStore = useAppStore()
|
||||||
|
|
||||||
var wss = ref('')
|
var wss = ref('')
|
||||||
|
|
||||||
function login() {
|
function login() {
|
||||||
const { status, data, send, open, close } = useWebSocket(wss.value)
|
if (wss.value) {
|
||||||
|
appStore.socketConnect(wss.value)
|
||||||
|
} else {
|
||||||
|
Message.error(`地址不正确`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function send() {
|
||||||
|
const send_msg = {
|
||||||
|
type: 'CMD',
|
||||||
|
data: 'g',
|
||||||
|
}
|
||||||
|
const send_msg_str = JSON.stringify(send_msg)
|
||||||
|
appStore.socketSend(send_msg_str)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
@ -25,12 +39,15 @@ function login() {
|
|||||||
<div>
|
<div>
|
||||||
<div class="commuse-item">
|
<div class="commuse-item">
|
||||||
<div class="text-slate-900 dark:text-slate-100"> wss: </div>
|
<div class="text-slate-900 dark:text-slate-100"> wss: </div>
|
||||||
<n-input v-model:value="wss" clearable placeholder="请从控制台获取" />
|
<a-input v-model="wss" clearable placeholder="请从控制台获取" />
|
||||||
</div>
|
</div>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<n-button type="tertiary" @click="login"> 登录 </n-button>
|
<a-button type="outline" @click="login"> 登录 </a-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<a-button type="outline" @click="send"> send </a-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import piniaStore from '@/store/index'
|
import piniaStore from '@/store/index'
|
||||||
import { AppState } from './types';
|
import { AppState } from './types';
|
||||||
|
import { useWebSocket } from '@vueuse/core'
|
||||||
|
import { watch } from 'vue'
|
||||||
|
|
||||||
export const useAppStore = defineStore(
|
export const useAppStore = defineStore(
|
||||||
// 唯一ID
|
// 唯一ID
|
||||||
@ -9,7 +11,8 @@ export const useAppStore = defineStore(
|
|||||||
state: () => ({
|
state: () => ({
|
||||||
title: "FastVue3,一个快速开箱即用的Vue3+Vite模板",
|
title: "FastVue3,一个快速开箱即用的Vue3+Vite模板",
|
||||||
h1: 'Vue3+Vite2.x+Ts+Pinia大厂开发必备',
|
h1: 'Vue3+Vite2.x+Ts+Pinia大厂开发必备',
|
||||||
theme: 'dark'
|
theme: 'dark',
|
||||||
|
send: (data: string | ArrayBuffer | Blob, useBuffer?: boolean | undefined) => { }
|
||||||
}),
|
}),
|
||||||
getters: {},
|
getters: {},
|
||||||
actions: {
|
actions: {
|
||||||
@ -33,6 +36,19 @@ export const useAppStore = defineStore(
|
|||||||
localStorage.setItem('theme', this.theme)
|
localStorage.setItem('theme', this.theme)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
socketConnect(wss: string) {
|
||||||
|
const { status, data, send, open, close } = useWebSocket(wss)
|
||||||
|
watch(
|
||||||
|
data,
|
||||||
|
(v) => {
|
||||||
|
console.log(v);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
this.send = send
|
||||||
|
},
|
||||||
|
socketSend(str: string) {
|
||||||
|
this.send(str)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user