feat(layout): 重构页面布局与音乐播放组件
将 PlayMusic 组件迁移至 layout/RightButton 并重构成通用右下角按钮组件, 提取音乐播放逻辑到独立 hook `usePlayMusic`,优化模态框提示逻辑并统一滚动行为。
This commit is contained in:
65
src/layout/useMounted.ts
Normal file
65
src/layout/useMounted.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import type { Ref } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { onMounted, provide, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { loadingKey, loadingState } from '@/components/Loading'
|
||||
import useStore from '@/store'
|
||||
import { themeChange } from '@/utils'
|
||||
|
||||
export function useMounted(tipDialog: Ref<any>) {
|
||||
provide(loadingKey, loadingState)
|
||||
const globalConfig = useStore().globalConfig
|
||||
const prizeConfig = useStore().prizeConfig
|
||||
const system = useStore().system
|
||||
const { getTheme: localTheme } = storeToRefs(globalConfig)
|
||||
const { getPrizeConfig: prizeList } = storeToRefs(prizeConfig)
|
||||
const tipDesc = ref('')
|
||||
const { t } = useI18n()
|
||||
// 设置当前奖列表
|
||||
function setCurrentPrize() {
|
||||
if (prizeList.value.length <= 0) {
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < prizeList.value.length; i++) {
|
||||
if (!prizeList.value[i].isUsed) {
|
||||
prizeConfig.setCurrentPrize(prizeList.value[i])
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// 判断是否手机端访问
|
||||
function judgeMobile() {
|
||||
const ua = navigator.userAgent
|
||||
const isAndroid = ua.includes('Android') || ua.includes('Adr')
|
||||
const isIOS = !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
|
||||
|
||||
system.setIsMobile(isAndroid || isIOS)
|
||||
|
||||
return isAndroid || isIOS
|
||||
}
|
||||
// 判断是否chrome或者edge访问
|
||||
function judgeChromeOrEdge() {
|
||||
const ua = navigator.userAgent
|
||||
const isChrome = ua.includes('Chrome')
|
||||
const isEdge = ua.includes('Edg')
|
||||
|
||||
system.setIsChrome(isChrome)
|
||||
|
||||
return isChrome || isEdge
|
||||
}
|
||||
onMounted(() => {
|
||||
themeChange(localTheme.value.name)
|
||||
setCurrentPrize()
|
||||
if (judgeMobile()) {
|
||||
tipDialog.value.showDialog()
|
||||
tipDesc.value = t('dialog.dialogPCWeb')
|
||||
}
|
||||
else if (!judgeChromeOrEdge()) {
|
||||
tipDialog.value.showDialog()
|
||||
tipDesc.value = t('dialog.dialogLatestBrowser')
|
||||
}
|
||||
})
|
||||
|
||||
return { tipDesc }
|
||||
}
|
||||
Reference in New Issue
Block a user