mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 07:49:19 +08:00
update: 升级vben5.5.9到5.7.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vben/access",
|
||||
"version": "5.5.9",
|
||||
"version": "5.7.0",
|
||||
"homepage": "https://github.com/vbenjs/vue-vben-admin",
|
||||
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
|
||||
"repository": {
|
||||
@@ -25,5 +25,8 @@
|
||||
"@vben/types": "workspace:*",
|
||||
"@vben/utils": "workspace:*",
|
||||
"vue": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "catalog:"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,16 +25,16 @@ async function generateAccessible(
|
||||
const { router } = options;
|
||||
|
||||
options.routes = cloneDeep(options.routes);
|
||||
|
||||
// 生成路由
|
||||
const accessibleRoutes = await generateRoutes(mode, options);
|
||||
|
||||
// 优先按 name 找 Root:getRoutes() 扁平化后 path === '/' 也可能命中别的记录
|
||||
// 不要 removeRoute(Root) 再整棵加回:登录后进入 Root 子路由时卸掉 Root 会取消导航,停在「加载菜单中」。
|
||||
const root =
|
||||
router.getRoutes().find((item) => item.name === 'Root') ??
|
||||
router.getRoutes().find((item) => item.path === '/');
|
||||
|
||||
// 动态路由挂到 Root 下。不要 removeRoute(Root) 再整棵加回:
|
||||
// 登录后会进入已是 Root 子路由的 /welcome,卸掉 Root 会取消这次导航,停在「加载菜单中」。
|
||||
accessibleRoutes.forEach((route) => {
|
||||
if (root && !route.meta?.noBasicLayout) {
|
||||
// 为了兼容之前的版本用法,如果包含子路由,则将component移除,以免出现多层BasicLayout
|
||||
@@ -91,8 +91,10 @@ async function generateRoutes(
|
||||
generateRoutesByFrontend(routes, roles || [], forbiddenComponent),
|
||||
generateRoutesByBackend(options),
|
||||
]);
|
||||
|
||||
resultRoutes = [...frontend_resultRoutes, ...backend_resultRoutes];
|
||||
resultRoutes = mergeRoutesByName(
|
||||
backend_resultRoutes,
|
||||
frontend_resultRoutes,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -143,4 +145,63 @@ async function generateRoutes(
|
||||
return resultRoutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 name 合并前后端路由
|
||||
* @param baseRoutes 后端路由
|
||||
* @param extraRoutes 前端路由
|
||||
*/
|
||||
function mergeRoutesByName(
|
||||
baseRoutes: RouteRecordRaw[],
|
||||
extraRoutes: RouteRecordRaw[],
|
||||
): RouteRecordRaw[] {
|
||||
const result: RouteRecordRaw[] = [];
|
||||
const routeMap = new Map<string, RouteRecordRaw>();
|
||||
|
||||
for (const route of baseRoutes) {
|
||||
const clone = { ...route } as RouteRecordRaw;
|
||||
result.push(clone);
|
||||
if (clone.name && isString(clone.name)) {
|
||||
routeMap.set(clone.name as string, clone);
|
||||
}
|
||||
}
|
||||
|
||||
for (const route of extraRoutes) {
|
||||
if (
|
||||
route.name &&
|
||||
isString(route.name) &&
|
||||
routeMap.has(route.name as string)
|
||||
) {
|
||||
const existing = routeMap.get(route.name as string);
|
||||
if (!existing) {
|
||||
continue;
|
||||
}
|
||||
const existingChildren = existing.children ?? [];
|
||||
const routeChildren = route.children ?? [];
|
||||
|
||||
const merged = {
|
||||
...route,
|
||||
...existing, // keep backend as base
|
||||
meta: {
|
||||
...route.meta,
|
||||
...existing.meta, // backend meta wins on conflicts
|
||||
},
|
||||
} as RouteRecordRaw;
|
||||
|
||||
if (existingChildren.length > 0 || routeChildren.length > 0) {
|
||||
merged.children = mergeRoutesByName(existingChildren, routeChildren);
|
||||
}
|
||||
|
||||
Object.assign(existing, merged);
|
||||
} else {
|
||||
const clone = { ...route } as RouteRecordRaw;
|
||||
result.push(clone);
|
||||
if (clone.name && isString(clone.name)) {
|
||||
routeMap.set(clone.name as string, clone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export { generateAccessible };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vben/common-ui",
|
||||
"version": "5.5.9",
|
||||
"version": "5.7.0",
|
||||
"homepage": "https://github.com/vbenjs/vue-vben-admin",
|
||||
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
|
||||
"repository": {
|
||||
@@ -28,6 +28,7 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@vben-core/design": "workspace:*",
|
||||
"@vben-core/form-ui": "workspace:*",
|
||||
"@vben-core/popup-ui": "workspace:*",
|
||||
"@vben-core/preferences": "workspace:*",
|
||||
@@ -44,11 +45,14 @@
|
||||
"qrcode": "catalog:",
|
||||
"tippy.js": "catalog:",
|
||||
"vue": "catalog:",
|
||||
"vue-json-viewer": "catalog:",
|
||||
"vue-json-pretty": "catalog:",
|
||||
"vue-router": "catalog:",
|
||||
"vue-tippy": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/qrcode": "catalog:"
|
||||
"@types/json-bigint": "catalog:",
|
||||
"@types/qrcode": "catalog:",
|
||||
"@vue/test-utils": "catalog:",
|
||||
"vite": "catalog:"
|
||||
}
|
||||
}
|
||||
|
||||
+40
-75
@@ -1,7 +1,8 @@
|
||||
<script lang="ts" setup>
|
||||
import type { Component } from 'vue';
|
||||
|
||||
import type { AnyPromiseFunction } from '@vben/types';
|
||||
import type {
|
||||
ApiComponentProps,
|
||||
ApiComponentOptionsItem as OptionsItem,
|
||||
} from './types';
|
||||
|
||||
import { computed, nextTick, ref, unref, useAttrs, watch } from 'vue';
|
||||
|
||||
@@ -11,70 +12,13 @@ import { cloneDeep, get, isEqual, isFunction } from '@vben-core/shared/utils';
|
||||
|
||||
import { objectOmit } from '@vueuse/core';
|
||||
|
||||
type OptionsItem = {
|
||||
[name: string]: any;
|
||||
children?: OptionsItem[];
|
||||
disabled?: boolean;
|
||||
label?: string;
|
||||
value?: string;
|
||||
};
|
||||
|
||||
interface Props {
|
||||
/** 组件 */
|
||||
component: Component;
|
||||
/** 是否将value从数字转为string */
|
||||
numberToString?: boolean;
|
||||
/** 获取options数据的函数 */
|
||||
api?: (arg?: any) => Promise<OptionsItem[] | Record<string, any>>;
|
||||
/** 传递给api的参数 */
|
||||
params?: Record<string, any>;
|
||||
/** 从api返回的结果中提取options数组的字段名 */
|
||||
resultField?: string;
|
||||
/** label字段名 */
|
||||
labelField?: string;
|
||||
/** children字段名,需要层级数据的组件可用 */
|
||||
childrenField?: string;
|
||||
/** value字段名 */
|
||||
valueField?: string;
|
||||
/** 组件接收options数据的属性名 */
|
||||
optionsPropName?: string;
|
||||
/** 是否立即调用api */
|
||||
immediate?: boolean;
|
||||
/** 每次`visibleEvent`事件发生时都重新请求数据 */
|
||||
alwaysLoad?: boolean;
|
||||
/** 在api请求之前的回调函数 */
|
||||
beforeFetch?: AnyPromiseFunction<any, any>;
|
||||
/** 在api请求之后的回调函数 */
|
||||
afterFetch?: AnyPromiseFunction<any, any>;
|
||||
/** 直接传入选项数据,也作为api返回空数据时的后备数据 */
|
||||
options?: OptionsItem[];
|
||||
/** 组件的插槽名称,用来显示一个"加载中"的图标 */
|
||||
loadingSlot?: string;
|
||||
/** 触发api请求的事件名 */
|
||||
visibleEvent?: string;
|
||||
/** 组件的v-model属性名,默认为modelValue。部分组件可能为value */
|
||||
modelPropName?: string;
|
||||
/**
|
||||
* 自动选择
|
||||
* - `first`:自动选择第一个选项
|
||||
* - `last`:自动选择最后一个选项
|
||||
* - `one`: 当请求的结果只有一个选项时,自动选择该选项
|
||||
* - 函数:自定义选择逻辑,函数的参数为请求的结果数组,返回值为选择的选项
|
||||
* - false:不自动选择(默认)
|
||||
*/
|
||||
autoSelect?:
|
||||
| 'first'
|
||||
| 'last'
|
||||
| 'one'
|
||||
| ((item: OptionsItem[]) => OptionsItem)
|
||||
| false;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'ApiComponent', inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<ApiComponentProps>(), {
|
||||
labelField: 'label',
|
||||
valueField: 'value',
|
||||
labelFn: undefined,
|
||||
disabledField: 'disabled',
|
||||
childrenField: '',
|
||||
optionsPropName: 'options',
|
||||
resultField: '',
|
||||
@@ -85,6 +29,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
alwaysLoad: false,
|
||||
loadingSlot: '',
|
||||
beforeFetch: undefined,
|
||||
shouldFetch: undefined,
|
||||
afterFetch: undefined,
|
||||
modelPropName: 'modelValue',
|
||||
api: undefined,
|
||||
@@ -108,27 +53,39 @@ const isFirstLoaded = ref(false);
|
||||
const hasPendingRequest = ref(false);
|
||||
|
||||
const getOptions = computed(() => {
|
||||
const { labelField, valueField, childrenField, numberToString } = props;
|
||||
const {
|
||||
labelField,
|
||||
labelFn,
|
||||
valueField,
|
||||
disabledField,
|
||||
childrenField,
|
||||
numberToString,
|
||||
} = props;
|
||||
|
||||
const refOptionsData = unref(refOptions);
|
||||
|
||||
function transformData(data: OptionsItem[]): OptionsItem[] {
|
||||
function transformData(data: OptionsItem[] = []): OptionsItem[] {
|
||||
return data.map((item) => {
|
||||
const value = get(item, valueField);
|
||||
const children = childrenField ? get(item, childrenField) : item.children;
|
||||
return {
|
||||
...objectOmit(item, [labelField, valueField, childrenField]),
|
||||
label: get(item, labelField),
|
||||
...objectOmit(item, [
|
||||
labelField,
|
||||
valueField,
|
||||
disabledField,
|
||||
...(childrenField ? [childrenField] : []),
|
||||
]),
|
||||
label: labelFn ? labelFn(item) : get(item, labelField),
|
||||
value: numberToString ? `${value}` : value,
|
||||
...(childrenField && item[childrenField]
|
||||
? { children: transformData(item[childrenField]) }
|
||||
disabled: get(item, disabledField),
|
||||
...(Array.isArray(children) && children.length > 0
|
||||
? { children: transformData(children) }
|
||||
: {}),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const data: OptionsItem[] = transformData(refOptionsData);
|
||||
const data = transformData(unref(refOptions));
|
||||
|
||||
return data.length > 0 ? data : props.options;
|
||||
return data.length > 0 ? data : transformData(props.options);
|
||||
});
|
||||
|
||||
const bindProps = computed(() => {
|
||||
@@ -148,7 +105,7 @@ const bindProps = computed(() => {
|
||||
});
|
||||
|
||||
async function fetchApi() {
|
||||
const { api, beforeFetch, afterFetch, resultField } = props;
|
||||
const { api, beforeFetch, shouldFetch, afterFetch, resultField } = props;
|
||||
|
||||
if (!api || !isFunction(api)) {
|
||||
return;
|
||||
@@ -167,6 +124,14 @@ async function fetchApi() {
|
||||
if (beforeFetch && isFunction(beforeFetch)) {
|
||||
finalParams = (await beforeFetch(cloneDeep(finalParams))) || finalParams;
|
||||
}
|
||||
// 判断是否需要控制执行中断
|
||||
if (
|
||||
shouldFetch &&
|
||||
isFunction(shouldFetch) &&
|
||||
!(await shouldFetch(finalParams))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
let res = await api(finalParams);
|
||||
if (afterFetch && isFunction(afterFetch)) {
|
||||
res = (await afterFetch(res)) || res;
|
||||
@@ -264,7 +229,7 @@ defineExpose({
|
||||
/** 获取当前值 */
|
||||
getValue: () => unref(modelValue),
|
||||
/** 获取被包装的组件实例 */
|
||||
getComponentRef: <T = any,>() => componentRef.value as T,
|
||||
getComponentRef: <T = any>() => componentRef.value as T,
|
||||
/** 更新Api参数 */
|
||||
updateParam(newParams: Record<string, any>) {
|
||||
innerParams.value = newParams;
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
export { default as ApiComponent } from './api-component.vue';
|
||||
export type {
|
||||
ApiComponentLabelFn,
|
||||
ApiComponentOptionsItem,
|
||||
ApiComponentProps,
|
||||
ApiComponentSharedProps,
|
||||
} from './types';
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { Component } from 'vue';
|
||||
|
||||
import type { AnyPromiseFunction } from '@vben/types';
|
||||
|
||||
export type ApiComponentOptionsItem = {
|
||||
[name: string]: any;
|
||||
children?: ApiComponentOptionsItem[];
|
||||
disabled?: boolean;
|
||||
label?: string;
|
||||
value?: number | string;
|
||||
};
|
||||
|
||||
export type ApiComponentLabelFn = (item: ApiComponentOptionsItem) => string;
|
||||
|
||||
export interface ApiComponentProps {
|
||||
/** 组件 */
|
||||
component: Component;
|
||||
/** 是否将value从数字转为string */
|
||||
numberToString?: boolean;
|
||||
/** 获取options数据的函数 */
|
||||
api?: (arg?: any) => Promise<ApiComponentOptionsItem[] | Record<string, any>>;
|
||||
/** 传递给api的参数 */
|
||||
params?: Record<string, any>;
|
||||
/** 从api返回的结果中提取options数组的字段名 */
|
||||
resultField?: string;
|
||||
/** label字段名 */
|
||||
labelField?: string;
|
||||
/** 通过选项数据自定义label */
|
||||
labelFn?: ApiComponentLabelFn;
|
||||
/** children字段名,需要层级数据的组件可用 */
|
||||
childrenField?: string;
|
||||
/** value字段名 */
|
||||
valueField?: string;
|
||||
/** disabled字段名 */
|
||||
disabledField?: string;
|
||||
/** 组件接收options数据的属性名 */
|
||||
optionsPropName?: string;
|
||||
/** 是否立即调用api */
|
||||
immediate?: boolean;
|
||||
/** 每次`visibleEvent`事件发生时都重新请求数据 */
|
||||
alwaysLoad?: boolean;
|
||||
/** 在api请求之前的回调函数 */
|
||||
beforeFetch?: AnyPromiseFunction<any, any>;
|
||||
/** 在api请求之前的判断是否允许请求的回调函数 */
|
||||
shouldFetch?: AnyPromiseFunction<any, boolean>;
|
||||
/** 在api请求之后的回调函数 */
|
||||
afterFetch?: AnyPromiseFunction<any, any>;
|
||||
/** 直接传入选项数据,也作为api返回空数据时的后备数据 */
|
||||
options?: ApiComponentOptionsItem[];
|
||||
/** 组件的插槽名称,用来显示一个"加载中"的图标 */
|
||||
loadingSlot?: string;
|
||||
/** 触发api请求的事件名 */
|
||||
visibleEvent?: string;
|
||||
/** 组件的v-model属性名,默认为modelValue。部分组件可能为value */
|
||||
modelPropName?: string;
|
||||
/**
|
||||
* 自动选择
|
||||
* - `first`:自动选择第一个选项
|
||||
* - `last`:自动选择最后一个选项
|
||||
* - `one`: 当请求的结果只有一个选项时,自动选择该选项
|
||||
* - 函数:自定义选择逻辑,函数的参数为请求的结果数组,返回值为选择的选项
|
||||
* - false:不自动选择(默认)
|
||||
*/
|
||||
autoSelect?:
|
||||
| 'first'
|
||||
| 'last'
|
||||
| 'one'
|
||||
| ((item: ApiComponentOptionsItem[]) => ApiComponentOptionsItem)
|
||||
| false;
|
||||
}
|
||||
|
||||
export type ApiComponentSharedProps = Omit<ApiComponentProps, 'component'>;
|
||||
+3
-3
@@ -152,7 +152,7 @@ function handleConfirm() {
|
||||
top: `${point.y - POINT_OFFSET}px`,
|
||||
left: `${point.x - POINT_OFFSET}px`,
|
||||
}"
|
||||
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"
|
||||
class="absolute z-20 flex-center size-5 cursor-default rounded-full border-2 border-primary-50 bg-primary text-primary-50"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
@@ -163,11 +163,11 @@ function handleConfirm() {
|
||||
v-if="hintImage"
|
||||
:alt="$t('ui.captcha.alt')"
|
||||
:src="hintImage"
|
||||
class="border-border h-10 w-full rounded border"
|
||||
class="h-10 w-full rounded-sm border border-border"
|
||||
/>
|
||||
<div
|
||||
v-else-if="hintText"
|
||||
class="border-border flex-center h-10 w-full rounded border"
|
||||
class="flex-center h-10 w-full rounded-sm border border-border"
|
||||
>
|
||||
{{ `${$t('ui.captcha.clickInOrder')}` + `【${hintText}】` }}
|
||||
</div>
|
||||
|
||||
+3
-1
@@ -64,7 +64,9 @@ function handleClick(e: MouseEvent) {
|
||||
</div>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="relative mt-2 flex w-full overflow-hidden rounded p-0">
|
||||
<CardContent
|
||||
class="relative mt-2 flex w-full overflow-hidden rounded-sm p-0"
|
||||
>
|
||||
<img
|
||||
v-show="captchaImage"
|
||||
:alt="$t('ui.captcha.alt')"
|
||||
|
||||
+25
-15
@@ -50,9 +50,11 @@ defineExpose({
|
||||
});
|
||||
|
||||
const wrapperRef = useTemplateRef<HTMLDivElement>('wrapperRef');
|
||||
const barRef = useTemplateRef<typeof SliderCaptchaBar>('barRef');
|
||||
const contentRef = useTemplateRef<typeof SliderCaptchaContent>('contentRef');
|
||||
const actionRef = useTemplateRef<typeof SliderCaptchaAction>('actionRef');
|
||||
const barRef = useTemplateRef<InstanceType<typeof SliderCaptchaBar>>('barRef');
|
||||
const contentRef =
|
||||
useTemplateRef<InstanceType<typeof SliderCaptchaContent>>('contentRef');
|
||||
const actionRef =
|
||||
useTemplateRef<InstanceType<typeof SliderCaptchaAction>>('actionRef');
|
||||
|
||||
watch(
|
||||
() => state.isPassing,
|
||||
@@ -83,20 +85,19 @@ function handleDragStart(e: MouseEvent | TouchEvent) {
|
||||
if (state.isPassing) {
|
||||
return;
|
||||
}
|
||||
if (!actionRef.value) return;
|
||||
const actionEl = actionRef.value;
|
||||
const actionStyle = actionEl?.getStyle();
|
||||
if (!actionEl || !actionStyle) return;
|
||||
emit('start', e);
|
||||
|
||||
state.moveDistance =
|
||||
getEventPageX(e) -
|
||||
Number.parseInt(
|
||||
actionRef.value.getStyle().left.replace('px', '') || '0',
|
||||
10,
|
||||
);
|
||||
Number.parseInt(actionStyle.left.replace('px', '') || '0', 10);
|
||||
state.startTime = Date.now();
|
||||
state.isMoving = true;
|
||||
}
|
||||
|
||||
function getOffset(actionEl: HTMLDivElement) {
|
||||
function getOffset(actionEl?: HTMLDivElement | null) {
|
||||
const wrapperWidth = wrapperRef.value?.offsetWidth ?? 220;
|
||||
const actionWidth = actionEl?.offsetWidth ?? 40;
|
||||
const offset = wrapperWidth - actionWidth - 6;
|
||||
@@ -109,7 +110,9 @@ function handleDragMoving(e: MouseEvent | TouchEvent) {
|
||||
const actionEl = unref(actionRef);
|
||||
const barEl = unref(barRef);
|
||||
if (!actionEl || !barEl) return;
|
||||
const { actionWidth, offset, wrapperWidth } = getOffset(actionEl.getEl());
|
||||
const actionNode = actionEl.getEl();
|
||||
if (!actionNode) return;
|
||||
const { actionWidth, offset, wrapperWidth } = getOffset(actionNode);
|
||||
const moveX = getEventPageX(e) - moveDistance;
|
||||
|
||||
emit('move', {
|
||||
@@ -138,14 +141,18 @@ function handleDragOver(e: MouseEvent | TouchEvent) {
|
||||
const barEl = unref(barRef);
|
||||
if (!actionEl || !barEl) return;
|
||||
const moveX = getEventPageX(e) - moveDistance;
|
||||
const { actionWidth, offset, wrapperWidth } = getOffset(actionEl.getEl());
|
||||
const actionNode = actionEl.getEl();
|
||||
if (!actionNode) return;
|
||||
const { actionWidth, offset, wrapperWidth } = getOffset(actionNode);
|
||||
if (moveX < offset) {
|
||||
if (props.isSlot) {
|
||||
setTimeout(() => {
|
||||
if (modelValue.value) {
|
||||
const contentEl = unref(contentRef);
|
||||
if (contentEl) {
|
||||
contentEl.getEl().style.width = `${Number.parseInt(barEl.getEl().style.width)}px`;
|
||||
const contentNode = contentEl?.getEl();
|
||||
const barNode = barEl.getEl();
|
||||
if (contentNode && barNode) {
|
||||
contentNode.style.width = `${Number.parseInt(barNode.style.width || '0', 10)}px`;
|
||||
}
|
||||
} else {
|
||||
resume();
|
||||
@@ -185,7 +192,10 @@ function resume() {
|
||||
const contentEl = unref(contentRef);
|
||||
if (!actionEl || !barEl || !contentEl) return;
|
||||
|
||||
contentEl.getEl().style.width = '100%';
|
||||
const contentNode = contentEl.getEl();
|
||||
if (!contentNode) return;
|
||||
|
||||
contentNode.style.width = '100%';
|
||||
state.toLeft = true;
|
||||
useTimeoutFn(() => {
|
||||
state.toLeft = false;
|
||||
@@ -200,7 +210,7 @@ function resume() {
|
||||
ref="wrapperRef"
|
||||
:class="
|
||||
cn(
|
||||
'border-border bg-background-deep relative flex h-10 w-full items-center overflow-hidden rounded-md border text-center',
|
||||
'relative flex h-10 w-full items-center overflow-hidden rounded-md border border-border bg-muted text-center',
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
|
||||
+3
-3
@@ -48,14 +48,14 @@ defineExpose({
|
||||
<div
|
||||
ref="actionRef"
|
||||
:class="{
|
||||
'transition-width !left-0 duration-300': toLeft,
|
||||
'transition-width left-0! duration-300': toLeft,
|
||||
'rounded-md': isDragging,
|
||||
}"
|
||||
:style="style"
|
||||
class="bg-background dark:bg-accent absolute left-0 top-0 flex h-full cursor-move items-center justify-center px-3.5 shadow-md"
|
||||
class="absolute top-0 left-0 flex-center z-10 h-full cursor-move border-r border-border bg-background px-3.5 shadow-md dark:bg-accent"
|
||||
name="captcha-action"
|
||||
>
|
||||
<Slot :is-passing="isPassing" class="text-foreground/60 size-4">
|
||||
<Slot :is-passing="isPassing" class="size-4 text-foreground/60">
|
||||
<slot name="icon">
|
||||
<ChevronsRight v-if="!isPassing" />
|
||||
<Check v-else />
|
||||
|
||||
+2
-2
@@ -33,8 +33,8 @@ defineExpose({
|
||||
<template>
|
||||
<div
|
||||
ref="barRef"
|
||||
:class="toLeft && 'transition-width !w-0 duration-300'"
|
||||
:class="toLeft && 'transition-width w-0! duration-300'"
|
||||
:style="style"
|
||||
class="bg-success absolute h-full"
|
||||
class="absolute h-full bg-success"
|
||||
></div>
|
||||
</template>
|
||||
|
||||
+4
-14
@@ -3,8 +3,6 @@ import type { CSSProperties } from 'vue';
|
||||
|
||||
import { computed, useTemplateRef } from 'vue';
|
||||
|
||||
import { VbenSpineText } from '@vben-core/shadcn-ui';
|
||||
|
||||
const props = defineProps<{
|
||||
contentStyle: CSSProperties;
|
||||
isPassing: boolean;
|
||||
@@ -32,22 +30,14 @@ defineExpose({
|
||||
<template>
|
||||
<div
|
||||
ref="contentRef"
|
||||
:class="{
|
||||
[$style.success]: isPassing,
|
||||
}"
|
||||
:style="style"
|
||||
class="absolute top-0 flex size-full select-none items-center justify-center text-xs"
|
||||
class="absolute top-0 flex-center size-full select-none text-xs"
|
||||
:class="isPassing ? 'font-medium text-foreground' : 'text-muted-foreground'"
|
||||
>
|
||||
<slot name="text">
|
||||
<VbenSpineText class="flex h-full items-center">
|
||||
<span class="flex h-full items-center">
|
||||
{{ isPassing ? successText : text }}
|
||||
</VbenSpineText>
|
||||
</span>
|
||||
</slot>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style module>
|
||||
.success {
|
||||
-webkit-text-fill-color: hsl(0deg 0% 98%);
|
||||
}
|
||||
</style>
|
||||
|
||||
+4
-4
@@ -84,12 +84,12 @@ function handleDragBarMove(data: SliderRotateVerifyPassingData) {
|
||||
state.dragging = true;
|
||||
const { imageSize, maxDegree } = props;
|
||||
const { moveX } = data;
|
||||
const denominator = imageSize!;
|
||||
const denominator = imageSize;
|
||||
if (denominator === 0) {
|
||||
return;
|
||||
}
|
||||
const currentRotate = Math.ceil(
|
||||
(moveX / denominator) * 1.5 * maxDegree! * unref(getFactorRef),
|
||||
(moveX / denominator) * 1.5 * maxDegree * unref(getFactorRef),
|
||||
);
|
||||
state.currentRotate = currentRotate;
|
||||
setImgRotate(state.randomRotate - currentRotate);
|
||||
@@ -98,7 +98,7 @@ function handleDragBarMove(data: SliderRotateVerifyPassingData) {
|
||||
function handleImgOnLoad() {
|
||||
const { maxDegree, minDegree } = props;
|
||||
const ranRotate = Math.floor(
|
||||
minDegree! + Math.random() * (maxDegree! - minDegree!),
|
||||
minDegree + Math.random() * (maxDegree - minDegree),
|
||||
); // 生成随机角度
|
||||
state.randomRotate = ranRotate;
|
||||
setImgRotate(ranRotate);
|
||||
@@ -167,7 +167,7 @@ defineExpose({
|
||||
<div class="relative flex flex-col items-center">
|
||||
<div
|
||||
:style="getImgWrapStyleRef"
|
||||
class="border-border relative cursor-pointer overflow-hidden rounded-full border shadow-md"
|
||||
class="relative cursor-pointer overflow-hidden rounded-full border border-border shadow-md"
|
||||
>
|
||||
<img
|
||||
:class="imgCls"
|
||||
|
||||
+11
-11
@@ -35,12 +35,12 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const PI: number = Math.PI;
|
||||
enum CanvasOpr {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
Clip = 'clip',
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
Fill = 'fill',
|
||||
}
|
||||
const canvasOpr = {
|
||||
clip: 'clip',
|
||||
fill: 'fill',
|
||||
} as const;
|
||||
|
||||
type CanvasOpr = (typeof canvasOpr)[keyof typeof canvasOpr];
|
||||
|
||||
const modalValue = defineModel<boolean>({ default: false });
|
||||
|
||||
@@ -189,8 +189,8 @@ function draw(ctx1: CanvasRenderingContext2D, ctx2: CanvasRenderingContext2D) {
|
||||
3 * circleRadius,
|
||||
canvasHeight - (squareLength + 2 * circleRadius),
|
||||
);
|
||||
drawPiece(ctx1, state.pieceX, state.pieceY, CanvasOpr.Fill);
|
||||
drawPiece(ctx2, state.pieceX, state.pieceY, CanvasOpr.Clip);
|
||||
drawPiece(ctx1, state.pieceX, state.pieceY, canvasOpr.fill);
|
||||
drawPiece(ctx2, state.pieceX, state.pieceY, canvasOpr.clip);
|
||||
}
|
||||
|
||||
// 绘制拼图切块
|
||||
@@ -233,7 +233,7 @@ function drawPiece(
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.7)';
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.7)';
|
||||
ctx.stroke();
|
||||
opr === CanvasOpr.Clip ? ctx.clip() : ctx.fill();
|
||||
opr === canvasOpr.clip ? ctx.clip() : ctx.fill();
|
||||
ctx.globalCompositeOperation = 'destination-over';
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ onMounted(() => {
|
||||
<template>
|
||||
<div class="relative flex flex-col items-center">
|
||||
<div
|
||||
class="border-border relative flex cursor-pointer overflow-hidden border shadow-md"
|
||||
class="relative flex cursor-pointer overflow-hidden border border-border shadow-md"
|
||||
>
|
||||
<canvas
|
||||
ref="puzzleCanvasRef"
|
||||
@@ -278,7 +278,7 @@ onMounted(() => {
|
||||
@click="resume"
|
||||
></canvas>
|
||||
<div
|
||||
class="h-15 absolute bottom-3 left-0 z-10 block w-full text-center text-xs leading-[30px] text-white"
|
||||
class="absolute bottom-3 left-0 z-10 block h-15 w-full text-center text-xs leading-[30px] text-white"
|
||||
>
|
||||
<div
|
||||
v-if="state.showTip"
|
||||
|
||||
@@ -54,8 +54,7 @@ export interface PointSelectionCaptchaCardProps {
|
||||
width?: number | string;
|
||||
}
|
||||
|
||||
export interface PointSelectionCaptchaProps
|
||||
extends PointSelectionCaptchaCardProps {
|
||||
export interface PointSelectionCaptchaProps extends PointSelectionCaptchaCardProps {
|
||||
/**
|
||||
* 是否展示确定按钮
|
||||
* @default false
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ColPageProps } from './types';
|
||||
|
||||
import { computed, nextTick, onMounted, ref, unref, useSlots, watch } from 'vue';
|
||||
import { computed, ref, useSlots } from 'vue';
|
||||
|
||||
import {
|
||||
ResizableHandle,
|
||||
@@ -18,34 +18,12 @@ defineOptions({
|
||||
|
||||
const props = withDefaults(defineProps<ColPageProps>(), {
|
||||
leftWidth: 30,
|
||||
leftCollapsed: false,
|
||||
rightWidth: 70,
|
||||
resizable: true,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:leftWidth': [width: number];
|
||||
'update:leftCollapsed': [collapsed: boolean];
|
||||
}>();
|
||||
|
||||
const delegatedProps = computed(() => {
|
||||
const {
|
||||
leftWidth: _leftWidth,
|
||||
leftMinWidth: _leftMinWidth,
|
||||
leftMaxWidth: _leftMaxWidth,
|
||||
leftCollapsedWidth: _leftCollapsedWidth,
|
||||
leftCollapsible: _leftCollapsible,
|
||||
leftCollapsed: _leftCollapsed,
|
||||
rightWidth: _rightWidth,
|
||||
rightMinWidth: _rightMinWidth,
|
||||
rightMaxWidth: _rightMaxWidth,
|
||||
rightCollapsedWidth: _rightCollapsedWidth,
|
||||
rightCollapsible: _rightCollapsible,
|
||||
resizable: _resizable,
|
||||
splitLine: _splitLine,
|
||||
splitHandle: _splitHandle,
|
||||
...delegated
|
||||
} = props;
|
||||
const { leftWidth: _, ...delegated } = props;
|
||||
return delegated;
|
||||
});
|
||||
|
||||
@@ -63,32 +41,6 @@ const delegatedSlots = computed(() => {
|
||||
});
|
||||
|
||||
const leftPanelRef = ref<InstanceType<typeof ResizablePanel>>();
|
||||
/** 自身操作引起的回写,避免与外部 v-model 互相触发 */
|
||||
const suppressExternalSync = ref(false);
|
||||
|
||||
const leftDefaultSize = computed(() =>
|
||||
props.leftCollapsed
|
||||
? (props.leftCollapsedWidth ?? 0)
|
||||
: props.leftWidth,
|
||||
);
|
||||
|
||||
const rightDefaultSize = computed(() =>
|
||||
props.leftCollapsed
|
||||
? 100 - (props.leftCollapsedWidth ?? 0)
|
||||
: props.rightWidth,
|
||||
);
|
||||
|
||||
function isLeftCollapsed() {
|
||||
return !!unref(leftPanelRef.value?.isCollapsed);
|
||||
}
|
||||
|
||||
function runAsSelfApply(apply: () => void) {
|
||||
suppressExternalSync.value = true;
|
||||
apply();
|
||||
void nextTick(() => {
|
||||
suppressExternalSync.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
function expandLeft() {
|
||||
leftPanelRef.value?.expand();
|
||||
@@ -98,56 +50,6 @@ function collapseLeft() {
|
||||
leftPanelRef.value?.collapse();
|
||||
}
|
||||
|
||||
function applyCollapsed(collapsed: boolean) {
|
||||
const panel = leftPanelRef.value;
|
||||
if (!panel) return;
|
||||
if (collapsed) {
|
||||
panel.collapse();
|
||||
return;
|
||||
}
|
||||
panel.expand();
|
||||
void nextTick(() => panel.resize(props.leftWidth));
|
||||
}
|
||||
|
||||
function onLeftCollapse() {
|
||||
runAsSelfApply(() => emit('update:leftCollapsed', true));
|
||||
}
|
||||
|
||||
function onLeftExpand() {
|
||||
runAsSelfApply(() => emit('update:leftCollapsed', false));
|
||||
}
|
||||
|
||||
/** 收起过程中的尺寸不写入展开宽度 */
|
||||
function onLeftResize(size: number) {
|
||||
const collapsedSize = props.leftCollapsedWidth ?? 0;
|
||||
if (isLeftCollapsed() || size <= collapsedSize + 0.51) return;
|
||||
if (Math.abs(size - props.leftWidth) < 0.15) return;
|
||||
runAsSelfApply(() => emit('update:leftWidth', size));
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.leftCollapsed,
|
||||
(collapsed) => {
|
||||
if (suppressExternalSync.value) return;
|
||||
applyCollapsed(collapsed);
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.leftWidth,
|
||||
(width) => {
|
||||
if (suppressExternalSync.value || isLeftCollapsed()) return;
|
||||
const current = leftPanelRef.value?.getSize();
|
||||
if (current == null || Math.abs(current - width) < 0.3) return;
|
||||
leftPanelRef.value?.resize(width);
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
if (!props.leftCollapsed) return;
|
||||
void nextTick(() => applyCollapsed(true));
|
||||
});
|
||||
|
||||
defineExpose({
|
||||
expandLeft,
|
||||
collapseLeft,
|
||||
@@ -166,16 +68,12 @@ defineExpose({
|
||||
|
||||
<ResizablePanelGroup class="w-full" direction="horizontal">
|
||||
<ResizablePanel
|
||||
id="col-page-left"
|
||||
ref="leftPanelRef"
|
||||
:collapsed-size="leftCollapsedWidth"
|
||||
:collapsible="leftCollapsible"
|
||||
:default-size="leftDefaultSize"
|
||||
:default-size="leftWidth"
|
||||
:max-size="leftMaxWidth"
|
||||
:min-size="leftMinWidth"
|
||||
@collapse="onLeftCollapse"
|
||||
@expand="onLeftExpand"
|
||||
@resize="onLeftResize"
|
||||
>
|
||||
<template #default="slotProps">
|
||||
<slot
|
||||
@@ -194,10 +92,9 @@ defineExpose({
|
||||
:with-handle="splitHandle"
|
||||
/>
|
||||
<ResizablePanel
|
||||
id="col-page-right"
|
||||
:collapsed-size="rightCollapsedWidth"
|
||||
:collapsible="rightCollapsible"
|
||||
:default-size="rightDefaultSize"
|
||||
:default-size="rightWidth"
|
||||
:max-size="rightMaxWidth"
|
||||
:min-size="rightMinWidth"
|
||||
>
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { PageProps } from '../page/types';
|
||||
|
||||
export interface ColPageProps extends PageProps {
|
||||
/**
|
||||
* 左侧宽度(百分比 1-100)。配合 `update:leftWidth` 可做受控/持久化。
|
||||
* 左侧宽度
|
||||
* @default 30
|
||||
*/
|
||||
leftWidth?: number;
|
||||
@@ -10,10 +10,6 @@ export interface ColPageProps extends PageProps {
|
||||
leftMaxWidth?: number;
|
||||
leftCollapsedWidth?: number;
|
||||
leftCollapsible?: boolean;
|
||||
/**
|
||||
* 左侧是否收起。配合 `update:leftCollapsed` 可做受控/持久化。
|
||||
*/
|
||||
leftCollapsed?: boolean;
|
||||
/**
|
||||
* 右侧宽度
|
||||
* @default 70
|
||||
|
||||
@@ -0,0 +1,981 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
|
||||
// 定义组件参数
|
||||
const props = defineProps<{
|
||||
/** 裁剪比例 格式如 '1:1', '16:9', '3:4' 等(非必填) */
|
||||
aspectRatio?: string;
|
||||
/** 容器高度(默认400) */
|
||||
height?: number;
|
||||
/** 图片地址 */
|
||||
img: string;
|
||||
/** 容器宽度(默认500) */
|
||||
width?: number;
|
||||
}>();
|
||||
|
||||
const CROPPER_CONSTANTS = {
|
||||
MIN_WIDTH: 60 as const,
|
||||
MIN_HEIGHT: 60 as const,
|
||||
DEFAULT_WIDTH: 500 as const,
|
||||
DEFAULT_HEIGHT: 400 as const,
|
||||
PADDING_RATIO: 0.1 as const,
|
||||
MAX_PADDING: 50 as const,
|
||||
} as const;
|
||||
|
||||
type Point = [number, number]; // [clientX, clientY]
|
||||
type Dimension = [number, number, number, number]; // [top, right, bottom, left]
|
||||
|
||||
// 拖拽点类型
|
||||
type DragAction =
|
||||
| 'bottom'
|
||||
| 'bottom-left'
|
||||
| 'bottom-right'
|
||||
| 'left'
|
||||
| 'move'
|
||||
| 'right'
|
||||
| 'top'
|
||||
| 'top-left'
|
||||
| 'top-right';
|
||||
|
||||
// DOM 引用
|
||||
const containerRef = ref<HTMLDivElement | null>(null);
|
||||
const bgImageRef = ref<HTMLImageElement | null>(null);
|
||||
// const maskRef = ref<HTMLDivElement | null>(null);
|
||||
const maskViewRef = ref<HTMLDivElement | null>(null);
|
||||
const cropperRef = ref<HTMLDivElement | null>(null);
|
||||
// const cropperViewRef = ref<HTMLDivElement | null>(null);
|
||||
|
||||
// 响应式数据
|
||||
const isCropperVisible = ref<boolean>(false);
|
||||
const validAspectRatio = ref<null | number>(null); // 有效比例值(null表示无固定比例)
|
||||
const containerWidth = ref<number>(
|
||||
props.width ?? CROPPER_CONSTANTS.DEFAULT_WIDTH,
|
||||
);
|
||||
const containerHeight = ref<number>(
|
||||
props.height ?? CROPPER_CONSTANTS.DEFAULT_HEIGHT,
|
||||
);
|
||||
|
||||
// 裁剪区域尺寸(top, right, bottom, left)
|
||||
const currentDimension = ref<Dimension>([50, 50, 50, 50]);
|
||||
const initDimension = ref<Dimension>([50, 50, 50, 50]);
|
||||
|
||||
// 拖拽状态
|
||||
const dragging = ref<boolean>(false);
|
||||
const startPoint = ref<Point>([0, 0]);
|
||||
const startDimension = ref<Dimension>([0, 0, 0, 0]);
|
||||
const direction = ref<Dimension>([0, 0, 0, 0]);
|
||||
const moving = ref<boolean>(false);
|
||||
|
||||
/**
|
||||
* 计算图片的适配尺寸,保证完整显示且不超过最大宽高限制
|
||||
*/
|
||||
const calculateImageFitSize = () => {
|
||||
if (!bgImageRef.value) return;
|
||||
|
||||
// 获取图片原始尺寸
|
||||
const imgWidth = bgImageRef.value.naturalWidth;
|
||||
const imgHeight = bgImageRef.value.naturalHeight;
|
||||
|
||||
if (imgWidth === 0 || imgHeight === 0) return;
|
||||
|
||||
// 计算缩放比例(使用传入的width/height,默认500/400)
|
||||
const widthRatio =
|
||||
(props.width ?? CROPPER_CONSTANTS.DEFAULT_WIDTH) / imgWidth;
|
||||
const heightRatio =
|
||||
(props.height ?? CROPPER_CONSTANTS.DEFAULT_HEIGHT) / imgHeight;
|
||||
const scaleRatio = Math.min(widthRatio, heightRatio, 1); // 不放大图片,只缩小
|
||||
|
||||
// 计算适配后的容器尺寸
|
||||
const fitWidth = Math.floor(imgWidth * scaleRatio);
|
||||
const fitHeight = Math.floor(imgHeight * scaleRatio);
|
||||
|
||||
containerWidth.value = fitWidth;
|
||||
containerHeight.value = fitHeight;
|
||||
|
||||
// 重置裁剪框初始尺寸(基于新的容器尺寸)
|
||||
const padding = Math.min(
|
||||
CROPPER_CONSTANTS.MAX_PADDING,
|
||||
Math.floor(fitWidth * CROPPER_CONSTANTS.PADDING_RATIO),
|
||||
Math.floor(fitHeight * CROPPER_CONSTANTS.PADDING_RATIO),
|
||||
);
|
||||
|
||||
initDimension.value = [padding, padding, padding, padding];
|
||||
currentDimension.value = [padding, padding, padding, padding];
|
||||
};
|
||||
|
||||
/**
|
||||
* 验证并解析比例字符串
|
||||
* @returns {number|null} 比例值 (width/height),解析失败返回null
|
||||
*/
|
||||
const parseAndValidateAspectRatio = (): null | number => {
|
||||
// 如果未传入比例参数,直接返回null
|
||||
if (!props.aspectRatio) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 验证比例格式
|
||||
const ratioRegex = /^[1-9]\d*:[1-9]\d*$/;
|
||||
if (!ratioRegex.test(props.aspectRatio)) {
|
||||
console.warn('裁剪比例格式错误,应为 "数字:数字" 格式,如 "16:9"');
|
||||
return null;
|
||||
}
|
||||
|
||||
// 解析比例
|
||||
const [width, height] = props.aspectRatio.split(':').map(Number);
|
||||
|
||||
// 验证解析结果有效性
|
||||
if (Number.isNaN(width) || Number.isNaN(height) || !width || !height) {
|
||||
console.warn('裁剪比例解析失败,宽高必须为正整数');
|
||||
return null;
|
||||
}
|
||||
|
||||
return width / height;
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置裁剪区域尺寸
|
||||
* @param {Dimension} dimension - [top, right, bottom, left]
|
||||
*/
|
||||
const setDimension = (dimension: Dimension) => {
|
||||
currentDimension.value = [...dimension];
|
||||
if (maskViewRef.value) {
|
||||
maskViewRef.value.style.clipPath = `inset(${dimension[0]}px ${dimension[1]}px ${dimension[2]}px ${dimension[3]}px)`;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 调整裁剪区域至指定比例
|
||||
*/
|
||||
const adjustCropperToAspectRatio = () => {
|
||||
if (!cropperRef.value) return;
|
||||
|
||||
// 验证并解析比例
|
||||
validAspectRatio.value = parseAndValidateAspectRatio();
|
||||
|
||||
// 如果无有效比例,使用初始尺寸,不强制固定比例
|
||||
if (validAspectRatio.value === null) {
|
||||
setDimension(initDimension.value);
|
||||
return;
|
||||
}
|
||||
|
||||
// 有有效比例,按比例调整裁剪框
|
||||
const ratio = validAspectRatio.value;
|
||||
const containerWidthVal = containerWidth.value;
|
||||
const containerHeightVal = containerHeight.value;
|
||||
|
||||
// 根据比例计算裁剪框尺寸
|
||||
let newHeight: number, newWidth: number;
|
||||
|
||||
// 先按宽度优先计算
|
||||
newWidth = containerWidthVal;
|
||||
newHeight = newWidth / ratio;
|
||||
|
||||
// 如果高度超出容器,按高度优先计算
|
||||
if (newHeight > containerHeightVal) {
|
||||
newHeight = containerHeightVal;
|
||||
newWidth = newHeight * ratio;
|
||||
}
|
||||
|
||||
// 居中显示
|
||||
const leftRight = (containerWidthVal - newWidth) / 2;
|
||||
const topBottom = (containerHeightVal - newHeight) / 2;
|
||||
|
||||
const newDimension: Dimension = [topBottom, leftRight, topBottom, leftRight];
|
||||
|
||||
setDimension(newDimension);
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建裁剪器
|
||||
*/
|
||||
const createCropper = () => {
|
||||
// 计算图片适配尺寸
|
||||
calculateImageFitSize();
|
||||
|
||||
isCropperVisible.value = true;
|
||||
adjustCropperToAspectRatio();
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理鼠标按下事件
|
||||
* @param {MouseEvent} e - 鼠标事件
|
||||
* @param {DragAction} action - 操作类型
|
||||
*/
|
||||
const handleMouseDown = (e: MouseEvent, action: DragAction) => {
|
||||
dragging.value = true;
|
||||
startPoint.value = [e.clientX, e.clientY];
|
||||
startDimension.value = [...currentDimension.value];
|
||||
direction.value = [0, 0, 0, 0];
|
||||
moving.value = false;
|
||||
|
||||
// 处理移动
|
||||
if (action === 'move') {
|
||||
direction.value[0] = 1;
|
||||
direction.value[2] = -1;
|
||||
direction.value[3] = 1;
|
||||
direction.value[1] = -1;
|
||||
moving.value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理拖拽方向
|
||||
switch (action) {
|
||||
case 'bottom': {
|
||||
direction.value[2] = -1;
|
||||
break;
|
||||
}
|
||||
case 'bottom-left': {
|
||||
direction.value[2] = -1;
|
||||
direction.value[3] = 1;
|
||||
break;
|
||||
}
|
||||
case 'bottom-right': {
|
||||
direction.value[2] = -1;
|
||||
direction.value[1] = -1;
|
||||
break;
|
||||
}
|
||||
case 'left': {
|
||||
direction.value[3] = 1;
|
||||
break;
|
||||
}
|
||||
case 'right': {
|
||||
direction.value[1] = -1;
|
||||
break;
|
||||
}
|
||||
case 'top': {
|
||||
direction.value[0] = 1;
|
||||
break;
|
||||
}
|
||||
case 'top-left': {
|
||||
direction.value[0] = 1;
|
||||
direction.value[3] = 1;
|
||||
break;
|
||||
}
|
||||
case 'top-right': {
|
||||
direction.value[0] = 1;
|
||||
direction.value[1] = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理鼠标移动事件
|
||||
* @param {MouseEvent} e - 鼠标事件
|
||||
*/
|
||||
const handleMouseMove = (e: MouseEvent) => {
|
||||
if (!dragging.value || !cropperRef.value) return;
|
||||
|
||||
const { clientX, clientY } = e;
|
||||
const diffX = clientX - startPoint.value[0];
|
||||
const diffY = clientY - startPoint.value[1];
|
||||
|
||||
// 处理移动裁剪框
|
||||
if (moving.value) {
|
||||
handleMoveCropBox(diffX, diffY);
|
||||
return;
|
||||
}
|
||||
|
||||
// 无有效比例
|
||||
if (validAspectRatio.value === null) {
|
||||
handleFreeAspectResize(diffX, diffY);
|
||||
} else {
|
||||
handleFixedAspectResize(diffX, diffY);
|
||||
}
|
||||
};
|
||||
|
||||
const handleMoveCropBox = (diffX: number, diffY: number) => {
|
||||
const newDimension = [...startDimension.value] as Dimension;
|
||||
|
||||
// 计算临时偏移后的位置
|
||||
const tempTop = startDimension.value[0] + diffY;
|
||||
const tempLeft = startDimension.value[3] + diffX;
|
||||
|
||||
// 计算裁剪框的固定尺寸
|
||||
const cropWidth =
|
||||
containerWidth.value - startDimension.value[3] - startDimension.value[1];
|
||||
const cropHeight =
|
||||
containerHeight.value - startDimension.value[0] - startDimension.value[2];
|
||||
|
||||
// 边界限制:确保裁剪框完全在容器内,且尺寸不变
|
||||
// 顶部边界:top >= 0,且 bottom = 容器高度 - top - 裁剪高度 >= 0
|
||||
newDimension[0] = Math.max(
|
||||
0,
|
||||
Math.min(tempTop, containerHeight.value - cropHeight),
|
||||
);
|
||||
// 底部边界:bottom = 容器高度 - top - 裁剪高度(由top推导,无需额外计算)
|
||||
newDimension[2] = containerHeight.value - newDimension[0] - cropHeight;
|
||||
// 左侧边界:left >= 0,且 right = 容器宽度 - left - 裁剪宽度 >= 0
|
||||
newDimension[3] = Math.max(
|
||||
0,
|
||||
Math.min(tempLeft, containerWidth.value - cropWidth),
|
||||
);
|
||||
// 右侧边界:right = 容器宽度 - left - 裁剪宽度(由left推导,无需额外计算)
|
||||
newDimension[1] = containerWidth.value - newDimension[3] - cropWidth;
|
||||
|
||||
// 强制保证尺寸不变(兜底)
|
||||
const finalWidth = containerWidth.value - newDimension[3] - newDimension[1];
|
||||
const finalHeight = containerHeight.value - newDimension[0] - newDimension[2];
|
||||
|
||||
if (finalWidth !== cropWidth) {
|
||||
newDimension[1] = containerWidth.value - newDimension[3] - cropWidth;
|
||||
}
|
||||
|
||||
if (finalHeight !== cropHeight) {
|
||||
newDimension[2] = containerHeight.value - newDimension[0] - cropHeight;
|
||||
}
|
||||
|
||||
// 更新裁剪区域(仅位置变化,尺寸/比例完全不变)
|
||||
setDimension(newDimension);
|
||||
};
|
||||
|
||||
const handleFreeAspectResize = (diffX: number, diffY: number) => {
|
||||
const cropperWidth = containerWidth.value;
|
||||
const cropperHeight = containerHeight.value;
|
||||
const currentDimensionNew: Dimension = [0, 0, 0, 0];
|
||||
|
||||
// 计算新的尺寸,确保不小于最小值
|
||||
currentDimensionNew[0] = Math.min(
|
||||
Math.max(startDimension.value[0] + direction.value[0] * diffY, 0),
|
||||
cropperHeight - CROPPER_CONSTANTS.MIN_HEIGHT,
|
||||
);
|
||||
|
||||
currentDimensionNew[1] = Math.min(
|
||||
Math.max(startDimension.value[1] + direction.value[1] * diffX, 0),
|
||||
cropperWidth - CROPPER_CONSTANTS.MIN_WIDTH,
|
||||
);
|
||||
|
||||
currentDimensionNew[2] = Math.min(
|
||||
Math.max(startDimension.value[2] + direction.value[2] * diffY, 0),
|
||||
cropperHeight - CROPPER_CONSTANTS.MIN_HEIGHT,
|
||||
);
|
||||
|
||||
currentDimensionNew[3] = Math.min(
|
||||
Math.max(startDimension.value[3] + direction.value[3] * diffX, 0),
|
||||
cropperWidth - CROPPER_CONSTANTS.MIN_WIDTH,
|
||||
);
|
||||
|
||||
// 确保裁剪区域宽度和高度不小于最小值
|
||||
const newWidth =
|
||||
cropperWidth - currentDimensionNew[3] - currentDimensionNew[1];
|
||||
const newHeight =
|
||||
cropperHeight - currentDimensionNew[0] - currentDimensionNew[2];
|
||||
|
||||
if (newWidth < CROPPER_CONSTANTS.MIN_WIDTH) {
|
||||
if (direction.value[3] === 1) {
|
||||
currentDimensionNew[3] =
|
||||
cropperWidth - currentDimensionNew[1] - CROPPER_CONSTANTS.MIN_WIDTH;
|
||||
} else {
|
||||
currentDimensionNew[1] =
|
||||
cropperWidth - currentDimensionNew[3] - CROPPER_CONSTANTS.MIN_WIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
if (newHeight < CROPPER_CONSTANTS.MIN_HEIGHT) {
|
||||
if (direction.value[0] === 1) {
|
||||
currentDimensionNew[0] =
|
||||
cropperHeight - currentDimensionNew[2] - CROPPER_CONSTANTS.MIN_HEIGHT;
|
||||
} else {
|
||||
currentDimensionNew[2] =
|
||||
cropperHeight - currentDimensionNew[0] - CROPPER_CONSTANTS.MIN_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
setDimension(currentDimensionNew);
|
||||
};
|
||||
|
||||
const handleFixedAspectResize = (diffX: number, diffY: number) => {
|
||||
if (validAspectRatio.value === null) return;
|
||||
const cropperWidth = containerWidth.value;
|
||||
const cropperHeight = containerHeight.value;
|
||||
// 有有效比例 - 固定比例裁剪
|
||||
const ratio = validAspectRatio.value;
|
||||
const currentWidth =
|
||||
cropperWidth - startDimension.value[3] - startDimension.value[1];
|
||||
const currentHeight =
|
||||
cropperHeight - startDimension.value[0] - startDimension.value[2];
|
||||
|
||||
let newHeight: number, newWidth: number;
|
||||
let widthChange = 0;
|
||||
let heightChange = 0;
|
||||
|
||||
// 计算宽度/高度变化量
|
||||
if (direction.value[3] === 1) widthChange = -diffX;
|
||||
else if (direction.value[1] === -1) widthChange = diffX;
|
||||
|
||||
if (direction.value[0] === 1) heightChange = -diffY;
|
||||
else if (direction.value[2] === -1) heightChange = diffY;
|
||||
|
||||
const isCornerDrag =
|
||||
(direction.value[3] === 1 || direction.value[1] === -1) &&
|
||||
(direction.value[0] === 1 || direction.value[2] === -1);
|
||||
|
||||
// 计算新尺寸
|
||||
if (isCornerDrag) {
|
||||
if (Math.abs(widthChange) > Math.abs(heightChange)) {
|
||||
newWidth = Math.max(
|
||||
CROPPER_CONSTANTS.MIN_WIDTH,
|
||||
currentWidth + widthChange,
|
||||
);
|
||||
newHeight = newWidth / ratio;
|
||||
} else {
|
||||
newHeight = Math.max(
|
||||
CROPPER_CONSTANTS.MIN_HEIGHT,
|
||||
currentHeight + heightChange,
|
||||
);
|
||||
newWidth = newHeight * ratio;
|
||||
}
|
||||
} else {
|
||||
if (direction.value[3] === 1 || direction.value[1] === -1) {
|
||||
newWidth = Math.max(
|
||||
CROPPER_CONSTANTS.MIN_WIDTH,
|
||||
currentWidth + widthChange,
|
||||
);
|
||||
newHeight = newWidth / ratio;
|
||||
} else {
|
||||
newHeight = Math.max(
|
||||
CROPPER_CONSTANTS.MIN_HEIGHT,
|
||||
currentHeight + heightChange,
|
||||
);
|
||||
newWidth = newHeight * ratio;
|
||||
}
|
||||
}
|
||||
|
||||
// 限制最大尺寸
|
||||
const maxWidth = cropperWidth;
|
||||
const maxHeight = cropperHeight;
|
||||
|
||||
if (newWidth > maxWidth) {
|
||||
newWidth = maxWidth;
|
||||
newHeight = newWidth / ratio;
|
||||
}
|
||||
|
||||
if (newHeight > maxHeight) {
|
||||
newHeight = maxHeight;
|
||||
newWidth = newHeight * ratio;
|
||||
}
|
||||
|
||||
// 计算新的位置
|
||||
let newLeft = startDimension.value[3];
|
||||
let newTop = startDimension.value[0];
|
||||
let newRight = startDimension.value[1];
|
||||
let newBottom = startDimension.value[2];
|
||||
|
||||
// 根据拖拽方向调整位置
|
||||
if (direction.value[3] === 1) {
|
||||
newLeft = cropperWidth - newWidth - startDimension.value[1];
|
||||
} else if (direction.value[1] === -1) {
|
||||
newRight = cropperWidth - newWidth - startDimension.value[3];
|
||||
} else if (!isCornerDrag) {
|
||||
// 居中调整
|
||||
const currentHorizontalCenter = startDimension.value[3] + currentWidth / 2;
|
||||
newLeft = Math.max(
|
||||
0,
|
||||
Math.min(cropperWidth - newWidth, currentHorizontalCenter - newWidth / 2),
|
||||
);
|
||||
newRight = cropperWidth - newWidth - newLeft;
|
||||
}
|
||||
|
||||
if (direction.value[0] === 1) {
|
||||
newTop = cropperHeight - newHeight - startDimension.value[2];
|
||||
} else if (direction.value[2] === -1) {
|
||||
newBottom = cropperHeight - newHeight - startDimension.value[0];
|
||||
} else if (!isCornerDrag) {
|
||||
// 居中调整
|
||||
const currentVerticalCenter = startDimension.value[0] + currentHeight / 2;
|
||||
newTop = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
cropperHeight - newHeight,
|
||||
currentVerticalCenter - newHeight / 2,
|
||||
),
|
||||
);
|
||||
newBottom = cropperHeight - newHeight - newTop;
|
||||
}
|
||||
|
||||
// 边界检查
|
||||
newLeft = Math.max(0, newLeft);
|
||||
newTop = Math.max(0, newTop);
|
||||
newRight = Math.max(0, newRight);
|
||||
newBottom = Math.max(0, newBottom);
|
||||
|
||||
const newDimension: Dimension = [newTop, newRight, newBottom, newLeft];
|
||||
setDimension(newDimension);
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理鼠标抬起事件
|
||||
*/
|
||||
const handleMouseUp = () => {
|
||||
dragging.value = false;
|
||||
moving.value = false;
|
||||
direction.value = [0, 0, 0, 0];
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理图片加载完成
|
||||
*/
|
||||
const handleImageLoad = () => {
|
||||
createCropper();
|
||||
};
|
||||
|
||||
/**
|
||||
* 裁剪图片
|
||||
* @param {'image/jpeg' | 'image/png'} format - 输出图片格式
|
||||
* @param {number} quality - 压缩质量(0-1)
|
||||
* @param {'blob' | 'base64'} outputType - 输出类型
|
||||
* @param {number} targetWidth - 目标宽度(可选,不传则为原始裁剪宽度)
|
||||
* @param {number} targetHeight - 目标高度(可选,不传则为原始裁剪高度)
|
||||
*/
|
||||
const getCropImage = async (
|
||||
format: 'image/jpeg' | 'image/png' = 'image/png',
|
||||
quality: number = 0.92,
|
||||
outputType: 'base64' | 'blob' = 'blob',
|
||||
targetWidth?: number,
|
||||
targetHeight?: number,
|
||||
): Promise<Blob | string | undefined> => {
|
||||
if (!props.img || !bgImageRef.value || !containerRef.value) return;
|
||||
|
||||
// 质量参数边界修正:强制限制在 0-1 区间,防止传入非法值报错
|
||||
const validQuality = Math.max(0, Math.min(1, quality));
|
||||
|
||||
// 创建临时图片对象获取原始尺寸
|
||||
const tempImg = new Image();
|
||||
// 跨域图片处理:仅对非同源的网络图片设置跨域匿名
|
||||
if (props.img.startsWith('http://') || props.img.startsWith('https://')) {
|
||||
try {
|
||||
const url = new URL(props.img);
|
||||
if (url.origin !== location.origin) {
|
||||
tempImg.crossOrigin = 'anonymous';
|
||||
}
|
||||
} catch {
|
||||
// Invalid URL,跳过跨域配置,不中断执行
|
||||
}
|
||||
}
|
||||
|
||||
// 等待临时图片加载完成
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
tempImg.removeEventListener('load', handleLoad);
|
||||
tempImg.removeEventListener('error', handleError);
|
||||
reject(new Error('图片加载超时,超时时间10秒'));
|
||||
}, 10_000);
|
||||
const handleLoad = () => {
|
||||
clearTimeout(timeout);
|
||||
tempImg.removeEventListener('load', handleLoad);
|
||||
tempImg.removeEventListener('error', handleError);
|
||||
resolve();
|
||||
};
|
||||
|
||||
const handleError = (err: ErrorEvent) => {
|
||||
clearTimeout(timeout);
|
||||
tempImg.removeEventListener('load', handleLoad);
|
||||
tempImg.removeEventListener('error', handleError);
|
||||
reject(new Error(`图片加载失败: ${err.message}`));
|
||||
};
|
||||
|
||||
tempImg.addEventListener('load', handleLoad);
|
||||
tempImg.addEventListener('error', handleError);
|
||||
tempImg.src = props.img;
|
||||
});
|
||||
|
||||
const containerRect = containerRef.value.getBoundingClientRect();
|
||||
const imgRect = bgImageRef.value.getBoundingClientRect();
|
||||
|
||||
// 1. 计算图片在容器内的渲染参数
|
||||
const containerWidth = containerRect.width;
|
||||
const containerHeight = containerRect.height;
|
||||
const renderedImgWidth = imgRect.width;
|
||||
const renderedImgHeight = imgRect.height;
|
||||
const imgOffsetX = (containerWidth - renderedImgWidth) / 2;
|
||||
const imgOffsetY = (containerHeight - renderedImgHeight) / 2;
|
||||
|
||||
// 2. 计算裁剪框在容器内的实际坐标
|
||||
const [cropTop, cropRight, cropBottom, cropLeft] = currentDimension.value;
|
||||
const cropBoxWidth = containerWidth - cropLeft - cropRight;
|
||||
const cropBoxHeight = containerHeight - cropTop - cropBottom;
|
||||
|
||||
// 3. 将裁剪框坐标转换为图片上的坐标(考虑图片偏移)
|
||||
const cropOnImgX = cropLeft - imgOffsetX;
|
||||
const cropOnImgY = cropTop - imgOffsetY;
|
||||
|
||||
// 4. 计算渲染图片到原始图片的缩放比例(保留原始像素)
|
||||
const scaleX = tempImg.width / renderedImgWidth;
|
||||
const scaleY = tempImg.height / renderedImgHeight;
|
||||
|
||||
// 5. 映射到原始图片的裁剪区域(精确到原始像素,防止越界)
|
||||
const originalCropX = Math.max(0, Math.floor(cropOnImgX * scaleX));
|
||||
const originalCropY = Math.max(0, Math.floor(cropOnImgY * scaleY));
|
||||
const originalCropWidth = Math.min(
|
||||
Math.floor(cropBoxWidth * scaleX),
|
||||
tempImg.width - originalCropX,
|
||||
);
|
||||
const originalCropHeight = Math.min(
|
||||
Math.floor(cropBoxHeight * scaleY),
|
||||
tempImg.height - originalCropY,
|
||||
);
|
||||
|
||||
// 边界校验:裁剪尺寸非法则返回
|
||||
if (originalCropWidth <= 0 || originalCropHeight <= 0) return;
|
||||
|
||||
// 6. 处理高清屏适配(解决Retina屏模糊)
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
|
||||
// 最终画布尺寸(优先使用传入的目标尺寸,无则用原始裁剪尺寸)
|
||||
const finalWidth = targetWidth ? Math.max(1, targetWidth) : originalCropWidth;
|
||||
const finalHeight = targetHeight
|
||||
? Math.max(1, targetHeight)
|
||||
: originalCropHeight;
|
||||
|
||||
// 创建画布并获取绘制上下文
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
|
||||
// 画布物理尺寸(乘以设备像素比,保证高清无模糊)
|
||||
canvas.width = finalWidth * dpr;
|
||||
canvas.height = finalHeight * dpr;
|
||||
|
||||
// 画布显示尺寸(视觉尺寸,和最终展示一致)
|
||||
canvas.style.width = `${finalWidth}px`;
|
||||
canvas.style.height = `${finalHeight}px`;
|
||||
|
||||
// 缩放画布上下文,适配高清屏DPR
|
||||
ctx.scale(dpr, dpr);
|
||||
|
||||
// 7. 绘制裁剪后的图片(使用原始像素绘制,保证清晰度)
|
||||
ctx.drawImage(
|
||||
tempImg,
|
||||
originalCropX, // 原始图片裁剪起始X(精确像素)
|
||||
originalCropY, // 原始图片裁剪起始Y(精确像素)
|
||||
originalCropWidth, // 原始图片裁剪宽度(精确像素)
|
||||
originalCropHeight, // 原始图片裁剪高度(精确像素)
|
||||
0, // 画布绘制起始X
|
||||
0, // 画布绘制起始Y
|
||||
finalWidth, // 画布绘制宽度(目标尺寸)
|
||||
finalHeight, // 画布绘制高度(目标尺寸)
|
||||
);
|
||||
|
||||
try {
|
||||
return outputType === 'base64'
|
||||
? canvas.toDataURL(format, validQuality)
|
||||
: new Promise<Blob>((resolve) => {
|
||||
canvas.toBlob(
|
||||
(blob) => {
|
||||
// 兜底:如果blob生成失败,返回空Blob(防止null)
|
||||
resolve(blob || new Blob([], { type: format }));
|
||||
},
|
||||
format,
|
||||
validQuality,
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('图片导出失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 监听比例变化,重新调整裁剪框
|
||||
watch(() => props.aspectRatio, adjustCropperToAspectRatio);
|
||||
|
||||
// 监听width/height变化,重新计算尺寸
|
||||
watch([() => props.width, () => props.height], () => {
|
||||
calculateImageFitSize();
|
||||
adjustCropperToAspectRatio();
|
||||
});
|
||||
|
||||
// 组件挂载时注册全局事件
|
||||
onMounted(() => {
|
||||
document.addEventListener('mousemove', handleMouseMove);
|
||||
document.addEventListener('mouseup', handleMouseUp);
|
||||
|
||||
// 如果图片已经加载完成,手动触发创建裁剪器
|
||||
if (
|
||||
bgImageRef.value &&
|
||||
bgImageRef.value.complete &&
|
||||
bgImageRef.value.naturalWidth > 0
|
||||
) {
|
||||
createCropper();
|
||||
}
|
||||
});
|
||||
|
||||
// 组件卸载时清理
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('mousemove', handleMouseMove);
|
||||
document.removeEventListener('mouseup', handleMouseUp);
|
||||
});
|
||||
|
||||
defineExpose({ getCropImage });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
:style="{
|
||||
width: `${width || CROPPER_CONSTANTS.DEFAULT_WIDTH}px`,
|
||||
height: `${height || CROPPER_CONSTANTS.DEFAULT_HEIGHT}px`,
|
||||
}"
|
||||
class="cropper-action-wrapper"
|
||||
>
|
||||
<div
|
||||
ref="containerRef"
|
||||
class="cropper-container"
|
||||
:style="{
|
||||
width: `${containerWidth}px`,
|
||||
height: `${containerHeight}px`,
|
||||
}"
|
||||
>
|
||||
<!-- 原图展示 - 自适应尺寸 -->
|
||||
<img
|
||||
ref="bgImageRef"
|
||||
class="cropper-image"
|
||||
:src="img"
|
||||
@load="handleImageLoad"
|
||||
:style="{
|
||||
maxWidth: '100%',
|
||||
maxHeight: '100%',
|
||||
objectFit: 'contain',
|
||||
}"
|
||||
alt="裁剪原图"
|
||||
/>
|
||||
|
||||
<!-- 遮罩层 -->
|
||||
<div
|
||||
class="cropper-mask"
|
||||
:style="{
|
||||
display: isCropperVisible ? 'block' : 'none',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
}"
|
||||
>
|
||||
<div
|
||||
ref="maskViewRef"
|
||||
class="cropper-mask-view"
|
||||
:style="{
|
||||
backgroundImage: `url(${img})`,
|
||||
backgroundSize: 'contain',
|
||||
backgroundPosition: 'center',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
clipPath: `inset(${currentDimension[0]}px ${currentDimension[1]}px ${currentDimension[2]}px ${currentDimension[3]}px)`,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
}"
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<!-- 裁剪框 -->
|
||||
<div
|
||||
ref="cropperRef"
|
||||
class="cropper-box"
|
||||
:style="{
|
||||
display: isCropperVisible ? 'block' : 'none',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
}"
|
||||
>
|
||||
<div
|
||||
class="cropper-view"
|
||||
:style="{
|
||||
inset: `${currentDimension[0]}px ${currentDimension[1]}px ${currentDimension[2]}px ${currentDimension[3]}px`,
|
||||
}"
|
||||
>
|
||||
<!-- 裁剪框辅助线-->
|
||||
<span class="cropper-dashed-h"></span>
|
||||
<span class="cropper-dashed-v"></span>
|
||||
|
||||
<!-- 裁剪框拖拽区域 -->
|
||||
<span
|
||||
class="cropper-move-area"
|
||||
@mousedown="handleMouseDown($event, 'move')"
|
||||
></span>
|
||||
|
||||
<!-- 边框线 -->
|
||||
<span class="cropper-line-e"></span>
|
||||
<span class="cropper-line-n"></span>
|
||||
<span class="cropper-line-w"></span>
|
||||
<span class="cropper-line-s"></span>
|
||||
|
||||
<!-- 边角拖拽点 -->
|
||||
<span
|
||||
class="cropper-point cropper-point-ne"
|
||||
@mousedown="handleMouseDown($event, 'top-right')"
|
||||
>
|
||||
<span class="cropper-point-inner"></span>
|
||||
</span>
|
||||
<span
|
||||
class="cropper-point cropper-point-nw"
|
||||
@mousedown="handleMouseDown($event, 'top-left')"
|
||||
>
|
||||
<span class="cropper-point-inner"></span>
|
||||
</span>
|
||||
<span
|
||||
class="cropper-point cropper-point-sw"
|
||||
@mousedown="handleMouseDown($event, 'bottom-left')"
|
||||
>
|
||||
<span class="cropper-point-inner"></span>
|
||||
</span>
|
||||
<span
|
||||
class="cropper-point cropper-point-se"
|
||||
@mousedown="handleMouseDown($event, 'bottom-right')"
|
||||
>
|
||||
<span class="cropper-point-inner"></span>
|
||||
</span>
|
||||
|
||||
<!-- 边中点拖拽点 -->
|
||||
<span
|
||||
class="cropper-point cropper-point-e"
|
||||
@mousedown="handleMouseDown($event, 'right')"
|
||||
>
|
||||
<span class="cropper-point-inner"></span>
|
||||
</span>
|
||||
<span
|
||||
class="cropper-point cropper-point-n"
|
||||
@mousedown="handleMouseDown($event, 'top')"
|
||||
>
|
||||
<span class="cropper-point-inner"></span>
|
||||
</span>
|
||||
<span
|
||||
class="cropper-point cropper-point-w"
|
||||
@mousedown="handleMouseDown($event, 'left')"
|
||||
>
|
||||
<span class="cropper-point-inner"></span>
|
||||
</span>
|
||||
<span
|
||||
class="cropper-point cropper-point-s"
|
||||
@mousedown="handleMouseDown($event, 'bottom')"
|
||||
>
|
||||
<span class="cropper-point-inner"></span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
@reference "@vben/tailwind-config/theme";
|
||||
|
||||
.cropper-action-wrapper {
|
||||
@apply box-border flex items-center justify-center;
|
||||
|
||||
background-color: transparent;
|
||||
|
||||
/* 马赛克背景 */
|
||||
background-image:
|
||||
linear-gradient(45deg, #ccc 25%, transparent 25%),
|
||||
linear-gradient(-45deg, #ccc 25%, transparent 25%),
|
||||
linear-gradient(45deg, transparent 75%, #ccc 75%),
|
||||
linear-gradient(-45deg, transparent 75%, #ccc 75%);
|
||||
background-position:
|
||||
0 0,
|
||||
0 10px,
|
||||
10px -10px,
|
||||
-10px 0;
|
||||
background-size: 20px 20px;
|
||||
}
|
||||
|
||||
.cropper-container {
|
||||
@apply relative;
|
||||
}
|
||||
|
||||
.cropper-image {
|
||||
@apply block;
|
||||
}
|
||||
|
||||
/* 遮罩层 */
|
||||
.cropper-mask {
|
||||
@apply absolute top-0 left-0 bg-black/50;
|
||||
}
|
||||
|
||||
.cropper-mask-view {
|
||||
@apply absolute top-0 left-0;
|
||||
}
|
||||
|
||||
/* 裁剪框 */
|
||||
.cropper-box {
|
||||
@apply absolute top-0 left-0 z-10;
|
||||
}
|
||||
|
||||
.cropper-view {
|
||||
@apply absolute top-0 right-0 bottom-0 left-0 outline-1 outline-blue-500 select-none;
|
||||
}
|
||||
|
||||
/* 裁剪框辅助线 */
|
||||
.cropper-dashed-h {
|
||||
@apply absolute top-1/3 left-0 block h-1/3 w-full border-t border-b border-dashed border-gray-200/50;
|
||||
}
|
||||
|
||||
.cropper-dashed-v {
|
||||
@apply absolute top-0 left-1/3 block h-full w-1/3 border-r border-l border-dashed border-gray-200/50;
|
||||
}
|
||||
|
||||
/* 裁剪框拖拽区域 */
|
||||
.cropper-move-area {
|
||||
@apply absolute top-0 left-0 block h-full w-full cursor-move bg-white/10;
|
||||
}
|
||||
|
||||
/* 边框拖拽线 */
|
||||
.cropper-line-e,
|
||||
.cropper-line-n,
|
||||
.cropper-line-w,
|
||||
.cropper-line-s {
|
||||
@apply absolute block bg-blue-500/10;
|
||||
}
|
||||
|
||||
.cropper-line-e {
|
||||
@apply top-0 -right-0.75 h-full w-1;
|
||||
}
|
||||
|
||||
.cropper-line-n {
|
||||
@apply -top-0.75 left-0 h-1 w-full;
|
||||
}
|
||||
|
||||
.cropper-line-w {
|
||||
@apply top-0 -left-0.75 h-full w-1;
|
||||
}
|
||||
|
||||
.cropper-line-s {
|
||||
@apply -bottom-0.75 left-0 h-1 w-full;
|
||||
}
|
||||
|
||||
/* 拖拽点 */
|
||||
.cropper-point {
|
||||
@apply absolute flex h-2 w-2 items-center justify-center bg-blue-500;
|
||||
}
|
||||
|
||||
.cropper-point-inner {
|
||||
@apply block h-1.5 w-1.5 bg-white;
|
||||
}
|
||||
|
||||
/* 边角拖拽点位置和光标 */
|
||||
.cropper-point-ne {
|
||||
@apply -top-1.25 -right-1.25 cursor-ne-resize;
|
||||
}
|
||||
|
||||
.cropper-point-nw {
|
||||
@apply -top-1.25 -left-1.25 cursor-nw-resize;
|
||||
}
|
||||
|
||||
.cropper-point-sw {
|
||||
@apply -bottom-1.25 -left-1.25 cursor-sw-resize;
|
||||
}
|
||||
|
||||
.cropper-point-se {
|
||||
@apply -right-1.25 -bottom-1.25 cursor-se-resize;
|
||||
}
|
||||
|
||||
/* 边中点拖拽点位置和光标 */
|
||||
.cropper-point-e {
|
||||
@apply top-1/2 -right-1.25 -mt-1 cursor-e-resize;
|
||||
}
|
||||
|
||||
.cropper-point-n {
|
||||
@apply -top-1.25 left-1/2 -ml-1 cursor-n-resize;
|
||||
}
|
||||
|
||||
.cropper-point-w {
|
||||
@apply top-1/2 -left-1.25 -mt-1 cursor-w-resize;
|
||||
}
|
||||
|
||||
.cropper-point-s {
|
||||
@apply -bottom-1.25 left-1/2 -ml-1 cursor-s-resize;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1 @@
|
||||
export { default as VCropper } from './cropper.vue';
|
||||
@@ -205,7 +205,7 @@ function handleExpand() {
|
||||
<div
|
||||
ref="ellipsis"
|
||||
:class="{
|
||||
'!cursor-pointer': expand,
|
||||
'cursor-pointer!': expand,
|
||||
['block truncate']: line === 1,
|
||||
[$style.ellipsisMultiLine]: line > 1,
|
||||
}"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import type { VNode } from 'vue';
|
||||
import type { IconPickerProps } from './types';
|
||||
|
||||
import { computed, ref, useAttrs, watch, watchEffect } from 'vue';
|
||||
|
||||
@@ -28,28 +28,7 @@ import { objectOmit, refDebounced, watchDebounced } from '@vueuse/core';
|
||||
|
||||
import { fetchIconsData } from './icons';
|
||||
|
||||
interface Props {
|
||||
pageSize?: number;
|
||||
/** 图标集的名字 */
|
||||
prefix?: string;
|
||||
/** 是否自动请求API以获得图标集的数据.提供prefix时有效 */
|
||||
autoFetchApi?: boolean;
|
||||
/**
|
||||
* 图标列表
|
||||
*/
|
||||
icons?: string[];
|
||||
/** Input组件 */
|
||||
inputComponent?: VNode;
|
||||
/** 图标插槽名,预览图标将被渲染到此插槽中 */
|
||||
iconSlot?: string;
|
||||
/** input组件的值属性名称 */
|
||||
modelValueProp?: string;
|
||||
/** 图标样式 */
|
||||
iconClass?: string;
|
||||
type?: 'icon' | 'input';
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<IconPickerProps>(), {
|
||||
prefix: 'ant-design',
|
||||
pageSize: 36,
|
||||
icons: () => [],
|
||||
@@ -71,17 +50,10 @@ const modelValue = defineModel({ default: '', type: String });
|
||||
|
||||
const visible = ref(false);
|
||||
const currentSelect = ref('');
|
||||
const currentPage = ref(1);
|
||||
const keyword = ref('');
|
||||
const keywordDebounce = refDebounced(keyword, 300);
|
||||
const innerIcons = ref<string[]>([]);
|
||||
|
||||
/* 当检索关键词变化时,重置分页 */
|
||||
watch(keywordDebounce, () => {
|
||||
currentPage.value = 1;
|
||||
setCurrentPage(1);
|
||||
});
|
||||
|
||||
watchDebounced(
|
||||
() => props.prefix,
|
||||
async (prefix) => {
|
||||
@@ -122,7 +94,7 @@ const showList = computed(() => {
|
||||
);
|
||||
});
|
||||
|
||||
const { paginationList, total, setCurrentPage } = usePagination(
|
||||
const { paginationList, total, setCurrentPage, currentPage } = usePagination(
|
||||
showList,
|
||||
props.pageSize,
|
||||
);
|
||||
@@ -145,7 +117,6 @@ const handleClick = (icon: string) => {
|
||||
};
|
||||
|
||||
const handlePageChange = (page: number) => {
|
||||
currentPage.value = page;
|
||||
setCurrentPage(page);
|
||||
};
|
||||
|
||||
@@ -176,6 +147,9 @@ const searchInputProps = computed(() => {
|
||||
|
||||
function updateCurrentSelect(v: string) {
|
||||
currentSelect.value = v;
|
||||
if (props.modelValueProp === 'modelValue') {
|
||||
modelValue.value = v;
|
||||
}
|
||||
const eventKey = `onUpdate:${props.modelValueProp}`;
|
||||
if (attrs[eventKey] && isFunction(attrs[eventKey])) {
|
||||
attrs[eventKey](v);
|
||||
@@ -227,7 +201,7 @@ defineExpose({ toggleOpenState, open, close });
|
||||
/>
|
||||
<VbenIcon
|
||||
:icon="currentSelect || Grip"
|
||||
class="absolute right-1 top-1 size-6"
|
||||
class="absolute top-1 right-1 size-6"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
@@ -254,7 +228,7 @@ defineExpose({ toggleOpenState, open, close });
|
||||
</div>
|
||||
|
||||
<template v-if="paginationList.length > 0">
|
||||
<div class="grid max-h-[360px] w-full grid-cols-6 justify-items-center">
|
||||
<div class="grid max-h-90 w-full grid-cols-6 justify-items-center">
|
||||
<VbenIconButton
|
||||
v-for="(item, index) in paginationList"
|
||||
:key="index"
|
||||
@@ -317,7 +291,7 @@ defineExpose({ toggleOpenState, open, close });
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="flex-col-center text-muted-foreground min-h-[150px] w-full">
|
||||
<div class="flex-col-center min-h-37.5 w-full text-muted-foreground">
|
||||
<EmptyIcon class="size-10" />
|
||||
<div class="mt-1 text-sm">{{ $t('common.noData') }}</div>
|
||||
</div>
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export { default as IconPicker } from './icon-picker.vue';
|
||||
export type { IconPickerProps } from './types';
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { VNode } from 'vue';
|
||||
|
||||
export interface IconPickerProps {
|
||||
pageSize?: number;
|
||||
/** 图标集的名字 */
|
||||
prefix?: string;
|
||||
/** 是否自动请求API以获得图标集的数据.提供prefix时有效 */
|
||||
autoFetchApi?: boolean;
|
||||
/**
|
||||
* 图标列表
|
||||
*/
|
||||
icons?: string[];
|
||||
/** Input组件 */
|
||||
inputComponent?: VNode;
|
||||
/** 图标插槽名,预览图标将被渲染到此插槽中 */
|
||||
iconSlot?: string;
|
||||
/** input组件的值属性名称 */
|
||||
modelValueProp?: string;
|
||||
/** 图标样式 */
|
||||
iconClass?: string;
|
||||
type?: 'icon' | 'input';
|
||||
}
|
||||
@@ -2,6 +2,7 @@ export * from './api-component';
|
||||
export * from './captcha';
|
||||
export * from './col-page';
|
||||
export * from './count-to';
|
||||
export * from './cropper';
|
||||
export * from './ellipsis-text';
|
||||
export * from './icon-picker';
|
||||
export * from './json-viewer';
|
||||
@@ -9,6 +10,7 @@ export * from './loading';
|
||||
export * from './page';
|
||||
export * from './resize';
|
||||
export * from './tippy';
|
||||
export * from './tree';
|
||||
export * from '@vben-core/form-ui';
|
||||
export * from '@vben-core/popup-ui';
|
||||
|
||||
@@ -19,16 +21,22 @@ export {
|
||||
VbenButtonGroup,
|
||||
VbenCheckbox,
|
||||
VbenCheckButtonGroup,
|
||||
VbenCollapsibleParams,
|
||||
VbenContextMenu,
|
||||
VbenCountToAnimator,
|
||||
VbenFullScreen,
|
||||
VbenIconButton,
|
||||
VbenInputPassword,
|
||||
VbenLoading,
|
||||
VbenLogo,
|
||||
VbenPinInput,
|
||||
VbenSelect,
|
||||
VbenSpinner,
|
||||
VbenTree,
|
||||
} from '@vben-core/shadcn-ui';
|
||||
|
||||
export type { FlattenedItem } from '@vben-core/shadcn-ui';
|
||||
export type {
|
||||
CollapsibleParamSchema,
|
||||
CollapsibleParamsProps,
|
||||
FlattenedItem,
|
||||
} from '@vben-core/shadcn-ui';
|
||||
export { globalShareState } from '@vben-core/shared/global-state';
|
||||
|
||||
@@ -10,15 +10,12 @@ import type {
|
||||
JsonViewerValue,
|
||||
} from './types';
|
||||
|
||||
import { computed, useAttrs } from 'vue';
|
||||
// @ts-ignore
|
||||
import VueJsonViewer from 'vue-json-viewer';
|
||||
import { computed, ref, useAttrs } from 'vue';
|
||||
import VueJsonPretty from 'vue-json-pretty';
|
||||
import 'vue-json-pretty/lib/styles.css';
|
||||
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { isBoolean } from '@vben-core/shared/utils';
|
||||
|
||||
// @ts-ignore
|
||||
import JsonBigint from 'json-bigint';
|
||||
|
||||
defineOptions({ name: 'JsonViewer' });
|
||||
@@ -45,30 +42,29 @@ const emit = defineEmits<{
|
||||
|
||||
const attrs: SetupContext['attrs'] = useAttrs();
|
||||
|
||||
function handleClick(event: MouseEvent) {
|
||||
if (
|
||||
event.target instanceof HTMLElement &&
|
||||
event.target.classList.contains('jv-item')
|
||||
) {
|
||||
const pathNode = event.target.closest('.jv-push');
|
||||
if (!pathNode || !pathNode.hasAttribute('path')) {
|
||||
return;
|
||||
const copiedPath = ref<null | string>(null);
|
||||
|
||||
const copyConfig = computed(() => {
|
||||
return {
|
||||
copiedText: $t('ui.jsonViewer.copied'),
|
||||
copyText: $t('ui.jsonViewer.copy'),
|
||||
timeout: 2000,
|
||||
};
|
||||
});
|
||||
|
||||
function handleCopy(node: any, defaultCopy: () => void) {
|
||||
defaultCopy();
|
||||
copiedPath.value = node.path;
|
||||
emit('copied', {
|
||||
action: 'copy',
|
||||
text: JSON.stringify(node.content),
|
||||
trigger: node.el ?? document.body,
|
||||
});
|
||||
setTimeout(() => {
|
||||
if (copiedPath.value === node.path) {
|
||||
copiedPath.value = null;
|
||||
}
|
||||
const param: JsonViewerValue = {
|
||||
path: '',
|
||||
value: '',
|
||||
depth: 0,
|
||||
el: event.target,
|
||||
};
|
||||
|
||||
param.path = pathNode.getAttribute('path') || '';
|
||||
param.depth = Number(pathNode.getAttribute('depth')) || 0;
|
||||
|
||||
param.value = event.target.textContent || undefined;
|
||||
param.value = JSON.parse(param.value);
|
||||
emit('valueClick', param);
|
||||
}
|
||||
emit('click', event);
|
||||
}, copyConfig.value.timeout ?? 2000);
|
||||
}
|
||||
|
||||
// 支持显示 bigint 数据,如较长的订单号
|
||||
@@ -86,30 +82,46 @@ const jsonData = computed<Record<string, any>>(() => {
|
||||
});
|
||||
|
||||
const bindProps = computed<Recordable<any>>(() => {
|
||||
const copyable = {
|
||||
copyText: $t('ui.jsonViewer.copy'),
|
||||
copiedText: $t('ui.jsonViewer.copied'),
|
||||
timeout: 2000,
|
||||
...(isBoolean(props.copyable) ? {} : props.copyable),
|
||||
};
|
||||
const prettyTheme =
|
||||
props.theme === 'dark' || props.theme === 'dark-json-theme'
|
||||
? 'dark'
|
||||
: 'light';
|
||||
|
||||
return {
|
||||
...props,
|
||||
...attrs,
|
||||
value: jsonData.value,
|
||||
onCopied: (event: JsonViewerAction) => emit('copied', event),
|
||||
onKeyclick: (key: string) => emit('keyClick', key),
|
||||
onClick: (event: MouseEvent) => handleClick(event),
|
||||
copyable: props.copyable ? copyable : false,
|
||||
data: jsonData.value,
|
||||
deep: props.expanded ? Infinity : props.expandDepth,
|
||||
showDoubleQuotes: props.showDoubleQuotes,
|
||||
showLine: props.boxed,
|
||||
showLength: true,
|
||||
showIcon: true,
|
||||
theme: prettyTheme,
|
||||
collapsedNodeLength: props.previewMode ? 0 : Infinity,
|
||||
renderNodeActions: !!props.copyable,
|
||||
};
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<VueJsonViewer v-bind="bindProps">
|
||||
<template #copy="slotProps">
|
||||
<slot name="copy" v-bind="slotProps"></slot>
|
||||
</template>
|
||||
</VueJsonViewer>
|
||||
<div :class="[props.theme, { boxed: props.boxed }]" class="vben-json-viewer">
|
||||
<VueJsonPretty v-bind="bindProps">
|
||||
<template #renderNodeActions="{ node, defaultActions }">
|
||||
<slot name="copy" :node="node" :default-actions="defaultActions">
|
||||
<span
|
||||
v-if="props.copyable"
|
||||
class="vben-json-copy-btn"
|
||||
:class="[{ 'is-copied': copiedPath === node.path }]"
|
||||
@click.stop="handleCopy(node, defaultActions.copy)"
|
||||
>
|
||||
{{
|
||||
copiedPath === node.path
|
||||
? copyConfig.copiedText
|
||||
: copyConfig.copyText
|
||||
}}
|
||||
</span>
|
||||
</slot>
|
||||
</template>
|
||||
</VueJsonPretty>
|
||||
</div>
|
||||
</template>
|
||||
<style lang="scss">
|
||||
@use './style.scss';
|
||||
|
||||
@@ -1,98 +1,91 @@
|
||||
.default-json-theme {
|
||||
.vben-json-viewer {
|
||||
font-family: Consolas, Menlo, Courier, monospace;
|
||||
font-size: 14px;
|
||||
color: hsl(var(--foreground));
|
||||
white-space: nowrap;
|
||||
background: hsl(var(--background));
|
||||
|
||||
&.jv-container.boxed {
|
||||
&.boxed {
|
||||
padding: 10px;
|
||||
border: 1px solid hsl(var(--border));
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.jv-ellipsis {
|
||||
display: inline-block;
|
||||
padding: 0 4px 2px;
|
||||
font-size: 0.9em;
|
||||
line-height: 0.9;
|
||||
vertical-align: 2px;
|
||||
.vjs-key {
|
||||
color: hsl(var(--heavy-foreground));
|
||||
}
|
||||
|
||||
.vjs-value-null,
|
||||
.vjs-value-undefined {
|
||||
color: hsl(var(--secondary-foreground));
|
||||
}
|
||||
|
||||
.vjs-value-boolean {
|
||||
color: hsl(var(--red-400));
|
||||
}
|
||||
|
||||
.vjs-value-number {
|
||||
color: hsl(var(--info-foreground));
|
||||
}
|
||||
|
||||
.vjs-value-string {
|
||||
color: hsl(var(--primary));
|
||||
overflow-wrap: break-word;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.vjs-tree-brackets {
|
||||
color: hsl(var(--heavy-foreground));
|
||||
}
|
||||
|
||||
.vjs-comment {
|
||||
color: hsl(var(--secondary-foreground));
|
||||
}
|
||||
|
||||
.vjs-tree-node {
|
||||
&.is-highlight {
|
||||
background-color: hsl(var(--accent));
|
||||
}
|
||||
}
|
||||
|
||||
.vjs-carets {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: hsl(var(--primary));
|
||||
}
|
||||
}
|
||||
|
||||
.vjs-indent-unit {
|
||||
&.has-line {
|
||||
border-left: 1px solid hsl(var(--border));
|
||||
}
|
||||
}
|
||||
|
||||
.vben-json-copy-btn {
|
||||
display: inline-block;
|
||||
padding: 0 6px;
|
||||
margin-left: 8px;
|
||||
font-size: 12px;
|
||||
line-height: 20px;
|
||||
color: hsl(var(--primary));
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
background-color: hsl(var(--secondary));
|
||||
border-radius: 3px;
|
||||
}
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s;
|
||||
|
||||
.jv-button {
|
||||
color: hsl(var(--primary));
|
||||
}
|
||||
|
||||
.jv-key {
|
||||
color: hsl(var(--heavy-foreground));
|
||||
}
|
||||
|
||||
.jv-item {
|
||||
&.jv-array {
|
||||
color: hsl(var(--heavy-foreground));
|
||||
&:hover {
|
||||
background-color: hsl(var(--accent));
|
||||
}
|
||||
|
||||
&.jv-boolean {
|
||||
color: hsl(var(--red-400));
|
||||
}
|
||||
|
||||
&.jv-function {
|
||||
color: hsl(var(--destructive-foreground));
|
||||
}
|
||||
|
||||
&.jv-number {
|
||||
color: hsl(var(--info-foreground));
|
||||
}
|
||||
|
||||
&.jv-number-float {
|
||||
color: hsl(var(--info-foreground));
|
||||
}
|
||||
|
||||
&.jv-number-integer {
|
||||
color: hsl(var(--info-foreground));
|
||||
}
|
||||
|
||||
&.jv-object {
|
||||
color: hsl(var(--accent-darker));
|
||||
}
|
||||
|
||||
&.jv-undefined {
|
||||
color: hsl(var(--secondary-foreground));
|
||||
}
|
||||
|
||||
&.jv-string {
|
||||
color: hsl(var(--primary));
|
||||
overflow-wrap: break-word;
|
||||
white-space: normal;
|
||||
&.is-copied {
|
||||
color: hsl(var(--success-foreground, var(--primary)));
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
&.jv-container .jv-code {
|
||||
padding: 10px;
|
||||
|
||||
&.boxed:not(.open) {
|
||||
padding-bottom: 20px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
&.open {
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.jv-toggle {
|
||||
&::before {
|
||||
padding: 0 2px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
&::before {
|
||||
background: hsl(var(--accent-foreground));
|
||||
}
|
||||
}
|
||||
}
|
||||
.vjs-tree-node:hover .vben-json-copy-btn {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ const {
|
||||
autoContentHeight = false,
|
||||
contentPaddingClass,
|
||||
heightOffset = 0,
|
||||
footerFixed = false,
|
||||
} = defineProps<PageProps>();
|
||||
|
||||
const headerHeight = ref(0);
|
||||
@@ -28,7 +29,7 @@ const footerRef = useTemplateRef<HTMLDivElement>('footerRef');
|
||||
const contentStyle = computed<StyleValue>(() => {
|
||||
if (autoContentHeight) {
|
||||
return {
|
||||
height: `calc(var(${CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT}) - ${headerHeight.value}px - ${typeof heightOffset === 'number' ? `${heightOffset}px` : heightOffset})`,
|
||||
height: `calc(var(${CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT}) - ${headerHeight.value}px - ${footerHeight.value}px - ${typeof heightOffset === 'number' ? `${heightOffset}px` : heightOffset})`,
|
||||
overflowY: shouldAutoHeight.value ? 'auto' : 'unset',
|
||||
};
|
||||
}
|
||||
@@ -39,9 +40,12 @@ async function calcContentHeight() {
|
||||
if (!autoContentHeight) {
|
||||
return;
|
||||
}
|
||||
shouldAutoHeight.value = false;
|
||||
await nextTick();
|
||||
headerHeight.value = headerRef.value?.offsetHeight || 0;
|
||||
footerHeight.value = footerRef.value?.offsetHeight || 0;
|
||||
|
||||
footerHeight.value = footerFixed ? 0 : footerRef.value?.offsetHeight || 0;
|
||||
|
||||
setTimeout(() => {
|
||||
shouldAutoHeight.value = true;
|
||||
}, 30);
|
||||
@@ -53,7 +57,7 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="relative">
|
||||
<div class="relative flex min-h-full flex-col">
|
||||
<div
|
||||
v-if="
|
||||
description ||
|
||||
@@ -65,7 +69,7 @@ onMounted(() => {
|
||||
ref="headerRef"
|
||||
:class="
|
||||
cn(
|
||||
'bg-card border-border relative flex items-end border-b px-6 py-4',
|
||||
'relative flex items-end border-b border-border bg-card px-6 py-4',
|
||||
headerClass,
|
||||
)
|
||||
"
|
||||
@@ -95,16 +99,10 @@ onMounted(() => {
|
||||
>
|
||||
<slot></slot>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="$slots.footer"
|
||||
ref="footerRef"
|
||||
:class="
|
||||
cn(
|
||||
'bg-card align-center absolute bottom-0 left-0 right-0 flex px-6 py-4',
|
||||
footerClass,
|
||||
)
|
||||
"
|
||||
:class="cn('align-center flex bg-card px-6 py-4', footerClass)"
|
||||
>
|
||||
<slot name="footer"></slot>
|
||||
</div>
|
||||
|
||||
@@ -18,4 +18,10 @@ export interface PageProps {
|
||||
* @default 0
|
||||
*/
|
||||
heightOffset?: number;
|
||||
/**
|
||||
* Whether the footer is position: fixed.
|
||||
* When true, footer height is excluded from content height calculation.
|
||||
* @default false
|
||||
*/
|
||||
footerFixed?: boolean;
|
||||
}
|
||||
|
||||
@@ -264,13 +264,64 @@ const currentStick = ref<null | string>(null);
|
||||
|
||||
const parentElement = ref<HTMLElement | null>(null);
|
||||
|
||||
const width = computed(() => parentWidth.value! - left.value! - right.value!);
|
||||
function getPointerPosition(
|
||||
ev: Partial<{
|
||||
pageX: number;
|
||||
pageY: number;
|
||||
touches: ArrayLike<{ pageX: number; pageY: number }>;
|
||||
}>,
|
||||
): null | { pointerX: number; pointerY: number } {
|
||||
const touch = ev.touches?.[0];
|
||||
const pointerX = ev.pageX ?? touch?.pageX;
|
||||
const pointerY = ev.pageY ?? touch?.pageY;
|
||||
|
||||
const height = computed(() => parentHeight.value! - top.value! - bottom.value!);
|
||||
if (
|
||||
pointerX === null ||
|
||||
pointerX === undefined ||
|
||||
pointerY === null ||
|
||||
pointerY === undefined
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return { pointerX, pointerY };
|
||||
}
|
||||
|
||||
const width = computed(() => {
|
||||
const currentParentWidth = parentWidth.value;
|
||||
const currentLeft = left.value;
|
||||
const currentRight = right.value;
|
||||
|
||||
if (
|
||||
currentParentWidth === null ||
|
||||
currentLeft === null ||
|
||||
currentRight === null
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return currentParentWidth - currentLeft - currentRight;
|
||||
});
|
||||
|
||||
const height = computed(() => {
|
||||
const currentParentHeight = parentHeight.value;
|
||||
const currentTop = top.value;
|
||||
const currentBottom = bottom.value;
|
||||
|
||||
if (
|
||||
currentParentHeight === null ||
|
||||
currentTop === null ||
|
||||
currentBottom === null
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return currentParentHeight - currentTop - currentBottom;
|
||||
});
|
||||
|
||||
const rect = computed(() => ({
|
||||
left: Math.round(left.value!),
|
||||
top: Math.round(top.value!),
|
||||
left: Math.round(left.value ?? 0),
|
||||
top: Math.round(top.value ?? 0),
|
||||
width: Math.round(width.value),
|
||||
height: Math.round(height.value),
|
||||
}));
|
||||
@@ -348,36 +399,48 @@ const rectCorrectionByAspectRatio = (rect: {
|
||||
newTop: number;
|
||||
}) => {
|
||||
let { newLeft, newRight, newTop, newBottom } = rect;
|
||||
// const { parentWidth, parentHeight, currentStick, aspectFactor, dimensionsBeforeMove } = this;
|
||||
const currentParentWidth = parentWidth.value;
|
||||
const currentParentHeight = parentHeight.value;
|
||||
const stick = currentStick.value;
|
||||
const factor = aspectFactor.value;
|
||||
|
||||
let newWidth = parentWidth.value! - newLeft - newRight;
|
||||
let newHeight = parentHeight.value! - newTop - newBottom;
|
||||
if (
|
||||
currentParentWidth === null ||
|
||||
currentParentHeight === null ||
|
||||
!stick ||
|
||||
factor === null
|
||||
) {
|
||||
return { newLeft, newRight, newTop, newBottom };
|
||||
}
|
||||
|
||||
if (currentStick.value![1] === 'm') {
|
||||
let newWidth = currentParentWidth - newLeft - newRight;
|
||||
let newHeight = currentParentHeight - newTop - newBottom;
|
||||
|
||||
if (stick[1] === 'm') {
|
||||
const deltaHeight = newHeight - dimensionsBeforeMove.value.height;
|
||||
|
||||
newLeft -= (deltaHeight * aspectFactor.value!) / 2;
|
||||
newRight -= (deltaHeight * aspectFactor.value!) / 2;
|
||||
} else if (currentStick.value![0] === 'm') {
|
||||
newLeft -= (deltaHeight * factor) / 2;
|
||||
newRight -= (deltaHeight * factor) / 2;
|
||||
} else if (stick[0] === 'm') {
|
||||
const deltaWidth = newWidth - dimensionsBeforeMove.value.width;
|
||||
|
||||
newTop -= deltaWidth / aspectFactor.value! / 2;
|
||||
newBottom -= deltaWidth / aspectFactor.value! / 2;
|
||||
} else if (newWidth / newHeight > aspectFactor.value!) {
|
||||
newWidth = aspectFactor.value! * newHeight;
|
||||
newTop -= deltaWidth / factor / 2;
|
||||
newBottom -= deltaWidth / factor / 2;
|
||||
} else if (newWidth / newHeight > factor) {
|
||||
newWidth = factor * newHeight;
|
||||
|
||||
if (currentStick.value![1] === 'l') {
|
||||
newLeft = parentWidth.value! - newRight - newWidth;
|
||||
if (stick[1] === 'l') {
|
||||
newLeft = currentParentWidth - newRight - newWidth;
|
||||
} else {
|
||||
newRight = parentWidth.value! - newLeft - newWidth;
|
||||
newRight = currentParentWidth - newLeft - newWidth;
|
||||
}
|
||||
} else {
|
||||
newHeight = newWidth / aspectFactor.value!;
|
||||
newHeight = newWidth / factor;
|
||||
|
||||
if (currentStick.value![0] === 't') {
|
||||
newTop = parentHeight.value! - newBottom - newHeight;
|
||||
if (stick[0] === 't') {
|
||||
newTop = currentParentHeight - newBottom - newHeight;
|
||||
} else {
|
||||
newBottom = parentHeight.value! - newTop - newHeight;
|
||||
newBottom = currentParentHeight - newTop - newHeight;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,11 +448,17 @@ const rectCorrectionByAspectRatio = (rect: {
|
||||
};
|
||||
|
||||
const stickMove = (delta: { x: number; y: number }) => {
|
||||
const stick = currentStick.value;
|
||||
|
||||
if (!stick) {
|
||||
return;
|
||||
}
|
||||
|
||||
let newTop = dimensionsBeforeMove.value.top;
|
||||
let newBottom = dimensionsBeforeMove.value.bottom;
|
||||
let newLeft = dimensionsBeforeMove.value.left;
|
||||
let newRight = dimensionsBeforeMove.value.right;
|
||||
switch (currentStick.value![0]) {
|
||||
switch (stick[0]) {
|
||||
case 'b': {
|
||||
newBottom = dimensionsBeforeMove.value.bottom + delta.y;
|
||||
|
||||
@@ -419,7 +488,7 @@ const stickMove = (delta: { x: number; y: number }) => {
|
||||
}
|
||||
}
|
||||
|
||||
switch (currentStick.value![1]) {
|
||||
switch (stick[1]) {
|
||||
case 'l': {
|
||||
newLeft = dimensionsBeforeMove.value.left - delta.x;
|
||||
|
||||
@@ -512,89 +581,121 @@ const calcDragLimitation = () => {
|
||||
};
|
||||
|
||||
const calcResizeLimits = () => {
|
||||
// const { aspectFactor, width, height, bottom, top, left, right } = this;
|
||||
|
||||
const parentLim = parentLimitation.value ? 0 : null;
|
||||
const currentAspectFactor = aspectFactor.value;
|
||||
const currentLeft = left.value;
|
||||
const currentRight = right.value;
|
||||
const currentTop = top.value;
|
||||
const currentBottom = bottom.value;
|
||||
const stick = currentStick.value;
|
||||
|
||||
if (aspectRatio.value) {
|
||||
if (minw.value / minh.value > (aspectFactor.value as number)) {
|
||||
minh.value = minw.value / (aspectFactor.value as number);
|
||||
if (
|
||||
currentLeft === null ||
|
||||
currentRight === null ||
|
||||
currentTop === null ||
|
||||
currentBottom === null
|
||||
) {
|
||||
return {
|
||||
left: { min: parentLim, max: parentLim },
|
||||
right: { min: parentLim, max: parentLim },
|
||||
top: { min: parentLim, max: parentLim },
|
||||
bottom: { min: parentLim, max: parentLim },
|
||||
};
|
||||
}
|
||||
|
||||
let minWidth = minw.value;
|
||||
let minHeight = minh.value;
|
||||
|
||||
if (aspectRatio.value && currentAspectFactor) {
|
||||
if (minWidth / minHeight > currentAspectFactor) {
|
||||
minHeight = minWidth / currentAspectFactor;
|
||||
} else {
|
||||
minw.value = ((aspectFactor.value as number) * minh.value) as number;
|
||||
minWidth = currentAspectFactor * minHeight;
|
||||
}
|
||||
}
|
||||
|
||||
const limits = {
|
||||
left: {
|
||||
min: parentLim,
|
||||
max: (left.value as number) + (width.value - minw.value),
|
||||
max: currentLeft + (width.value - minWidth),
|
||||
},
|
||||
right: {
|
||||
min: parentLim,
|
||||
max: (right.value as number) + (width.value - minw.value),
|
||||
max: currentRight + (width.value - minWidth),
|
||||
},
|
||||
top: {
|
||||
min: parentLim,
|
||||
max: (top.value as number) + (height.value - minh.value),
|
||||
max: currentTop + (height.value - minHeight),
|
||||
},
|
||||
bottom: {
|
||||
min: parentLim,
|
||||
max: (bottom.value as number) + (height.value - minh.value),
|
||||
max: currentBottom + (height.value - minHeight),
|
||||
},
|
||||
};
|
||||
|
||||
if (aspectRatio.value) {
|
||||
if (aspectRatio.value && currentAspectFactor) {
|
||||
const aspectLimits = {
|
||||
left: {
|
||||
min:
|
||||
left.value! -
|
||||
Math.min(top.value!, bottom.value!) * aspectFactor.value! * 2,
|
||||
currentLeft -
|
||||
Math.min(currentTop, currentBottom) * currentAspectFactor * 2,
|
||||
max:
|
||||
left.value! +
|
||||
((height.value - minh.value!) / 2) * aspectFactor.value! * 2,
|
||||
currentLeft +
|
||||
((height.value - minHeight) / 2) * currentAspectFactor * 2,
|
||||
},
|
||||
right: {
|
||||
min:
|
||||
right.value! -
|
||||
Math.min(top.value!, bottom.value!) * aspectFactor.value! * 2,
|
||||
currentRight -
|
||||
Math.min(currentTop, currentBottom) * currentAspectFactor * 2,
|
||||
max:
|
||||
right.value! +
|
||||
((height.value - minh.value!) / 2) * aspectFactor.value! * 2,
|
||||
currentRight +
|
||||
((height.value - minHeight) / 2) * currentAspectFactor * 2,
|
||||
},
|
||||
top: {
|
||||
min:
|
||||
top.value! -
|
||||
(Math.min(left.value!, right.value!) / aspectFactor.value!) * 2,
|
||||
currentTop -
|
||||
(Math.min(currentLeft, currentRight) / currentAspectFactor) * 2,
|
||||
max:
|
||||
top.value! +
|
||||
((width.value - minw.value) / 2 / aspectFactor.value!) * 2,
|
||||
currentTop + ((width.value - minWidth) / 2 / currentAspectFactor) * 2,
|
||||
},
|
||||
bottom: {
|
||||
min:
|
||||
bottom.value! -
|
||||
(Math.min(left.value!, right.value!) / aspectFactor.value!) * 2,
|
||||
currentBottom -
|
||||
(Math.min(currentLeft, currentRight) / currentAspectFactor) * 2,
|
||||
max:
|
||||
bottom.value! +
|
||||
((width.value - minw.value) / 2 / aspectFactor.value!) * 2,
|
||||
currentBottom +
|
||||
((width.value - minWidth) / 2 / currentAspectFactor) * 2,
|
||||
},
|
||||
};
|
||||
|
||||
if (currentStick.value![0] === 'm') {
|
||||
if (stick?.[0] === 'm') {
|
||||
limits.left = {
|
||||
min: Math.max(limits.left.min!, aspectLimits.left.min),
|
||||
min: Math.max(
|
||||
limits.left.min ?? aspectLimits.left.min,
|
||||
aspectLimits.left.min,
|
||||
),
|
||||
max: Math.min(limits.left.max, aspectLimits.left.max),
|
||||
};
|
||||
limits.right = {
|
||||
min: Math.max(limits.right.min!, aspectLimits.right.min),
|
||||
min: Math.max(
|
||||
limits.right.min ?? aspectLimits.right.min,
|
||||
aspectLimits.right.min,
|
||||
),
|
||||
max: Math.min(limits.right.max, aspectLimits.right.max),
|
||||
};
|
||||
} else if (currentStick.value![1] === 'm') {
|
||||
} else if (stick?.[1] === 'm') {
|
||||
limits.top = {
|
||||
min: Math.max(limits.top.min!, aspectLimits.top.min),
|
||||
min: Math.max(
|
||||
limits.top.min ?? aspectLimits.top.min,
|
||||
aspectLimits.top.min,
|
||||
),
|
||||
max: Math.min(limits.top.max, aspectLimits.top.max),
|
||||
};
|
||||
limits.bottom = {
|
||||
min: Math.max(limits.bottom.min!, aspectLimits.bottom.min),
|
||||
min: Math.max(
|
||||
limits.bottom.min ?? aspectLimits.bottom.min,
|
||||
aspectLimits.bottom.min,
|
||||
),
|
||||
max: Math.min(limits.bottom.max, aspectLimits.bottom.max),
|
||||
};
|
||||
}
|
||||
@@ -604,9 +705,9 @@ const calcResizeLimits = () => {
|
||||
};
|
||||
|
||||
const positionStyle = computed(() => ({
|
||||
top: `${top.value}px`,
|
||||
left: `${left.value}px`,
|
||||
zIndex: zIndex.value!,
|
||||
top: `${top.value ?? 0}px`,
|
||||
left: `${left.value ?? 0}px`,
|
||||
zIndex: zIndex.value ?? 'auto',
|
||||
}));
|
||||
|
||||
const sizeStyle = computed(() => ({
|
||||
@@ -618,13 +719,11 @@ const stickStyles = computed(() => (stick: string) => {
|
||||
const stickStyle = {
|
||||
width: `${stickSize.value / parentScaleX.value}px`,
|
||||
height: `${stickSize.value / parentScaleY.value}px`,
|
||||
[styleMapping.y[stick[0] as 'b' | 'm' | 't'] as 'height' | 'width']:
|
||||
`${stickSize.value / parentScaleX.value / -2}px`,
|
||||
[styleMapping.x[stick[1] as 'l' | 'm' | 'r'] as 'height' | 'width']:
|
||||
`${stickSize.value / parentScaleX.value / -2}px`,
|
||||
};
|
||||
stickStyle[
|
||||
styleMapping.y[stick[0] as 'b' | 'm' | 't'] as 'height' | 'width'
|
||||
] = `${stickSize.value / parentScaleX.value / -2}px`;
|
||||
stickStyle[
|
||||
styleMapping.x[stick[1] as 'l' | 'm' | 'r'] as 'height' | 'width'
|
||||
] = `${stickSize.value / parentScaleX.value / -2}px`;
|
||||
return stickStyle;
|
||||
});
|
||||
|
||||
@@ -719,12 +818,15 @@ const stickDown = (
|
||||
return;
|
||||
}
|
||||
|
||||
const pointerPosition = getPointerPosition(ev);
|
||||
|
||||
if (!pointerPosition) {
|
||||
return;
|
||||
}
|
||||
|
||||
stickDrag.value = true;
|
||||
|
||||
const pointerX = ev.pageX === undefined ? ev.touches[0].pageX : ev.pageX;
|
||||
const pointerY = ev.pageY === undefined ? ev.touches[0].pageY : ev.pageY;
|
||||
|
||||
saveDimensionsBeforeMove({ pointerX, pointerY });
|
||||
saveDimensionsBeforeMove(pointerPosition);
|
||||
|
||||
currentStick.value = stick;
|
||||
|
||||
@@ -738,13 +840,19 @@ const move = (ev: MouseEvent & TouchEvent) => {
|
||||
|
||||
ev.stopPropagation();
|
||||
|
||||
// touches 兼容性代码
|
||||
const pageX = ev.pageX === undefined ? ev.touches![0]!.pageX : ev.pageX;
|
||||
const pageY = ev.pageY === undefined ? ev.touches![0]!.pageY : ev.pageY;
|
||||
const pointerPosition = getPointerPosition(ev);
|
||||
|
||||
if (!pointerPosition) {
|
||||
return;
|
||||
}
|
||||
|
||||
const delta = {
|
||||
x: (dimensionsBeforeMove.value.pointerX - pageX) / parentScaleX.value,
|
||||
y: (dimensionsBeforeMove.value.pointerY - pageY) / parentScaleY.value,
|
||||
x:
|
||||
(dimensionsBeforeMove.value.pointerX - pointerPosition.pointerX) /
|
||||
parentScaleX.value,
|
||||
y:
|
||||
(dimensionsBeforeMove.value.pointerY - pointerPosition.pointerY) /
|
||||
parentScaleY.value,
|
||||
};
|
||||
|
||||
if (stickDrag.value) {
|
||||
@@ -812,12 +920,17 @@ onMounted(() => {
|
||||
|
||||
left.value = x.value;
|
||||
top.value = y.value;
|
||||
right.value = (parentWidth.value -
|
||||
(w.value === 'auto' ? container.value!.scrollWidth : (w.value as number)) -
|
||||
left.value) as number;
|
||||
bottom.value = (parentHeight.value -
|
||||
(h.value === 'auto' ? container.value!.scrollHeight : (h.value as number)) -
|
||||
top.value) as number;
|
||||
const containerElement = container.value;
|
||||
const contentWidth =
|
||||
w.value === 'auto'
|
||||
? (containerElement?.scrollWidth ?? 0)
|
||||
: (w.value as number);
|
||||
const contentHeight =
|
||||
h.value === 'auto'
|
||||
? (containerElement?.scrollHeight ?? 0)
|
||||
: (h.value as number);
|
||||
right.value = (parentWidth.value ?? 0) - contentWidth - (left.value ?? 0);
|
||||
bottom.value = (parentHeight.value ?? 0) - contentHeight - (top.value ?? 0);
|
||||
|
||||
addEvents(domEvents.value);
|
||||
|
||||
@@ -841,13 +954,14 @@ onMounted(() => {
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
removeEvents(domEvents.value);
|
||||
});
|
||||
|
||||
const bodyDown = (ev: MouseEvent & TouchEvent) => {
|
||||
const { target, button } = ev;
|
||||
const targetElement = target instanceof HTMLElement ? target : null;
|
||||
const uid = getCurrentInstance()?.uid.toString();
|
||||
|
||||
if (!preventActiveBehavior.value) {
|
||||
active.value = true;
|
||||
@@ -865,17 +979,13 @@ const bodyDown = (ev: MouseEvent & TouchEvent) => {
|
||||
|
||||
if (
|
||||
dragHandle.value &&
|
||||
(target! as HTMLElement).dataset.dragHandle !==
|
||||
getCurrentInstance()?.uid.toString()
|
||||
targetElement &&
|
||||
targetElement.dataset.dragHandle !== uid
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
dragCancel.value &&
|
||||
(target! as HTMLElement).dataset.dragCancel ===
|
||||
getCurrentInstance()?.uid.toString()
|
||||
) {
|
||||
if (dragCancel.value && targetElement?.dataset.dragCancel === uid) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -887,14 +997,17 @@ const bodyDown = (ev: MouseEvent & TouchEvent) => {
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
const pointerPosition = getPointerPosition(ev);
|
||||
|
||||
if (!pointerPosition) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isDraggable.value) {
|
||||
bodyDrag.value = true;
|
||||
}
|
||||
|
||||
const pointerX = ev.pageX === undefined ? ev.touches[0]!.pageX : ev.pageX;
|
||||
const pointerY = ev.pageY === undefined ? ev.touches[0]!.pageY : ev.pageY;
|
||||
|
||||
saveDimensionsBeforeMove({ pointerX, pointerY });
|
||||
saveDimensionsBeforeMove(pointerPosition);
|
||||
|
||||
if (parentLimitation.value) {
|
||||
limits.value = calcDragLimitation();
|
||||
@@ -923,8 +1036,10 @@ watch(
|
||||
watch(
|
||||
() => z.value,
|
||||
(val) => {
|
||||
if ((val as number) >= 0 || val === 'auto') {
|
||||
zIndex.value = val as number;
|
||||
if (typeof val === 'number' && val >= 0) {
|
||||
zIndex.value = val;
|
||||
} else if (val === 'auto') {
|
||||
zIndex.value = null;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
@@ -933,13 +1048,22 @@ watch(
|
||||
watch(
|
||||
() => x.value,
|
||||
(newVal, oldVal) => {
|
||||
if (stickDrag.value || bodyDrag.value || newVal === left.value) {
|
||||
const currentLeft = left.value;
|
||||
const currentTop = top.value;
|
||||
|
||||
if (
|
||||
stickDrag.value ||
|
||||
bodyDrag.value ||
|
||||
currentLeft === null ||
|
||||
currentTop === null ||
|
||||
newVal === currentLeft
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const delta = oldVal - newVal;
|
||||
|
||||
bodyDown({ pageX: left.value!, pageY: top.value! } as MouseEvent &
|
||||
bodyDown({ pageX: currentLeft, pageY: currentTop } as MouseEvent &
|
||||
TouchEvent);
|
||||
bodyMove({ x: delta, y: 0 });
|
||||
|
||||
@@ -952,13 +1076,22 @@ watch(
|
||||
watch(
|
||||
() => y.value,
|
||||
(newVal, oldVal) => {
|
||||
if (stickDrag.value || bodyDrag.value || newVal === top.value) {
|
||||
const currentLeft = left.value;
|
||||
const currentTop = top.value;
|
||||
|
||||
if (
|
||||
stickDrag.value ||
|
||||
bodyDrag.value ||
|
||||
currentLeft === null ||
|
||||
currentTop === null ||
|
||||
newVal === currentTop
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const delta = oldVal - newVal;
|
||||
|
||||
bodyDown({ pageX: left.value, pageY: top.value } as MouseEvent &
|
||||
bodyDown({ pageX: currentLeft, pageY: currentTop } as MouseEvent &
|
||||
TouchEvent);
|
||||
bodyMove({ x: 0, y: delta });
|
||||
|
||||
@@ -971,16 +1104,23 @@ watch(
|
||||
watch(
|
||||
() => w.value,
|
||||
(newVal, oldVal) => {
|
||||
const currentRight = right.value;
|
||||
const currentTop = top.value;
|
||||
|
||||
if (stickDrag.value || bodyDrag.value || newVal === width.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentRight === null || currentTop === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const stick = 'mr';
|
||||
const delta = (oldVal as number) - (newVal as number);
|
||||
|
||||
stickDown(
|
||||
stick,
|
||||
{ pageX: right.value, pageY: top.value! + height.value / 2 },
|
||||
{ pageX: currentRight, pageY: currentTop + height.value / 2 },
|
||||
true,
|
||||
);
|
||||
stickMove({ x: delta, y: 0 });
|
||||
@@ -994,16 +1134,23 @@ watch(
|
||||
watch(
|
||||
() => h.value,
|
||||
(newVal, oldVal) => {
|
||||
const currentLeft = left.value;
|
||||
const currentBottom = bottom.value;
|
||||
|
||||
if (stickDrag.value || bodyDrag.value || newVal === height.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentLeft === null || currentBottom === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const stick = 'bm';
|
||||
const delta = (oldVal as number) - (newVal as number);
|
||||
|
||||
stickDown(
|
||||
stick,
|
||||
{ pageX: left.value! + width.value / 2, pageY: bottom.value },
|
||||
{ pageX: currentLeft + width.value / 2, pageY: currentBottom },
|
||||
true,
|
||||
);
|
||||
stickMove({ x: 0, y: delta });
|
||||
@@ -1017,7 +1164,7 @@ watch(
|
||||
watch(
|
||||
() => parentW.value,
|
||||
(val) => {
|
||||
right.value = val - width.value - left.value!;
|
||||
right.value = val - width.value - (left.value ?? 0);
|
||||
parentWidth.value = val;
|
||||
},
|
||||
);
|
||||
@@ -1025,7 +1172,7 @@ watch(
|
||||
watch(
|
||||
() => parentH.value,
|
||||
(val) => {
|
||||
bottom.value = val - height.value - top.value!;
|
||||
bottom.value = val - height.value - (top.value ?? 0);
|
||||
parentHeight.value = val;
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { default as Tree } from './tree.vue';
|
||||
@@ -0,0 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import type { TreeProps } from '@vben-core/shadcn-ui';
|
||||
|
||||
import { Inbox } from '@vben/icons';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { treePropsDefaults, VbenTree } from '@vben-core/shadcn-ui';
|
||||
|
||||
const props = withDefaults(defineProps<TreeProps>(), treePropsDefaults());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VbenTree v-if="props.treeData?.length > 0" v-bind="props">
|
||||
<template v-for="(_, key) in $slots" :key="key" #[key]="slotProps">
|
||||
<slot :name="key" v-bind="slotProps"> </slot>
|
||||
</template>
|
||||
</VbenTree>
|
||||
<div
|
||||
v-else
|
||||
class="flex-col-center cursor-pointer rounded-lg border p-10 text-sm font-medium text-muted-foreground"
|
||||
>
|
||||
<Inbox class="size-10" />
|
||||
<div class="mt-1">{{ $t('common.noData') }}</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -114,7 +114,7 @@ const devDependenciesItems = Object.keys(devDependencies).map((key) => ({
|
||||
<template>
|
||||
<Page :title="title">
|
||||
<template #description>
|
||||
<p class="text-foreground mt-3 text-sm leading-6">
|
||||
<p class="mt-3 text-sm/6 text-foreground">
|
||||
<a :href="VBEN_GITHUB_URL" class="vben-link" target="_blank">
|
||||
{{ name }}
|
||||
</a>
|
||||
@@ -123,16 +123,16 @@ const devDependenciesItems = Object.keys(devDependencies).map((key) => ({
|
||||
</template>
|
||||
<div class="card-box p-5">
|
||||
<div>
|
||||
<h5 class="text-foreground text-lg">基本信息</h5>
|
||||
<h5 class="text-lg text-foreground">基本信息</h5>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<dl class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4">
|
||||
<template v-for="item in vbenDescriptionItems" :key="item.title">
|
||||
<div class="border-border border-t px-4 py-6 sm:col-span-1 sm:px-0">
|
||||
<dt class="text-foreground text-sm font-medium leading-6">
|
||||
<div class="border-t border-border px-4 py-6 sm:col-span-1 sm:px-0">
|
||||
<dt class="text-sm/6 font-medium text-foreground">
|
||||
{{ item.title }}
|
||||
</dt>
|
||||
<dd class="text-foreground mt-1 text-sm leading-6 sm:mt-2">
|
||||
<dd class="mt-1 text-sm/6 text-foreground sm:mt-2">
|
||||
<VbenRenderContent :content="item.content" />
|
||||
</dd>
|
||||
</div>
|
||||
@@ -143,16 +143,16 @@ const devDependenciesItems = Object.keys(devDependencies).map((key) => ({
|
||||
|
||||
<div class="card-box mt-6 p-5">
|
||||
<div>
|
||||
<h5 class="text-foreground text-lg">生产环境依赖</h5>
|
||||
<h5 class="text-lg text-foreground">生产环境依赖</h5>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<dl class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4">
|
||||
<template v-for="item in dependenciesItems" :key="item.title">
|
||||
<div class="border-border border-t px-4 py-3 sm:col-span-1 sm:px-0">
|
||||
<dt class="text-foreground text-sm">
|
||||
<div class="border-t border-border px-4 py-3 sm:col-span-1 sm:px-0">
|
||||
<dt class="text-sm text-foreground">
|
||||
{{ item.title }}
|
||||
</dt>
|
||||
<dd class="text-foreground/80 mt-1 text-sm sm:mt-2">
|
||||
<dd class="mt-1 text-sm text-foreground/80 sm:mt-2">
|
||||
<VbenRenderContent :content="item.content" />
|
||||
</dd>
|
||||
</div>
|
||||
@@ -162,16 +162,16 @@ const devDependenciesItems = Object.keys(devDependencies).map((key) => ({
|
||||
</div>
|
||||
<div class="card-box mt-6 p-5">
|
||||
<div>
|
||||
<h5 class="text-foreground text-lg">开发环境依赖</h5>
|
||||
<h5 class="text-lg text-foreground">开发环境依赖</h5>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<dl class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4">
|
||||
<template v-for="item in devDependenciesItems" :key="item.title">
|
||||
<div class="border-border border-t px-4 py-3 sm:col-span-1 sm:px-0">
|
||||
<dt class="text-foreground text-sm">
|
||||
<div class="border-t border-border px-4 py-3 sm:col-span-1 sm:px-0">
|
||||
<dt class="text-sm text-foreground">
|
||||
{{ item.title }}
|
||||
</dt>
|
||||
<dd class="text-foreground/80 mt-1 text-sm sm:mt-2">
|
||||
<dd class="mt-1 text-sm text-foreground/80 sm:mt-2">
|
||||
<VbenRenderContent :content="item.content" />
|
||||
</dd>
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<template>
|
||||
<div class="mb-7 sm:mx-auto sm:w-full sm:max-w-md">
|
||||
<h2
|
||||
class="text-foreground mb-3 text-3xl font-bold leading-9 tracking-tight lg:text-4xl"
|
||||
class="mb-3 text-3xl/9 font-bold tracking-tight text-foreground lg:text-4xl"
|
||||
>
|
||||
<slot></slot>
|
||||
</h2>
|
||||
|
||||
<p class="text-muted-foreground lg:text-md text-sm">
|
||||
<p class="lg:text-md text-sm text-muted-foreground">
|
||||
<slot name="desc"></slot>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -35,6 +35,10 @@ interface Props {
|
||||
* @zh_CN 按钮文本
|
||||
*/
|
||||
submitButtonText?: string;
|
||||
/**
|
||||
* @zh_CN 是否显示返回按钮
|
||||
*/
|
||||
showBack?: boolean;
|
||||
}
|
||||
|
||||
defineOptions({
|
||||
@@ -43,6 +47,7 @@ defineOptions({
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
loading: false,
|
||||
showBack: true,
|
||||
loginPath: '/auth/login',
|
||||
submitButtonText: '',
|
||||
subTitle: '',
|
||||
@@ -110,7 +115,12 @@ defineExpose({
|
||||
{{ submitButtonText || $t('common.login') }}
|
||||
</slot>
|
||||
</VbenButton>
|
||||
<VbenButton class="mt-4 w-full" variant="outline" @click="goToLogin()">
|
||||
<VbenButton
|
||||
v-if="showBack"
|
||||
class="mt-4 w-full"
|
||||
variant="outline"
|
||||
@click="goToLogin()"
|
||||
>
|
||||
{{ $t('common.back') }}
|
||||
</VbenButton>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import { RiDingding } from '@vben/icons';
|
||||
import { SvgDingDingIcon } from '@vben/icons';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { alert, useVbenModal } from '@vben-core/popup-ui';
|
||||
@@ -25,7 +25,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||
header: false,
|
||||
footer: false,
|
||||
fullscreenButton: false,
|
||||
class: 'w-[302px] h-[302px] dingding-qrcode-login-modal',
|
||||
class: 'size-75.5 dingding-qrcode-login-modal',
|
||||
onOpened() {
|
||||
handleQrCodeLogin();
|
||||
},
|
||||
@@ -96,7 +96,7 @@ const handleLogin = () => {
|
||||
:tooltip="$t('authentication.dingdingLogin')"
|
||||
tooltip-side="top"
|
||||
>
|
||||
<RiDingding />
|
||||
<SvgDingDingIcon />
|
||||
</VbenIconButton>
|
||||
<Modal>
|
||||
<div id="dingding_qrcode_login_element"></div>
|
||||
|
||||
@@ -78,7 +78,7 @@ function calcZIndex() {
|
||||
:fullscreen-button="false"
|
||||
:header="false"
|
||||
:z-index="getZIndex"
|
||||
class="border-none px-10 py-6 text-center shadow-xl sm:w-[600px] sm:rounded-2xl md:h-[unset]"
|
||||
class="border-none px-10 py-6 text-center shadow-xl sm:w-150 sm:rounded-2xl md:h-[unset]"
|
||||
>
|
||||
<VbenAvatar :src="avatar" class="mx-auto mb-6 size-20" />
|
||||
<Slot
|
||||
|
||||
@@ -14,6 +14,7 @@ import { useVbenForm } from '@vben-core/form-ui';
|
||||
import { VbenButton, VbenCheckbox } from '@vben-core/shadcn-ui';
|
||||
|
||||
import Title from './auth-title.vue';
|
||||
import ThirdPartyLogin from './third-party-login.vue';
|
||||
|
||||
interface Props extends AuthenticationProps {
|
||||
formSchema?: VbenFormSchema[];
|
||||
@@ -61,19 +62,15 @@ const REMEMBER_ME_KEY = `REMEMBER_ME_USERNAME_${location.hostname}`;
|
||||
|
||||
const localUsername = localStorage.getItem(REMEMBER_ME_KEY) || '';
|
||||
|
||||
// 清理可能存在的 undefined 值
|
||||
const cleanLocalUsername = localUsername === 'undefined' ? '' : localUsername;
|
||||
|
||||
const rememberMe = ref(!!cleanLocalUsername);
|
||||
const rememberMe = ref(!!localUsername);
|
||||
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formApi.validate();
|
||||
const values = await formApi.getValues();
|
||||
if (valid) {
|
||||
const username = values?.account || values?.username;
|
||||
localStorage.setItem(
|
||||
REMEMBER_ME_KEY,
|
||||
rememberMe.value && username && username !== 'undefined' ? username : '',
|
||||
rememberMe.value ? values?.username : '',
|
||||
);
|
||||
emit('submit', values);
|
||||
}
|
||||
@@ -84,13 +81,8 @@ function handleGo(path: string) {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 清理 localStorage 中可能存在的 undefined 值
|
||||
if (localUsername === 'undefined') {
|
||||
localStorage.removeItem(REMEMBER_ME_KEY);
|
||||
}
|
||||
|
||||
if (cleanLocalUsername) {
|
||||
formApi.setFieldValue('account', cleanLocalUsername);
|
||||
if (localUsername) {
|
||||
formApi.setFieldValue('username', localUsername);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -125,7 +117,7 @@ defineExpose({
|
||||
<div class="flex-center">
|
||||
<VbenCheckbox
|
||||
v-if="showRememberMe"
|
||||
v-model:checked="rememberMe"
|
||||
v-model="rememberMe"
|
||||
name="rememberMe"
|
||||
>
|
||||
{{ $t('authentication.rememberMe') }}
|
||||
@@ -152,9 +144,9 @@ defineExpose({
|
||||
{{ submitButtonText || $t('common.login') }}
|
||||
</VbenButton>
|
||||
|
||||
<!-- <div
|
||||
<div
|
||||
v-if="showCodeLogin || showQrcodeLogin"
|
||||
class="mb-2 mt-4 flex items-center justify-between"
|
||||
class="mt-4 mb-2 flex items-center justify-between"
|
||||
>
|
||||
<VbenButton
|
||||
v-if="showCodeLogin"
|
||||
@@ -172,12 +164,12 @@ defineExpose({
|
||||
>
|
||||
{{ $t('authentication.qrcodeLogin') }}
|
||||
</VbenButton>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
<!-- 第三方登录 -->
|
||||
<!-- <slot name="third-party-login">
|
||||
<slot name="third-party-login">
|
||||
<ThirdPartyLogin v-if="showThirdPartyLogin" />
|
||||
</slot> -->
|
||||
</slot>
|
||||
|
||||
<slot name="to-register">
|
||||
<div v-if="showRegister" class="mt-3 text-center text-sm">
|
||||
|
||||
@@ -35,6 +35,10 @@ interface Props {
|
||||
* @zh_CN 描述
|
||||
*/
|
||||
description?: string;
|
||||
/**
|
||||
* @zh_CN 是否显示返回按钮
|
||||
*/
|
||||
showBack?: boolean;
|
||||
}
|
||||
|
||||
defineOptions({
|
||||
@@ -44,6 +48,7 @@ defineOptions({
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
description: '',
|
||||
loading: false,
|
||||
showBack: true,
|
||||
loginPath: '/auth/login',
|
||||
submitButtonText: '',
|
||||
subTitle: '',
|
||||
@@ -79,16 +84,21 @@ function goToLogin() {
|
||||
</template>
|
||||
</Title>
|
||||
|
||||
<div class="flex-col-center mt-6">
|
||||
<div class="mt-6 flex-col-center">
|
||||
<img :src="qrcode" alt="qrcode" class="w-1/2" />
|
||||
<p class="text-muted-foreground mt-4 text-sm">
|
||||
<p class="mt-4 text-sm text-muted-foreground">
|
||||
<slot name="description">
|
||||
{{ description || $t('authentication.qrcodePrompt') }}
|
||||
</slot>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<VbenButton class="mt-4 w-full" variant="outline" @click="goToLogin()">
|
||||
<VbenButton
|
||||
v-if="showBack"
|
||||
class="mt-4 w-full"
|
||||
variant="outline"
|
||||
@click="goToLogin()"
|
||||
>
|
||||
{{ $t('common.back') }}
|
||||
</VbenButton>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { useAppConfig } from '@vben/hooks';
|
||||
import { MdiGithub, MdiGoogle, MdiQqchat, MdiWechat } from '@vben/icons';
|
||||
import {
|
||||
SvgGithubIcon,
|
||||
SvgGoogleIcon,
|
||||
SvgQQChatIcon,
|
||||
SvgWeChatIcon,
|
||||
} from '@vben/icons';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { VbenIconButton } from '@vben-core/shadcn-ui';
|
||||
@@ -19,11 +24,11 @@ const {
|
||||
<template>
|
||||
<div class="w-full sm:mx-auto md:max-w-md">
|
||||
<div class="mt-4 flex items-center justify-between">
|
||||
<span class="border-input w-[35%] border-b dark:border-gray-600"></span>
|
||||
<span class="text-muted-foreground text-center text-xs uppercase">
|
||||
<span class="w-[35%] border-b border-input dark:border-gray-600"></span>
|
||||
<span class="text-center text-xs text-muted-foreground uppercase">
|
||||
{{ $t('authentication.thirdPartyLogin') }}
|
||||
</span>
|
||||
<span class="border-input w-[35%] border-b dark:border-gray-600"></span>
|
||||
<span class="w-[35%] border-b border-input dark:border-gray-600"></span>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex flex-wrap justify-center">
|
||||
@@ -32,28 +37,28 @@ const {
|
||||
tooltip-side="top"
|
||||
class="mb-3"
|
||||
>
|
||||
<MdiWechat />
|
||||
<SvgWeChatIcon />
|
||||
</VbenIconButton>
|
||||
<VbenIconButton
|
||||
:tooltip="$t('authentication.qqLogin')"
|
||||
tooltip-side="top"
|
||||
class="mb-3"
|
||||
>
|
||||
<MdiQqchat />
|
||||
<SvgQQChatIcon />
|
||||
</VbenIconButton>
|
||||
<VbenIconButton
|
||||
:tooltip="$t('authentication.githubLogin')"
|
||||
tooltip-side="top"
|
||||
class="mb-3"
|
||||
>
|
||||
<MdiGithub />
|
||||
<SvgGithubIcon />
|
||||
</VbenIconButton>
|
||||
<VbenIconButton
|
||||
:tooltip="$t('authentication.googleLogin')"
|
||||
tooltip-side="top"
|
||||
class="mb-3"
|
||||
>
|
||||
<MdiGoogle />
|
||||
<SvgGoogleIcon />
|
||||
</VbenIconButton>
|
||||
<DingdingLogin
|
||||
v-if="dingdingAuthConfig"
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ const defaultValue = computed(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="card-box w-full px-4 pb-5 pt-3">
|
||||
<div class="card-box w-full px-4 pt-3 pb-5">
|
||||
<Tabs :default-value="defaultValue">
|
||||
<TabsList>
|
||||
<template v-for="tab in tabs" :key="tab.label">
|
||||
|
||||
@@ -39,7 +39,7 @@ withDefaults(defineProps<Props>(), {
|
||||
class="text-xl"
|
||||
prefix=""
|
||||
/>
|
||||
<VbenIcon :icon="item.icon" class="size-8 flex-shrink-0" />
|
||||
<VbenIcon :icon="item.icon" class="size-8 shrink-0" />
|
||||
</CardContent>
|
||||
<CardFooter class="justify-between">
|
||||
<span>{{ item.totalTitle }}</span>
|
||||
|
||||
@@ -18,12 +18,12 @@ withDefaults(defineProps<Props>(), {
|
||||
<VbenAvatar :src="avatar" class="size-20" />
|
||||
<div
|
||||
v-if="$slots.title || $slots.description"
|
||||
class="flex flex-col justify-center md:ml-6 md:mt-0"
|
||||
class="flex flex-col justify-center md:mt-0 md:ml-6"
|
||||
>
|
||||
<h1 v-if="$slots.title" class="text-md font-semibold md:text-xl">
|
||||
<slot name="title"></slot>
|
||||
</h1>
|
||||
<span v-if="$slots.description" class="text-foreground/80 mt-1">
|
||||
<span v-if="$slots.description" class="mt-1 text-foreground/80">
|
||||
<slot name="description"></slot>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
+3
-3
@@ -40,7 +40,7 @@ defineEmits(['click']);
|
||||
'rounded-bl-xl': index === items.length - 3,
|
||||
'rounded-br-xl': index === items.length - 1,
|
||||
}"
|
||||
class="border-border group w-full cursor-pointer border-r border-t p-4 transition-all hover:shadow-xl md:w-1/2 lg:w-1/3"
|
||||
class="group w-full cursor-pointer border-t border-r border-border p-4 transition-all hover:shadow-xl md:w-1/2 lg:w-1/3"
|
||||
>
|
||||
<div class="flex items-center">
|
||||
<VbenIcon
|
||||
@@ -51,10 +51,10 @@ defineEmits(['click']);
|
||||
/>
|
||||
<span class="ml-4 text-lg font-medium">{{ item.title }}</span>
|
||||
</div>
|
||||
<div class="text-foreground/80 mt-4 flex h-10">
|
||||
<div class="mt-4 flex h-10 text-foreground/80">
|
||||
{{ item.content }}
|
||||
</div>
|
||||
<div class="text-foreground/80 flex justify-between">
|
||||
<div class="flex justify-between text-foreground/80">
|
||||
<span>{{ item.group }}</span>
|
||||
<span>{{ item.date }}</span>
|
||||
</div>
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ defineEmits(['click']);
|
||||
'rounded-bl-xl': index === items.length - 3,
|
||||
'rounded-br-xl': index === items.length - 1,
|
||||
}"
|
||||
class="flex-col-center border-border group w-1/3 cursor-pointer border-r border-t py-8 hover:shadow-xl"
|
||||
class="group flex-col-center w-1/3 cursor-pointer border-t border-r border-border py-8 hover:shadow-xl"
|
||||
@click="$emit('click', item)"
|
||||
>
|
||||
<VbenIcon
|
||||
|
||||
@@ -29,30 +29,30 @@ withDefaults(defineProps<Props>(), {
|
||||
<CardTitle class="text-lg">{{ title }}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-wrap p-5 pt-0">
|
||||
<ul class="divide-border w-full divide-y" role="list">
|
||||
<ul class="w-full divide-y divide-border" role="list">
|
||||
<li
|
||||
v-for="item in items"
|
||||
:key="item.title"
|
||||
:class="{
|
||||
'select-none line-through opacity-60': item.completed,
|
||||
'line-through opacity-60 select-none': item.completed,
|
||||
}"
|
||||
class="flex cursor-pointer justify-between gap-x-6 py-5"
|
||||
>
|
||||
<div class="flex min-w-0 items-center gap-x-4">
|
||||
<VbenCheckbox v-model:checked="item.completed" name="completed" />
|
||||
<VbenCheckbox v-model="item.completed" name="completed" />
|
||||
<div class="min-w-0 flex-auto">
|
||||
<p class="text-foreground text-sm font-semibold leading-6">
|
||||
<p class="text-sm/6 font-semibold text-foreground">
|
||||
{{ item.title }}
|
||||
</p>
|
||||
<!-- eslint-disable vue/no-v-html -->
|
||||
<p
|
||||
class="text-foreground/80 *:text-primary mt-1 truncate text-xs leading-5"
|
||||
class="mt-1 truncate text-xs/5 text-foreground/80 *:text-primary"
|
||||
v-html="item.content"
|
||||
></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden h-full shrink-0 sm:flex sm:flex-col sm:items-end">
|
||||
<span class="text-foreground/80 mt-6 text-xs leading-6">
|
||||
<span class="mt-6 text-xs/6 text-foreground/80">
|
||||
{{ item.date }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -29,7 +29,7 @@ withDefaults(defineProps<Props>(), {
|
||||
<CardTitle class="text-lg">{{ title }}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-wrap p-5 pt-0">
|
||||
<ul class="divide-border w-full divide-y" role="list">
|
||||
<ul class="w-full divide-y divide-border" role="list">
|
||||
<li
|
||||
v-for="item in items"
|
||||
:key="item.title"
|
||||
@@ -42,18 +42,18 @@ withDefaults(defineProps<Props>(), {
|
||||
class="size-10 flex-none rounded-full"
|
||||
/>
|
||||
<div class="min-w-0 flex-auto">
|
||||
<p class="text-foreground text-sm font-semibold leading-6">
|
||||
<p class="text-sm/6 font-semibold text-foreground">
|
||||
{{ item.title }}
|
||||
</p>
|
||||
<!-- eslint-disable vue/no-v-html -->
|
||||
<p
|
||||
class="text-foreground/80 *:text-primary mt-1 truncate text-xs leading-5"
|
||||
class="mt-1 truncate text-xs/5 text-foreground/80 *:text-primary"
|
||||
v-html="item.content"
|
||||
></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden h-full shrink-0 sm:flex sm:flex-col sm:items-end">
|
||||
<span class="text-foreground/80 mt-6 text-xs leading-6">
|
||||
<span class="mt-6 text-xs/6 text-foreground/80">
|
||||
{{ item.date }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -128,7 +128,7 @@ function refresh() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex size-full flex-col items-center justify-center duration-300">
|
||||
<div class="flex-col-center size-full duration-300">
|
||||
<img v-if="image" :src="image" class="md:1/3 w-1/2 lg:w-1/4" />
|
||||
<component
|
||||
:is="fallbackIcon"
|
||||
@@ -139,14 +139,14 @@ function refresh() {
|
||||
<slot v-if="$slots.title" name="title"></slot>
|
||||
<p
|
||||
v-else-if="titleText"
|
||||
class="text-foreground mt-8 text-2xl md:text-3xl lg:text-4xl"
|
||||
class="mt-8 text-2xl text-foreground md:text-3xl lg:text-4xl"
|
||||
>
|
||||
{{ titleText }}
|
||||
</p>
|
||||
<slot v-if="$slots.describe" name="describe"></slot>
|
||||
<p
|
||||
v-else-if="descText"
|
||||
class="text-muted-foreground md:text-md my-4 lg:text-lg"
|
||||
class="md:text-md my-4 text-muted-foreground lg:text-lg"
|
||||
>
|
||||
{{ descText }}
|
||||
</p>
|
||||
|
||||
@@ -2,3 +2,4 @@ export * from './about';
|
||||
export * from './authentication';
|
||||
export * from './dashboard';
|
||||
export * from './fallback';
|
||||
export * from './profile';
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<script setup lang="ts">
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import type { VbenFormSchema } from '@vben-core/form-ui';
|
||||
|
||||
import { computed, reactive } from 'vue';
|
||||
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { useVbenForm } from '@vben-core/form-ui';
|
||||
import { VbenButton } from '@vben-core/shadcn-ui';
|
||||
|
||||
interface Props {
|
||||
formSchema?: VbenFormSchema[];
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
formSchema: () => [],
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
submit: [Recordable<any>];
|
||||
}>();
|
||||
|
||||
const [Form, formApi] = useVbenForm(
|
||||
reactive({
|
||||
commonConfig: {
|
||||
// 所有表单项
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: computed(() => props.formSchema),
|
||||
showDefaultActions: false,
|
||||
}),
|
||||
);
|
||||
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formApi.validate();
|
||||
const values = await formApi.getValues();
|
||||
if (valid) {
|
||||
emit('submit', values);
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
getFormApi: () => formApi,
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<div @keydown.enter.prevent="handleSubmit">
|
||||
<Form />
|
||||
<VbenButton type="submit" class="mt-4" @click="handleSubmit">
|
||||
{{ $t('profile.updateBasicProfile') }}
|
||||
</VbenButton>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,6 @@
|
||||
export { default as ProfileBaseSetting } from './base-setting.vue';
|
||||
export { default as ProfileNotificationSetting } from './notification-setting.vue';
|
||||
export { default as ProfilePasswordSetting } from './password-setting.vue';
|
||||
export { default as Profile } from './profile.vue';
|
||||
export { default as ProfileSecuritySetting } from './security-setting.vue';
|
||||
export type * from './types';
|
||||
@@ -0,0 +1,53 @@
|
||||
<script setup lang="ts">
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import type { SettingProps } from './types';
|
||||
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormDescription,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
Switch,
|
||||
} from '@vben-core/shadcn-ui';
|
||||
|
||||
withDefaults(defineProps<SettingProps>(), {
|
||||
formSchema: () => [],
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
change: [Recordable<any>];
|
||||
}>();
|
||||
|
||||
function handleChange(fieldName: string, value: boolean) {
|
||||
emit('change', { fieldName, value });
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<Form class="space-y-8">
|
||||
<div class="space-y-4">
|
||||
<template v-for="item in formSchema" :key="item.fieldName">
|
||||
<FormField type="checkbox" :name="item.fieldName">
|
||||
<FormItem
|
||||
class="flex flex-row items-center justify-between rounded-lg border p-4"
|
||||
>
|
||||
<div class="space-y-0.5">
|
||||
<FormLabel class="text-base"> {{ item.label }} </FormLabel>
|
||||
<FormDescription>
|
||||
{{ item.description }}
|
||||
</FormDescription>
|
||||
</div>
|
||||
<FormControl>
|
||||
<Switch
|
||||
:model-value="item.value"
|
||||
@update:model-value="handleChange(item.fieldName, $event)"
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
</FormField>
|
||||
</template>
|
||||
</div>
|
||||
</Form>
|
||||
</template>
|
||||
@@ -0,0 +1,59 @@
|
||||
<script setup lang="ts">
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import type { VbenFormSchema } from '@vben-core/form-ui';
|
||||
|
||||
import { computed, reactive } from 'vue';
|
||||
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { useVbenForm } from '@vben-core/form-ui';
|
||||
import { VbenButton } from '@vben-core/shadcn-ui';
|
||||
|
||||
interface Props {
|
||||
formSchema?: VbenFormSchema[];
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
formSchema: () => [],
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
submit: [Recordable<any>];
|
||||
}>();
|
||||
|
||||
const [Form, formApi] = useVbenForm(
|
||||
reactive({
|
||||
commonConfig: {
|
||||
labelWidth: 130,
|
||||
// 所有表单项
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: computed(() => props.formSchema),
|
||||
showDefaultActions: false,
|
||||
}),
|
||||
);
|
||||
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formApi.validate();
|
||||
const values = await formApi.getValues();
|
||||
if (valid) {
|
||||
emit('submit', values);
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
getFormApi: () => formApi,
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<Form />
|
||||
<VbenButton type="submit" class="mt-4" @click="handleSubmit">
|
||||
{{ $t('profile.updatePassword') }}
|
||||
</VbenButton>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,62 @@
|
||||
<script setup lang="ts">
|
||||
import type { Props } from './types';
|
||||
|
||||
import { preferences } from '@vben-core/preferences';
|
||||
import {
|
||||
Card,
|
||||
Separator,
|
||||
Tabs,
|
||||
TabsList,
|
||||
TabsTrigger,
|
||||
VbenAvatar,
|
||||
} from '@vben-core/shadcn-ui';
|
||||
|
||||
import { Page } from '../../components';
|
||||
|
||||
defineOptions({
|
||||
name: 'ProfileUI',
|
||||
});
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
title: '关于项目',
|
||||
tabs: () => [],
|
||||
});
|
||||
|
||||
const tabsValue = defineModel<string>('modelValue');
|
||||
</script>
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<div class="flex size-full">
|
||||
<Card class="w-1/6 flex-none">
|
||||
<div class="mt-4 flex-col-center h-40 gap-4">
|
||||
<VbenAvatar
|
||||
:src="userInfo?.avatar ?? preferences.app.defaultAvatar"
|
||||
class="size-20"
|
||||
/>
|
||||
<span class="text-lg font-semibold">
|
||||
{{ userInfo?.realName ?? '' }}
|
||||
</span>
|
||||
<span class="text-sm text-foreground/80">
|
||||
{{ userInfo?.username ?? '' }}
|
||||
</span>
|
||||
</div>
|
||||
<Separator class="my-4" />
|
||||
<Tabs v-model="tabsValue" orientation="vertical" class="m-4">
|
||||
<TabsList class="grid w-full grid-cols-1 bg-card">
|
||||
<TabsTrigger
|
||||
v-for="tab in tabs"
|
||||
:key="tab.value"
|
||||
:value="tab.value"
|
||||
class="h-12 justify-start data-[state=active]:bg-primary data-[state=active]:text-primary-foreground"
|
||||
>
|
||||
{{ tab.label }}
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
</Card>
|
||||
<Card class="ml-4 w-5/6 flex-auto p-8">
|
||||
<slot name="content"></slot>
|
||||
</Card>
|
||||
</div>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,53 @@
|
||||
<script setup lang="ts">
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import type { SettingProps } from './types';
|
||||
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormDescription,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
Switch,
|
||||
} from '@vben-core/shadcn-ui';
|
||||
|
||||
withDefaults(defineProps<SettingProps>(), {
|
||||
formSchema: () => [],
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
change: [Recordable<any>];
|
||||
}>();
|
||||
|
||||
function handleChange(fieldName: string, value: boolean) {
|
||||
emit('change', { fieldName, value });
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<Form class="space-y-8">
|
||||
<div class="space-y-4">
|
||||
<template v-for="item in formSchema" :key="item.fieldName">
|
||||
<FormField type="checkbox" :name="item.fieldName">
|
||||
<FormItem
|
||||
class="flex flex-row items-center justify-between rounded-lg border p-4"
|
||||
>
|
||||
<div class="space-y-0.5">
|
||||
<FormLabel class="text-base"> {{ item.label }} </FormLabel>
|
||||
<FormDescription>
|
||||
{{ item.description }}
|
||||
</FormDescription>
|
||||
</div>
|
||||
<FormControl>
|
||||
<Switch
|
||||
:model-value="item.value"
|
||||
@update:model-value="handleChange(item.fieldName, $event)"
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
</FormField>
|
||||
</template>
|
||||
</div>
|
||||
</Form>
|
||||
</template>
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { BasicUserInfo } from '@vben/types';
|
||||
|
||||
export interface Props {
|
||||
title?: string;
|
||||
userInfo: BasicUserInfo | null;
|
||||
tabs: {
|
||||
label: string;
|
||||
value: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface FormSchemaItem {
|
||||
description: string;
|
||||
fieldName: string;
|
||||
label: string;
|
||||
value: boolean;
|
||||
}
|
||||
|
||||
export interface SettingProps {
|
||||
formSchema: FormSchemaItem[];
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vben/hooks",
|
||||
"version": "5.5.9",
|
||||
"version": "5.7.0",
|
||||
"homepage": "https://github.com/vbenjs/vue-vben-admin",
|
||||
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
|
||||
"repository": {
|
||||
@@ -29,5 +29,8 @@
|
||||
"vue": "catalog:",
|
||||
"vue-router": "catalog:",
|
||||
"watermark-js-plus": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "catalog:"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ import type { Arrayable, MaybeElementRef } from '@vueuse/core';
|
||||
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
import { computed, effectScope, onUnmounted, ref, unref, watch } from 'vue';
|
||||
import { computed, effectScope, ref, unref, watch } from 'vue';
|
||||
|
||||
import { isFunction } from '@vben/utils';
|
||||
|
||||
import { useElementHover } from '@vueuse/core';
|
||||
import { tryOnScopeDispose, useElementHover } from '@vueuse/core';
|
||||
|
||||
interface HoverDelayOptions {
|
||||
/** 鼠标进入延迟时间 */
|
||||
@@ -151,7 +151,7 @@ export function useHoverToggle(
|
||||
},
|
||||
};
|
||||
|
||||
onUnmounted(() => {
|
||||
tryOnScopeDispose(() => {
|
||||
clearTimers();
|
||||
// 停止监听器
|
||||
stopWatcher();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
import { computed, ref, unref } from 'vue';
|
||||
import { computed, ref, unref, watch } from 'vue';
|
||||
|
||||
/**
|
||||
* Paginates an array of items
|
||||
@@ -22,7 +22,11 @@ function pagination<T = any>(list: T[], pageNo: number, pageSize: number): T[] {
|
||||
return ret;
|
||||
}
|
||||
|
||||
export function usePagination<T = any>(list: Ref<T[]>, pageSize: number) {
|
||||
export function usePagination<T = any>(
|
||||
list: Ref<T[]>,
|
||||
pageSize: number,
|
||||
totalChangeToFirstPage = true,
|
||||
) {
|
||||
const currentPage = ref(1);
|
||||
const pageSizeRef = ref(pageSize);
|
||||
|
||||
@@ -38,11 +42,21 @@ export function usePagination<T = any>(list: Ref<T[]>, pageSize: number) {
|
||||
return unref(list).length;
|
||||
});
|
||||
|
||||
if (totalChangeToFirstPage) {
|
||||
watch(total, () => {
|
||||
setCurrentPage(1);
|
||||
});
|
||||
}
|
||||
|
||||
function setCurrentPage(page: number) {
|
||||
if (page < 1 || page > unref(totalPages)) {
|
||||
throw new Error('Invalid page number');
|
||||
if (page === 1 && unref(totalPages) === 0) {
|
||||
currentPage.value = 1;
|
||||
} else {
|
||||
if (page < 1 || page > unref(totalPages)) {
|
||||
throw new Error('Invalid page number');
|
||||
}
|
||||
currentPage.value = page;
|
||||
}
|
||||
currentPage.value = page;
|
||||
}
|
||||
|
||||
function setPageSize(pageSize: number) {
|
||||
@@ -54,5 +68,5 @@ export function usePagination<T = any>(list: Ref<T[]>, pageSize: number) {
|
||||
currentPage.value = 1;
|
||||
}
|
||||
|
||||
return { setCurrentPage, total, setPageSize, paginationList };
|
||||
return { setCurrentPage, total, setPageSize, paginationList, currentPage };
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export function useTabs() {
|
||||
}
|
||||
|
||||
async function openTabInNewWindow(tab?: RouteLocationNormalized) {
|
||||
await tabbarStore.openTabInNewWindow(tab || route);
|
||||
await tabbarStore.openTabInNewWindow(tab || route, router);
|
||||
}
|
||||
|
||||
async function closeTabByKey(key: string) {
|
||||
@@ -86,17 +86,6 @@ export function useTabs() {
|
||||
* @param tab
|
||||
*/
|
||||
function getTabDisableState(tab: RouteLocationNormalized = route) {
|
||||
if (!tab || typeof tab.path !== 'string') {
|
||||
return {
|
||||
disabledCloseAll: true,
|
||||
disabledCloseCurrent: true,
|
||||
disabledCloseLeft: true,
|
||||
disabledCloseOther: true,
|
||||
disabledCloseRight: true,
|
||||
disabledRefresh: true,
|
||||
};
|
||||
}
|
||||
|
||||
const tabs = tabbarStore.getTabs;
|
||||
const affixTabs = tabbarStore.affixTabs;
|
||||
const index = tabs.findIndex((item) => item.path === tab.path);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vben/layouts",
|
||||
"version": "5.5.9",
|
||||
"version": "5.7.0",
|
||||
"homepage": "https://github.com/vbenjs/vue-vben-admin",
|
||||
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
|
||||
"repository": {
|
||||
@@ -21,6 +21,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@vben-core/composables": "workspace:*",
|
||||
"@vben-core/design": "workspace:*",
|
||||
"@vben-core/form-ui": "workspace:*",
|
||||
"@vben-core/layout-ui": "workspace:*",
|
||||
"@vben-core/menu-ui": "workspace:*",
|
||||
@@ -39,5 +40,8 @@
|
||||
"@vueuse/core": "catalog:",
|
||||
"vue": "catalog:",
|
||||
"vue-router": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "catalog:"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import type { ToolbarType } from './types';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { preferences, usePreferences } from '@vben/preferences';
|
||||
|
||||
import { Copyright } from '../basic/copyright';
|
||||
@@ -11,6 +13,7 @@ import Toolbar from './toolbar.vue';
|
||||
interface Props {
|
||||
appName?: string;
|
||||
logo?: string;
|
||||
logoDark?: string;
|
||||
pageTitle?: string;
|
||||
pageDescription?: string;
|
||||
sloganImage?: string;
|
||||
@@ -20,10 +23,11 @@ interface Props {
|
||||
clickLogo?: () => void;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
appName: '',
|
||||
copyright: true,
|
||||
logo: '',
|
||||
logoDark: '',
|
||||
pageDescription: '',
|
||||
pageTitle: '',
|
||||
sloganImage: '',
|
||||
@@ -34,12 +38,24 @@ withDefaults(defineProps<Props>(), {
|
||||
|
||||
const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
||||
usePreferences();
|
||||
|
||||
/**
|
||||
* @zh_CN 根据主题选择合适的 logo 图标
|
||||
*/
|
||||
const logoSrc = computed(() => {
|
||||
// 如果是暗色主题且提供了 logoDark,则使用暗色主题的 logo
|
||||
if (isDark.value && props.logoDark) {
|
||||
return props.logoDark;
|
||||
}
|
||||
// 否则使用默认的 logo
|
||||
return props.logo;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
:class="[isDark ? 'dark' : '']"
|
||||
class="flex min-h-full flex-1 select-none overflow-x-hidden"
|
||||
class="flex min-h-full flex-1 overflow-x-hidden select-none"
|
||||
>
|
||||
<template v-if="toolbar">
|
||||
<slot name="toolbar">
|
||||
@@ -50,7 +66,7 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
||||
<AuthenticationFormView
|
||||
v-if="authPanelLeft"
|
||||
class="min-h-full w-2/5 flex-1"
|
||||
transition-name="slide-left"
|
||||
data-side="left"
|
||||
>
|
||||
<template v-if="copyright" #copyright>
|
||||
<slot name="copyright">
|
||||
@@ -65,14 +81,21 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
||||
<slot name="logo">
|
||||
<!-- 头部 Logo 和应用名称 -->
|
||||
<div
|
||||
v-if="logo || appName"
|
||||
class="absolute left-0 top-0 z-10 flex flex-1"
|
||||
v-if="logoSrc || appName"
|
||||
class="absolute top-0 left-0 z-10 flex flex-1"
|
||||
@click="clickLogo"
|
||||
>
|
||||
<div
|
||||
class="text-foreground lg:text-foreground ml-4 mt-4 flex flex-1 items-center sm:left-6 sm:top-6"
|
||||
class="mt-4 ml-4 flex flex-1 items-center text-foreground sm:top-6 sm:left-6 lg:text-foreground"
|
||||
>
|
||||
<img v-if="logo" :alt="appName" :src="logo" class="mr-2" width="42" />
|
||||
<img
|
||||
v-if="logoSrc"
|
||||
:key="logoSrc"
|
||||
:alt="appName"
|
||||
:src="logoSrc"
|
||||
class="mr-2"
|
||||
width="42"
|
||||
/>
|
||||
<p v-if="appName" class="m-0 text-xl font-medium">
|
||||
{{ appName }}
|
||||
</p>
|
||||
@@ -81,24 +104,31 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
||||
</slot>
|
||||
|
||||
<!-- 系统介绍 -->
|
||||
<div v-if="!authPanelCenter" class="relative hidden w-0 flex-1 lg:block">
|
||||
<div v-if="!authPanelCenter" class="relative hidden w-0 flex-1 md:block">
|
||||
<div
|
||||
class="bg-background-deep absolute inset-0 h-full w-full dark:bg-[#070709]"
|
||||
class="absolute inset-0 size-full bg-background-deep dark:bg-[#070709]"
|
||||
>
|
||||
<div class="login-background absolute left-0 top-0 size-full"></div>
|
||||
<div class="flex-col-center -enter-x mr-20 h-full">
|
||||
<div class="login-background absolute top-0 left-0 size-full"></div>
|
||||
<div
|
||||
:key="authPanelLeft ? 'left' : authPanelRight ? 'right' : 'center'"
|
||||
class="mr-20 flex-col-center h-full"
|
||||
:class="{
|
||||
'enter-x': authPanelLeft,
|
||||
'-enter-x': authPanelRight,
|
||||
}"
|
||||
>
|
||||
<template v-if="sloganImage">
|
||||
<img
|
||||
:alt="appName"
|
||||
:src="sloganImage"
|
||||
class="animate-float h-64 w-2/5"
|
||||
class="h-64 w-2/5 animate-float"
|
||||
/>
|
||||
</template>
|
||||
<SloganIcon v-else :alt="appName" class="animate-float h-64 w-2/5" />
|
||||
<div class="text-1xl text-foreground mt-6 font-sans lg:text-2xl">
|
||||
<SloganIcon v-else :alt="appName" class="h-64 w-2/5 animate-float" />
|
||||
<div class="text-1xl mt-6 font-sans text-foreground lg:text-2xl">
|
||||
{{ pageTitle }}
|
||||
</div>
|
||||
<div class="dark:text-muted-foreground mt-2">
|
||||
<div class="mt-2 dark:text-muted-foreground">
|
||||
{{ pageDescription }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -106,10 +136,11 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
||||
</div>
|
||||
|
||||
<!-- 中心认证面板 -->
|
||||
<div v-if="authPanelCenter" class="flex-center relative w-full">
|
||||
<div class="login-background absolute left-0 top-0 size-full"></div>
|
||||
<div v-if="authPanelCenter" class="relative flex-center w-full">
|
||||
<div class="login-background absolute top-0 left-0 size-full"></div>
|
||||
<AuthenticationFormView
|
||||
class="md:bg-background shadow-primary/5 shadow-float w-full rounded-3xl pb-20 md:w-2/3 lg:w-1/2 xl:w-[36%]"
|
||||
class="w-full rounded-3xl pb-20 shadow-float shadow-primary/5 md:w-2/3 md:bg-background lg:w-1/2 xl:w-[36%]"
|
||||
data-side="bottom"
|
||||
>
|
||||
<template v-if="copyright" #copyright>
|
||||
<slot name="copyright">
|
||||
@@ -125,7 +156,8 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
||||
<!-- 右侧认证面板 -->
|
||||
<AuthenticationFormView
|
||||
v-if="authPanelRight"
|
||||
class="min-h-full w-[34%] flex-1"
|
||||
class="min-h-full w-2/5 flex-1"
|
||||
data-side="right"
|
||||
>
|
||||
<template v-if="copyright" #copyright>
|
||||
<slot name="copyright">
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
defineOptions({
|
||||
name: 'AuthenticationFormView',
|
||||
});
|
||||
|
||||
defineProps<{
|
||||
dataSide?: 'bottom' | 'left' | 'right' | 'top';
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="flex-col-center dark:bg-background-deep bg-background relative px-6 py-10 lg:flex-initial lg:px-8"
|
||||
class="relative flex-col-center bg-background px-6 py-10 lg:flex-initial lg:px-8 dark:bg-background-deep"
|
||||
>
|
||||
<slot></slot>
|
||||
<!-- Router View with Transition and KeepAlive -->
|
||||
@@ -16,7 +20,8 @@ defineOptions({
|
||||
<component
|
||||
:is="Component"
|
||||
:key="route.fullPath"
|
||||
class="enter-x mt-6 w-full sm:mx-auto md:max-w-md"
|
||||
class="side-content mt-6 w-full sm:mx-auto md:max-w-md"
|
||||
:data-side="dataSide"
|
||||
/>
|
||||
</KeepAlive>
|
||||
</Transition>
|
||||
@@ -25,7 +30,7 @@ defineOptions({
|
||||
<!-- Footer Copyright -->
|
||||
|
||||
<div
|
||||
class="text-muted-foreground absolute bottom-3 flex text-center text-xs"
|
||||
class="absolute bottom-3 flex text-center text-xs text-muted-foreground"
|
||||
>
|
||||
<slot name="copyright"> </slot>
|
||||
</div>
|
||||
|
||||
@@ -33,9 +33,9 @@ const showTheme = computed(() => props.toolbarList.includes('theme'));
|
||||
<template>
|
||||
<div
|
||||
:class="{
|
||||
'bg-accent rounded-3xl px-3 py-1': toolbarList.length > 1,
|
||||
'rounded-3xl bg-accent px-3 py-1': toolbarList.length > 1,
|
||||
}"
|
||||
class="flex-center absolute right-2 top-4 z-10"
|
||||
class="absolute top-4 right-2 z-10 flex-center"
|
||||
>
|
||||
<!-- Only show on medium and larger screens -->
|
||||
<div class="hidden md:flex">
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VNode } from 'vue';
|
||||
import type {
|
||||
RouteLocationNormalizedLoaded,
|
||||
RouteLocationNormalizedLoadedGeneric,
|
||||
} from 'vue-router';
|
||||
import type { RouteLocationNormalizedLoadedGeneric } from 'vue-router';
|
||||
|
||||
import { computed } from 'vue';
|
||||
import { unref } from 'vue';
|
||||
import { RouterView } from 'vue-router';
|
||||
|
||||
import { preferences, usePreferences } from '@vben/preferences';
|
||||
import { usePreferences } from '@vben/preferences';
|
||||
import { getTabKey, storeToRefs, useTabbarStore } from '@vben/stores';
|
||||
|
||||
import { transformComponent, useLayoutHook } from '../../hooks';
|
||||
import { IFrameRouterView } from '../../iframe';
|
||||
import { RouteCachedPage, RouteCachedView } from '../../route-cached';
|
||||
|
||||
defineOptions({ name: 'LayoutContent' });
|
||||
|
||||
@@ -21,85 +19,27 @@ const { keepAlive } = usePreferences();
|
||||
const { getCachedTabs, getExcludeCachedTabs, renderRouteView } =
|
||||
storeToRefs(tabbarStore);
|
||||
|
||||
/**
|
||||
* 是否使用动画
|
||||
*/
|
||||
const getEnabledTransition = computed(() => {
|
||||
const { transition } = preferences;
|
||||
const transitionName = transition.name;
|
||||
return transitionName && transition.enable;
|
||||
});
|
||||
|
||||
// 页面切换动画
|
||||
function getTransitionName(_route: RouteLocationNormalizedLoaded) {
|
||||
// 如果偏好设置未设置,则不使用动画
|
||||
const { tabbar, transition } = preferences;
|
||||
const transitionName = transition.name;
|
||||
if (!transitionName || !transition.enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 标签页未启用或者未开启缓存,则使用全局配置动画
|
||||
if (!tabbar.enable || !keepAlive) {
|
||||
return transitionName;
|
||||
}
|
||||
|
||||
// 如果页面已经加载过,则不使用动画
|
||||
// if (route.meta.loaded) {
|
||||
// return;
|
||||
// }
|
||||
// 已经打开且已经加载过的页面不使用动画
|
||||
// const inTabs = getCachedTabs.value.includes(route.name as string);
|
||||
|
||||
// return inTabs && route.meta.loaded ? undefined : transitionName;
|
||||
return transitionName;
|
||||
}
|
||||
const { getEnabledTransition, getTransitionName } = useLayoutHook();
|
||||
|
||||
/**
|
||||
* 转换组件,自动添加 name
|
||||
* @param component
|
||||
* 是否显示component
|
||||
* @param route
|
||||
*/
|
||||
function transformComponent(
|
||||
component: VNode,
|
||||
route: RouteLocationNormalizedLoadedGeneric,
|
||||
) {
|
||||
// 组件视图未找到,如果有设置后备视图,则返回后备视图,如果没有,则抛出错误
|
||||
if (!component) {
|
||||
console.error(
|
||||
'Component view not found,please check the route configuration',
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const routeName = route.name as string;
|
||||
// 如果组件没有 name,则直接返回
|
||||
if (!routeName) {
|
||||
return component;
|
||||
}
|
||||
const componentName = (component?.type as any)?.name;
|
||||
|
||||
// 已经设置过 name,则直接返回
|
||||
if (componentName) {
|
||||
return component;
|
||||
}
|
||||
|
||||
// componentName 与 routeName 一致,则直接返回
|
||||
if (componentName === routeName) {
|
||||
return component;
|
||||
}
|
||||
|
||||
// 设置 name
|
||||
component.type ||= {};
|
||||
(component.type as any).name = routeName;
|
||||
|
||||
return component;
|
||||
}
|
||||
const showComponent = (route: RouteLocationNormalizedLoadedGeneric) => {
|
||||
return !route.meta.domCached && unref(renderRouteView);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="relative h-full">
|
||||
<IFrameRouterView />
|
||||
<RouteCachedView />
|
||||
<RouterView v-slot="{ Component, route }">
|
||||
<RouteCachedPage
|
||||
:component="Component"
|
||||
:route="route"
|
||||
v-if="route.meta.domCached"
|
||||
/>
|
||||
<Transition
|
||||
v-if="getEnabledTransition"
|
||||
:name="getTransitionName(route)"
|
||||
@@ -113,14 +53,14 @@ function transformComponent(
|
||||
>
|
||||
<component
|
||||
:is="transformComponent(Component, route)"
|
||||
v-if="renderRouteView"
|
||||
v-if="showComponent(route)"
|
||||
v-show="!route.meta.iframeSrc"
|
||||
:key="getTabKey(route)"
|
||||
/>
|
||||
</KeepAlive>
|
||||
<component
|
||||
:is="Component"
|
||||
v-else-if="renderRouteView"
|
||||
v-else-if="showComponent(route)"
|
||||
:key="getTabKey(route)"
|
||||
/>
|
||||
</Transition>
|
||||
@@ -132,14 +72,14 @@ function transformComponent(
|
||||
>
|
||||
<component
|
||||
:is="transformComponent(Component, route)"
|
||||
v-if="renderRouteView"
|
||||
v-if="showComponent(route)"
|
||||
v-show="!route.meta.iframeSrc"
|
||||
:key="getTabKey(route)"
|
||||
/>
|
||||
</KeepAlive>
|
||||
<component
|
||||
:is="Component"
|
||||
v-else-if="renderRouteView"
|
||||
v-else-if="showComponent(route)"
|
||||
:key="getTabKey(route)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -26,7 +26,7 @@ withDefaults(defineProps<Props>(), {
|
||||
<a
|
||||
v-if="icp"
|
||||
:href="icpLink || 'javascript:void(0)'"
|
||||
class="hover:text-primary-hover mx-1"
|
||||
class="mx-1 hover:text-primary-hover"
|
||||
target="_blank"
|
||||
>
|
||||
{{ icp }}
|
||||
@@ -39,7 +39,7 @@ withDefaults(defineProps<Props>(), {
|
||||
<a
|
||||
v-if="companyName"
|
||||
:href="companySiteLink || 'javascript:void(0)'"
|
||||
class="hover:text-primary-hover mx-1"
|
||||
class="mx-1 hover:text-primary-hover"
|
||||
target="_blank"
|
||||
>
|
||||
{{ companyName }}
|
||||
|
||||
@@ -5,7 +5,7 @@ defineOptions({
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex-center text-muted-foreground relative h-full w-full text-xs">
|
||||
<div class="relative flex-center size-full text-xs text-muted-foreground">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
LanguageToggle,
|
||||
PreferencesButton,
|
||||
ThemeToggle,
|
||||
TimezoneButton,
|
||||
} from '../../widgets';
|
||||
|
||||
interface Props {
|
||||
@@ -32,65 +33,87 @@ withDefaults(defineProps<Props>(), {
|
||||
|
||||
const emit = defineEmits<{ clearPreferencesAndLogout: [] }>();
|
||||
|
||||
const REFERENCE_VALUE = 50;
|
||||
const REFERENCE_VALUE = 100;
|
||||
|
||||
const accessStore = useAccessStore();
|
||||
const { globalSearchShortcutKey, preferencesButtonPosition } = usePreferences();
|
||||
const slots = useSlots();
|
||||
const { refresh } = useRefresh();
|
||||
|
||||
/**
|
||||
* 插槽列表类型
|
||||
*/
|
||||
type SlotItem = { index: number; name: string };
|
||||
|
||||
const rightSlots = computed(() => {
|
||||
const list = [{ index: REFERENCE_VALUE + 100, name: 'user-dropdown' }];
|
||||
const list: Array<SlotItem> = [];
|
||||
// 全局搜索
|
||||
if (preferences.widget.globalSearch) {
|
||||
list.push({
|
||||
index: REFERENCE_VALUE,
|
||||
name: 'global-search',
|
||||
});
|
||||
}
|
||||
|
||||
// 偏好设置快捷功能
|
||||
if (preferencesButtonPosition.value.header) {
|
||||
list.push({
|
||||
index: REFERENCE_VALUE + 10,
|
||||
name: 'preferences',
|
||||
});
|
||||
// 将偏好设置中的子功能分组到同一个按钮位置控制逻辑下
|
||||
if (preferences.widget.themeToggle) {
|
||||
list.push({
|
||||
index: REFERENCE_VALUE + 20,
|
||||
name: 'theme-toggle',
|
||||
});
|
||||
}
|
||||
if (preferences.widget.languageToggle) {
|
||||
list.push({
|
||||
index: REFERENCE_VALUE + 30,
|
||||
name: 'language-toggle',
|
||||
});
|
||||
}
|
||||
if (preferences.widget.timezone) {
|
||||
list.push({
|
||||
index: REFERENCE_VALUE + 40,
|
||||
name: 'timezone',
|
||||
});
|
||||
}
|
||||
}
|
||||
if (preferences.widget.themeToggle) {
|
||||
list.push({
|
||||
index: REFERENCE_VALUE + 20,
|
||||
name: 'theme-toggle',
|
||||
});
|
||||
}
|
||||
if (preferences.widget.languageToggle) {
|
||||
list.push({
|
||||
index: REFERENCE_VALUE + 30,
|
||||
name: 'language-toggle',
|
||||
});
|
||||
}
|
||||
// 全屏
|
||||
if (preferences.widget.fullscreen) {
|
||||
list.push({
|
||||
index: REFERENCE_VALUE + 40,
|
||||
index: REFERENCE_VALUE + 50,
|
||||
name: 'fullscreen',
|
||||
});
|
||||
}
|
||||
// 消息通知
|
||||
if (preferences.widget.notification) {
|
||||
list.push({
|
||||
index: REFERENCE_VALUE + 50,
|
||||
index: REFERENCE_VALUE + 60,
|
||||
name: 'notification',
|
||||
});
|
||||
}
|
||||
|
||||
Object.keys(slots).forEach((key) => {
|
||||
const name = key.split('-');
|
||||
// 适配插槽名称,例如第一个插槽名:header-right-1
|
||||
if (key.startsWith('header-right')) {
|
||||
list.push({ index: Number(name[2]), name: key });
|
||||
// 取第三个占位的数字,若是第三个占位不是数字,则自动分配排序索引
|
||||
const slotIndex = Number(key.split('-')[2]);
|
||||
const index = Number.isNaN(slotIndex) ? nextIndex(list) : slotIndex;
|
||||
list.push({ index, name: key });
|
||||
}
|
||||
});
|
||||
return list.sort((a, b) => a.index - b.index);
|
||||
// 最后追加用户下拉框,若是索引值超过1000时则固定在1000(适配用户按钮不在最后的场景)
|
||||
const userDropdownIndex = Math.min(1000, nextIndex(list));
|
||||
list.push({ index: userDropdownIndex, name: 'user-dropdown' });
|
||||
// 按照索引排序,保证插槽顺序(兼容无 toSorted 的浏览器)
|
||||
return [...list].sort((a, b) => a.index - b.index);
|
||||
});
|
||||
|
||||
const leftSlots = computed(() => {
|
||||
const list: Array<{ index: number; name: string }> = [];
|
||||
|
||||
const list: Array<SlotItem> = [];
|
||||
// 刷新
|
||||
if (preferences.widget.refresh) {
|
||||
list.push({
|
||||
index: 0,
|
||||
@@ -99,14 +122,28 @@ const leftSlots = computed(() => {
|
||||
}
|
||||
|
||||
Object.keys(slots).forEach((key) => {
|
||||
const name = key.split('-');
|
||||
// 适配插槽名称,例如第一个插槽名:header-left-1
|
||||
if (key.startsWith('header-left')) {
|
||||
list.push({ index: Number(name[2]), name: key });
|
||||
// 取第三个占位的数字,若是第三个占位不是数字,则自动分配排序索引
|
||||
const slotIndex = Number(key.split('-')[2]);
|
||||
const index = Number.isNaN(slotIndex) ? nextIndex(list) : slotIndex;
|
||||
list.push({ index, name: key });
|
||||
}
|
||||
});
|
||||
return list.sort((a, b) => a.index - b.index);
|
||||
// 按照索引排序,保证插槽顺序(兼容无 toSorted 的浏览器)
|
||||
return [...list].sort((a, b) => a.index - b.index);
|
||||
});
|
||||
|
||||
/**
|
||||
* 获取列表下一个索引值(用于排序)
|
||||
* @param list 列表
|
||||
*/
|
||||
function nextIndex(list: Array<SlotItem>) {
|
||||
const index =
|
||||
list.length > 0 ? Math.max(...list.map((item) => item.index)) : 0;
|
||||
return index + 1;
|
||||
}
|
||||
|
||||
function clearPreferencesAndLogout() {
|
||||
emit('clearPreferencesAndLogout');
|
||||
}
|
||||
@@ -140,7 +177,7 @@ function clearPreferencesAndLogout() {
|
||||
>
|
||||
<slot name="menu"></slot>
|
||||
</div>
|
||||
<div class="flex h-full min-w-0 flex-shrink-0 items-center">
|
||||
<div class="flex h-full min-w-0 shrink-0 items-center">
|
||||
<template v-for="slot in rightSlots" :key="slot.name">
|
||||
<slot :name="slot.name">
|
||||
<template v-if="slot.name === 'global-search'">
|
||||
@@ -158,7 +195,7 @@ function clearPreferencesAndLogout() {
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="slot.name === 'theme-toggle'">
|
||||
<ThemeToggle class="mr-1 mt-[2px]" />
|
||||
<ThemeToggle class="mt-0.5 mr-1" />
|
||||
</template>
|
||||
<template v-else-if="slot.name === 'language-toggle'">
|
||||
<LanguageToggle class="mr-1" />
|
||||
@@ -166,6 +203,9 @@ function clearPreferencesAndLogout() {
|
||||
<template v-else-if="slot.name === 'fullscreen'">
|
||||
<VbenFullScreen class="mr-1" />
|
||||
</template>
|
||||
<template v-else-if="slot.name === 'timezone'">
|
||||
<TimezoneButton class="mt-0.5 mr-1" />
|
||||
</template>
|
||||
</slot>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
updatePreferences,
|
||||
usePreferences,
|
||||
} from '@vben/preferences';
|
||||
import { useAccessStore } from '@vben/stores';
|
||||
import { useAccessStore, useTabbarStore, useTimezoneStore } from '@vben/stores';
|
||||
import { cloneDeep, mapTree } from '@vben/utils';
|
||||
|
||||
import { VbenAdminLayout } from '@vben-core/layout-ui';
|
||||
@@ -43,6 +43,7 @@ const {
|
||||
isHeaderNav,
|
||||
isMixedNav,
|
||||
isMobile,
|
||||
isSideMode,
|
||||
isSideMixedNav,
|
||||
isHeaderMixedNav,
|
||||
isHeaderSidebarNav,
|
||||
@@ -52,6 +53,7 @@ const {
|
||||
theme,
|
||||
} = usePreferences();
|
||||
const accessStore = useAccessStore();
|
||||
const timezoneStore = useTimezoneStore();
|
||||
const { refresh } = useRefresh();
|
||||
|
||||
const sidebarTheme = computed(() => {
|
||||
@@ -59,6 +61,11 @@ const sidebarTheme = computed(() => {
|
||||
return dark ? 'dark' : 'light';
|
||||
});
|
||||
|
||||
const sidebarThemeSub = computed(() => {
|
||||
const dark = isDark.value || preferences.theme.semiDarkSidebarSub;
|
||||
return dark ? 'dark' : 'light';
|
||||
});
|
||||
|
||||
const headerTheme = computed(() => {
|
||||
const dark = isDark.value || preferences.theme.semiDarkHeader;
|
||||
return dark ? 'dark' : 'light';
|
||||
@@ -102,6 +109,15 @@ const showHeaderNav = computed(() => {
|
||||
);
|
||||
});
|
||||
|
||||
const logoTheme = computed(() => {
|
||||
const showLogoInHeader =
|
||||
!isSideMode.value ||
|
||||
isHeaderSidebarNav.value ||
|
||||
isMixedNav.value ||
|
||||
isMobile.value;
|
||||
return showLogoInHeader ? headerTheme.value : sidebarTheme.value;
|
||||
});
|
||||
|
||||
const {
|
||||
handleMenuSelect,
|
||||
handleMenuOpen,
|
||||
@@ -158,7 +174,9 @@ function clickLogo() {
|
||||
function autoCollapseMenuByRouteMeta(route: RouteLocationNormalizedLoaded) {
|
||||
// 只在双列模式下生效
|
||||
if (
|
||||
preferences.app.layout === 'sidebar-mixed-nav' &&
|
||||
['header-mixed-nav', 'sidebar-mixed-nav'].includes(
|
||||
preferences.app.layout,
|
||||
) &&
|
||||
route.meta &&
|
||||
route.meta.hideInMenu
|
||||
) {
|
||||
@@ -185,9 +203,19 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
const tabbarStore = useTabbarStore();
|
||||
|
||||
function refreshAll() {
|
||||
tabbarStore.cachedTabs.clear();
|
||||
refresh();
|
||||
}
|
||||
|
||||
// 语言更新后,刷新页面
|
||||
// i18n.global.locale会在preference.app.locale变更之后才会更新,因此watchpreference.app.locale是不合适的,刷新页面时可能语言配置尚未完全加载完成
|
||||
watch(i18n.global.locale, refresh, { flush: 'post' });
|
||||
watch(i18n.global.locale, refreshAll, { flush: 'post' });
|
||||
|
||||
// 时区更新后,刷新页面
|
||||
watch(() => timezoneStore.timezone, refreshAll, { flush: 'post' });
|
||||
|
||||
const slots: SetupContext['slots'] = useSlots();
|
||||
const headerSlots = computed(() => {
|
||||
@@ -216,6 +244,7 @@ const headerSlots = computed(() => {
|
||||
:header-visible="preferences.header.enable"
|
||||
:is-mobile="preferences.app.isMobile"
|
||||
:layout="layout"
|
||||
:sidebar-draggable="preferences.sidebar.draggable"
|
||||
:sidebar-collapse="preferences.sidebar.collapsed"
|
||||
:sidebar-collapse-show-title="preferences.sidebar.collapsedShowTitle"
|
||||
:sidebar-enable="sidebarVisible"
|
||||
@@ -227,6 +256,7 @@ const headerSlots = computed(() => {
|
||||
:sidebar-hidden="preferences.sidebar.hidden"
|
||||
:sidebar-mixed-width="preferences.sidebar.mixedWidth"
|
||||
:sidebar-theme="sidebarTheme"
|
||||
:sidebar-theme-sub="sidebarThemeSub"
|
||||
:sidebar-width="preferences.sidebar.width"
|
||||
:side-collapse-width="preferences.sidebar.collapseWidth"
|
||||
:tabbar-enable="preferences.tabbar.enable"
|
||||
@@ -248,6 +278,9 @@ const headerSlots = computed(() => {
|
||||
(value: boolean) =>
|
||||
updatePreferences({ sidebar: { extraCollapse: value } })
|
||||
"
|
||||
@update:sidebar-width="
|
||||
(value: number) => updatePreferences({ sidebar: { width: value } })
|
||||
"
|
||||
>
|
||||
<!-- logo -->
|
||||
<template #logo>
|
||||
@@ -257,8 +290,9 @@ const headerSlots = computed(() => {
|
||||
:class="logoClass"
|
||||
:collapsed="logoCollapsed"
|
||||
:src="preferences.logo.source"
|
||||
:src-dark="preferences.logo.sourceDark"
|
||||
:text="preferences.app.name"
|
||||
:theme="showHeaderNav ? headerTheme : theme"
|
||||
:theme="logoTheme"
|
||||
@click="clickLogo"
|
||||
>
|
||||
<template v-if="$slots['logo-text']" #text>
|
||||
@@ -300,6 +334,9 @@ const headerSlots = computed(() => {
|
||||
<template #notification>
|
||||
<slot name="notification"></slot>
|
||||
</template>
|
||||
<template #timezone>
|
||||
<slot name="timezone"></slot>
|
||||
</template>
|
||||
<template v-for="item in headerSlots" #[item]>
|
||||
<slot :name="item"></slot>
|
||||
</template>
|
||||
@@ -338,7 +375,7 @@ const headerSlots = computed(() => {
|
||||
:collapse="preferences.sidebar.extraCollapse"
|
||||
:menus="wrapperMenus(extraMenus)"
|
||||
:rounded="isMenuRounded"
|
||||
:theme="sidebarTheme"
|
||||
:theme="sidebarThemeSub"
|
||||
/>
|
||||
</template>
|
||||
<template #side-extra-title>
|
||||
@@ -346,7 +383,7 @@ const headerSlots = computed(() => {
|
||||
v-if="preferences.logo.enable"
|
||||
:fit="preferences.logo.fit"
|
||||
:text="preferences.app.name"
|
||||
:theme="theme"
|
||||
:theme="sidebarThemeSub"
|
||||
>
|
||||
<template v-if="$slots['logo-text']" #text>
|
||||
<slot name="logo-text"></slot>
|
||||
@@ -394,7 +431,7 @@ const headerSlots = computed(() => {
|
||||
|
||||
<template v-if="preferencesButtonPosition.fixed">
|
||||
<Preferences
|
||||
class="z-100 fixed bottom-20 right-0"
|
||||
class="fixed top-1/2 right-0 z-100 -translate-y-1/2 transform"
|
||||
@clear-preferences-and-logout="clearPreferencesAndLogout"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -29,7 +29,8 @@ function useNavigation() {
|
||||
return true;
|
||||
}
|
||||
const route = routeMetaMap.get(path);
|
||||
return route?.meta?.openInNewWindow ?? false;
|
||||
// 如果有外链或者设置了在新窗口打开,返回 true
|
||||
return !!(route?.meta?.link || route?.meta?.openInNewWindow);
|
||||
};
|
||||
|
||||
const resolveHref = (path: string): string => {
|
||||
@@ -39,7 +40,13 @@ function useNavigation() {
|
||||
const navigation = async (path: string) => {
|
||||
try {
|
||||
const route = routeMetaMap.get(path);
|
||||
const { openInNewWindow = false, query = {} } = route?.meta ?? {};
|
||||
const { openInNewWindow = false, query = {}, link } = route?.meta ?? {};
|
||||
|
||||
// 检查是否有外链
|
||||
if (link && typeof link === 'string') {
|
||||
openWindow(link, { target: '_blank' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (isHttpUrl(path)) {
|
||||
openWindow(path, { target: '_blank' });
|
||||
|
||||
@@ -6,7 +6,12 @@ import { useContentMaximize, useTabs } from '@vben/hooks';
|
||||
import { preferences } from '@vben/preferences';
|
||||
import { useTabbarStore } from '@vben/stores';
|
||||
|
||||
import { TabsToolMore, TabsToolScreen, TabsView } from '@vben-core/tabs-ui';
|
||||
import {
|
||||
TabsToolMore,
|
||||
TabsToolRefresh,
|
||||
TabsToolScreen,
|
||||
TabsView,
|
||||
} from '@vben-core/tabs-ui';
|
||||
|
||||
import { useTabbar } from './use-tabbar';
|
||||
|
||||
@@ -19,7 +24,7 @@ defineProps<{ showIcon?: boolean; theme?: string }>();
|
||||
const route = useRoute();
|
||||
const tabbarStore = useTabbarStore();
|
||||
const { contentIsMaximize, toggleMaximize } = useContentMaximize();
|
||||
const { unpinTab } = useTabs();
|
||||
const { refreshTab, unpinTab } = useTabs();
|
||||
|
||||
const {
|
||||
createContextMenus,
|
||||
@@ -31,9 +36,6 @@ const {
|
||||
|
||||
const menus = computed(() => {
|
||||
const tab = tabbarStore.getTabByKey(currentActive.value);
|
||||
if (!tab || typeof tab.path !== 'string') {
|
||||
return [];
|
||||
}
|
||||
const menus = createContextMenus(tab);
|
||||
return menus.map((item) => {
|
||||
return {
|
||||
@@ -68,6 +70,10 @@ if (!preferences.tabbar.persist) {
|
||||
/>
|
||||
<div class="flex-center h-full">
|
||||
<TabsToolMore v-if="preferences.tabbar.showMore" :menus="menus" />
|
||||
<TabsToolRefresh
|
||||
v-if="preferences.tabbar.showRefresh"
|
||||
@refresh="refreshTab"
|
||||
/>
|
||||
<TabsToolScreen
|
||||
v-if="preferences.tabbar.showMaximize"
|
||||
:screen="contentIsMaximize"
|
||||
|
||||
@@ -86,36 +86,11 @@ export function useTabbar() {
|
||||
};
|
||||
|
||||
function wrapperTabLocale(tab: RouteLocationNormalizedGeneric) {
|
||||
const title = tab?.meta?.title;
|
||||
const tabTitle = tab?.meta?.tabTitle;
|
||||
let processedTitle = 'Unknown';
|
||||
let processedTabTitle: string | undefined;
|
||||
|
||||
try {
|
||||
if (title && typeof title === 'string' && title.trim()) {
|
||||
processedTitle = $t(title);
|
||||
} else if (tab?.name) {
|
||||
processedTitle = tab.name as string;
|
||||
}
|
||||
if (tabTitle && typeof tabTitle === 'string' && tabTitle.trim()) {
|
||||
processedTabTitle = $t(tabTitle);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('国际化处理失败,使用原始标题:', title, error);
|
||||
processedTitle = title || (tab?.name as string) || 'Unknown';
|
||||
processedTabTitle =
|
||||
tabTitle && typeof tabTitle === 'string' && tabTitle.trim()
|
||||
? tabTitle
|
||||
: undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
...tab,
|
||||
meta: {
|
||||
...tab?.meta,
|
||||
title: processedTitle,
|
||||
// 空则不写入,展示层回退 title
|
||||
...(processedTabTitle ? { tabTitle: processedTabTitle } : { tabTitle: undefined }),
|
||||
title: $t(tab?.meta?.title as string),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -141,10 +116,6 @@ export function useTabbar() {
|
||||
);
|
||||
|
||||
const createContextMenus = (tab: TabDefinition) => {
|
||||
if (!tab || typeof tab.path !== 'string') {
|
||||
return [];
|
||||
}
|
||||
|
||||
const {
|
||||
disabledCloseAll,
|
||||
disabledCloseCurrent,
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import type { VNode } from 'vue';
|
||||
import type {
|
||||
RouteLocationNormalizedLoaded,
|
||||
RouteLocationNormalizedLoadedGeneric,
|
||||
} from 'vue-router';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { preferences, usePreferences } from '@vben/preferences';
|
||||
|
||||
/**
|
||||
* 转换组件,自动添加 name
|
||||
* @param component
|
||||
* @param route
|
||||
*/
|
||||
export function transformComponent(
|
||||
component: VNode,
|
||||
route: RouteLocationNormalizedLoadedGeneric,
|
||||
) {
|
||||
// 组件视图未找到,如果有设置后备视图,则返回后备视图,如果没有,则抛出错误
|
||||
if (!component) {
|
||||
console.error(
|
||||
'Component view not found,please check the route configuration',
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const routeName = route.name as string;
|
||||
// 如果组件没有 name,则直接返回
|
||||
if (!routeName) {
|
||||
return component;
|
||||
}
|
||||
const componentName = (component?.type as any)?.name;
|
||||
|
||||
// 已经设置过 name,则直接返回
|
||||
if (componentName) {
|
||||
return component;
|
||||
}
|
||||
|
||||
// componentName 与 routeName 一致,则直接返回
|
||||
if (componentName === routeName) {
|
||||
return component;
|
||||
}
|
||||
|
||||
// 设置 name
|
||||
component.type ||= {};
|
||||
(component.type as any).name = routeName;
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Layout相关hook
|
||||
*/
|
||||
export function useLayoutHook() {
|
||||
const { keepAlive } = usePreferences();
|
||||
/**
|
||||
* 是否使用动画
|
||||
*/
|
||||
const getEnabledTransition = computed(() => {
|
||||
const { transition } = preferences;
|
||||
const transitionName = transition.name;
|
||||
return transitionName && transition.enable;
|
||||
});
|
||||
|
||||
/**
|
||||
* 获取路由过渡动画
|
||||
* @param _route
|
||||
*/
|
||||
function getTransitionName(_route: RouteLocationNormalizedLoaded) {
|
||||
// 如果偏好设置未设置,则不使用动画
|
||||
const { tabbar, transition } = preferences;
|
||||
const transitionName = transition.name;
|
||||
if (!transitionName || !transition.enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 标签页未启用或者未开启缓存,则使用全局配置动画
|
||||
if (!tabbar.enable || !keepAlive) {
|
||||
return transitionName;
|
||||
}
|
||||
|
||||
// 如果页面已经加载过,则不使用动画
|
||||
// if (route.meta.loaded) {
|
||||
// return;
|
||||
// }
|
||||
// 已经打开且已经加载过的页面不使用动画
|
||||
// const inTabs = getCachedTabs.value.includes(route.name as string);
|
||||
|
||||
// return inTabs && route.meta.loaded ? undefined : transitionName;
|
||||
return transitionName;
|
||||
}
|
||||
|
||||
return {
|
||||
getEnabledTransition,
|
||||
getTransitionName,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { default as RouteCachedPage } from './route-cached-page.vue';
|
||||
export { default as RouteCachedView } from './route-cached-view.vue';
|
||||
@@ -0,0 +1,36 @@
|
||||
<!-- 本组件用于获取缓存的route并保存到pinia -->
|
||||
<script setup lang="ts">
|
||||
import type { VNode } from 'vue';
|
||||
import type { RouteLocationNormalizedLoadedGeneric } from 'vue-router';
|
||||
|
||||
import { watch } from 'vue';
|
||||
|
||||
import { useTabbarStore } from '@vben/stores';
|
||||
|
||||
interface Props {
|
||||
component?: VNode;
|
||||
route: RouteLocationNormalizedLoadedGeneric;
|
||||
}
|
||||
|
||||
/**
|
||||
* 这是页面缓存组件,不做任何的的实际渲染
|
||||
*/
|
||||
defineOptions({
|
||||
render() {
|
||||
return null;
|
||||
},
|
||||
});
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const { addCachedRoute } = useTabbarStore();
|
||||
|
||||
watch(
|
||||
() => props.route,
|
||||
() => {
|
||||
if (props.component && props.route.meta.domCached) {
|
||||
addCachedRoute(props.component, props.route);
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
@@ -0,0 +1,98 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, unref, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import { preferences } from '@vben/preferences';
|
||||
import { getTabKey, storeToRefs, useTabbarStore } from '@vben/stores';
|
||||
|
||||
import { transformComponent, useLayoutHook } from '../hooks';
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
const tabbarStore = useTabbarStore();
|
||||
|
||||
const { getTabs, getCachedRoutes, getExcludeCachedTabs } =
|
||||
storeToRefs(tabbarStore);
|
||||
const { removeCachedRoute } = tabbarStore;
|
||||
|
||||
const { getEnabledTransition, getTransitionName } = useLayoutHook();
|
||||
|
||||
/**
|
||||
* 是否启用tab
|
||||
*/
|
||||
const enableTabbar = computed(() => preferences.tabbar.enable);
|
||||
|
||||
const computedCachedRouteKeys = computed(() => {
|
||||
if (!unref(enableTabbar)) {
|
||||
return [];
|
||||
}
|
||||
return unref(getTabs)
|
||||
.filter((item) => item.meta.domCached)
|
||||
.map((item) => getTabKey(item));
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听缓存路由变化,删除不存在的缓存路由
|
||||
*/
|
||||
watch(computedCachedRouteKeys, (keys) => {
|
||||
unref(getCachedRoutes).forEach((item) => {
|
||||
if (!keys.includes(item.key)) {
|
||||
removeCachedRoute(item.key);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* 所有缓存的route
|
||||
*/
|
||||
const computedCachedRoutes = computed(() => {
|
||||
if (!unref(enableTabbar)) {
|
||||
return [];
|
||||
}
|
||||
// 刷新路由可刷新缓存
|
||||
const excludeCachedTabKeys = unref(getExcludeCachedTabs);
|
||||
return [...unref(getCachedRoutes).values()].filter((item) => {
|
||||
const componentType: any = item.component.type || {};
|
||||
let componentName = componentType.name;
|
||||
if (!componentName) {
|
||||
componentName = item.route.name;
|
||||
}
|
||||
return !excludeCachedTabKeys.includes(componentName);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* 是否显示
|
||||
*/
|
||||
const computedShowView = computed(() => unref(computedCachedRoutes).length > 0);
|
||||
|
||||
const computedCurrentRouteKey = computed(() => {
|
||||
return getTabKey(route);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-if="computedShowView">
|
||||
<template v-for="item in computedCachedRoutes" :key="item.key">
|
||||
<Transition
|
||||
v-if="getEnabledTransition"
|
||||
appear
|
||||
mode="out-in"
|
||||
:name="getTransitionName(item.route)"
|
||||
>
|
||||
<component
|
||||
v-show="item.key === computedCurrentRouteKey"
|
||||
:is="transformComponent(item.component, item.route)"
|
||||
/>
|
||||
</Transition>
|
||||
<template v-else>
|
||||
<component
|
||||
v-show="item.key === computedCurrentRouteKey"
|
||||
:is="transformComponent(item.component, item.route)"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
@@ -31,16 +31,16 @@ function handleUpdate(colorPrimary: string, type: BuiltinThemeType) {
|
||||
>
|
||||
<template v-for="preset in COLOR_PRESETS" :key="preset.color">
|
||||
<VbenIconButton
|
||||
class="flex-center flex-shrink-0"
|
||||
class="flex-center shrink-0"
|
||||
@click="handleUpdate(preset.color, preset.type)"
|
||||
>
|
||||
<div
|
||||
:style="{ backgroundColor: preset.color }"
|
||||
class="flex-center relative size-5 rounded-full hover:scale-110"
|
||||
class="relative flex-center size-5 rounded-full hover:scale-110"
|
||||
>
|
||||
<svg
|
||||
v-if="preferences.theme.builtinType === preset.type"
|
||||
class="h-3.5 w-3.5 text-white"
|
||||
class="size-3.5 text-white"
|
||||
height="1em"
|
||||
viewBox="0 0 15 15"
|
||||
width="1em"
|
||||
@@ -58,7 +58,7 @@ function handleUpdate(colorPrimary: string, type: BuiltinThemeType) {
|
||||
</div>
|
||||
|
||||
<VbenIconButton>
|
||||
<Palette class="text-primary size-4" />
|
||||
<Palette class="size-4 text-primary" />
|
||||
</VbenIconButton>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -53,11 +53,13 @@ function handleClose() {
|
||||
|
||||
const keys = useMagicKeys();
|
||||
const cmd = isWindowsOs() ? keys['ctrl+k'] : keys['cmd+k'];
|
||||
whenever(cmd!, () => {
|
||||
if (props.enableShortcutKey) {
|
||||
modalApi.open();
|
||||
}
|
||||
});
|
||||
if (cmd) {
|
||||
whenever(cmd, () => {
|
||||
if (props.enableShortcutKey) {
|
||||
modalApi.open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
whenever(open, () => {
|
||||
nextTick(() => {
|
||||
@@ -98,17 +100,17 @@ onMounted(() => {
|
||||
<div>
|
||||
<Modal
|
||||
:fullscreen-button="false"
|
||||
class="w-[600px]"
|
||||
class="w-150"
|
||||
header-class="py-2 border-b"
|
||||
>
|
||||
<template #title>
|
||||
<div class="flex items-center">
|
||||
<Search class="text-muted-foreground mr-2 size-4" />
|
||||
<Search class="mr-2 size-4 text-muted-foreground" />
|
||||
<input
|
||||
ref="searchInputRef"
|
||||
v-model="keyword"
|
||||
:placeholder="$t('ui.widgets.search.searchNavigate')"
|
||||
class="ring-none placeholder:text-muted-foreground w-[80%] rounded-md border border-none bg-transparent p-2 pl-0 text-sm font-normal outline-none ring-0 ring-offset-transparent focus-visible:ring-transparent"
|
||||
class="ring-none w-[80%] rounded-md border border-none bg-transparent p-2 pl-0 text-sm font-normal ring-0 ring-offset-transparent outline-hidden placeholder:text-muted-foreground focus-visible:ring-transparent"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -133,20 +135,20 @@ onMounted(() => {
|
||||
</template>
|
||||
</Modal>
|
||||
<div
|
||||
class="md:bg-accent group flex h-8 cursor-pointer items-center gap-3 rounded-2xl border-none bg-none px-2 py-0.5 outline-none"
|
||||
class="group flex h-8 cursor-pointer items-center gap-3 rounded-2xl border-none bg-none px-2 py-0.5 outline-hidden md:bg-accent"
|
||||
@click="toggleOpen()"
|
||||
>
|
||||
<Search
|
||||
class="text-muted-foreground group-hover:text-foreground size-4 group-hover:opacity-100"
|
||||
class="size-4 text-muted-foreground group-hover:text-foreground group-hover:opacity-100"
|
||||
/>
|
||||
<span
|
||||
class="text-muted-foreground group-hover:text-foreground hidden text-xs duration-300 md:block"
|
||||
class="hidden text-xs text-muted-foreground duration-300 group-hover:text-foreground md:block"
|
||||
>
|
||||
{{ $t('ui.widgets.search.title') }}
|
||||
</span>
|
||||
<span
|
||||
v-if="enableShortcutKey"
|
||||
class="bg-background border-foreground/60 text-muted-foreground group-hover:text-foreground relative hidden rounded-sm rounded-r-xl px-1.5 py-1 text-xs leading-none group-hover:opacity-100 md:block"
|
||||
class="relative hidden rounded-sm rounded-r-xl border-foreground/60 bg-background px-1.5 py-1 text-xs leading-none text-muted-foreground group-hover:text-foreground group-hover:opacity-100 md:block"
|
||||
>
|
||||
{{ isWindowsOs() ? 'Ctrl' : '⌘' }}
|
||||
<kbd>K</kbd>
|
||||
|
||||
@@ -11,7 +11,12 @@ import { mapTree, traverseTreeValues, uniqueByField } from '@vben/utils';
|
||||
import { VbenIcon, VbenScrollbar } from '@vben-core/shadcn-ui';
|
||||
import { isHttpUrl } from '@vben-core/shared/utils';
|
||||
|
||||
import { onKeyStroke, useLocalStorage, useThrottleFn } from '@vueuse/core';
|
||||
import {
|
||||
onKeyStroke,
|
||||
useEventListener,
|
||||
useLocalStorage,
|
||||
useThrottleFn,
|
||||
} from '@vueuse/core';
|
||||
|
||||
defineOptions({
|
||||
name: 'SearchPanel',
|
||||
@@ -34,6 +39,7 @@ const searchHistory = useLocalStorage<MenuRecordRaw[]>(
|
||||
const activeIndex = ref(-1);
|
||||
const searchItems = shallowRef<MenuRecordRaw[]>([]);
|
||||
const searchResults = ref<MenuRecordRaw[]>([]);
|
||||
const isNavigating = ref(false);
|
||||
|
||||
const handleSearch = useThrottleFn(search, 200);
|
||||
|
||||
@@ -47,6 +53,8 @@ function search(searchKey: string) {
|
||||
searchResults.value = [];
|
||||
return;
|
||||
}
|
||||
// 将搜索关键词转换为小写,确保大小写不敏感的搜索
|
||||
searchKey = searchKey.toLowerCase();
|
||||
|
||||
// 使用搜索关键词创建正则表达式
|
||||
const reg = createSearchReg(searchKey);
|
||||
@@ -114,6 +122,7 @@ function handleUp() {
|
||||
if (searchResults.value.length === 0) {
|
||||
return;
|
||||
}
|
||||
isNavigating.value = true;
|
||||
activeIndex.value--;
|
||||
if (activeIndex.value < 0) {
|
||||
activeIndex.value = searchResults.value.length - 1;
|
||||
@@ -126,6 +135,7 @@ function handleDown() {
|
||||
if (searchResults.value.length === 0) {
|
||||
return;
|
||||
}
|
||||
isNavigating.value = true;
|
||||
activeIndex.value++;
|
||||
if (activeIndex.value > searchResults.value.length - 1) {
|
||||
activeIndex.value = 0;
|
||||
@@ -141,6 +151,7 @@ function handleClose() {
|
||||
|
||||
// Activate when the mouse moves to a certain line
|
||||
function handleMouseenter(e: MouseEvent) {
|
||||
if (isNavigating.value) return;
|
||||
const index = (e.target as HTMLElement)?.dataset.index;
|
||||
activeIndex.value = Number(index);
|
||||
}
|
||||
@@ -196,7 +207,7 @@ watch(
|
||||
if (val) {
|
||||
handleSearch(val);
|
||||
} else {
|
||||
searchResults.value = [...searchHistory.value];
|
||||
searchResults.value = searchHistory.value;
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -219,20 +230,24 @@ onMounted(() => {
|
||||
// esc close
|
||||
onKeyStroke('Escape', handleClose);
|
||||
});
|
||||
|
||||
useEventListener('mousemove', () => {
|
||||
isNavigating.value = false;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VbenScrollbar>
|
||||
<div class="!flex h-full justify-center px-2 sm:max-h-[450px]">
|
||||
<div class="flex! h-full justify-center px-2 sm:max-h-112.5">
|
||||
<!-- 无搜索结果 -->
|
||||
<div
|
||||
v-if="keyword && searchResults.length === 0"
|
||||
class="text-muted-foreground text-center"
|
||||
class="text-center text-muted-foreground"
|
||||
>
|
||||
<SearchX class="mx-auto mt-4 size-12" />
|
||||
<p class="mb-10 mt-6 text-xs">
|
||||
<p class="mt-6 mb-10 text-xs">
|
||||
{{ $t('ui.widgets.search.noResults') }}
|
||||
<span class="text-foreground text-sm font-medium">
|
||||
<span class="text-sm font-medium text-foreground">
|
||||
"{{ keyword }}"
|
||||
</span>
|
||||
</p>
|
||||
@@ -240,7 +255,7 @@ onMounted(() => {
|
||||
<!-- 历史搜索记录 & 没有搜索结果 -->
|
||||
<div
|
||||
v-if="!keyword && searchResults.length === 0"
|
||||
class="text-muted-foreground text-center"
|
||||
class="text-center text-muted-foreground"
|
||||
>
|
||||
<p class="my-10 text-xs">
|
||||
{{ $t('ui.widgets.search.noRecent') }}
|
||||
@@ -250,7 +265,7 @@ onMounted(() => {
|
||||
<ul v-show="searchResults.length > 0" class="w-full">
|
||||
<li
|
||||
v-if="searchHistory.length > 0 && !keyword"
|
||||
class="text-muted-foreground mb-2 text-xs"
|
||||
class="mb-2 text-xs text-muted-foreground"
|
||||
>
|
||||
{{ $t('ui.widgets.search.recent') }}
|
||||
</li>
|
||||
@@ -264,19 +279,15 @@ onMounted(() => {
|
||||
"
|
||||
:data-index="index"
|
||||
:data-search-item="index"
|
||||
class="bg-accent flex-center group mb-3 w-full cursor-pointer rounded-lg px-4 py-4"
|
||||
class="group mb-3 flex-center w-full cursor-pointer rounded-lg bg-accent p-4"
|
||||
@click="handleEnter"
|
||||
@mouseenter="handleMouseenter"
|
||||
>
|
||||
<VbenIcon
|
||||
:icon="item.icon"
|
||||
class="mr-2 size-5 flex-shrink-0"
|
||||
fallback
|
||||
/>
|
||||
<VbenIcon :icon="item.icon" class="mr-2 size-5 shrink-0" fallback />
|
||||
|
||||
<span class="flex-1">{{ item.name }}</span>
|
||||
<div
|
||||
class="flex-center dark:hover:bg-accent hover:text-primary-foreground rounded-full p-1 hover:scale-110"
|
||||
class="flex-center rounded-full p-1 hover:scale-110 hover:text-primary-foreground dark:hover:bg-accent"
|
||||
@click.stop="removeItem(index)"
|
||||
>
|
||||
<X class="size-4" />
|
||||
|
||||
@@ -8,4 +8,5 @@ export * from './lock-screen';
|
||||
export * from './notification';
|
||||
export * from './preferences';
|
||||
export * from './theme-toggle';
|
||||
export * from './timezone';
|
||||
export * from './user-dropdown';
|
||||
|
||||
@@ -31,8 +31,8 @@ async function handleUpdate(value: string | undefined) {
|
||||
:model-value="preferences.app.locale"
|
||||
@update:model-value="handleUpdate"
|
||||
>
|
||||
<VbenIconButton>
|
||||
<Languages class="text-foreground size-4" />
|
||||
<VbenIconButton class="hover:animate-[shrink_0.3s_ease-in-out]">
|
||||
<Languages class="size-4 text-foreground" />
|
||||
</VbenIconButton>
|
||||
</VbenDropdownRadioMenu>
|
||||
</div>
|
||||
|
||||
@@ -27,29 +27,30 @@ const emit = defineEmits<{
|
||||
submit: [Recordable<any>];
|
||||
}>();
|
||||
|
||||
const [Form, { resetForm, validate, getValues }] = useVbenForm(
|
||||
reactive({
|
||||
commonConfig: {
|
||||
hideLabel: true,
|
||||
hideRequiredMark: true,
|
||||
},
|
||||
schema: computed(() => [
|
||||
{
|
||||
component: 'VbenInputPassword' as const,
|
||||
componentProps: {
|
||||
placeholder: $t('ui.widgets.lockScreen.placeholder'),
|
||||
},
|
||||
fieldName: 'lockScreenPassword',
|
||||
formFieldProps: { validateOnBlur: false },
|
||||
label: $t('authentication.password'),
|
||||
rules: z
|
||||
.string()
|
||||
.min(1, { message: $t('ui.widgets.lockScreen.placeholder') }),
|
||||
const [Form, { resetForm, validate, getValues, getFieldComponentRef }] =
|
||||
useVbenForm(
|
||||
reactive({
|
||||
commonConfig: {
|
||||
hideLabel: true,
|
||||
hideRequiredMark: true,
|
||||
},
|
||||
]),
|
||||
showDefaultActions: false,
|
||||
}),
|
||||
);
|
||||
schema: computed(() => [
|
||||
{
|
||||
component: 'VbenInputPassword' as const,
|
||||
componentProps: {
|
||||
placeholder: $t('ui.widgets.lockScreen.placeholder'),
|
||||
},
|
||||
fieldName: 'lockScreenPassword',
|
||||
formFieldProps: { validateOnBlur: false },
|
||||
label: $t('authentication.password'),
|
||||
rules: z
|
||||
.string()
|
||||
.min(1, { message: $t('ui.widgets.lockScreen.placeholder') }),
|
||||
},
|
||||
]),
|
||||
showDefaultActions: false,
|
||||
}),
|
||||
);
|
||||
|
||||
const [Modal] = useVbenModal({
|
||||
onConfirm() {
|
||||
@@ -60,6 +61,13 @@ const [Modal] = useVbenModal({
|
||||
resetForm();
|
||||
}
|
||||
},
|
||||
onOpened() {
|
||||
requestAnimationFrame(() => {
|
||||
getFieldComponentRef('lockScreenPassword')
|
||||
?.$el?.querySelector('[name="lockScreenPassword"]')
|
||||
?.focus();
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
@@ -88,7 +96,7 @@ async function handleSubmit() {
|
||||
class="size-20"
|
||||
dot-class="bottom-0 right-1 border-2 size-4 bg-green-500"
|
||||
/>
|
||||
<div class="text-foreground my-6 flex items-center font-medium">
|
||||
<div class="my-6 flex items-center font-medium text-foreground">
|
||||
{{ text }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -37,7 +37,7 @@ const date = useDateFormat(now, 'YYYY-MM-DD dddd', { locales: locale.value });
|
||||
const showUnlockForm = ref(false);
|
||||
const { lockScreenPassword } = storeToRefs(accessStore);
|
||||
|
||||
const [Form, { form, validate }] = useVbenForm(
|
||||
const [Form, { form, validate, getFieldComponentRef }] = useVbenForm(
|
||||
reactive({
|
||||
commonConfig: {
|
||||
hideLabel: true,
|
||||
@@ -75,17 +75,24 @@ async function handleSubmit() {
|
||||
|
||||
function toggleUnlockForm() {
|
||||
showUnlockForm.value = !showUnlockForm.value;
|
||||
if (showUnlockForm.value) {
|
||||
requestAnimationFrame(() => {
|
||||
getFieldComponentRef('password')
|
||||
?.$el?.querySelector('[name="password"]')
|
||||
?.focus();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
useScrollLock();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="bg-background fixed z-[2000] size-full">
|
||||
<div class="fixed z-2000 size-full bg-background">
|
||||
<transition name="slide-left">
|
||||
<div v-show="!showUnlockForm" class="size-full">
|
||||
<div
|
||||
class="flex-col-center text-foreground/80 hover:text-foreground group fixed left-1/2 top-6 z-[2001] -translate-x-1/2 cursor-pointer text-xl font-semibold"
|
||||
class="group fixed top-6 left-1/2 z-2001 flex-col-center -translate-x-1/2 cursor-pointer text-xl font-semibold text-foreground/80 hover:text-foreground"
|
||||
@click="toggleUnlockForm"
|
||||
>
|
||||
<LockKeyhole
|
||||
@@ -93,20 +100,20 @@ useScrollLock();
|
||||
/>
|
||||
<span>{{ $t('ui.widgets.lockScreen.unlock') }}</span>
|
||||
</div>
|
||||
<div class="flex h-full w-full items-center justify-center">
|
||||
<div class="flex-center size-full">
|
||||
<div class="flex w-full justify-center gap-4 px-4 sm:gap-6 md:gap-8">
|
||||
<div
|
||||
class="bg-accent relative flex h-[140px] w-[140px] items-center justify-center rounded-xl text-[36px] sm:h-[160px] sm:w-[160px] sm:text-[42px] md:h-[200px] md:w-[200px] md:text-[72px]"
|
||||
class="relative flex-center h-35 w-35 rounded-xl bg-accent text-[36px] sm:h-40 sm:w-40 sm:text-[42px] md:h-50 md:w-50 md:text-[72px]"
|
||||
>
|
||||
<span
|
||||
class="absolute left-3 top-3 text-xs font-semibold sm:text-sm md:text-xl"
|
||||
class="absolute top-3 left-3 text-xs font-semibold sm:text-sm md:text-xl"
|
||||
>
|
||||
{{ meridiem }}
|
||||
</span>
|
||||
{{ hour }}
|
||||
</div>
|
||||
<div
|
||||
class="bg-accent flex h-[140px] w-[140px] items-center justify-center rounded-xl text-[36px] sm:h-[160px] sm:w-[160px] sm:text-[42px] md:h-[200px] md:w-[200px] md:text-[72px]"
|
||||
class="flex-center h-35 w-35 rounded-xl bg-accent text-[36px] sm:h-40 sm:w-40 sm:text-[42px] md:h-50 md:w-50 md:text-[72px]"
|
||||
>
|
||||
{{ minute }}
|
||||
</div>
|
||||
@@ -121,7 +128,7 @@ useScrollLock();
|
||||
class="flex-center size-full"
|
||||
@keydown.enter.prevent="handleSubmit"
|
||||
>
|
||||
<div class="flex-col-center mb-10 w-[90%] max-w-[300px] px-4">
|
||||
<div class="mb-10 flex-col-center w-[90%] max-w-75 px-4">
|
||||
<VbenAvatar :src="avatar" class="enter-x mb-6 size-20" />
|
||||
<div class="enter-x mb-2 w-full items-center">
|
||||
<Form />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { NotificationItem } from './types';
|
||||
|
||||
import { Bell, MailCheck } from '@vben/icons';
|
||||
import { Bell, CircleCheckBig, CircleX, MailCheck } from '@vben/icons';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import {
|
||||
@@ -13,65 +13,57 @@ import {
|
||||
|
||||
import { useToggle } from '@vueuse/core';
|
||||
|
||||
interface Props {
|
||||
/**
|
||||
* 显示圆点
|
||||
*/
|
||||
dot?: boolean;
|
||||
/**
|
||||
* 消息列表
|
||||
*/
|
||||
notifications?: NotificationItem[];
|
||||
}
|
||||
|
||||
defineOptions({ name: 'NotificationPopup' });
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
dot: false,
|
||||
notifications: () => [],
|
||||
});
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
/** 显示圆点 */
|
||||
dot?: boolean;
|
||||
/** 消息列表 */
|
||||
notifications?: NotificationItem[];
|
||||
}>(),
|
||||
{
|
||||
dot: false,
|
||||
notifications: () => [],
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
clear: [];
|
||||
makeAll: [];
|
||||
onClick: [NotificationItem];
|
||||
read: [NotificationItem];
|
||||
remove: [NotificationItem];
|
||||
viewAll: [];
|
||||
}>();
|
||||
|
||||
const [open, toggle] = useToggle();
|
||||
|
||||
function close() {
|
||||
const close = () => {
|
||||
open.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
function handleViewAll() {
|
||||
const handleViewAll = () => {
|
||||
emit('viewAll');
|
||||
close();
|
||||
}
|
||||
};
|
||||
|
||||
function handleMakeAll() {
|
||||
const handleMakeAll = () => {
|
||||
emit('makeAll');
|
||||
}
|
||||
};
|
||||
|
||||
function handleClear() {
|
||||
const handleClear = () => {
|
||||
emit('clear');
|
||||
}
|
||||
|
||||
function handleClick(item: NotificationItem) {
|
||||
emit('read', item);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<template>
|
||||
<VbenPopover
|
||||
v-model:open="open"
|
||||
content-class="relative right-2 w-[360px] p-0"
|
||||
>
|
||||
<VbenPopover v-model:open="open" content-class="relative right-2 w-90 p-0">
|
||||
<template #trigger>
|
||||
<div class="flex-center mr-2 h-full" @click.stop="toggle()">
|
||||
<VbenIconButton class="bell-button text-foreground relative">
|
||||
<div class="mr-2 flex-center h-full" @click.stop="toggle()">
|
||||
<VbenIconButton class="bell-button relative text-foreground">
|
||||
<span
|
||||
v-if="dot"
|
||||
class="bg-primary absolute right-0.5 top-0.5 h-2 w-2 rounded"
|
||||
class="absolute top-0.5 right-0.5 size-2 rounded-sm bg-primary"
|
||||
></span>
|
||||
<Bell class="size-4" />
|
||||
</VbenIconButton>
|
||||
@@ -90,48 +82,77 @@ function handleClick(item: NotificationItem) {
|
||||
</VbenIconButton>
|
||||
</div>
|
||||
<VbenScrollbar v-if="notifications.length > 0">
|
||||
<ul class="!flex max-h-[360px] w-full flex-col">
|
||||
<template v-for="item in notifications" :key="item.title">
|
||||
<ul class="flex! max-h-90 w-full flex-col">
|
||||
<template v-for="item in notifications" :key="item.id ?? item.title">
|
||||
<li
|
||||
class="hover:bg-accent border-border relative flex w-full cursor-pointer items-start gap-5 border-t px-3 py-3"
|
||||
@click="handleClick(item)"
|
||||
class="relative flex w-full cursor-pointer items-start gap-5 border-t border-border p-3 hover:bg-accent"
|
||||
@click="emit('onClick', item)"
|
||||
>
|
||||
<span
|
||||
v-if="!item.isRead"
|
||||
class="bg-primary absolute right-2 top-2 h-2 w-2 rounded"
|
||||
></span>
|
||||
<slot name="content" :item="item">
|
||||
<span
|
||||
v-if="!item.isRead"
|
||||
class="absolute top-2 right-2 size-2 rounded-sm bg-primary"
|
||||
></span>
|
||||
|
||||
<span
|
||||
class="relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full"
|
||||
>
|
||||
<img
|
||||
:src="item.avatar"
|
||||
class="aspect-square h-full w-full object-cover"
|
||||
role="img"
|
||||
/>
|
||||
</span>
|
||||
<div class="flex flex-col gap-1 leading-none">
|
||||
<p class="font-semibold">{{ item.title }}</p>
|
||||
<p class="text-muted-foreground my-1 line-clamp-2 text-xs">
|
||||
{{ item.message }}
|
||||
</p>
|
||||
<p class="text-muted-foreground line-clamp-2 text-xs">
|
||||
{{ item.date }}
|
||||
</p>
|
||||
</div>
|
||||
<span
|
||||
class="relative flex size-10 shrink-0 overflow-hidden rounded-full"
|
||||
>
|
||||
<img
|
||||
:src="item.avatar"
|
||||
class="aspect-square size-full object-cover"
|
||||
/>
|
||||
</span>
|
||||
<div class="flex flex-col gap-1 leading-none">
|
||||
<p class="font-semibold">{{ item.title }}</p>
|
||||
<p class="my-1 line-clamp-2 text-xs text-muted-foreground">
|
||||
{{ item.message }}
|
||||
</p>
|
||||
<p class="line-clamp-2 text-xs text-muted-foreground">
|
||||
{{ item.date }}
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
class="absolute top-1/2 right-3 flex -translate-y-1/2 flex-row gap-1"
|
||||
>
|
||||
<slot name="action" :item="item">
|
||||
<slot name="action-prepend" :item="item"></slot>
|
||||
<VbenIconButton
|
||||
v-if="!item.isRead"
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
class="h-6 px-2"
|
||||
:tooltip="$t('common.confirm')"
|
||||
@click.stop="emit('read', item)"
|
||||
>
|
||||
<CircleCheckBig class="size-4" />
|
||||
</VbenIconButton>
|
||||
<VbenIconButton
|
||||
v-if="item.isRead"
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
class="h-6 px-2 text-destructive"
|
||||
:tooltip="$t('common.delete')"
|
||||
@click.stop="emit('remove', item)"
|
||||
>
|
||||
<CircleX class="size-4" />
|
||||
</VbenIconButton>
|
||||
<slot name="action-append" :item="item"></slot>
|
||||
</slot>
|
||||
</div>
|
||||
</slot>
|
||||
</li>
|
||||
</template>
|
||||
</ul>
|
||||
</VbenScrollbar>
|
||||
|
||||
<template v-else>
|
||||
<div class="flex-center text-muted-foreground min-h-[150px] w-full">
|
||||
<div class="flex-center min-h-37.5 w-full text-muted-foreground">
|
||||
{{ $t('common.noData') }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div
|
||||
class="border-border flex items-center justify-between border-t px-4 py-3"
|
||||
class="flex items-center justify-between border-t border-border px-4 py-3"
|
||||
>
|
||||
<VbenButton
|
||||
:disabled="notifications.length <= 0"
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
interface NotificationItem {
|
||||
id: number | string;
|
||||
avatar: string;
|
||||
date: string;
|
||||
isRead?: boolean;
|
||||
message: string;
|
||||
title: string;
|
||||
/**
|
||||
* 跳转链接,可以是路由路径或完整 URL
|
||||
* @example '/dashboard' 或 'https://example.com'
|
||||
*/
|
||||
link?: string;
|
||||
query?: Record<string, any>;
|
||||
state?: Record<string, any>;
|
||||
/** 业务字段 */
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export type { NotificationItem };
|
||||
|
||||
@@ -14,7 +14,7 @@ withDefaults(defineProps<Props>(), {
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col py-4">
|
||||
<h3 class="mb-3 font-semibold leading-none tracking-tight">
|
||||
<h3 class="mb-3 leading-none font-semibold tracking-tight">
|
||||
{{ title }}
|
||||
</h3>
|
||||
<slot></slot>
|
||||
|
||||
@@ -53,7 +53,7 @@ const slots = useSlots();
|
||||
</span>
|
||||
<VbenCheckButtonGroup
|
||||
v-model="inputValue"
|
||||
class="h-8 w-[165px]"
|
||||
class="h-8 w-41.25"
|
||||
:options="items"
|
||||
:disabled="disabled"
|
||||
:multiple="multiple"
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
<script setup lang="ts">
|
||||
import type {
|
||||
CustomPreferencesField,
|
||||
CustomPreferencesRecord,
|
||||
} from '@vben/preferences';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import InputItem from '../input-item.vue';
|
||||
import NumberFieldItem from '../number-field-item.vue';
|
||||
import SelectItem from '../select-item.vue';
|
||||
import SwitchItem from '../switch-item.vue';
|
||||
|
||||
defineOptions({
|
||||
name: 'PreferenceCustomFields',
|
||||
});
|
||||
|
||||
const props = defineProps<{
|
||||
fields: Array<CustomPreferencesField>;
|
||||
values: CustomPreferencesRecord;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
update: [updates: CustomPreferencesRecord];
|
||||
}>();
|
||||
|
||||
function handleUpdate(key: string, value: boolean | number | string) {
|
||||
emit('update', { [key]: value });
|
||||
}
|
||||
|
||||
function handleBooleanUpdate(key: string, value: boolean | undefined) {
|
||||
handleUpdate(key, value ?? false);
|
||||
}
|
||||
|
||||
function resolveNumberValue(value: unknown) {
|
||||
return typeof value === 'number' && Number.isFinite(value)
|
||||
? value
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function handleNumberUpdate(key: string, value: number | undefined) {
|
||||
const resolvedValue = resolveNumberValue(value);
|
||||
|
||||
if (resolvedValue !== undefined) {
|
||||
handleUpdate(key, resolvedValue);
|
||||
}
|
||||
}
|
||||
|
||||
function handleStringUpdate(key: string, value: string | undefined) {
|
||||
handleUpdate(key, value ?? '');
|
||||
}
|
||||
|
||||
const resolvedFields = computed(() => {
|
||||
return props.fields.map((field) => {
|
||||
return {
|
||||
...field,
|
||||
label: $t(field.label),
|
||||
options:
|
||||
field.component === 'select'
|
||||
? field.options.map((option) => ({
|
||||
...option,
|
||||
label: $t(option.label),
|
||||
}))
|
||||
: undefined,
|
||||
placeholder: field.placeholder ? $t(field.placeholder) : '',
|
||||
tip: field.tip ? $t(field.tip) : '',
|
||||
};
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-for="field in resolvedFields" :key="field.key">
|
||||
<SwitchItem
|
||||
v-if="field.component === 'switch'"
|
||||
:disabled="field.disabled"
|
||||
:model-value="Boolean(values[field.key])"
|
||||
:tip="field.tip"
|
||||
v-bind="field.componentProps"
|
||||
@update:model-value="handleBooleanUpdate(field.key, $event)"
|
||||
>
|
||||
{{ field.label }}
|
||||
</SwitchItem>
|
||||
<NumberFieldItem
|
||||
v-else-if="field.component === 'number'"
|
||||
:disabled="field.disabled"
|
||||
:model-value="resolveNumberValue(values[field.key])"
|
||||
:placeholder="field.placeholder"
|
||||
:tip="field.tip"
|
||||
v-bind="field.componentProps"
|
||||
@update:model-value="handleNumberUpdate(field.key, $event)"
|
||||
>
|
||||
{{ field.label }}
|
||||
</NumberFieldItem>
|
||||
<SelectItem
|
||||
v-else-if="field.component === 'select'"
|
||||
:disabled="field.disabled"
|
||||
:items="field.options"
|
||||
:model-value="String(values[field.key] ?? '')"
|
||||
:placeholder="field.placeholder"
|
||||
:tip="field.tip"
|
||||
v-bind="field.componentProps"
|
||||
@update:model-value="handleStringUpdate(field.key, $event)"
|
||||
>
|
||||
{{ field.label }}
|
||||
</SelectItem>
|
||||
<InputItem
|
||||
v-else
|
||||
:disabled="field.disabled"
|
||||
:model-value="String(values[field.key] ?? '')"
|
||||
:placeholder="field.placeholder"
|
||||
:tip="field.tip"
|
||||
v-bind="field.componentProps"
|
||||
@update:model-value="handleStringUpdate(field.key, $event)"
|
||||
>
|
||||
{{ field.label }}
|
||||
</InputItem>
|
||||
</template>
|
||||
</template>
|
||||
+2
-2
@@ -34,7 +34,7 @@ function handleClick(value: string) {
|
||||
</SwitchItem>
|
||||
<div
|
||||
v-if="transitionEnable"
|
||||
class="mb-2 mt-3 flex justify-between gap-3 px-2"
|
||||
class="mt-3 mb-2 flex justify-between gap-3 px-2"
|
||||
>
|
||||
<div
|
||||
v-for="item in transitionPreset"
|
||||
@@ -45,7 +45,7 @@ function handleClick(value: string) {
|
||||
class="outline-box p-2"
|
||||
@click="handleClick(item)"
|
||||
>
|
||||
<div :class="`${item}-slow`" class="bg-accent h-10 w-12 rounded-md"></div>
|
||||
<div :class="`${item}-slow`" class="h-10 w-12 rounded-md bg-accent"></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+47
-1
@@ -1,7 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, unref } from 'vue';
|
||||
|
||||
import { SUPPORT_LANGUAGES } from '@vben/constants';
|
||||
import { $t } from '@vben/locales';
|
||||
import { useTimezoneStore } from '@vben/stores';
|
||||
|
||||
import InputItem from '../input-item.vue';
|
||||
import SelectItem from '../select-item.vue';
|
||||
import SwitchItem from '../switch-item.vue';
|
||||
|
||||
@@ -10,22 +14,64 @@ defineOptions({
|
||||
});
|
||||
|
||||
const appLocale = defineModel<string>('appLocale');
|
||||
const appTimezone = defineModel<string>('appTimezone');
|
||||
const appDynamicTitle = defineModel<boolean>('appDynamicTitle');
|
||||
const appWatermark = defineModel<boolean>('appWatermark');
|
||||
const appWatermarkContent = defineModel<string>('appWatermarkContent');
|
||||
const appEnableCheckUpdates = defineModel<boolean>('appEnableCheckUpdates');
|
||||
const appEnableCopyPreferences = defineModel<boolean>(
|
||||
'appEnableCopyPreferences',
|
||||
);
|
||||
const timezoneStore = useTimezoneStore();
|
||||
|
||||
const timezoneOptionsRef = ref<
|
||||
{
|
||||
label: string;
|
||||
value: string;
|
||||
}[]
|
||||
>([]);
|
||||
|
||||
onMounted(async () => {
|
||||
timezoneOptionsRef.value = await timezoneStore.getTimezoneOptions();
|
||||
// 获取当前时区,例如:Asia/Shanghai
|
||||
const timezoneValue = unref(timezoneStore.timezone);
|
||||
if (timezoneValue) {
|
||||
appTimezone.value = timezoneValue;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<SelectItem v-model="appLocale" :items="SUPPORT_LANGUAGES">
|
||||
{{ $t('preferences.language') }}
|
||||
</SelectItem>
|
||||
<SelectItem v-model="appTimezone" :items="timezoneOptionsRef">
|
||||
{{ $t('preferences.timezone') }}
|
||||
</SelectItem>
|
||||
<SwitchItem v-model="appDynamicTitle">
|
||||
{{ $t('preferences.dynamicTitle') }}
|
||||
</SwitchItem>
|
||||
<SwitchItem v-model="appWatermark">
|
||||
<SwitchItem
|
||||
v-model="appWatermark"
|
||||
@update:model-value="
|
||||
(val) => {
|
||||
if (!val) appWatermarkContent = '';
|
||||
}
|
||||
"
|
||||
>
|
||||
{{ $t('preferences.watermark') }}
|
||||
</SwitchItem>
|
||||
<InputItem
|
||||
v-if="appWatermark"
|
||||
v-model="appWatermarkContent"
|
||||
:placeholder="$t('preferences.watermarkContent')"
|
||||
>
|
||||
{{ $t('preferences.watermarkContent') }}
|
||||
</InputItem>
|
||||
<SwitchItem v-model="appEnableCheckUpdates">
|
||||
{{ $t('preferences.checkUpdates') }}
|
||||
</SwitchItem>
|
||||
<SwitchItem v-model="appEnableCopyPreferences">
|
||||
{{ $t('preferences.enableCopyPreferences') }}
|
||||
</SwitchItem>
|
||||
</template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export { default as Block } from './block.vue';
|
||||
export { default as Custom } from './custom/custom.vue';
|
||||
export { default as Animation } from './general/animation.vue';
|
||||
export { default as General } from './general/general.vue';
|
||||
export { default as Breadcrumb } from './layout/breadcrumb.vue';
|
||||
@@ -15,5 +16,6 @@ export { default as GlobalShortcutKeys } from './shortcut-keys/global.vue';
|
||||
export { default as SwitchItem } from './switch-item.vue';
|
||||
export { default as BuiltinTheme } from './theme/builtin.vue';
|
||||
export { default as ColorMode } from './theme/color-mode.vue';
|
||||
export { default as FontSize } from './theme/font-size.vue';
|
||||
export { default as Radius } from './theme/radius.vue';
|
||||
export { default as Theme } from './theme/theme.vue';
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { SelectOption } from '@vben/types';
|
||||
|
||||
import { useSlots } from 'vue';
|
||||
|
||||
import { CircleHelp } from '@vben/icons';
|
||||
import { CircleHelp, CircleX } from '@vben/icons';
|
||||
|
||||
import { Input, VbenTooltip } from '@vben-core/shadcn-ui';
|
||||
|
||||
@@ -16,10 +16,12 @@ withDefaults(
|
||||
disabled?: boolean;
|
||||
items?: SelectOption[];
|
||||
placeholder?: string;
|
||||
tip?: string;
|
||||
}>(),
|
||||
{
|
||||
disabled: false,
|
||||
placeholder: '',
|
||||
tip: '',
|
||||
items: () => [],
|
||||
},
|
||||
);
|
||||
@@ -32,7 +34,7 @@ const slots = useSlots();
|
||||
<template>
|
||||
<div
|
||||
:class="{
|
||||
'hover:bg-accent': !slots.tip,
|
||||
'hover:bg-accent': !(slots.tip || tip),
|
||||
'pointer-events-none opacity-50': disabled,
|
||||
}"
|
||||
class="my-1 flex w-full items-center justify-between rounded-md px-2 py-1"
|
||||
@@ -40,13 +42,30 @@ const slots = useSlots();
|
||||
<span class="flex items-center text-sm">
|
||||
<slot></slot>
|
||||
|
||||
<VbenTooltip v-if="slots.tip" side="bottom">
|
||||
<VbenTooltip v-if="slots.tip || tip" side="bottom">
|
||||
<template #trigger>
|
||||
<CircleHelp class="ml-1 size-3 cursor-help" />
|
||||
</template>
|
||||
<slot name="tip"></slot>
|
||||
<slot name="tip">
|
||||
<template v-if="tip">
|
||||
<p v-for="(line, index) in tip.split('\n')" :key="index">
|
||||
{{ line }}
|
||||
</p>
|
||||
</template>
|
||||
</slot>
|
||||
</VbenTooltip>
|
||||
</span>
|
||||
<Input v-model="inputValue" class="h-8 w-[165px]" />
|
||||
<div class="relative">
|
||||
<Input
|
||||
v-model="inputValue"
|
||||
class="h-8 w-41.25"
|
||||
:placeholder="placeholder"
|
||||
/>
|
||||
<CircleX
|
||||
v-if="inputValue"
|
||||
class="absolute top-1/2 right-2 size-3 -translate-y-1/2 transform cursor-pointer text-foreground/60 hover:text-foreground"
|
||||
@click="() => (inputValue = '')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -38,13 +38,13 @@ function activeClass(theme: string): string[] {
|
||||
<div class="flex w-full gap-5">
|
||||
<template v-for="theme in PRESET" :key="theme.name">
|
||||
<div
|
||||
class="flex w-[100px] cursor-pointer flex-col"
|
||||
class="flex w-25 cursor-pointer flex-col"
|
||||
@click="modelValue = theme.type"
|
||||
>
|
||||
<div :class="activeClass(theme.type)" class="outline-box flex-center">
|
||||
<component :is="components[theme.type]" />
|
||||
</div>
|
||||
<div class="text-muted-foreground mt-2 text-center text-xs">
|
||||
<div class="mt-2 text-center text-xs text-muted-foreground">
|
||||
{{ theme.name }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -89,14 +89,14 @@ function activeClass(theme: string): string[] {
|
||||
<div class="flex w-full flex-wrap gap-5">
|
||||
<template v-for="theme in PRESET" :key="theme.name">
|
||||
<div
|
||||
class="flex w-[100px] cursor-pointer flex-col"
|
||||
class="flex w-25 cursor-pointer flex-col"
|
||||
@click="modelValue = theme.type"
|
||||
>
|
||||
<div :class="activeClass(theme.type)" class="outline-box flex-center">
|
||||
<component :is="components[theme.type]" />
|
||||
</div>
|
||||
<div
|
||||
class="text-muted-foreground flex-center hover:text-foreground mt-2 text-center text-xs"
|
||||
class="mt-2 flex-center text-center text-xs text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{{ theme.name }}
|
||||
<VbenTooltip v-if="theme.tip" side="bottom">
|
||||
|
||||
@@ -19,6 +19,7 @@ const sidebarCollapsedShowTitle = defineModel<boolean>(
|
||||
const sidebarAutoActivateChild = defineModel<boolean>(
|
||||
'sidebarAutoActivateChild',
|
||||
);
|
||||
const sidebarDraggable = defineModel<boolean>('sidebarDraggable');
|
||||
const sidebarCollapsed = defineModel<boolean>('sidebarCollapsed');
|
||||
const sidebarExpandOnHover = defineModel<boolean>('sidebarExpandOnHover');
|
||||
|
||||
@@ -48,6 +49,9 @@ const handleCheckboxChange = () => {
|
||||
<SwitchItem v-model="sidebarEnable" :disabled="disabled">
|
||||
{{ $t('preferences.sidebar.visible') }}
|
||||
</SwitchItem>
|
||||
<SwitchItem v-model="sidebarDraggable" :disabled="!sidebarEnable || disabled">
|
||||
{{ $t('preferences.sidebar.draggable') }}
|
||||
</SwitchItem>
|
||||
<SwitchItem v-model="sidebarCollapsed" :disabled="!sidebarEnable || disabled">
|
||||
{{ $t('preferences.sidebar.collapsed') }}
|
||||
</SwitchItem>
|
||||
|
||||
@@ -18,6 +18,7 @@ defineProps<{ disabled?: boolean }>();
|
||||
const tabbarEnable = defineModel<boolean>('tabbarEnable');
|
||||
const tabbarShowIcon = defineModel<boolean>('tabbarShowIcon');
|
||||
const tabbarPersist = defineModel<boolean>('tabbarPersist');
|
||||
const tabbarVisitHistory = defineModel<boolean>('tabbarVisitHistory');
|
||||
const tabbarDraggable = defineModel<boolean>('tabbarDraggable');
|
||||
const tabbarWheelable = defineModel<boolean>('tabbarWheelable');
|
||||
const tabbarStyleType = defineModel<string>('tabbarStyleType');
|
||||
@@ -56,6 +57,13 @@ const styleItems = computed((): SelectOption[] => [
|
||||
<SwitchItem v-model="tabbarPersist" :disabled="!tabbarEnable">
|
||||
{{ $t('preferences.tabbar.persist') }}
|
||||
</SwitchItem>
|
||||
<SwitchItem
|
||||
v-model="tabbarVisitHistory"
|
||||
:disabled="!tabbarEnable"
|
||||
:tip="$t('preferences.tabbar.visitHistoryTip')"
|
||||
>
|
||||
{{ $t('preferences.tabbar.visitHistory') }}
|
||||
</SwitchItem>
|
||||
<NumberFieldItem
|
||||
v-model="tabbarMaxCount"
|
||||
:disabled="!tabbarEnable"
|
||||
|
||||
@@ -23,6 +23,7 @@ const appPreferencesButtonPosition = defineModel<string>(
|
||||
'appPreferencesButtonPosition',
|
||||
);
|
||||
const widgetRefresh = defineModel<boolean>('widgetRefresh');
|
||||
const widgetTimezone = defineModel<boolean>('widgetTimezone');
|
||||
|
||||
const positionItems = computed((): SelectOption[] => [
|
||||
{
|
||||
@@ -37,6 +38,10 @@ const positionItems = computed((): SelectOption[] => [
|
||||
label: $t('preferences.position.fixed'),
|
||||
value: 'fixed',
|
||||
},
|
||||
{
|
||||
label: $t('preferences.position.userDropdown'),
|
||||
value: 'user-dropdown',
|
||||
},
|
||||
]);
|
||||
</script>
|
||||
|
||||
@@ -65,6 +70,9 @@ const positionItems = computed((): SelectOption[] => [
|
||||
<SwitchItem v-model="widgetRefresh">
|
||||
{{ $t('preferences.widget.refresh') }}
|
||||
</SwitchItem>
|
||||
<SwitchItem v-model="widgetTimezone">
|
||||
{{ $t('preferences.widget.timezone') }}
|
||||
</SwitchItem>
|
||||
<SelectItem v-model="appPreferencesButtonPosition" :items="positionItems">
|
||||
{{ $t('preferences.position.title') }}
|
||||
</SelectItem>
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ const slots = useSlots();
|
||||
</VbenTooltip>
|
||||
</span>
|
||||
|
||||
<NumberField v-model="inputValue" v-bind="$attrs" class="w-[165px]">
|
||||
<NumberField v-model="inputValue" v-bind="$attrs" class="w-41.25">
|
||||
<NumberFieldContent>
|
||||
<NumberFieldDecrement />
|
||||
<NumberFieldInput />
|
||||
|
||||
@@ -23,10 +23,12 @@ withDefaults(
|
||||
disabled?: boolean;
|
||||
items?: SelectOption[];
|
||||
placeholder?: string;
|
||||
tip?: string;
|
||||
}>(),
|
||||
{
|
||||
disabled: false,
|
||||
placeholder: '',
|
||||
tip: '',
|
||||
items: () => [],
|
||||
},
|
||||
);
|
||||
@@ -39,7 +41,7 @@ const slots = useSlots();
|
||||
<template>
|
||||
<div
|
||||
:class="{
|
||||
'hover:bg-accent': !slots.tip,
|
||||
'hover:bg-accent': !(slots.tip || tip),
|
||||
'pointer-events-none opacity-50': disabled,
|
||||
}"
|
||||
class="my-1 flex w-full items-center justify-between rounded-md px-2 py-1"
|
||||
@@ -47,15 +49,21 @@ const slots = useSlots();
|
||||
<span class="flex items-center text-sm">
|
||||
<slot></slot>
|
||||
|
||||
<VbenTooltip v-if="slots.tip" side="bottom">
|
||||
<VbenTooltip v-if="slots.tip || tip" side="bottom">
|
||||
<template #trigger>
|
||||
<CircleHelp class="ml-1 size-3 cursor-help" />
|
||||
</template>
|
||||
<slot name="tip"></slot>
|
||||
<slot name="tip">
|
||||
<template v-if="tip">
|
||||
<p v-for="(line, index) in tip.split('\n')" :key="index">
|
||||
{{ line }}
|
||||
</p>
|
||||
</template>
|
||||
</slot>
|
||||
</VbenTooltip>
|
||||
</span>
|
||||
<Select v-model="selectValue">
|
||||
<SelectTrigger class="h-8 w-[165px]">
|
||||
<SelectTrigger class="h-8 w-41.25">
|
||||
<SelectValue :placeholder="placeholder" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
|
||||
@@ -28,7 +28,7 @@ function handleClick() {
|
||||
:class="{
|
||||
'pointer-events-none opacity-50': disabled,
|
||||
}"
|
||||
class="hover:bg-accent my-1 flex w-full items-center justify-between rounded-md px-2 py-2.5"
|
||||
class="my-1 flex w-full items-center justify-between rounded-md px-2 py-2.5 hover:bg-accent"
|
||||
@click="handleClick"
|
||||
>
|
||||
<span class="flex items-center text-sm">
|
||||
@@ -47,9 +47,9 @@ function handleClick() {
|
||||
</slot>
|
||||
</VbenTooltip>
|
||||
</span>
|
||||
<span v-if="$slots.shortcut" class="ml-auto mr-2 text-xs opacity-60">
|
||||
<span v-if="$slots.shortcut" class="mr-2 ml-auto text-xs opacity-60">
|
||||
<slot name="shortcut"></slot>
|
||||
</span>
|
||||
<Switch v-model:checked="checked" @click.stop />
|
||||
<Switch v-model="checked" @click.stop />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -58,7 +58,6 @@ function typeView(name: BuiltinThemeType) {
|
||||
case 'green': {
|
||||
return $t('preferences.theme.builtin.green');
|
||||
}
|
||||
|
||||
case 'neutral': {
|
||||
return $t('preferences.theme.builtin.neutral');
|
||||
}
|
||||
@@ -127,19 +126,19 @@ watch(
|
||||
:class="{
|
||||
'outline-box-active': theme.type === modelValue,
|
||||
}"
|
||||
class="outline-box flex-center group cursor-pointer"
|
||||
class="group outline-box flex-center cursor-pointer"
|
||||
>
|
||||
<template v-if="theme.type !== 'custom'">
|
||||
<div
|
||||
:style="{ backgroundColor: theme.color }"
|
||||
class="mx-10 my-2 size-5 rounded-md"
|
||||
class="mx-9 my-2 size-5 rounded-md"
|
||||
></div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="size-full px-10 py-2" @click.stop="selectColor">
|
||||
<div class="flex-center relative size-5 rounded-sm">
|
||||
<div class="size-full px-9 py-2" @click.stop="selectColor">
|
||||
<div class="relative flex-center size-5 rounded-sm">
|
||||
<UserRoundPen
|
||||
class="absolute z-10 size-5 opacity-60 group-hover:opacity-100"
|
||||
class="absolute z-1 size-5 opacity-60 group-hover:opacity-100"
|
||||
/>
|
||||
<input
|
||||
ref="colorInput"
|
||||
@@ -152,7 +151,7 @@ watch(
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="text-muted-foreground my-2 text-center text-xs">
|
||||
<div class="my-2 text-center text-xs text-muted-foreground">
|
||||
{{ typeView(theme.type) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user