mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
The card asked for 65rem. The root font is 0.9em up to 1400px and 16px above it, so on any wider viewport — a 200% display scaling or a zoomed-out window gets there — 65rem is 1040px while the wrapper Buefy sizes the dialog with is capped at 960px: the card ran 80px past it and the close button, which sits on the wrapper's corner, ended up in the middle of the header. 60rem is 960px at the 16px root and never wider than the wrapper.
1169 lines
36 KiB
Vue
1169 lines
36 KiB
Vue
<template>
|
|
<div id="app">
|
|
<b-navbar ref="navs" fixed-top shadow type="is-light">
|
|
<template slot="brand">
|
|
<b-navbar-item href="/" class="brand no-select">
|
|
<img src="@/assets/img/v2raya-icon.svg" alt="" class="brand__icon" />
|
|
<span class="brand__name">v2rayA</span>
|
|
</b-navbar-item>
|
|
<b-navbar-item tag="div">
|
|
<b-tag id="statusTag" class="pointerTag" role="button" tabindex="0" :type="statusType"
|
|
@mouseenter.native="handleOnStatusMouseEnter" @mouseleave.native="handleOnStatusMouseLeave"
|
|
@click.native="handleClickStatus" @keydown.native.enter.prevent="handleClickStatus"
|
|
@keydown.native.space.prevent="handleClickStatus"><span class="tag-text">{{ coverStatusText ? coverStatusText : runningState.running }}</span>
|
|
</b-tag>
|
|
</b-navbar-item>
|
|
<b-navbar-item tag="div">
|
|
<OutboundGroupPanel
|
|
:outbounds="outbounds"
|
|
:current-outbound="outboundName"
|
|
:is-mobile="isMobile"
|
|
@select="outboundName = $event"
|
|
@add-outbound="handleAddOutbound"
|
|
@changed="handleGroupChanged"
|
|
@group-deleted="handleGroupDeleted"
|
|
/>
|
|
</b-navbar-item>
|
|
</template>
|
|
<template slot="burger" slot-scope="{ isOpened, toggleActive }">
|
|
<a
|
|
class="navbar-burger burger"
|
|
role="button"
|
|
:aria-label="$t('common.menu')"
|
|
:aria-expanded="isOpened ? 'true' : 'false'"
|
|
tabindex="0"
|
|
@click="toggleActive"
|
|
@keydown.enter.prevent="toggleActive"
|
|
@keydown.space.prevent="toggleActive"
|
|
>
|
|
<i class="lucide" :class="isOpened ? 'icon-x' : 'icon-menu'"></i>
|
|
</a>
|
|
</template>
|
|
|
|
<template slot="start"></template>
|
|
|
|
<template slot="end">
|
|
<!-- <b-navbar-item tag="router-link" to="/node" :active="nav === 'node'">-->
|
|
<!-- <i class="lucide icon-cloud" style="font-size: 1.4em"></i>-->
|
|
<!-- 节点-->
|
|
<!-- </b-navbar-item>-->
|
|
<b-navbar-item tag="a" @click.native="handleClickSetting">
|
|
<i class="lucide icon-settings" style="font-size: 1.25em"></i>
|
|
{{ $t("common.setting") }}
|
|
</b-navbar-item>
|
|
<b-navbar-item tag="a" @click.native="handleClickAbout">
|
|
<i class="lucide icon-heart" style="font-size: 1.25em"></i>
|
|
{{ $t("common.about") }}
|
|
</b-navbar-item>
|
|
<b-navbar-item tag="a" @click.native="handleClickLogs">
|
|
<i class="lucide icon-scroll-text" style="font-size: 1.25em"></i>
|
|
{{ $t("common.log") }}
|
|
</b-navbar-item>
|
|
<b-navbar-item tag="a" @click.native="toggleTheme">
|
|
<i
|
|
:class="['lucide', themePreference === 'auto' ? 'icon-sun-moon' : (isDarkTheme ? 'icon-sun' : 'icon-moon')]"
|
|
style="font-size: 1.25em"
|
|
></i>
|
|
{{ themeSwitchLabel }}
|
|
</b-navbar-item>
|
|
<b-dropdown position="is-bottom-left" aria-role="menu" class="langdropdown">
|
|
<a slot="trigger" class="navbar-item" role="button">
|
|
<i class="lucide icon-globe" style="font-size: 1.25em; margin-right: 4px"></i>
|
|
<span class="no-select">{{ currentLangLabel }}</span>
|
|
<i class="lucide icon-chevron-down" style="position: relative; top: 1px; left: 2px"></i>
|
|
</a>
|
|
<b-dropdown-item v-for="lang of langs" :key="lang.code" aria-role="menuitem" class="no-select"
|
|
@click="handleClickLang(lang.code)">
|
|
<span style="font-weight: 500; min-width: 120px; display: inline-block">{{ lang.label }}</span>
|
|
<span style="margin-left: 8px; color: #7a7a7a">{{ lang.code }}</span>
|
|
</b-dropdown-item>
|
|
</b-dropdown>
|
|
<b-dropdown position="is-bottom-left" aria-role="menu" style="margin-right: 10px" class="menudropdown">
|
|
<a slot="trigger" class="navbar-item" role="button">
|
|
<i class="lucide icon-user" style="font-size: 1.25em; margin-right: 4px"></i>
|
|
<span class="no-select">{{ username }}</span>
|
|
<i class="lucide icon-chevron-down" style="position: relative; top: 1px; left: 2px"></i>
|
|
</a>
|
|
<b-dropdown-item custom aria-role="menuitem" v-html="$t('common.loggedAs', { username: usernameHtml })">
|
|
</b-dropdown-item>
|
|
<hr class="dropdown-divider" />
|
|
<b-dropdown-item value="logout" aria-role="menuitem" class="no-select" @click="handleClickLogout">
|
|
<i class="lucide icon-log-out" style="position: relative; top: 1px"></i>
|
|
{{ $t("operations.logout") }}
|
|
</b-dropdown-item>
|
|
</b-dropdown>
|
|
</template>
|
|
</b-navbar>
|
|
<node ref="nodeRef" v-model="runningState" :outbound="outboundName" :outbounds="outbounds" :observatory="observatory" :load-balance-valid="loadBalanceValid" :core-version-valid="coreVersionValid" :core-version-err="coreVersionErr" />
|
|
<b-modal :active.sync="showCustomPorts" has-modal-card trap-focus aria-role="dialog" aria-modal
|
|
class="modal-custom-ports">
|
|
<ModalCustomAddress @close="showCustomPorts = false" />
|
|
</b-modal>
|
|
<b-modal :active.sync="loginModalActive" has-modal-card trap-focus aria-role="dialog" aria-modal class="modal-login modal-login-app">
|
|
<ModalLogin :first="loginModalFirst" @close="loginModalActive = false" />
|
|
</b-modal>
|
|
<div id="login"></div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import ModalSetting from "@/components/modalSetting";
|
|
import node from "@/node";
|
|
import { Base64 } from "js-base64";
|
|
import ModalCustomAddress from "@/components/modalCustomPorts";
|
|
import ModalOutboundSetting from "@/components/modalOutboundSetting";
|
|
import OutboundGroupPanel from "@/components/outboundGroupPanel";
|
|
import { backendMessage, parseURL } from "@/assets/js/utils";
|
|
import { waitingConnected } from "@/assets/js/networkInspect";
|
|
import axios from "@/plugins/axios";
|
|
import ModalLog from "@/components/modalLog";
|
|
import ModalLogin from "@/components/modalLogin";
|
|
import { ModalProgrammatic } from "buefy";
|
|
|
|
export default {
|
|
components: { ModalCustomAddress, node, OutboundGroupPanel, ModalLogin },
|
|
data() {
|
|
return {
|
|
ws: null,
|
|
observatory: null,
|
|
loginModalActive: false,
|
|
loginModalFirst: false,
|
|
showSidebar: true,
|
|
coverStatusText: "",
|
|
runningState: {
|
|
running: this.$t("common.checkRunning"),
|
|
networkPaused: false,
|
|
connectedServer: null,
|
|
outboundToServerName: {},
|
|
},
|
|
showCustomPorts: false,
|
|
langs: [
|
|
{ code: "zh_CN", label: "中文-中国", flag: "zh" },
|
|
{ code: "en_US", label: "English-US", flag: "en" },
|
|
{ code: "fa_IR", label: "فارسی", flag: "fa" },
|
|
{ code: "ru_RU", label: "Русский", flag: "ru" },
|
|
{ code: "pt_BR", label: "Português-Brasil", flag: "pt" },
|
|
{ code: "ko_KR", label: "한국어-대한민국", flag: "ko" },
|
|
],
|
|
outboundName: "proxy",
|
|
outbounds: ["proxy"],
|
|
loadBalanceValid: localStorage["loadBalanceValid"] === "true",
|
|
// seeded from the last load so a reload paints the banner immediately,
|
|
// then replaced by the /version response of this load
|
|
coreVersionValid: localStorage["coreVersionValid"] !== "false",
|
|
coreVersionErr: localStorage["coreVersionErr"] || "",
|
|
outboundDropdownHover: {},
|
|
updateOutboundDropdown: true,
|
|
themePreference: 'auto',
|
|
systemDark: window.matchMedia('(prefers-color-scheme: dark)').matches,
|
|
};
|
|
},
|
|
computed: {
|
|
// The label is a translated string, and this used to be a map built once
|
|
// in data() with the then-current translations as its keys: after a
|
|
// language change no key matched any more and the tag lost its colour.
|
|
// A computed re-reads both sides together.
|
|
statusType() {
|
|
switch (this.runningState.running) {
|
|
case this.$t("common.isRunning"):
|
|
return "is-success";
|
|
case this.$t("common.notRunning"):
|
|
return "is-danger";
|
|
case this.$t("common.waitingNetwork"):
|
|
return "is-warning";
|
|
default:
|
|
return "is-light";
|
|
}
|
|
},
|
|
username() {
|
|
let token = localStorage["token"];
|
|
if (!token) {
|
|
return this.$t("common.notLogin");
|
|
}
|
|
let payload;
|
|
try {
|
|
payload = JSON.parse(Base64.decode(token.split(".")[1]));
|
|
} catch (e) {
|
|
// a corrupt token would otherwise throw during render and blank
|
|
// the app before any request could clear it
|
|
return this.$t("common.notLogin");
|
|
}
|
|
return payload["uname"];
|
|
},
|
|
usernameHtml() {
|
|
// the account menu renders this through v-html
|
|
return String(this.username).replace(
|
|
/[&<>"']/g,
|
|
(c) => `&#${c.charCodeAt(0)};`
|
|
);
|
|
},
|
|
isMobile() {
|
|
return window.screen.width < 800;
|
|
},
|
|
currentLangLabel() {
|
|
// Read the locale vue-i18n actually chose (browser language when
|
|
// nothing is stored) rather than guessing from localStorage.
|
|
const lang = this.langs.find((l) => l.flag === this.$i18n.locale);
|
|
return lang ? lang.label : this.$i18n.locale;
|
|
},
|
|
isDarkTheme() {
|
|
if (this.themePreference === 'dark') return true;
|
|
if (this.themePreference === 'light') return false;
|
|
return this.systemDark;
|
|
},
|
|
themeSwitchLabel() {
|
|
if (this.themePreference === 'auto') return this.$t('common.autoTheme');
|
|
if (this.themePreference === 'dark') return this.$t('common.darkTheme');
|
|
return this.$t('common.lightTheme');
|
|
},
|
|
},
|
|
mounted() {
|
|
console.log("app created");
|
|
this.initTheme();
|
|
const ba = localStorage.getItem("backendAddress");
|
|
const isRelativeAddress =
|
|
!ba || (ba.startsWith("/") && !ba.startsWith("//"));
|
|
if (isRelativeAddress) {
|
|
document.title = `v2rayA - ${location.host}`;
|
|
} else {
|
|
const u = parseURL(ba);
|
|
document.title = `v2rayA - ${u.host}:${u.port}`;
|
|
}
|
|
// 没有 token:先检查是否需要注册,避免触发需要认证的请求导致 401 二次弹窗
|
|
if (!localStorage["token"]) {
|
|
// 使用重试机制确保注册页面可靠弹出
|
|
const checkAccount = (retries = 3) => {
|
|
this.$axios({
|
|
url: apiRoot + "/account",
|
|
method: "get",
|
|
}).then((res) => {
|
|
if (res.data.code === "SUCCESS") {
|
|
const hasAnyAccounts = !!(res.data.data && res.data.data.hasAnyAccounts);
|
|
// first=true -> register flow, first=false -> login flow
|
|
this.showLoginModal(!hasAnyAccounts);
|
|
}
|
|
}).catch(() => {
|
|
if (retries > 0) {
|
|
// 网络错误时延迟重试,避免因后端尚未就绪而错过注册页面
|
|
setTimeout(() => checkAccount(retries - 1), 2000);
|
|
}
|
|
});
|
|
};
|
|
checkAccount();
|
|
// 无 token 时跳过需要认证的请求,注册/登录后会自动 remount
|
|
return;
|
|
}
|
|
this.$axios({
|
|
url: apiRoot + "/version",
|
|
}).then((res) => {
|
|
if (res.data.code === "SUCCESS") {
|
|
let toastConf = {
|
|
message: this.$t(
|
|
res.data.data.dockerMode ? "welcome.docker" : "welcome.default",
|
|
{ version: res.data.data.version }
|
|
),
|
|
type: "is-dark",
|
|
position: "is-top",
|
|
duration: 3000,
|
|
};
|
|
if (res.data.data.foundNew) {
|
|
toastConf.duration = 5000;
|
|
toastConf.message +=
|
|
this.$t("welcome.separator") +
|
|
this.$t("welcome.newVersion", {
|
|
version: res.data.data.remoteVersion,
|
|
});
|
|
toastConf.type = "is-success";
|
|
}
|
|
// the running/new-version notice once per browser session, not on
|
|
// every reload or remount
|
|
const seenKey = "welcomeShown:" + res.data.data.version;
|
|
let seen = false;
|
|
try {
|
|
seen = sessionStorage.getItem(seenKey) === "1";
|
|
sessionStorage.setItem(seenKey, "1");
|
|
} catch (_) {
|
|
// storage unavailable: fall back to showing it
|
|
}
|
|
if (!seen || res.data.data.foundNew) {
|
|
this.$buefy.toast.open(toastConf);
|
|
}
|
|
localStorage["docker"] = res.data.data.dockerMode;
|
|
localStorage["version"] = res.data.data.version;
|
|
// a core version mismatch is already shown as the persistent banner
|
|
// in node.vue; no toast on top of it
|
|
if (res.data.data.coreVersionValid === false) {
|
|
// banner only
|
|
} else if (res.data.data.serviceValid === false) {
|
|
this.$buefy.toast.open({
|
|
message: this.$t("version.v2rayInvalid"),
|
|
type: "is-danger",
|
|
position: "is-top",
|
|
duration: 10000,
|
|
});
|
|
}
|
|
localStorage["lite"] = res.data.data.lite;
|
|
localStorage["loadBalanceValid"] = res.data.data.loadBalanceValid;
|
|
this.loadBalanceValid =
|
|
res.data.data.loadBalanceValid === true ||
|
|
res.data.data.loadBalanceValid === "true";
|
|
localStorage["variant"] = res.data.data.variant;
|
|
localStorage["coreVersionValid"] = res.data.data.coreVersionValid;
|
|
localStorage["coreVersionErr"] = res.data.data.coreVersionErr || "";
|
|
this.coreVersionValid = res.data.data.coreVersionValid !== false;
|
|
this.coreVersionErr = res.data.data.coreVersionErr || "";
|
|
}
|
|
});
|
|
this.$axios({
|
|
url: apiRoot + "/outbounds",
|
|
}).then((res) => {
|
|
if (res.data.code === "SUCCESS") {
|
|
this.outbounds = this.normalizeOutbounds(res.data.data.outbounds);
|
|
}
|
|
}).catch(() => {
|
|
// 静默处理认证错误(如 token 过期),避免触发 axios 401 拦截器弹出登录框
|
|
});
|
|
this.connectWsMessage();
|
|
},
|
|
beforeDestroy() {
|
|
if (this.ws) {
|
|
// detach first: onclose would otherwise schedule a reconnect from the
|
|
// destroyed instance
|
|
this.ws.onclose = null;
|
|
this.ws.close();
|
|
this.ws = null;
|
|
}
|
|
if (this._darkMediaQuery && this._onSystemThemeChange) {
|
|
this._darkMediaQuery.removeEventListener('change', this._onSystemThemeChange);
|
|
}
|
|
},
|
|
methods: {
|
|
showLoginModal(first) {
|
|
this.loginModalFirst = first;
|
|
this.loginModalActive = true;
|
|
},
|
|
connectWsMessage() {
|
|
const that = this;
|
|
let url = apiRoot;
|
|
if (!url.trim() || url.startsWith("/")) {
|
|
url = location.protocol + "//" + location.host + url;
|
|
}
|
|
let protocol = "ws";
|
|
let u = parseURL(url);
|
|
if (u.protocol === "https") {
|
|
protocol = "wss";
|
|
}
|
|
let basePath = u.path;
|
|
if (basePath.endsWith("/api")) {
|
|
basePath = basePath.slice(0, -4);
|
|
}
|
|
url = `${protocol}://${u.host}:${u.port}${basePath}/api/message?Authorization=${encodeURIComponent(localStorage["token"])}`;
|
|
if (this.ws) {
|
|
// console.log("ws close");
|
|
this.ws.close();
|
|
}
|
|
const ws = new WebSocket(url);
|
|
// WebSocket 重连指数退避参数
|
|
if (typeof this._wsRetries === "undefined") {
|
|
this._wsRetries = 0;
|
|
}
|
|
ws.onopen = () => {
|
|
// console.log("ws opened");
|
|
this._wsRetries = 0; // 连接成功后重置重试计数
|
|
// Re-sync running state on every (re)connect. WebSocket messages are
|
|
// not replayed, so if the connection was broken while Tun was setting up
|
|
// routes the frontend might miss the running_state message and stay
|
|
// stuck on "检测中" (Checking) forever.
|
|
this.$nextTick(() => {
|
|
if (this.$refs.nodeRef) {
|
|
this.$refs.nodeRef.syncLatestNodeOverview();
|
|
}
|
|
});
|
|
};
|
|
ws.onmessage = (msg) => {
|
|
msg.data && that.handleMessage(JSON.parse(msg.data));
|
|
};
|
|
ws.onclose = () => {
|
|
ws.onmessage = null;
|
|
that.ws = null;
|
|
if (that._isDestroyed) {
|
|
return;
|
|
}
|
|
// 指数退避重连:1s, 2s, 4s, 8s... 最大 30 秒
|
|
const delay = Math.min(1000 * Math.pow(2, that._wsRetries), 30000);
|
|
that._wsRetries++;
|
|
setTimeout(() => {
|
|
if (that.ws === null) {
|
|
that.connectWsMessage();
|
|
}
|
|
}, delay);
|
|
};
|
|
this.ws = ws;
|
|
},
|
|
handleMessage(msg) {
|
|
if (
|
|
msg.type === "observatory" &&
|
|
msg.body.outboundName === this.outboundName
|
|
) {
|
|
this.observatory = msg;
|
|
}
|
|
if (msg.type === "running_state" && msg.body) {
|
|
if (msg.body.running === false) {
|
|
this.$refs.nodeRef && this.$refs.nodeRef.notifyStopped(!!msg.body.networkPaused);
|
|
} else {
|
|
this.$refs.nodeRef && this.$refs.nodeRef.notifyRunning(!!msg.body.networkPaused);
|
|
}
|
|
}
|
|
},
|
|
handleOutboundDropdownActiveChange(active) {
|
|
if (active) {
|
|
this.updateOutboundDropdown = false;
|
|
this.updateOutboundDropdown = true;
|
|
}
|
|
},
|
|
handleGroupChanged() {
|
|
// Refresh node.vue's data after group membership change from the panel
|
|
if (this.$refs.nodeRef) {
|
|
this.$refs.nodeRef.$axios({ url: apiRoot + "/touch" }).then((res) => {
|
|
if (res.data && res.data.code === "SUCCESS") {
|
|
this.$refs.nodeRef.refreshTableData(res.data.data.touch, res.data.data.running, res.data.data.networkPaused);
|
|
this.$refs.nodeRef.updateConnectView();
|
|
}
|
|
}).catch(() => {});
|
|
}
|
|
},
|
|
handleGroupDeleted(newOutbounds) {
|
|
this.outbounds = this.normalizeOutbounds(newOutbounds);
|
|
// If deleted group was selected, fall back to proxy
|
|
if (!this.outbounds.includes(this.outboundName)) {
|
|
this.outboundName = "proxy";
|
|
}
|
|
},
|
|
normalizeOutbounds(outbounds) {
|
|
const seen = new Set();
|
|
const normalized = [];
|
|
if (outbounds instanceof Array) {
|
|
for (const outbound of outbounds) {
|
|
if (typeof outbound !== "string") {
|
|
continue;
|
|
}
|
|
const name = outbound.trim();
|
|
if (!name || seen.has(name)) {
|
|
continue;
|
|
}
|
|
seen.add(name);
|
|
normalized.push(name);
|
|
}
|
|
}
|
|
if (!seen.has("proxy")) {
|
|
normalized.unshift("proxy");
|
|
}
|
|
return normalized;
|
|
},
|
|
outboundNameDecorator(outbound) {
|
|
if (this.runningState.outboundToServerName[outbound]) {
|
|
if (
|
|
typeof this.runningState.outboundToServerName[outbound] === "number"
|
|
) {
|
|
return `${outbound} - ${this.$t("common.loadBalance")} (${this.runningState.outboundToServerName[outbound]
|
|
})`;
|
|
} else {
|
|
return `${outbound} - ${this.runningState.outboundToServerName[outbound]}`;
|
|
}
|
|
}
|
|
return outbound;
|
|
},
|
|
handleAddOutbound() {
|
|
this.$buefy.dialog.prompt({
|
|
message: this.$t("outbound.addMessage"),
|
|
inputAttrs: {
|
|
maxlength: 10,
|
|
},
|
|
trapFocus: true,
|
|
onConfirm: (outbound) => {
|
|
let cancel;
|
|
waitingConnected(
|
|
this.$axios({
|
|
url: apiRoot + "/outbound",
|
|
method: "post",
|
|
data: {
|
|
outbound,
|
|
},
|
|
cancelToken: new axios.CancelToken(function executor(c) {
|
|
cancel = c;
|
|
}),
|
|
}).then((res) => {
|
|
if (res.data.code === "SUCCESS") {
|
|
this.$buefy.toast.open({
|
|
message: this.$t("outbound.added"),
|
|
type: "is-success",
|
|
duration: 2000,
|
|
position: "is-top",
|
|
});
|
|
this.outbounds = this.normalizeOutbounds(res.data.data.outbounds);
|
|
} else {
|
|
this.$buefy.toast.open({
|
|
message: this.$t("outbound.addFailed", {
|
|
message: backendMessage(this, res) || this.$t("common.fail"),
|
|
}),
|
|
type: "is-warning",
|
|
duration: 5000,
|
|
position: "is-top",
|
|
});
|
|
}
|
|
}),
|
|
3 * 1000,
|
|
cancel
|
|
);
|
|
},
|
|
});
|
|
},
|
|
handleDeleteOutbound(outbound) {
|
|
let cancel;
|
|
waitingConnected(
|
|
this.$axios({
|
|
url: apiRoot + "/outbound",
|
|
method: "delete",
|
|
data: {
|
|
outbound,
|
|
},
|
|
cancelToken: new axios.CancelToken(function executor(c) {
|
|
cancel = c;
|
|
}),
|
|
}).then((res) => {
|
|
if (res.data.code === "SUCCESS") {
|
|
this.$buefy.toast.open({
|
|
message: this.$t("outbound.deleted"),
|
|
type: "is-success",
|
|
duration: 2000,
|
|
position: "is-top",
|
|
});
|
|
this.outbounds = this.normalizeOutbounds(res.data.data.outbounds);
|
|
if (this.outboundName === outbound) {
|
|
this.outboundName = "proxy";
|
|
}
|
|
if (outbound in this.runningState.outboundToServerName) {
|
|
this.runningState.connectedServer =
|
|
this.runningState.connectedServer.filter(
|
|
(cs) => cs.outbound !== outbound
|
|
);
|
|
}
|
|
} else {
|
|
this.$buefy.toast.open({
|
|
message: this.$t("outbound.deleteFailed", {
|
|
group: outbound,
|
|
message: backendMessage(this, res) || this.$t("common.fail"),
|
|
}),
|
|
type: "is-warning",
|
|
duration: 5000,
|
|
position: "is-top",
|
|
});
|
|
}
|
|
}),
|
|
3 * 1000,
|
|
cancel
|
|
);
|
|
},
|
|
handleClickOutboundSetting(event, outbound) {
|
|
event.stopPropagation();
|
|
const that = this;
|
|
this.$buefy.modal.open({
|
|
parent: this,
|
|
component: ModalOutboundSetting,
|
|
hasModalCard: true,
|
|
canCancel: true,
|
|
props: {
|
|
outbound: outbound,
|
|
},
|
|
events: {
|
|
delete() {
|
|
that.handleDeleteOutbound(outbound);
|
|
},
|
|
},
|
|
});
|
|
},
|
|
handleClickLang(langCode) {
|
|
const lang = this.langs.find(l => l.code === langCode);
|
|
if (lang) {
|
|
localStorage["_lang"] = lang.flag;
|
|
location.reload();
|
|
}
|
|
},
|
|
handleOnOutboundMouseEnter(outbound) {
|
|
this.outboundDropdownHover = { [outbound]: true };
|
|
},
|
|
handleOnOutboundMouseLeave() {
|
|
this.outboundDropdownHover = {};
|
|
},
|
|
handleOnStatusMouseEnter() {
|
|
if (this.runningState.running === this.$t("common.isRunning")) {
|
|
this.coverStatusText = this.$t("v2ray.stop");
|
|
} else if (this.runningState.running === this.$t("common.notRunning")) {
|
|
this.coverStatusText = this.$t("v2ray.start");
|
|
} else if (this.runningState.running === this.$t("common.waitingNetwork")) {
|
|
this.coverStatusText = this.$t("common.waitingNetwork");
|
|
}
|
|
},
|
|
handleOnStatusMouseLeave() {
|
|
this.coverStatusText = "";
|
|
},
|
|
handleClickSetting() {
|
|
const that = this;
|
|
this.$buefy.modal.open({
|
|
parent: this,
|
|
component: ModalSetting,
|
|
hasModalCard: true,
|
|
canCancel: true,
|
|
events: {
|
|
clickPorts() {
|
|
that.showCustomPorts = true;
|
|
},
|
|
},
|
|
});
|
|
},
|
|
handleClickAbout() {
|
|
this.$buefy.modal.open({
|
|
width: 640,
|
|
content: `
|
|
<div class="modal-card" style="margin:auto">
|
|
<header class="modal-card-head">
|
|
<p class="modal-card-title">mzz2017 / v2rayA</p>
|
|
</header>
|
|
<section class="modal-card-body lazy">
|
|
${this.$t(`about`)}
|
|
</section>
|
|
<footer class="modal-card-foot">
|
|
<a class="is-link" href="https://github.com/v2rayA/v2rayA" target="_blank">
|
|
<img class="leave-right" src="https://img.shields.io/github/stars/mzz2017/v2rayA.svg?style=social" alt="stars">
|
|
<img class="leave-right" src="https://img.shields.io/github/forks/mzz2017/v2rayA.svg?style=social" alt="forks">
|
|
<img class="leave-right" src="https://img.shields.io/github/watchers/mzz2017/v2rayA.svg?style=social" alt="watchers">
|
|
</a>
|
|
</footer>
|
|
</div>
|
|
`,
|
|
});
|
|
},
|
|
handleClickStatus() {
|
|
if (
|
|
this.runningState.running === this.$t("common.notRunning") ||
|
|
this.runningState.running === this.$t("common.waitingNetwork")
|
|
) {
|
|
let cancel;
|
|
let loading = this.$buefy.loading.open();
|
|
waitingConnected(
|
|
this.$axios({
|
|
url: apiRoot + "/v2ray",
|
|
method: "post",
|
|
cancelToken: new axios.CancelToken(function executor(c) {
|
|
cancel = c;
|
|
}),
|
|
}).then((res) => {
|
|
if (res.data.code === "SUCCESS") {
|
|
Object.assign(this.runningState, {
|
|
running: this.$t("common.isRunning"),
|
|
networkPaused: false,
|
|
connectedServer: res.data.data.touch.connectedServer,
|
|
});
|
|
} else {
|
|
this.$buefy.toast.open({
|
|
message: this.$t("v2ray.startFailed", {
|
|
message: backendMessage(this, res) || this.$t("common.fail"),
|
|
}),
|
|
type: "is-warning",
|
|
duration: 5000,
|
|
position: "is-top",
|
|
});
|
|
}
|
|
}).finally(() => {
|
|
loading.close();
|
|
}),
|
|
3 * 1000,
|
|
cancel
|
|
);
|
|
} else if (this.runningState.running === this.$t("common.isRunning")) {
|
|
this.$axios({
|
|
url: apiRoot + "/v2ray",
|
|
method: "delete",
|
|
}).then((res) => {
|
|
if (res.data.code === "SUCCESS") {
|
|
Object.assign(this.runningState, {
|
|
running: this.$t("common.notRunning"),
|
|
networkPaused: false,
|
|
connectedServer: res.data.data.touch.connectedServer,
|
|
});
|
|
} else {
|
|
this.$buefy.toast.open({
|
|
message: this.$t("v2ray.stopFailed", {
|
|
message: backendMessage(this, res) || this.$t("common.fail"),
|
|
}),
|
|
type: "is-warning",
|
|
duration: 5000,
|
|
position: "is-top",
|
|
});
|
|
}
|
|
});
|
|
}
|
|
},
|
|
handleClickLogout() {
|
|
localStorage.removeItem("token");
|
|
this.$remount();
|
|
},
|
|
initTheme() {
|
|
const stored = localStorage.getItem('theme');
|
|
this.themePreference = (stored === 'dark' || stored === 'light') ? stored : 'auto';
|
|
this._darkMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
this._onSystemThemeChange = (e) => {
|
|
this.systemDark = e.matches;
|
|
this.applyThemeClass();
|
|
};
|
|
this._darkMediaQuery.addEventListener('change', this._onSystemThemeChange);
|
|
this.applyThemeClass();
|
|
},
|
|
applyThemeClass() {
|
|
document.body.classList.toggle('theme-dark', this.isDarkTheme);
|
|
document.documentElement.classList.toggle('theme-dark', this.isDarkTheme);
|
|
},
|
|
toggleTheme() {
|
|
const order = ['auto', 'light', 'dark'];
|
|
const idx = order.indexOf(this.themePreference);
|
|
this.themePreference = order[(idx + 1) % order.length];
|
|
localStorage.setItem('theme', this.themePreference);
|
|
this.applyThemeClass();
|
|
},
|
|
handleClickLogs() {
|
|
this.$buefy.modal.open({
|
|
parent: this,
|
|
component: ModalLog,
|
|
hasModalCard: true,
|
|
canCancel: true,
|
|
});
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
@import "assets/scss/reset.scss";
|
|
@import "assets/scss/dark-theme.scss";
|
|
</style>
|
|
|
|
<style lang="scss" scoped>
|
|
#app {
|
|
margin: 0;
|
|
}
|
|
|
|
.menucontainer {
|
|
padding: 20px;
|
|
}
|
|
|
|
// The brand is the vector icon plus the name as text: the old PNG wordmark
|
|
// needed a colour filter for the dark theme and blurred at 2x displays.
|
|
.brand {
|
|
gap: 0.55em;
|
|
padding-left: 1em;
|
|
padding-right: 1em;
|
|
}
|
|
|
|
.brand__icon {
|
|
height: 30px;
|
|
width: 30px;
|
|
min-height: 30px;
|
|
max-height: none;
|
|
flex: 0 0 30px;
|
|
}
|
|
|
|
.brand__name {
|
|
font-weight: 600;
|
|
font-size: 1.15rem;
|
|
letter-spacing: 0.01em;
|
|
color: inherit;
|
|
}
|
|
|
|
.navbar-item .lucide {
|
|
margin-right: 0.15em;
|
|
}
|
|
|
|
.pointerTag:hover {
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
|
|
<style lang="scss">
|
|
html {
|
|
// &::-webkit-scrollbar {
|
|
// // remove annoying scrollbar
|
|
// display: none;
|
|
// }
|
|
|
|
#app {
|
|
min-height: calc(100vh - 3.25rem);
|
|
/*overflow-y: auto;*/
|
|
//overflow-scrolling: touch;
|
|
//-webkit-overflow-scrolling: touch;
|
|
}
|
|
}
|
|
|
|
// Buefy's toast/snackbar layer starts at the viewport top and covered the
|
|
// fixed navbar (and, on phones, the toolbar buttons right under it); start
|
|
// it below the navbar.
|
|
.notices {
|
|
padding-top: 4.5rem !important;
|
|
}
|
|
|
|
// Below the tablet breakpoint reset.scss scales the root font to 0.8em,
|
|
// which made the status tags ~10px and the logo ~32px; size the brand row
|
|
// in px so it stays a touch target.
|
|
@media screen and (max-width: 768px) {
|
|
.navbar-brand .brand {
|
|
padding-left: 0.5em;
|
|
padding-right: 0.5em;
|
|
}
|
|
|
|
.navbar-brand .brand__icon {
|
|
height: 28px;
|
|
width: 28px;
|
|
min-height: 28px;
|
|
flex-basis: 28px;
|
|
}
|
|
|
|
// very narrow phones: the two tags and the burger come first; the name
|
|
// goes, then the icon
|
|
@media screen and (max-width: 380px) {
|
|
.navbar-brand .brand__name {
|
|
display: none;
|
|
}
|
|
}
|
|
|
|
@media screen and (max-width: 330px) {
|
|
.navbar-brand > .navbar-item:first-child {
|
|
display: none;
|
|
}
|
|
}
|
|
.navbar-brand .tag {
|
|
font-size: 13px;
|
|
height: 2.2em;
|
|
padding-left: 0.9em;
|
|
padding-right: 0.9em;
|
|
}
|
|
.navbar-brand > .navbar-item {
|
|
padding-left: 0.5rem;
|
|
padding-right: 0.5rem;
|
|
}
|
|
// The brand row is a flex row whose items do not shrink by default, so
|
|
// below ~400px the tags pushed the burger past the right edge and the menu
|
|
// could not be opened. Let the tags shrink and truncate; pin the burger.
|
|
.navbar-brand {
|
|
flex-wrap: nowrap;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.navbar-brand > .navbar-item {
|
|
min-width: 0;
|
|
flex-shrink: 1;
|
|
}
|
|
|
|
// keep Bulma's inline-flex centring (inline-block blockifies as a flex
|
|
// item and drops the text to the baseline); truncate the inner span
|
|
.navbar-brand .tag {
|
|
min-width: 0;
|
|
max-width: 100%;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.navbar-brand .tag .tag-text {
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
min-width: 0;
|
|
}
|
|
|
|
#statusTag {
|
|
min-width: 0;
|
|
}
|
|
|
|
.navbar-burger {
|
|
height: 48px;
|
|
width: 48px;
|
|
margin-left: auto;
|
|
flex: 0 0 48px;
|
|
}
|
|
}
|
|
|
|
// The burger is a Lucide glyph, not Bulma's three spans; centre it and give
|
|
// it the navbar's text colour. Keep Bulma's breakpoint: this block used to
|
|
// set display unconditionally, which showed the burger next to the full menu
|
|
// on a desktop screen.
|
|
.navbar-burger {
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: inherit;
|
|
|
|
.lucide {
|
|
font-size: 24px;
|
|
vertical-align: 0;
|
|
}
|
|
}
|
|
|
|
@media screen and (max-width: 1023px) {
|
|
.navbar-burger {
|
|
display: flex;
|
|
}
|
|
}
|
|
|
|
@media screen and (min-width: 1024px) {
|
|
.navbar-burger {
|
|
display: none;
|
|
}
|
|
}
|
|
|
|
// Bulma pins .modal-close to the top-right of the viewport, far from the
|
|
// card it closes. Put it on the card instead, at every width; the card is
|
|
// position: relative so the button lands on its corner.
|
|
// Buefy puts .modal-close inside .animation-content, which wraps the card
|
|
// but is stretched to the whole modal, so the button lands in the corner of
|
|
// the screen rather than of the card. Shrink the wrapper to its card.
|
|
// One backdrop value for every dialog: the component library ships several
|
|
// (0.86 opaque here, a lighter one in two components), which read as a
|
|
// shadow around the light card.
|
|
.modal .modal-background {
|
|
background-color: rgba(10, 10, 10, 0.55);
|
|
}
|
|
|
|
.modal .modal-card-head,
|
|
.modal .modal-card-foot {
|
|
border-radius: 6px 6px 0 0;
|
|
}
|
|
|
|
.modal .modal-card-foot {
|
|
border-radius: 0 0 6px 6px;
|
|
}
|
|
|
|
.modal .animation-content {
|
|
position: relative;
|
|
width: auto;
|
|
margin: auto;
|
|
}
|
|
|
|
.modal .modal-close.is-large {
|
|
// Bulma sets position: fixed on .modal-close, which anchors it to the
|
|
// viewport; absolute puts it on the wrapper above, i.e. the card corner
|
|
position: absolute;
|
|
top: 0.75rem;
|
|
right: 0.75rem;
|
|
height: 2rem;
|
|
width: 2rem;
|
|
max-height: 2rem;
|
|
max-width: 2rem;
|
|
z-index: 1;
|
|
background-color: transparent;
|
|
|
|
// Bulma draws the glyph as two white bars, which vanish on the light
|
|
// card head; follow the head's text colour instead.
|
|
&::before,
|
|
&::after {
|
|
background-color: currentColor;
|
|
}
|
|
|
|
color: rgba(0, 0, 0, 0.75);
|
|
|
|
&:hover,
|
|
&:focus {
|
|
background-color: rgba(0, 0, 0, 0.08);
|
|
color: rgba(0, 0, 0, 0.95);
|
|
}
|
|
}
|
|
|
|
// Phone dialogs: Bulma floats the card in the middle of the viewport
|
|
// (max-height: 100vh - 160px) with the close button fixed at the top of the
|
|
// screen, far above the card. Fill the screen so the card head is at the
|
|
// top and the close button sits at its top-right corner.
|
|
@media screen and (max-width: 768px) {
|
|
.modal .modal-card {
|
|
margin: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
max-height: 100vh;
|
|
}
|
|
.modal .modal-card-head {
|
|
padding-right: 3.75rem;
|
|
border-radius: 0;
|
|
}
|
|
.modal .modal-card-foot {
|
|
border-radius: 0;
|
|
}
|
|
}
|
|
|
|
// Bulma only centres navbar items from the desktop breakpoint up; below it
|
|
// the brand row is a plain block and the status tag and group panel sit at
|
|
// the top of the row while the logo fills it.
|
|
.navbar-brand > .navbar-item {
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
@media screen and (max-width: 1023px) {
|
|
// The dropdowns are no longer mobile modals (see plugins/buefy.js), so
|
|
// the menu is positioned inside the collapsed navbar menu: keep it in
|
|
// the flow of its row instead of floating over the page.
|
|
// Bulma gives the collapsed menu `overflow: auto` with a max-height, which
|
|
// clips anything floating out of it: the language menu showed one row and
|
|
// the rest was cut off. The menu holds six items and never needs its own
|
|
// scrollbar on a phone, so let it overflow and give the dropdown its own
|
|
// bounded scroll instead.
|
|
.navbar.is-fixed-top .navbar-menu,
|
|
.navbar-menu {
|
|
overflow: visible;
|
|
}
|
|
|
|
.navbar-menu .navbar-end > .dropdown {
|
|
position: relative;
|
|
|
|
> .dropdown-menu {
|
|
position: absolute;
|
|
top: 100%;
|
|
left: 0;
|
|
right: auto;
|
|
width: max-content;
|
|
min-width: 100%;
|
|
max-width: calc(100vw - 2rem);
|
|
transform: none;
|
|
padding-top: 0.25rem;
|
|
}
|
|
|
|
// a menu floating over the rows below it needs its own surface and a
|
|
// border, or it reads as part of the list it covers
|
|
> .dropdown-menu .dropdown-content {
|
|
max-height: 60vh;
|
|
overflow-y: auto;
|
|
border: 1px solid rgba(10, 10, 10, 0.12);
|
|
border-radius: 6px;
|
|
box-shadow: 0 8px 16px rgba(10, 10, 10, 0.18);
|
|
}
|
|
}
|
|
|
|
// In the collapsed menu each dropdown is inline-flex, so the language and
|
|
// account triggers share one row with different baselines. Give each its
|
|
// own full-width row like the plain navbar items above them.
|
|
.navbar-menu .navbar-end > .dropdown {
|
|
display: flex;
|
|
// Buefy spaces adjacent dropdowns with .dropdown + .dropdown; stacked
|
|
// rows must not inherit that indent.
|
|
margin-left: 0;
|
|
|
|
> .dropdown-trigger {
|
|
width: 100%;
|
|
}
|
|
}
|
|
}
|
|
|
|
.dropdown-item:focus {
|
|
// remove ugly outline
|
|
outline: none !important;
|
|
}
|
|
|
|
.no-select {
|
|
user-select: none;
|
|
-webkit-user-drag: none;
|
|
}
|
|
|
|
.menudropdown .dropdown-item {
|
|
font-size: 0.8em;
|
|
}
|
|
|
|
.leave-right {
|
|
margin-right: 0.6rem;
|
|
}
|
|
|
|
.lazy {
|
|
p {
|
|
margin: 0.5em 0;
|
|
}
|
|
}
|
|
|
|
a.navbar-item:focus,
|
|
a.navbar-item:focus-within,
|
|
a.navbar-item:hover,
|
|
a.navbar-item.is-active,
|
|
.navbar-link:focus,
|
|
.navbar-link:focus-within,
|
|
.navbar-link:hover,
|
|
.navbar-link.is-active,
|
|
.is-link,
|
|
a {
|
|
$success: #506da4;
|
|
color: $success;
|
|
}
|
|
|
|
.icon-loader-circle {
|
|
font-size: 2.5rem;
|
|
color: rgba(0, 0, 0, 0.45);
|
|
animation: loading-rotate 2s infinite linear;
|
|
}
|
|
|
|
.modal-custom-ports {
|
|
z-index: 999;
|
|
}
|
|
|
|
/* Keep App-level login modal above any other modal overlays. */
|
|
.modal-login-app {
|
|
z-index: 5000 !important;
|
|
}
|
|
|
|
.modal-login-app .modal-background {
|
|
z-index: 0 !important;
|
|
}
|
|
|
|
.modal-login-app .modal-content,
|
|
.modal-login-app .animation-content,
|
|
.modal-login-app .modal-card {
|
|
position: relative;
|
|
z-index: 1 !important;
|
|
pointer-events: auto !important;
|
|
}
|
|
|
|
.after-line-dot5 {
|
|
p {
|
|
margin-bottom: 0.5em;
|
|
}
|
|
}
|
|
|
|
.about-small {
|
|
font-size: 0.85em;
|
|
text-indent: 1em;
|
|
color: rgba(0, 0, 0, 0.6);
|
|
}
|
|
|
|
.margin-right-2em {
|
|
margin-right: 2em;
|
|
}
|
|
|
|
.justify-content-space-between {
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.padding-right-1rem {
|
|
padding-right: 2rem !important;
|
|
}
|
|
|
|
#statusTag {
|
|
min-width: 5em;
|
|
}
|
|
|
|
.dropdown-menu .is-fullwidth {
|
|
width: 100%;
|
|
}
|
|
|
|
.dropdown-menu .outbound-setting {
|
|
position: absolute;
|
|
right: -1.5rem;
|
|
top: 0;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.navbar-item .dropdown-menu .dropdown-content {
|
|
max-height: calc(100vh - 60px);
|
|
overflow-y: auto;
|
|
}
|
|
</style>
|