fix(v0.3.3): 单击只选中部门;开新部门自动打开工作台

单击部门卡只更新选中与详情,不再切宿主会话导致选中回弹到丞相;点开始对话才进会话;开启部门成功后自动打开三省六部面板。
This commit is contained in:
qyh15 2026-11-17 22:52:39 +08:00
parent 7f5bc28ef9
commit bada1e602c
4 changed files with 76 additions and 19 deletions

38
preview/check-click.mjs Normal file
View File

@ -0,0 +1,38 @@
import { spawn } from 'node:child_process'
import { mkdtemp } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
const url = process.argv[2]
const EDGE = 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'
const profile = await mkdtemp(join(tmpdir(), 'ss-click-'))
const sleep = ms => new Promise(r => setTimeout(r, ms))
let browser, ws
const out = {}
try {
browser = spawn(EDGE, ['--headless=new','--disable-gpu','--no-first-run','--no-default-browser-check','--remote-debugging-port=0','--user-data-dir=' + profile, 'about:blank'], { stdio: ['ignore','ignore','pipe'] })
const endpoint = await new Promise((resolve, reject) => { let log=''; const t=setTimeout(()=>reject(Error('timeout')),20000); browser.stderr.on('data', b=>{ log+=b; const m=log.match(/DevTools listening on (.+)/); if(m){clearTimeout(t);resolve(m[1].trim())} }); browser.on('error',reject) })
ws = new WebSocket(endpoint); await new Promise((r,j)=>{ws.onopen=r;ws.onerror=j})
let n=0; const pend=new Map()
ws.onmessage = e => { const m=JSON.parse(e.data); if(m.id){const p=pend.get(m.id);pend.delete(m.id);m.error?p.reject(Error(JSON.stringify(m.error))):p.resolve(m.result)} }
const cdp=(method,params={},sid)=>new Promise((res,rej)=>{const id=++n;pend.set(id,{resolve:res,reject:rej});ws.send(JSON.stringify({id,method,params,...(sid?{sessionId:sid}:{})}))})
const { targetId } = await cdp('Target.createTarget', { url: 'about:blank' })
const { sessionId } = await cdp('Target.attachToTarget', { targetId, flatten: true })
const call=(m,p={})=>cdp(m,p,sessionId)
await call('Page.enable'); await call('Runtime.enable')
const ev = async x => { const r=await call('Runtime.evaluate',{expression:x,returnByValue:true,awaitPromise:true}); if(r.exceptionDetails) throw Error(r.exceptionDetails.exception?.description||r.exceptionDetails.text); return r.result.value }
const waitFor = async (x,t=45000)=>{ const end=Date.now()+t; while(Date.now()<end){ try{ if(await ev(x)) return true }catch{} await sleep(250) } return false }
await call('Emulation.setDeviceMetricsOverride',{width:1440,height:900,deviceScaleFactor:1,mobile:false})
await call('Page.navigate',{url})
await waitFor("document.readyState === 'complete'",30000)
try { await ev("(() => { const b=[...document.querySelectorAll('button')].find(x=>(x.innerText||'').trim()==='继续'); if(b)b.click(); return !!b })()") } catch {}
await waitFor("!!document.querySelector('.ssw-nav-hit')",60000)
await ev("document.querySelector('.ssw-nav-hit').click(); true")
await waitFor("!!document.querySelector('.ssw-root')",20000)
await sleep(2200)
const before = await ev("document.querySelector('.ssw-current-name')?.innerText")
await ev("(() => { const b=[...document.querySelectorAll('.ssw-seat')].find(x=>x.innerText.includes('工部')); if(b){b.click(); return true} return false })()")
await sleep(500)
const afterClick = await ev("({ name: document.querySelector('.ssw-current-name')?.innerText, selected: document.querySelector('.ssw-seat[aria-pressed=true] .ssw-role-name')?.innerText, page: document.title })")
out.before = before; out.afterClick = afterClick
} catch(e) { out.fatal = String(e?.stack ?? e) } finally { try{ws?.close()}catch{}; try{browser?.kill()}catch{} }
console.log(JSON.stringify(out, null, 2))

View File

