feat: ✨ 手机端访问二维码受websocket连接状态控制 (#189)
This commit is contained in:
@@ -2,13 +2,19 @@
|
|||||||
import { useFullscreen } from '@vueuse/core'
|
import { useFullscreen } from '@vueuse/core'
|
||||||
import { useQRCode } from '@vueuse/integrations/useQRCode'
|
import { useQRCode } from '@vueuse/integrations/useQRCode'
|
||||||
import { Maximize, Minimize, TabletSmartphone } from 'lucide-vue-next'
|
import { Maximize, Minimize, TabletSmartphone } from 'lucide-vue-next'
|
||||||
|
import { storeToRefs } from 'pinia'
|
||||||
import { onMounted, ref, shallowRef, watch } from 'vue'
|
import { onMounted, ref, shallowRef, watch } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import CustomDialog from '@/components/Dialog/index.vue'
|
import CustomDialog from '@/components/Dialog/index.vue'
|
||||||
|
import useStore from '@/store'
|
||||||
import { getOriginUrl, getUniqueSignature } from '@/utils/auth'
|
import { getOriginUrl, getUniqueSignature } from '@/utils/auth'
|
||||||
import { usePlayMusic } from './usePlayMusic'
|
import { usePlayMusic } from './usePlayMusic'
|
||||||
|
|
||||||
|
const serverConfig = useStore().serverConfig
|
||||||
|
const {
|
||||||
|
getServerStatus: serverStatus,
|
||||||
|
} = storeToRefs(serverConfig)
|
||||||
const { playMusic, currentMusic, nextPlay } = usePlayMusic()
|
const { playMusic, currentMusic, nextPlay } = usePlayMusic()
|
||||||
const { isFullscreen, toggle: toggleScreen } = useFullscreen()
|
const { isFullscreen, toggle: toggleScreen } = useFullscreen()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
@@ -110,7 +116,7 @@ onMounted(() => {
|
|||||||
<svg-icon :name="currentMusic.paused ? 'play' : 'pause'" />
|
<svg-icon :name="currentMusic.paused ? 'play' : 'pause'" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tooltip tooltip-left" data-tip="访问手机端">
|
<div v-if="serverStatus" class="tooltip tooltip-left" data-tip="访问手机端">
|
||||||
<div class="flex items-center justify-center w-10 h-10 p-0 m-0 cursor-pointer setting-container bg-slate-500/50 rounded-l-xl hover:bg-slate-500/80 hover:text-blue-400/90" @click="openMobileQrCode">
|
<div class="flex items-center justify-center w-10 h-10 p-0 m-0 cursor-pointer setting-container bg-slate-500/50 rounded-l-xl hover:bg-slate-500/80 hover:text-blue-400/90" @click="openMobileQrCode">
|
||||||
<TabletSmartphone />
|
<TabletSmartphone />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export const useServerConfig = defineStore('server', {
|
|||||||
serverConfig: {
|
serverConfig: {
|
||||||
serverList: defaultServerHostList,
|
serverList: defaultServerHostList,
|
||||||
currentServer: defaultServerHostList[0],
|
currentServer: defaultServerHostList[0],
|
||||||
|
serverStatus: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -20,6 +21,10 @@ export const useServerConfig = defineStore('server', {
|
|||||||
getCurrentServer(state) {
|
getCurrentServer(state) {
|
||||||
return state.serverConfig.currentServer
|
return state.serverConfig.currentServer
|
||||||
},
|
},
|
||||||
|
// 获取服务器状态
|
||||||
|
getServerStatus(state) {
|
||||||
|
return state.serverConfig.serverStatus
|
||||||
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@@ -36,11 +41,16 @@ export const useServerConfig = defineStore('server', {
|
|||||||
setCurrentServer(userServer: ServerType) {
|
setCurrentServer(userServer: ServerType) {
|
||||||
this.serverConfig.currentServer = userServer
|
this.serverConfig.currentServer = userServer
|
||||||
},
|
},
|
||||||
|
// 设置服务器状态
|
||||||
|
setServerStatus(status: boolean) {
|
||||||
|
this.serverConfig.serverStatus = status
|
||||||
|
},
|
||||||
// 重置所有配置
|
// 重置所有配置
|
||||||
resetDefault() {
|
resetDefault() {
|
||||||
this.serverConfig = {
|
this.serverConfig = {
|
||||||
serverList: defaultServerHostList,
|
serverList: defaultServerHostList,
|
||||||
currentServer: defaultServerHostList[0],
|
currentServer: defaultServerHostList[0],
|
||||||
|
serverStatus: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ import { IndexDb } from '@/utils/dexie'
|
|||||||
|
|
||||||
export function useViewModel() {
|
export function useViewModel() {
|
||||||
const serverConfig = useStore().serverConfig
|
const serverConfig = useStore().serverConfig
|
||||||
const { getServerList: serverList, getCurrentServer: currentServer } = storeToRefs(serverConfig)
|
const {
|
||||||
|
getServerList: serverList,
|
||||||
|
getCurrentServer: currentServer,
|
||||||
|
} = storeToRefs(serverConfig)
|
||||||
const currentServerValue = ref<ServerType>(cloneDeep(currentServer.value))
|
const currentServerValue = ref<ServerType>(cloneDeep(currentServer.value))
|
||||||
const wsUrl = ref<string>('ws://localhost:8080/echo')
|
const wsUrl = ref<string>('ws://localhost:8080/echo')
|
||||||
const msgList = ref<WsMsgData[]>([])
|
const msgList = ref<WsMsgData[]>([])
|
||||||
@@ -41,6 +44,16 @@ export function useViewModel() {
|
|||||||
currentServerValue.value.host = newValue
|
currentServerValue.value.host = newValue
|
||||||
serverConfig.updateServerList(currentServerValue.value)
|
serverConfig.updateServerList(currentServerValue.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => wsStatus.value,
|
||||||
|
(newValue) => {
|
||||||
|
if (newValue && (newValue.connected === true || newValue.connected === false)) {
|
||||||
|
serverConfig.setServerStatus(newValue.connected)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getAllMsg()
|
getAllMsg()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user