🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

mooljs

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mooljs - npm Package Compare versions

Comparing version
1.0.0-beta
to
1.0.1
+4
-1
lib/type.ts

@@ -17,2 +17,3 @@ import { Router } from "vue-router";

export type GetInitialState = GetInitialStateReturnType<RuntimeConfig['getInitialState']>;
// 定义路由配置接口

@@ -91,4 +92,6 @@ export interface IMenuRoutes {

config: RuntimeConfig;
access?: (typeof import("src/access"))["default"];
access?: {
default:(typeof import("src/access"))["default"];
}
router?: Router;
}
+65
-37
import { App, inject } from "vue";
import { UseProviderOptions, IMenuRoutes, LayoutConfig } from "./type"; // 假设type.ts和hooks文件在同一目录
import { type } from "./utils/type";
const LAYOUT_CONFIG = Symbol("layout-config");
const MENU_ROUTES = Symbol("menu-config");
const LAYOUT_CONFIG = Symbol('layout-config');
const MENU_ROUTES = Symbol('menu-config');
let ACCESS_KEY: symbol;
function convertToArray(value: any) {
// 如果已经是数组,则直接返回
if (Array.isArray(value)) {
return value;
}
// 否则,将非数组值包装在数组中,确保最终返回数组
return [];
}
function convertToObject(value) {
// 如果value已经是对象,并且不是null
if (type(value) === "object") {
return value;
}
// 对于基本类型或null/undefined,将其作为值放入一个新对象的属性中
return {};
}
export const getAppConfig = async (options: UseProviderOptions) => {
const { config, access = {} } = options;
const { routes = [], layout = {}, getInitialState } = config ?? {};
const { config, access = { default: () => ({}) } } = options;
const { routes = [], layout = {}, getInitialState } = config ?? {};
const initialState = (await getInitialState?.()) ?? {};
const accessConfig = access?.(initialState);
const initialState = (await getInitialState?.()) ?? {};
const accessConfig = access.default?.(initialState);
const layoutConfig =
typeof layout === "function" ? layout(initialState) : layout;
const layoutConfig =
typeof layout === "function" ? layout(initialState) : layout;
const menuRoutes =
(await (layoutConfig as LayoutConfig).menu?.request?.()) ?? routes;
const menuRoutes =
(await (layoutConfig as LayoutConfig).menu?.request?.()) ?? routes;
return { routes: menuRoutes, access: accessConfig,layout:layoutConfig };
return {
routes: convertToArray(menuRoutes),
access: convertToObject(accessConfig),
layout: convertToObject(layoutConfig),
};
};
export const useProvider = (app: App, options: { accessInjectKey: symbol; routes: IMenuRoutes[],layout:LayoutConfig }) => {
// const { accessInjectKey, routesInjectKey } = options;
const { routes, accessInjectKey,layout } = options;
export const useProvider = (
app: App,
options: {
accessInjectKey: symbol;
routes: IMenuRoutes[];
layout: LayoutConfig;
},
) => {
// const { accessInjectKey, routesInjectKey } = options;
const { routes, accessInjectKey, layout } = options;
/**
* 注入菜单路由
*/
app.provide(MENU_ROUTES, routes);
/**
* 注入菜单路由
*/
app.provide(MENU_ROUTES, routes);
/**
* 注入布局配置
*/
/**
* 注入布局配置
*/
app.provide(LAYOUT_CONFIG,layout);
app.provide(LAYOUT_CONFIG, layout);
/**
* 获取插件的注入key
*/
ACCESS_KEY = accessInjectKey;
/**
* 获取插件的注入key
*/
ACCESS_KEY = accessInjectKey;
/**
* 注入全局store
*/
// createStore('@@initialState',initialState);
/**
* 注入全局store
*/
// createStore('@@initialState',initialState);
};
export const useAccess = () => {
return inject(ACCESS_KEY) as ReturnType<
return ACCESS_KEY
? (inject(ACCESS_KEY) as ReturnType<
(typeof import("src/access"))["default"]
>;
>)
: {};
};
export const useMenuRoutes = () => {
return inject(MENU_ROUTES) as IMenuRoutes;
return inject(MENU_ROUTES) as IMenuRoutes;
};
export const useLayout = () => {
return inject(LAYOUT_CONFIG) as LayoutConfig
}
return inject(LAYOUT_CONFIG) as LayoutConfig;
};
{
"name": "mooljs",
"version": "1.0.0-beta",
"version": "1.0.1",
"description": "function tool library for mooljs",

@@ -5,0 +5,0 @@ "main": "lib/index.ts",