EnvVariableInput

EnvVariableInput 是面向环境变量的输入组件。它只暴露 $env 命名空间,适合密钥、凭证和连接参数。

开启 password 后,非变量字面值会用 Antd Input.Password 遮盖;变量表达式仍然可以通过变量选择器编辑。

基本用法

import React from 'react';
import { Application, EnvVariableInput, Plugin } from '@nocobase/client-v2';
import { Form } from 'antd';

function DemoPage() {
  return (
    <Form
      layout="vertical"
      style={{ maxWidth: 420 }}
      initialValues={{ accessKeySecret: '{{ $env.ACCESS_KEY_SECRET }}' }}
    >
      <Form.Item name="accessKeySecret" label="Access Key Secret">
        <EnvVariableInput
          password
          placeholder="Input secret or select env variable"
        />
      </Form.Item>
    </Form>
  );
}

class DemoPlugin extends Plugin {
  async load() {
    this.flowEngine.context.defineProperty('$env', {
      value: { ACCESS_KEY_SECRET: 'secret' },
      meta: {
        title: 'Environment variables',
        type: 'object',
        properties: {
          ACCESS_KEY_SECRET: { title: 'ACCESS_KEY_SECRET', type: 'string' },
        },
      },
    });

    this.router.add('root', {
      path: '/',
      element: <DemoPage />,
    });
  }
}

const app = new Application({
  router: { type: 'memory', initialEntries: ['/'] },
  plugins: [DemoPlugin],
});

export default app.getRootComponent();
import { EnvVariableInput } from '@nocobase/client-v2';

<Form.Item name={['options', 'accessKeySecret']} label={t('Access Key Secret')}>
  <EnvVariableInput password />
</Form.Item>;

API

参数类型说明
valuestring当前值
onChange(value: string) => void值变化回调
addonBeforeReact.ReactNode前置内容
disabledboolean是否禁用
passwordboolean是否遮盖非变量字面值
placeholderstring占位文字

相关链接