Api

API 参考

NextJS Base 组件和函数的详细 API 文档


📚 API 目录

核心 API

组件 API

工具库 API


🔧 快速参考

wrapAction

import { wrapAction } from '@/lib/core/action-wrapper'

export const myAction = wrapAction(
  'sysMyAction',           // Action 名称
  async (params, ctx) => { // 处理函数
    // ctx: { userId, user, isAdmin }
    return { success: true, data: result }
  },
  { skipLog: false }       // 选项
)

createCrudActions

import { createCrudActions } from '@/lib/core/crud-helper'

export const {
  getList,
  getDetail,
  create,
  update,
  delete: del,
} = createCrudActions({
  modelName: 'post',
  fields: { creatable: [...], updatable: [...] },
  validation: { ... },
  hooks: { ... },
})

fieldsConfig

const fieldsConfig = [
  {
    key: 'name',
    title: '名称',
    type: 'text',
    table: { width: 200 },
    form: { required: true },
    search: { enabled: true, mode: 'like' },
  },
]

nb.pubfn

import nb from '@/lib/function'

// 时间处理
nb.pubfn.timeFormat(new Date(), 'yyyy-MM-dd')

// 数组操作
nb.pubfn.arrayUnique([1, 2, 2, 3])

// 对象操作
nb.pubfn.deepClone(obj)

// 验证
nb.pubfn.test('[email protected]','email')

nb.cache

import nb from '@/lib/nb' // 仅服务端

await nb.cache.set('demo:key', { foo: 'bar' }, 60)
const value = await nb.cache.get('demo:key')
await nb.cache.incr('demo:counter', 120)

支持 PostgreSQL(默认)与 Redis;可用 cacheManage 工厂按需创建实例,详见缓存文档。