mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-08-17 19:47:10 +08:00
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import { reactive } from "vue";
|
|
|
|
export const modalState = reactive({
|
|
visible: false,
|
|
title: "提示",
|
|
content: "",
|
|
confirmText: "确定",
|
|
cancelText: "取消",
|
|
showCancel: true,
|
|
confirmDisabled: false,
|
|
_resolve: null,
|
|
});
|
|
|
|
/**
|
|
* 显示确认弹窗,返回 Promise<boolean>
|
|
* @param {Object} options - { title, content }
|
|
* @returns {Promise<boolean>} - true=确定, false=取消
|
|
*/
|
|
export function showModal(options = {}) {
|
|
return new Promise((resolve) => {
|
|
modalState.visible = true;
|
|
modalState.title = options.title ?? "提示";
|
|
modalState.content = options.content ?? "";
|
|
modalState.confirmText = options.confirmText ?? "确定";
|
|
modalState.cancelText = options.cancelText ?? "取消";
|
|
modalState.showCancel = options.showCancel ?? true;
|
|
modalState.confirmDisabled = options.confirmDisabled ?? false;
|
|
modalState._resolve = resolve;
|
|
});
|
|
}
|
|
|
|
export function resolveModal(ok) {
|
|
modalState.visible = false;
|
|
const resolve = modalState._resolve;
|
|
modalState._resolve = null;
|
|
resolve?.(ok);
|
|
}
|