Skip to content

Commit

Permalink
fix: ts fix
Browse files Browse the repository at this point in the history
  • Loading branch information
PengYYYYY committed Jun 12, 2022
1 parent 9742bf9 commit 082102c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
22 changes: 13 additions & 9 deletions src/tree-select/tree-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { InputValue } from '../input';
import FakeArrow from '../common-components/fake-arrow';

import { INodeOptions } from './interface';
import { TreeSelectValue, TdTreeSelectProps } from './type';
import { TreeSelectValue, TdTreeSelectProps, TreeSelectValueChangeTrigger } from './type';
import { TreeOptionData } from '../common';
import props from './props';

Expand All @@ -26,7 +26,7 @@ import useDefaultValue from '../hooks/useDefaultValue';
export default defineComponent({
name: 'TTreeSelect',
props,
setup(props, { slots }) {
setup(props: TdTreeSelectProps, { slots }) {
const renderTNodeJSX = useTNodeJSX();
const renderDefaultTNode = useTNodeDefault();
const classPrefix = usePrefixClass();
Expand Down Expand Up @@ -133,7 +133,7 @@ export default defineComponent({
// timelifes
onMounted(async () => {
if (!treeSelectValue.value && props.defaultValue) {
await change(props.defaultValue, null);
await change(props.defaultValue, null, 'uncheck');
}
if (isObjectValue.value) {
actived.value = isArray(treeSelectValue.value)
Expand All @@ -149,16 +149,20 @@ export default defineComponent({

// methods

const change = (valueParam: TreeSelectValue, node: TreeNodeModel<TreeOptionData>) => {
const change = (
valueParam: TreeSelectValue,
node: TreeNodeModel<TreeOptionData>,
trigger: TreeSelectValueChangeTrigger,
) => {
setTreeSelectValue(valueParam, { node });
changeNodeInfo();
props.onChange?.(valueParam, { node });
props.onChange?.(valueParam, { node, trigger });
};

const clear = (content: { e: MouseEvent }) => {
const defaultValue: TreeSelectValue = props.multiple ? [] : '';
actived.value = [];
change(defaultValue, null);
change(defaultValue, null, 'clear');
props.onClear?.({ e: content.e });
};

Expand All @@ -170,7 +174,7 @@ export default defineComponent({
if (isObjectValue.value) {
current = valueParam.map((nodeValue) => getTreeNode(props.data, nodeValue));
}
change(current, context.node);
change(current, context.node, 'check');
};

const treeNodeActive = (
Expand All @@ -193,7 +197,7 @@ export default defineComponent({
} else {
current = isEmpty(valueParam) ? '' : valueParam[0];
}
change(current, context.node);
change(current, context.node, 'check');
actived.value = valueParam;
};

Expand Down Expand Up @@ -230,7 +234,7 @@ export default defineComponent({
isArray(treeSelectValue.value) && (treeSelectValue.value as Array<TreeSelectValue>).splice(index, 1);
}
props.onRemove?.({ value, data: null, e: context && (context.e as MouseEvent) });
change(treeSelectValue.value, null);
change(treeSelectValue.value, null, trigger as 'tag-remove' | 'backspace');
};

const changeNodeInfo = async () => {
Expand Down
15 changes: 14 additions & 1 deletion src/tree/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computed } from 'vue';
import { computed, ComputedRef, Slots, InjectionKey } from 'vue';
import { usePrefixClass } from '../hooks/useConfig';
import { TdTreeProps } from './type';

export const useCLASSNAMES = () => {
const classPrefix = usePrefixClass();
Expand Down Expand Up @@ -39,3 +40,15 @@ export const useCLASSNAMES = () => {
};
});
};

export const injectKey: InjectionKey<
ComputedRef<{
checkProps: TdTreeProps['checkProps'];
icon: TdTreeProps['icon'];
label: TdTreeProps['label'];
line: TdTreeProps['line'];
operations: TdTreeProps['operations'];
disableCheck: TdTreeProps['disableCheck'];
scopedSlots: Slots;
}>
> = Symbol('treeProvider');
19 changes: 3 additions & 16 deletions src/tree/td-tree.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import { computed, defineComponent, ComputedRef, Slots, TransitionGroup, provide, InjectionKey } from 'vue';
import { computed, defineComponent, TransitionGroup, provide } from 'vue';

import props from './props';
import { useConfig } from '../hooks/useConfig';
import { useTNodeDefault } from '../hooks/tnode';
import { useCLASSNAMES } from './constants';
import { useCLASSNAMES, injectKey } from './constants';
import useTree from './useTree';
import useExposeFunc from './useExposeFunc';
import { TdTreeProps } from './type';

export const injectKey: InjectionKey<
ComputedRef<{
checkProps: TdTreeProps['checkProps'];
icon: TdTreeProps['icon'];
label: TdTreeProps['label'];
line: TdTreeProps['line'];
operations: TdTreeProps['operations'];
disableCheck: TdTreeProps['disableCheck'];
scopedSlots: Slots;
}>
> = Symbol('treeProvider');

export default defineComponent({
name: 'TTree',
Expand All @@ -45,7 +32,7 @@ export default defineComponent({
provide(injectKey, statusContext);

// tree核心逻辑
const { treeStore, treeNodeViews } = useTree(props, statusContext);
const { treeStore, treeNodeViews } = useTree(props);

// 导出方法
useExposeFunc(treeStore, expose);
Expand Down
3 changes: 1 addition & 2 deletions src/tree/tree-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import TLoading from '../loading';

import { getTNode } from './util';
import { TypeEventState, TreeNodeModel } from './interface';
import { useCLASSNAMES } from './constants';
import { useCLASSNAMES, injectKey } from './constants';
import TreeNode from '../_common/js/tree/tree-node';

import useRipple from '../hooks/useRipple';
import { useConfig } from '../hooks/useConfig';
import { injectKey } from './td-tree';

export default defineComponent({
name: 'TTreeNode',
Expand Down
5 changes: 2 additions & 3 deletions src/tree/useExposeFunc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Ref } from 'vue';
import upperFirst from 'lodash/upperFirst';
import TreeStore from '../_common/js/tree/tree-store';
import TreeNode from '../_common/js/tree/tree-node';
import { TreeOptionData } from '../common';
Expand All @@ -14,11 +15,9 @@ export default function useExposeFunc(treeStore: Ref<TreeStore>, expose: (expose
if (node && spec) {
['expanded', 'actived', 'checked'].forEach((name) => {
if (keys.includes(name)) {
// this[`set${upperFirst(name)}`](node, spec[name]);
// delete spec[name];
node[`set${upperFirst(name)}`](spec);
}
});
node.set(spec);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/tree/useTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getMark, getNode, getStoreConfig } from './util';

import { TypeEventState, TypeTreeNodeModel } from './interface';

export default function useTree(props: TdTreeProps, statusContext: any) {
export default function useTree(props: TdTreeProps) {
const treeStore = ref();
const cacheMap = new Map();
const treeNodeViews = ref([]);
Expand Down

0 comments on commit 082102c

Please sign in to comment.