Skip to content

Commit

Permalink
perf: optimize some code
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Mar 3, 2024
1 parent 26aa5c7 commit f9c5eaf
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 354 deletions.
3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"mrmlnc.vscode-less",
"lokalise.i18n-ally",
"antfu.iconify",
"mikestead.dotenv",
"heybourn.headwind"
"mikestead.dotenv"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"tinymce": "^6.8.3",
"vue": "~3.4.21",
"vue-echarts": "^6.6.9",
"vue-i18n": "9.9.1",
"vue-i18n": "9.10.1",
"vue-router": "~4.3.0",
"vue-types": "~5.1.1",
"vue-virtual-scroller": "2.0.0-beta.8",
Expand Down
33 changes: 21 additions & 12 deletions packages/vite-plugin-tinymce-resource/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ let base: string;
type Options = {
/** Public Dir */
baseUrl: string;
/** 要复制的目标文件夹 */
destDir?: string;
/**
* 要复制的目标文件夹
* @default: ['skins/content/default', 'skins/ui/oxide', 'skins/ui/oxide-dark']
**/
destDir?: string | string[];
};

const defaultDestDir = ['skins/content/default', 'skins/ui/oxide', 'skins/ui/oxide-dark'] as const;

export default (options: Options): Plugin => {
const { baseUrl, destDir = 'skins' } = options;
const { baseUrl, destDir = defaultDestDir } = options;

return {
name: 'vite-plugin-tinymce-resource',
Expand Down Expand Up @@ -44,16 +49,20 @@ export default (options: Options): Plugin => {
});
},
async closeBundle() {
const sourceDir = resolve(tinymceDir, destDir);
const destinationDir = resolve(outDir, `./${baseUrl}`, destDir);
// console.log(sourceDir);
// console.log(destinationDir);
Array<string>()
.concat(destDir)
.forEach(async (dir) => {
const sourceDir = resolve(tinymceDir, dir);
const destinationDir = resolve(outDir, `./${baseUrl}`, dir);
// console.log(sourceDir);
// console.log(destinationDir);

try {
await cp(sourceDir, destinationDir, { recursive: true, force: true });
} catch (error) {
console.error('[@admin-pkg/vite-plugin-tinymce-resource]: ', error);
}
try {
await cp(sourceDir, destinationDir, { recursive: true, force: true });
} catch (error) {
console.error('[@admin-pkg/vite-plugin-tinymce-resource]: ', error);
}
});
},
};
};
30 changes: 15 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import type { PropType } from 'vue';
import type { CustomRenderParams, EditableType } from '@/components/core/dynamic-table/src/types';
import { schemaFormItemProps, SchemaFormItem } from '@/components/core/schema-form';
import { isAsyncFunction } from '@/utils/is';
import { isFunction } from '@/utils/is';
const props = defineProps({
...schemaFormItemProps,
Expand Down Expand Up @@ -105,7 +105,7 @@
const handleSaveCell = async () => {
const { rowKey, column } = props;
await validateCell(rowKey!, dataIndex.value);
if (isAsyncFunction(tableContext?.onSave)) {
if (isFunction(tableContext?.onSave)) {
saving.value = true;
await tableContext
.onSave(rowKey!, editFormModel.value[rowKey!], column?.record)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import type { CustomRenderParams } from '../types/column';
import { hasPermission } from '@/permission';
import { Icon } from '@/components/basic/icon';
import { isAsyncFunction } from '@/utils/is';
const ActionItemRender: FunctionalComponent<ActionItem> = (action, { slots }) => {
const { popConfirm, tooltip } = action;
Expand Down Expand Up @@ -88,7 +87,7 @@
.map((item, index) => {
const onClick = item.onClick;
if (isAsyncFunction(onClick) && !hasClickFnFlag(onClick)) {
if (isFunction(onClick) && !hasClickFnFlag(onClick)) {
item.onClick = debounce(async () => {
const key = getKey(item, index);
loadingMap.value.set(key, true);
Expand All @@ -97,9 +96,6 @@
});
});
setClickFnFlag(item.onClick);
} else if (isFunction(onClick) && !hasClickFnFlag(onClick)) {
item.onClick = debounce(onClick);
setClickFnFlag(item.onClick);
}
if (item.icon) {
item.icon = <Icon icon={item.icon} class={{ 'mr-1': !!item.label }} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
import type { TableColumn } from '../../types/column';
import Checkbox from '@/components/basic/check-box/index.vue';
import { useSortable } from '@/hooks/useSortable';
import { isNullAndUnDef } from '@/utils/is';
import { isNil } from '@/utils/is';
import { useI18n } from '@/hooks/useI18n';
const { t } = useI18n();
Expand Down Expand Up @@ -159,7 +159,7 @@
onEnd: (evt) => {
const { oldIndex, newIndex } = evt;
if (isNullAndUnDef(oldIndex) || isNullAndUnDef(newIndex) || oldIndex === newIndex) {
if (isNil(oldIndex) || isNil(newIndex) || oldIndex === newIndex) {
return;
}
// Sort column
Expand Down
4 changes: 2 additions & 2 deletions src/components/core/schema-form/src/hooks/useFormMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { set } from 'lodash-es';
import type { FormState } from './useFormState';
import type { SchemaFormProps } from '../schema-form';
import { deepMerge } from '@/utils/';
import { isFunction, isNullOrUnDef, isObject, isArray, isString } from '@/utils/is';
import { isFunction, isDef, isObject, isArray, isString } from '@/utils/is';
import { dateUtil } from '@/utils/dateUtil';

type UseFormMethodsContext = FormState;
Expand Down Expand Up @@ -107,7 +107,7 @@ export const useFormMethods = (formMethodsContext: UseFormMethodsContext) => {
const initFormValues = () => {
unref(formPropsRef).schemas?.forEach((item) => {
const { defaultValue } = item;
if (!isNullOrUnDef(defaultValue)) {
if (isDef(defaultValue)) {
formModel[item.field] = defaultValue;
defaultFormValues[item.field] = defaultValue;
cacheFormModel[item.field] = defaultValue;
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/event/useScrollTo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ref, unref } from 'vue';
import { isFunction, isUnDef } from '@/utils/is';
import { isFunction, isDef } from '@/utils/is';

export interface ScrollToParams {
el: any;
Expand Down Expand Up @@ -29,7 +29,7 @@ export function useScrollTo({ el, to, duration = 500, callback }: ScrollToParams
const change = to - start;
const increment = 20;
let currentTime = 0;
duration = isUnDef(duration) ? 500 : duration;
duration = isDef(duration) ? duration : 500;

const animateScroll = function () {
if (!unref(isActiveRef)) {
Expand Down
5 changes: 4 additions & 1 deletion src/layout/tabs/tabs-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
@after-leave="overflow = 'auto'"
>
<keep-alive :include="keepAliveComponents">
<component :is="Component" :key="route.fullPath" />
<Suspense>
<component :is="Component" :key="route.fullPath" />
<template #fallback> 正在加载... </template>
</Suspense>
</keep-alive>
</Transition>
</template>
Expand Down
64 changes: 64 additions & 0 deletions src/utils/is.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export {
isArguments,
isArrayBuffer,
isArrayLike,
isArrayLikeObject,
isBuffer,
isBoolean,
isDate,
isElement,
isEmpty,
isEqual,
isEqualWith,
isError,
isFunction,
isFinite,
isLength,
isMap,
isMatch,
isMatchWith,
isNative,
isNil,
isNumber,
isNull,
isObjectLike,
isPlainObject,
isRegExp,
isSafeInteger,
isSet,
isString,
isSymbol,
isTypedArray,
isUndefined,
isWeakMap,
isWeakSet,
isObject,
isArray,
} from 'lodash-es';
const toString = Object.prototype.toString;

export function is(val: unknown, type: string) {
return toString.call(val) === `[object ${type}]`;
}

export function isDef<T = unknown>(val?: T): val is T {
return typeof val !== 'undefined';
}

export function isWindow(val: any): val is Window {
return typeof window !== 'undefined' && is(val, 'Window');
}

export const isServer = typeof window === 'undefined';

export const isClient = !isServer;

export function isHttpUrl(path: string): boolean {
const reg = /^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?/;
return reg.test(path);
}

export function isPascalCase(str: string): boolean {
const regex = /^[A-Z][A-Za-z]*$/;
return regex.test(str);
}
Loading

0 comments on commit f9c5eaf

Please sign in to comment.