3106d96ac7
iotlcm-admin-ui:管理前端(基于 Vben Admin 5.5.9 二次开发)。 - 天地图 API Key → YOUR_TIANDITU_KEY - OAuth 客户端 ID → your-client-id,store 加密密钥 → 提示自行替换 - Makefile 移除明文 registry 登录口令,镜像地址改 - appIcon 指向内网图床的链接 → /favicon.ico - 真实手机号 → 合法 11 位编造号(保留号段前 3 位 + 后 4 位) - 真实邮箱 → example.com(署名头内的上游作者邮箱保留) - 移除 CI 触发器 - 补 MIT LICENSE(含 Vben Admin 上游声明)+ README - 统一 LF 行尾并加 .gitattributes 上游 Vben Admin 的版权与许可声明完整保留(各源文件 @Author/@Copyright 头 + LICENSE)。
107 lines
2.8 KiB
TypeScript
107 lines
2.8 KiB
TypeScript
import { DEFAULT_NAMESPACE } from '@vben-core/shared/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 };
|