Skip to content

Commit

Permalink
fix(components): 修复Tab在移动端设备无法点击的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Soybean committed Feb 7, 2022
1 parent e93b94c commit 2c9660f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"print-js": "^1.6.0",
"qs": "^6.10.3",
"swiper": "^8.0.3",
"ua-parser-js": "^1.0.2",
"vditor": "^3.8.11",
"vue": "^3.2.29",
"vue-router": "^4.0.12",
Expand All @@ -55,6 +56,7 @@
"@types/crypto-js": "^4.1.0",
"@types/node": "^17.0.15",
"@types/qs": "^6.9.7",
"@types/ua-parser-js": "^0.7.36",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"@vitejs/plugin-vue": "^2.1.0",
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/components/custom/BetterScroll/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ function initBetterScroll() {
}
// 滚动元素发生变化,刷新BS
const { width: wrapWidth } = useElementSize(bsWrap);
const { width, height } = useElementSize(bsContent);
watch([() => width.value, () => height.value], () => {
watch([() => wrapWidth.value, () => width.value, () => height.value], () => {
if (instance.value) {
instance.value.refresh();
}
Expand Down
12 changes: 6 additions & 6 deletions src/composables/common/system.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useBreakpoints, breakpointsTailwind } from '@vueuse/core';
import UAParser from 'ua-parser-js';

interface AppInfo {
/** 项目名称 */
Expand All @@ -20,9 +20,9 @@ export function useAppInfo(): AppInfo {
};
}

/** 是否是移动端 */
export function useIsMobile() {
const breakpoints = useBreakpoints(breakpointsTailwind);
const isMobile = breakpoints.smaller('lg');
return isMobile;
/** 获取设备信息 */
export function useDeviceInfo() {
const parser = new UAParser();
const result = parser.getResult();
return result;
}
7 changes: 4 additions & 3 deletions src/layouts/common/GlobalTab/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<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">
<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" />
</better-scroll>
</div>
Expand All @@ -15,20 +15,21 @@ import { useRoute } from 'vue-router';
import { useElementBounding } from '@vueuse/core';
import { DarkModeContainer, BetterScroll } from '@/components';
import { useThemeStore, useTabStore } from '@/store';
import { useIsMobile } from '@/composables';
import { useDeviceInfo } from '@/composables';
import type { ExposeBetterScroll } from '@/interface';
import { TabDetail, ReloadButton } from './components';
const route = useRoute();
const theme = useThemeStore();
const tab = useTabStore();
const deviceInfo = useDeviceInfo();
const bsWrapper = ref<HTMLElement>();
const { width: bsWrapperWidth, left: bsWrapperLeft } = useElementBounding(bsWrapper);
const bsScroll = ref<ExposeBetterScroll>();
const isMobile = useIsMobile();
const canClick = Boolean(deviceInfo.device.type);
function handleScroll(clientX: number) {
const currentX = clientX - bsWrapperLeft.value;
Expand Down

1 comment on commit 2c9660f

@vercel
Copy link

@vercel vercel bot commented on 2c9660f Feb 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.