11<script setup lang="ts">
2- import { ref , computed } from ' vue'
2+ import { ref } from ' vue'
33import { useI18n } from ' vue-i18n'
44import { apiFetch } from ' @/shared/api'
55import { useToast , useConfirm , SModal , SButton , SBadge } from ' sbot-ui'
@@ -9,47 +9,23 @@ const { t, locale } = useI18n()
99const { show } = useToast ()
1010const { confirm } = useConfirm ()
1111
12- interface ChannelSessionRow {
13- id: number
14- profileId: number
15- }
16-
1712const visible = ref (false )
18- const dbSessionId = ref <number | null >(null )
1913const profileIdRef = ref <string | null >(null )
2014const sessionLabel = ref (' ' )
2115const loading = ref (false )
22- const all = ref <SchedulerRow []>([])
23-
24- const filtered = computed (() => {
25- // scheduler 按 profileId 绑(同 profile 的所有 session 共享视图)
26- const pid = profileIdRef .value ? Number (profileIdRef .value ) : null
27- if (! pid ) return []
28- return all .value .filter (r => r .profileId === pid )
29- })
16+ const rows = ref <SchedulerRow []>([])
3017
3118function formatTime(ts : number | null ): string {
3219 if (! ts ) return ' -'
3320 return new Date (ts ).toLocaleString (locale .value === ' zh' ? ' zh-CN' : undefined )
3421}
3522
3623async function load() {
24+ if (! profileIdRef .value ) return
3725 loading .value = true
3826 try {
39- const [timersRes, sessionsRes] = await Promise .all ([
40- apiFetch (' /api/schedulers' ),
41- apiFetch (' /api/channel-sessions' ),
42- ])
43- all .value = timersRes .data || []
44- const sessions: ChannelSessionRow [] = sessionsRes .data || []
45- // 任一入口都最终归位到 profileId 上做过滤
46- if (profileIdRef .value == null && dbSessionId .value != null ) {
47- const row = sessions .find (s => s .id === dbSessionId .value )
48- profileIdRef .value = row ? String (row .profileId ) : null
49- } else if (dbSessionId .value == null && profileIdRef .value ) {
50- const row = sessions .find (s => String (s .profileId ) === profileIdRef .value )
51- dbSessionId .value = row ?.id ?? null
52- }
27+ const res = await apiFetch (` /api/schedulers?profileId=${encodeURIComponent (profileIdRef .value )} ` )
28+ rows .value = res .data || []
5329 } catch (e : any ) {
5430 show (e ?.message || String (e ), ' error' )
5531 } finally {
@@ -68,25 +44,15 @@ async function remove(row: SchedulerRow) {
6844 }
6945}
7046
71- function open(id : number , label : string ) {
72- dbSessionId .value = id
73- profileIdRef .value = null
74- sessionLabel .value = label
75- all .value = []
76- visible .value = true
77- load ()
78- }
79-
8047function openByProfileId(profileId : string , label : string ) {
81- dbSessionId .value = null
8248 profileIdRef .value = profileId
8349 sessionLabel .value = label
84- all .value = []
50+ rows .value = []
8551 visible .value = true
8652 load ()
8753}
8854
89- defineExpose ({ open , openByProfileId })
55+ defineExpose ({ openByProfileId })
9056 </script >
9157
9258<template >
@@ -105,9 +71,9 @@ defineExpose({ open, openByProfileId })
10571 </template >
10672
10773 <div v-if =" loading" class =" modal-loading" >{{ t('common.loading') }}</div >
108- <div v-else-if =" filtered .length === 0" class =" modal-empty" >{{ t('scheduler.empty') }}</div >
74+ <div v-else-if =" rows .length === 0" class =" modal-empty" >{{ t('scheduler.empty') }}</div >
10975 <ul v-else class =" sched-list" >
110- <li v-for =" row in filtered " :key =" row.id" class =" sched-row" >
76+ <li v-for =" row in rows " :key =" row.id" class =" sched-row" >
11177 <div class =" sched-row-main" >
11278 <span class =" sched-row-id" >#{{ row.id }}</span >
11379 <SBadge :variant =" TYPE_VARIANT [detectUIType (row .expr )]" size="sm" pill>
0 commit comments