Browse Source

refactor: ♻️ 监听屏幕点击代码修改

pull/1/head
jiangx 3 years ago
parent
commit
f089778b8b
  1. 27
      src/components/PublicComponent/PublicComponent.vue
  2. 20
      src/composables/useHandleScreen.ts
  3. 2
      src/store/root/getters.ts
  4. 5
      src/store/root/state.ts

27
src/components/PublicComponent/PublicComponent.vue

@ -27,19 +27,9 @@ const AutoBackNotification = defineAsyncComponent(() => import('@/base/AutoBackN
const router = useRouter() const router = useRouter()
const route = useRoute() const route = useRoute()
const store = useRootStore() const store = useRootStore()
const { language, showSearch, showDetail, mapStatus, nativeMethods } = storeToRefs(store)
const {
checkHandleScreen,
showCountDownDialog,
title,
toIndexTime,
toWallpaperTime,
isWallpaper,
setLogout,
resetClickNumber,
logout,
sleepToWallpaper
} = useHandleScreen(handleScreen)
const { language, showSearch, showDetail } = storeToRefs(store)
const { checkHandleScreen, showCountDownDialog, title, toIndexTime, toWallpaperTime, isWallpaper, setLogout, resetClickNumber, logout } =
useHandleScreen(handleScreen)
// //
function handleScreen() { function handleScreen() {
@ -64,17 +54,6 @@ onBeforeUnmount(() => {
window.removeEventListener('touchend', checkHandleScreen) window.removeEventListener('touchend', checkHandleScreen)
}) })
watch(mapStatus, async newVal => {
//便
if (newVal) {
if (!nativeMethods.value?.hasProgram()) {
return
}
await sleepToWallpaper()
nativeMethods.value?.goScreenSave()
}
})
watch(route, to => { watch(route, to => {
if (to.fullPath === '/' || to.fullPath === '/nav') { if (to.fullPath === '/' || to.fullPath === '/nav') {
window?.Map_QM?.startRender() window?.Map_QM?.startRender()

20
src/composables/useHandleScreen.ts

@ -12,7 +12,7 @@ export const useHandleScreen = (callback: () => void) => {
const router = useRouter() const router = useRouter()
const store = useRootStore() const store = useRootStore()
const { isAndroid, nativeMethods } = toRefs(store)
const { device, nativeMethods, mapStatus } = toRefs(store)
const { logout, resetClickNumber, setLogout, addTotalClick } = useLogout() const { logout, resetClickNumber, setLogout, addTotalClick } = useLogout()
@ -59,7 +59,7 @@ export const useHandleScreen = (callback: () => void) => {
window.sleepToWallpaper = sleepToWallpaper window.sleepToWallpaper = sleepToWallpaper
async function checkHandleScreen(e: TouchEvent) { async function checkHandleScreen(e: TouchEvent) {
!isAndroid && addTotalClick(e)
device.value.label === 'windows' && addTotalClick(e)
toIndexTime.value = totalTime.value[0] toIndexTime.value = totalTime.value[0]
toWallpaperTime.value = totalTime.value[1] toWallpaperTime.value = totalTime.value[1]
@ -85,10 +85,17 @@ export const useHandleScreen = (callback: () => void) => {
//监听时间 大于等于0且小于等于5时显示弹框 //监听时间 大于等于0且小于等于5时显示弹框
watch([toIndexTime, toWallpaperTime], ([indexTime, wallpaperTime]) => { watch([toIndexTime, toWallpaperTime], ([indexTime, wallpaperTime]) => {
if ((indexTime >= MIN_TIME && indexTime <= MAX_TIME) || (wallpaperTime >= MIN_TIME && wallpaperTime <= MAX_TIME)) {
showCountDownDialog.value = true
} else {
showCountDownDialog.value = false
showCountDownDialog.value = (indexTime >= MIN_TIME && indexTime <= MAX_TIME) || (wallpaperTime >= MIN_TIME && wallpaperTime <= MAX_TIME)
})
watch(mapStatus, async (newVal: boolean) => {
//当地图加载成功之后自动触发一次屏保弹框以便能进入屏保
if (newVal) {
if (!nativeMethods.value?.hasProgram()) {
return
}
await sleepToWallpaper()
nativeMethods.value?.goScreenSave()
} }
}) })
@ -111,7 +118,6 @@ export const useHandleScreen = (callback: () => void) => {
logout, logout,
checkHandleScreen, checkHandleScreen,
resetClickNumber, resetClickNumber,
sleepToWallpaper,
setLogout setLogout
} }
} }

2
src/store/root/getters.ts

@ -14,7 +14,7 @@ export type GenGetters = CreateGetters<State, GettersMap>
export const getters: GenGetters = { export const getters: GenGetters = {
nativeMethods() { nativeMethods() {
if (this.isAndroid) {
if (this.device.label === 'android') {
return window.android return window.android
} }
return window.chrome?.webview?.hostObjects?.sync?.csobj return window.chrome?.webview?.hostObjects?.sync?.csobj

5
src/store/root/state.ts

@ -1,5 +1,4 @@
import type { GroupList, BrandRes } from '@/http/api/brand/types' import type { GroupList, BrandRes } from '@/http/api/brand/types'
import { isAndroid } from '@/utils/utils'
export interface State { export interface State {
shopList: Readonly<Shop[]> //店铺列表 shopList: Readonly<Shop[]> //店铺列表
@ -16,7 +15,6 @@ export interface State {
mapStatus: boolean //地图加载是否成功 mapStatus: boolean //地图加载是否成功
device: Device //当前设备信息 device: Device //当前设备信息
shop: Shop //店铺信息 shop: Shop //店铺信息
isAndroid: boolean
} }
export const state = (): State => ({ export const state = (): State => ({
@ -33,6 +31,5 @@ export const state = (): State => ({
config: {} as Config, config: {} as Config,
mapStatus: false, mapStatus: false,
device: {} as Device, device: {} as Device,
shop: {} as Shop,
isAndroid: isAndroid()
shop: {} as Shop
}) })

Loading…
Cancel
Save