parent
953bfc6f1a
commit
60577d6720
|
|
@ -1,3 +1,7 @@
|
||||||
|
### ✨ Features
|
||||||
|
|
||||||
|
- **BasicTree** 添加搜索功能相关属性和方法
|
||||||
|
|
||||||
### 🐛 Bug Fixes
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
- **Cropper** 修复未能及时销毁的问题
|
- **Cropper** 修复未能及时销毁的问题
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,14 @@
|
||||||
name: 'BasicTree',
|
name: 'BasicTree',
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
props: basicProps,
|
props: basicProps,
|
||||||
emits: ['update:expandedKeys', 'update:selectedKeys', 'update:value', 'change', 'check'],
|
emits: [
|
||||||
|
'update:expandedKeys',
|
||||||
|
'update:selectedKeys',
|
||||||
|
'update:value',
|
||||||
|
'change',
|
||||||
|
'check',
|
||||||
|
'update:searchValue',
|
||||||
|
],
|
||||||
setup(props, { attrs, slots, emit, expose }) {
|
setup(props, { attrs, slots, emit, expose }) {
|
||||||
const state = reactive<State>({
|
const state = reactive<State>({
|
||||||
checkStrictly: props.checkStrictly,
|
checkStrictly: props.checkStrictly,
|
||||||
|
|
@ -192,7 +199,14 @@
|
||||||
state.checkStrictly = strictly;
|
state.checkStrictly = strictly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const searchText = ref('');
|
||||||
|
watchEffect(() => {
|
||||||
|
if (props.searchValue !== searchText.value) searchText.value = props.searchValue;
|
||||||
|
});
|
||||||
|
|
||||||
function handleSearch(searchValue: string) {
|
function handleSearch(searchValue: string) {
|
||||||
|
if (searchValue !== searchText.value) searchText.value = searchValue;
|
||||||
|
emit('update:searchValue', searchValue);
|
||||||
if (!searchValue) {
|
if (!searchValue) {
|
||||||
searchState.startSearch = false;
|
searchState.startSearch = false;
|
||||||
return;
|
return;
|
||||||
|
|
@ -293,6 +307,12 @@
|
||||||
filterByLevel: (level: number) => {
|
filterByLevel: (level: number) => {
|
||||||
state.expandedKeys = filterByLevel(level);
|
state.expandedKeys = filterByLevel(level);
|
||||||
},
|
},
|
||||||
|
setSearchValue: (value: string) => {
|
||||||
|
handleSearch(value);
|
||||||
|
},
|
||||||
|
getSearchValue: () => {
|
||||||
|
return searchText.value;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
expose(instance);
|
expose(instance);
|
||||||
|
|
@ -380,6 +400,7 @@
|
||||||
helpMessage={helpMessage}
|
helpMessage={helpMessage}
|
||||||
onStrictlyChange={onStrictlyChange}
|
onStrictlyChange={onStrictlyChange}
|
||||||
onSearch={handleSearch}
|
onSearch={handleSearch}
|
||||||
|
searchText={unref(searchText)}
|
||||||
>
|
>
|
||||||
{extendSlots(slots)}
|
{extendSlots(slots)}
|
||||||
</TreeHeader>
|
</TreeHeader>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
:placeholder="t('common.searchText')"
|
:placeholder="t('common.searchText')"
|
||||||
size="small"
|
size="small"
|
||||||
allowClear
|
allowClear
|
||||||
@change="handleSearch"
|
v-model:value="searchValue"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Dropdown @click.prevent v-if="toolbar">
|
<Dropdown @click.prevent v-if="toolbar">
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PropType } from 'vue';
|
import type { PropType } from 'vue';
|
||||||
import { defineComponent, computed } from 'vue';
|
import { defineComponent, computed, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { Dropdown, Menu, Input } from 'ant-design-vue';
|
import { Dropdown, Menu, Input } from 'ant-design-vue';
|
||||||
import { Icon } from '/@/components/Icon';
|
import { Icon } from '/@/components/Icon';
|
||||||
|
|
@ -77,10 +77,12 @@
|
||||||
search: propTypes.bool,
|
search: propTypes.bool,
|
||||||
checkAll: propTypes.func,
|
checkAll: propTypes.func,
|
||||||
expandAll: propTypes.func,
|
expandAll: propTypes.func,
|
||||||
|
searchText: propTypes.string,
|
||||||
},
|
},
|
||||||
emits: ['strictly-change', 'search'],
|
emits: ['strictly-change', 'search'],
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const searchValue = ref('');
|
||||||
|
|
||||||
const toolbarList = computed(() => {
|
const toolbarList = computed(() => {
|
||||||
const { checkable } = props;
|
const { checkable } = props;
|
||||||
|
|
@ -137,11 +139,25 @@
|
||||||
}
|
}
|
||||||
const debounceEmitChange = useDebounceFn(emitChange, 200);
|
const debounceEmitChange = useDebounceFn(emitChange, 200);
|
||||||
|
|
||||||
function handleSearch(e: ChangeEvent): void {
|
watch(
|
||||||
debounceEmitChange(e.target.value);
|
() => searchValue.value,
|
||||||
}
|
(v) => {
|
||||||
|
debounceEmitChange(v);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
watch(
|
||||||
|
() => props.searchText,
|
||||||
|
(v) => {
|
||||||
|
if (v !== searchValue.value) {
|
||||||
|
searchValue.value = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
// function handleSearch(e: ChangeEvent): void {
|
||||||
|
// debounceEmitChange(e.target.value);
|
||||||
|
// }
|
||||||
|
|
||||||
return { t, toolbarList, handleMenuClick, handleSearch };
|
return { t, toolbarList, handleMenuClick, searchValue };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ export const basicProps = {
|
||||||
title: propTypes.string,
|
title: propTypes.string,
|
||||||
toolbar: propTypes.bool,
|
toolbar: propTypes.bool,
|
||||||
search: propTypes.bool,
|
search: propTypes.bool,
|
||||||
|
searchValue: propTypes.string,
|
||||||
checkStrictly: propTypes.bool,
|
checkStrictly: propTypes.bool,
|
||||||
clickRowToExpand: propTypes.bool.def(true),
|
clickRowToExpand: propTypes.bool.def(true),
|
||||||
checkable: propTypes.bool.def(false),
|
checkable: propTypes.bool.def(false),
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ export interface TreeActionType {
|
||||||
insertNodesByKey: (opt: InsertNodeParams) => void;
|
insertNodesByKey: (opt: InsertNodeParams) => void;
|
||||||
deleteNodeByKey: (key: string) => void;
|
deleteNodeByKey: (key: string) => void;
|
||||||
updateNodeByKey: (key: string, node: Omit<TreeDataItem, 'key'>) => void;
|
updateNodeByKey: (key: string, node: Omit<TreeDataItem, 'key'>) => void;
|
||||||
|
setSearchValue: (value: string) => void;
|
||||||
|
getSearchValue: () => string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InsertNodeParams {
|
export interface InsertNodeParams {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue