refactor: 重写useEventBus
This commit is contained in:
parent
10745207e6
commit
80351516ce
|
@ -8,7 +8,7 @@ interface Option {
|
||||||
|
|
||||||
const emitter = mitt()
|
const emitter = mitt()
|
||||||
|
|
||||||
export const useEmitt = (option?: Option) => {
|
export const useEventBus = (option?: Option) => {
|
||||||
if (option) {
|
if (option) {
|
||||||
emitter.on(option.name, option.callback)
|
emitter.on(option.name, option.callback)
|
||||||
|
|
||||||
|
@ -18,6 +18,9 @@ export const useEmitt = (option?: Option) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
emitter
|
on: emitter.on,
|
||||||
|
off: emitter.off,
|
||||||
|
emit: emitter.emit,
|
||||||
|
all: emitter.all
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,9 +5,9 @@ import { ref, unref } from 'vue'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { saveTableApi } from '@/api/table'
|
import { saveTableApi } from '@/api/table'
|
||||||
import { useEmitt } from '@/hooks/event/useEmitt'
|
import { useEventBus } from '@/hooks/event/useEventBus'
|
||||||
|
|
||||||
const { emitter } = useEmitt()
|
const { emit } = useEventBus()
|
||||||
|
|
||||||
const { push, go } = useRouter()
|
const { push, go } = useRouter()
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ const save = async () => {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
})
|
})
|
||||||
if (res) {
|
if (res) {
|
||||||
emitter.emit('getList', 'add')
|
emit('getList', 'add')
|
||||||
push('/example/example-page')
|
push('/example/example-page')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,4 +49,4 @@ const save = async () => {
|
||||||
</template>
|
</template>
|
||||||
</ContentDetailWrap>
|
</ContentDetailWrap>
|
||||||
</template>
|
</template>
|
||||||
@/hooks/event/useEmitt
|
@/hooks/event/useEventBus
|
||||||
|
|
|
@ -6,9 +6,9 @@ import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import { saveTableApi, getTableDetApi } from '@/api/table'
|
import { saveTableApi, getTableDetApi } from '@/api/table'
|
||||||
import { TableData } from '@/api/table/types'
|
import { TableData } from '@/api/table/types'
|
||||||
import { useEmitt } from '@/hooks/event/useEmitt'
|
import { useEventBus } from '@/hooks/event/useEventBus'
|
||||||
|
|
||||||
const { emitter } = useEmitt()
|
const { emit } = useEventBus()
|
||||||
|
|
||||||
const { push, go } = useRouter()
|
const { push, go } = useRouter()
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ const save = async () => {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
})
|
})
|
||||||
if (res) {
|
if (res) {
|
||||||
emitter.emit('getList', 'editor')
|
emit('getList', 'editor')
|
||||||
push('/example/example-page')
|
push('/example/example-page')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,4 +63,4 @@ const save = async () => {
|
||||||
</template>
|
</template>
|
||||||
</ContentDetailWrap>
|
</ContentDetailWrap>
|
||||||
</template>
|
</template>
|
||||||
@/hooks/event/useEmitt
|
@/hooks/event/useEventBus
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { useTable } from '@/hooks/web/useTable'
|
||||||
import { TableData } from '@/api/table/types'
|
import { TableData } from '@/api/table/types'
|
||||||
import { reactive, ref, unref } from 'vue'
|
import { reactive, ref, unref } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useEmitt } from '@/hooks/event/useEmitt'
|
import { useEventBus } from '@/hooks/event/useEventBus'
|
||||||
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
|
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
|
||||||
import { BaseButton } from '@/components/Button'
|
import { BaseButton } from '@/components/Button'
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ const { getList, getElTableExpose, delList } = tableMethods
|
||||||
|
|
||||||
getList()
|
getList()
|
||||||
|
|
||||||
useEmitt({
|
useEventBus({
|
||||||
name: 'getList',
|
name: 'getList',
|
||||||
callback: (type: string) => {
|
callback: (type: string) => {
|
||||||
if (type === 'add') {
|
if (type === 'add') {
|
||||||
|
@ -294,4 +294,4 @@ const action = (row: TableData, type: string) => {
|
||||||
/>
|
/>
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
</template>
|
</template>
|
||||||
@/hooks/event/useEmitt
|
@/hooks/event/useEventBus
|
||||||
|
|
Loading…
Reference in New Issue