fix: emit names

pull/30/MERGE
xingyu 2023-08-11 21:03:12 +08:00
parent 77739a6259
commit b5f17955df
7 changed files with 18 additions and 32 deletions

View File

@ -16,7 +16,7 @@ import { useAttrs } from '@/hooks/core/useAttrs'
defineOptions({ inheritAttrs: false })
const props = defineProps(basicProps)
const emit = defineEmits(['open-change', 'ok', 'close', 'register'])
const emit = defineEmits(['openChange', 'ok', 'close', 'register'])
const openRef = ref(false)
const attrs = useAttrs()
@ -101,7 +101,7 @@ watch(
() => openRef.value,
(open) => {
nextTick(() => {
emit('open-change', open)
emit('openChange', open)
instance && drawerInstance.emitOpen?.(open, instance.uid)
})
},

View File

@ -33,7 +33,7 @@ const props = defineProps({
valueField: propTypes.string.def('value'),
immediate: propTypes.bool.def(true),
})
const emit = defineEmits(['options-change', 'change'])
const emit = defineEmits(['optionsChange', 'change'])
const RadioButton = Radio.Button
const RadioGroup = Radio.Group
@ -103,7 +103,7 @@ async function fetch() {
}
function emitChange() {
emit('options-change', unref(getOptions))
emit('optionsChange', unref(getOptions))
}
function handleChange(args) {

View File

@ -33,7 +33,7 @@ const props = defineProps({
alwaysLoad: propTypes.bool.def(false),
})
const emit = defineEmits(['options-change', 'change', 'update:value'])
const emit = defineEmits(['optionsChange', 'change', 'update:value'])
interface OptionsItem { label: string; value: string; disabled?: boolean }
@ -120,7 +120,7 @@ async function handleFetch(open) {
}
function emitChange() {
emit('options-change', unref(getOptions))
emit('optionsChange', unref(getOptions))
}
function handleChange(_, ...args) {

View File

@ -31,7 +31,7 @@ const props = defineProps({
showSelectAll: { type: Boolean, default: true },
targetKeys: { type: Array as PropType<Array<string>> },
})
const emit = defineEmits(['options-change', 'change'])
const emit = defineEmits(['optionsChange', 'change'])
const attrs = useAttrs()
const _dataSource = ref<TransferItem[]>([])
@ -109,7 +109,7 @@ async function fetch() {
}
}
function emitChange() {
emit('options-change', unref(getdataSource))
emit('optionsChange', unref(getdataSource))
}
</script>

View File

@ -2,7 +2,6 @@
import { computed, onMounted, ref, unref, useAttrs, useSlots, watch } from 'vue'
import { Tree } from 'ant-design-vue'
import { get } from 'lodash-es'
import { LoadingOutlined } from '@ant-design/icons-vue'
import { isArray, isFunction } from '@/utils/is'
import { handleTree as handleTreeFn } from '@/utils/tree'
import { propTypes } from '@/utils/propTypes'
@ -17,7 +16,7 @@ const props = defineProps({
afterFetch: { type: Function as PropType<Fn> },
handleTree: { type: String, default: '' },
})
const emit = defineEmits(['options-change', 'change'])
const emit = defineEmits(['optionsChange', 'change'])
const attrs = useAttrs()
const slots = useSlots()
@ -81,7 +80,7 @@ async function fetch() {
treeData.value = (result as Recordable[]) || []
isFirstLoaded.value = true
emit('options-change', treeData.value)
emit('optionsChange', treeData.value)
}
</script>
@ -90,8 +89,8 @@ async function fetch() {
<template v-for="item in Object.keys(slots)" #[item]="data">
<slot :name="item" v-bind="data || {}" />
</template>
<template v-if="loading" #suffixIcon>
<!-- <template v-if="loading" #suffixIcon>
<LoadingOutlined spin />
</template>
</template> -->
</Tree>
</template>

View File

@ -1,5 +1,5 @@
<script lang="ts" setup>
import { computed, onMounted, ref, unref, useAttrs, watch, watchEffect } from 'vue'
import { computed, onMounted, ref, unref, useAttrs, watch } from 'vue'
import { TreeSelect } from 'ant-design-vue'
import { get, set } from 'lodash-es'
import { LoadingOutlined } from '@ant-design/icons-vue'
@ -14,15 +14,12 @@ const props = defineProps({
params: { type: Object },
immediate: { type: Boolean, default: true },
resultField: propTypes.string.def(''),
labelField: propTypes.string.def('title'),
valueField: propTypes.string.def('value'),
childrenField: propTypes.string.def('children'),
handleTree: { type: String, default: '' },
parentId: { type: Number, default: 0 },
parentLabel: { type: String, default: '' },
parentFiled: { type: String, default: 'name' },
})
const emit = defineEmits(['options-change', 'change'])
const emit = defineEmits(['optionsChange', 'change'])
const attrs = useAttrs()
const treeData = ref<Recordable[]>([])
@ -35,20 +32,10 @@ const getAttrs = computed(() => {
}
})
const fieldNames = {
children: props.childrenField,
value: props.valueField,
label: props.labelField,
}
function handleChange(...args) {
emit('change', ...args)
}
watchEffect(() => {
props.immediate && fetch()
})
watch(
() => props.params,
() => {
@ -101,12 +88,12 @@ async function fetch() {
}
isFirstLoaded.value = true
emit('options-change', treeData.value)
emit('optionsChange', treeData.value)
}
</script>
<template>
<TreeSelect v-bind="getAttrs" :field-names="fieldNames" @change="handleChange">
<TreeSelect v-bind="getAttrs" @change="handleChange">
<template v-for="item in Object.keys($slots)" #[item]="data">
<slot :name="item" v-bind="data || {}" />
</template>

View File

@ -35,7 +35,7 @@ const props = defineProps({
hideAdvanceBtn: propTypes.bool,
})
const emit = defineEmits(['toggle-advanced'])
const emit = defineEmits(['toggleAdvanced'])
const FormItem = Form.Item
@ -75,7 +75,7 @@ const getSubmitBtnOptions = computed(() => {
})
function toggleAdvanced() {
emit('toggle-advanced')
emit('toggleAdvanced')
}
const { resetAction, submitAction } = useFormContext()