Commit b44985bd by qlintonger xeno

Merge remote-tracking branch 'origin/master'

parents 77c6a1d5 218865ba
import { cloneDeep } from 'lodash'
import { onUnmounted, onActivated, onDeactivated, getCurrentInstance } from 'vue'
interface Event {
readonly uid: string
cb: (data: any) => void
alive?: boolean
del?: boolean
only?: boolean
}
class EventBus {
protected eventMap: { [key: string]: Array<Event> }
constructor() {
this.eventMap = {}
}
// 发布事件
emit(eventName: string, ...args: Array<any>) {
let eventList = this.eventMap[eventName]
if (eventList) {
let delIndexs: Array<number> = []
for (let i = 0; i < eventList.length; i++) {
let { cb, del = false, only = false, alive } = eventList[i]
if (!alive) {
continue
}
cb(...(args as [any]))
if (del) {
delIndexs.push(i)
}
if (only) {
break
}
}
if (delIndexs.length) {
this.eventMap[eventName] = eventList.filter((event, i) => {
return !delIndexs.includes(i)
})
}
} else if (import.meta.env.MODE === 'development') {
console.warn(eventName + ' not found!')
}
}
// 订阅事件
on(eventName: string, opt: Event) {
if (!this.eventMap[eventName]) {
this.eventMap[eventName] = []
}
let uid = opt.uid
let index = this.eventMap[eventName].findIndex((item) => {
return uid == item.uid
})
if (index >= 0) {
this.eventMap[eventName].splice(index, 1, opt)
return
}
this.eventMap[eventName].unshift(opt)
}
// 取消订阅时间
off(eventName: string, uid: string) {
if (this.eventMap[eventName]) {
let index = this.eventMap[eventName].findIndex((item) => {
return uid == item.uid
})
if (index >= 0) {
this.eventMap[eventName].splice(index, 1)
if (!this.eventMap[eventName].length) {
delete this.eventMap[eventName]
}
}
}
// console.log(this.eventMap)
}
// 只订阅一次
one(eventName: string, opt: Event) {
opt.del = true
return this.on(eventName, opt)
}
// 激活
enable(eventName: string, uid: string) {
if (this.eventMap[eventName]) {
let index = this.eventMap[eventName].findIndex((item) => {
return uid == item.uid
})
if (index == 0) {
this.eventMap[eventName][index].alive = true
} else if (index > 0) {
const newEvent = cloneDeep(this.eventMap[eventName][index])
this.eventMap[eventName].splice(index, 1)
newEvent.alive = true
this.eventMap[eventName].unshift(newEvent)
}
}
}
// 禁用
disable(eventName: string, uid: string, alive: boolean = false) {
if (this.eventMap[eventName]) {
let index = this.eventMap[eventName].findIndex((item) => {
return uid == item.uid
})
if (index >= 0) {
this.eventMap[eventName][index].alive = alive
}
}
}
}
const eventBus = new EventBus()
export function useBusOn(eventName: string, cb: (value: any) => void, opt?: { del?: boolean; only?: boolean; alive?: boolean }) {
const currentInstance = getCurrentInstance()
const _opt = {
uid: String(currentInstance?.uid),
cb: cb as (value: any) => void,
alive: true,
...opt
}
eventBus.on(eventName, _opt)
onActivated(() => {
eventBus.on(eventName, _opt)
})
function off() {
eventBus.off(eventName, _opt.uid)
}
onUnmounted(() => off())
onDeactivated(() => {
off()
})
return {
off,
enable: () => {
eventBus.enable(eventName, _opt.uid)
},
disable: () => {
eventBus.disable(eventName, _opt.uid)
}
}
}
export function useBusOne(eventName: string, cb: (value: any) => void, opt?: { del?: boolean; only?: boolean }) {
let _opt = { ...opt, del: true }
return useBusOn(eventName, cb, _opt)
}
export function useBusOff(eventName: string) {
const currentInstance = getCurrentInstance()
const uid = String(currentInstance?.uid)
eventBus.off(eventName, uid)
}
export function useBusEmit(eventName: string, ...args: Array<any>) {
eventBus.emit(eventName, ...(args as Array<any>))
}
...@@ -6,23 +6,25 @@ export const eventListColumns: TableColumnData[] = [ ...@@ -6,23 +6,25 @@ export const eventListColumns: TableColumnData[] = [
title: '序号', title: '序号',
align: 'center', align: 'center',
dataIndex: 'index', dataIndex: 'index',
slotName: 'index' slotName: 'index',
width: 80
}, },
{ {
title: '事件名称', title: '事件名称',
dataIndex: 'title', dataIndex: 'title',
slotName: 'title', slotName: 'title'
width: 400
}, },
{ {
title: '发起人', title: '发起人',
dataIndex: 'initiator', dataIndex: 'initiator',
slotName: 'initiator' slotName: 'initiator',
width: 150
}, },
{ {
title: '参与人', title: '参与人',
dataIndex: 'participants', dataIndex: 'participants',
slotName: 'participants' slotName: 'participants',
width: 210
}, },
// { // {
// title: '职位', // title: '职位',
...@@ -32,13 +34,15 @@ export const eventListColumns: TableColumnData[] = [ ...@@ -32,13 +34,15 @@ export const eventListColumns: TableColumnData[] = [
{ {
title: '会议时间', title: '会议时间',
dataIndex: 'createdTime', dataIndex: 'createdTime',
slotName: 'createdTime' slotName: 'createdTime',
width: 180
}, },
{ {
title: '操作', title: '操作',
align: 'center', align: 'center',
dataIndex: 'operation', dataIndex: 'operation',
slotName: 'operation' slotName: 'operation',
width: 150
} }
// { // {
// title: '结束时间', // title: '结束时间',
......
<template> <template>
<!-- 事件列表 --> <!-- 事件列表 -->
<event-list v-show="!showDetails" @show-details="handleShowDetails" @show-list="handleShowList"></event-list> <div class="h-full" v-show="!showDetails">
<event-list @show-details="handleShowDetails" @show-list="handleShowList"></event-list>
</div>
<!-- 事件详情 --> <!-- 事件详情 -->
<event-details v-show="showDetails" :record="record" :details="details" @show-list="handleShowList"></event-details> <div class="h-full" v-show="showDetails">
<event-details :record="record" :details="details" @show-list="handleShowList"></event-details>
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
......
...@@ -178,6 +178,7 @@ const handleConfirm = async (record: any, rowIndex: number) => { ...@@ -178,6 +178,7 @@ const handleConfirm = async (record: any, rowIndex: number) => {
const res = await sendUpdateTitle(record, rowIndex) const res = await sendUpdateTitle(record, rowIndex)
if (res.code == 200) { if (res.code == 200) {
handleFocus(record, rowIndex) handleFocus(record, rowIndex)
Message.success(res.message)
} else { } else {
titleArr.value[rowIndex].focus() titleArr.value[rowIndex].focus()
Message.error(res.message) Message.error(res.message)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment