fix(components): 修复Tab在移动端设备无法点击的问题

This commit is contained in:
Soybean 2022-02-07 15:46:35 +08:00
parent e93b94cb24
commit 2c9660fdbf
5 changed files with 30 additions and 10 deletions

View File

@ -39,6 +39,7 @@
"print-js": "^1.6.0", "print-js": "^1.6.0",
"qs": "^6.10.3", "qs": "^6.10.3",
"swiper": "^8.0.3", "swiper": "^8.0.3",
"ua-parser-js": "^1.0.2",
"vditor": "^3.8.11", "vditor": "^3.8.11",
"vue": "^3.2.29", "vue": "^3.2.29",
"vue-router": "^4.0.12", "vue-router": "^4.0.12",
@ -55,6 +56,7 @@
"@types/crypto-js": "^4.1.0", "@types/crypto-js": "^4.1.0",
"@types/node": "^17.0.15", "@types/node": "^17.0.15",
"@types/qs": "^6.9.7", "@types/qs": "^6.9.7",
"@types/ua-parser-js": "^0.7.36",
"@typescript-eslint/eslint-plugin": "^5.10.2", "@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2", "@typescript-eslint/parser": "^5.10.2",
"@vitejs/plugin-vue": "^2.1.0", "@vitejs/plugin-vue": "^2.1.0",

View File

