补全屏幕截图、屏幕取色、获取显示器信息、剪贴板操作

This commit is contained in:
fofolee
2025-01-09 22:43:33 +08:00
parent 682f6d0bcd
commit 378ae7f92f
10 changed files with 420 additions and 83 deletions

View File

@@ -41,16 +41,16 @@ export default defineComponent({
// 过滤掉特定函数排除的参数, excludeConfig格式为[要排除的参数索引]
this.modelValue.config?.filter(
(_, index) =>
!this.getSelectFunction()?.excludeConfig?.includes(index)
!this.getSelectSubCommand()?.excludeConfig?.includes(index)
) || []
);
},
// 特定函数独有参数配置config格式和通用的config一致
functionConfig() {
return this.getSelectFunction()?.config || [];
subCommandConfig() {
return this.getSelectSubCommand()?.config || [];
},
localConfig() {
return [...this.commonConfig, ...this.functionConfig].map((item) => {
return [...this.commonConfig, ...this.subCommandConfig].map((item) => {
const value =
item.type === "varInput"
? item.defaultValue || newVarInputVal("str")
@@ -79,7 +79,7 @@ export default defineComponent({
});
// 使用新选择的函数独有配置的默认值
this.getSelectFunction(value)?.config?.forEach((config, index) => {
this.getSelectSubCommand(value)?.config?.forEach((config, index) => {
newArgvs[this.commonConfig.length + index] = config.defaultValue;
});
@@ -96,7 +96,7 @@ export default defineComponent({
},
},
methods: {
getSelectFunction(funcName = this.funcName) {
getSelectSubCommand(funcName = this.funcName) {
return this.modelValue.subCommands?.find(
(item) => item.value === funcName
);
@@ -165,7 +165,7 @@ export default defineComponent({
},
getSummary(argvs) {
// 虽然header里对溢出做了处理但是这里截断主要是为了节省存储空间
const funcNameLabel = this.getSelectFunction()?.label;
const funcNameLabel = this.getSelectSubCommand()?.label;
const subFeature = funcNameLabel ? `${funcNameLabel} ` : "";
const allArgvs = argvs
.filter((item) => item != null && item != "")

View File

@@ -82,7 +82,10 @@
"
/>
</div>
<div v-if="item.type !== 'fixed'" class="col-auto">
<div
v-if="item.type !== 'fixed' && !options?.disableAdd"
class="col-auto"
>
<div class="btn-container">
<template v-if="editableItems.length === 1">
<q-btn
@@ -145,6 +148,7 @@ import BorderLabel from "components/composer/common/BorderLabel.vue";
* @property {Object} options - 配置选项
* @property {String[]|Object[]} [options.optionKeys] - 可选键名
* @property {String[]|Object[]} [options.fixedKeys] - 固定键名
* @property {Boolean} [options.disableAdd] - 禁止添加新的键值对
*
* @example
* // 基础字典对象
@@ -195,30 +199,7 @@ export default defineComponent({
},
emits: ["update:modelValue"],
data() {
const modelEntries = Object.entries(this.modelValue || {});
const fixedKeys = this.normalizeKeys(this.options?.fixedKeys || []);
const fixedKeyValues = fixedKeys.map((key) => ({
type: "fixed",
key: key.value,
value:
modelEntries.find(([k]) => k === key.value)?.[1] ||
newVarInputVal("str"),
}));
const editableEntries = modelEntries.filter(
([key]) => !fixedKeys.some((k) => k.value === key)
);
return {
fixedItems: fixedKeyValues,
localItems: editableEntries.length
? editableEntries.map(([key, value]) => ({
type: "editable",
key,
value,
}))
: [{ type: "editable", key: "", value: newVarInputVal("str") }],
filterOptions: this.normalizeKeys(this.options?.optionKeys || []),
inputValue: "",
};
},
@@ -232,11 +213,49 @@ export default defineComponent({
this.updateModelValue();
},
},
normalizedOptionKeys() {
return this.filterOptions;
},
// 规范化的固定键列表
normalizedFixedKeys() {
return this.normalizeKeys(this.options?.fixedKeys || []);
},
// 从 modelValue 中提取的所有条目
modelEntries() {
return Object.entries(this.modelValue || {});
},
// 固定键项
fixedItems() {
return this.normalizedFixedKeys.map((key) => ({
type: "fixed",
key: key.value,
value:
this.modelEntries.find(([k]) => k === key.value)?.[1] ||
newVarInputVal("str"),
}));
},
// 可编辑项
localItems() {
// 过滤出不在固定键中的条目
const editableEntries = this.modelEntries.filter(
([key]) => !this.normalizedFixedKeys.some((k) => k.value === key)
);
return editableEntries.length || this.options?.disableAdd
? editableEntries.map(([key, value]) => ({
type: "editable",
key,
value,
}))
: [{ type: "editable", key: "", value: newVarInputVal("str") }];
},
// 所有项目的组合
allItems() {
return [...this.fixedItems, ...this.localItems];
},
normalizedOptionKeys() {
return this.filterOptions;
// 过滤选项
filterOptions() {
return this.normalizeKeys(this.options?.optionKeys || []);
},
},
methods: {
@@ -251,10 +270,7 @@ export default defineComponent({
getKeyLabel(key) {
if (typeof key === "object") return key.label;
const allKeys = [
...this.normalizeKeys(this.options?.fixedKeys || []),
...this.normalizeKeys(this.options?.optionKeys || []),
];
const allKeys = [...this.normalizedFixedKeys, ...this.filterOptions];
return allKeys.find((k) => k.value === key)?.label || key;
},
@@ -280,62 +296,57 @@ export default defineComponent({
},
updateItemValue(val, index, isFixed = false) {
if (isFixed) {
const newItems = [...this.fixedItems];
newItems[index].value = val;
this.fixedItems = newItems;
} else {
const newItems = [...this.localItems];
newItems[index].value = val;
this.localItems = newItems;
const dict = { ...this.modelValue };
const item = this.allItems[index];
if (item.key) {
dict[item.key] = val;
this.$emit("update:modelValue", dict);
}
this.updateModelValue();
},
addItem() {
this.localItems = [
...this.localItems,
{
key: "",
value: newVarInputVal("str"),
},
];
if (this.options?.disableAdd) return;
const dict = { ...this.modelValue };
dict[""] = newVarInputVal("str");
this.$emit("update:modelValue", dict);
},
removeItem(index) {
const newItems = [...this.localItems];
newItems.splice(index, 1);
if (newItems.length === 0) {
newItems.push({
key: "",
value: newVarInputVal("str"),
});
if (this.options?.disableAdd) return;
const dict = { ...this.modelValue };
const item = this.localItems[index];
if (item.key) {
delete dict[item.key];
this.$emit("update:modelValue", dict);
}
this.localItems = newItems;
},
updateItemKey(val, index) {
const newItems = [...this.localItems];
newItems[index].key = val;
this.localItems = newItems;
const dict = { ...this.modelValue };
const oldItem = this.localItems[index];
if (oldItem.key) {
delete dict[oldItem.key];
}
dict[val] = oldItem.value;
this.$emit("update:modelValue", dict);
},
handleInput(val, index) {
this.inputValue = val;
if (val) {
const newItems = [...this.localItems];
newItems[index].key = val;
this.localItems = newItems;
this.updateModelValue();
this.updateItemKey(val, index);
}
},
handleSelect(val, index) {
this.inputValue = "";
const newItems = [...this.localItems];
newItems[index].key = val.value || val;
this.localItems = newItems;
this.updateModelValue();
this.updateItemKey(val.value || val, index);
},
handleBlur() {
this.inputValue = "";
},
filterFn(val, update) {
if (!this.options?.optionKeys) return;