@ -1292,16 +1292,21 @@ function apply(ctx) {
setConfigOpen(false);
}
const seat = seatById[id];
if (seat && seat.status === "bound") {
const rec = seatRecordOf(view, id);
if (rec && rec.sessionId) {
navigateToSession(rec.sessionId);
setNotice("已切换到" + seat.name + "会话");
return;
}
}
if (seat && seat.status !== "bound" && seat.status !== "creating") setNotice("「" + seat.name + "」还没开启,点下面的按钮开启这个部门");
}
function openSelectedSeat() {
const seat = seatById[wb.selected.id];
if (!seat) return;
if (seat.status !== "bound") {
setNotice("「" + seat.name + "」还没开启,先点「开启『" + seat.name + "』」");
return;
}
const rec = seatRecordOf(view, seat.id);
if (rec && rec.sessionId) {
navigateToSession(rec.sessionId);
setNotice("已切换到" + seat.name + "会话");
}
}
function setModelValue(value) {
setDraft((prev) => updateDraft(prev, selectedSeatId, { modelValue: value }));
}
@ -1320,6 +1325,10 @@ function apply(ctx) {
if (!alive.current) return;
setView(next);
setNotice("已开启「" + wb.selected.name + "」的独立会话");
try {
tryOpenRightTab();
} catch {
}
} catch (enableError) {
if (alive.current) setError(enableError && enableError.message ? enableError.message : "开启失败");
} finally {
@ -1513,7 +1522,7 @@ function apply(ctx) {
type: "button",
className: "ssw-primary",
disabled: busy,
onClick: () => pickSeat(wb.selected.id)
onClick: openSelectedSeat
}, "开始对话") : (0, import_react.createElement)("button", {
type: "button",
className: "ssw-primary",

View File

@ -1,6 +1,6 @@
{
"name": "dsh-sansheng-liubu",
"version": "0.3.2",
"version": "0.3.3",
"description": "三省六部:每个项目固定十席角色与独立会话的 DSH 插件(第一版)。",
"keywords": [
"dsh-plugin",

View File

@ -390,6 +390,7 @@ export function apply(ctx) {
return map
}, [wb.seats])
// 单击只负责“选中部门”,不切换宿主会话;切换会话会让工作台重挂载、选中项回到丞相。
function pickSeat(id) {
if (!id) return
if (id !== selectedSeatId) {
@ -397,17 +398,24 @@ export function apply(ctx) {
setConfigOpen(false)
}
const seat = seatById[id]
if (seat && seat.status === 'bound') {
const rec = seatRecordOf(view, id)
if (rec && rec.sessionId) {
navigateToSession(rec.sessionId)
setNotice('已切换到' + seat.name + '会话')
return
}
}
if (seat && seat.status !== 'bound' && seat.status !== 'creating') setNotice('「' + seat.name + '」还没开启,点下面的按钮开启这个部门')
}
// 只有明确点“开始对话”时才进入该部门的宿主会话。
function openSelectedSeat() {
const seat = seatById[wb.selected.id]
if (!seat) return
if (seat.status !== 'bound') {
setNotice('「' + seat.name + '」还没开启,先点「开启『' + seat.name + '』」')
return
}
const rec = seatRecordOf(view, seat.id)
if (rec && rec.sessionId) {
navigateToSession(rec.sessionId)
setNotice('已切换到' + seat.name + '会话')
}
}
function setModelValue(value) {
setDraft(prev => updateDraft(prev, selectedSeatId, { modelValue: value }))
}
@ -425,6 +433,8 @@ export function apply(ctx) {
if (!alive.current) return
setView(next)
setNotice('已开启「' + wb.selected.name + '」的独立会话')
// 开新部门时自动把三省六部工作台面板打开/置前,避免用户以为没反应。
try { tryOpenRightTab() } catch { /* 打开失败不影响开启结果 */ }
} catch (enableError) {
if (alive.current) setError(enableError && enableError.message ? enableError.message : '开启失败')
} finally {
@ -590,7 +600,7 @@ export function apply(ctx) {
selectedStatus === 'bound'
? h('button', {
type: 'button', className: 'ssw-primary', disabled: busy,
onClick: () => pickSeat(wb.selected.id),
onClick: openSelectedSeat,
}, '开始对话')
: h('button', {
type: 'button', className: 'ssw-primary', disabled: busy || selectedStatus === 'creating',