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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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