Bảng tra cứu phát triển Plugin

Khi viết Plugin thường tự hỏi "thứ này nên viết trong tệp nào, gọi API nào". Bảng tra cứu này giúp bạn định vị nhanh.

Cấu trúc thư mục Plugin

Tạo Plugin thông qua yarn pm create @my-project/plugin-name, sẽ tự động sinh cấu trúc thư mục sau. Đừng tạo thư mục thủ công, để tránh thiếu bước đăng ký dẫn đến Plugin không có hiệu lực. Xem chi tiết tại Viết Plugin đầu tiên.

plugin-name/
├── src/
   ├── client-v2/              # Code client (v2)
   ├── plugin.tsx          # Lối vào Plugin client
   ├── locale.ts           # useT / tExpr hook dịch
   ├── models/             # FlowModel (Block, Field, Action)
   └── pages/              # Component trang
   ├── client/                 # Code client (v1, tương thích)
   ├── plugin.tsx
   ├── locale.ts
   ├── models/
   └── pages/
   ├── server/                 # Code server
   ├── plugin.ts           # Lối vào Plugin server
   └── collections/        # Định nghĩa bảng dữ liệu
   └── locale/                 # Tệp dịch đa ngôn ngữ
       ├── zh-CN.json
       └── en-US.json
├── client-v2.js                # Lối vào thư mục gốc (build artifact trỏ đến)
├── client-v2.d.ts
├── client.js
├── client.d.ts
├── server.js
├── server.d.ts
└── package.json

Client: Tôi muốn làm gì → Viết như thế nào

Tôi muốn làm gìViết trong tệp nàoGọi API gìTài liệu
Đăng ký một route trangload() của plugin.tsxthis.router.add()Router
Đăng ký một trang cài đặt pluginload() của plugin.tsxpluginSettingsManager.addMenuItem() + addPageTabItem()Router
Đăng ký một Block tùy chỉnhload() của plugin.tsxthis.flowEngine.registerModelLoaders()FlowEngine → Mở rộng Block
Đăng ký một Field tùy chỉnhload() của plugin.tsxthis.flowEngine.registerModelLoaders()FlowEngine → Mở rộng Field
Đăng ký một Action tùy chỉnhload() của plugin.tsxthis.flowEngine.registerModelLoaders()FlowEngine → Mở rộng Action
Cho bảng nội bộ xuất hiện trong lựa chọn bảng dữ liệu của Blockload() của plugin.tsxmainDS.addCollection()Collections
Dịch văn bản của Pluginlocale/zh-CN.json + locale/en-US.jsonI18n

Server: Tôi muốn làm gì → Viết như thế nào

Tôi muốn làm gìViết trong tệp nàoGọi API gìTài liệu
Định nghĩa một bảng dữ liệuserver/collections/xxx.tsdefineCollection()Collections
Mở rộng bảng dữ liệu hiện cóserver/collections/xxx.tsextendCollection()Collections
Đăng ký interface tùy chỉnhload() của server/plugin.tsthis.app.resourceManager.define()ResourceManager
Cấu hình quyền interfaceload() của server/plugin.tsthis.app.acl.allow()ACL
Ghi dữ liệu khởi tạo khi cài Plugininstall() của server/plugin.tsthis.db.getRepository().create()Plugin

Bảng tra cứu FlowModel

Tôi muốn làm gìKế thừa lớp cơ sở nàoAPI quan trọng
Tạo một Block hiển thị thuầnBlockModelrenderComponent() + define()
Tạo một Block gắn bảng dữ liệu (render tùy chỉnh)CollectionBlockModelcreateResource() + renderComponent()
Tạo một Block bảng đầy đủ (tùy chỉnh trên cơ sở bảng tích hợp)TableBlockModelfilterCollection() + customModelClasses
Tạo một component hiển thị FieldClickableFieldModelrenderComponent(value) + bindModelToInterface()
Tạo một nút ActionActionModelstatic scene + registerFlow({ on: 'click' })

Bảng tra cứu phương thức dịch

Ngữ cảnhDùng gìImport từ đâu
Trong load() của Pluginthis.t('key')Lớp cơ sở Plugin có sẵn
Trong component Reactconst t = useT(); t('key')locale.ts
Định nghĩa tĩnh FlowModel (define(), registerFlow())tExpr('key')locale.ts

Bảng tra cứu gọi API phổ biến

Tôi muốn làm gìTrong PluginTrong component
Gửi API requestthis.context.api.request()ctx.api.request()
Lấy bản dịchthis.t()useT()
Lấy loggerthis.context.loggerctx.logger
Đăng ký routethis.router.add()
Điều hướng trangctx.router.navigate()
Mở dialogctx.viewer.dialog()

Liên kết liên quan