修改全局变量

This commit is contained in:
fofolee 2022-04-03 20:48:48 +08:00
parent 0fc83c31de
commit ec82130469
7 changed files with 50 additions and 31 deletions

View File

@ -26,8 +26,7 @@ module.exports = configure(function (ctx) {
// --> boot files are part of "main.js" // --> boot files are part of "main.js"
// https://v2.quasar.dev/quasar-cli-webpack/boot-files // https://v2.quasar.dev/quasar-cli-webpack/boot-files
boot: [ boot: [
'global.js'
], ],
// https://v2.quasar.dev/quasar-cli-webpack/quasar-config-js#Property%3A-css // https://v2.quasar.dev/quasar-cli-webpack/quasar-config-js#Property%3A-css

View File

@ -12,10 +12,10 @@ export default defineComponent({
}, },
computed: {}, computed: {},
created: function () { created: function () {
this.pluginEnterEvent(); this.init();
}, },
methods: { methods: {
pluginEnterEvent() { init() {
// //
const requiredVersion = "2.6.1"; const requiredVersion = "2.6.1";
let version = utools.getAppVersion(); let version = utools.getAppVersion();

10
src/boot/global.js Normal file
View File

@ -0,0 +1,10 @@
import { boot } from 'quasar/wrappers'
import UTOOLS from "../js/utools.js";
import programmings from '../js/programs.js';
// "async" is optional;
// more info on params: https://v2.quasar.dev/quasar-cli/boot-files
export default boot(async ({ app }) => {
app.config.globalProperties.$utools = UTOOLS
app.config.globalProperties.$programmings = programmings
})

View File

@ -175,13 +175,11 @@
</template> </template>
<script> <script>
import allProgrammings from "../js/programs.js";
import UTOOLS from "../js/utools.js";
export default { export default {
data() { data() {
return { return {
allProgrammings: allProgrammings, allProgrammings: this.$programmings,
isCommandActivated: this.activated, isCommandActivated: this.activated,
maxCmdStingLen: 8, maxCmdStingLen: 8,
cmdBadgeSheet: { cmdBadgeSheet: {
@ -266,8 +264,8 @@ export default {
type: "disable", type: "disable",
data: this.commandInfo.features.code, data: this.commandInfo.features.code,
}; };
if (!UTOOLS.whole.removeFeature(this.commandInfo.features.code)) { if (!this.$utools.whole.removeFeature(this.commandInfo.features.code)) {
UTOOLS.whole.setFeature( this.$utools.whole.setFeature(
JSON.parse(JSON.stringify(this.commandInfo.features)) JSON.parse(JSON.stringify(this.commandInfo.features))
); );
event.type = "enable"; event.type = "enable";
@ -280,8 +278,8 @@ export default {
if (!x) return; if (!x) return;
let code = this.commandInfo.features.code; let code = this.commandInfo.features.code;
utools.copyText(JSON.stringify(this.commandInfo, null, 4)); utools.copyText(JSON.stringify(this.commandInfo, null, 4));
UTOOLS.delDB(UTOOLS.DBPRE.QC + code); this.$utools.delDB(this.$utools.DBPRE.QC + code);
UTOOLS.whole.removeFeature(code); this.$utools.whole.removeFeature(code);
this.isCommandAlive = false; this.isCommandAlive = false;
this.$emit("commandChanged", { this.$emit("commandChanged", {
type: "remove", type: "remove",

View File

@ -129,15 +129,13 @@
</template> </template>
<script> <script>
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 },
data() { data() {
return { return {
options: Object.keys(allProgrammings), options: Object.keys(this.$programmings),
program: "quickcommand", program: "quickcommand",
customOptions: { bin: "", argv: "", ext: "" }, customOptions: { bin: "", argv: "", ext: "" },
scptarg: "", scptarg: "",
@ -165,7 +163,7 @@ export default {
// //
loadOrSaveHistory() { loadOrSaveHistory() {
// //
var history = UTOOLS.getDB(UTOOLS.DBPRE.CFG + "codeHistory"); var history = this.$utools.getDB(this.$utools.DBPRE.CFG + "codeHistory");
if (history.program) { if (history.program) {
this.$refs.editor.setEditorValue(history.cmd); this.$refs.editor.setEditorValue(history.cmd);
this.program = history.program; this.program = history.program;
@ -184,7 +182,7 @@ export default {
customOptions: JSON.parse(JSON.stringify(this.customOptions)), customOptions: JSON.parse(JSON.stringify(this.customOptions)),
}; };
// //
UTOOLS.putDB(saveData, UTOOLS.DBPRE.CFG + "codeHistory"); this.$utools.putDB(saveData, this.$utools.DBPRE.CFG + "codeHistory");
}); });
}, },
// //
@ -197,7 +195,7 @@ export default {
}, },
// //
matchLanguage() { matchLanguage() {
let language = Object.values(allProgrammings).filter( let language = Object.values(this.$programmings).filter(
(program) => program.ext === this.customOptions.ext (program) => program.ext === this.customOptions.ext
); );
if (language.length) { if (language.length) {
@ -206,7 +204,7 @@ export default {
}, },
// //
setLanguage(language) { setLanguage(language) {
let highlight = allProgrammings[language].highlight; let highlight = this.$programmings[language].highlight;
this.$refs.editor.setEditorLanguage(highlight ? highlight : language); this.$refs.editor.setEditorLanguage(highlight ? highlight : language);
}, },
// //
@ -255,7 +253,7 @@ export default {
this.showRunResult(stdout, raw, true); this.showRunResult(stdout, raw, true);
}); });
} else { } else {
let option = allProgrammings[this.program]; let option = this.$programmings[this.program];
if (this.program === "custom") if (this.program === "custom")
option = { option = {
bin: this.customOptions.bin, bin: this.customOptions.bin,

View File

@ -276,7 +276,6 @@
</template> </template>
<script> <script>
import UTOOLS from "../js/utools.js";
import quickcommandParser from "../js/quickcommandParser.js"; import quickcommandParser from "../js/quickcommandParser.js";
import CommandCard from "components/CommandCard"; import CommandCard from "components/CommandCard";
@ -365,7 +364,18 @@ export default {
this.activatedQuickPanels = activatedFeatures.quickpanels; this.activatedQuickPanels = activatedFeatures.quickpanels;
// //
this.allQuickCommands = this.getAllQuickCommands(); this.allQuickCommands = this.getAllQuickCommands();
let userPreferences = this.$utools.getDB(
this.$utools.DBPRE.CFG + "preferences"
);
this.commandCardStyle = userPreferences.commandCardStyle || "normal";
console.log("ConfigurationPage", this); console.log("ConfigurationPage", this);
utools.onPluginOut(() => {
userPreferences.commandCardStyle = this.commandCardStyle;
this.$utools.putDB(
userPreferences,
this.$utools.DBPRE.CFG + "preferences"
);
});
}, },
// features // features
getActivatedFeatures() { getActivatedFeatures() {
@ -385,9 +395,9 @@ export default {
// //
getAllQuickCommands() { getAllQuickCommands() {
let allQcs = {}; let allQcs = {};
UTOOLS.getDocs(UTOOLS.DBPRE.QC).forEach( this.$utools
(x) => (allQcs[x.data.features.code] = x.data) .getDocs(this.$utools.DBPRE.QC)
); .forEach((x) => (allQcs[x.data.features.code] = x.data));
return allQcs; return allQcs;
}, },
// //
@ -450,15 +460,18 @@ export default {
}; };
// //
if (dataToPushed.single) { if (dataToPushed.single) {
UTOOLS.putDB( this.$utools.putDB(
dataToPushed.qc, dataToPushed.qc,
UTOOLS.DBPRE.QC + dataToPushed.qc.features.code this.$utools.DBPRE.QC + dataToPushed.qc.features.code
); );
this.allQuickCommands[dataToPushed.qc.features.code] = dataToPushed.qc; this.allQuickCommands[dataToPushed.qc.features.code] = dataToPushed.qc;
// //
} else { } else {
for (var code of Object.keys(dataToPushed.qc)) { for (var code of Object.keys(dataToPushed.qc)) {
UTOOLS.putDB(dataToPushed.qc[code], UTOOLS.DBPRE.QC + code); this.$utools.putDB(
dataToPushed.qc[code],
this.$utools.DBPRE.QC + code
);
} }
Object.assign(this.allQuickCommands, dataToPushed.qc); Object.assign(this.allQuickCommands, dataToPushed.qc);
} }
@ -512,9 +525,10 @@ export default {
if (!isConfirmed) if (!isConfirmed)
return quickcommand.showMessageBox("取消操作", "info"); return quickcommand.showMessageBox("取消操作", "info");
this.exportAllCommands(false); this.exportAllCommands(false);
UTOOLS.getDocs(UTOOLS.DBPRE.QC) this.$utools
.getDocs(this.$utools.DBPRE.QC)
.map((x) => x._id) .map((x) => x._id)
.forEach((y) => UTOOLS.delDB(y)); .forEach((y) => this.$utools.delDB(y));
this.importDefaultCommands(); this.importDefaultCommands();
this.clearAllFeatures(); this.clearAllFeatures();
Object.keys(this.allQuickCommands).forEach((featureCode) => { Object.keys(this.allQuickCommands).forEach((featureCode) => {
@ -529,7 +543,7 @@ export default {
// features // features
clearAllFeatures() { clearAllFeatures() {
for (var feature of utools.getFeatures()) { for (var feature of utools.getFeatures()) {
UTOOLS.whole.removeFeature(feature.code); this.$utools.whole.removeFeature(feature.code);
} }
}, },
// //

View File

@ -1,9 +1,9 @@
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 '../js/quickcommand' import quickcommandUI from '../js/quickcommand'
window.quickcommand = quickcommand Object.assign(window.quickcommand, quickcommandUI)
/* /*
* If not building with SSR mode, you can * If not building with SSR mode, you can