Commit 9f67fa79 by Lin

feat: 组合函数工具模块

1 parent 3c29dd7d
...@@ -32,24 +32,39 @@ ...@@ -32,24 +32,39 @@
## 项目结构 ## 项目结构
``` ```
venus-admin-monorepo/ venus/
├── apps/ # 应用目录 ├── apps/ # 应用目录
│ ├── web-antd/ # Ant Design Vue 版本 │ ├── web/ # Web 应用
│ ├── web-ele/ # Element Plus 版本 │ │ ├── venus-agentic/ # 智能体应用
│ ├── web-naive/ # Naive UI 版本 │ │ ├── venus-base/ # 基础应用模板
│ │ └── vue2/ # Vue 2 版本应用
│ ├── miniprogram/ # 小程序应用
│ └── uniapp/ # UniApp 应用
├── packages/ # 公共包 ├── packages/ # 公共包
│ ├── composables/ # Vue Composables │ ├── charts/ # 图表组件库
│ ├── effects/ # 业务逻辑 │ ├── cli/ # CLI 工具(项目脚手架)
│ ├── icons/ # 图标组件 │ ├── common-ui/ # 通用 UI 组件库
│ ├── preferences/ # 偏好设置 │ ├── components/ # 公共组件
│ ├── composables/ # Vue Composables(组合式函数)
│ ├── constants/ # 常量定义(多应用共享)
│ ├── stores/ # 状态管理(Pinia stores)
│ ├── tools/ # 工具函数(自动路由生成等)
│ ├── types/ # 类型定义 │ ├── types/ # 类型定义
│ ├── ui-kit/ # UI 组件库 │ └── utils/ # 工具函数
│ ├── utils/ # 工具函数 ├── internal/ # 内部工具包
│ └── ...
├── internal/ # 内部工具
│ ├── lint-configs/ # 代码规范配置 │ ├── lint-configs/ # 代码规范配置
│ ├── vite-config/ # Vite 配置 │ │ ├── commitlint-config/ # Commit 规范配置
│ └── ... │ │ ├── eslint-config/ # ESLint 配置
│ │ ├── prettier-config/ # Prettier 配置
│ │ └── stylelint-config/ # Stylelint 配置
│ ├── node-utils/ # Node.js 工具库(文件操作、Git、日期、哈希等)
│ ├── tailwind-config/ # Tailwind CSS 配置
│ ├── tsconfig/ # TypeScript 配置预设
│ └── vite-config/ # Vite 构建配置
├── scripts/ # 构建和开发脚本
│ ├── build/ # 构建相关脚本
│ ├── turbo-run/ # Turbo 运行工具
│ └── vsh/ # Venus Shell 工具(依赖检查、代码检查等)
└── docs/ # 文档站点 └── docs/ # 文档站点
``` ```
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
"dependencies": { "dependencies": {
"@element-plus/icons-vue": "catalog:", "@element-plus/icons-vue": "catalog:",
"@venus/common-ui-vue": "workspace:*", "@venus/common-ui-vue": "workspace:*",
"@venus/composables": "workspace:*",
"@vueuse/core": "catalog:", "@vueuse/core": "catalog:",
"element-plus": "catalog:", "element-plus": "catalog:",
"pinia": "catalog:", "pinia": "catalog:",
......
...@@ -18,6 +18,12 @@ export const systemMenus: MenuItem[] = [ ...@@ -18,6 +18,12 @@ export const systemMenus: MenuItem[] = [
level: 1, level: 1,
}, },
{ {
id: "page-hooks",
title: "组合函数",
path: "/pageHooks/index",
level: 1,
},
{
id: "system-role", id: "system-role",
title: "角色管理", title: "角色管理",
path: "/system/role", path: "/system/role",
......
...@@ -37,6 +37,14 @@ const routes: RouteRecordRaw[] = [ ...@@ -37,6 +37,14 @@ const routes: RouteRecordRaw[] = [
}, },
}, },
{ {
path: "/pageHooks/index",
name: "PageHooks",
component: () => import("@/views/pageHooks/index.vue"),
meta: {
title: "Hooks 示例"
},
},
{
path: "/system/role", path: "/system/role",
name: "SystemRole", name: "SystemRole",
component: () => import("@/views/system/Role.vue"), component: () => import("@/views/system/Role.vue"),
......
<script setup lang="ts">
import { onMounted, ref } from "vue";
import {
useIsMobile,
useSimpleLocale,
useSortable
} from "@venus/composables";
import { ElCard, ElOption, ElSelect, ElTag } from "element-plus";
// ==================== useIsMobile ====================
const { isMobile } = useIsMobile();
// ==================== useSortable ====================
const sortableList = ref([ "项目 1", "项目 2", "项目 3", "项目 4", "项目 5" ]);
const sortableContainer = ref<HTMLElement | null>(null);
onMounted(async () => {
if (sortableContainer.value) {
const { initializeSortable } = useSortable(sortableContainer.value, {
animation: 200,
ghostClass: "sortable-ghost",
});
await initializeSortable();
}
});
// ==================== useSimpleLocale ====================
const { $t, currentLocale, setSimpleLocale } = useSimpleLocale();
const localeOptions = [
{ label: "中文", value: "zh-CN" },
{ label: "English", value: "en-US" },
];
const changeLocale = (locale: "en-US" | "zh-CN") => {
setSimpleLocale(locale);
};
// 在模板中使用 $t 的辅助函数
const t = (key: string) => $t.value(key);
</script>
<template>
<div class="page-hooks-container">
<div class="page-header">
<h1>Composables Hooks 使用示例</h1>
<p class="page-description">
展示 @venus/composables 包中所有 Hooks 的使用方法和示例
</p>
</div>
<div class="hooks-grid">
<!-- useIsMobile -->
<ElCard class="hook-card" shadow="hover">
<template #header>
<div class="card-header">
<span class="card-title">useIsMobile</span>
<ElTag type="info">
响应式
</ElTag>
</div>
</template>
<div class="card-content">
<p class="card-description">
检测当前设备是否为移动端,基于 Tailwind 断点系统
</p>
<div class="demo-section">
<div class="demo-item">
<span class="demo-label">是否为移动端:</span>
<ElTag :type="isMobile ? 'warning' : 'success'">
{{ isMobile ? "是" : "否" }}
</ElTag>
</div>
<div class="demo-tip">
💡 提示:调整浏览器窗口大小,观察值的变化
</div>
</div>
<div class="code-example">
<pre>
<code>
const { isMobile } = useIsMobile();
// isMobile 是一个响应式的 ref,当窗口宽度小于 md 断点时返回 true
</code>
</pre>
</div>
</div>
</ElCard>
<!-- useSortable -->
<ElCard class="hook-card" shadow="hover">
<template #header>
<div class="card-header">
<span class="card-title">useSortable</span>
<ElTag type="primary">
交互
</ElTag>
</div>
</template>
<div class="card-content">
<p class="card-description">
基于 SortableJS 的拖拽排序功能
</p>
<div class="demo-section">
<div ref="sortableContainer"
class="sortable-list">
<div v-for="(item, index) in sortableList"
:key="index"
class="sortable-item">
{{ item }}
</div>
</div>
<div class="demo-tip">
💡 拖拽列表项进行排序
</div>
</div>
<div class="code-example">
<pre>
<code>
const container = ref&lt;HTMLElement&gt;(null);
const { initializeSortable } = useSortable(container.value, {
animation: 200,
ghostClass: "sortable-ghost"
});
const sortable = await initializeSortable();
</code>
</pre>
</div>
</div>
</ElCard>
<!-- useSimpleLocale -->
<ElCard class="hook-card" shadow="hover">
<template #header>
<div class="card-header">
<span class="card-title">useSimpleLocale</span>
<ElTag type="success">
国际化
</ElTag>
</div>
</template>
<div class="card-content">
<p class="card-description">
简单的国际化解决方案,支持多语言切换
</p>
<div class="demo-section">
<div class="demo-item">
<span class="demo-label">当前语言:</span>
<ElSelect v-model="currentLocale"
style="width: 150px;"
@change="changeLocale">
<ElOption v-for="option in localeOptions"
:key="option.value"
:label="option.label"
:value="option.value" />
</ElSelect>
</div>
<div class="demo-item">
<span class="demo-label">翻译示例:</span>
<div class="locale-examples">
<div class="locale-item">
<span class="locale-key">confirm:</span>
<span class="locale-value">{{ t("confirm") }}</span>
</div>
<div class="locale-item">
<span class="locale-key">cancel:</span>
<span class="locale-value">{{ t("cancel") }}</span>
</div>
<div class="locale-item">
<span class="locale-key">submit:</span>
<span class="locale-value">{{ t("submit") }}</span>
</div>
</div>
</div>
</div>
<div class="code-example">
<pre>
<code>
const { $t, currentLocale, setSimpleLocale } = useSimpleLocale();
setSimpleLocale("zh-CN");
const text = $t("confirm"); // "确认" 或 "Confirm"
</code>
</pre>
</div>
</div>
</ElCard>
</div>
</div>
</template>
<style scoped>
.page-hooks-container {
padding: 24px;
background: #f5f7fa;
min-height: 100vh;
}
.page-header {
margin-bottom: 24px;
text-align: center;
}
.page-header h1 {
margin: 0 0 12px;
font-size: 28px;
font-weight: 600;
color: #303133;
}
.page-description {
margin: 0;
font-size: 14px;
color: #909399;
}
.hooks-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
gap: 24px;
}
.hook-card {
border-radius: 8px;
transition: all 0.3s ease;
}
.hook-card:hover {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
transform: translateY(-2px);
}
.card-header {
display: flex;
align-items: center;
justify-content: space-between;
}
.card-title {
font-size: 18px;
font-weight: 600;
color: #303133;
}
.card-content {
padding: 0;
}
.card-description {
margin: 0 0 16px;
font-size: 14px;
color: #606266;
line-height: 1.6;
}
.demo-section {
margin-bottom: 16px;
}
.demo-item {
display: flex;
align-items: center;
margin-bottom: 12px;
gap: 8px;
}
.demo-label {
min-width: 100px;
font-size: 14px;
color: #606266;
font-weight: 500;
}
.demo-value {
font-size: 14px;
color: #303133;
font-weight: 600;
}
.demo-unit {
font-size: 14px;
color: #909399;
margin-left: 4px;
}
.demo-code {
padding: 2px 8px;
font-family: "Courier New", Consolas, monospace;
font-size: 13px;
color: #e6a23c;
background: #fdf6ec;
border-radius: 4px;
}
.demo-tip {
margin-top: 12px;
padding: 8px 12px;
font-size: 12px;
color: #909399;
background: #f4f4f5;
border-radius: 4px;
line-height: 1.6;
}
.code-example {
margin-top: 16px;
padding: 12px;
background: #f5f7fa;
border-radius: 4px;
border-left: 3px solid #409eff;
}
.code-example pre {
margin: 0;
font-family: "Courier New", Consolas, monospace;
font-size: 12px;
color: #303133;
line-height: 1.6;
white-space: pre-wrap;
word-wrap: break-word;
}
.code-example code {
font-family: inherit;
}
.sortable-list {
margin-top: 12px;
}
.sortable-item {
padding: 12px 16px;
margin-bottom: 8px;
background: #fff;
border: 1px solid #dcdfe6;
border-radius: 4px;
cursor: move;
transition: all 0.3s;
}
.sortable-item:hover {
background: #f5f7fa;
border-color: #409eff;
}
.sortable-ghost {
opacity: 0.5;
background: #f0f9ff;
}
.locale-examples {
display: flex;
flex-direction: column;
gap: 8px;
}
.locale-item {
display: flex;
align-items: center;
gap: 8px;
}
.locale-key {
font-family: "Courier New", Consolas, monospace;
font-size: 13px;
color: #909399;
}
.locale-value {
font-size: 14px;
color: #303133;
font-weight: 500;
}
@media (max-width: 768px) {
.hooks-grid {
grid-template-columns: 1fr;
}
}
</style>
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
"moduleResolution": "bundler", "moduleResolution": "bundler",
"paths": { "paths": {
"@/*": ["src/*"], "@/*": ["src/*"],
"@venus/common-ui-vue": ["../../packages/common-ui/vue-ui/src/index.ts"] "@venus/common-ui-vue": ["../../packages/common-ui/vue-ui/src/index.ts"],
"@venus/composables": ["../../packages/composables/src/index.ts"]
}, },
"resolveJsonModule": true, "resolveJsonModule": true,
"typeRoots": ["../node_modules/@types", "./node_modules/@types"], "typeRoots": ["../node_modules/@types", "./node_modules/@types"],
......
...@@ -30,6 +30,7 @@ export default defineConfig(() => { ...@@ -30,6 +30,7 @@ export default defineConfig(() => {
resolve: { resolve: {
alias: { alias: {
"@": resolve(__dirname, "src"), "@": resolve(__dirname, "src"),
"@venus/composables": resolve(__dirname, "../packages/composables/src/index.ts"),
}, },
// 配置条件导出优先级,让打包时也使用 development 模式的源码 // 配置条件导出优先级,让打包时也使用 development 模式的源码
conditions: [ "development", "module", "import", "default" ], conditions: [ "development", "module", "import", "default" ],
......
{
"name": "@venus/components-vue",
"version": "1.0.0",
"description": "Vue components library for Venus design system",
"keywords": [
"vue",
"components",
"ui",
"venus",
"design-system"
],
"license": "ISC",
"author": "liimin",
"scripts": {
"clean": "rimraf dist",
"type-check": "vue-tsc --noEmit",
"test": "echo \"Error: no test specified\" && exit 1"
},
"files": [
"dist",
"src"
],
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
},
"./dist/*": "./dist/*"
},
"peerDependencies": {
"vue": "^3.0.0"
},
"dependencies": {
"vue": "^3.5.22"
},
"devDependencies": {
"@types/node": "^24.5.2",
"@vue/typescript-plugin": "^3.1.0",
"rimraf": "^6.0.1",
"typescript": "^5.9.2",
"vue-tsc": "^3.1.0"
},
"buildOptions": {
"name": "VenusComponentsVue",
"formats": [
"esm",
"cjs",
"iife"
]
}
}
<template>
<button class="v-button"
:class="[
`v-button--${variant}`,
`v-button--${size}`,
{
'v-button--disabled': disabled,
'v-button--loading': loading,
},
]"
:disabled="disabled || loading"
:type="type"
@click="handleClick">
<span v-if="loading" class="v-button__loading">⏳</span>
<span v-if="icon && !loading" class="v-button__icon">{{ icon }}</span>
<span v-if="$slots.default" class="v-button__content">
<slot></slot>
</span>
</button>
</template>
<script lang="ts">
// Props 定义
export interface VButtonProps {
disabled?: boolean;
icon?: string;
loading?: boolean;
size?: "large" | "medium" | "small";
type?: "button" | "reset" | "submit";
variant?: "danger" | "ghost" | "primary" | "secondary";
}
// Emits 定义
export interface VButtonEmits {
click: [event: MouseEvent];
}
</script>
<script setup lang="ts">
const props = withDefaults(defineProps<VButtonProps>(), {
type: "button",
size: "medium",
variant: "primary",
disabled: false,
loading: false,
icon: "",
});
const emit = defineEmits<VButtonEmits>();
// 点击事件处理
const handleClick = (event: Event) => {
if (!props.disabled && !props.loading) {
emit("click", event as MouseEvent);
}
};
</script>
<style scoped>
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.venus-button {
display: inline-flex;
gap: 8px;
align-items: center;
justify-content: center;
padding: 8px 16px;
font-size: 14px;
font-weight: 500;
line-height: 1.5;
cursor: pointer;
user-select: none;
border: 1px solid transparent;
border-radius: 6px;
transition: all 0.2s ease-in-out;
}
.venus-button:focus {
outline: 2px solid #3b82f6;
outline-offset: 2px;
}
/* 尺寸变体 */
.venus-button--small {
padding: 4px 8px;
font-size: 12px;
}
.venus-button--medium {
padding: 8px 16px;
font-size: 14px;
}
.venus-button--large {
padding: 12px 24px;
font-size: 16px;
}
/* 颜色变体 */
.venus-button--primary {
color: white;
background-color: #3b82f6;
border-color: #3b82f6;
}
.venus-button--primary:hover:not(:disabled) {
background-color: #2563eb;
border-color: #2563eb;
}
.venus-button--secondary {
color: white;
background-color: #6b7280;
border-color: #6b7280;
}
.venus-button--secondary:hover:not(:disabled) {
background-color: #4b5563;
border-color: #4b5563;
}
.venus-button--danger {
color: white;
background-color: #ef4444;
border-color: #ef4444;
}
.venus-button--danger:hover:not(:disabled) {
background-color: #dc2626;
border-color: #dc2626;
}
.venus-button--ghost {
color: #3b82f6;
background-color: transparent;
border-color: #3b82f6;
}
.venus-button--ghost:hover:not(:disabled) {
color: white;
background-color: #3b82f6;
}
/* 状态 */
.venus-button--disabled,
.venus-button:disabled {
cursor: not-allowed;
opacity: 0.5;
}
.venus-button--loading {
cursor: not-allowed;
}
.venus-button--icon-only {
padding: 8px;
}
.venus-button--icon-only.venus-button--small {
padding: 4px;
}
.venus-button--icon-only.venus-button--large {
padding: 12px;
}
.venus-button__loading {
animation: spin 1s linear infinite;
}
</style>
export { default, default as VButton } from "./VButton.vue";
// @ts-nocheck - This file is auto-generated by Vue Language Tools
/* eslint-disable @typescript-eslint/no-empty-object-type */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable unused-imports/no-unused-vars */
export {};
declare module "vue" {
export interface GlobalComponents {}
export interface GlobalDirectives {}
}
declare global {
const __VLS_directiveBindingRestFields: {
dir: any;
instance: null;
modifiers: any;
oldValue: null;
};
const __VLS_unref: typeof import("vue").unref;
const __VLS_placeholder: any;
const __VLS_intrinsics: globalThis.JSX.IntrinsicElements;
type __VLS_Elements = __VLS_SpreadMerge<SVGElementTagNameMap, HTMLElementTagNameMap>;
type __VLS_GlobalComponents = import("vue").GlobalComponents &
Pick<typeof import("vue"), "KeepAlive" | "Suspense" | "Teleport" | "Transition" | "TransitionGroup">;
type __VLS_GlobalDirectives = import("vue").GlobalDirectives;
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
type __VLS_SpreadMerge<A, B> = B & Omit<A, keyof B>;
type __VLS_WithComponent<
N0 extends string,
LocalComponents,
Self,
N1 extends string,
N2 extends string,
N3 extends string,
> = N1 extends keyof LocalComponents
? { [K in N0]: LocalComponents[N1] }
: N2 extends keyof LocalComponents
? { [K in N0]: LocalComponents[N2] }
: N3 extends keyof LocalComponents
? { [K in N0]: LocalComponents[N3] }
: Self extends object
? { [K in N0]: Self }
: N1 extends keyof __VLS_GlobalComponents
? { [K in N0]: __VLS_GlobalComponents[N1] }
: N2 extends keyof __VLS_GlobalComponents
? { [K in N0]: __VLS_GlobalComponents[N2] }
: N3 extends keyof __VLS_GlobalComponents
? { [K in N0]: __VLS_GlobalComponents[N3] }
: {};
type __VLS_FunctionalComponentCtx<T, K> = __VLS_PickNotAny<
"__ctx" extends keyof __VLS_PickNotAny<K, {}>
? K extends { __ctx?: infer Ctx }
? NonNullable<Ctx>
: never
: any,
T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
>;
type __VLS_FunctionalComponentProps<T, K> = "__ctx" extends keyof __VLS_PickNotAny<K, {}>
? K extends { __ctx?: { props?: infer P } }
? NonNullable<P>
: never
: T extends (props: infer P, ...args: any) => any
? P
: {};
type __VLS_FunctionalComponent<T> = (
props: Record<string, unknown> & (T extends { $props: infer Props } ? Props : {}),
ctx?: any,
) => globalThis.JSX.Element & {
__ctx?: {
attrs?: any;
emit?: T extends { $emit: infer Emit } ? Emit : {};
expose?: (exposed: T) => void;
props?: Record<string, unknown> & (T extends { $props: infer Props } ? Props : {});
slots?: T extends { $slots: infer Slots } ? Slots : Record<string, any>;
};
};
type __VLS_IsFunction<T, K> = K extends keyof T
? __VLS_IsAny<T[K]> extends false
? unknown extends T[K]
? false
: true
: false
: false;
type __VLS_NormalizeComponentEvent<
Props,
Emits,
onEvent extends keyof Props,
Event extends keyof Emits,
CamelizedEvent extends keyof Emits,
> =
__VLS_IsFunction<Props, onEvent> extends true
? Props
: __VLS_IsFunction<Emits, Event> extends true
? { [K in onEvent]?: Emits[Event] }
: __VLS_IsFunction<Emits, CamelizedEvent> extends true
? { [K in onEvent]?: Emits[CamelizedEvent] }
: Props;
// fix https://github.com/vuejs/language-tools/issues/926
type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends (
arg: infer P,
) => unknown
? P
: never;
type __VLS_OverloadUnionInner<T, U = unknown> = T & U extends (...args: infer A) => infer R
? U extends T
? never
: ((...args: A) => R) | __VLS_OverloadUnionInner<T, ((...args: A) => R) & Pick<T, keyof T> & U>
: never;
type __VLS_OverloadUnion<T> = Exclude<
__VLS_OverloadUnionInner<(() => never) & T>,
T extends () => never ? never : () => never
>;
type __VLS_ConstructorOverloads<T> =
__VLS_OverloadUnion<T> extends infer F
? F extends (event: infer E, ...args: infer A) => any
? { [K in E & string]: (...args: A) => void }
: never
: never;
type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
__VLS_UnionToIntersection<
__VLS_ConstructorOverloads<T> & {
[K in keyof T]: T[K] extends any[] ? { (...args: T[K]): void } : never;
}
>
>;
type __VLS_EmitsToProps<T> = __VLS_PrettifyGlobal<{
[K in keyof T & string as `on${Capitalize<K>}`]?: (
...args: T[K] extends (...args: infer P) => any ? P : T[K] extends null ? any[] : never
) => any;
}>;
type __VLS_ResolveEmits<
Comp,
Emits,
TypeEmits = {},
NormalizedEmits = __VLS_NormalizeEmits<Emits> extends infer E ? (string extends keyof E ? {} : E) : never,
> = __VLS_SpreadMerge<NormalizedEmits, TypeEmits>;
type __VLS_ResolveDirectives<T> = {
[K in keyof T & string as `v${Capitalize<K>}`]: T[K];
};
type __VLS_PrettifyGlobal<T> = { [K in keyof T as K]: T[K] } & {};
type __VLS_WithDefaultsGlobal<P, D> = {
[K in keyof P as K extends keyof D ? K : never]-?: P[K];
} & {
[K in keyof P as K extends keyof D ? never : K]: P[K];
};
type __VLS_UseTemplateRef<T> = Readonly<import("vue").ShallowRef<null | T>>;
type __VLS_ProxyRefs<T> = import("vue").ShallowUnwrapRef<T>;
function __VLS_getVForSourceType<T extends any[] | Iterable<any> | number | string>(
source: T,
): [
item: T extends number
? number
: T extends string
? string
: T extends any[]
? T[number]
: T extends Iterable<infer T1>
? T1
: any,
index: number,
][];
function __VLS_getVForSourceType<T>(source: T): [item: T[keyof T], key: keyof T, index: number][];
function __VLS_getSlotParameters<S, D extends S>(
slot: S,
decl?: D,
): D extends (...args: infer P) => any ? P : any[];
function __VLS_asFunctionalDirective<T>(
dir: T,
): T extends import("vue").ObjectDirective
? NonNullable<
T["beforeMount" | "beforeUnmount" | "beforeUpdate" | "created" | "mounted" | "unmounted" | "updated"]
>
: T extends (...args: any) => any
? T
: (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(
t: T,
instance?: K,
): T extends new (...args: any) => any
? __VLS_FunctionalComponent<K>
: T extends () => any
? (props: {}, ctx?: any) => ReturnType<T>
: T extends (...args: any) => any
? T
: __VLS_FunctionalComponent<{}>;
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(
t: T,
): 2 extends Parameters<T>["length"] ? [any] : [];
function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: Record<string, unknown> & T) => void;
function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
function __VLS_tryAsConstant<const T>(t: T): T;
}
/*
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @Date: 2025-10-29 14:52:18
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @LastEditTime: 2025-11-11 09:38:11
* @FilePath: \venus\packages\components\vue\src\index.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
// 组件导出
// 导入组件用于默认导出
import VButton from "./VButton";
export { default as VButton } from "./VButton";
// 类型导出 - 暂时注释掉,因为 Vue 组件的类型导出在构建时有问题
// export type { VButtonProps, VButtonEmits } from './VButton/VButton.vue'
// 版本信息
export const version = "1.0.0";
// 默认导出所有组件
export default {
VButton,
version,
};
{
"extends": "@venus/tsconfig/web.json",
"compilerOptions": {
"composite": true,
"lib": ["DOM", "ES2020"],
"rootDir": "./src",
"moduleResolution": "bundler",
"types": ["node"],
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"skipLibCheck": true
},
"vueCompilerOptions": {
"target": 3
},
"include": ["src/**/*", "src/global.d.ts"],
"exclude": ["node_modules", "dist"]
}
export * from "./use-is-mobile"; export * from "./use-is-mobile";
export * from "./use-layout-style";
export * from "./use-namespace";
export * from "./use-priority-value";
export * from "./use-scroll-lock";
export * from "./use-simple-locale"; export * from "./use-simple-locale";
export * from "./use-sortable"; export * from "./use-sortable";
export { useEmitAsProps, useForwardExpose, useForwardProps, useForwardPropsEmits } from "radix-vue"; export { useEmitAsProps, useForwardExpose, useForwardProps, useForwardPropsEmits } from "radix-vue";
import type { CSSProperties } from "vue";
import type { VisibleDomRect } from "@venus/utils";
import { computed, onMounted, onUnmounted, ref } from "vue";
import {
CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT,
CSS_VARIABLE_LAYOUT_CONTENT_WIDTH,
CSS_VARIABLE_LAYOUT_FOOTER_HEIGHT,
CSS_VARIABLE_LAYOUT_HEADER_HEIGHT,
} from "@venus/constants";
import { getElementVisibleRect } from "@venus/utils";
import { useCssVar, useDebounceFn } from "@vueuse/core";
/**
* @zh_CN content style
*/
export function useLayoutContentStyle() {
let resizeObserver: null | ResizeObserver = null;
const contentElement = ref<HTMLDivElement | null>(null);
const visibleDomRect = ref<null | VisibleDomRect>(null);
const contentHeight = useCssVar(CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT);
const contentWidth = useCssVar(CSS_VARIABLE_LAYOUT_CONTENT_WIDTH);
const overlayStyle = computed((): CSSProperties => {
const { height, left, top, width } = visibleDomRect.value ?? {};
return {
height: `${height}px`,
left: `${left}px`,
position: "fixed",
top: `${top}px`,
width: `${width}px`,
zIndex: 150,
};
});
const debouncedCalcHeight = useDebounceFn((_entries: ResizeObserverEntry[]) => {
visibleDomRect.value = getElementVisibleRect(contentElement.value);
contentHeight.value = `${visibleDomRect.value.height}px`;
contentWidth.value = `${visibleDomRect.value.width}px`;
}, 16);
onMounted(() => {
if (contentElement.value && !resizeObserver) {
resizeObserver = new ResizeObserver(debouncedCalcHeight);
resizeObserver.observe(contentElement.value);
}
});
onUnmounted(() => {
resizeObserver?.disconnect();
resizeObserver = null;
});
return { contentElement, overlayStyle, visibleDomRect };
}
export function useLayoutHeaderStyle() {
const headerHeight = useCssVar(CSS_VARIABLE_LAYOUT_HEADER_HEIGHT);
return {
getLayoutHeaderHeight: () => {
return Number.parseInt(`${headerHeight.value}`, 10);
},
setLayoutHeaderHeight: (height: number) => {
headerHeight.value = `${height}px`;
},
};
}
export function useLayoutFooterStyle() {
const footerHeight = useCssVar(CSS_VARIABLE_LAYOUT_FOOTER_HEIGHT);
return {
getLayoutFooterHeight: () => {
return Number.parseInt(`${footerHeight.value}`, 10);
},
setLayoutFooterHeight: (height: number) => {
footerHeight.value = `${height}px`;
},
};
}
import { DEFAULT_NAMESPACE } from "@venus/constants";
/**
* @see copy https://github.com/element-plus/element-plus/blob/dev/packages/hooks/use-namespace/index.ts
*/
const statePrefix = "is-";
const _bem = (namespace: string, block: string, blockSuffix: string, element: string, modifier: string) => {
let cls = `${namespace}-${block}`;
if (blockSuffix) {
cls += `-${blockSuffix}`;
}
if (element) {
cls += `__${element}`;
}
if (modifier) {
cls += `--${modifier}`;
}
return cls;
};
const is: {
(name: string): string;
// eslint-disable-next-line @typescript-eslint/unified-signatures
(name: string, state: boolean | undefined): string;
} = (name: string, ...args: [] | [boolean | undefined]) => {
const state = args.length > 0 ? args[0] : true;
return name && state ? `${statePrefix}${name}` : "";
};
const useNamespace = (block: string) => {
const namespace = DEFAULT_NAMESPACE;
const b = (blockSuffix = "") => _bem(namespace, block, blockSuffix, "", "");
const e = (element?: string) => (element ? _bem(namespace, block, "", element, "") : "");
const m = (modifier?: string) => (modifier ? _bem(namespace, block, "", "", modifier) : "");
const be = (blockSuffix?: string, element?: string) =>
blockSuffix && element ? _bem(namespace, block, blockSuffix, element, "") : "";
const em = (element?: string, modifier?: string) =>
element && modifier ? _bem(namespace, block, "", element, modifier) : "";
const bm = (blockSuffix?: string, modifier?: string) =>
blockSuffix && modifier ? _bem(namespace, block, blockSuffix, "", modifier) : "";
const bem = (blockSuffix?: string, element?: string, modifier?: string) =>
blockSuffix && element && modifier ? _bem(namespace, block, blockSuffix, element, modifier) : "";
// for css var
// --el-xxx: value;
const cssVar = (object: Record<string, string>) => {
const styles: Record<string, string> = {};
for (const key in object) {
if (object[key]) {
styles[`--${namespace}-${key}`] = object[key];
}
}
return styles;
};
// with block
const cssVarBlock = (object: Record<string, string>) => {
const styles: Record<string, string> = {};
for (const key in object) {
if (object[key]) {
styles[`--${namespace}-${block}-${key}`] = object[key];
}
}
return styles;
};
const cssVarName = (name: string) => `--${namespace}-${name}`;
const cssVarBlockName = (name: string) => `--${namespace}-${block}-${name}`;
return {
b,
be,
bem,
bm,
// css
cssVar,
cssVarBlock,
cssVarBlockName,
cssVarName,
e,
em,
is,
m,
namespace,
};
};
type UseNamespaceReturn = ReturnType<typeof useNamespace>;
export type { UseNamespaceReturn };
export { useNamespace };
import type { ComputedRef, Ref } from "vue";
import { computed, getCurrentInstance, unref, useAttrs, useSlots } from "vue";
import { getFirstNonNullOrUndefined, kebabToCamelCase } from "@venus/utils";
/**
* 依次从插槽、attrs、props、state 中获取值
* @param key
* @param props
* @param state
*/
export function usePriorityValue<
T extends Record<string, any>,
S extends Record<string, any>,
K extends keyof T = keyof T,
>(key: K, props: T, state: Readonly<Ref<NoInfer<S>>> | undefined) {
const instance = getCurrentInstance();
const slots = useSlots();
const attrs = useAttrs() as T;
const value = computed((): T[K] => {
// props不管有没有传,都会有默认值,会影响这里的顺序,
// 通过判断原始props是否有值来判断是否传入
const rawProps = (instance?.vnode?.props || {}) as T;
const standardRawProps = {} as T;
for (const [ key, value ] of Object.entries(rawProps)) {
standardRawProps[kebabToCamelCase(key) as K] = value;
}
const propsKey = standardRawProps?.[key] === undefined ? undefined : props[key];
// slot可以关闭
return getFirstNonNullOrUndefined(
slots[key as string],
attrs[key],
propsKey,
state?.value?.[key as keyof S],
) as T[K];
});
return value;
}
/**
* 批量获取state中的值(每个值都是ref)
* @param props
* @param state
*/
export function usePriorityValues<
T extends Record<string, any>,
S extends Ref<Record<string, any>> = Readonly<Ref<NoInfer<T>, NoInfer<T>>>,
>(props: T, state: S | undefined) {
const result: { [K in keyof T]: ComputedRef<T[K]> } = {} as never;
(Object.keys(props) as (keyof T)[]).forEach((key) => {
result[key] = usePriorityValue(key as keyof typeof props, props, state);
});
return result;
}
/**
* 批量获取state中的值(集中在一个computed,用于透传)
* @param props
* @param state
*/
export function useForwardPriorityValues<
T extends Record<string, any>,
S extends Ref<Record<string, any>> = Readonly<Ref<NoInfer<T>, NoInfer<T>>>,
>(props: T, state: S | undefined) {
const computedResult: { [K in keyof T]: ComputedRef<T[K]> } = {} as never;
(Object.keys(props) as (keyof T)[]).forEach((key) => {
computedResult[key] = usePriorityValue(key as keyof typeof props, props, state);
});
return computed(() => {
const unwrapResult: Record<string, any> = {};
Object.keys(props).forEach((key) => {
unwrapResult[key] = unref(computedResult[key]);
});
return unwrapResult as { [K in keyof T]: T[K] };
});
}
import { getScrollbarWidth, needsScrollbar } from "@venus/utils";
import { useScrollLock as _useScrollLock, tryOnBeforeUnmount, tryOnMounted } from "@vueuse/core";
export const SCROLL_FIXED_CLASS = `_scroll__fixed_`;
export function useScrollLock() {
const isLocked = _useScrollLock(document.body);
const scrollbarWidth = getScrollbarWidth();
tryOnMounted(() => {
if (!needsScrollbar()) {
return;
}
document.body.style.paddingRight = `${scrollbarWidth}px`;
const layoutFixedNodes = document.querySelectorAll<HTMLElement>(`.${SCROLL_FIXED_CLASS}`);
const nodes = [ ...layoutFixedNodes ];
if (nodes.length > 0) {
nodes.forEach((node) => {
node.dataset.transition = node.style.transition;
node.style.transition = "none";
node.style.paddingRight = `${scrollbarWidth}px`;
});
}
isLocked.value = true;
});
tryOnBeforeUnmount(() => {
if (!needsScrollbar()) {
return;
}
isLocked.value = false;
const layoutFixedNodes = document.querySelectorAll<HTMLElement>(`.${SCROLL_FIXED_CLASS}`);
const nodes = [ ...layoutFixedNodes ];
if (nodes.length > 0) {
nodes.forEach((node) => {
node.style.paddingRight = "";
requestAnimationFrame(() => {
node.style.transition = node.dataset.transition || "";
});
});
}
document.body.style.paddingRight = "";
});
}
...@@ -613,6 +613,9 @@ importers: ...@@ -613,6 +613,9 @@ importers:
glsk-oss-jssdk: glsk-oss-jssdk:
specifier: 'catalog:' specifier: 'catalog:'
version: 1.0.6 version: 1.0.6
glsk-toolkit:
specifier: 'catalog:'
version: 1.0.5
pinia: pinia:
specifier: ^3.0.3 specifier: ^3.0.3
version: 3.0.4(typescript@5.9.3)(vue@3.5.26(typescript@5.9.3)) version: 3.0.4(typescript@5.9.3)(vue@3.5.26(typescript@5.9.3))
...@@ -745,6 +748,9 @@ importers: ...@@ -745,6 +748,9 @@ importers:
'@venus/common-ui-vue': '@venus/common-ui-vue':
specifier: workspace:* specifier: workspace:*
version: link:../packages/common-ui/vue-ui version: link:../packages/common-ui/vue-ui
'@venus/composables':
specifier: workspace:*
version: link:../packages/composables
'@vueuse/core': '@vueuse/core':
specifier: 'catalog:' specifier: 'catalog:'
version: 13.9.0(vue@3.5.26(typescript@5.9.3)) version: 13.9.0(vue@3.5.26(typescript@5.9.3))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!