2021-01-13 12:01:02 +08:00
|
|
|
import { toRef, inject, provide, reactive, watchEffect } from 'vue'
|
2021-04-05 17:59:04 +08:00
|
|
|
import { useBreakpoint, useMemo } from 'vooks'
|
|
|
|
|
2021-06-05 12:05:41 +08:00
|
|
|
export function useIsMobile () {
|
2021-04-05 17:59:04 +08:00
|
|
|
const breakpointRef = useBreakpoint()
|
|
|
|
return useMemo(() => {
|
|
|
|
return breakpointRef.value === 'xs'
|
|
|
|
})
|
|
|
|
}
|
2021-01-13 12:01:02 +08:00
|
|
|
|
2021-06-05 12:05:41 +08:00
|
|
|
export function useIsTablet () {
|
2021-04-06 01:31:09 +08:00
|
|
|
const breakpointRef = useBreakpoint()
|
|
|
|
return useMemo(() => {
|
2021-06-05 12:05:41 +08:00
|
|
|
return breakpointRef.value === 's'
|
2021-04-06 01:31:09 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-06-05 12:05:41 +08:00
|
|
|
export function useIsSmallDesktop () {
|
2021-04-06 01:31:09 +08:00
|
|
|
const breakpointRef = useBreakpoint()
|
|
|
|
return useMemo(() => {
|
2021-06-05 12:05:41 +08:00
|
|
|
return breakpointRef.value === 'm'
|
2021-04-06 01:31:09 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-13 12:01:02 +08:00
|
|
|
export const i18n = function (data) {
|
|
|
|
const localeReactive = inject('i18n', null)
|
|
|
|
return {
|
|
|
|
locale: toRef(localeReactive, 'locale'),
|
|
|
|
t (key) {
|
|
|
|
const { locale } = localeReactive
|
|
|
|
return data[locale][key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i18n.provide = function (localeRef) {
|
|
|
|
const localeReactive = reactive({})
|
|
|
|
watchEffect(() => {
|
|
|
|
localeReactive.locale = localeRef.value
|
|
|
|
})
|
|
|
|
provide('i18n', localeReactive)
|
|
|
|
}
|