forked from element-plus/element-plus
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(filter): added components of list filter
AB#13
- Loading branch information
Showing
50 changed files
with
523 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<template> | ||
<div class="filter-input"> | ||
<label v-if="label" class="label"> | ||
{{ label }} | ||
</label> | ||
<el-input | ||
v-model="internalModelValue" | ||
:placeholder="placeholder" | ||
clearable | ||
@clear="onClear" | ||
@input="onChange" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import {defineComponent, ref} from 'vue'; | ||
import {debounce} from 'vue-debounce'; | ||
export default defineComponent({ | ||
name: 'FilterInput', | ||
props: { | ||
label: { | ||
type: String, | ||
}, | ||
placeholder: { | ||
type: String, | ||
}, | ||
}, | ||
emits: [ | ||
'change', | ||
], | ||
setup(props: FilterInputProps, {emit}) { | ||
const internalModelValue = ref(); | ||
const onChange = debounce((value: any) => { | ||
emit('change', value); | ||
}, 500); | ||
const onClear = () => { | ||
internalModelValue.value = undefined; | ||
emit('change', internalModelValue.value); | ||
}; | ||
return { | ||
internalModelValue, | ||
onChange, | ||
onClear, | ||
}; | ||
} | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<template> | ||
<div class="filter-select"> | ||
<label v-if="label" class="label"> | ||
{{ label }} | ||
</label> | ||
<el-select | ||
v-model="internalModelValue" | ||
:placeholder="placeholder" | ||
clearable | ||
@clear="onClear" | ||
@change="onChange" | ||
> | ||
<el-option | ||
v-for="(option, $index) in computedOptions" | ||
:key="$index" | ||
:label="option.label" | ||
:value="option.value" | ||
/> | ||
</el-select> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import {computed, defineComponent, onBeforeMount, PropType, ref} from 'vue'; | ||
import useRequest from '@/services/request'; | ||
import {cloneArray, prependAllToSelectOptions} from '@/utils'; | ||
const { | ||
get, | ||
} = useRequest(); | ||
export default defineComponent({ | ||
name: 'FilterSelect', | ||
props: { | ||
label: { | ||
type: String, | ||
}, | ||
placeholder: { | ||
type: String, | ||
}, | ||
options: { | ||
type: Array as PropType<SelectOption[]>, | ||
}, | ||
optionsRemote: { | ||
type: Object as PropType<FilterSelectOptionsRemote>, | ||
}, | ||
}, | ||
emits: [ | ||
'change', | ||
], | ||
setup(props: FilterSelectProps, {emit}) { | ||
const internalModelValue = ref(); | ||
const internalOptions = ref<SelectOption[]>([]); | ||
const computedOptions = computed<SelectOption[]>(() => { | ||
const options = cloneArray(props.options || internalOptions.value || []); | ||
return prependAllToSelectOptions(options); | ||
}); | ||
const onChange = (value: any) => { | ||
emit('change', value); | ||
}; | ||
const onClear = () => { | ||
emit('change', undefined); | ||
}; | ||
const getOptions = async () => { | ||
if (!props.optionsRemote) return; | ||
const {colName, value, label} = props.optionsRemote; | ||
let url = `/filters/${colName}`; | ||
if (value) url += `/${value}`; | ||
if (label) url += `/${label}`; | ||
const res = await get(url); | ||
internalOptions.value = res.data; | ||
}; | ||
onBeforeMount(async () => { | ||
await getOptions(); | ||
}); | ||
return { | ||
internalModelValue, | ||
computedOptions, | ||
onChange, | ||
onClear, | ||
}; | ||
} | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.