Skip to content

Commit

Permalink
feat(v-console): 支持返回上一页
Browse files Browse the repository at this point in the history
  • Loading branch information
novlan1 committed Aug 8, 2023
1 parent f657fd1 commit 045f08a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 3 additions & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ const rollupConfig = {
resolve(),

// 使得 rollup 支持 commonjs 规范,识别 commonjs 规范的依赖
commonjs(),
commonjs({
sourceMap: false,
}),

// filesize(),

Expand Down
4 changes: 3 additions & 1 deletion src/v-console/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const V_CONSOLE_DOM = {
LINE: 'line',
WRAP: 'v-console-custom-tab',
URL_INPUT_ID: 'vConsolePluginInput',
URL_JUMP_BUTTON: 'vConsolePluginButton',
URL_JUMP_BUTTON: 'vConsolePluginUrlJumpButton',
GO_BACK_BUTTON: 'vConsolePluginGoBackButton',
} as const;

export const EMPTY_LINE = `<div class="${V_CONSOLE_DOM.LINE}"> </div>`;
Expand Down Expand Up @@ -66,6 +67,7 @@ export const V_CONSOLE_STYLE_CONTENT = `
border: 1px solid #07c160;
font-size: 14px;
padding: 0 12px;
margin-right: 10px;
}
.vc-cmd,
Expand Down
27 changes: 19 additions & 8 deletions src/v-console/plugin/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ function jumpToUrl() {
location.href = inputValue;
}

function goBack() {
history.go(-1);
window.vConsole?.hide?.();
}

export function initVersionPlugin() {
const plugin = new VConsole.VConsolePlugin('versionPerformance', '其他信息');
const parseNumber = (num: string | number) => +(+num).toFixed(2);
Expand All @@ -43,6 +48,7 @@ export function initVersionPlugin() {
html += `
<textarea id="${V_CONSOLE_DOM.URL_INPUT_ID}" type="text" placeholder="请输入跳转路径"></textarea>
<button id="${V_CONSOLE_DOM.URL_JUMP_BUTTON}">跳转</button>
<button id="${V_CONSOLE_DOM.GO_BACK_BUTTON}">返回上一页</button>
`;

html += '</div>';
Expand All @@ -65,17 +71,22 @@ export function initVersionPlugin() {
});

plugin.on('show', () => {
const input = document.getElementById(V_CONSOLE_DOM.URL_INPUT_ID);
const btn = document.getElementById(V_CONSOLE_DOM.URL_JUMP_BUTTON);
input?.addEventListener('input', updateInputValue);
btn?.addEventListener('click', jumpToUrl);
document.getElementById(V_CONSOLE_DOM.URL_INPUT_ID)
?.addEventListener('input', updateInputValue);
document.getElementById(V_CONSOLE_DOM.URL_JUMP_BUTTON)
?.addEventListener('click', jumpToUrl);
document.getElementById(V_CONSOLE_DOM.GO_BACK_BUTTON)
?.addEventListener('click', goBack);
});

plugin.on('hide', () => {
const input = document.getElementById(V_CONSOLE_DOM.URL_INPUT_ID);
const btn = document.getElementById(V_CONSOLE_DOM.URL_JUMP_BUTTON);
input?.removeEventListener('input', updateInputValue);
btn?.removeEventListener('click', jumpToUrl);
document.getElementById(V_CONSOLE_DOM.URL_INPUT_ID)
?.removeEventListener('input', updateInputValue);
document.getElementById(V_CONSOLE_DOM.URL_JUMP_BUTTON)
?.removeEventListener('click', jumpToUrl);

document.getElementById(V_CONSOLE_DOM.GO_BACK_BUTTON)
?.addEventListener('click', goBack);
});

return plugin;
Expand Down

0 comments on commit 045f08a

Please sign in to comment.