基于vue3.0和element-plus的组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

2.2 KiB

Config API

plugs/api/config.ts - System configuration management.

Overview

System configuration API with list and update operations, plus single value retrieval.

Endpoint

  • Root: config

Exports

Function HTTP Description
list GET List config entries with filter
set PUT Update existing config entry
getValue GET Get config value by key

Functions

list

export const list = (example) => {
  return queryPage(root, example);
};
  • Uses: queryPage from base
  • URL: config
  • Parameters: example - Filter criteria (optional)
  • Returns: Paginated result

set

export const set = (config) => {
  return update(root, config);
};
  • Uses: update from base (PUT)
  • Parameters: config - Config object to update

getValue

export const getValue = (key) => {
  return new Promise((resolve, reject) => {
    get(root + '/' + key, null, true, true).then(
      (rsp: any) => {
        resolve(rsp);
      },
      (err) => {
        resolve(null);
      }
    );
  });
};
  • URL: config/{key}
  • Parameters: key - Configuration key
  • noMsg: true - Suppress success message
  • noLoading: true - Suppress loading indicator
  • Returns: null on error (not false or {})

Usage Example

import { config } from 'plugs/api';

// List all configs
const configs = await config.list();

// List filtered configs
const dbConfigs = await config.list({ category: 'database' });

// Update config
await config.set({ key: 'app.name', value: 'My App', id: 1 });

// Get single config value
const appName = await config.getValue('app.name');

Pattern Notes

  • No add function - configs are typically only updated, not created
  • getValue returns null on error (different from other APIs that return false)
  • getValue uses custom implementation instead of getById from base

Anti-Patterns

  1. Missing add function - Inconsistent with other CRUD APIs
  2. Custom getValue instead of getById - Could use base's getById with URL template