处理第一次打开online报错问题

This commit is contained in:
hejin 2025-10-19 12:24:30 +08:00
parent ed69f0ff60
commit 8b97e5d91e
2 changed files with 37 additions and 29 deletions

View File

@ -1,4 +1,4 @@
NODE_ENV='development'
VITE_APP_TITLE='开发环境'
VITE_APP_BASE_API='http://127.0.0.1:8099'
VITE_APP_SCOKET='ws://1.92.99.15:8099/ws/asset/'
VITE_APP_BASE_API='https://admin.cdtrucktralier.com'
VITE_APP_SCOKET='wss://admin.cdtrucktralier.com/ws/asset/'

View File

@ -95,15 +95,21 @@ export const useScoketMsg = defineStore('scoketMsg', () => {
const chatMain = ref({})
const scoketInit = () => {
return new Promise((reslove,reject) => {
scoket.value = uni.connectSocket({
url: `${import.meta.env.VITE_APP_SCOKET}${onlyId.value}`,
success: () => {
console.log('创建链接成功')
},
fail: (err) => {
reject(err)
console.log('创建失败',err)
}
})
scoket.value.onOpen((e) => {
reslove()
console.log('链接打开')
})
scoket.value.onMessage((e) => {
if (e.data === '连接成功') {
return
@ -123,8 +129,10 @@ export const useScoketMsg = defineStore('scoketMsg', () => {
scoket.value.onError((err) => {
console.log('链接错误',err)
})
})
}
const send = (text) => {
console.log(text)
return new Promise((reslove,reject) => {
scoket.value.send({
data: text,