Skip to Content
TAdminVue frontend integration

Vue frontend integration

On this page

Source dependency and styles

The frontend is not published to npm. @tgateway/tadmin-web is the module name in the repository’s web/package.json; reference it through a local directory.

Get the source from the TAdmin repository  and build from its root:

npm --prefix web ci npm --prefix web run build

With the Vue host and TAdmin in sibling directories, run in the host directory:

npm install ../TAdmin/web

The directory dependency uses the built dist. Rebuild after changing shared source; the standalone sample’s predev and prebuild scripts do this automatically. In the host’s existing Vite configuration, set resolve.dedupe to ['vue', 'vue-router', 'element-plus', '@element-plus/icons-vue'] to avoid duplicate framework instances through directory links.

The host provides Vue, Vue Router, i18n, Element Plus and its session implementation. See peerDependencies in web/package.json for compatible versions. Prepare request and permission adapters before installing the plugin:

import { createTAdminPlugin } from '@tgateway/tadmin-web' import type { TAdminRuntimeContext } from '@tgateway/tadmin-web' import '@tgateway/tadmin-web/style.css' import type { App } from 'vue' /** 将已实现的宿主适配器安装到当前 Vue App,多个 App 不共享上下文。 */ export function installAdmin(app: App, runtime: TAdminRuntimeContext) { app.use(createTAdminPlugin(runtime)) }

Required adapters

MemberContract
request.get<T> / post<T>Resolve with unwrapped business data; reject on failure
captureRequestScopeCapture endpoint, realm and stable login identity; return a validity predicate
tTranslate shared package keys through the host’s language instance
hasPermissionEvaluate one or more permission codes against the server snapshot

Forward signal and suppressErrorMessage. postBlob applies the same authentication, cancellation and error ownership to binary exports. Supply optional capabilities such as getLocale, getCurrentUser and refreshAuthAndMenus when shared pages need them.

captureRequestScope must reflect actual login scope. A constant true or comparison of rotating token strings violates its contract. See authentication.

What the request adapter returns

An ordinary successful response has this shape:

{ "code": 200, "msg": "ok", "data": [{ "id": 1, "name": "Pump" }] }

request.get<T> resolves with the array inside data. See TWebApi responses for HTTP status and business code semantics. The adapter handles:

StageHost responsibilityResult for the shared page
SendApply endpoint, realm, locale and authentication; forward signal to the transportA request belonging to the same business scope
Ordinary successCheck HTTP status and business code, then unwrap data onceThe business value of Promise<T>
Business or transport failurePreserve the code and message, and reject the PromiseFailure cleanup with actionable errors
Binary exportGive postBlob the same authentication and cancellation behavior; recognize JSON error responsesA Blob on success, rejection on failure
Token renewalAccept credentials only while the original login scope remains currentNormal renewal preserves the current draft

Cancellation, notifications and late responses

createTAdminClient(context) captures captureRequestScope() when created, checks it before sending and after receiving, and rejects expired calls when its component becomes inactive or is disposed. The host implements the predicate and forwards signal to the network layer to abort transmission.

isTAdminRequestCancelled recognizes AbortError and code = 'ERR_CANCELED'. Preserve the original types of validation, authorization, timeout and service errors. A page sets suppressErrorMessage: true when it displays the error; the host suppresses its generic notification while still rejecting the Promise.

If the host has displayed the error, preserve messageShown: true on the error passed to the shared page to avoid duplicate notifications. The Promise must still reject.

Verify these behaviors in the actual host:

ScenarioExpected observation
Successful HTTP response with code = 200The page receives data directly without another unwrap
Successful HTTP status with a failing business codeThe Promise rejects; an invented empty result does not overwrite a list or draft
Authorization denied in the current loginReport a permission failure without unbounded refresh or replay
Logout, endpoint change or realm change during a requestThe old response cannot update the new scope; an old command cannot move to the new endpoint
Normal token renewal within the same loginScope stays valid and the draft is preserved
Page closure cancels a requestThe transport receives cancellation without duplicate notifications
A download returns a JSON errorShow one real failure rather than downloading an error body as a workbook

Routes and menus

import { createTAdminAdminRouteRegistry } from '@tgateway/tadmin-web' /** 可信组件目录与后端菜单路径使用同一个宿主前缀。 */ export const adminRoutes = createTAdminAdminRouteRegistry({ routePrefix: '/sample' })

The registry returns componentKey, path, component, icon and title information for your Vue Router integration. It supplies a trusted catalog rather than loading arbitrary component paths from the database.

Import shared log, certificate, callback and account-security components as needed. Build menus from the server snapshot, protect routes with guards, and authorize APIs on the backend.

Async work and extension panels

getRoleExtensionPanels supplies role sidebar panels. Their exposed contract may include confirmClose, dirty, loading, previewing, saving, loadError, preview and save, allowing the sidebar to coordinate navigation and saving. The host owns its extension’s authorization data.

Related source:

SourceWhat to inspect
web/src/runtime/context.tsTAdminRuntimeContext, request options and extension-panel interfaces
web/src/api/client.tsShared scope checks, component lifetime and cancellation recognition
samples/TAdmin.Sample/web/src/api/session.tsHost response unwrapping, renewal and stable login scopes
samples/TAdmin.Sample/web/src/main.tsInstalling adapters into Vue App with the host’s theme and locale