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 buildWith the Vue host and TAdmin in sibling directories, run in the host directory:
npm install ../TAdmin/webThe 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
| Member | Contract |
|---|---|
request.get<T> / post<T> | Resolve with unwrapped business data; reject on failure |
captureRequestScope | Capture endpoint, realm and stable login identity; return a validity predicate |
t | Translate shared package keys through the host’s language instance |
hasPermission | Evaluate 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:
| Stage | Host responsibility | Result for the shared page |
|---|---|---|
| Send | Apply endpoint, realm, locale and authentication; forward signal to the transport | A request belonging to the same business scope |
| Ordinary success | Check HTTP status and business code, then unwrap data once | The business value of Promise<T> |
| Business or transport failure | Preserve the code and message, and reject the Promise | Failure cleanup with actionable errors |
| Binary export | Give postBlob the same authentication and cancellation behavior; recognize JSON error responses | A Blob on success, rejection on failure |
| Token renewal | Accept credentials only while the original login scope remains current | Normal 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:
| Scenario | Expected observation |
|---|---|
Successful HTTP response with code = 200 | The page receives data directly without another unwrap |
Successful HTTP status with a failing business code | The Promise rejects; an invented empty result does not overwrite a list or draft |
| Authorization denied in the current login | Report a permission failure without unbounded refresh or replay |
| Logout, endpoint change or realm change during a request | The old response cannot update the new scope; an old command cannot move to the new endpoint |
| Normal token renewal within the same login | Scope stays valid and the draft is preserved |
| Page closure cancels a request | The transport receives cancellation without duplicate notifications |
| A download returns a JSON error | Show 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:
| Source | What to inspect |
|---|---|
web/src/runtime/context.ts | TAdminRuntimeContext, request options and extension-panel interfaces |
web/src/api/client.ts | Shared scope checks, component lifetime and cancellation recognition |
samples/TAdmin.Sample/web/src/api/session.ts | Host response unwrapping, renewal and stable login scopes |
samples/TAdmin.Sample/web/src/main.ts | Installing adapters into Vue App with the host’s theme and locale |