feat: 完善search组件demo
This commit is contained in:
@@ -340,7 +340,7 @@ export default defineComponent({
|
||||
<ElForm
|
||||
ref={elFormRef}
|
||||
{...getFormBindValue()}
|
||||
model={props.isCustom ? props.model : formModel}
|
||||
model={unref(getProps).isCustom ? unref(getProps).model : formModel}
|
||||
class={prefixCls}
|
||||
>
|
||||
{{
|
||||
|
||||
@@ -37,7 +37,9 @@ const props = defineProps({
|
||||
model: {
|
||||
type: Object as PropType<Recordable>,
|
||||
default: () => ({})
|
||||
}
|
||||
},
|
||||
searchLoading: propTypes.bool.def(false),
|
||||
resetLoading: propTypes.bool.def(false)
|
||||
})
|
||||
|
||||
const emit = defineEmits(['search', 'reset', 'register'])
|
||||
@@ -48,9 +50,10 @@ const visible = ref(true)
|
||||
const formModel = ref<Recordable>({})
|
||||
|
||||
const newSchema = computed(() => {
|
||||
let schema: FormSchema[] = cloneDeep(unref(getProps).schema)
|
||||
if (unref(getProps).showExpand && unref(getProps).expandField && !unref(visible)) {
|
||||
const index = findIndex(schema, (v: FormSchema) => v.field === unref(getProps).expandField)
|
||||
const propsComputed = unref(getProps)
|
||||
let schema: FormSchema[] = cloneDeep(propsComputed.schema)
|
||||
if (propsComputed.showExpand && propsComputed.expandField && !unref(visible)) {
|
||||
const index = findIndex(schema, (v: FormSchema) => v.field === propsComputed.expandField)
|
||||
schema.map((v, i) => {
|
||||
if (i >= index) {
|
||||
v.hidden = true
|
||||
@@ -60,7 +63,7 @@ const newSchema = computed(() => {
|
||||
return v
|
||||
})
|
||||
}
|
||||
if (unref(getProps).layout === 'inline') {
|
||||
if (propsComputed.layout === 'inline') {
|
||||
schema = schema.concat([
|
||||
{
|
||||
field: 'action',
|
||||
@@ -71,9 +74,11 @@ const newSchema = computed(() => {
|
||||
return (
|
||||
<div>
|
||||
<ActionButton
|
||||
showSearch={unref(getProps).showSearch}
|
||||
showReset={unref(getProps).showReset}
|
||||
showExpand={unref(getProps).showExpand}
|
||||
showSearch={propsComputed.showSearch}
|
||||
showReset={propsComputed.showReset}
|
||||
showExpand={propsComputed.showExpand}
|
||||
searchLoading={propsComputed.searchLoading}
|
||||
resetLoading={propsComputed.resetLoading}
|
||||
visible={visible.value}
|
||||
onExpand={setVisible}
|
||||
onReset={reset}
|
||||
@@ -91,7 +96,7 @@ const newSchema = computed(() => {
|
||||
})
|
||||
|
||||
const { formRegister, formMethods } = useForm()
|
||||
const { getElFormExpose, getFormData } = formMethods
|
||||
const { getElFormExpose, getFormData, getFormExpose } = formMethods
|
||||
|
||||
// useSearch传入的props
|
||||
const outsideProps = ref<SearchProps>({})
|
||||
@@ -171,8 +176,10 @@ const setSchema = (schemaProps: FormSetProps[]) => {
|
||||
}
|
||||
|
||||
// 对表单赋值
|
||||
const setValues = (data: Recordable = {}) => {
|
||||
const setValues = async (data: Recordable = {}) => {
|
||||
formModel.value = Object.assign(unref(formModel), data)
|
||||
const formExpose = await getFormExpose()
|
||||
formExpose?.setValues(data)
|
||||
}
|
||||
|
||||
const delSchema = (field: string) => {
|
||||
@@ -227,6 +234,8 @@ defineExpose(defaultExpose)
|
||||
:show-reset="getProps.showReset"
|
||||
:show-search="getProps.showSearch"
|
||||
:show-expand="getProps.showExpand"
|
||||
:search-loading="getProps.searchLoading"
|
||||
:reset-loading="getProps.resetLoading"
|
||||
@expand="setVisible"
|
||||
@reset="reset"
|
||||
@search="search"
|
||||
|
||||
@@ -12,7 +12,9 @@ defineProps({
|
||||
showSearch: propTypes.bool.def(true),
|
||||
showReset: propTypes.bool.def(true),
|
||||
showExpand: propTypes.bool.def(false),
|
||||
visible: propTypes.bool.def(true)
|
||||
visible: propTypes.bool.def(true),
|
||||
searchLoading: propTypes.bool.def(false),
|
||||
resetLoading: propTypes.bool.def(false)
|
||||
})
|
||||
|
||||
const onSearch = () => {
|
||||
@@ -32,12 +34,18 @@ const onExpand = () => {
|
||||
<ElButton
|
||||
v-if="showSearch"
|
||||
type="primary"
|
||||
:loading="searchLoading"
|
||||
:icon="useIcon({ icon: 'ep:search' })"
|
||||
@click="onSearch"
|
||||
>
|
||||
{{ t('common.query') }}
|
||||
</ElButton>
|
||||
<ElButton v-if="showReset" :icon="useIcon({ icon: 'ep:refresh-right' })" @click="onReset">
|
||||
<ElButton
|
||||
v-if="showReset"
|
||||
:loading="resetLoading"
|
||||
:icon="useIcon({ icon: 'ep:refresh-right' })"
|
||||
@click="onReset"
|
||||
>
|
||||
{{ t('common.reset') }}
|
||||
</ElButton>
|
||||
<ElButton
|
||||
|
||||
Reference in New Issue
Block a user