Bỏ qua, đến nội dung

Tham chiếu API

Endpoints

EndpointMethodMô tả
{collection}:templatePrintPOSTRender dữ liệu bản ghi vào template, trả file kết quả
printingTemplates:uploadPOSTUpload template mới
printingTemplates:downloadGETTải file template gốc
printingTemplates CRUDGET/POST/PUT/DELETEQuản trị metadata template (admin)

{collection}:templatePrint

Method: POST

Render dữ liệu bản ghi vào template Carbone, trả file kết quả.

Request body:

Tham sốKiểuBắt buộcMô tả
filterByTkstring/numberID bản ghi cần in
templateNamestringTên template sử dụng
blockNamestringKhôngTên block chứa action (xác định data context)
convertedToPDFbooleanKhôngChuyển đổi kết quả sang PDF

Response: Binary file stream (responseType: blob).

Luồng xử lý server:

  1. Đọc metadata template từ DB (printingTemplates).
  2. Đọc file template từ storage/print-templates/.
  3. Query dữ liệu bản ghi từ DB (kèm associations, attachments).
  4. Resolve hình ảnh từ attachment field.
  5. Tạo QR code (nếu template chứa QR placeholder).
  6. Gọi Carbone engine render data vào template.
  7. Trả binary file về client.

printingTemplates:upload

Method: POST

Upload file template mới. File được lưu vào storage/print-templates/.

printingTemplates:download

Method: GET

Tải file template gốc (file admin đã upload, chưa render dữ liệu).

Database schema

Bảng printingTemplates

CộtKiểuMô tả
namestringTên định danh template (unique)
titlestringTên hiển thị
collectionNamestringCollection mà template áp dụng
rootDataTypestringLoại dữ liệu gốc (single record / list)
dataSourcestringData source sử dụng
filenamestringTên file template trên filesystem
enabledbooleanTemplate có đang hoạt động

Carbone engine

Plugin sử dụng Carbone để render dữ liệu vào template:

Tính năngMô tả
Placeholder{d.field} — thay thế bằng giá trị field
Loop{d.items[i].field} — lặp qua mảng
Format{d.field:formatN(2)} — format số, ngày
Condition{d.field:ifEQ(value)}...{d.field:showEnd} — hiện/ẩn block
ImageNhúng hình ảnh từ attachment field
QR codeTự động tạo và nhúng QR code

ACL

QuyềnLoạiMô tả
ui.templatePrintSnippetCho phép truy cập UI template print
templatePrintActionCho phép user đã đăng nhập thực hiện in
On installStrategyTự động thêm vào admin + member role strategies