重构: confirmDialog抽composable+tool_result反向查找+search列限定
- FR-D5 抽 useConfirm 收敛 4 视图(Projects/ProjectDetail/Ideas/Settings)确认弹层重复 - FR-D4 replace_tool_result_content 正向 O(n) 改反向 rposition(审批替换命中最近,调用低频) - FR-D2 search_vector SELECT * 改显式 14 列(消除隐式依赖,字段级精简待单独立项)
This commit is contained in:
50
src/composables/useConfirm.ts
Normal file
50
src/composables/useConfirm.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
//! 统一确认弹层状态机 — 抽自 Projects/ProjectDetail/Ideas/Settings 四处重复
|
||||
//!
|
||||
//! 背景:原生 window.confirm 在 Tauri webview 带 localhost:port 来源信息无法去除,
|
||||
//! 改为自建弹层。四视图各自重复一份 {visible,msg,resolve} + Promise 机制,此处收敛。
|
||||
//!
|
||||
//! 分工:本 composable 只管「状态 + Promise」,不渲染 UI ——
|
||||
//! - Projects/ProjectDetail/Ideas 复用 ../components/ConfirmDialog.vue
|
||||
//! - Settings 用内联模板(沿用其既有 toast/confirm 同框布局)
|
||||
//! 各视图绑定 confirmState 的 visible/msg 并把按钮点击回 answerConfirm 即可。
|
||||
//!
|
||||
//! i18n:composable 在 setup 内调用,文案由调用方用各自 useI18n().t 翻译后传入 msg,
|
||||
//! 这里无需 i18n 依赖。dangerLabel 由 ConfirmDialog 组件侧兜底为 common.delete。
|
||||
|
||||
import { ref } from 'vue'
|
||||
|
||||
export interface ConfirmState {
|
||||
visible: boolean
|
||||
msg: string
|
||||
resolve: null | ((v: boolean) => void)
|
||||
}
|
||||
|
||||
/** 弹出确认对话框,返回 Promise;resolve(true) 表示用户确认,resolve(false) 表示取消 */
|
||||
export type ConfirmFn = (msg: string) => Promise<boolean>
|
||||
|
||||
/** 关闭弹层并回传结果 */
|
||||
export type AnswerFn = (ok: boolean) => void
|
||||
|
||||
export function useConfirm() {
|
||||
const confirmState = ref<ConfirmState>({
|
||||
visible: false,
|
||||
msg: '',
|
||||
resolve: null,
|
||||
})
|
||||
|
||||
function confirmDialog(msg: string): Promise<boolean> {
|
||||
return new Promise(resolve => {
|
||||
confirmState.value.msg = msg
|
||||
confirmState.value.visible = true
|
||||
confirmState.value.resolve = resolve
|
||||
})
|
||||
}
|
||||
|
||||
function answerConfirm(ok: boolean) {
|
||||
confirmState.value.visible = false
|
||||
confirmState.value.resolve?.(ok)
|
||||
confirmState.value.resolve = null
|
||||
}
|
||||
|
||||
return { confirmState, confirmDialog, answerConfirm }
|
||||
}
|
||||
Reference in New Issue
Block a user