Skip to content

Commit

Permalink
perf: 定时任务发送消息逻辑处理
Browse files Browse the repository at this point in the history
  • Loading branch information
yzqzy committed Feb 1, 2024
1 parent 6532846 commit fd9cb38
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
23 changes: 22 additions & 1 deletion src/demos/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { useMessage } from '../composables/useMessage'
import { Task } from '../store/task'

const { sendMsgBatch } = useMessage()

window.ipcRenderer.on('main-process-message', (_event, ...args) => {
console.log('[Receive Main-process message]:', ...args)
})

window.ipcRenderer.on('main-process-cron-message', (_event, ...args) => {
console.log('[Receive Main-process corn message]:', ...args)
// TODO: send message

const task = args[0] as Task

if (!Array.isArray(task.receiver_ids)) return

// Send message to receiver
sendMsgBatch(task.receiver_ids, {
mode: task.type,
...task.params
})

console.log(
'[Send Msg Batch]:',
task.receiver_ids.join('、'),
task.type,
task.params
)
})
2 changes: 1 addition & 1 deletion src/store/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Task {
mode: TaskMode
type: MessageType
name: string
receiver_ids: number[]
receiver_ids: string[]
cron: string
enabled: boolean
params: any
Expand Down
7 changes: 4 additions & 3 deletions src/views/cron/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
<el-table-column label="操作" width="340" align="center">
<template #default="scope">
<el-button type="primary" plain class="btn" @click="handleShowEditTask(scope.$index)">编辑</el-button>
<el-button type="primary" plain class="btn" @click="handleEnabledTask(scope.$index)">{{ scope.row.enabled ?
'禁用' :
'启用' }}</el-button>
<el-button :type="scope.row.enabled ? 'danger' : 'primary'" plain class="btn"
@click="handleEnabledTask(scope.$index)">{{ scope.row.enabled ?
'禁用' :
'启用' }}</el-button>
<el-button type="danger" plain class="btn" @click="handleDeleteTask(scope.$index)">删除</el-button>
</template>
</el-table-column>
Expand Down
5 changes: 3 additions & 2 deletions src/views/cron/useTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ export const useTask = () => {
}

const handleEditTask = (index: number, task: Task) => {
CronTask.stop(task)

if (task.enabled) {
CronTask.start(task)
} else {
CronTask.stop(task)
}

editTask(index, task)
}

Expand Down

0 comments on commit fd9cb38

Please sign in to comment.