使用组件而非插件的形式重写 quickcommandUI

This commit is contained in:
fofolee
2022-04-25 01:43:57 +08:00
parent b0d06875b3
commit 6d8034d950
18 changed files with 426 additions and 493 deletions

View File

@@ -8,10 +8,10 @@ let escapeItem = item => {
return item.replace('$', '$$$')
}
let handlingJsonVar = (jsonVar, name) => {
let handlingJsonVar = (jsonVar, name, payload) => {
try {
return escapeItem(window.evalCodeInSandbox(jsonVar.slice(2, -2), {
[name]: quickcommand.enterData.payload
[name]: payload
}))
} catch (e) {
return utools.showNotification(e)
@@ -73,7 +73,7 @@ const specialVars = {
label: "{{input}}",
desc: "主输入框的文本",
match: /{{input}}/mg,
repl: () => quickcommand.enterData.payload
repl: (text, enterData) => enterData.payload
},
pwd: {
name: "pwd",
@@ -88,21 +88,21 @@ const specialVars = {
desc: "当前窗口信息JSON格式可以指定键值如{{WindowInfo.id}}",
type: "json",
match: /{{WindowInfo(.*?)}}/mg,
repl: jsonVar => handlingJsonVar(jsonVar, "WindowInfo")
repl: (jsonVar, enterData) => handlingJsonVar(jsonVar, "WindowInfo", enterData.payload)
},
MatchImage: {
name: "MatchImage",
label: "{{MatchImage}}",
desc: "匹配到图片的 DataUrl",
match: /{{MatchImage}}/mg,
repl: () => quickcommand.enterData.payload
repl: (text, enterData) => enterData.payload
},
SelectFile: {
name: "SelectFile",
label: "{{SelectFile}}",
desc: "文件管理器选中的文件不支持Linux",
match: /{{SelectFile}}/mg,
repl: () => window.getSelectFile(quickcommand.enterData.payload.id)
repl: (text, enterData) => window.getSelectFile(enterData.payload.id)
},
MatchedFiles: {
name: "MatchedFiles",
@@ -110,14 +110,14 @@ const specialVars = {
desc: "匹配的文件JSON格式可以指定键值如{{MatchedFiles[0].path}}",
type: "json",
match: /{{MatchedFiles(.*?)}}/mg,
repl: jsonVar => handlingJsonVar(jsonVar, "MatchedFiles")
repl: (jsonVar, enterData) => handlingJsonVar(jsonVar, "MatchedFiles", enterData.payload)
},
type: {
name: "type",
label: "{{type}}",
desc: "onPluginEnter的type匹配的类型",
match: /{{type}}/mg,
repl: () => quickcommand.enterData.type
repl: (text, enterData) => enterData.type
},
payload: {
name: "payload",
@@ -125,7 +125,7 @@ const specialVars = {
desc: "onPluginEnter的payload,当为JSON时可以指定键值如{{payload.id}}",
type: "json",
match: /{{payload(.*?)}}/mg,
repl: jsonVar => handlingJsonVar(jsonVar, "payload")
repl: (jsonVar, enterData) => handlingJsonVar(jsonVar, "payload", enterData.payload)
},
js: {
name: "js",

View File

@@ -1,131 +0,0 @@
/**
* 通过quickcommand的api快速生成可交互的UI界面
* UI界面基于quasar
*/
import {
Dialog,
Notify
} from 'quasar'
import inputBox from "../components/quickcommandUI/InputBox"
import buttonBox from "../components/quickcommandUI/ButtonBox"
import TextArea from "../components/quickcommandUI/TextArea"
import SelectList from "../components/quickcommandUI/SelectList"
import WaitButton from "../components/quickcommandUI/waitButton"
const quickcommand = {
showInputBox: (options = ["请输入"], title = "") => new Promise((reslove, reject) => {
let props = {
labels: [],
values: [],
hints: [],
title: title
}
if (!_.isObject(options)) return reject(new TypeError(`应为 Object, 而非 ${typeof options}`))
if (_.isArray(options)) props.labels = options
else Object.assign(props, options)
Dialog.create({
component: inputBox,
componentProps: props
}).onOk(results => {
reslove(Array.from(results))
}).onCancel(() => {
console.log('取消')
})
}),
showButtonBox: (labels = ["确定"], title = "") => new Promise((reslove, reject) => {
if (!_.isArray(labels)) return reject(new TypeError(`应为 Array, 而非 ${typeof labels}`))
let props = {
labels: labels,
title: title
}
Dialog.create({
component: buttonBox,
componentProps: props
}).onOk(results => {
reslove(results)
}).onCancel(() => {
console.log('取消')
})
}),
showConfirmBox: (message = "", title = "提示") => new Promise((reslove, reject) => {
Dialog.create({
title: title,
message: message,
cancel: true,
persistent: true
}).onOk(() => {
reslove(true)
}).onCancel(() => {
reslove(false)
})
}),
showMessageBox: (message, icon = 'success', time = 3000) => {
if (icon === 'success') icon = 'positive'
if (icon === 'error') icon = 'negative'
Notify.create({
type: icon,
message: message,
timeout: time,
position: 'top',
})
},
showTextArea: (placeholder = "", value = "") => new Promise((reslove, reject) => {
let props = {
placeholder: placeholder,
value: value
}
Dialog.create({
component: TextArea,
componentProps: props
}).onOk(results => {
reslove(results)
}).onCancel(() => {
console.log('取消')
})
}),
showSelectList: (selects, options = {}) => new Promise((reslove, reject) => {
if (!_.isArray(selects)) return reject(new TypeError(`应为 Array, 而非 ${typeof selects}`))
let defaultOptions = {
placeholder: "输入进行筛选,支持拼音",
optionType: "plaintext",
enableSearch: true,
showCancelButton: false,
closeOnSelect: true
}
Object.assign(defaultOptions, options)
let props = {
initItems: selects,
options: defaultOptions
}
Dialog.create({
component: SelectList,
componentProps: props
}).onOk(results => {
reslove(results)
}).onCancel(() => {
console.log('取消')
})
}),
showWaitButton: (callback, label = "确定") => {
Dialog.create({
component: WaitButton,
componentProps: {
label
}
}).onOk(() => {
callback()
}).onCancel(() => {
console.log('取消')
})
}
}
export default quickcommand