Bỏ qua, đến nội dung

@digiforce-nc/plugin-mobile ​

Plugin cung cấp giao diện mobile — layout riêng cho thiết bị di động, tab bar navigation, dynamic pages, và tích hợp JSBridge cho native features.

Plugin này làm gì? ​

Plugin tạo một ứng dụng mobile hoàn chỉnh chạy song song với desktop — router riêng (basename /m), layout tối ưu cho mobile, tab bar navigation, và trang động cấu hình từ admin.

Ba nhiệm vụ chính ​

#Nhiệm vụChi tiết
1Mobile layout & navigationRouter /m, antd-mobile layout, tab bar, header back
2Dynamic pagesAdmin cấu hình trang mobile, gán route, phân quyền theo role
3Native integrationJSBridge cho camera, GPS, push notification trong WebView

Kiến trúc ​

Luồng truy cập mobile ​

Mobile Router architecture ​

RouteMô tả
/mEntry point, redirect đến tab đầu tiên
/m/page/:idDynamic page (nội dung do admin cấu hình)
/m/tab/:nameTab cụ thể

Database - collection mobileRoutes ​

FieldMô tả
typeLoại route: tab, page, link
titleTiêu đề hiển thị
iconIcon cho tab bar hoặc menu
schemaUidReference đến UI schema (nội dung trang)
parentIdRoute cha (nested navigation)

Server hooks & extensions ​

Hook / ExtensionMô tả
mobileRoutes:afterCreate/Update/DestroyĐồng bộ routes khi admin thay đổi
roles:afterSaveCập nhật mobile access khi role thay đổi
listAccessible actionCustom action lọc routes theo role hiện tại
Localization registrationĐăng ký translations cho mobile UI

Vòng đời plugin ​

ACL - Phân quyền ​

ACL snippetQuyềnMô tả
ui.mobileRole-basedQuyền truy cập giao diện mobile
pm.mobileAdminQuyền cấu hình mobile routes

Desktop vs Mobile ​

Đặc điểmDesktopMobile
Base path//m
LayoutAntd (sidebar, header)antd-mobile (tab bar, stack)
Componentsantdantd-mobile
DetectionMặc địnhreact-device-detect auto-redirect

Ví dụ sử dụng API ​

Lấy mobile routes cho user ​

typescript
const response = await agent.resource('mobileRoutes').listAccessible();
const routes = response.body.data;
// [{ id: 1, type: 'tab', title: 'Trang chủ', icon: 'home' }, ...]

Tạo mobile route (admin) ​

typescript
await agent.resource('mobileRoutes').create({
  values: {
    type: 'tab',
    title: 'Báo cáo',
    icon: 'bar-chart',
    schemaUid: 'report-schema',
    sort: 3,
  },
});

Thành phần client ​

Thành phầnMô tả
MobileLayout / MobileTabBarLayout chính và tab bar (antd-mobile)
MobileRouterRouter với basename /m
DynamicPageRender page từ UI schema
JSBridgeInterface native features (camera, GPS)
MobileAdminSettingsSettings cấu hình mobile routes (desktop)

Dependencies ​

PackageVai trò
antd-mobileUI component library cho mobile
react-device-detectPhát hiện thiết bị mobile
@digiforce-nc/plugin-aclPhân quyền mobile access
@digiforce-nc/plugin-localizationĐa ngôn ngữ cho mobile UI

Mục lục chi tiết ​