InboundList.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. <script setup>
  2. import { computed, ref } from 'vue';
  3. import { useI18n } from 'vue-i18n';
  4. import {
  5. PlusOutlined,
  6. MenuOutlined,
  7. SearchOutlined,
  8. FilterOutlined,
  9. MoreOutlined,
  10. EditOutlined,
  11. QrcodeOutlined,
  12. UserAddOutlined,
  13. UsergroupAddOutlined,
  14. CopyOutlined,
  15. FileDoneOutlined,
  16. ExportOutlined,
  17. ImportOutlined,
  18. ReloadOutlined,
  19. RestOutlined,
  20. RetweetOutlined,
  21. BlockOutlined,
  22. DeleteOutlined,
  23. InfoCircleOutlined,
  24. RightOutlined,
  25. } from '@ant-design/icons-vue';
  26. import { HttpUtil, ObjectUtil, SizeFormatter, IntlUtil, ColorUtils } from '@/utils';
  27. import { DBInbound } from '@/models/dbinbound.js';
  28. import { Inbound } from '@/models/inbound.js';
  29. import InfinityIcon from '@/components/InfinityIcon.vue';
  30. import ClientRowTable from './ClientRowTable.vue';
  31. import { useDatepicker } from '@/composables/useDatepicker.js';
  32. const { datepicker } = useDatepicker();
  33. const { t } = useI18n();
  34. const props = defineProps({
  35. dbInbounds: { type: Array, required: true },
  36. clientCount: { type: Object, required: true },
  37. onlineClients: { type: Array, required: true },
  38. lastOnlineMap: { type: Object, default: () => ({}) },
  39. expireDiff: { type: Number, default: 0 },
  40. trafficDiff: { type: Number, default: 0 },
  41. pageSize: { type: Number, default: 0 },
  42. isMobile: { type: Boolean, default: false },
  43. isDarkTheme: { type: Boolean, default: false },
  44. subEnable: { type: Boolean, default: false },
  45. // Map node id -> node row, supplied by the parent page so each
  46. // inbound row can render its node name without an extra fetch.
  47. nodesById: { type: Map, default: () => new Map() },
  48. });
  49. const emit = defineEmits([
  50. 'refresh',
  51. 'add-inbound',
  52. 'general-action',
  53. 'row-action',
  54. // Per-client events surfaced from the expand-row table.
  55. 'edit-client',
  56. 'qrcode-client',
  57. 'info-client',
  58. 'reset-traffic-client',
  59. 'delete-client',
  60. 'toggle-enable-client',
  61. ]);
  62. // ============ Toolbar / search & filter =============================
  63. const enableFilter = ref(false);
  64. const searchKey = ref('');
  65. const filterBy = ref('');
  66. // Toggle the filter mode — flip cleans the other input.
  67. function onToggleFilter() {
  68. if (enableFilter.value) searchKey.value = '';
  69. else filterBy.value = '';
  70. }
  71. // ============ Search / filter projection =============================
  72. // Mirrors the legacy logic: when searching, keep inbounds that match
  73. // anywhere (deep search); when filtering, keep inbounds that have at
  74. // least one client in the requested bucket and reduce their settings
  75. // to that bucket.
  76. function projectInbound(dbInbound, predicate) {
  77. const next = new DBInbound(dbInbound);
  78. let settings;
  79. try {
  80. settings = JSON.parse(dbInbound.settings || '{}');
  81. } catch (_e) {
  82. settings = {};
  83. }
  84. if (!Array.isArray(settings.clients)) return next;
  85. const filtered = settings.clients.filter(predicate);
  86. next.settings = Inbound.Settings.fromJson(dbInbound.protocol, { clients: filtered });
  87. next.invalidateCache();
  88. return next;
  89. }
  90. const visibleInbounds = computed(() => {
  91. if (enableFilter.value) {
  92. if (ObjectUtil.isEmpty(filterBy.value)) return [...props.dbInbounds];
  93. const out = [];
  94. for (const dbInbound of props.dbInbounds) {
  95. const c = props.clientCount[dbInbound.id];
  96. if (!c || !c[filterBy.value] || c[filterBy.value].length === 0) continue;
  97. const list = c[filterBy.value];
  98. out.push(projectInbound(dbInbound, (client) => list.includes(client.email)));
  99. }
  100. return out;
  101. }
  102. if (ObjectUtil.isEmpty(searchKey.value)) return [...props.dbInbounds];
  103. const out = [];
  104. for (const dbInbound of props.dbInbounds) {
  105. if (!ObjectUtil.deepSearch(dbInbound, searchKey.value)) continue;
  106. out.push(projectInbound(dbInbound, (client) => ObjectUtil.deepSearch(client, searchKey.value)));
  107. }
  108. return out;
  109. });
  110. // ============ Columns =================================================
  111. // `key`-driven so we can render via the body-cell slot below. AD-Vue 4's
  112. // `responsive` array still works on column defs. Computed so column
  113. // labels react to live locale switches.
  114. const desktopColumns = computed(() => {
  115. const cols = [
  116. { title: 'ID', dataIndex: 'id', key: 'id', align: 'right', width: 30, responsive: ['xs'] },
  117. { title: t('pages.inbounds.operate'), key: 'action', align: 'center', width: 30 },
  118. { title: t('pages.inbounds.enable'), key: 'enable', align: 'center', width: 35 },
  119. { title: t('pages.inbounds.remark'), dataIndex: 'remark', key: 'remark', align: 'center', width: 60 },
  120. ];
  121. if (props.nodesById.size > 0) {
  122. cols.push({ title: t('pages.inbounds.node'), key: 'node', align: 'center', width: 60 });
  123. }
  124. cols.push(
  125. { title: t('pages.inbounds.port'), dataIndex: 'port', key: 'port', align: 'center', width: 40 },
  126. { title: t('pages.inbounds.protocol'), key: 'protocol', align: 'left', width: 130 },
  127. { title: t('clients'), key: 'clients', align: 'left', width: 50 },
  128. { title: t('pages.inbounds.traffic'), key: 'traffic', align: 'center', width: 90 },
  129. { title: t('pages.inbounds.allTimeTraffic'), key: 'allTimeInbound', align: 'center', width: 95 },
  130. { title: t('pages.inbounds.expireDate'), key: 'expiryTime', align: 'center', width: 40 },
  131. );
  132. return cols;
  133. });
  134. const columns = computed(() => desktopColumns.value);
  135. // Mobile expansion state — replaces a-table's expandable() since the
  136. // mobile branch renders a hand-rolled card list rather than a table.
  137. const expandedIds = ref(new Set());
  138. function toggleExpanded(id) {
  139. const next = new Set(expandedIds.value);
  140. if (next.has(id)) next.delete(id);
  141. else next.add(id);
  142. expandedIds.value = next;
  143. }
  144. function isExpanded(id) {
  145. return expandedIds.value.has(id);
  146. }
  147. // ============ Pagination ============================================
  148. function paginationFor(rows) {
  149. const size = props.pageSize > 0 ? props.pageSize : rows.length || 1;
  150. return {
  151. pageSize: size,
  152. showSizeChanger: false,
  153. hideOnSinglePage: true,
  154. };
  155. }
  156. // ============ Per-row enable switch =================================
  157. async function onSwitchEnable(dbInbound, next) {
  158. const previous = dbInbound.enable;
  159. dbInbound.enable = next; // optimistic
  160. try {
  161. const formData = new FormData();
  162. formData.append('enable', String(next));
  163. const msg = await HttpUtil.post(`/panel/api/inbounds/setEnable/${dbInbound.id}`, formData);
  164. if (!msg?.success) dbInbound.enable = previous;
  165. } catch (_e) {
  166. dbInbound.enable = previous;
  167. }
  168. }
  169. // ============ Helpers shared with the templates =====================
  170. // Whether to show the "Switch xray" / qrcode menu entry — same predicate
  171. // as legacy: SS single-user inbounds and WireGuard inbounds expose
  172. // inbound-wide QR codes.
  173. function showQrCodeMenu(dbInbound) {
  174. if (dbInbound.isWireguard) return true;
  175. if (dbInbound.isSS) {
  176. try {
  177. return !dbInbound.toInbound().isSSMultiUser;
  178. } catch (_e) {
  179. return false;
  180. }
  181. }
  182. return false;
  183. }
  184. </script>
  185. <template>
  186. <a-card hoverable>
  187. <template #title>
  188. <a-space direction="horizontal">
  189. <a-button type="primary" @click="emit('add-inbound')">
  190. <template #icon>
  191. <PlusOutlined />
  192. </template>
  193. <template v-if="!isMobile">{{ t('pages.inbounds.addInbound') }}</template>
  194. </a-button>
  195. <a-dropdown :trigger="['click']">
  196. <a-button type="primary">
  197. <template #icon>
  198. <MenuOutlined />
  199. </template>
  200. <template v-if="!isMobile">{{ t('pages.inbounds.generalActions') }}</template>
  201. </a-button>
  202. <template #overlay>
  203. <a-menu @click="(a) => emit('general-action', a.key)">
  204. <a-menu-item key="import">
  205. <ImportOutlined /> {{ t('pages.inbounds.importInbound') }}
  206. </a-menu-item>
  207. <a-menu-item key="export">
  208. <ExportOutlined /> {{ t('pages.inbounds.export') }}
  209. </a-menu-item>
  210. <a-menu-item v-if="subEnable" key="subs">
  211. <ExportOutlined /> {{ t('pages.inbounds.export') }} — {{ t('pages.settings.subSettings') }}
  212. </a-menu-item>
  213. <a-menu-item key="resetInbounds">
  214. <ReloadOutlined /> {{ t('pages.inbounds.resetAllTraffic') }}
  215. </a-menu-item>
  216. <a-menu-item key="resetClients">
  217. <FileDoneOutlined /> {{ t('pages.inbounds.resetAllClientTraffics') }}
  218. </a-menu-item>
  219. <a-menu-item key="delDepletedClients" class="danger-item">
  220. <RestOutlined /> {{ t('pages.inbounds.delDepletedClients') }}
  221. </a-menu-item>
  222. </a-menu>
  223. </template>
  224. </a-dropdown>
  225. </a-space>
  226. </template>
  227. <a-space direction="vertical" :style="{ width: '100%' }">
  228. <!-- Search / filter toolbar -->
  229. <div :class="isMobile ? 'filter-bar mobile' : 'filter-bar'">
  230. <a-switch v-model:checked="enableFilter" @change="onToggleFilter">
  231. <template #checkedChildren>
  232. <SearchOutlined />
  233. </template>
  234. <template #unCheckedChildren>
  235. <FilterOutlined />
  236. </template>
  237. </a-switch>
  238. <a-input v-if="!enableFilter" v-model:value="searchKey" :placeholder="t('search')" autofocus
  239. :size="isMobile ? 'small' : 'middle'" :style="{ maxWidth: '300px' }" />
  240. <a-radio-group v-if="enableFilter" v-model:value="filterBy" button-style="solid"
  241. :size="isMobile ? 'small' : 'middle'">
  242. <a-radio-button value="">{{ t('none') }}</a-radio-button>
  243. <a-radio-button value="active">{{ t('subscription.active') }}</a-radio-button>
  244. <a-radio-button value="deactive">{{ t('disabled') }}</a-radio-button>
  245. <a-radio-button value="depleted">{{ t('depleted') }}</a-radio-button>
  246. <a-radio-button value="expiring">{{ t('depletingSoon') }}</a-radio-button>
  247. <a-radio-button value="online">{{ t('online') }}</a-radio-button>
  248. </a-radio-group>
  249. </div>
  250. <!-- ====================== Mobile: card list ======================= -->
  251. <div v-if="isMobile" class="inbound-cards">
  252. <div v-if="visibleInbounds.length === 0" class="card-empty">—</div>
  253. <div v-for="record in visibleInbounds" :key="record.id" class="inbound-card">
  254. <!-- Header: chevron (multi-user only) + remark + enable + actions -->
  255. <div class="card-head" @click="record.isMultiUser() && toggleExpanded(record.id)">
  256. <RightOutlined v-if="record.isMultiUser()" class="card-expand"
  257. :class="{ 'is-expanded': isExpanded(record.id) }" />
  258. <span class="card-id">#{{ record.id }}</span>
  259. <span class="tag-name">{{ record.remark }}</span>
  260. <div class="card-actions" @click.stop>
  261. <a-switch :checked="record.enable" size="small"
  262. @change="(next) => onSwitchEnable(record, next)" />
  263. <a-dropdown :trigger="['click']" placement="bottomRight">
  264. <MoreOutlined class="row-action-trigger" @click.prevent />
  265. <template #overlay>
  266. <a-menu @click="(a) => emit('row-action', { key: a.key, dbInbound: record })">
  267. <a-menu-item key="edit">
  268. <EditOutlined /> {{ t('edit') }}
  269. </a-menu-item>
  270. <a-menu-item v-if="showQrCodeMenu(record)" key="qrcode">
  271. <QrcodeOutlined /> {{ t('qrCode') }}
  272. </a-menu-item>
  273. <template v-if="record.isMultiUser()">
  274. <a-menu-item key="addClient">
  275. <UserAddOutlined /> {{ t('pages.client.add') }}
  276. </a-menu-item>
  277. <a-menu-item key="addBulkClient">
  278. <UsergroupAddOutlined /> {{ t('pages.client.bulk') }}
  279. </a-menu-item>
  280. <a-menu-item key="copyClients">
  281. <CopyOutlined /> {{ t('pages.client.copyFromInbound') }}
  282. </a-menu-item>
  283. <a-menu-item key="resetClients">
  284. <FileDoneOutlined /> {{ t('pages.inbounds.resetInboundClientTraffics') }}
  285. </a-menu-item>
  286. <a-menu-item key="export">
  287. <ExportOutlined /> {{ t('pages.inbounds.export') }}
  288. </a-menu-item>
  289. <a-menu-item v-if="subEnable" key="subs">
  290. <ExportOutlined /> {{ t('pages.inbounds.export') }} — {{ t('pages.settings.subSettings') }}
  291. </a-menu-item>
  292. <a-menu-item key="delDepletedClients" class="danger-item">
  293. <RestOutlined /> {{ t('pages.inbounds.delDepletedClients') }}
  294. </a-menu-item>
  295. </template>
  296. <template v-else>
  297. <a-menu-item key="showInfo">
  298. <InfoCircleOutlined /> {{ t('info') }}
  299. </a-menu-item>
  300. </template>
  301. <a-menu-item key="clipboard">
  302. <CopyOutlined /> {{ t('pages.inbounds.exportInbound') }}
  303. </a-menu-item>
  304. <a-menu-item key="resetTraffic">
  305. <RetweetOutlined /> {{ t('pages.inbounds.resetTraffic') }}
  306. </a-menu-item>
  307. <a-menu-item key="clone">
  308. <BlockOutlined /> {{ t('pages.inbounds.clone') }}
  309. </a-menu-item>
  310. <a-menu-item key="delete" class="danger-item">
  311. <DeleteOutlined /> {{ t('delete') }}
  312. </a-menu-item>
  313. </a-menu>
  314. </template>
  315. </a-dropdown>
  316. </div>
  317. </div>
  318. <!-- 2-column labelled stat grid: protocol/port/node + traffic/clients/expiry -->
  319. <div class="card-stats">
  320. <div class="stat-row">
  321. <span class="stat-label">{{ t('pages.inbounds.protocol') }}</span>
  322. <a-tag color="purple">{{ record.protocol }}</a-tag>
  323. <template v-if="record.isVMess || record.isVLess || record.isTrojan || record.isSS">
  324. <a-tag color="green">{{ record.toInbound().stream.network }}</a-tag>
  325. <a-tag v-if="record.toInbound().stream.isTls" color="blue">TLS</a-tag>
  326. <a-tag v-if="record.toInbound().stream.isReality" color="blue">Reality</a-tag>
  327. </template>
  328. </div>
  329. <div class="stat-row">
  330. <span class="stat-label">{{ t('pages.inbounds.port') }}</span>
  331. <a-tag>{{ record.port }}</a-tag>
  332. </div>
  333. <div v-if="nodesById.size > 0" class="stat-row">
  334. <span class="stat-label">{{ t('pages.inbounds.node') }}</span>
  335. <a-tag v-if="record.nodeId == null" color="default">
  336. {{ t('pages.inbounds.localPanel') }}
  337. </a-tag>
  338. <a-tag v-else-if="nodesById.get(record.nodeId)"
  339. :color="nodesById.get(record.nodeId).status === 'online' ? 'blue' : 'red'">
  340. {{ nodesById.get(record.nodeId).name }}
  341. </a-tag>
  342. <a-tag v-else color="orange">#{{ record.nodeId }}</a-tag>
  343. </div>
  344. <div class="stat-row">
  345. <span class="stat-label">{{ t('pages.inbounds.traffic') }}</span>
  346. <a-tag :color="ColorUtils.usageColor(record.up + record.down, trafficDiff, record.total)">
  347. {{ SizeFormatter.sizeFormat(record.up + record.down) }} /
  348. <template v-if="record.total > 0">{{ SizeFormatter.sizeFormat(record.total) }}</template>
  349. <InfinityIcon v-else />
  350. </a-tag>
  351. </div>
  352. <div class="stat-row">
  353. <span class="stat-label">{{ t('pages.inbounds.allTimeTraffic') }}</span>
  354. <a-tag>{{ SizeFormatter.sizeFormat(record.allTime || 0) }}</a-tag>
  355. </div>
  356. <div v-if="clientCount[record.id]" class="stat-row">
  357. <span class="stat-label">{{ t('clients') }}</span>
  358. <a-tag color="green">{{ clientCount[record.id].clients }}</a-tag>
  359. <a-tag v-if="clientCount[record.id].online.length" color="blue">
  360. {{ clientCount[record.id].online.length }} {{ t('online') }}
  361. </a-tag>
  362. <a-tag v-if="clientCount[record.id].depleted.length" color="red">
  363. {{ clientCount[record.id].depleted.length }} {{ t('depleted') }}
  364. </a-tag>
  365. <a-tag v-if="clientCount[record.id].expiring.length" color="orange">
  366. {{ clientCount[record.id].expiring.length }} {{ t('depletingSoon') }}
  367. </a-tag>
  368. </div>
  369. <div class="stat-row">
  370. <span class="stat-label">{{ t('pages.inbounds.expireDate') }}</span>
  371. <a-tag v-if="record.expiryTime > 0"
  372. :color="ColorUtils.usageColor(Date.now(), expireDiff, record._expiryTime)">
  373. {{ IntlUtil.formatRelativeTime(record.expiryTime) }}
  374. </a-tag>
  375. <a-tag v-else color="purple"><InfinityIcon /></a-tag>
  376. </div>
  377. </div>
  378. <!-- Expanded client list (multi-user only) -->
  379. <div v-if="record.isMultiUser() && isExpanded(record.id)" class="card-clients">
  380. <ClientRowTable :db-inbound="record" :is-mobile="true"
  381. :traffic-diff="trafficDiff" :expire-diff="expireDiff" :online-clients="onlineClients"
  382. :last-online-map="lastOnlineMap" :is-dark-theme="isDarkTheme"
  383. @edit-client="(p) => emit('edit-client', p)"
  384. @qrcode-client="(p) => emit('qrcode-client', p)"
  385. @info-client="(p) => emit('info-client', p)"
  386. @reset-traffic-client="(p) => emit('reset-traffic-client', p)"
  387. @delete-client="(p) => emit('delete-client', p)"
  388. @toggle-enable-client="(p) => emit('toggle-enable-client', p)" />
  389. </div>
  390. </div>
  391. </div>
  392. <!-- ====================== Desktop: a-table ======================== -->
  393. <a-table v-else :columns="columns" :data-source="visibleInbounds" :row-key="(r) => r.id"
  394. :pagination="paginationFor(visibleInbounds)" :scroll="{ x: 1000 }"
  395. :style="{ marginTop: '10px' }" size="small"
  396. :row-class-name="(r) => (r.isMultiUser() ? '' : 'hide-expand-icon')">
  397. <!-- Per-inbound client list, expanded by clicking the row's
  398. default expand chevron. Hidden via row-class-name for
  399. non-multi-user inbounds (matches legacy behavior). -->
  400. <template #expandedRowRender="{ record }">
  401. <ClientRowTable v-if="record.isMultiUser()" :db-inbound="record" :is-mobile="isMobile"
  402. :traffic-diff="trafficDiff" :expire-diff="expireDiff" :online-clients="onlineClients"
  403. :last-online-map="lastOnlineMap" :is-dark-theme="isDarkTheme" @edit-client="(p) => emit('edit-client', p)"
  404. @qrcode-client="(p) => emit('qrcode-client', p)" @info-client="(p) => emit('info-client', p)"
  405. @reset-traffic-client="(p) => emit('reset-traffic-client', p)"
  406. @delete-client="(p) => emit('delete-client', p)"
  407. @toggle-enable-client="(p) => emit('toggle-enable-client', p)" />
  408. </template>
  409. <template #bodyCell="{ column, record }">
  410. <!-- ============== Action dropdown ============== -->
  411. <template v-if="column.key === 'action'">
  412. <a-dropdown :trigger="['click']">
  413. <MoreOutlined class="row-action-trigger" @click.prevent />
  414. <template #overlay>
  415. <a-menu @click="(a) => emit('row-action', { key: a.key, dbInbound: record })">
  416. <a-menu-item key="edit">
  417. <EditOutlined /> {{ t('edit') }}
  418. </a-menu-item>
  419. <a-menu-item v-if="showQrCodeMenu(record)" key="qrcode">
  420. <QrcodeOutlined /> {{ t('qrCode') }}
  421. </a-menu-item>
  422. <template v-if="record.isMultiUser()">
  423. <a-menu-item key="addClient">
  424. <UserAddOutlined /> {{ t('pages.client.add') }}
  425. </a-menu-item>
  426. <a-menu-item key="addBulkClient">
  427. <UsergroupAddOutlined /> {{ t('pages.client.bulk') }}
  428. </a-menu-item>
  429. <a-menu-item key="copyClients">
  430. <CopyOutlined /> {{ t('pages.client.copyFromInbound') }}
  431. </a-menu-item>
  432. <a-menu-item key="resetClients">
  433. <FileDoneOutlined /> {{ t('pages.inbounds.resetInboundClientTraffics') }}
  434. </a-menu-item>
  435. <a-menu-item key="export">
  436. <ExportOutlined /> {{ t('pages.inbounds.export') }}
  437. </a-menu-item>
  438. <a-menu-item v-if="subEnable" key="subs">
  439. <ExportOutlined /> {{ t('pages.inbounds.export') }} — {{ t('pages.settings.subSettings') }}
  440. </a-menu-item>
  441. <a-menu-item key="delDepletedClients" class="danger-item">
  442. <RestOutlined /> {{ t('pages.inbounds.delDepletedClients') }}
  443. </a-menu-item>
  444. </template>
  445. <template v-else>
  446. <a-menu-item key="showInfo">
  447. <InfoCircleOutlined /> {{ t('info') }}
  448. </a-menu-item>
  449. </template>
  450. <a-menu-item key="clipboard">
  451. <CopyOutlined /> {{ t('pages.inbounds.exportInbound') }}
  452. </a-menu-item>
  453. <a-menu-item key="resetTraffic">
  454. <RetweetOutlined /> {{ t('pages.inbounds.resetTraffic') }}
  455. </a-menu-item>
  456. <a-menu-item key="clone">
  457. <BlockOutlined /> {{ t('pages.inbounds.clone') }}
  458. </a-menu-item>
  459. <a-menu-item key="delete" class="danger-item">
  460. <DeleteOutlined /> {{ t('delete') }}
  461. </a-menu-item>
  462. </a-menu>
  463. </template>
  464. </a-dropdown>
  465. </template>
  466. <!-- ============== Enable switch (desktop) ============== -->
  467. <template v-else-if="column.key === 'enable'">
  468. <a-switch :checked="record.enable" @change="(next) => onSwitchEnable(record, next)" />
  469. </template>
  470. <!-- ============== Node deployment tag ============== -->
  471. <template v-else-if="column.key === 'node'">
  472. <template v-if="record.nodeId == null">
  473. <a-tag color="default">{{ t('pages.inbounds.localPanel') }}</a-tag>
  474. </template>
  475. <template v-else-if="nodesById.get(record.nodeId)">
  476. <a-tag :color="nodesById.get(record.nodeId).status === 'online' ? 'blue' : 'red'">
  477. {{ nodesById.get(record.nodeId).name }}
  478. </a-tag>
  479. </template>
  480. <template v-else>
  481. <!-- Node row was deleted but inbound still references it. -->
  482. <a-tag color="orange">node #{{ record.nodeId }}</a-tag>
  483. </template>
  484. </template>
  485. <!-- ============== Protocol tags ============== -->
  486. <template v-else-if="column.key === 'protocol'">
  487. <div class="protocol-tags">
  488. <a-tag color="purple">{{ record.protocol }}</a-tag>
  489. <template v-if="record.isVMess || record.isVLess || record.isTrojan || record.isSS">
  490. <a-tag color="green">{{ record.toInbound().stream.network }}</a-tag>
  491. <a-tag v-if="record.toInbound().stream.isTls" color="blue">TLS</a-tag>
  492. <a-tag v-if="record.toInbound().stream.isReality" color="blue">Reality</a-tag>
  493. </template>
  494. </div>
  495. </template>
  496. <!-- ============== Clients tag + popovers ============== -->
  497. <template v-else-if="column.key === 'clients'">
  498. <template v-if="clientCount[record.id]">
  499. <a-tag color="green" style="margin: 0">{{ clientCount[record.id].clients }}</a-tag>
  500. <a-popover v-if="clientCount[record.id].deactive.length" :title="t('disabled')">
  501. <template #content>
  502. <div v-for="email in clientCount[record.id].deactive" :key="email">{{ email }}</div>
  503. </template>
  504. <a-tag style="margin: 0; padding: 0 2px">{{ clientCount[record.id].deactive.length }}</a-tag>
  505. </a-popover>
  506. <a-popover v-if="clientCount[record.id].depleted.length" :title="t('depleted')">
  507. <template #content>
  508. <div v-for="email in clientCount[record.id].depleted" :key="email">{{ email }}</div>
  509. </template>
  510. <a-tag color="red" style="margin: 0; padding: 0 2px">{{ clientCount[record.id].depleted.length
  511. }}</a-tag>
  512. </a-popover>
  513. <a-popover v-if="clientCount[record.id].expiring.length" :title="t('depletingSoon')">
  514. <template #content>
  515. <div v-for="email in clientCount[record.id].expiring" :key="email">{{ email }}</div>
  516. </template>
  517. <a-tag color="orange" style="margin: 0; padding: 0 2px">{{ clientCount[record.id].expiring.length
  518. }}</a-tag>
  519. </a-popover>
  520. <a-popover v-if="clientCount[record.id].online.length" :title="t('online')">
  521. <template #content>
  522. <div v-for="email in clientCount[record.id].online" :key="email">{{ email }}</div>
  523. </template>
  524. <a-tag color="blue" style="margin: 0; padding: 0 2px">{{ clientCount[record.id].online.length }}</a-tag>
  525. </a-popover>
  526. </template>
  527. </template>
  528. <!-- ============== Traffic ============== -->
  529. <template v-else-if="column.key === 'traffic'">
  530. <a-popover>
  531. <template #content>
  532. <table cellpadding="2">
  533. <tbody>
  534. <tr>
  535. <td>↑ {{ SizeFormatter.sizeFormat(record.up) }}</td>
  536. <td>↓ {{ SizeFormatter.sizeFormat(record.down) }}</td>
  537. </tr>
  538. <tr v-if="record.total > 0 && record.up + record.down < record.total">
  539. <td>{{ t('remained') }}</td>
  540. <td>{{ SizeFormatter.sizeFormat(record.total - record.up - record.down) }}</td>
  541. </tr>
  542. </tbody>
  543. </table>
  544. </template>
  545. <a-tag :color="ColorUtils.usageColor(record.up + record.down, trafficDiff, record.total)">
  546. {{ SizeFormatter.sizeFormat(record.up + record.down) }} /
  547. <template v-if="record.total > 0">{{ SizeFormatter.sizeFormat(record.total) }}</template>
  548. <InfinityIcon v-else />
  549. </a-tag>
  550. </a-popover>
  551. </template>
  552. <!-- ============== All-time inbound traffic ============== -->
  553. <template v-else-if="column.key === 'allTimeInbound'">
  554. <a-tag>{{ SizeFormatter.sizeFormat(record.allTime || 0) }}</a-tag>
  555. </template>
  556. <!-- ============== Expiry ============== -->
  557. <template v-else-if="column.key === 'expiryTime'">
  558. <a-popover v-if="record.expiryTime > 0">
  559. <template #content>{{ IntlUtil.formatDate(record.expiryTime, datepicker) }}</template>
  560. <a-tag :color="ColorUtils.usageColor(Date.now(), expireDiff, record._expiryTime)" style="min-width: 50px">
  561. {{ IntlUtil.formatRelativeTime(record.expiryTime) }}
  562. </a-tag>
  563. </a-popover>
  564. <a-tag v-else color="purple">
  565. <InfinityIcon />
  566. </a-tag>
  567. </template>
  568. </template>
  569. </a-table>
  570. </a-space>
  571. </a-card>
  572. </template>
  573. <style scoped>
  574. .filter-bar {
  575. display: flex;
  576. align-items: center;
  577. gap: 8px;
  578. }
  579. .filter-bar.mobile {
  580. display: block;
  581. }
  582. .filter-bar.mobile>* {
  583. margin-bottom: 4px;
  584. }
  585. .protocol-tags {
  586. display: inline-flex;
  587. flex-wrap: wrap;
  588. gap: 4px;
  589. }
  590. .row-action-trigger {
  591. font-size: 20px;
  592. cursor: pointer;
  593. }
  594. .danger-item {
  595. color: #ff4d4f;
  596. }
  597. /* Hide the expand chevron on rows whose inbound has no client list
  598. * (HTTP/Mixed/Tunnel/WireGuard single-config). */
  599. :deep(.hide-expand-icon .ant-table-row-expand-icon) {
  600. visibility: hidden;
  601. }
  602. /* Push the expand chevron away from the table's left edge so it has
  603. * a little breathing room instead of being flush against the corner. */
  604. :deep(.ant-table-tbody .ant-table-cell-with-append) {
  605. padding-left: 12px;
  606. }
  607. :deep(.ant-table-row-expand-icon) {
  608. margin-inline-end: 10px;
  609. margin-inline-start: 4px;
  610. }
  611. /* Round the table's outer corners — AD-Vue gives .ant-table the radius
  612. * token, but the inner header strip and footer touch the edges, so clip
  613. * them here. */
  614. :deep(.ant-table) {
  615. border-radius: 8px;
  616. overflow: hidden;
  617. }
  618. :deep(.ant-table-container) {
  619. border-radius: 8px;
  620. overflow: hidden;
  621. }
  622. :deep(.ant-table-thead > tr:first-child > *:first-child) {
  623. border-start-start-radius: 8px;
  624. }
  625. :deep(.ant-table-thead > tr:first-child > *:last-child) {
  626. border-start-end-radius: 8px;
  627. }
  628. :deep(.ant-table-tbody > tr:last-child > *:first-child) {
  629. border-end-start-radius: 8px;
  630. }
  631. :deep(.ant-table-tbody > tr:last-child > *:last-child) {
  632. border-end-end-radius: 8px;
  633. }
  634. /* ===== Mobile card list ===========================================
  635. * <768px renders inbounds as a vertical stack of cards via the
  636. * v-if="isMobile" branch above; the desktop <a-table> isn't mounted
  637. * so the legacy table-cell tightening rules went away. */
  638. .inbound-cards {
  639. display: flex;
  640. flex-direction: column;
  641. gap: 12px;
  642. margin-top: 4px;
  643. }
  644. .inbound-card {
  645. border: 1px solid rgba(128, 128, 128, 0.2);
  646. border-radius: 10px;
  647. padding: 12px;
  648. background: rgba(255, 255, 255, 0.02);
  649. display: flex;
  650. flex-direction: column;
  651. gap: 8px;
  652. }
  653. :global(body.dark) .inbound-card {
  654. background: rgba(255, 255, 255, 0.03);
  655. border-color: rgba(255, 255, 255, 0.1);
  656. }
  657. .card-head {
  658. display: flex;
  659. align-items: center;
  660. gap: 8px;
  661. cursor: pointer;
  662. user-select: none;
  663. }
  664. .card-id {
  665. font-size: 11px;
  666. opacity: 0.6;
  667. }
  668. .tag-name {
  669. font-weight: 600;
  670. flex: 1;
  671. min-width: 0;
  672. overflow: hidden;
  673. text-overflow: ellipsis;
  674. white-space: nowrap;
  675. }
  676. .card-actions {
  677. display: flex;
  678. align-items: center;
  679. gap: 8px;
  680. flex-shrink: 0;
  681. }
  682. .card-expand {
  683. font-size: 12px;
  684. opacity: 0.6;
  685. transition: transform 150ms ease;
  686. flex-shrink: 0;
  687. }
  688. .card-expand.is-expanded {
  689. transform: rotate(90deg);
  690. }
  691. .card-stats {
  692. display: flex;
  693. flex-direction: column;
  694. gap: 6px;
  695. }
  696. .stat-row {
  697. display: flex;
  698. align-items: center;
  699. flex-wrap: wrap;
  700. gap: 6px;
  701. }
  702. .stat-label {
  703. font-size: 10px;
  704. text-transform: uppercase;
  705. letter-spacing: 0.04em;
  706. opacity: 0.6;
  707. min-width: 96px;
  708. flex-shrink: 0;
  709. }
  710. .card-stats :deep(.ant-tag) {
  711. margin: 0;
  712. }
  713. .card-clients {
  714. margin-top: 4px;
  715. padding-top: 8px;
  716. border-top: 1px solid rgba(128, 128, 128, 0.15);
  717. }
  718. .card-empty {
  719. text-align: center;
  720. opacity: 0.4;
  721. padding: 20px 0;
  722. }
  723. @media (max-width: 768px) {
  724. :deep(.ant-card-head) {
  725. padding: 0 12px;
  726. min-height: 44px;
  727. }
  728. :deep(.ant-card-head-title),
  729. :deep(.ant-card-extra) {
  730. padding: 8px 0;
  731. }
  732. :deep(.ant-card-body) {
  733. padding: 8px;
  734. }
  735. .filter-bar.mobile {
  736. display: flex;
  737. flex-wrap: wrap;
  738. gap: 6px;
  739. }
  740. .filter-bar.mobile > * {
  741. margin-bottom: 0;
  742. }
  743. .row-action-trigger {
  744. font-size: 22px;
  745. padding: 4px;
  746. }
  747. }
  748. </style>