From 025d5aeeafe838ae102cc95e1b7e10f93110f1fc Mon Sep 17 00:00:00 2001 From: invalid w Date: Fri, 13 Sep 2024 16:11:52 +0800 Subject: [PATCH 01/24] =?UTF-8?q?chore(@vben/common-ui):=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=8B=96=E6=8B=BD=E6=A0=A1=E9=AA=8C=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/effects/common-ui/package.json | 1 + .../effects/common-ui/src/components/index.ts | 1 + .../components/verify/drag-verify/action.vue | 9 + .../src/components/verify/drag-verify/bar.vue | 9 + .../components/verify/drag-verify/content.vue | 14 + .../components/verify/drag-verify/index.vue | 314 ++++++++++++++++++ .../common-ui/src/components/verify/index.ts | 2 + .../common-ui/src/components/verify/typing.ts | 14 + .../components/verify/use-event-listener.ts | 61 ++++ .../src/router/routes/modules/examples.ts | 19 ++ .../examples/verify/drag-verify/index.vue | 36 ++ pnpm-lock.yaml | 3 + 12 files changed, 483 insertions(+) create mode 100644 packages/effects/common-ui/src/components/verify/drag-verify/action.vue create mode 100644 packages/effects/common-ui/src/components/verify/drag-verify/bar.vue create mode 100644 packages/effects/common-ui/src/components/verify/drag-verify/content.vue create mode 100644 packages/effects/common-ui/src/components/verify/drag-verify/index.vue create mode 100644 packages/effects/common-ui/src/components/verify/index.ts create mode 100644 packages/effects/common-ui/src/components/verify/typing.ts create mode 100644 packages/effects/common-ui/src/components/verify/use-event-listener.ts create mode 100644 playground/src/views/examples/verify/drag-verify/index.vue diff --git a/packages/effects/common-ui/package.json b/packages/effects/common-ui/package.json index 9bc0a8a03de..10d3d1049fb 100644 --- a/packages/effects/common-ui/package.json +++ b/packages/effects/common-ui/package.json @@ -27,6 +27,7 @@ "@vben/icons": "workspace:*", "@vben/locales": "workspace:*", "@vben/types": "workspace:*", + "@vueuse/core": "^11.0.3", "@vueuse/integrations": "^11.0.3", "qrcode": "^1.5.4", "vue": "^3.5.4", diff --git a/packages/effects/common-ui/src/components/index.ts b/packages/effects/common-ui/src/components/index.ts index 865adf409db..cefe1ce3fc6 100644 --- a/packages/effects/common-ui/src/components/index.ts +++ b/packages/effects/common-ui/src/components/index.ts @@ -1,6 +1,7 @@ export * from './captcha'; export * from './ellipsis-text'; export * from './page'; +export * from './verify'; export * from '@vben-core/form-ui'; export * from '@vben-core/popup-ui'; diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/action.vue b/packages/effects/common-ui/src/components/verify/drag-verify/action.vue new file mode 100644 index 00000000000..7e861709390 --- /dev/null +++ b/packages/effects/common-ui/src/components/verify/drag-verify/action.vue @@ -0,0 +1,9 @@ + + + + + diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/bar.vue b/packages/effects/common-ui/src/components/verify/drag-verify/bar.vue new file mode 100644 index 00000000000..e1617fbe5fa --- /dev/null +++ b/packages/effects/common-ui/src/components/verify/drag-verify/bar.vue @@ -0,0 +1,9 @@ + + + + + diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/content.vue b/packages/effects/common-ui/src/components/verify/drag-verify/content.vue new file mode 100644 index 00000000000..fba8e411da2 --- /dev/null +++ b/packages/effects/common-ui/src/components/verify/drag-verify/content.vue @@ -0,0 +1,14 @@ + + + + + diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue new file mode 100644 index 00000000000..ec073a8bb0d --- /dev/null +++ b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue @@ -0,0 +1,314 @@ + + + diff --git a/packages/effects/common-ui/src/components/verify/index.ts b/packages/effects/common-ui/src/components/verify/index.ts new file mode 100644 index 00000000000..991ba7a6be1 --- /dev/null +++ b/packages/effects/common-ui/src/components/verify/index.ts @@ -0,0 +1,2 @@ +export { default as DragVerify } from './drag-verify/index.vue'; +export * from './typing'; diff --git a/packages/effects/common-ui/src/components/verify/typing.ts b/packages/effects/common-ui/src/components/verify/typing.ts new file mode 100644 index 00000000000..42256968bef --- /dev/null +++ b/packages/effects/common-ui/src/components/verify/typing.ts @@ -0,0 +1,14 @@ +export interface DragVerifyActionType { + resume: () => void; +} + +export interface VerifyPassingData { + isPassing: boolean; + time: number; +} + +export interface VerifyMoveData { + event: MouseEvent | TouchEvent; + moveDistance: number; + moveX: number; +} diff --git a/packages/effects/common-ui/src/components/verify/use-event-listener.ts b/packages/effects/common-ui/src/components/verify/use-event-listener.ts new file mode 100644 index 00000000000..180023527d0 --- /dev/null +++ b/packages/effects/common-ui/src/components/verify/use-event-listener.ts @@ -0,0 +1,61 @@ +import type { Ref } from 'vue'; +import { ref, unref, watch } from 'vue'; + +import { useDebounceFn, useThrottleFn } from '@vueuse/core'; + +export type RemoveEventFn = () => void; +export interface UseEventParams { + el?: any | Element | Ref | Window; + name: string; + listener: EventListener; + options?: AddEventListenerOptions | boolean; + autoRemove?: boolean; + isDebounce?: boolean; + wait?: number; +} +export function useEventListener({ + autoRemove = true, + el = window, + isDebounce = true, + listener, + name, + options, + wait = 80, +}: UseEventParams): { removeEvent: RemoveEventFn } { + let remove: RemoveEventFn = () => {}; + const isAddRef = ref(false); + + if (el) { + const element = ref(el as Element) as Ref; + + const handler = isDebounce + ? useDebounceFn(listener, wait) + : useThrottleFn(listener, wait); + const realHandler = wait ? handler : listener; + const removeEventListener = (e: Element) => { + isAddRef.value = true; + e.removeEventListener(name, realHandler, options); + }; + const addEventListener = (e: Element) => + e.addEventListener(name, realHandler, options); + + const removeWatch = watch( + element, + (v, _ov, cleanUp) => { + if (v) { + !unref(isAddRef) && addEventListener(v); + cleanUp(() => { + autoRemove && removeEventListener(v); + }); + } + }, + { immediate: true }, + ); + + remove = () => { + removeEventListener(element.value); + removeWatch(); + }; + } + return { removeEvent: remove }; +} diff --git a/playground/src/router/routes/modules/examples.ts b/playground/src/router/routes/modules/examples.ts index c946e79c2bc..1e53131cc40 100644 --- a/playground/src/router/routes/modules/examples.ts +++ b/playground/src/router/routes/modules/examples.ts @@ -101,6 +101,25 @@ const routes: RouteRecordRaw[] = [ }, ], }, + { + name: 'VerifyExample', + path: '/examples/verify', + meta: { + icon: 'logos:recaptcha', + title: '验证组件', + }, + children: [ + { + name: 'DragVerifyExample', + path: '/examples/verify/drag-verify', + component: () => + import('#/views/examples/verify/drag-verify/index.vue'), + meta: { + title: '拖拽校验', + }, + }, + ], + }, ], }, ]; diff --git a/playground/src/views/examples/verify/drag-verify/index.vue b/playground/src/views/examples/verify/drag-verify/index.vue new file mode 100644 index 00000000000..823b839e6d7 --- /dev/null +++ b/playground/src/views/examples/verify/drag-verify/index.vue @@ -0,0 +1,36 @@ + + + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ac4c17b74c..3da5bae4e90 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -983,6 +983,9 @@ importers: '@vben/types': specifier: workspace:* version: link:../../types + '@vueuse/core': + specifier: ^11.0.3 + version: 11.0.3(vue@3.5.4(typescript@5.6.2)) '@vueuse/integrations': specifier: ^11.0.3 version: 11.0.3(async-validator@4.2.5)(axios@1.7.7)(focus-trap@7.5.4)(nprogress@0.2.0)(qrcode@1.5.4)(sortablejs@1.15.3)(vue@3.5.4(typescript@5.6.2)) From e6fa94450902bb033e5850498b0307af58deec80 Mon Sep 17 00:00:00 2001 From: invalid w Date: Fri, 13 Sep 2024 16:34:16 +0800 Subject: [PATCH 02/24] =?UTF-8?q?chore:=20=E5=A2=9E=E5=8A=A0=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/verify/drag-verify/index.vue | 88 ++++++++++++++++++- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue index ec073a8bb0d..9100ede765b 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue @@ -307,8 +307,92 @@ function resume() { + From e0986374046f0ef1f24ad329f04991e5e115bf5a Mon Sep 17 00:00:00 2001 From: invalid w Date: Sat, 14 Sep 2024 12:03:12 +0800 Subject: [PATCH 03/24] Merge branch 'main' into wangjue-verify-comp From 5530e6e1c3668ab176cda47b877003bea0cb0d8a Mon Sep 17 00:00:00 2001 From: invalid w Date: Sat, 14 Sep 2024 12:42:25 +0800 Subject: [PATCH 04/24] =?UTF-8?q?chore:=20=E5=B0=81=E8=A3=85action?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/verify/drag-verify/action.vue | 29 +++++++++++- .../src/components/verify/drag-verify/bar.vue | 12 ++++- .../components/verify/drag-verify/content.vue | 14 ++++-- .../components/verify/drag-verify/index.vue | 46 +++++++++++-------- pnpm-lock.yaml | 2 +- 5 files changed, 77 insertions(+), 26 deletions(-) diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/action.vue b/packages/effects/common-ui/src/components/verify/drag-verify/action.vue index 7e861709390..966cc406bd2 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/action.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/action.vue @@ -1,9 +1,34 @@ diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/bar.vue b/packages/effects/common-ui/src/components/verify/drag-verify/bar.vue index e1617fbe5fa..82d1eefe306 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/bar.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/bar.vue @@ -1,5 +1,15 @@ - From e976f588e05b77dd23ab2e95d3b14a565a8a340f Mon Sep 17 00:00:00 2001 From: invalid w Date: Sat, 14 Sep 2024 16:47:50 +0800 Subject: [PATCH 07/24] =?UTF-8?q?chore:=20=E5=AF=BC=E5=87=BAcheck=E5=9B=BE?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@core/base/icons/src/lucide.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@core/base/icons/src/lucide.ts b/packages/@core/base/icons/src/lucide.ts index 6e99dcf2150..592bd73c647 100644 --- a/packages/@core/base/icons/src/lucide.ts +++ b/packages/@core/base/icons/src/lucide.ts @@ -10,6 +10,7 @@ export { ArrowUpToLine, Bell, BookOpenText, + Check, ChevronDown, ChevronLeft, ChevronRight, From fb62ffe8f4947239b4418cb0dbd5ae6f923cd869 Mon Sep 17 00:00:00 2001 From: invalid w Date: Sat, 14 Sep 2024 16:48:39 +0800 Subject: [PATCH 08/24] =?UTF-8?q?chore:=20=E6=8B=96=E5=8A=A8=E7=9A=84?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E5=8F=98=E4=B8=BA@vben/icons=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common-ui/src/components/verify/drag-verify/action.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/action.vue b/packages/effects/common-ui/src/components/verify/drag-verify/action.vue index aacb85c554d..3b5ce1ba9f5 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/action.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/action.vue @@ -1,6 +1,8 @@ @@ -283,7 +282,11 @@ function resume() { :success-text="successText" :text="text" :width="width" - /> + > + + + > + + diff --git a/playground/src/views/examples/verify/drag-verify/index.vue b/playground/src/views/examples/verify/drag-verify/index.vue index 823b839e6d7..32e6ef95b04 100644 --- a/playground/src/views/examples/verify/drag-verify/index.vue +++ b/playground/src/views/examples/verify/drag-verify/index.vue @@ -7,8 +7,9 @@ import { Page, type VerifyPassingData, } from '@vben/common-ui'; +import { Bell, Github } from '@vben/icons'; -import { Button, message } from 'ant-design-vue'; +import { Button, Card, message } from 'ant-design-vue'; function handleSuccess(data: VerifyPassingData) { const { time } = data; @@ -22,15 +23,69 @@ function handleBtnClick(elRef?: DragVerifyActionType) { } const el1 = ref(); +const el2 = ref(); +const el3 = ref(); +const el4 = ref(); +const el5 = ref(); From 15023e12daa5fd06721a890bea08d818684726ab Mon Sep 17 00:00:00 2001 From: invalid w Date: Sat, 14 Sep 2024 17:55:10 +0800 Subject: [PATCH 10/24] fix: ci error --- .../common-ui/src/components/verify/drag-verify/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue index e6180ac0708..6f801f38cdd 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue @@ -208,7 +208,7 @@ function handleDragOver(e: MouseEvent | TouchEvent) { if (props.value) { const contentEl = unref(contentElRef); if (contentEl) { - contentEl.style.width = `${Number.parseInt(barEl.getEl().style.width)}px`; + contentEl.getEl().style.width = `${Number.parseInt(barEl.getEl().style.width)}px`; } } else { resume(); From b7fbfa3a60367f2ae5b58c854092b4090b273718 Mon Sep 17 00:00:00 2001 From: invalid w Date: Sat, 14 Sep 2024 18:07:38 +0800 Subject: [PATCH 11/24] =?UTF-8?q?chore:=20=E9=80=82=E9=85=8D=E6=9A=97?= =?UTF-8?q?=E9=BB=91=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common-ui/src/components/verify/drag-verify/action.vue | 3 ++- .../common-ui/src/components/verify/drag-verify/content.vue | 5 ----- .../common-ui/src/components/verify/drag-verify/index.vue | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/action.vue b/packages/effects/common-ui/src/components/verify/drag-verify/action.vue index ec60279acfa..6e8c00ab457 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/action.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/action.vue @@ -16,6 +16,7 @@ const style = computed(() => { const { actionStyle, height } = props; const h = `${Number.parseInt(height as string)}px`; return { + background: 'hsl(var(--background))', height: h, left: left.value, width: h, @@ -41,7 +42,7 @@ defineExpose({ ref="divRef" :class="toLeft ? 'transition-width !left-0 duration-300' : ''" :style="style" - class="absolute left-0 top-0 flex cursor-move items-center justify-center rounded-md bg-white" + class="absolute left-0 top-0 flex cursor-move items-center justify-center rounded-md" > diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/content.vue b/packages/effects/common-ui/src/components/verify/drag-verify/content.vue index 3ba6319db2d..21a82c28f0e 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/content.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/content.vue @@ -37,7 +37,6 @@ defineExpose({ :class="{ [$style.content]: true, [$style.success]: isPassing, - [$style.default]: !isPassing, }" :style="style" class="absolute top-0 flex select-none items-center justify-center text-xs" @@ -69,8 +68,4 @@ defineExpose({ .success { -webkit-text-fill-color: white; } - -.default { - -webkit-text-fill-color: #333; -} diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue index 6f801f38cdd..3470197a03c 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue @@ -110,6 +110,7 @@ const getWrapStyleRef = computed(() => { const h = Number.parseInt(height as string); const w = `${Number.parseInt(width as string)}px`; return { + backgroundColor: 'hsl(var(--background-deep))', borderRadius: circle ? `${h / 2}px` : 0, height: `${h}px`, lineHeight: `${h}px`, @@ -260,7 +261,7 @@ function resume() {
Date: Sat, 14 Sep 2024 18:15:47 +0800 Subject: [PATCH 12/24] =?UTF-8?q?chore:=20=E5=9B=BD=E9=99=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/src/locales/langs/en-US.json | 6 ++++++ playground/src/locales/langs/zh-CN.json | 6 ++++++ playground/src/router/routes/modules/examples.ts | 6 +++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/playground/src/locales/langs/en-US.json b/playground/src/locales/langs/en-US.json index 95f3c8831b6..38aab840350 100644 --- a/playground/src/locales/langs/en-US.json +++ b/playground/src/locales/langs/en-US.json @@ -102,6 +102,12 @@ "timestamp": "Timestamp:", "x": "x:", "y": "y:" + }, + "verify": { + "title": "Verify", + "drag-verify": { + "title": "Drag Verify" + } } } } diff --git a/playground/src/locales/langs/zh-CN.json b/playground/src/locales/langs/zh-CN.json index 91d4962c2b0..bae489cdd3e 100644 --- a/playground/src/locales/langs/zh-CN.json +++ b/playground/src/locales/langs/zh-CN.json @@ -102,6 +102,12 @@ "timestamp": "时间戳:", "x": "x:", "y": "y:" + }, + "verify": { + "title": "验证组件", + "drag-verify": { + "title": "拖动验证" + } } } } diff --git a/playground/src/router/routes/modules/examples.ts b/playground/src/router/routes/modules/examples.ts index 1e53131cc40..727bb1c22e3 100644 --- a/playground/src/router/routes/modules/examples.ts +++ b/playground/src/router/routes/modules/examples.ts @@ -105,8 +105,8 @@ const routes: RouteRecordRaw[] = [ name: 'VerifyExample', path: '/examples/verify', meta: { - icon: 'logos:recaptcha', - title: '验证组件', + icon: 'arcticons:okta-verify', + title: $t('page.examples.verify.title'), }, children: [ { @@ -115,7 +115,7 @@ const routes: RouteRecordRaw[] = [ component: () => import('#/views/examples/verify/drag-verify/index.vue'), meta: { - title: '拖拽校验', + title: $t('page.examples.verify.drag-verify.title'), }, }, ], From b61cdf876bf5bde71881e943c71d0a9c9b435f77 Mon Sep 17 00:00:00 2001 From: invalid w Date: Thu, 19 Sep 2024 14:35:30 +0800 Subject: [PATCH 13/24] chore: resolve conflict --- packages/effects/common-ui/package.json | 1 + pnpm-lock.yaml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/effects/common-ui/package.json b/packages/effects/common-ui/package.json index a9cd03a4df6..34929543834 100644 --- a/packages/effects/common-ui/package.json +++ b/packages/effects/common-ui/package.json @@ -27,6 +27,7 @@ "@vben/icons": "workspace:*", "@vben/locales": "workspace:*", "@vben/types": "workspace:*", + "@vueuse/core": "^11.1.0", "@vueuse/integrations": "^11.1.0", "qrcode": "^1.5.4", "vue": "^3.5.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1f74d17716c..57ed250db4d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -990,8 +990,8 @@ importers: specifier: workspace:* version: link:../../types '@vueuse/core': - specifier: ^11.0.3 - version: 11.0.3(vue@3.5.5(typescript@5.6.2)) + specifier: ^11.1.0 + version: 11.1.0(vue@3.5.6(typescript@5.6.2)) '@vueuse/integrations': specifier: ^11.1.0 version: 11.1.0(async-validator@4.2.5)(axios@1.7.7)(focus-trap@7.5.4)(nprogress@0.2.0)(qrcode@1.5.4)(sortablejs@1.15.3)(vue@3.5.6(typescript@5.6.2)) From 306398d6c2db53605a081df9eba4b52809ed956c Mon Sep 17 00:00:00 2001 From: invalid w Date: Thu, 19 Sep 2024 15:03:34 +0800 Subject: [PATCH 14/24] =?UTF-8?q?chore:=20=E8=BF=81=E7=A7=BBv2=E7=9A=84?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=97=8B=E8=BD=AC=E6=A0=A1=E9=AA=8C=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/verify/drag-verify/index.vue | 63 +------ .../components/verify/img-rotate/index.vue | 154 ++++++++++++++++++ .../common-ui/src/components/verify/props.ts | 85 ++++++++++ 3 files changed, 242 insertions(+), 60 deletions(-) create mode 100644 packages/effects/common-ui/src/components/verify/img-rotate/index.vue create mode 100644 packages/effects/common-ui/src/components/verify/props.ts diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue index 3470197a03c..07c0b9a858a 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue @@ -1,72 +1,15 @@ + + + + diff --git a/packages/effects/common-ui/src/components/verify/props.ts b/packages/effects/common-ui/src/components/verify/props.ts new file mode 100644 index 00000000000..04094128c12 --- /dev/null +++ b/packages/effects/common-ui/src/components/verify/props.ts @@ -0,0 +1,85 @@ +import type { PropType } from 'vue'; + +export const basicProps = { + actionStyle: { + default: () => ({}), + type: Object as PropType, + }, + + barStyle: { + default: () => ({}), + type: Object as PropType, + }, + + circle: { + default: false, + type: Boolean as PropType, + }, + contentStyle: { + default: () => ({}), + type: Object as PropType, + }, + height: { + default: 40, + type: [Number, String] as PropType, + }, + + isSlot: { + default: false, + type: Boolean as PropType, + }, + + successText: { + default: '验证通过', + type: [String] as PropType, + }, + + text: { + default: '请按住滑块拖动', + type: [String] as PropType, + }, + value: { + default: false, + type: Boolean as PropType, + }, + width: { + default: 220, + type: [Number, String] as PropType, + }, + wrapStyle: { + default: () => ({}), + type: Object as PropType, + }, +}; + +export const rotateProps = { + ...basicProps, + diffDegree: { + default: 20, + type: Number as PropType, + }, + + imgWidth: { + default: 260, + type: Number as PropType, + }, + + imgWrapStyle: { + default: () => ({}), + type: Object as PropType, + }, + + maxDegree: { + default: 270, + type: Number as PropType, + }, + + minDegree: { + default: 90, + type: Number as PropType, + }, + + src: { + type: String as PropType, + }, +}; From ee76773d9e1deb0a0da96cc917043ce28388f8ee Mon Sep 17 00:00:00 2001 From: invalid w Date: Thu, 19 Sep 2024 16:25:20 +0800 Subject: [PATCH 15/24] =?UTF-8?q?chore:=20=E5=AE=8C=E5=96=84=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=A0=A1=E9=AA=8Cdemo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common-ui/src/components/verify/index.ts | 2 + .../{img-rotate => rotate-verify}/index.vue | 106 +++++++++++++----- playground/src/locales/langs/en-US.json | 3 + playground/src/locales/langs/zh-CN.json | 3 + .../src/router/routes/modules/examples.ts | 9 ++ .../examples/verify/rotate-verify/index.vue | 26 +++++ 6 files changed, 124 insertions(+), 25 deletions(-) rename packages/effects/common-ui/src/components/verify/{img-rotate => rotate-verify}/index.vue (63%) create mode 100644 playground/src/views/examples/verify/rotate-verify/index.vue diff --git a/packages/effects/common-ui/src/components/verify/index.ts b/packages/effects/common-ui/src/components/verify/index.ts index 991ba7a6be1..b96f54ec124 100644 --- a/packages/effects/common-ui/src/components/verify/index.ts +++ b/packages/effects/common-ui/src/components/verify/index.ts @@ -1,2 +1,4 @@ export { default as DragVerify } from './drag-verify/index.vue'; +export { default as RotateVerify } from './rotate-verify/index.vue'; + export * from './typing'; diff --git a/packages/effects/common-ui/src/components/verify/img-rotate/index.vue b/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue similarity index 63% rename from packages/effects/common-ui/src/components/verify/img-rotate/index.vue rename to packages/effects/common-ui/src/components/verify/rotate-verify/index.vue index 20ddc47d911..469245b6420 100644 --- a/packages/effects/common-ui/src/components/verify/img-rotate/index.vue +++ b/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue @@ -65,9 +65,7 @@ function handleDragBarMove(data: VerifyMoveData) { unref(getFactorRef), ); state.currentRotate = currentRotate; - state.imgStyle = { - transform: `rotateZ(${state.randomRotate - currentRotate}deg)`, - }; + setImgRotate(state.randomRotate - currentRotate); } function handleImgOnLoad() { @@ -76,9 +74,7 @@ function handleImgOnLoad() { minDegree! + Math.random() * (maxDegree! - minDegree!), ); // 生成随机角度 state.randomRotate = ranRotate; - state.imgStyle = { - transform: `rotateZ(${ranRotate}deg)`, - }; + setImgRotate(ranRotate); } function handleDragEnd() { @@ -86,9 +82,7 @@ function handleDragEnd() { const { diffDegree } = props; if (Math.abs(randomRotate - currentRotate) >= (diffDegree || 20)) { - state.imgStyle = { - transform: `rotateZ(${randomRotate}deg)`, - }; + setImgRotate(randomRotate); state.toOrigin = true; useTimeoutFn(() => { state.toOrigin = false; @@ -100,6 +94,13 @@ function handleDragEnd() { } state.showTip = true; } + +function setImgRotate(deg: number) { + state.imgStyle = { + transform: `rotateZ(${deg}deg)`, + }; +} + function checkPass() { state.isPassing = true; state.endTime = Date.now(); @@ -117,28 +118,51 @@ function resume() { handleImgOnLoad(); } +const imgCls = computed(() => { + return state.toOrigin ? ['transition-transform duration-300'] : []; +}); + +const tip = computed(() => { + return state.isPassing + ? `验证校验成功,耗时${((state.endTime - state.startTime) / 1000).toFixed(1)}秒!` + : '验证失败!'; +}); + defineExpose({ resume, }); - + diff --git a/playground/src/locales/langs/en-US.json b/playground/src/locales/langs/en-US.json index 38aab840350..186a69f5061 100644 --- a/playground/src/locales/langs/en-US.json +++ b/playground/src/locales/langs/en-US.json @@ -107,6 +107,9 @@ "title": "Verify", "drag-verify": { "title": "Drag Verify" + }, + "rotate-verify": { + "title": "Rotate Verify" } } } diff --git a/playground/src/locales/langs/zh-CN.json b/playground/src/locales/langs/zh-CN.json index bae489cdd3e..9f6271d61f2 100644 --- a/playground/src/locales/langs/zh-CN.json +++ b/playground/src/locales/langs/zh-CN.json @@ -107,6 +107,9 @@ "title": "验证组件", "drag-verify": { "title": "拖动验证" + }, + "rotate-verify": { + "title": "旋转校验" } } } diff --git a/playground/src/router/routes/modules/examples.ts b/playground/src/router/routes/modules/examples.ts index 727bb1c22e3..59463e8648f 100644 --- a/playground/src/router/routes/modules/examples.ts +++ b/playground/src/router/routes/modules/examples.ts @@ -118,6 +118,15 @@ const routes: RouteRecordRaw[] = [ title: $t('page.examples.verify.drag-verify.title'), }, }, + { + name: 'RotateVerifyExample', + path: '/examples/verify/rotate-verify', + component: () => + import('#/views/examples/verify/rotate-verify/index.vue'), + meta: { + title: $t('page.examples.verify.rotate-verify.title'), + }, + }, ], }, ], diff --git a/playground/src/views/examples/verify/rotate-verify/index.vue b/playground/src/views/examples/verify/rotate-verify/index.vue new file mode 100644 index 00000000000..9a98ce2972f --- /dev/null +++ b/playground/src/views/examples/verify/rotate-verify/index.vue @@ -0,0 +1,26 @@ + + + From 1497d4cf90710f273478c68913309abdd110b8c3 Mon Sep 17 00:00:00 2001 From: invalid w Date: Thu, 19 Sep 2024 16:33:14 +0800 Subject: [PATCH 16/24] =?UTF-8?q?chore:=20=E8=BD=AC=E6=8D=A2=E4=B8=BAtailw?= =?UTF-8?q?indcss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/verify/rotate-verify/index.vue | 62 +++++++------------ 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue b/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue index 469245b6420..3d204da44ad 100644 --- a/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue +++ b/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue @@ -149,25 +149,25 @@ defineExpose({ @click="resume" @load="handleImgOnLoad" /> - - {{ tip }} - - - 点击图片可刷新 - +
+ {{ tip }} +
+
+ 点击图片可刷新 +
+
From 17fb81c1444e1c84981da3c68bc457a171ce847f Mon Sep 17 00:00:00 2001 From: invalid w Date: Thu, 19 Sep 2024 18:15:30 +0800 Subject: [PATCH 17/24] =?UTF-8?q?chore:=20=E6=9B=BF=E6=8D=A2=E4=B8=BA?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=9A=84=E9=A2=9C=E8=89=B2=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/verify/drag-verify/bar.vue | 3 ++- .../components/verify/rotate-verify/index.vue | 27 ++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/bar.vue b/packages/effects/common-ui/src/components/verify/drag-verify/bar.vue index c8dfeef36f5..32cdac78b15 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/bar.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/bar.vue @@ -14,6 +14,7 @@ const style = computed(() => { const { barStyle, circle, height } = props; const h = Number.parseInt(height as string); return { + background: 'hsl(var(--success))', borderRadius: circle ? `${h / 2}px 0 0 ${h / 2}px` : 0, height: `${h}px`, ...barStyle, @@ -36,7 +37,7 @@ defineExpose({ ref="divRef" :class="props.toLeft ? 'transition-width !w-0 duration-300' : ''" :style="style" - class="absolute h-9 w-0 rounded-md bg-green-600" + class="absolute h-9 w-0 rounded-md" > diff --git a/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue b/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue index 3d204da44ad..9aed3589c94 100644 --- a/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue +++ b/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue @@ -154,18 +154,27 @@ defineExpose({ >
{{ tip }}
-
+
点击图片可刷新
- - From c1d79161a09bf64a3fc00b48b07df0adedc2d585 Mon Sep 17 00:00:00 2001 From: invalid w Date: Thu, 19 Sep 2024 18:32:57 +0800 Subject: [PATCH 18/24] =?UTF-8?q?chore:=20=E4=BD=BF=E7=94=A8interface?= =?UTF-8?q?=E4=BB=A3=E6=9B=BF=E7=BB=84=E4=BB=B6=E7=9A=84props=E5=A3=B0?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/verify/drag-verify/index.vue | 16 ++++- .../common-ui/src/components/verify/props.ts | 69 ++++++++++++++++++- 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue index 07c0b9a858a..591b9bce61c 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue @@ -3,13 +3,25 @@ import { computed, reactive, ref, unref, watch, watchEffect } from 'vue'; import { useTimeoutFn } from '@vueuse/core'; -import { basicProps } from '../props'; +import { type VerifyProps } from '../props'; import { useEventListener } from '../use-event-listener'; import ActionCmp from './action.vue'; import BarCmp from './bar.vue'; import ContentCmp from './content.vue'; -const props = defineProps(basicProps); +const props = withDefaults(defineProps(), { + actionStyle: () => ({}), + barStyle: () => ({}), + circle: false, + contentStyle: () => ({}), + height: '40', + isSlot: false, + successText: '验证通过', + text: '请按住滑块拖动', + value: false, + width: '220', + wrapStyle: () => ({}), +}); const emit = defineEmits([ 'success', diff --git a/packages/effects/common-ui/src/components/verify/props.ts b/packages/effects/common-ui/src/components/verify/props.ts index 04094128c12..0c549e4236f 100644 --- a/packages/effects/common-ui/src/components/verify/props.ts +++ b/packages/effects/common-ui/src/components/verify/props.ts @@ -1,4 +1,4 @@ -import type { PropType } from 'vue'; +import type { CSSProperties, PropType } from 'vue'; export const basicProps = { actionStyle: { @@ -83,3 +83,70 @@ export const rotateProps = { type: String as PropType, }, }; + +export interface VerifyProps { + /** + * @description 滑块的样式 + * @default {} + */ + actionStyle?: CSSProperties; + + /** + * @description 滑块条的样式 + * @default {} + */ + barStyle?: CSSProperties; + + /** + * @description 内容的样式 + * @default {} + */ + contentStyle?: CSSProperties; + + /** + * @description 组件的样式 + * @default {} + */ + wrapStyle?: CSSProperties; + + /** + * @description 组件是否为圆角 + * @default false + */ + circle?: boolean; + + /** + * @description 组件宽度 + * @default 220px + */ + width?: number | string; + /** + * @description 组件高度 + * @default 40px + */ + height?: number | string; + + /** + * @description 是否作为插槽使用,用于联动组件,可参考旋转校验组件 + * @default false + */ + isSlot?: boolean; + + /** + * @description 验证成功的提示 + * @default '验证通过' + */ + successText?: string; + + /** + * @description 提示文字 + * @default '请按住滑块拖动' + */ + text?: string; + + /** + * @description 是否验证成功 + * @default false + */ + value?: boolean; +} From 0af84eb7d3119f8c279157de6612980235a2588d Mon Sep 17 00:00:00 2001 From: invalid w Date: Fri, 20 Sep 2024 10:58:14 +0800 Subject: [PATCH 19/24] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4props?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/verify/drag-verify/index.vue | 19 +-- .../common-ui/src/components/verify/props.ts | 151 ++++++++---------- .../components/verify/rotate-verify/index.vue | 13 +- .../examples/verify/drag-verify/index.vue | 6 +- .../examples/verify/rotate-verify/index.vue | 12 +- pnpm-lock.yaml | 2 +- 6 files changed, 96 insertions(+), 107 deletions(-) diff --git a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue index 591b9bce61c..9ed1ac62063 100644 --- a/packages/effects/common-ui/src/components/verify/drag-verify/index.vue +++ b/packages/effects/common-ui/src/components/verify/drag-verify/index.vue @@ -3,25 +3,16 @@ import { computed, reactive, ref, unref, watch, watchEffect } from 'vue'; import { useTimeoutFn } from '@vueuse/core'; -import { type VerifyProps } from '../props'; +import { defaultDragVerifyProps, type VerifyProps } from '../props'; import { useEventListener } from '../use-event-listener'; import ActionCmp from './action.vue'; import BarCmp from './bar.vue'; import ContentCmp from './content.vue'; -const props = withDefaults(defineProps(), { - actionStyle: () => ({}), - barStyle: () => ({}), - circle: false, - contentStyle: () => ({}), - height: '40', - isSlot: false, - successText: '验证通过', - text: '请按住滑块拖动', - value: false, - width: '220', - wrapStyle: () => ({}), -}); +const props = withDefaults( + defineProps(), + defaultDragVerifyProps(), +); const emit = defineEmits([ 'success', diff --git a/packages/effects/common-ui/src/components/verify/props.ts b/packages/effects/common-ui/src/components/verify/props.ts index 0c549e4236f..6f65144a989 100644 --- a/packages/effects/common-ui/src/components/verify/props.ts +++ b/packages/effects/common-ui/src/components/verify/props.ts @@ -1,88 +1,4 @@ -import type { CSSProperties, PropType } from 'vue'; - -export const basicProps = { - actionStyle: { - default: () => ({}), - type: Object as PropType, - }, - - barStyle: { - default: () => ({}), - type: Object as PropType, - }, - - circle: { - default: false, - type: Boolean as PropType, - }, - contentStyle: { - default: () => ({}), - type: Object as PropType, - }, - height: { - default: 40, - type: [Number, String] as PropType, - }, - - isSlot: { - default: false, - type: Boolean as PropType, - }, - - successText: { - default: '验证通过', - type: [String] as PropType, - }, - - text: { - default: '请按住滑块拖动', - type: [String] as PropType, - }, - value: { - default: false, - type: Boolean as PropType, - }, - width: { - default: 220, - type: [Number, String] as PropType, - }, - wrapStyle: { - default: () => ({}), - type: Object as PropType, - }, -}; - -export const rotateProps = { - ...basicProps, - diffDegree: { - default: 20, - type: Number as PropType, - }, - - imgWidth: { - default: 260, - type: Number as PropType, - }, - - imgWrapStyle: { - default: () => ({}), - type: Object as PropType, - }, - - maxDegree: { - default: 270, - type: Number as PropType, - }, - - minDegree: { - default: 90, - type: Number as PropType, - }, - - src: { - type: String as PropType, - }, -}; +import type { CSSProperties } from 'vue'; export interface VerifyProps { /** @@ -150,3 +66,68 @@ export interface VerifyProps { */ value?: boolean; } + +export interface RotateProps extends VerifyProps { + /** + * @description 旋转的角度 + * @default 20 + */ + diffDegree?: number; + + /** + * @description 图片的宽度 + * @default 260 + */ + imgWidth?: number; + + /** + * @description 图片的样式 + * @default {} + */ + imgWrapStyle?: CSSProperties; + + /** + * @description 最大旋转角度 + * @default 270 + */ + maxDegree?: number; + + /** + * @description 最小旋转角度 + * @default 90 + */ + minDegree?: number; + + /** + * @description 图片的地址 + */ + src?: string; +} + +export function defaultDragVerifyProps() { + return { + actionStyle: () => ({}), + barStyle: () => ({}), + circle: false, + contentStyle: () => ({}), + height: '40', + isSlot: false, + successText: '验证通过', + text: '请按住滑块拖动', + value: false, + width: '220', + wrapStyle: () => ({}), + }; +} + +export function defaultRotateVerifyProps() { + return { + ...defaultDragVerifyProps(), + diffDegree: 20, + imgWidth: 260, + imgWrapStyle: () => ({}), + maxDegree: 270, + minDegree: 90, + src: '', + }; +} diff --git a/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue b/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue index 9aed3589c94..f460f8493ad 100644 --- a/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue +++ b/packages/effects/common-ui/src/components/verify/rotate-verify/index.vue @@ -6,9 +6,12 @@ import { computed, reactive, ref, unref, watch } from 'vue'; import { useTimeoutFn } from '@vueuse/core'; import DragVerify from '../drag-verify/index.vue'; -import { rotateProps } from '../props'; +import { defaultRotateVerifyProps, type RotateProps } from '../props'; -const props = defineProps(rotateProps); +const props = withDefaults( + defineProps(), + defaultRotateVerifyProps(), +); const emit = defineEmits(['success', 'change', 'update:value']); const basicRef = ref(null); const state = reactive({ @@ -180,6 +183,10 @@ defineExpose({ @end="handleDragEnd" @move="handleDragBarMove" @start="handleStart" - /> + > + + diff --git a/playground/src/views/examples/verify/drag-verify/index.vue b/playground/src/views/examples/verify/drag-verify/index.vue index 32e6ef95b04..218005972c6 100644 --- a/playground/src/views/examples/verify/drag-verify/index.vue +++ b/playground/src/views/examples/verify/drag-verify/index.vue @@ -7,7 +7,7 @@ import { Page, type VerifyPassingData, } from '@vben/common-ui'; -import { Bell, Github } from '@vben/icons'; +import { Bell, Sun } from '@vben/icons'; import { Button, Card, message } from 'ant-design-vue'; @@ -62,7 +62,7 @@ const el5 = ref();