SubPage.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <script setup>
  2. import { computed, onMounted, ref } from 'vue';
  3. import { useI18n } from 'vue-i18n';
  4. import {
  5. SettingOutlined,
  6. AndroidOutlined,
  7. AppleOutlined,
  8. DownOutlined,
  9. CopyOutlined,
  10. } from '@ant-design/icons-vue';
  11. import { message } from 'ant-design-vue';
  12. import { ClipboardManager, IntlUtil, LanguageManager } from '@/utils';
  13. import {
  14. theme as themeState,
  15. antdThemeConfig,
  16. toggleTheme,
  17. toggleUltra,
  18. pauseAnimationsUntilLeave,
  19. } from '@/composables/useTheme.js';
  20. const { t } = useI18n();
  21. // Read the view-model Go injects via window.__SUB_PAGE_DATA__. Falls
  22. // back to safe defaults so the page still renders if the global is
  23. // missing (e.g. during local dev without the backend).
  24. const subData = window.__SUB_PAGE_DATA__ || {};
  25. const sId = subData.sId || '';
  26. const enabled = !!subData.enabled;
  27. const download = subData.download || '0';
  28. const upload = subData.upload || '0';
  29. const total = subData.total || '∞';
  30. const used = subData.used || '0';
  31. const remained = subData.remained || '';
  32. const totalByte = Number(subData.totalByte || 0);
  33. const expireMs = Number(subData.expire || 0) * 1000;
  34. const lastOnlineMs = Number(subData.lastOnline || 0);
  35. const subUrl = subData.subUrl || '';
  36. const subJsonUrl = subData.subJsonUrl || '';
  37. const subClashUrl = subData.subClashUrl || '';
  38. const subTitle = subData.subTitle || '';
  39. const links = Array.isArray(subData.links) ? subData.links : [];
  40. // Panel's "Calendar Type" setting; controls whether expiry / lastOnline
  41. // render in Gregorian or Jalali on this standalone subscription page.
  42. const datepicker = subData.datepicker || 'gregorian';
  43. // Derived state ===============================================
  44. const isUnlimited = computed(() => totalByte <= 0 && expireMs === 0);
  45. const isActive = computed(() => {
  46. if (!enabled) return false;
  47. if (totalByte > 0) {
  48. const used = Number(subData.usedByte || 0)
  49. || (Number(subData.downloadByte || 0) + Number(subData.uploadByte || 0));
  50. if (used >= totalByte) return false;
  51. }
  52. if (expireMs > 0 && Date.now() >= expireMs) return false;
  53. return true;
  54. });
  55. // Mobile-aware layout — shows app dropdowns full-width below 576px
  56. const isMobile = ref(false);
  57. function updateMobile() { isMobile.value = window.innerWidth < 576; }
  58. onMounted(() => {
  59. updateMobile();
  60. window.addEventListener('resize', updateMobile);
  61. });
  62. // Language switcher mirrors the legacy panel: setting the language
  63. // triggers a full-page reload which re-renders with the new locale.
  64. const lang = ref(LanguageManager.getLanguage());
  65. function onLangChange(next) {
  66. LanguageManager.setLanguage(next);
  67. }
  68. /* Same Light -> Dark -> Ultra Dark -> Light cycle the panel sidebar
  69. * uses, so the standalone subscription page offers a one-click theme
  70. * toggle without the popover ceremony. */
  71. function cycleTheme() {
  72. pauseAnimationsUntilLeave('sub-theme-cycle');
  73. if (!themeState.isDark) {
  74. toggleTheme();
  75. if (themeState.isUltra) toggleUltra();
  76. } else if (!themeState.isUltra) {
  77. toggleUltra();
  78. } else {
  79. toggleUltra();
  80. toggleTheme();
  81. }
  82. }
  83. const QR_SIZE = 240;
  84. // Actions =====================================================
  85. async function copy(value) {
  86. if (!value) return;
  87. const ok = await ClipboardManager.copyText(value);
  88. if (ok) message.success(t('copied'));
  89. }
  90. function open(url) {
  91. if (!url) return;
  92. window.open(url, '_blank');
  93. }
  94. // Pretty label per share link — pulls protocol + remark out of the
  95. // URL fragment (most clients put the remark after the # sign).
  96. function linkName(link, idx) {
  97. if (!link) return `Link ${idx + 1}`;
  98. const hashIdx = link.indexOf('#');
  99. if (hashIdx >= 0 && hashIdx + 1 < link.length) {
  100. try {
  101. return decodeURIComponent(link.slice(hashIdx + 1));
  102. } catch (_e) {
  103. return link.slice(hashIdx + 1);
  104. }
  105. }
  106. const proto = link.split('://')[0];
  107. return `${proto.toUpperCase()} ${idx + 1}`;
  108. }
  109. // iOS deep links — taken verbatim from the legacy subpage. Each
  110. // client expects the sub URL in a slightly different param name.
  111. const shadowrocketUrl = computed(() => {
  112. if (!subUrl) return '';
  113. const separator = subUrl.includes('?') ? '&' : '?';
  114. const rawUrl = subUrl + separator + 'flag=shadowrocket';
  115. const base64Url = encodeURIComponent(btoa(rawUrl));
  116. const remark = encodeURIComponent(subTitle || sId || 'Subscription');
  117. return `shadowrocket://add/sub/${base64Url}?remark=${remark}`;
  118. });
  119. const v2boxUrl = computed(() => `v2box://install-sub?url=${encodeURIComponent(subUrl)}&name=${encodeURIComponent(sId)}`);
  120. const streisandUrl = computed(() => `streisand://import/${encodeURIComponent(subUrl)}`);
  121. const v2raytunUrl = computed(() => subUrl);
  122. const npvtunUrl = computed(() => subUrl);
  123. const happUrl = computed(() => `happ://add/${subUrl}`);
  124. // Theme classes for the page wrapper.
  125. const themeClass = computed(() => ({
  126. 'is-dark': themeState.isDark,
  127. 'is-ultra': themeState.isUltra,
  128. }));
  129. </script>
  130. <template>
  131. <a-config-provider :theme="antdThemeConfig">
  132. <a-layout class="subscription-page" :class="themeClass">
  133. <a-layout-content class="content">
  134. <a-row type="flex" justify="center">
  135. <a-col :xs="24" :sm="22" :md="18" :lg="14" :xl="12">
  136. <a-card hoverable class="subscription-card">
  137. <template #title>
  138. <a-space>
  139. <span>{{ t('subscription.title') }}</span>
  140. <a-tag>{{ sId }}</a-tag>
  141. </a-space>
  142. </template>
  143. <template #extra>
  144. <a-space :size="8" align="center">
  145. <button type="button" class="theme-cycle" :aria-label="t('menu.theme')" :title="t('menu.theme')"
  146. @click="cycleTheme">
  147. <svg v-if="!themeState.isDark" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  148. stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
  149. <circle cx="12" cy="12" r="4" />
  150. <path
  151. d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41" />
  152. </svg>
  153. <svg v-else-if="!themeState.isUltra" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  154. stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
  155. <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
  156. </svg>
  157. <svg v-else viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="1.5"
  158. stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
  159. <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
  160. <path fill="none" d="M19 3l0.7 1.4 1.4 0.7-1.4 0.7L19 7.2l-0.7-1.4-1.4-0.7 1.4-0.7z" />
  161. </svg>
  162. </button>
  163. <a-popover :title="t('pages.settings.language')" placement="bottomRight" trigger="click">
  164. <template #content>
  165. <a-space direction="vertical" :size="10" class="settings-popover">
  166. <a-select v-model:value="lang" class="lang-select" @change="onLangChange">
  167. <a-select-option v-for="l in LanguageManager.supportedLanguages" :key="l.value"
  168. :value="l.value">
  169. <span :aria-label="l.name">{{ l.icon }}</span>
  170. &nbsp;&nbsp;<span>{{ l.name }}</span>
  171. </a-select-option>
  172. </a-select>
  173. </a-space>
  174. </template>
  175. <a-button shape="circle">
  176. <template #icon>
  177. <SettingOutlined />
  178. </template>
  179. </a-button>
  180. </a-popover>
  181. </a-space>
  182. </template>
  183. <!-- ============== QR codes ============== -->
  184. <a-row :gutter="[8, 8]" justify="center" class="qr-row">
  185. <a-col :xs="24" :sm="subJsonUrl || subClashUrl ? 12 : 24" class="qr-col">
  186. <div class="qr-box">
  187. <a-tag color="purple" class="qr-tag">{{ t('pages.settings.subSettings') }}</a-tag>
  188. <a-qrcode class="qr-code" :value="subUrl" :size="QR_SIZE" type="svg" :bordered="false"
  189. :title="t('copy')" @click="copy(subUrl)" />
  190. </div>
  191. </a-col>
  192. <a-col v-if="subJsonUrl" :xs="24" :sm="12" class="qr-col">
  193. <div class="qr-box">
  194. <a-tag color="purple" class="qr-tag">
  195. {{ t('pages.settings.subSettings') }} JSON
  196. </a-tag>
  197. <a-qrcode class="qr-code" :value="subJsonUrl" :size="QR_SIZE" type="svg" :bordered="false"
  198. :title="t('copy')" @click="copy(subJsonUrl)" />
  199. </div>
  200. </a-col>
  201. <a-col v-if="subClashUrl" :xs="24" :sm="12" class="qr-col">
  202. <div class="qr-box">
  203. <a-tag color="purple" class="qr-tag">Clash / Mihomo</a-tag>
  204. <a-qrcode class="qr-code" :value="subClashUrl" :size="QR_SIZE" type="svg" :bordered="false"
  205. :title="t('copy')" @click="copy(subClashUrl)" />
  206. </div>
  207. </a-col>
  208. </a-row>
  209. <!-- ============== Subscription details ============== -->
  210. <a-descriptions bordered :column="1" size="small" class="info-table">
  211. <a-descriptions-item :label="t('subscription.subId')">{{ sId }}</a-descriptions-item>
  212. <a-descriptions-item :label="t('subscription.status')">
  213. <a-tag v-if="!enabled" color="red">{{ t('subscription.inactive') }}</a-tag>
  214. <a-tag v-else-if="isUnlimited" color="purple">{{ t('subscription.unlimited') }}</a-tag>
  215. <a-tag v-else :color="isActive ? 'green' : 'red'">
  216. {{ isActive ? t('subscription.active') : t('subscription.inactive') }}
  217. </a-tag>
  218. </a-descriptions-item>
  219. <a-descriptions-item :label="t('subscription.downloaded')">{{ download }}</a-descriptions-item>
  220. <a-descriptions-item :label="t('subscription.uploaded')">{{ upload }}</a-descriptions-item>
  221. <a-descriptions-item :label="t('usage')">{{ used }}</a-descriptions-item>
  222. <a-descriptions-item :label="t('subscription.totalQuota')">{{ total }}</a-descriptions-item>
  223. <a-descriptions-item v-if="totalByte > 0" :label="t('remained')">
  224. {{ remained }}
  225. </a-descriptions-item>
  226. <a-descriptions-item :label="t('lastOnline')">
  227. <template v-if="lastOnlineMs > 0">{{ IntlUtil.formatDate(lastOnlineMs, datepicker) }}</template>
  228. <template v-else>-</template>
  229. </a-descriptions-item>
  230. <a-descriptions-item :label="t('subscription.expiry')">
  231. <template v-if="expireMs === 0">{{ t('subscription.noExpiry') }}</template>
  232. <template v-else>{{ IntlUtil.formatDate(expireMs, datepicker) }}</template>
  233. </a-descriptions-item>
  234. </a-descriptions>
  235. <!-- ============== Individual links ============== -->
  236. <div v-if="links.length" class="links-section">
  237. <div v-for="(link, idx) in links" :key="link" class="link-row" @click="copy(link)">
  238. <a-tag color="purple" class="link-tag">{{ linkName(link, idx) }}</a-tag>
  239. <div class="link-box">
  240. <CopyOutlined class="link-copy-icon" />
  241. {{ link }}
  242. </div>
  243. </div>
  244. </div>
  245. <!-- ============== App dropdowns ============== -->
  246. <a-row :gutter="[8, 8]" justify="center" class="apps-row">
  247. <a-col :xs="24" :sm="12" class="app-col">
  248. <a-dropdown :trigger="['click']">
  249. <a-button :block="isMobile" size="large" type="primary">
  250. <AndroidOutlined /> Android
  251. <DownOutlined />
  252. </a-button>
  253. <template #overlay>
  254. <a-menu>
  255. <a-menu-item key="android-v2box"
  256. @click="open(`v2box://install-sub?url=${encodeURIComponent(subUrl)}&name=${encodeURIComponent(sId)}`)">V2Box</a-menu-item>
  257. <a-menu-item key="android-v2rayng"
  258. @click="open(`v2rayng://install-config?url=${encodeURIComponent(subUrl)}`)">V2RayNG</a-menu-item>
  259. <a-menu-item key="android-singbox" @click="copy(subUrl)">Sing-box</a-menu-item>
  260. <a-menu-item key="android-v2raytun" @click="copy(subUrl)">V2RayTun</a-menu-item>
  261. <a-menu-item key="android-npvtunnel" @click="copy(subUrl)">NPV Tunnel</a-menu-item>
  262. <a-menu-item key="android-happ" @click="open(`happ://add/${subUrl}`)">Happ</a-menu-item>
  263. </a-menu>
  264. </template>
  265. </a-dropdown>
  266. </a-col>
  267. <a-col :xs="24" :sm="12" class="app-col">
  268. <a-dropdown :trigger="['click']">
  269. <a-button :block="isMobile" size="large" type="primary">
  270. <AppleOutlined /> iOS
  271. <DownOutlined />
  272. </a-button>
  273. <template #overlay>
  274. <a-menu>
  275. <a-menu-item key="ios-shadowrocket" @click="open(shadowrocketUrl)">Shadowrocket</a-menu-item>
  276. <a-menu-item key="ios-v2box" @click="open(v2boxUrl)">V2Box</a-menu-item>
  277. <a-menu-item key="ios-streisand" @click="open(streisandUrl)">Streisand</a-menu-item>
  278. <a-menu-item key="ios-v2raytun" @click="copy(v2raytunUrl)">V2RayTun</a-menu-item>
  279. <a-menu-item key="ios-npvtunnel" @click="copy(npvtunUrl)">NPV Tunnel</a-menu-item>
  280. <a-menu-item key="ios-happ" @click="open(happUrl)">Happ</a-menu-item>
  281. </a-menu>
  282. </template>
  283. </a-dropdown>
  284. </a-col>
  285. </a-row>
  286. </a-card>
  287. </a-col>
  288. </a-row>
  289. </a-layout-content>
  290. </a-layout>
  291. </a-config-provider>
  292. </template>
  293. <style scoped>
  294. .subscription-page {
  295. --bg-page: #e6e8ec;
  296. --bg-card: #ffffff;
  297. min-height: 100vh;
  298. background: var(--bg-page);
  299. }
  300. .subscription-page.is-dark {
  301. --bg-page: #1e1e1e;
  302. --bg-card: #252526;
  303. }
  304. .subscription-page.is-dark.is-ultra {
  305. --bg-page: #050505;
  306. --bg-card: #0c0e12;
  307. }
  308. .subscription-page :deep(.ant-layout),
  309. .subscription-page :deep(.ant-layout-content) {
  310. background: transparent;
  311. }
  312. .content {
  313. padding: 24px 12px;
  314. }
  315. .subscription-card {
  316. margin-top: 8px;
  317. }
  318. /* QR section */
  319. .qr-row {
  320. margin-bottom: 12px;
  321. }
  322. .qr-col {
  323. display: flex;
  324. justify-content: center;
  325. }
  326. .qr-box {
  327. display: inline-flex;
  328. flex-direction: column;
  329. align-items: center;
  330. gap: 4px;
  331. width: 240px;
  332. }
  333. .qr-tag {
  334. width: 100%;
  335. text-align: center;
  336. margin: 0;
  337. }
  338. .qr-code {
  339. cursor: pointer;
  340. padding: 0 !important;
  341. background: #fff;
  342. border-radius: 4px;
  343. }
  344. /* Description list spacing + visible borders. AD-Vue's default
  345. * descriptions border is rgba(5,5,5,0.06) which disappears against
  346. * the white card in light theme. AD-Vue puts the horizontal divider
  347. * on <tr> with border-collapse:collapse — browsers treat <tr>
  348. * borders inconsistently in collapse mode, so paint the divider on
  349. * each cell's bottom edge instead. */
  350. .info-table {
  351. margin-top: 12px;
  352. }
  353. .info-table :deep(.ant-descriptions-view),
  354. .info-table :deep(.ant-descriptions-view) table,
  355. .info-table :deep(.ant-descriptions-view) th,
  356. .info-table :deep(.ant-descriptions-view) td {
  357. border-color: rgba(0, 0, 0, 0.18) !important;
  358. }
  359. .info-table :deep(tbody > tr > th),
  360. .info-table :deep(tbody > tr > td) {
  361. border-bottom: 1px solid rgba(0, 0, 0, 0.18) !important;
  362. }
  363. .info-table :deep(tbody > tr:last-child > th),
  364. .info-table :deep(tbody > tr:last-child > td) {
  365. border-bottom: none !important;
  366. }
  367. .is-dark .info-table :deep(.ant-descriptions-view),
  368. .is-dark .info-table :deep(.ant-descriptions-view) table,
  369. .is-dark .info-table :deep(.ant-descriptions-view) th,
  370. .is-dark .info-table :deep(.ant-descriptions-view) td {
  371. border-color: rgba(255, 255, 255, 0.18) !important;
  372. }
  373. .is-dark .info-table :deep(tbody > tr > th),
  374. .is-dark .info-table :deep(tbody > tr > td) {
  375. border-bottom: 1px solid rgba(255, 255, 255, 0.18) !important;
  376. }
  377. .is-dark .info-table :deep(tbody > tr:last-child > th),
  378. .is-dark .info-table :deep(tbody > tr:last-child > td) {
  379. border-bottom: none !important;
  380. }
  381. /* Share links */
  382. .links-section {
  383. margin-top: 16px;
  384. }
  385. .link-row {
  386. position: relative;
  387. margin-bottom: 16px;
  388. text-align: center;
  389. }
  390. .link-tag {
  391. margin-bottom: -10px;
  392. position: relative;
  393. z-index: 2;
  394. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  395. }
  396. .link-box {
  397. cursor: pointer;
  398. border-radius: 12px;
  399. padding: 22px 18px 14px;
  400. margin-top: -10px;
  401. word-break: break-all;
  402. font-size: 13px;
  403. line-height: 1.5;
  404. text-align: left;
  405. font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  406. transition: background 120ms ease, border-color 120ms ease;
  407. box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
  408. background: rgba(0, 0, 0, 0.03);
  409. border: 1px solid rgba(0, 0, 0, 0.08);
  410. }
  411. .link-box:hover {
  412. background: rgba(0, 0, 0, 0.05);
  413. border-color: rgba(0, 0, 0, 0.14);
  414. }
  415. .link-copy-icon {
  416. margin-right: 6px;
  417. opacity: 0.6;
  418. }
  419. .is-dark .link-box {
  420. background: rgba(0, 0, 0, 0.2);
  421. border-color: rgba(255, 255, 255, 0.1);
  422. color: rgba(255, 255, 255, 0.85);
  423. }
  424. .is-dark .link-box:hover {
  425. background: rgba(0, 0, 0, 0.3);
  426. border-color: rgba(255, 255, 255, 0.2);
  427. }
  428. /* App dropdown row */
  429. .apps-row {
  430. margin-top: 24px;
  431. }
  432. .app-col {
  433. text-align: center;
  434. }
  435. .settings-popover {
  436. min-width: 220px;
  437. }
  438. .theme-cycle {
  439. width: 32px;
  440. height: 32px;
  441. border-radius: 50%;
  442. border: 1px solid rgba(0, 0, 0, 0.08);
  443. background: var(--bg-card);
  444. color: rgba(0, 0, 0, 0.65);
  445. display: inline-flex;
  446. align-items: center;
  447. justify-content: center;
  448. cursor: pointer;
  449. padding: 0;
  450. transition: background-color 0.2s, transform 0.15s, color 0.2s;
  451. }
  452. .theme-cycle:hover,
  453. .theme-cycle:focus-visible {
  454. background-color: rgba(64, 150, 255, 0.1);
  455. color: #4096ff;
  456. transform: scale(1.05);
  457. outline: none;
  458. }
  459. .theme-cycle svg {
  460. width: 16px;
  461. height: 16px;
  462. }
  463. .is-dark .theme-cycle {
  464. border-color: rgba(255, 255, 255, 0.08);
  465. color: rgba(255, 255, 255, 0.85);
  466. }
  467. .is-dark .theme-cycle:hover,
  468. .is-dark .theme-cycle:focus-visible {
  469. background-color: rgba(64, 150, 255, 0.1);
  470. color: #4096ff;
  471. }
  472. .lang-select {
  473. width: 100%;
  474. }
  475. </style>