@ -12,6 +12,7 @@ specifiers:
'@types/crypto-js': ^4.1.0 '@types/crypto-js': ^4.1.0
'@types/node': ^17.0.15 '@types/node': ^17.0.15
'@types/qs': ^6.9.7 '@types/qs': ^6.9.7
'@types/ua-parser-js': ^0.7.36
'@typescript-eslint/eslint-plugin': ^5.10.2 '@typescript-eslint/eslint-plugin': ^5.10.2
'@typescript-eslint/parser': ^5.10.2 '@typescript-eslint/parser': ^5.10.2
'@vitejs/plugin-vue': ^2.1.0 '@vitejs/plugin-vue': ^2.1.0
@ -49,6 +50,7 @@ specifiers:
sass: ^1.49.7 sass: ^1.49.7
swiper: ^8.0.3 swiper: ^8.0.3
typescript: ^4.5.5 typescript: ^4.5.5
ua-parser-js: ^1.0.2
unplugin-icons: ^0.13.0 unplugin-icons: ^0.13.0
unplugin-vue-components: ^0.17.17 unplugin-vue-components: ^0.17.17
vditor: ^3.8.11 vditor: ^3.8.11
@ -80,6 +82,7 @@ dependencies:
print-js: registry.npmmirror.com/print-js/1.6.0 print-js: registry.npmmirror.com/print-js/1.6.0
qs: registry.npmmirror.com/qs/6.10.3 qs: registry.npmmirror.com/qs/6.10.3
swiper: registry.npmmirror.com/swiper/8.0.3 swiper: registry.npmmirror.com/swiper/8.0.3
ua-parser-js: registry.npmmirror.com/ua-parser-js/1.0.2
vditor: registry.npmmirror.com/vditor/3.8.11 vditor: registry.npmmirror.com/vditor/3.8.11
vue: registry.npmmirror.com/vue/3.2.29 vue: registry.npmmirror.com/vue/3.2.29
vue-router: registry.npmmirror.com/vue-router/4.0.12_vue@3.2.29 vue-router: registry.npmmirror.com/vue-router/4.0.12_vue@3.2.29
@ -96,6 +99,7 @@ devDependencies:
'@types/crypto-js': registry.npmmirror.com/@types/crypto-js/4.1.0 '@types/crypto-js': registry.npmmirror.com/@types/crypto-js/4.1.0
'@types/node': registry.npmmirror.com/@types/node/17.0.15 '@types/node': registry.npmmirror.com/@types/node/17.0.15
'@types/qs': registry.npmmirror.com/@types/qs/6.9.7 '@types/qs': registry.npmmirror.com/@types/qs/6.9.7
'@types/ua-parser-js': registry.npmmirror.com/@types/ua-parser-js/0.7.36
'@typescript-eslint/eslint-plugin': registry.npmmirror.com/@typescript-eslint/eslint-plugin/5.10.2_2595c2126aec4d4b6e944b931dabb4c2 '@typescript-eslint/eslint-plugin': registry.npmmirror.com/@typescript-eslint/eslint-plugin/5.10.2_2595c2126aec4d4b6e944b931dabb4c2
'@typescript-eslint/parser': registry.npmmirror.com/@typescript-eslint/parser/5.10.2_eslint@8.8.0+typescript@4.5.5 '@typescript-eslint/parser': registry.npmmirror.com/@typescript-eslint/parser/5.10.2_eslint@8.8.0+typescript@4.5.5
'@vitejs/plugin-vue': registry.npmmirror.com/@vitejs/plugin-vue/2.1.0_vite@2.7.13+vue@3.2.29 '@vitejs/plugin-vue': registry.npmmirror.com/@vitejs/plugin-vue/2.1.0_vite@2.7.13+vue@3.2.29
@ -2873,6 +2877,12 @@ packages:
version: 2.1.0 version: 2.1.0
dev: true dev: true
registry.npmmirror.com/@types/ua-parser-js/0.7.36:
resolution: {integrity: sha512-N1rW+njavs70y2cApeIw1vLMYXRwfBy+7trgavGuuTfOd7j1Yh7QTRc/yqsPl6ncokt72ZXuxEU0PiCp9bSwNQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@types/ua-parser-js/-/ua-parser-js-0.7.36.tgz}
name: '@types/ua-parser-js'
version: 0.7.36
dev: true
registry.npmmirror.com/@types/yargs-parser/20.2.1: registry.npmmirror.com/@types/yargs-parser/20.2.1:
resolution: {integrity: sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@types/yargs-parser/-/yargs-parser-20.2.1.tgz} resolution: {integrity: sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@types/yargs-parser/-/yargs-parser-20.2.1.tgz}
name: '@types/yargs-parser' name: '@types/yargs-parser'
@ -7087,6 +7097,12 @@ packages:
hasBin: true hasBin: true
dev: true dev: true
registry.npmmirror.com/ua-parser-js/1.0.2:
resolution: {integrity: sha512-00y/AXhx0/SsnI51fTc0rLRmafiGOM4/O+ny10Ps7f+j/b8p/ZY11ytMgznXkOVo4GQ+KwQG5UQLkLGirsACRg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/ua-parser-js/-/ua-parser-js-1.0.2.tgz}
name: ua-parser-js
version: 1.0.2
dev: false
registry.npmmirror.com/uglify-js/2.8.29: registry.npmmirror.com/uglify-js/2.8.29:
resolution: {integrity: sha1-KcVzMUgFe7Th913zW3qcty5qWd0=, registry: http://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/uglify-js/download/uglify-js-2.8.29.tgz} resolution: {integrity: sha1-KcVzMUgFe7Th913zW3qcty5qWd0=, registry: http://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/uglify-js/download/uglify-js-2.8.29.tgz}
name: uglify-js name: uglify-js

View File

@ -30,8 +30,9 @@ function initBetterScroll() {
} }
// BS // BS
const { width: wrapWidth } = useElementSize(bsWrap);
const { width, height } = useElementSize(bsContent); const { width, height } = useElementSize(bsContent);
watch([() => width.value, () => height.value], () => { watch([() => wrapWidth.value, () => width.value, () => height.value], () => {
if (instance.value) { if (instance.value) {
instance.value.refresh(); instance.value.refresh();
} }

View File

@ -1,4 +1,4 @@
import { useBreakpoints, breakpointsTailwind } from '@vueuse/core'; import UAParser from 'ua-parser-js';
interface AppInfo { interface AppInfo {
/** 项目名称 */ /** 项目名称 */
@ -20,9 +20,9 @@ export function useAppInfo(): AppInfo {
}; };
} }
/** 是否是移动端 */ /** 获取设备信息 */
export function useIsMobile() { export function useDeviceInfo() {
const breakpoints = useBreakpoints(breakpointsTailwind); const parser = new UAParser();
const isMobile = breakpoints.smaller('lg'); const result = parser.getResult();
return isMobile; return result;
} }

View File

@ -1,7 +1,7 @@
<template> <template>
<dark-mode-container class="global-tab flex-y-center w-full pl-16px" :style="{ height: theme.tab.height + 'px' }"> <dark-mode-container class="global-tab flex-y-center w-full pl-16px" :style="{ height: theme.tab.height + 'px' }">
<div ref="bsWrapper" class="flex-1-hidden h-full"> <div ref="bsWrapper" class="flex-1-hidden h-full">
<better-scroll ref="bsScroll" :options="{ scrollX: true, scrollY: false, click: isMobile }"> <better-scroll ref="bsScroll" :options="{ scrollX: true, scrollY: false, click: canClick }">
<tab-detail @scroll="handleScroll" /> <tab-detail @scroll="handleScroll" />
</better-scroll> </better-scroll>
</div> </div>
@ -15,20 +15,21 @@ import { useRoute } from 'vue-router';
import { useElementBounding } from '@vueuse/core'; import { useElementBounding } from '@vueuse/core';
import { DarkModeContainer, BetterScroll } from '@/components'; import { DarkModeContainer, BetterScroll } from '@/components';
import { useThemeStore, useTabStore } from '@/store'; import { useThemeStore, useTabStore } from '@/store';
import { useIsMobile } from '@/composables'; import { useDeviceInfo } from '@/composables';
import type { ExposeBetterScroll } from '@/interface'; import type { ExposeBetterScroll } from '@/interface';
import { TabDetail, ReloadButton } from './components'; import { TabDetail, ReloadButton } from './components';
const route = useRoute(); const route = useRoute();
const theme = useThemeStore(); const theme = useThemeStore();
const tab = useTabStore(); const tab = useTabStore();
const deviceInfo = useDeviceInfo();
const bsWrapper = ref<HTMLElement>(); const bsWrapper = ref<HTMLElement>();
const { width: bsWrapperWidth, left: bsWrapperLeft } = useElementBounding(bsWrapper); const { width: bsWrapperWidth, left: bsWrapperLeft } = useElementBounding(bsWrapper);
const bsScroll = ref<ExposeBetterScroll>(); const bsScroll = ref<ExposeBetterScroll>();
const isMobile = useIsMobile(); const canClick = Boolean(deviceInfo.device.type);
function handleScroll(clientX: number) { function handleScroll(clientX: number) {
const currentX = clientX - bsWrapperLeft.value; const currentX = clientX - bsWrapperLeft.value;