新增quickcommand.showLoadingBar,支持显示加载条

This commit is contained in:
fofolee
2025-02-17 22:38:19 +08:00
parent d7508c36a7
commit 3eca3b448e
14 changed files with 339 additions and 84 deletions

View File

@@ -26,7 +26,6 @@ export default defineComponent({
commandManager: useCommandManager(),
setCssVar: setCssVar,
programs: programmings,
isRunningCommand: false,
profile: defaultProfile.common,
nativeProfile: defaultProfile.native,
utools: utoolsFull,

View File

@@ -126,7 +126,6 @@ export default {
if (command.program === "quickcomposer") {
command.cmd = generateFlowsCode(command.flows);
}
this.$root.isRunningCommand = true;
this.needTempPayload && (await this.getTempPayload(command));
// 如果命令包含子输入框,则设置子输入框
if (command.cmd.includes("{{subinput")) return this.setSubInput(command);
@@ -292,7 +291,6 @@ export default {
};
},
handleResult(stdout, stderr, options) {
this.$root.isRunningCommand = false;
if (stderr) {
return options.earlyExit
? alert(stderr)
@@ -302,7 +300,6 @@ export default {
},
// 显示运行结果
async showRunResult(content, isSuccess) {
this.$root.isRunningCommand = false;
content = await this.handleContent(content);
this.runResultStatus = isSuccess;
this.runResult = this.runResult.concat(content);

View File

@@ -17,9 +17,6 @@
/>
</div>
</div>
<q-inner-loading :showing="hasCommandNeedLoading && $root.isRunningCommand">
<q-spinner-cube size="50px" color="primary" />
</q-inner-loading>
</div>
</template>
@@ -38,7 +35,6 @@ export default defineComponent({
data() {
return {
availableCommands,
hasCommandNeedLoading: false,
};
},
props: {
@@ -57,16 +53,6 @@ export default defineComponent({
// 直接转发事件和代码
this.$emit("action", actionType, actionData);
},
findCommandNeedLoading(flow) {
// 暂时只在运行单独命令时显示载入界面,因为运行整个命令流时,如果不打印输出,是无法判断什么时候运行结束的,
// 运行单独命令时添加了打印流程且showLoading参数可控
if (!flow) return;
return flow.some(
(cmd) =>
cmd.showLoading ||
cmd.subCommands?.find((c) => c.value === cmd.value)?.showLoading
);
},
},
});
</script>

View File

@@ -11,7 +11,6 @@ export const aiCommands = {
desc: "获取API支持的模型列表",
asyncMode: "await",
icon: "list",
showLoading: true,
config: [
{
label: "API配置",
@@ -74,7 +73,6 @@ export const aiCommands = {
desc: "与AI助手进行对话",
asyncMode: "await",
icon: "chat",
showLoading: true,
config: [
{
label: "API配置",

View File

@@ -440,26 +440,21 @@ export const uiCommands = {
{
component: "OptionEditor",
options: {
title: {
label: "标题",
component: "VariableInput",
width: 6,
},
text: {
label: "文本",
component: "VariableInput",
width: 6,
width: 4,
},
value: {
label: "初始进度值",
component: "VariableInput",
disableToggleType: true,
width: 3,
width: 4,
},
position: {
label: "位置",
component: "QSelect",
width: 3,
width: 4,
options: [
{ label: "屏幕左上角", value: "top-left" },
{ label: "屏幕右上角", value: "top-right" },
@@ -471,20 +466,20 @@ export const uiCommands = {
label: "关闭按钮回调函数",
component: "VariableInput",
disableToggleType: true,
width: 6,
width: 4,
},
onPause: {
label: "暂停按钮回调函数",
component: "VariableInput",
disableToggleType: true,
width: 6,
width: 4,
placeholder: "必须和恢复回调一起配置",
},
onResume: {
label: "恢复按钮回调函数",
component: "VariableInput",
disableToggleType: true,
width: 6,
width: 4,
placeholder: "必须和暂停回调一起配置",
},
},
@@ -542,6 +537,65 @@ export const uiCommands = {
},
],
},
{
value: "quickcommand.showLoadingBar",
label: "显示载入界面",
neverHasOutput: true,
asyncMode: "await",
config: [
{
component: "OptionEditor",
options: {
text: {
label: "文本",
component: "VariableInput",
width: 4,
},
position: {
label: "位置",
component: "QSelect",
width: 4,
options: [
{ label: "屏幕左上角", value: "top-left" },
{ label: "屏幕右上角", value: "top-right" },
{ label: "屏幕左下角", value: "bottom-left" },
{ label: "屏幕右下角", value: "bottom-right" },
],
},
onClose: {
label: "关闭按钮回调函数",
component: "VariableInput",
disableToggleType: true,
width: 4,
},
},
defaultValue: {
text: newVarInputVal("str", "加载中..."),
position: "bottom-right",
onClose: newVarInputVal("var"),
},
},
],
outputs: {
label: "载入条对象",
suggestName: "loadingBar",
},
},
{
value: "quickcommand.closeLoadingBar",
label: "关闭载入界面",
neverHasOutput: true,
config: [
{
label: "载入条对象",
component: "VariableInput",
placeholder: "不传则关闭最近的载入条",
width: 12,
defaultValue: newVarInputVal("var"),
disableToggleType: true,
},
],
},
{
value: "utools.showOpenDialog",
label: "文件选择框",

View File

@@ -933,7 +933,6 @@ export const windowsCommands = {
label: "剪贴板/文件监控",
icon: "monitor_heart",
asyncMode: "await",
showLoading: true,
subCommands: [
{
value: "quickcomposer.windows.monitor.watchClipboard",

View File

@@ -724,7 +724,6 @@ interface quickcommandApi {
/**
* 显示一个带有暂停、恢复、关闭回调功能的进度条,支持动态更新进度
* @param {object} options - 配置选项
* @param {string} [options.title="进度"] - 对话框标题
* @param {string} [options.text="处理中..."] - 进度条上方的文本
* @param {number} [options.value=0] - 初始进度值(0-100)
* @param {string} [options.position="bottom-right"] - 进度条位置可选值top-left, top-right, bottom-left, bottom-right
@@ -736,7 +735,6 @@ interface quickcommandApi {
* ```js
* // 基本使用
* const processBar = await quickcommand.showProcessBar({
* title: "下载进度",
* text: "正在下载文件...",
* value: 0,
* position: "bottom-right"
@@ -745,7 +743,6 @@ interface quickcommandApi {
* // 带暂停/恢复,关闭回调功能
* let isPaused = false;
* const processBar = await quickcommand.showProcessBar({
* title: "下载进度",
* text: "正在下载文件...",
* value: 0,
* onPause: () => {
@@ -839,6 +836,58 @@ interface quickcommandApi {
close: () => void;
}
): void;
/**
* 显示一个循环动画的加载条
* @param {object} options - 配置选项
* @param {string} [options.text="加载中..."] - 加载条上方的文本
* @param {string} [options.position="bottom-right"] - 加载条位置可选值top-left, top-right, bottom-left, bottom-right
* @param {Function} [options.onClose] - 关闭按钮点击时的回调函数
* @returns {Promise<{id: number, close: Function}>} 返回加载条对象
*
* ```js
* // 基本使用
* const loadingBar = await quickcommand.showLoadingBar({
* text: "正在加载...",
* position: "bottom-right"
* });
*
* // 带关闭回调
* const loadingBar = await quickcommand.showLoadingBar({
* text: "正在加载...",
* onClose: () => {
* console.log("用户关闭了加载条");
* }
* });
*
* // 手动关闭
* loadingBar.close();
* // 或者
* quickcommand.closeLoadingBar();
* ```
*/
showLoadingBar(options?: {
text?: string;
position?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
onClose?: () => void;
}): Promise<{
id: number;
close: () => void;
}>;
/**
* 关闭加载条
* @param {{id: number, close: Function}|undefined} loadingBar - 加载条对象,如果不传入则关闭上一次创建的加载条
*
* ```js
* // 关闭最近创建的加载条
* quickcommand.closeLoadingBar();
*
* // 关闭指定的加载条
* quickcommand.closeLoadingBar(loadingBar);
* ```
*/
closeLoadingBar(loadingBar?: { id: number; close: () => void }): void;
}
declare var quickcommand: quickcommandApi;