From c59f86c69876dbfe6ad8678cc8c85d5e599b5ef8 Mon Sep 17 00:00:00 2001
From: linjinyuan <2841541624@qq.com>
Date: Thu, 8 Sep 2022 11:27:26 +0800
Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=B0=8F=E7=A8=8B=E5=BA=8F=E3=80=91--?=
=?UTF-8?q?=20=E6=96=B0=E5=A2=9Etab=EF=BC=8Ctbs=E7=BB=84=E4=BB=B6=EF=BC=8C?=
=?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=B7=A6=E5=8F=B3=E6=BB=91=E5=8A=A8=E5=88=87?=
=?UTF-8?q?=E6=8D=A2tab?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/src/components/tab/tab.vue | 79 ++++++
app/src/components/tabs/tabs.vue | 405 +++++++++++++++++++++++++++++++
app/src/hooks/useTouch.ts | 73 ++++++
app/src/utils/util.ts | 23 ++
4 files changed, 580 insertions(+)
create mode 100644 app/src/components/tab/tab.vue
create mode 100644 app/src/components/tabs/tabs.vue
create mode 100644 app/src/hooks/useTouch.ts
create mode 100644 app/src/utils/util.ts
diff --git a/app/src/components/tab/tab.vue b/app/src/components/tab/tab.vue
new file mode 100644
index 00000000..0d752bdc
--- /dev/null
+++ b/app/src/components/tab/tab.vue
@@ -0,0 +1,79 @@
+
+
+
+
+
+
+
+
+
diff --git a/app/src/components/tabs/tabs.vue b/app/src/components/tabs/tabs.vue
new file mode 100644
index 00000000..8b5f1890
--- /dev/null
+++ b/app/src/components/tabs/tabs.vue
@@ -0,0 +1,405 @@
+
+
+
+
+
+
+
+
+ {{ item[name] || item['name']}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/hooks/useTouch.ts b/app/src/hooks/useTouch.ts
new file mode 100644
index 00000000..509764a9
--- /dev/null
+++ b/app/src/hooks/useTouch.ts
@@ -0,0 +1,73 @@
+import { reactive } from "vue"
+
+/**
+ * @description 触碰屏幕钩子函数
+ * @return { Function } 暴露钩子
+ */
+export function useTouch () {
+ // 最小移动距离
+ const MIN_DISTANCE = 10;
+
+ const touch = reactive({
+ direction: '',
+ deltaX: 0,
+ deltaY: 0,
+ offsetX: 0,
+ offsetY: 0
+ })
+
+ /**
+ * @description 计算距离
+ * @return { string } 空字符串
+ */
+ const getDirection = (x: number, y: number) => {
+ if (x > y && x > MIN_DISTANCE) {
+ return 'horizontal';
+ }
+ if (y > x && y > MIN_DISTANCE) {
+ return 'vertical';
+ }
+ return '';
+ }
+
+ /**
+ * @description 重置参数
+ */
+ const resetTouchStatus = () => {
+ touch.direction = '';
+ touch.deltaX = 0;
+ touch.deltaY = 0;
+ touch.offsetX = 0;
+ touch.offsetY = 0;
+ }
+
+ /**
+ * @description 触发
+ */
+ const touchStart = (event: any) => {
+ resetTouchStatus();
+ const events = event.touches[0];
+ touch.startX = events.clientX;
+ touch.startY = events.clientY;
+ }
+
+ /**
+ * @description 移动
+ */
+ const touchMove = (event: any) => {
+ const events = event.touches[0];
+ touch.deltaX = events.clientX - touch.startX;
+ touch.deltaY = events.clientY - touch.startY;
+ touch.offsetX = Math.abs(touch.deltaX);
+ touch.offsetY = Math.abs(touch.deltaY);
+ touch.direction =
+ touch.direction || getDirection(touch.offsetX, touch.offsetY);
+ }
+
+ return {
+ touch,
+ resetTouchStatus,
+ touchStart,
+ touchMove
+ }
+}
diff --git a/app/src/utils/util.ts b/app/src/utils/util.ts
new file mode 100644
index 00000000..b7d35726
--- /dev/null
+++ b/app/src/utils/util.ts
@@ -0,0 +1,23 @@
+/**
+ * @description 获取元素节点信息(在组件中的元素必须要传ctx)
+ * @param { String } selector 选择器 '.app' | '#app'
+ * @param { Boolean } all 是否多选
+ * @param { ctx } context 当前组件实例
+ */
+export const getRect = (selector: string, all: boolean = false, context?: any) => {
+ return new Promise((resolve, reject) => {
+ let qurey = uni.createSelectorQuery()
+ if (context) {
+ qurey = uni.createSelectorQuery().in(context)
+ }
+ qurey[all ? 'selectAll' : 'select'](selector).boundingClientRect(function(rect) {
+ if (all && Array.isArray(rect) && rect.length) {
+ return resolve(rect)
+ }
+ if (!all && rect) {
+ return resolve(rect)
+ }
+ reject('找不到元素')
+ }).exec()
+ })
+}
\ No newline at end of file