Reduce web ele bootstrap dependencies

This commit is contained in:
2026-06-09 10:35:05 +08:00
parent 429ceb0a28
commit e5faa6e061
7 changed files with 111 additions and 75 deletions
@@ -37,7 +37,6 @@
"dependencies": {
"@vben-core/shared": "workspace:*",
"@vueuse/core": "catalog:",
"radix-vue": "catalog:",
"sortablejs": "catalog:",
"vue": "catalog:"
},
+1 -6
View File
@@ -1,13 +1,8 @@
export * from './use-is-mobile';
export * from './use-forward-props';
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-sortable';
export {
useEmitAsProps,
useForwardExpose,
useForwardProps,
useForwardPropsEmits,
} from 'radix-vue';
@@ -0,0 +1,89 @@
import type { EmitsOptions, MaybeRefOrGetter } from 'vue';
import {
camelize,
computed,
getCurrentInstance,
toHandlerKey,
toValue,
} from 'vue';
function getEmitKeys(emits?: EmitsOptions | null) {
if (Array.isArray(emits)) {
return emits;
}
if (emits && typeof emits === 'object') {
return Object.keys(emits);
}
return [];
}
function useEmitAsProps<Name extends string>(
emit: (name: Name, ...args: any[]) => void,
) {
const vm = getCurrentInstance();
const emitKeys = getEmitKeys(vm?.type.emits);
const emitProps: Record<string, any> = {};
for (const key of emitKeys) {
emitProps[toHandlerKey(camelize(key))] = (...args: any[]) =>
emit(key as Name, ...args);
}
return emitProps;
}
function useForwardProps<T extends Record<string, any>>(
props: MaybeRefOrGetter<T>,
) {
const vm = getCurrentInstance();
const defaultProps = Object.keys(vm?.type.props ?? {}).reduce(
(defaults, key) => {
const defaultValue = (vm?.type.props as Record<string, any>)[key]?.default;
if (defaultValue !== undefined) {
defaults[key] = defaultValue;
}
return defaults;
},
{} as Record<string, any>,
);
return computed(() => {
const forwardedProps: Record<string, any> = {};
const vnodeProps = Object.keys(vm?.vnode.props ?? {}).reduce(
(normalizedProps, key) => {
normalizedProps[camelize(key)] = vm?.vnode.props?.[key];
return normalizedProps;
},
{} as Record<string, any>,
);
const currentProps = toValue(props);
for (const key of Object.keys({ ...defaultProps, ...vnodeProps })) {
const value = currentProps[key];
if (value !== undefined) {
forwardedProps[key] = value;
}
}
return forwardedProps as T;
});
}
function useForwardPropsEmits<
T extends Record<string, any>,
Name extends string,
>(
props: MaybeRefOrGetter<T>,
emit?: (name: Name, ...args: any[]) => void,
) {
const forwardedProps = useForwardProps(props);
const emitProps = emit ? useEmitAsProps(emit) : {};
return computed(() => ({
...forwardedProps.value,
...emitProps,
}));
}
export { useEmitAsProps, useForwardProps, useForwardPropsEmits };
-1
View File
@@ -25,7 +25,6 @@
"@vben-core/typings": "workspace:*",
"pinia": "catalog:",
"pinia-plugin-persistedstate": "catalog:",
"secure-ls": "catalog:",
"vue": "catalog:",
"vue-router": "catalog:"
}
+1 -18
View File
@@ -3,7 +3,6 @@ import type { Pinia } from 'pinia';
import type { App } from 'vue';
import { createPinia } from 'pinia';
import SecureLS from 'secure-ls';
let pinia: Pinia;
@@ -21,27 +20,11 @@ export async function initStores(app: App, options: InitStoreOptions) {
const { createPersistedState } = await import('pinia-plugin-persistedstate');
pinia = createPinia();
const { namespace } = options;
const ls = new SecureLS({
encodingType: 'aes',
encryptionSecret: import.meta.env.VITE_APP_STORE_SECURE_KEY,
isCompression: true,
// @ts-ignore secure-ls does not have a type definition for this
metaKey: `${namespace}-secure-meta`,
});
pinia.use(
createPersistedState({
// key $appName-$store.id
key: (storeKey) => `${namespace}-${storeKey}`,
storage: import.meta.env.DEV
? localStorage
: {
getItem(key) {
return ls.get(key);
},
setItem(key, value) {
ls.set(key, value);
},
},
storage: localStorage,
}),
);
app.use(pinia);