This commit is contained in:
dap 2024-09-15 09:16:26 +08:00
commit ca30857eff
28 changed files with 127 additions and 78 deletions

View File

@ -3,3 +3,5 @@ node_modules
.gitignore
*.md
dist
.turbo
dist.zip

View File

@ -212,7 +212,6 @@
"*.env": "$(capture).env.*",
"README.md": "README*,CHANGELOG*,LICENSE,CNAME",
"package.json": "pnpm-lock.yaml,pnpm-workspace.yaml,.gitattributes,.gitignore,.gitpod.yml,.npmrc,.browserslistrc,.node-version,.git*,.tazerc.json",
"Dockerfile": "Dockerfile,.docker*,docker-entrypoint.sh,build-local-docker*,nginx.conf",
"eslint.config.mjs": ".eslintignore,.prettierignore,.stylelintignore,.commitlintrc.*,.prettierrc.*,stylelint.config.*,.lintstagedrc.mjs,cspell.json",
"tailwind.config.mjs": "postcss.*"
},

View File

@ -83,7 +83,12 @@ export const demoPreviewPlugin = (md: MarkdownRenderer) => {
if (!state.tokens[index]) {
return '';
}
const firstString = 'index.vue';
childFiles = childFiles.sort((a, b) => {
if (a === firstString) return -1;
if (b === firstString) return 1;
return a.localeCompare(b, 'en', { sensitivity: 'base' });
});
state.tokens[index].content =
`<DemoPreview files="${encodeURIComponent(JSON.stringify(childFiles))}" ><${ComponentName}/>
`;

View File

@ -65,3 +65,12 @@ pnpm install
}
}
```
## 其他
如果你想更进一步精简,你可以删除参考一下文件或者文件夹的作用,判断自己是否需要,不需要删除即可:
- `.changeset` 文件夹用于管理版本变更
- `.github` 文件夹用于存放 GitHub 的配置文件
- `.vscode` 文件夹用于存放 VSCode 的配置文件,如果你使用其他编辑器,可以删除
- `./scripts/deploy` 文件夹用于存放部署脚本如果你不需要docker部署可以删除

View File

@ -14,6 +14,7 @@ function generatorColorVariables(colorItems: ColorItem[]) {
colorItems.forEach(({ alias, color, name }) => {
if (color) {
const colorsMap = getColors(new TinyColor(color).toHexString());
let mainColor = colorsMap['500'];
const colorKeys = Object.keys(colorsMap);

View File

@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { openWindow } from '../window'; // 假设你的函数在 'openWindow' 文件中
import { openWindow } from '../window';
describe('openWindow', () => {
// 保存原始的 window.open 函数

View File

@ -86,21 +86,22 @@ function updateMainColorVariables(preference: Preferences) {
{ alias: 'destructive', color: colorDestructive, name: 'red' },
]);
if (colorPrimary) {
const mainColor = colorVariables['--primary-500'];
mainColor &&
document.documentElement.style.setProperty('--primary', mainColor);
}
// 要设置的 CSS 变量映射
const colorMappings = {
'--green-500': '--success',
'--primary-500': '--primary',
'--red-500': '--destructive',
'--yellow-500': '--warning',
};
if (colorVariables['--green-500']) {
colorVariables['--success'] = colorVariables['--green-500'];
}
if (colorVariables['--yellow-500']) {
colorVariables['--warning'] = colorVariables['--yellow-500'];
}
if (colorVariables['--red-500']) {
colorVariables['--destructive'] = colorVariables['--red-500'];
// 统一处理颜色变量的更新
Object.entries(colorMappings).forEach(([sourceVar, targetVar]) => {
const colorValue = colorVariables[sourceVar];
if (colorValue) {
document.documentElement.style.setProperty(targetVar, colorValue);
}
});
executeUpdateCSSVariables(colorVariables);
}

View File

@ -177,7 +177,7 @@ export class FormApi {
}
unmounted() {
this.state = null;
// this.state = null;
this.isMounted = false;
this.stateHandler.reset();
}

View File

@ -16,7 +16,7 @@ import {
import { cn, isFunction, isObject, isString } from '@vben-core/shared/utils';
import { toTypedSchema } from '@vee-validate/zod';
import { useFormValues } from 'vee-validate';
import { useFieldError, useFormValues } from 'vee-validate';
import { injectRenderFormProps, useFormContext } from './context';
import useDependencies from './dependencies';
@ -43,8 +43,11 @@ const {
const { componentBindEventMap, componentMap, isVertical } = useFormContext();
const formRenderProps = injectRenderFormProps();
const values = useFormValues();
const errors = useFieldError(fieldName);
const formApi = formRenderProps.form;
const isInValid = computed(() => errors.value?.length > 0);
const fieldComponent = computed(() => {
const finalComponent = isString(component)
? componentMap.value[component]
@ -217,6 +220,7 @@ function createComponentProps(slotProps: Record<string, any>) {
<FormItem
v-show="isShow"
:class="{
'form-valid-error': isInValid,
'flex-col': isVertical,
'flex-row items-center': !isVertical,
}"
@ -248,10 +252,14 @@ function createComponentProps(slotProps: Record<string, any>) {
...slotProps,
...createComponentProps(slotProps),
disabled: shouldDisabled,
isInValid,
}"
>
<component
:is="fieldComponent"
:class="{
'border-destructive focus:border-destructive': isInValid,
}"
v-bind="createComponentProps(slotProps)"
:disabled="shouldDisabled"
>

View File

@ -1,7 +1,8 @@
import type { ModalState } from '../modal';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { ModalApi } from '../modal-api'; // 假设 ModalApi 位于同一目录
import type { ModalState } from '../modal';
import { ModalApi } from '../modal-api';
vi.mock('@vben-core/shared/store', () => {
return {

View File

@ -52,7 +52,9 @@ defineExpose({
<template>
<DialogPortal>
<Transition name="fade">
<DialogOverlay v-if="open && modal" @click="() => emits('close')" />
</Transition>
<DialogContent
ref="contentRef"
v-bind="forwarded"

View File

@ -5,7 +5,7 @@ useScrollLock();
</script>
<template>
<div
class="data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 bg-overlay fixed inset-0 z-[1000]"
class="bg-overlay fixed inset-0 z-[1000]"
data-dismissable-modal="true"
></div>
</template>

View File

@ -46,7 +46,9 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
<template>
<DialogPortal>
<Transition name="fade">
<SheetOverlay v-if="open && modal" />
</Transition>
<DialogContent
:class="cn(sheetVariants({ side }), 'z-[1000]', props.class)"
v-bind="{ ...forwarded, ...$attrs }"

View File

@ -5,7 +5,7 @@ useScrollLock();
</script>
<template>
<div
class="bg-overlay data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-[1000]"
class="bg-overlay fixed inset-0 z-[1000]"
data-dismissable-modal="true"
></div>
</template>

View File

@ -0,0 +1,18 @@
import type { CaptchaPoint } from '../types';
import { reactive } from 'vue';
export function useCaptchaPoints() {
const points = reactive<CaptchaPoint[]>([]);
function addPoint(point: CaptchaPoint) {
points.push(point);
}
function clearPoints() {
points.splice(0, points.length);
}
return {
addPoint,
clearPoints,
points,
};
}

View File

@ -1,13 +1,12 @@
<script setup lang="ts">
import type { CaptchaPoint, PointSelectionCaptchaProps } from './types';
import { ref } from 'vue';
import { RotateCw } from '@vben/icons';
import { $t } from '@vben/locales';
import { VbenButton, VbenIconButton } from '@vben-core/shadcn-ui';
import { CaptchaCard } from '.';
import { useCaptchaPoints } from './hooks/useCaptchaPoints';
const props = withDefaults(defineProps<PointSelectionCaptchaProps>(), {
height: '220px',
@ -19,44 +18,24 @@ const props = withDefaults(defineProps<PointSelectionCaptchaProps>(), {
title: '',
width: '300px',
});
const emit = defineEmits<{
click: [CaptchaPoint];
confirm: [Array<CaptchaPoint>, clear: () => void];
refresh: [];
}>();
const { addPoint, clearPoints, points } = useCaptchaPoints();
if (!props.hintImage && !props.hintText) {
throw new Error('At least one of hint image or hint text must be provided');
console.warn('At least one of hint image or hint text must be provided');
}
const points = ref<CaptchaPoint[]>([]);
const POINT_OFFSET = 11;
function getElementPosition(element: HTMLElement) {
let posX = 0;
let posY = 0;
if (element.getBoundingClientRect) {
const rect = element.getBoundingClientRect();
const doc = document.documentElement;
posX =
rect.left +
Math.max(doc.scrollLeft, document.body.scrollLeft) -
doc.clientLeft;
posY =
rect.top +
Math.max(doc.scrollTop, document.body.scrollTop) -
doc.clientTop;
} else {
while (element !== document.body) {
posX += element.offsetLeft;
posY += element.offsetTop;
element = element.offsetParent as HTMLElement;
}
}
return {
x: posX,
y: posY,
x: rect.left + window.scrollX,
y: rect.top + window.scrollY,
};
}
@ -67,25 +46,35 @@ function handleClick(e: MouseEvent) {
const { x: domX, y: domY } = getElementPosition(dom);
const mouseX = e.pageX || e.clientX;
const mouseY = e.pageY || e.clientY;
const mouseX = e.clientX + window.scrollX;
const mouseY = e.clientY + window.scrollY;
if (mouseX === undefined || mouseY === undefined)
throw new Error('Mouse coordinates not found');
if (typeof mouseX !== 'number' || typeof mouseY !== 'number') {
throw new TypeError('Mouse coordinates not found');
}
const xPos = mouseX - domX;
const yPos = mouseY - domY;
const rect = dom.getBoundingClientRect();
//
if (xPos < 0 || yPos < 0 || xPos > rect.width || yPos > rect.height) {
console.warn('Click position is out of the valid range');
return;
}
const x = Math.ceil(xPos);
const y = Math.ceil(yPos);
const point = {
i: points.value.length,
i: points.length,
t: Date.now(),
x,
y,
};
points.value.push(point);
addPoint(point);
emit('click', point);
e.stopPropagation();
@ -97,7 +86,7 @@ function handleClick(e: MouseEvent) {
function clear() {
try {
points.value = [];
clearPoints();
} catch (error) {
console.error('Error in clear:', error);
}
@ -115,7 +104,7 @@ function handleRefresh() {
function handleConfirm() {
if (!props.showConfirm) return;
try {
emit('confirm', points.value, clear);
emit('confirm', points, clear);
} catch (error) {
console.error('Error in handleConfirm:', error);
}
@ -164,6 +153,7 @@ function handleConfirm() {
}"
class="bg-primary text-primary-50 border-primary-50 absolute z-20 flex h-5 w-5 cursor-default items-center justify-center rounded-full border-2"
role="button"
tabindex="0"
>
{{ index + 1 }}
</div>

View File

@ -5,7 +5,6 @@ import { useLockStore } from './lock';
describe('useLockStore', () => {
beforeEach(() => {
// 每个测试前重置 Pinia
setActivePinia(createPinia());
});

View File

@ -63,12 +63,11 @@ describe('useAccessStore', () => {
store.tabs = [
{ fullPath: '/home', meta: {}, name: 'Home', path: '/home' },
] as any;
router.replace = vi.fn(); // 使用 vitest 的 mock 函数
router.replace = vi.fn();
await store.closeAllTabs(router);
expect(store.tabs.length).toBe(1); // 假设没有固定的标签页
// expect(router.replace).toHaveBeenCalled();
expect(store.tabs.length).toBe(1);
});
it('closes a non-affix tab', () => {
@ -161,7 +160,7 @@ describe('useAccessStore', () => {
await store._bulkCloseByPaths(['/home', '/contact']);
expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('About');
expect(store.tabs[0]?.name).toBe('About');
});
it('closes all tabs to the left of the specified tab', async () => {
@ -189,7 +188,7 @@ describe('useAccessStore', () => {
await store.closeLeftTabs(targetTab);
expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('Contact');
expect(store.tabs[0]?.name).toBe('Contact');
});
it('closes all tabs except the specified tab', async () => {
@ -217,7 +216,7 @@ describe('useAccessStore', () => {
await store.closeOtherTabs(targetTab);
expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('About');
expect(store.tabs[0]?.name).toBe('About');
});
it('closes all tabs to the right of the specified tab', async () => {
@ -245,7 +244,7 @@ describe('useAccessStore', () => {
await store.closeRightTabs(targetTab);
expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('Home');
expect(store.tabs[0]?.name).toBe('Home');
});
it('closes the tab with the specified key', async () => {

View File

@ -24,7 +24,7 @@ describe('useUserStore', () => {
expect(store.userInfo).not.toBeNull();
expect(store.userRoles.length).toBeGreaterThan(0);
store.setUserInfo(null as any); // 重置用户信息
store.setUserInfo(null as any);
expect(store.userInfo).toBeNull();
expect(store.userRoles).toEqual([]);
});

View File

@ -11,3 +11,7 @@
.ant-notification-notice {
@apply dark:border-border/60 dark:border;
}
.ant-app .form-valid-error .ant-select-selector {
border-color: hsl(var(--destructive));
}

View File

@ -1,12 +1,10 @@
import type { Router, RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';
import { describe, expect, it, vi } from 'vitest';
import { generateMenus } from '../generate-menus'; // 替换为您的实际路径
import {
createRouter,
createWebHistory,
type Router,
type RouteRecordRaw,
} from 'vue-router';
import { generateMenus } from '../generate-menus';
// Nested route setup to test child inclusion and hideChildrenInMenu functionality

View File

@ -9,4 +9,5 @@ export const overridesPreferences = defineOverridesPreferences({
app: {
name: import.meta.env.VITE_APP_TITLE,
},
theme: {},
});

View File

@ -24,7 +24,7 @@ async function handleClick(type: LoginExpiredModeType) {
接口请求遇到401状态码时需要重新登录有两种方式
<p>1.转到登录页登录成功后跳转回原页面</p>
<p>
2.弹出重新登录弹窗登录后关闭弹窗不进行任何页面跳转刷新后调整登录页面
2.弹出重新登录弹窗登录后关闭弹窗不进行任何页面跳转刷新后还是会跳转登录页面
</p>
</div>
</template>

View File

@ -46,7 +46,10 @@ const handleClick = (point: CaptchaPoint) => {
:description="$t('page.examples.captcha.pageDescription')"
:title="$t('page.examples.captcha.pageTitle')"
>
<Card :title="$t('page.examples.captcha.basic')" class="mb-4">
<Card
:title="$t('page.examples.captcha.basic')"
class="mb-4 overflow-x-auto"
>
<div class="mb-3 flex items-center justify-start">
<Input
v-model:value="params.title"

View File

@ -1,13 +1,20 @@
<script lang="ts" setup>
import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { useVbenForm } from '#/adapter';
defineOptions({
name: 'FormModelDemo',
});
function onSubmit(values: Record<string, any>) {
message.info(JSON.stringify(values)); //
}
const [Form, formApi] = useVbenForm({
handleSubmit: onSubmit,
schema: [
{
component: 'Input',