repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
my-fingerprint | github_2023 | omegaee | typescript | getSeedByMode | const getSeedByMode = (storage: LocalStorageObject, mode: HookMode) => {
switch (mode?.type) {
case HookType.browser:
return storage.config.browserSeed
case HookType.global:
return storage.config.customSeed
default:
return undefined
}
} | /**
* 获取seed
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/background/index.ts#L129-L138 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | refreshRequestHeader | const refreshRequestHeader = async () => {
const storage = await getLocalStorage()
const options: chrome.declarativeNetRequest.UpdateRuleOptions = {
removeRuleIds: [UA_NET_RULE_ID],
}
if (!storage.config.enable || !storage.config.hookNetRequest) {
chrome.declarativeNetRequest.updateSessionRules(options)
return
}
const requestHeaders: chrome.declarativeNetRequest.ModifyHeaderInfo[] = []
const equipmentSeed = getSeedByMode(storage, storage.config.fingerprint.navigator.equipment);
if (equipmentSeed) {
requestHeaders.push({
header: "User-Agent",
operation: chrome.declarativeNetRequest.HeaderOperation.SET,
value: genRandomVersionUserAgent(equipmentSeed, navigator),
})
const uaData = await genRandomVersionUserAgentData(equipmentSeed, navigator)
uaData.brands && requestHeaders.push({
header: "Sec-Ch-Ua",
operation: chrome.declarativeNetRequest.HeaderOperation.SET,
value: uaData.brands.map((brand) => `"${brand.brand}";v="${brand.version}"`).join(", "),
})
uaData.fullVersionList && requestHeaders.push({
header: "Sec-Ch-Ua-Full-Version-List",
operation: chrome.declarativeNetRequest.HeaderOperation.SET,
value: uaData.fullVersionList.map((brand) => `"${brand.brand}";v="${brand.version}"`).join(", "),
})
uaData.uaFullVersion && requestHeaders.push({
header: "Sec-Ch-Ua-Full-Version",
operation: chrome.declarativeNetRequest.HeaderOperation.SET,
value: uaData.uaFullVersion,
})
}
const langsMode = storage.config.fingerprint.navigator.languages
if (langsMode && langsMode.type !== HookType.default) {
/* 获取种子 */
let langs: string[] | undefined
if (langsMode.type === HookType.value) {
langs = langsMode.value
} else {
const langSeed = getSeedByMode(storage, langsMode)
if (langSeed) {
langs = shuffleArray(RAW.languages, langSeed)
}
}
/* 修改 */
if (langs?.length) {
const [first, ...rest] = langs
let qFactor = 1
for (let i = 0; i < rest.length && qFactor > 0.1; i++) {
qFactor -= 0.1
rest[i] = `${rest[i]};q=${qFactor.toFixed(1)}`
}
requestHeaders.push({
header: "Accept-Language",
operation: chrome.declarativeNetRequest.HeaderOperation.SET,
value: [first, ...rest].join(","),
})
}
}
if (requestHeaders.length) {
options.addRules = [{
id: UA_NET_RULE_ID,
// priority: 1,
condition: {
excludedInitiatorDomains: [...new Set([...storage.whitelist].map((host) => host.split(':')[0]))],
resourceTypes: Object.values(chrome.declarativeNetRequest.ResourceType),
// resourceTypes: [RT.MAIN_FRAME, RT.SUB_FRAME, RT.IMAGE, RT.FONT, RT.MEDIA, RT.STYLESHEET, RT.SCRIPT ],
},
action: {
type: chrome.declarativeNetRequest.RuleActionType.MODIFY_HEADERS,
requestHeaders,
},
}]
}
chrome.declarativeNetRequest.updateSessionRules(options)
} | /**
* 刷新请求头UA
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/background/index.ts#L143-L228 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | updateLocalConfig | const updateLocalConfig = async (config: DeepPartial<LocalStorageConfig>) => {
const storage = await getLocalStorage()
storage.config = deepmerge<LocalStorageConfig, DeepPartial<LocalStorageConfig>>(
storage.config,
config,
{ arrayMerge: (destinationArray, sourceArray, options) => sourceArray },
)
saveLocalConfig(storage)
if (
config.enable !== undefined ||
config.hookNetRequest !== undefined ||
config.fingerprint?.navigator?.equipment !== undefined ||
config.fingerprint?.navigator?.language !== undefined
) {
refreshRequestHeader()
}
} | /**
* 修改配置
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/background/index.ts#L247-L263 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | updateLocalWhitelist | const updateLocalWhitelist = async (type: 'add' | 'del', host: string | string[]) => {
const storage = await getLocalStorage()
if (Array.isArray(host)) {
if (type === 'add') {
for (const hh of host) {
storage.whitelist.add(hh)
}
} else if (type === 'del') {
for (const hh of host) {
storage.whitelist.delete(hh)
}
}
} else {
if (type === 'add') {
storage.whitelist.add(host)
} else if (type === 'del') {
storage.whitelist.delete(host)
}
}
saveLocalWhitelist(storage)
if (storage.config.enable && storage.config.hookNetRequest && storage.config.fingerprint.navigator.equipment) {
refreshRequestHeader()
}
} | /**
* 修改白名单
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/background/index.ts#L268-L291 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | getBadgeContent | const getBadgeContent = (records: Partial<Record<HookFingerprintKey, number>>): [string, string] => {
let baseNum = 0
let specialNum = 0
for (const [key, num] of Object.entries(records)) {
if (SPECIAL_KEYS.includes(key as any)) {
specialNum += num
} else {
baseNum += num
}
}
const showNum = specialNum || baseNum
return [showNum >= 100 ? '99+' : String(showNum), specialNum ? BADGE_COLOR.high : BADGE_COLOR.low]
} | /**
* 获取Badge内容
* @returns [文本, 颜色]
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/background/index.ts#L297-L309 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | setBadgeWhitelist | const setBadgeWhitelist = (tabId: number) => {
chrome.action.setBadgeText({ tabId, text: ' ' });
chrome.action.setBadgeBackgroundColor({ tabId, color: BADGE_COLOR.whitelist })
} | /**
* 设置白名单标识
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/background/index.ts#L314-L317 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | remBadge | const remBadge = (tabId: number) => {
chrome.action.setBadgeText({ tabId, text: '' })
} | /**
* 移除标识
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/background/index.ts#L322-L324 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | injectScript | const injectScript = (tabId: number, storage: LocalStorageObject) => {
chrome.scripting.executeScript({
target: {
tabId,
allFrames: true,
},
world: 'MAIN',
injectImmediately: true,
args: [tabId, { ...storage, whitelist: [...storage.whitelist] }],
func: coreInject,
}).catch(() => { })
} | /**
* 注入脚本
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/background/index.ts#L412-L423 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | FingerprintHandler.isEnable | public isEnable() {
return !!this.conf.enable && !this.info.inWhitelist
} | /**
* 脚本是否启动
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/core/core.ts#L150-L152 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | FingerprintHandler.hook | public hook() {
if (!this.isEnable()) return;
for (const task of hookTasks) {
if (!task.condition || task.condition(this) === true) {
task.onEnable?.(this)
}
}
} | /**
* hook内容
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/core/core.ts#L157-L164 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | FingerprintHandler.hookIframe | public hookIframe = (iframe: HTMLIFrameElement) => {
new FingerprintHandler(iframe.contentWindow as any, this.info, this.conf)
} | /**
* hook iframe
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/core/core.ts#L169-L171 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | FingerprintHandler.isAllDefault | public isAllDefault(ops?: Record<string, HookMode>) {
if (!ops) return true
for (const value of Object.values(ops)) {
if (value!.type !== HookType.default) return false
}
return true
} | /**
* 是否所有字段的type都是default
* ops为空则返回true
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/core/core.ts#L177-L183 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
my-fingerprint | github_2023 | omegaee | typescript | FingerprintHandler.getSeed | public getSeed = (type?: HookType): number | null => {
switch (type) {
case HookType.page:
return this.seed.page
case HookType.domain:
return this.seed.domain
case HookType.browser:
return this.seed.browser
case HookType.global:
return this.seed.global
case HookType.default:
default:
return null
}
} | /**
* 获取value对应的的seed
*/ | https://github.com/omegaee/my-fingerprint/blob/5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04/src/core/core.ts#L188-L202 | 5177a7f0e061bef5ca76e08cd4aa5e9ecf61ff04 |
rill-flow | github_2023 | weibocom | typescript | getBaseConfig | function getBaseConfig(node) {
const {
type,
shape,
tooltip,
attrs,
x,
y,
size,
id,
position,
data,
actionType,
icon,
ports,
status,
nodePrototype,
label,
name,
} = node;
let _width,
_height,
_x = x,
_y = y,
_shape = shape,
_tooltip = tooltip,
_actionType = actionType;
if (data && data.actionType) {
_actionType = data.actionType;
}
if (size) {
// G6
if (Lang.isArray(size)) {
_width = size[0];
_height = size[1];
}
// x6
else if (Lang.isObject(size)) {
_width = size.width;
_height = size.height;
}
}
if (Lang.isObject(position)) {
_x = position.x;
_y = position.y;
}
// 形状转义
// G6
if (Lang.isString(type)) {
_shape = type;
if (type === 'diamond') _shape = 'rect';
}
if (Lang.isObject(attrs)) {
_tooltip = attrs.label.text;
}
return {
type: _shape,
label: label,
x: _x,
y: _y,
width: _width,
height: _height,
id,
actionType: _actionType,
data: {
icon: icon,
nodePrototype: nodePrototype,
nodeId: id,
name: name,
status: status,
},
icon,
ports,
status,
position: position,
};
} | /**
* 获取默认配置选项
* 兼容x6/g6
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/flow-graph/src/common/transform.ts#L27-L104 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | Channel.dispatchEvent | static dispatchEvent(TypeEnum: CustomEventTypeEnum<string>, detail: any): void {
if (!TypeEnum) throw new Error('TypeEnum not found');
window.dispatchEvent(
new CustomEvent(TypeEnum, {
detail,
bubbles: false,
cancelable: true,
}),
);
} | /**
* 事件分发
* @param {CustomEventTypeEnum<string>} TypeEnum 事件分发类型
* @param {any} detail 详情
* @static
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/flow-graph/src/common/transmit.ts#L13-L22 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | Channel.eventListener | static eventListener(TypeEnum: CustomEventTypeEnum<string>, callback: Function): void {
if (!TypeEnum) throw new Error('TypeEnum not found');
window.addEventListener(
TypeEnum,
function (event) {
callback(event.detail);
},
false,
);
} | /**
* 事件监听
* @param {CustomEventTypeEnum<string>} TypeEnum 事件分发类型
* @param {Function} callback 回调
* @static
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/flow-graph/src/common/transmit.ts#L30-L39 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getVariableName | const getVariableName = (title: string) => {
function strToHex(str: string) {
const result: string[] = [];
for (let i = 0; i < str.length; ++i) {
const hex = str.charCodeAt(i).toString(16);
result.push(('000' + hex).slice(-4));
}
return result.join('').toUpperCase();
}
return `__PRODUCTION__${strToHex(title) || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, '');
}; | /**
* Get the configuration file variable name
* @param env
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/internal/vite-config/src/plugins/appConfig.ts#L76-L87 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getConfFiles | function getConfFiles() {
const script = process.env.npm_lifecycle_script as string;
const reg = new RegExp('--mode ([a-z_\\d]+)');
const result = reg.exec(script);
if (result) {
const mode = result[1];
return ['.env', `.env.${mode}`];
}
return ['.env', '.env.production'];
} | /**
* 获取当前环境下生效的配置文件名
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/internal/vite-config/src/utils/env.ts#L9-L18 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | onMountedOrActivated | function onMountedOrActivated(hook: AnyFunction) {
let mounted: boolean;
onMounted(() => {
hook();
nextTick(() => {
mounted = true;
});
});
onActivated(() => {
if (mounted) {
hook();
}
});
} | /**
* 在 OnMounted 或者 OnActivated 时触发
* @param hook 任何函数(包括异步函数)
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/packages/hooks/src/onMountedOrActivated.ts#L8-L23 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | transform | function transform(c: string) {
const code: string[] = ['$', '(', ')', '*', '+', '.', '[', ']', '?', '\\', '^', '{', '}', '|'];
return code.includes(c) ? `\\${c}` : c;
} | // Translate special characters | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Application/src/search/useMenuSearch.ts#L19-L22 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleMouseenter | function handleMouseenter(e: any) {
const index = e.target.dataset.index;
activeIndex.value = Number(index);
} | // Activate when the mouse moves to a certain line | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Application/src/search/useMenuSearch.ts#L84-L87 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleUp | function handleUp() {
if (!searchResult.value.length) return;
activeIndex.value--;
if (activeIndex.value < 0) {
activeIndex.value = searchResult.value.length - 1;
}
handleScroll();
} | // Arrow key up | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Application/src/search/useMenuSearch.ts#L90-L97 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleDown | function handleDown() {
if (!searchResult.value.length) return;
activeIndex.value++;
if (activeIndex.value > searchResult.value.length - 1) {
activeIndex.value = 0;
}
handleScroll();
} | // Arrow key down | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Application/src/search/useMenuSearch.ts#L100-L107 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleScroll | function handleScroll() {
const refList = unref(refs);
if (!refList || !Array.isArray(refList) || refList.length === 0 || !unref(scrollWrap)) {
return;
}
const index = unref(activeIndex);
const currentRef = refList[index];
if (!currentRef) {
return;
}
const wrapEl = unref(scrollWrap);
if (!wrapEl) {
return;
}
const scrollHeight = currentRef.offsetTop + currentRef.offsetHeight;
const wrapHeight = wrapEl.offsetHeight;
const { start } = useScrollTo({
el: wrapEl,
duration: 100,
to: scrollHeight - wrapHeight,
});
start();
} | // When the keyboard up and down keys move to an invisible place | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Application/src/search/useMenuSearch.ts#L111-L134 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleEnter | async function handleEnter() {
if (!searchResult.value.length) {
return;
}
const result = unref(searchResult);
const index = unref(activeIndex);
if (result.length === 0 || index < 0) {
return;
}
const to = result[index];
handleClose();
await nextTick();
go(to.path);
} | // enter keyboard event | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Application/src/search/useMenuSearch.ts#L137-L150 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleClose | function handleClose() {
searchResult.value = [];
emit('close');
} | // close search modal | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Application/src/search/useMenuSearch.ts#L153-L156 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getMarks | const getMarks = () => {
const l = {};
for (let i = min; i < max + 1; i++) {
l[i] = {
style: {
color: '#fff',
},
label: i,
};
}
return l;
}; | // 每行显示个数滑动条 | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/CardList/src/data.ts#L7-L18 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | setFieldsValue | async function setFieldsValue(values: Recordable): Promise<void> {
const fields = unref(getSchema)
.map((item) => item.field)
.filter(Boolean);
// key 支持 a.b.c 的嵌套写法
const delimiter = '.';
const nestKeyArray = fields.filter((item) => String(item).indexOf(delimiter) >= 0);
const validKeys: string[] = [];
fields.forEach((key) => {
const schema = unref(getSchema).find((item) => item.field === key);
let value = get(values, key);
const hasKey = Reflect.has(values, key);
value = handleInputNumberValue(schema?.component, value);
const { componentProps } = schema || {};
let _props = componentProps as any;
if (typeof componentProps === 'function') {
_props = _props({ formModel: unref(formModel) });
}
const constructValue = tryConstructArray(key, values) || tryConstructObject(key, values);
// 0| '' is allow
if (hasKey || !!constructValue) {
const fieldValue = constructValue || value;
// time type
if (itemIsDateType(key)) {
if (Array.isArray(fieldValue)) {
const arr: any[] = [];
for (const ele of fieldValue) {
arr.push(ele ? dateUtil(ele) : null);
}
unref(formModel)[key] = arr;
} else {
unref(formModel)[key] = fieldValue
? _props?.valueFormat
? fieldValue
: dateUtil(fieldValue)
: null;
}
} else {
unref(formModel)[key] = fieldValue;
}
if (_props?.onChange) {
_props?.onChange(fieldValue);
}
validKeys.push(key);
} else {
nestKeyArray.forEach((nestKey: string) => {
try {
const value = nestKey.split('.').reduce((out, item) => out[item], values);
if (isDef(value)) {
unref(formModel)[nestKey] = unref(value);
validKeys.push(nestKey);
}
} catch (e) {
// key not exist
if (isDef(defaultValueRef.value[nestKey])) {
unref(formModel)[nestKey] = cloneDeep(unref(defaultValueRef.value[nestKey]));
}
}
});
}
});
validateFields(validKeys).catch((_) => {});
} | /**
* @description: Set form value
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Form/src/hooks/useFormEvents.ts#L103-L170 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | removeSchemaByField | async function removeSchemaByField(fields: string | string[]): Promise<void> {
const schemaList: FormSchema[] = cloneDeep(unref(getSchema));
if (!fields) {
return;
}
let fieldList: string[] = isString(fields) ? [fields] : fields;
if (isString(fields)) {
fieldList = [fields];
}
for (const field of fieldList) {
_removeSchemaByFeild(field, schemaList);
}
schemaRef.value = schemaList;
} | /**
* @description: Delete based on field name
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Form/src/hooks/useFormEvents.ts#L175-L189 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | _removeSchemaByFeild | function _removeSchemaByFeild(field: string, schemaList: FormSchema[]): void {
if (isString(field)) {
const index = schemaList.findIndex((schema) => schema.field === field);
if (index !== -1) {
delete formModel[field];
schemaList.splice(index, 1);
}
}
} | /**
* @description: Delete based on field name
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Form/src/hooks/useFormEvents.ts#L194-L202 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | appendSchemaByField | async function appendSchemaByField(
schema: FormSchema | FormSchema[],
prefixField?: string,
first = false,
) {
const schemaList: FormSchema[] = cloneDeep(unref(getSchema));
const addSchemaIds: string[] = Array.isArray(schema)
? schema.map((item) => item.field)
: [schema.field];
if (schemaList.find((item) => addSchemaIds.includes(item.field))) {
error('There are schemas that have already been added');
return;
}
const index = schemaList.findIndex((schema) => schema.field === prefixField);
const _schemaList = isObject(schema) ? [schema as FormSchema] : (schema as FormSchema[]);
if (!prefixField || index === -1 || first) {
first ? schemaList.unshift(..._schemaList) : schemaList.push(..._schemaList);
schemaRef.value = schemaList;
_setDefaultValue(schema);
return;
}
if (index !== -1) {
schemaList.splice(index + 1, 0, ..._schemaList);
}
_setDefaultValue(schema);
schemaRef.value = schemaList;
} | /**
* @description: Insert after a certain field, if not insert the last
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Form/src/hooks/useFormEvents.ts#L207-L234 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | itemIsDateType | function itemIsDateType(key: string) {
return unref(getSchema).some((item) => {
return item.field === key ? dateItemType.includes(item.component) : false;
});
} | /**
* @description: Is it time
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Form/src/hooks/useFormEvents.ts#L333-L337 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleSubmit | async function handleSubmit(e?: Event): Promise<void> {
e && e.preventDefault();
const { submitFunc } = unref(getProps);
if (submitFunc && isFunction(submitFunc)) {
await submitFunc();
return;
}
const formEl = unref(formElRef);
if (!formEl) return;
try {
const values = await validate();
const res = handleFormValues(values);
emit('submit', res);
} catch (error: any) {
if (error?.outOfDate === false && error?.errorFields) {
return;
}
throw new Error(error);
}
} | /**
* @description: Form submission
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Form/src/hooks/useFormEvents.ts#L358-L377 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | tryDeconstructArray | function tryDeconstructArray(key: string, value: any, target: Recordable) {
const pattern = /^\[(.+)\]$/;
if (pattern.test(key)) {
const match = key.match(pattern);
if (match && match[1]) {
const keys = match[1].split(',');
value = Array.isArray(value) ? value : [value];
keys.forEach((k, index) => {
set(target, k.trim(), value[index]);
});
return true;
}
}
} | /**
* @desription deconstruct array-link key. This method will mutate the target.
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Form/src/hooks/useFormValues.ts#L18-L31 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | tryDeconstructObject | function tryDeconstructObject(key: string, value: any, target: Recordable) {
const pattern = /^\{(.+)\}$/;
if (pattern.test(key)) {
const match = key.match(pattern);
if (match && match[1]) {
const keys = match[1].split(',');
value = isObject(value) ? value : {};
keys.forEach((k) => {
set(target, k.trim(), value[k.trim()]);
});
return true;
}
}
} | /**
* @desription deconstruct object-link key. This method will mutate the target.
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Form/src/hooks/useFormValues.ts#L36-L49 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleFormValues | function handleFormValues(values: Recordable) {
if (!isObject(values)) {
return {};
}
const res: Recordable = {};
for (const item of Object.entries(values)) {
let [, value] = item;
const [key] = item;
if (!key || (isArray(value) && value.length === 0) || isFunction(value)) {
continue;
}
const transformDateFunc = unref(getProps).transformDateFunc;
if (isObject(value)) {
value = transformDateFunc?.(value);
}
if (isArray(value) && value[0]?.format && value[1]?.format) {
value = value.map((item) => transformDateFunc?.(item));
}
// Remove spaces
if (isString(value)) {
// remove params from URL
if (value === '') {
value = undefined;
} else {
value = value.trim();
}
}
if (!tryDeconstructArray(key, value, res) && !tryDeconstructObject(key, value, res)) {
// 没有解构成功的,按原样赋值
set(res, key, value);
}
}
return handleRangeTimeValue(res);
} | // Processing form values | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Form/src/hooks/useFormValues.ts#L58-L92 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleRangeTimeValue | function handleRangeTimeValue(values: Recordable) {
const fieldMapToTime = unref(getProps).fieldMapToTime;
if (!fieldMapToTime || !Array.isArray(fieldMapToTime)) {
return values;
}
for (const [field, [startTimeKey, endTimeKey], format = 'YYYY-MM-DD'] of fieldMapToTime) {
if (!field || !startTimeKey || !endTimeKey) {
continue;
}
// If the value to be converted is empty, remove the field
if (!values[field]) {
Reflect.deleteProperty(values, field);
continue;
}
const [startTime, endTime]: string[] = values[field];
const [startTimeFormat, endTimeFormat] = Array.isArray(format) ? format : [format, format];
values[startTimeKey] = dateUtil(startTime).format(startTimeFormat);
values[endTimeKey] = dateUtil(endTime).format(endTimeFormat);
Reflect.deleteProperty(values, field);
}
return values;
} | /**
* @description: Processing time interval parameters
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Form/src/hooks/useFormValues.ts#L97-L124 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | resetKeys | function resetKeys() {
menuState.selectedKeys = [];
menuState.openKeys = [];
} | /**
* @description: 重置值
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Menu/src/useOpenKeys.ts#L51-L54 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getOriginWidth | function getOriginWidth(content: ContentType, options: QRCodeRenderersOptions) {
const _canvas = document.createElement('canvas');
return toCanvas(_canvas, content, options).then(() => _canvas.width);
} | // 得到原QrCode的大小,以便缩放得到正确的QrCode大小 | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Qrcode/src/drawCanvas.ts#L23-L26 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getErrorCorrectionLevel | function getErrorCorrectionLevel(content: ContentType) {
if (content.length > 36) {
return 'M';
} else if (content.length > 16) {
return 'Q';
} else {
return 'H';
}
} | // 对于内容少的QrCode,增大容错率 | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Qrcode/src/drawCanvas.ts#L29-L37 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | drawLogoWithImage | const drawLogoWithImage = (image: CanvasImageSource) => {
ctx.drawImage(image, logoXY, logoXY, logoWidth, logoWidth);
}; | // 使用image绘制可以避免某些跨域情况 | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Qrcode/src/drawLogo.ts#L42-L44 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | drawLogoWithCanvas | const drawLogoWithCanvas = (image: HTMLImageElement) => {
const canvasImage = document.createElement('canvas');
canvasImage.width = logoXY + logoWidth;
canvasImage.height = logoXY + logoWidth;
const imageCanvas = canvasImage.getContext('2d');
if (!imageCanvas || !ctx) return;
imageCanvas.drawImage(image, logoXY, logoXY, logoWidth, logoWidth);
canvasRoundRect(ctx)(logoXY, logoXY, logoWidth, logoWidth, logoRadius);
if (!ctx) return;
const fillStyle = ctx.createPattern(canvasImage, 'no-repeat');
if (fillStyle) {
ctx.fillStyle = fillStyle;
ctx.fill();
}
}; | // 使用canvas绘制以获得更多的功能 | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Qrcode/src/drawLogo.ts#L47-L62 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | canvasRoundRect | function canvasRoundRect(ctx: CanvasRenderingContext2D) {
return (x: number, y: number, w: number, h: number, r: number) => {
const minSize = Math.min(w, h);
if (r > minSize / 2) {
r = minSize / 2;
}
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
return ctx;
};
} | // copy来的方法,用于绘制圆角 | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Qrcode/src/drawLogo.ts#L74-L89 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | setColumns | function setColumns(columnList: Partial<BasicColumn>[] | (string | string[])[]) {
const columns = cloneDeep(columnList);
if (!isArray(columns)) return;
if (columns.length <= 0) {
columnsRef.value = [];
return;
}
const firstColumn = columns[0];
const cacheKeys = cacheColumns.map((item) => item.dataIndex);
if (!isString(firstColumn) && !isArray(firstColumn)) {
columnsRef.value = columns as BasicColumn[];
} else {
const columnKeys = (columns as (string | string[])[]).map((m) => m.toString());
const newColumns: BasicColumn[] = [];
cacheColumns.forEach((item) => {
newColumns.push({
...item,
defaultHidden: !columnKeys.includes(item.dataIndex?.toString() || (item.key as string)),
});
});
// Sort according to another array
if (!isEqual(cacheKeys, columns)) {
newColumns.sort((prev, next) => {
return (
columnKeys.indexOf(prev.dataIndex?.toString() as string) -
columnKeys.indexOf(next.dataIndex?.toString() as string)
);
});
}
columnsRef.value = newColumns;
}
} | /**
* set columns
* @param columnList key|column
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Table/src/hooks/useColumns.ts#L207-L242 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getEnabledKeys | function getEnabledKeys(list?: TreeDataItem[]) {
const keys: string[] = [];
const treeData = list || unref(treeDataRef);
const { key: keyField, children: childrenField } = unref(getFieldNames);
if (!childrenField || !keyField) return keys;
for (let index = 0; index < treeData.length; index++) {
const node = treeData[index];
node.disabled !== true && node.selectable !== false && keys.push(node[keyField]!);
const children = node[childrenField];
if (children && children.length) {
keys.push(...(getEnabledKeys(children) as string[]));
}
}
return keys as KeyType[];
} | // get keys that can be checked and selected | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Tree/src/hooks/useTree.ts#L28-L43 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | updateNodeByKey | function updateNodeByKey(key: string, node: TreeDataItem, list?: TreeDataItem[]) {
if (!key) return;
const treeData = list || unref(treeDataRef);
const { key: keyField, children: childrenField } = unref(getFieldNames);
if (!childrenField || !keyField) return;
for (let index = 0; index < treeData.length; index++) {
const element: any = treeData[index];
const children = element[childrenField];
if (element[keyField] === key) {
treeData[index] = { ...treeData[index], ...node };
break;
} else if (children && children.length) {
updateNodeByKey(key, node, element[childrenField]);
}
}
} | // Update node | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Tree/src/hooks/useTree.ts#L68-L86 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | filterByLevel | function filterByLevel(level = 1, list?: TreeDataItem[], currentLevel = 1) {
if (!level) {
return [];
}
const res: (string | number)[] = [];
const data = list || unref(treeDataRef) || [];
for (let index = 0; index < data.length; index++) {
const item = data[index];
const { key: keyField, children: childrenField } = unref(getFieldNames);
const key = keyField ? item[keyField] : '';
const children = childrenField ? item[childrenField] : [];
res.push(key);
if (children && children.length && currentLevel < level) {
currentLevel += 1;
res.push(...filterByLevel(level, children, currentLevel));
}
}
return res as string[] | number[];
} | // Expand the specified level | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Tree/src/hooks/useTree.ts#L89-L108 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | insertNodeByKey | function insertNodeByKey({ parentKey = null, node, push = 'push' }: InsertNodeParams) {
const treeData: any = cloneDeep(unref(treeDataRef));
if (!parentKey) {
treeData[push](node);
treeDataRef.value = treeData;
return;
}
const { key: keyField, children: childrenField } = unref(getFieldNames);
if (!childrenField || !keyField) return;
forEach(treeData, (treeItem) => {
if (treeItem[keyField] === parentKey) {
treeItem[childrenField] = treeItem[childrenField] || [];
treeItem[childrenField][push](node);
return true;
}
});
treeDataRef.value = treeData;
} | /**
* 添加节点
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Tree/src/hooks/useTree.ts#L113-L131 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | insertNodesByKey | function insertNodesByKey({ parentKey = null, list, push = 'push' }: InsertNodeParams) {
const treeData: any = cloneDeep(unref(treeDataRef));
if (!list || list.length < 1) {
return;
}
if (!parentKey) {
for (let i = 0; i < list.length; i++) {
treeData[push](list[i]);
}
treeDataRef.value = treeData;
return;
} else {
const { key: keyField, children: childrenField } = unref(getFieldNames);
if (!childrenField || !keyField) return;
forEach(treeData, (treeItem) => {
if (treeItem[keyField] === parentKey) {
treeItem[childrenField] = treeItem[childrenField] || [];
for (let i = 0; i < list.length; i++) {
treeItem[childrenField][push](list[i]);
}
treeDataRef.value = treeData;
return true;
}
});
}
} | /**
* 批量添加节点
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Tree/src/hooks/useTree.ts#L135-L161 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | deleteNodeByKey | function deleteNodeByKey(key: string, list?: TreeDataItem[]) {
if (!key) return;
const treeData = list || unref(treeDataRef);
const { key: keyField, children: childrenField } = unref(getFieldNames);
if (!childrenField || !keyField) return;
for (let index = 0; index < treeData.length; index++) {
const element: any = treeData[index];
const children = element[childrenField];
if (element[keyField] === key) {
treeData.splice(index, 1);
break;
} else if (children && children.length) {
deleteNodeByKey(key, element[childrenField]);
}
}
} | // Delete node | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Tree/src/hooks/useTree.ts#L163-L180 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getSelectedNode | function getSelectedNode(key: KeyType, list?: TreeItem[], selectedNode?: TreeItem | null) {
if (!key && key !== 0) return null;
const treeData = list || unref(treeDataRef);
const { key: keyField, children: childrenField } = unref(getFieldNames);
if (!keyField) return;
treeData.forEach((item) => {
if (selectedNode?.key || selectedNode?.key === 0) return selectedNode;
if (item[keyField] === key) {
selectedNode = item;
return;
}
if (item[childrenField!] && item[childrenField!].length) {
selectedNode = getSelectedNode(key, item[childrenField!], selectedNode);
}
});
return selectedNode || null;
} | // Get selected node | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/Tree/src/hooks/useTree.ts#L183-L199 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getModelKey | function getModelKey(renderOpts: VxeGlobalRendererHandles.RenderOptions) {
let prop = 'value';
switch (renderOpts.name) {
case 'ASwitch':
prop = 'checked';
break;
}
return prop;
} | /**
* @description: 获取组件传值所接受的属性
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/VxeTable/src/components/common.tsx#L43-L51 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getModelEvent | function getModelEvent(renderOpts: VxeGlobalRendererHandles.RenderOptions) {
let type = 'update:value';
switch (renderOpts.name) {
case 'ASwitch':
type = 'update:checked';
break;
}
return type;
} | /**
* @description: 回去双向更新的方法
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/VxeTable/src/components/common.tsx#L56-L64 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getChangeEvent | function getChangeEvent() {
return 'change';
} | /**
* @description: chang值改变方法
* @param {}
* @return {*}
* @author: *
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/VxeTable/src/components/common.tsx#L72-L74 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getEventTargetNode | function getEventTargetNode(evnt: any, container: HTMLElement, className: string) {
let targetElem;
let target = evnt.target;
while (target && target.nodeType && target !== document) {
if (
className &&
target.className &&
target.className.split &&
target.className.split(' ').indexOf(className) > -1
) {
targetElem = target;
} else if (target === container) {
return { flag: className ? !!targetElem : true, container, targetElem: targetElem };
}
target = target.parentNode;
}
return { flag: false };
} | /**
* 检查触发源是否属于目标节点
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/VxeTable/src/components/index.tsx#L28-L45 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleClearEvent | function handleClearEvent(
params:
| VxeGlobalInterceptorHandles.InterceptorClearFilterParams
| VxeGlobalInterceptorHandles.InterceptorClearActivedParams
| VxeGlobalInterceptorHandles.InterceptorClearAreasParams,
) {
const { $event } = params;
const bodyElem = document.body;
if (
// 下拉框
getEventTargetNode($event, bodyElem, 'ant-select-dropdown').flag ||
// 级联
getEventTargetNode($event, bodyElem, 'ant-cascader-menus').flag ||
// 日期
getEventTargetNode($event, bodyElem, 'ant-calendar-picker-container').flag ||
// 时间选择
getEventTargetNode($event, bodyElem, 'ant-time-picker-panel').flag
) {
return false;
}
} | /**
* 事件兼容性处理
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/components/VxeTable/src/components/index.tsx#L50-L70 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | remove | let remove: RemoveEventFn = () => {}; | /* eslint-disable-next-line */ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/hooks/event/useEventListener.ts#L25-L25 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | setHeaderSetting | function setHeaderSetting(headerSetting: Partial<HeaderSetting>) {
appStore.setProjectConfig({ headerSetting });
} | // Set header configuration | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/hooks/setting/useHeaderSetting.ts#L82-L84 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | setMenuSetting | function setMenuSetting(menuSetting: Partial<MenuSetting>): void {
appStore.setMenuSetting(menuSetting);
} | // Set menu configuration | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/hooks/setting/useMenuSetting.ts#L125-L127 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | calcCompensationHeight | const calcCompensationHeight = () => {
compensationHeight.elements?.forEach((item) => {
height += getEl(unref(item))?.offsetHeight ?? 0;
});
}; | // compensation height | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/hooks/web/useContentHeight.ts#L152-L156 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | createConfirm | function createConfirm(options: ModalOptionsEx): ConfirmOptions {
const iconType = options.iconType || 'warning';
Reflect.deleteProperty(options, 'iconType');
const opt: ModalFuncProps = {
centered: true,
icon: getIcon(iconType),
...options,
content: renderContent(options),
};
return Modal.confirm(opt) as unknown as ConfirmOptions;
} | /**
* @description: Create confirmation box
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/hooks/web/useMessage.tsx#L58-L68 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | togglePermissionMode | async function togglePermissionMode() {
appStore.setProjectConfig({
permissionMode:
appStore.projectConfig?.permissionMode === PermissionModeEnum.BACK
? PermissionModeEnum.ROUTE_MAPPING
: PermissionModeEnum.BACK,
});
location.reload();
} | /**
* Change permission mode
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/hooks/web/usePermission.ts#L30-L38 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | resume | async function resume() {
const tabStore = useMultipleTabStore();
tabStore.clearCacheTabs();
resetRouter();
const routes = await permissionStore.buildRoutesAction();
routes.forEach((route) => {
router.addRoute(route as unknown as RouteRecordRaw);
});
permissionStore.setLastBuildMenuTime();
closeAll();
} | /**
* Reset and regain authority resource information
* 重置和重新获得权限资源信息
* @param id
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/hooks/web/usePermission.ts#L45-L55 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | hasPermission | function hasPermission(value?: RoleEnum | RoleEnum[] | string | string[], def = true): boolean {
// Visible by default
if (!value) {
return def;
}
const permMode = projectSetting.permissionMode;
if ([PermissionModeEnum.ROUTE_MAPPING, PermissionModeEnum.ROLE].includes(permMode)) {
if (!isArray(value)) {
return userStore.getRoleList?.includes(value as RoleEnum);
}
return (intersection(value, userStore.getRoleList) as RoleEnum[]).length > 0;
}
if (PermissionModeEnum.BACK === permMode) {
const allCodeList = permissionStore.getPermCodeList as string[];
if (!isArray(value)) {
return allCodeList.includes(value);
}
return (intersection(value, allCodeList) as string[]).length > 0;
}
return true;
} | /**
* Determine whether there is permission
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/hooks/web/usePermission.ts#L60-L83 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | changeRole | async function changeRole(roles: RoleEnum | RoleEnum[]): Promise<void> {
if (projectSetting.permissionMode !== PermissionModeEnum.ROUTE_MAPPING) {
throw new Error(
'Please switch PermissionModeEnum to ROUTE_MAPPING mode in the configuration to operate!',
);
}
if (!isArray(roles)) {
roles = [roles];
}
userStore.setRoleList(roles);
await resume();
} | /**
* Change roles
* @param roles
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/hooks/web/usePermission.ts#L89-L101 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | refreshMenu | async function refreshMenu() {
resume();
} | /**
* refresh menu data
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/hooks/web/usePermission.ts#L106-L108 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleSplitLeftMenu | async function handleSplitLeftMenu(parentPath: string) {
if (unref(getSplitLeft) || unref(getIsMobile)) return;
// spilt mode left
const children = await getChildrenMenus(parentPath);
if (!children || !children.length) {
setMenuSetting({ hidden: true });
menusRef.value = [];
return;
}
setMenuSetting({ hidden: false });
menusRef.value = children;
} | // Handle left menu split | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/layouts/default/menu/useLayoutMenu.ts#L75-L89 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | genMenus | async function genMenus() {
// normal mode
if (unref(normalType) || unref(getIsMobile)) {
menusRef.value = await getMenus();
return;
}
// split-top
if (unref(getSpiltTop)) {
const shallowMenus = await getShallowMenus();
menusRef.value = shallowMenus;
return;
}
} | // get menus | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/layouts/default/menu/useLayoutMenu.ts#L92-L106 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | removeMouseup | function removeMouseup(ele: any) {
const wrap = getEl(siderRef);
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
wrap.style.transition = 'width 0.2s';
const width = parseInt(wrap.style.width);
if (!mix) {
const miniWidth = unref(getMiniWidthNumber);
if (!unref(getCollapsed)) {
width > miniWidth + 20
? setMenuSetting({ menuWidth: width })
: setMenuSetting({ collapsed: true });
} else {
width > miniWidth && setMenuSetting({ collapsed: false, menuWidth: width });
}
} else {
setMenuSetting({ menuWidth: width });
}
ele.releaseCapture?.();
};
} | // Drag and drop in the menu area-release the mouse | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/layouts/default/sider/useLayoutSider.ts#L100-L123 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | filterAffixTabs | function filterAffixTabs(routes: RouteLocationNormalized[]) {
const tabs: RouteLocationNormalized[] = [];
routes &&
routes.forEach((route) => {
if (route.meta && route.meta.affix) {
tabs.push(toRaw(route));
}
});
return tabs;
} | /**
* @description: Filter all fixed routes
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/layouts/default/tabs/useMultipleTabs.ts#L18-L27 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | addAffixTabs | function addAffixTabs(): void {
const affixTabs = filterAffixTabs(router.getRoutes() as unknown as RouteLocationNormalized[]);
affixList.value = affixTabs;
for (const tab of affixTabs) {
tabStore.addTab({
meta: tab.meta,
name: tab.name,
path: tab.path,
} as unknown as RouteLocationNormalized);
}
} | /**
* @description: Set fixed tabs
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/layouts/default/tabs/useMultipleTabs.ts#L32-L42 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | handleMenuEvent | function handleMenuEvent(menu: DropMenu): void {
const { event } = menu;
switch (event) {
case MenuEventEnum.REFRESH_PAGE:
// refresh page
refreshPage();
break;
// Close current
case MenuEventEnum.CLOSE_CURRENT:
close(tabContentProps.tabItem);
break;
// Close left
case MenuEventEnum.CLOSE_LEFT:
closeLeft();
break;
// Close right
case MenuEventEnum.CLOSE_RIGHT:
closeRight();
break;
// Close other
case MenuEventEnum.CLOSE_OTHER:
closeOther();
break;
// Close all
case MenuEventEnum.CLOSE_ALL:
closeAll();
break;
}
} | // Handle right click event | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/layouts/default/tabs/useTabDropdown.ts#L110-L138 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | changeLocale | async function changeLocale(locale: LocaleType) {
const globalI18n = i18n.global;
const currentLocale = unref(globalI18n.locale);
if (currentLocale === locale) {
return locale;
}
if (loadLocalePool.includes(locale)) {
setI18nLanguage(locale);
return locale;
}
const langModule = ((await import(`./lang/${locale}.ts`)) as any).default as LangModule;
if (!langModule) return;
const { message } = langModule;
globalI18n.setLocaleMessage(locale, message);
loadLocalePool.push(locale);
setI18nLanguage(locale);
return locale;
} | // Switching the language will change the locale of useI18n | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/locales/useLocale.ts#L40-L61 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | processStackMsg | function processStackMsg(error: Error) {
if (!error.stack) {
return '';
}
let stack = error.stack
.replace(/\n/gi, '') // Remove line breaks to save the size of the transmitted content
.replace(/\bat\b/gi, '@') // At in chrome, @ in ff
.split('@') // Split information with @
.slice(0, 9) // The maximum stack length (Error.stackTraceLimit = 10), so only take the first 10
.map((v) => v.replace(/^\s*|\s*$/g, '')) // Remove extra spaces
.join('~') // Manually add separators for later display
.replace(/\?[^:]+/gi, ''); // Remove redundant parameters of js file links (?x=1 and the like)
const msg = error.toString();
if (stack.indexOf(msg) < 0) {
stack = msg + '@' + stack;
}
return stack;
} | /**
* Handling error stack information
* @param error
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/logics/error-handle/index.ts#L17-L34 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | formatComponentName | function formatComponentName(vm: any) {
if (vm.$root === vm) {
return {
name: 'root',
path: 'root',
};
}
const options = vm.$options as any;
if (!options) {
return {
name: 'anonymous',
path: 'anonymous',
};
}
const name = options.name || options._componentTag;
return {
name: name,
path: options.__file,
};
} | /**
* get comp name
* @param vm
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/logics/error-handle/index.ts#L40-L60 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | vueErrorHandler | function vueErrorHandler(err: Error, vm: any, info: string) {
const errorLogStore = useErrorLogStoreWithOut();
const { name, path } = formatComponentName(vm);
errorLogStore.addErrorLogInfo({
type: ErrorTypeEnum.VUE,
name,
file: path,
message: err.message,
stack: processStackMsg(err),
detail: info,
url: window.location.href,
});
} | /**
* Configure Vue error handling function
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/logics/error-handle/index.ts#L66-L78 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | registerPromiseErrorHandler | function registerPromiseErrorHandler() {
window.addEventListener(
'unhandledrejection',
function (event) {
const errorLogStore = useErrorLogStoreWithOut();
errorLogStore.addErrorLogInfo({
type: ErrorTypeEnum.PROMISE,
name: 'Promise Error!',
file: 'none',
detail: 'promise error!',
url: window.location.href,
stack: 'promise error!',
message: event.reason,
});
},
true,
);
} | /**
* Configure Promise error handling function
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/logics/error-handle/index.ts#L117-L134 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | registerResourceErrorHandler | function registerResourceErrorHandler() {
// Monitoring resource loading error(img,script,css,and jsonp)
window.addEventListener(
'error',
function (e: Event) {
const target = e.target ? e.target : (e.srcElement as any);
const errorLogStore = useErrorLogStoreWithOut();
errorLogStore.addErrorLogInfo({
type: ErrorTypeEnum.RESOURCE,
name: 'Resource Error!',
file: (e.target || ({} as any)).currentSrc,
detail: JSON.stringify({
tagName: target.localName,
html: target.outerHTML,
type: e.type,
}),
url: window.location.href,
stack: 'resource is not found',
message: (e.target || ({} as any)).localName + ' is load error',
});
},
true,
);
} | /**
* Configure monitoring resource loading error handling function
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/logics/error-handle/index.ts#L139-L162 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | createPageGuard | function createPageGuard(router: Router) {
const loadedPageMap = new Map<string, boolean>();
router.beforeEach(async (to) => {
// The page has already been loaded, it will be faster to open it again, you don’t need to do loading and other processing
to.meta.loaded = !!loadedPageMap.get(to.path);
// Notify routing changes
setRouteChange(to);
return true;
});
router.afterEach((to) => {
loadedPageMap.set(to.path, true);
});
} | /**
* Hooks for handling page state
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/router/guard/index.ts#L32-L47 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | createPageLoadingGuard | function createPageLoadingGuard(router: Router) {
const userStore = useUserStoreWithOut();
const appStore = useAppStoreWithOut();
const { getOpenPageLoading } = useTransitionSetting();
router.beforeEach(async (to) => {
if (!userStore.getToken) {
return true;
}
if (to.meta.loaded) {
return true;
}
if (unref(getOpenPageLoading)) {
appStore.setPageLoadingAction(true);
return true;
}
return true;
});
router.afterEach(async () => {
if (unref(getOpenPageLoading)) {
// TODO Looking for a better way
// The timer simulates the loading time to prevent flashing too fast,
setTimeout(() => {
appStore.setPageLoading(false);
}, 220);
}
return true;
});
} | // Used to handle page loading status | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/router/guard/index.ts#L50-L79 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | createHttpGuard | function createHttpGuard(router: Router) {
const { removeAllHttpPending } = projectSetting;
let axiosCanceler: Nullable<AxiosCanceler>;
if (removeAllHttpPending) {
axiosCanceler = new AxiosCanceler();
}
router.beforeEach(async () => {
// Switching the route will delete the previous request
axiosCanceler?.removeAllPending();
return true;
});
} | /**
* The interface used to close the current page to complete the request when the route is switched
* @param router
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/router/guard/index.ts#L85-L96 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | createScrollGuard | function createScrollGuard(router: Router) {
const isHash = (href: string) => {
return /^#/.test(href);
};
const body = document.body;
router.afterEach(async (to) => {
// scroll top
isHash((to as RouteLocationNormalized & { href: string })?.href) && body.scrollTo(0, 0);
return true;
});
} | // Routing switch back to the top | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/router/guard/index.ts#L99-L111 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | joinParentPath | function joinParentPath(menus: Menu[], parentPath = '') {
for (let index = 0; index < menus.length; index++) {
const menu = menus[index];
// https://next.router.vuejs.org/guide/essentials/nested-routes.html
// Note that nested paths that start with / will be treated as a root path.
// 请注意,以 / 开头的嵌套路径将被视为根路径。
// This allows you to leverage the component nesting without having to use a nested URL.
// 这允许你利用组件嵌套,而无需使用嵌套 URL。
if (!(menu.path.startsWith('/') || isUrl(menu.path))) {
// path doesn't start with /, nor is it a url, join parent path
// 路径不以 / 开头,也不是 url,加入父路径
menu.path = `${parentPath}/${menu.path}`;
}
if (menu?.children?.length) {
joinParentPath(menu.children, menu.meta?.hidePathForChildren ? parentPath : menu.path);
}
}
} | // 路径处理 | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/router/helper/menuHelper.ts#L15-L32 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | asyncImportRoute | function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) {
dynamicViewsModules = dynamicViewsModules || import.meta.glob('../../views/**/*.{vue,tsx}');
if (!routes) return;
routes.forEach((item) => {
if (!item.component && item.meta?.frameSrc) {
item.component = 'IFRAME';
}
const { component, name } = item;
const { children } = item;
if (component) {
const layoutFound = LayoutMap.get(component.toUpperCase());
if (layoutFound) {
item.component = layoutFound;
} else {
item.component = dynamicImport(dynamicViewsModules, component as string);
}
} else if (name) {
item.component = getParentLayout();
}
children && asyncImportRoute(children);
});
} | // Dynamic introduction | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/router/helper/routeHelper.ts#L19-L40 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | promoteRouteLevel | function promoteRouteLevel(routeModule: AppRouteModule) {
// Use vue-router to splice menus
// 使用vue-router拼接菜单
// createRouter 创建一个可以被 Vue 应用程序使用的路由实例
let router: Router | null = createRouter({
routes: [routeModule as unknown as RouteRecordNormalized],
history: createWebHistory(),
});
// getRoutes: 获取所有 路由记录的完整列表。
const routes = router.getRoutes();
// 将所有子路由添加到二级路由
addToChildren(routes, routeModule.children || [], routeModule);
router = null;
// omit lodash的函数 对传入的item对象的children进行删除
routeModule.children = routeModule.children?.map((item) => omit(item, 'children'));
} | // Routing level upgrade | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/router/helper/routeHelper.ts#L117-L133 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | addToChildren | function addToChildren(
routes: RouteRecordNormalized[],
children: AppRouteRecordRaw[],
routeModule: AppRouteModule,
) {
for (let index = 0; index < children.length; index++) {
const child = children[index];
const route = routes.find((item) => item.name === child.name);
if (!route) {
continue;
}
routeModule.children = routeModule.children || [];
if (!routeModule.children.find((item) => item.name === route.name)) {
routeModule.children?.push(route as unknown as AppRouteModule);
}
if (child.children?.length) {
addToChildren(routes, child.children, routeModule);
}
}
} | // Add all sub-routes to the secondary route | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/router/helper/routeHelper.ts#L137-L156 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | isMultipleRoute | function isMultipleRoute(routeModule: AppRouteModule) {
// Reflect.has 与 in 操作符 相同, 用于检查一个对象(包括它原型链上)是否拥有某个属性
if (!routeModule || !Reflect.has(routeModule, 'children') || !routeModule.children?.length) {
return false;
}
const children = routeModule.children;
let flag = false;
for (let index = 0; index < children.length; index++) {
const child = children[index];
if (child.children?.length) {
flag = true;
break;
}
}
return flag;
} | // Determine whether the level exceeds 2 levels | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/router/helper/routeHelper.ts#L160-L177 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getPermissionMode | const getPermissionMode = () => {
const appStore = useAppStoreWithOut();
return appStore.getProjectConfig.permissionMode;
}; | // =========================== | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/router/menus/index.ts#L27-L30 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | menuFilter | const menuFilter = (items) => {
return items.filter((item) => {
const show = !item.meta?.hideMenu && !item.hideMenu;
if (show && item.children) {
item.children = menuFilter(item.children);
}
return show;
});
}; | //递归过滤所有隐藏的菜单 | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/router/menus/index.ts#L57-L65 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | routeFilter | const routeFilter = (route: AppRouteRecordRaw) => {
const { meta } = route;
// 抽出角色
const { roles } = meta || {};
if (!roles) return true;
// 进行角色权限判断
return roleList.some((role) => roles.includes(role));
}; | // 路由过滤器 在 函数filter 作为回调传入遍历使用 | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/store/modules/permission.ts#L122-L129 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | patchHomeAffix | const patchHomeAffix = (routes: AppRouteRecordRaw[]) => {
if (!routes || routes.length === 0) return;
let homePath: string = userStore.getUserInfo.homePath || PageEnum.BASE_HOME;
function patcher(routes: AppRouteRecordRaw[], parentPath = '') {
if (parentPath) parentPath = parentPath + '/';
routes.forEach((route: AppRouteRecordRaw) => {
const { path, children, redirect } = route;
const currentPath = path.startsWith('/') ? path : parentPath + path;
if (currentPath === homePath) {
if (redirect) {
homePath = route.redirect! as string;
} else {
route.meta = Object.assign({}, route.meta, { affix: true });
throw new Error('end');
}
}
children && children.length > 0 && patcher(children, currentPath);
});
}
try {
patcher(routes);
} catch (e) {
// 已处理完毕跳出循环
}
return;
}; | /**
* @description 根据设置的首页path,修正routes中的affix标记(固定首页)
* */ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/store/modules/permission.ts#L142-L169 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | addLight | function addLight(color: string, amount: number) {
const cc = parseInt(color, 16) + amount;
const c = cc > 255 ? 255 : cc;
return c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`;
} | /* Suma el porcentaje indicado a un color (RR, GG o BB) hexadecimal para aclararlo */ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/color.ts#L98-L102 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | luminanace | function luminanace(r: number, g: number, b: number) {
const a = [r, g, b].map((v) => {
v /= 255;
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
});
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
} | /**
* Calculates luminance of an rgb color
* @param {number} r red
* @param {number} g green
* @param {number} b blue
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/color.ts#L110-L116 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | contrast | function contrast(rgb1: string[], rgb2: number[]) {
return (
(luminanace(~~rgb1[0], ~~rgb1[1], ~~rgb1[2]) + 0.05) /
(luminanace(rgb2[0], rgb2[1], rgb2[2]) + 0.05)
);
} | /**
* Calculates contrast between two rgb colors
* @param {string} rgb1 rgb color 1
* @param {string} rgb2 rgb color 2
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/color.ts#L123-L128 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | subtractLight | function subtractLight(color: string, amount: number) {
const cc = parseInt(color, 16) - amount;
const c = cc < 0 ? 0 : cc;
return c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`;
} | /**
* Subtracts the indicated percentage to the R, G or B of a HEX color
* @param {string} color The color to change
* @param {number} amount The amount to change the color by
* @returns {string} The processed part of the color
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/color.ts#L147-L151 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | propTypes.style | static get style() {
return toValidableType('style', {
type: [String, Object],
});
} | // a native-like validator that supports the `.validable` method | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/propTypes.ts#L23-L27 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | Memory.get | get<K extends keyof T>(key: K) {
return this.cache[key];
} | // } | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/cache/memory.ts#L36-L38 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | resizeHandler | function resizeHandler(entries: any[]) {
for (const entry of entries) {
const listeners = entry.target.__resizeListeners__ || [];
if (listeners.length) {
listeners.forEach((fn: () => any) => {
fn();
});
}
}
} | /* istanbul ignore next */ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/event/index.ts#L6-L15 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | getConfig | const getConfig = (config: Partial<TreeHelperConfig>) => Object.assign({}, DEFAULT_CONFIG, config); | // 获取配置。 Object.assign 从一个或多个源对象复制到目标对象 | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/helper/treeHelper.ts#L15-L15 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | VAxios.createAxios | private createAxios(config: CreateAxiosOptions): void {
this.axiosInstance = axios.create(config);
} | /**
* @description: Create axios instance
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/Axios.ts#L36-L38 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.