Skip to content

Commit

Permalink
实现菜单debug & 修复脚本缓存问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed May 18, 2021
1 parent ce7ebbe commit 42b9adb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
5 changes: 3 additions & 2 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
## v0.3.4

* 新建脚本默认开启
* 新建脚本默认开启(从远程安装的后端脚本依旧默认为不开启)
* 管理面板简单的分页功能
* 增加开机启动自动运行
* 支持`@require-css`直接引入css文件
* 支持`document-menu`执行方式
* 修复若干bug
* 支持`@include``@exclude`
* 移除`@debug`,新增菜单条
* 修复若干bug

## v0.3.0
> 开始支持油猴脚本了
Expand Down
6 changes: 5 additions & 1 deletion src/apps/script/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ export class ScriptManager {

public loadScriptByUrl(url: string): Promise<ScriptUrlInfo | undefined> {
return new Promise(resolve => {
axios.get(url).then((response): ScriptUrlInfo | undefined => {
axios.get(url, {
headers: {
'Cache-Control': 'no-cache'
}
}).then((response): ScriptUrlInfo | undefined => {
if (response.status != 200) {
return undefined;
}
Expand Down
1 change: 1 addition & 0 deletions src/types/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface IUpdateMeta {
interface ISave {
scriptId: number;
currentCode: string;
debug: boolean;
}

interface IInitialScript {
Expand Down
9 changes: 7 additions & 2 deletions src/views/pages/Option/tabs/ScriptTab/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ export default class CloseButton extends Vue {
{
action: "调试",
handler: () => {
console.log("菜单action");
eventBus.$emit<ISave>(EventType.Save, {
scriptId: this.scriptId,
currentCode: this.editor.getValue(),
debug: true,
});
},
tooltip: "调试后台脚本",
},
Expand Down Expand Up @@ -154,6 +158,7 @@ export default class CloseButton extends Vue {
eventBus.$emit<ISave>(EventType.Save, {
scriptId: this.scriptId,
currentCode: this.editor.getValue(),
debug: false,
});
});
Expand All @@ -177,4 +182,4 @@ export default class CloseButton extends Vue {
color: rgb(128, 128, 128);
cursor: not-allowed;
}
</style>
</style>
21 changes: 7 additions & 14 deletions src/views/pages/Option/tabs/ScriptTab/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default class ScriptTab extends Vue {
this.handleInitialSctipt(payload);
}
});
eventBus.$on<ISave>("save", (payload) => {
eventBus.$on<ISave>(EventType.Save, (payload) => {
if (payload.scriptId === this.scriptId) {
this.handleSave(payload);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ export default class ScriptTab extends Vue {
this.script = script;
this.metaBuffer = this.prepareMetaBuffer(this.script.metadata);
eventBus.$emit<IChangeTitle>("change-title", {
eventBus.$emit<IChangeTitle>(EventType.ChangeTitle, {
title: script.name,
scriptId: this.scriptId ?? this.localScriptId,
});
Expand All @@ -187,7 +187,7 @@ export default class ScriptTab extends Vue {
this.onMetaChange = false;
}
async handleSave({ currentCode }: ISave) {
async handleSave({ currentCode, debug }: ISave) {
// todo 保存时候错误处理
let [newScript, oldScript] = await this.scriptMgr.prepareScriptByCode(
currentCode,
Expand Down Expand Up @@ -225,21 +225,14 @@ export default class ScriptTab extends Vue {
await this.handleInitialSctipt({} as any);
// 还原unsavdChange状态的title
eventBus.$emit<IChangeTitle>("change-title", {
eventBus.$emit<IChangeTitle>(EventType.ChangeTitle, {
title: `${this.script.name}`,
scriptId: this.scriptId ?? this.localScriptId,
});
if (oldScript) {
// 后台脚本才可以调用
if (this.script.metadata["debug"] != undefined) {
this.scriptMgr.execScript(this.script, true);
}
} else {
// eventBus.$emit<INewScript>("new-script", {
// scriptId: this.scriptId ?? this.localScriptId,
// });
// this.$router.push({ path: "/" });
// 后台脚本才可以调用
if (debug) {
this.scriptMgr.execScript(this.script, true);
}
this.$refs.editor.hasUnsavedChange = false;
Expand Down

0 comments on commit 42b9adb

Please sign in to comment.