mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 23:16:18 +08:00
添加历史代码功能
This commit is contained in:
parent
4d07847196
commit
27e077b56b
@ -1,24 +0,0 @@
|
|||||||
import { Dialog } from 'quasar'
|
|
||||||
import inputBox from "../components/InputBox"
|
|
||||||
|
|
||||||
let showInputBox = (labels = [], title = "", hints = []) => {
|
|
||||||
return new Promise((reslove, reject) => {
|
|
||||||
Dialog.create({
|
|
||||||
component: inputBox,
|
|
||||||
componentProps: {
|
|
||||||
labels: labels,
|
|
||||||
title: title,
|
|
||||||
hints: hints
|
|
||||||
}
|
|
||||||
}).onOk(results => {
|
|
||||||
reslove(Array.from(results))
|
|
||||||
}).onCancel(() => {
|
|
||||||
console.log('取消')
|
|
||||||
}).onDismiss(() => {
|
|
||||||
console.log('对话框被关闭')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
};
|
|
||||||
export default {
|
|
||||||
showInputBox,
|
|
||||||
};
|
|
@ -5,7 +5,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import * as monaco from "monaco-editor";
|
import * as monaco from "monaco-editor";
|
||||||
import { toRaw } from "vue";
|
import { toRaw } from "vue";
|
||||||
import importAll from "../api/importAll.js";
|
import importAll from "../js/importAll.js";
|
||||||
|
|
||||||
// 批量导入声明文件
|
// 批量导入声明文件
|
||||||
let apis = importAll(
|
let apis = importAll(
|
||||||
@ -135,6 +135,9 @@ export default {
|
|||||||
getEditorValue() {
|
getEditorValue() {
|
||||||
return toRaw(this.editor).getValue();
|
return toRaw(this.editor).getValue();
|
||||||
},
|
},
|
||||||
|
setEditorValue(value) {
|
||||||
|
toRaw(this.editor).setValue(value);
|
||||||
|
},
|
||||||
setEditorLanguage(language) {
|
setEditorLanguage(language) {
|
||||||
monaco.editor.setModelLanguage(this.editor.getModel(), language);
|
monaco.editor.setModelLanguage(this.editor.getModel(), language);
|
||||||
},
|
},
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* 快速导入同一目录下的所有脚本
|
||||||
|
*/
|
||||||
|
|
||||||
const importAll = context => {
|
const importAll = context => {
|
||||||
const map = {}
|
const map = {}
|
||||||
for (const key of context.keys()) {
|
for (const key of context.keys()) {
|
@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* 所有支持的编程语言
|
||||||
|
*/
|
||||||
|
|
||||||
const programs = {
|
const programs = {
|
||||||
quickcommand: {
|
quickcommand: {
|
||||||
name: "quickcommand",
|
name: "quickcommand",
|
@ -14,8 +14,8 @@ let showInputBox = (options = [], title = "") => {
|
|||||||
if (!(options instanceof Object)) return reject(new TypeError("必须为数组或对象"))
|
if (!(options instanceof Object)) return reject(new TypeError("必须为数组或对象"))
|
||||||
if (options instanceof Array) props.labels = options
|
if (options instanceof Array) props.labels = options
|
||||||
else props = options
|
else props = options
|
||||||
if (!props.values) props.values = options.map(() => "")
|
if (!props.values) props.values = options.labels.map(() => "")
|
||||||
if (!props.hints) props.hints = options.map(() => "")
|
if (!props.hints) props.hints = options.labels.map(() => "")
|
||||||
Dialog.create({
|
Dialog.create({
|
||||||
component: inputBox,
|
component: inputBox,
|
||||||
componentProps: props
|
componentProps: props
|
||||||
|
51
src/js/utools.js
Normal file
51
src/js/utools.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
* 阉割utools,同时返回一个满血版的UTOOLS
|
||||||
|
* 防止输出html输出时,通过script标签调用utools执行危险函数
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 禁用危险函数
|
||||||
|
let whole = window.utools
|
||||||
|
if (!utools.isDev()) window.utools = window.getuToolsLite()
|
||||||
|
|
||||||
|
// 数据库前缀
|
||||||
|
const DBPRE = {
|
||||||
|
QC: 'qc_',
|
||||||
|
CFG: 'cfg_',
|
||||||
|
PAN: 'pan_'
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据库函数封装
|
||||||
|
let getDB = id => {
|
||||||
|
let db = whole.db.get(id)
|
||||||
|
return db ? db.data : {}
|
||||||
|
}
|
||||||
|
|
||||||
|
let putDB = (value, id) => {
|
||||||
|
let db = whole.db.get(id);
|
||||||
|
if (db) whole.db.put({
|
||||||
|
_id: id,
|
||||||
|
data: value,
|
||||||
|
_rev: db._rev
|
||||||
|
})
|
||||||
|
else whole.db.put({
|
||||||
|
_id: id,
|
||||||
|
data: value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let delDB = id => {
|
||||||
|
return whole.db.remove(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
let getDocs = key => {
|
||||||
|
return whole.db.allDocs(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
whole,
|
||||||
|
getDB,
|
||||||
|
putDB,
|
||||||
|
delDB,
|
||||||
|
getDocs,
|
||||||
|
DBPRE
|
||||||
|
}
|
@ -127,8 +127,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import allProgrammings from "../api/programs.js";
|
import allProgrammings from "../js/programs.js";
|
||||||
import MonocaEditor from "components/MonocaEditor";
|
import MonocaEditor from "components/MonocaEditor";
|
||||||
|
import UTOOLS from "../js/utools.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { MonocaEditor },
|
components: { MonocaEditor },
|
||||||
@ -149,6 +150,7 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.bindKeys();
|
this.bindKeys();
|
||||||
|
this.loadOrSaveHistory();
|
||||||
},
|
},
|
||||||
computed: {},
|
computed: {},
|
||||||
created() {},
|
created() {},
|
||||||
@ -158,6 +160,30 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
loadOrSaveHistory() {
|
||||||
|
// 读取
|
||||||
|
var history = UTOOLS.getDB(UTOOLS.DBPRE.CFG + "codeHistory");
|
||||||
|
if (history.program) {
|
||||||
|
this.$refs.editor.setEditorValue(history.cmd);
|
||||||
|
this.program = history.program;
|
||||||
|
this.scptarg = history.scptarg || "";
|
||||||
|
this.scriptCode = history.scriptCode || "";
|
||||||
|
this.outputCode = history.outputCode || "";
|
||||||
|
if (history.customOptions) this.customOptions = history.customOptions;
|
||||||
|
}
|
||||||
|
utools.onPluginOut(() => {
|
||||||
|
var saveData = {
|
||||||
|
cmd: this.$refs.editor.getEditorValue(),
|
||||||
|
program: this.program,
|
||||||
|
scptarg: this.scptarg,
|
||||||
|
scriptCode: this.scriptCode,
|
||||||
|
outputCode: this.outputCode,
|
||||||
|
customOptions: JSON.parse(JSON.stringify(this.customOptions))
|
||||||
|
};
|
||||||
|
// 保存
|
||||||
|
UTOOLS.putDB(saveData, UTOOLS.DBPRE.CFG + "codeHistory");
|
||||||
|
});
|
||||||
|
},
|
||||||
bindKeys() {
|
bindKeys() {
|
||||||
let that = this;
|
let that = this;
|
||||||
// ctrl+b 运行
|
// ctrl+b 运行
|
||||||
@ -184,14 +210,18 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
showCodingPage() {
|
showCodingPage() {
|
||||||
quickcommand.showInputBox(
|
quickcommand
|
||||||
["文件编码", "输出编码"],
|
.showInputBox(
|
||||||
"编码设置",
|
{
|
||||||
["基于iconv-lite进行编码,无乱码请留空", "无乱码请留空"],
|
labels: ["文件编码", "输出编码"],
|
||||||
(res) => {
|
hints: ["基于iconv-lite进行编码,无乱码请留空", "无乱码请留空"],
|
||||||
|
values: [this.scriptCode, this.outputCode],
|
||||||
|
},
|
||||||
|
"编码设置"
|
||||||
|
)
|
||||||
|
.then((res) => {
|
||||||
if (res) [this.scriptCode, this.outputCode] = res;
|
if (res) [this.scriptCode, this.outputCode] = res;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
},
|
},
|
||||||
async runCurrentCommand() {
|
async runCurrentCommand() {
|
||||||
let cmd = this.$refs.editor.getEditorValue();
|
let cmd = this.$refs.editor.getEditorValue();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { route } from 'quasar/wrappers'
|
import { route } from 'quasar/wrappers'
|
||||||
import { createRouter, createMemoryHistory, createWebHistory, createWebHashHistory } from 'vue-router'
|
import { createRouter, createMemoryHistory, createWebHistory, createWebHashHistory } from 'vue-router'
|
||||||
import routes from './routes'
|
import routes from './routes'
|
||||||
import quickcommand from '../api/quickcommand'
|
import quickcommand from '../js/quickcommand'
|
||||||
|
|
||||||
window.quickcommand = quickcommand
|
window.quickcommand = quickcommand
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user