### Starting Local Debug Server Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Provides the bash command to start the local debug server for the plugin. This server allows accessing the plugin's API views and potentially a debug panel via a web browser, enabling interactive testing and debugging. Requires the plugin environment and database to be set up. ```bash python bin/manage.py rundebugserver ``` -------------------------------- ### Installing Plugin Dependencies Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Provides bash commands to check and upgrade the `pip` package manager and then install the plugin's required Python dependencies listed in `requirements.txt`. This is a standard step for setting up the development environment. Requires `pip` and a `requirements.txt` file. ```bash # 请务必确保 pip 版本大于 21.0.0 pip --version # 如果 pip 版本过旧,请升级 pip 版本 pip install --upgrade pip pip install -r requirements.txt ``` -------------------------------- ### Starting Celery Worker for Debugging Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Provides the bash command to start a Celery worker process required for plugins that use asynchronous tasks like `wait_poll` or `wait_callback`. It sets necessary environment variables and runs the Celery worker command with specific arguments. Requires Celery and a message broker (like RabbitMQ or Redis) to be installed and configured. ```bash DJANGO_SETTINGS_MODULE=bk_plugin_runtime.settings BK_APP_CONFIG_PATH=bk_plugin_runtime.config celery worker -A blueapps.core.celery -P threads -Q plugin_schedule -l DEBUG ``` -------------------------------- ### Creating First Plugin Project with Cookiecutter (Shell) Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Installs the cookiecutter tool and uses it to generate a new plugin project based on the bk-plugin-framework-python template. This is the initial step to set up a new plugin development environment. ```shell pip install cookiecutter cookiecutter https://github.com/TencentBlueKing/bk-plugin-framework-python/ --directory template ``` -------------------------------- ### Input Model Field Definition Examples (Python) Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Provides examples of defining different types of fields within an `InputsModel`. It shows how to declare required fields using type hints and optional fields with default values or using the `Field` function for more detailed configuration. ```python class Inputs(InputsModel): int_field: int # int 类型必填 str_field: str # str 类型必填 no_required_field: dict = {"a": 1} # dict 类型非必填,默认值为 {"a": 1} detail_field: bool = Field(default=True, description="字段详细说明") # bool 类型非必填,默认值为 True ``` -------------------------------- ### Defining Form Data Interface API in Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Demonstrates how to create a data interface API endpoint for frontend forms by defining a class that inherits from `PluginAPIView`. This example shows a `get` method that returns a list of items suitable for a dropdown or similar form component. ```python # task_list.py from rest_framework.response import Response from bk_plugin_framework.kit.api import PluginAPIView class TaskList(PluginAPIView): def get(self, request, biz_id): return Response( [{"text": "task 1", "value": 1}, {"text": "task 2", "value": 2}] ) ``` -------------------------------- ### Initializing Plugin Database Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Provides the bash command to run Django database migrations. This command initializes or updates the database schema required by the plugin framework and the plugin itself. This must be run after setting up the database connection. Requires a Python environment with Django and the plugin dependencies installed. ```bash python bin/manage.py migrate ``` -------------------------------- ### Querying CMDB Business List in Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Defines a `PluginAPIView` subclass `BusinessList` with a GET method. It demonstrates making a POST request to the BK-ESB CMDB API to fetch a list of businesses the user has permission for, using `requests` and environment variables for authentication. Requires `os`, `requests`, `rest_framework.response.Response`, and `bk_plugin_framework.kit.api.PluginAPIView`. ```python import os import requests from rest_framework.response import Response from bk_plugin_framework.kit.api import PluginAPIView class BusinessList(PluginAPIView): def get(self, request): response = requests.post( url="http://{esb_host}/api/c/compapi/v2/cc/search_business/", headers={ "Content-Type": "application/json", "X-Bkapi-Authorization": self.get_bkapi_authorization_info(request), }, json={ "bk_app_code": os.getenv("APP_ID"), "bk_app_secret": os.getenv("APP_TOKEN"), "bk_username": request.user.username, }, ) json_data = response.json() return Response([{"text": b["bk_biz_name"], "value": b["bk_biz_id"]} for b in json_data["data"]["info"]]) ``` -------------------------------- ### Defining TaskList API View in Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Defines a `PluginAPIView` subclass `TaskList` with a GET method. It demonstrates making requests to hypothetical APIGW and ESB endpoints using the `requests` library and returning a sample JSON response. Requires `requests`, `rest_framework.response.Response`, and `bk_plugin_framework.kit.api.PluginAPIView`. ```python import requests from rest_framework.response import Response from bk_plugin_framework.kit.api import PluginAPIView class TaskList(PluginAPIView): def get(self, request, biz_id): # apigw 请求 apigw_url = "" header = { "Content-Type": "application/json", "X-Bkapi-Authorization": self.get_bkapi_authorization_info(request) } response = requests.get(url=apigw_url, headers=header) # esb 请求 esb_url = "" header = { "Content-Type": "application/json", "X-Bkapi-Authorization": self.get_bkapi_authorization_info(request) } response = requests.get(url=esb_url, headers=header) return Response( [{"text": "task 1", "value": 1}, {"text": "task 2", "value": 2}] ) ``` -------------------------------- ### Overriding Plugin Initialization in bk-plugin-framework Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Demonstrates how to override the `__init__` method of a plugin class to perform custom initialization tasks, such as loading configuration from environment variables. It is crucial to call the parent class's `__init__` method using `super().__init__()` to ensure proper framework setup. ```python import os from bk_plugin_framework.kit import Plugin class SopsExecPlugin(Plugin): ... def __init__(self): super().__init__() # 从环境变量中获取调用标准运维 API 所需的 APP_CODE 与 APP_SECRET self.app_code = os.getenv("BKSOPS_API_APP_CODE") self.app_secret = os.getenv("BKSOPS_API_APP_SECRET") ... ``` -------------------------------- ### Getting Invocation Count in Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Shows how to access `context.invoke_count` to determine the number of times the `execute` method has been called for the current plugin invocation. This can be useful for tracking retries or progress. ```python def execute(self, inputs: Inputs, context: Context): logger.info("%s times execute" % context.invoke_count) ``` -------------------------------- ### Defining Form Input Tag in JavaScript Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Shows an example of defining a single input tag within the form definition array in `form.js`. It specifies the tag type, attributes like name and hookable, and the `tag_code` which links the form field to a plugin input. ```javascript (function () { $.atoms["{{your plugin app code}}"] = [ { "type": "input", "attrs": { "name": "模板ID", "hookable": true, }, "tag_code": "template_id" } ] })(); ``` -------------------------------- ### Listening to Tag Component Change Event in JavaScript Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/docs/tags.md Demonstrates how to configure a standard plugin form item to listen for events from another Tag component. The example shows how the 'biz_input' component listens for the 'change' event from the 'biz_info' component and updates its own value based on the 'biz_info' component's value. ```javascript tag_code: 'biz_input', type: 'input', attrs: { name: 'some label' }, events: [ { source: "biz_info", type: "change", action: function () { const bizInfo = this.get_parent().get_child('biz_info') const value = bizInfo._get_value() this.updateForm(value) } } ] ``` -------------------------------- ### Setting Core Debug Environment Variables Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Provides bash commands to set essential environment variables required for local debugging of the plugin. These variables include application credentials, configuration path, broker URL, engine region, and login URL. These must be configured before running the debug server. ```bash export BKPAAS_APP_ID="" # 插件 app code,从 paas 开发者中心获取 export BKPAAS_APP_SECRET="" # 插件 app secret paas 开发者中心获取 export BK_APP_CONFIG_PATH="bk_plugin_runtime.config" export BK_PLUGIN_RUNTIME_BROKER_URL="amqp://guest:guest@localhost:5672//" # broker url,如果插件没有 wait_poll 或 wait_callback 操作可以不设置该变量 export BKPAAS_ENGINE_REGION="open" export BKPAAS_LOGIN_URL="BK PaaS 登陆 URL" ``` -------------------------------- ### Defining Plugin Settings from Environment Variables Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Defines a configuration setting `TEST_ENV` by reading its value from an environment variable using `os.getenv`. This allows plugin behavior to be customized based on the deployment environment. Requires the `os` module. ```py import os # 从环境变量中获取配置项 TEST_ENV = os.getenv("TEST_ENV", "test") ``` -------------------------------- ### Setting Plugin Outputs in Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Explains how to define the structure of the plugin's output data using an `OutputsModel` and set the actual output values in the `context.outputs` dictionary. Data stored in `context.outputs` must be JSON serializable. ```python class Outputs(OutputsModel): task_id: int = Field(title="标准运维任务 ID", description="") task_url: str = Field(title="标准运维任务 URL", description="") def execute(self, inputs: Inputs, context: Context): context.outputs["task_id"] = 123 context.outputs["task_url"] = "xxx" ``` -------------------------------- ### Defining Plugin Outputs Model (Python) Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Illustrates how to define the output model for a plugin using an inner `Outputs` class inheriting from `OutputsModel`. This class declares the expected output fields, their types, and optional titles or descriptions using `Field`. ```python from bk_plugin_framework.kit import Plugin, OutputsModel, Field class SopsExecPlugin(Plugin): ... class Outputs(OutputsModel): task_id: int = Field(title="标准运维任务 ID", description="") task_url: str = Field(title="标准运维任务 URL", description="") ... ``` -------------------------------- ### Setting MySQL Debug Environment Variables Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Provides bash commands to set environment variables specifically for configuring the plugin to use a local MySQL database during debugging. These variables specify the database user, password, host, and port. These are optional if using SQLite. ```bash export BK_PLUGIN_DEV_USE_MYSQL="1" # 本地使用mysql数据库 export BK_PLUGIN_RUNTIME_DB_USER="" # 本地 DB 用户名 export BK_PLUGIN_RUNTIME_DB_PWD="" # 本地 DB 密码 export BK_PLUGIN_RUNTIME_DB_HOST="localhost" # 本地 DB 域名 export BK_PLUGIN_RUNTIME_DB_PORT="3306" # 本地 DB 端口 ``` -------------------------------- ### Running Python Tests via manage.py Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/runtime/bk-plugin-runtime/bk_plugin_runtime/packages/open/blueking/tests/README.md These commands execute specific test suites within the blueking.tests package using Django's manage.py command. The --keepdb flag ensures that the test database is preserved between runs, which can speed up subsequent test executions. ```Shell python manage.py test --keepdb blueking.tests.test_client python manage.py test --keepdb blueking.tests.test_shortcuts python manage.py test --keepdb blueking.tests.test_utils ``` -------------------------------- ### Defining API Routes in Django URLs Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Defines URL patterns for the plugin's API views using Django's `path`. It maps the `/task_list/` URL to the `TaskList` view, allowing it to be accessed via HTTP requests. Requires `django.urls.path` and the defined API view module (`task_list`). ```py # urls.py from django.urls import path from . import task_list urlpatterns = [ path(r"task_list/", task_list.TaskList.as_view()), ] ``` -------------------------------- ### Defining a Basic Plugin Class (Python) Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Shows the basic structure for defining a plugin class in the bk-plugin-framework. All custom plugins must inherit from the `Plugin` base class provided by the framework kit. ```python from bk_plugin_framework.kit import Plugin class SopsExecPlugin(Plugin): pass ``` -------------------------------- ### Defining Plugin Context Inputs Model (Python) Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Shows how to define the context input model for a plugin using an inner `ContextInputs` class inheriting from `ContextRequire`. This model declares fields provided by the execution environment, not directly by the plugin user. ```python from bk_plugin_framework.kit import Plugin, ContextRequire, Field class SopsExecPlugin(Plugin): ... class ContextInputs(ContextRequire): biz_cc_id: int = Field(title="业务 cc id", description="业务在 cmdb 中的 id") executor: str = Field(title="任务执行人") ... ``` -------------------------------- ### Implementing Callback Logic in bk-plugin-framework Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Demonstrates how to use `self.wait_callback()` to pause execution and wait for an external system to trigger a callback. The `context.state` becomes `State.CALLBACK` upon receiving a callback. `self.prepare_callback(context)` generates a unique URL and ID for the callback. `context.callback.id` and `context.callback.data` provide details about the received callback, allowing the plugin to process the result and potentially wait for further callbacks or complete. ```python def execute(self, inputs: Inputs, context: Context): if context.state is State.EMPTY: # 生成回调的所需的url和标识回调唯一性的id pre_callback = self.prepare_callback(context) # 暂存回调id,用于回调到来之时,处理job回调的相关逻辑 context.storage["job_callback_id"] = pre_callback.id job_kwargs = { "bk_biz_id": 1, "ip_list": [], # 传入回调url "bk_callback": pre_callback.url, } client.job.fast_execute_script(job_kwargs) # 此时context.state由引擎负责调整变为State.CALLBACK self.wait_callback() if context.state is State.CALLBACK: # 如果回调id是执行job任务的回调id,则处理一些相应逻辑 if context.callback.id == context.storage["job_callback_id"]: do_something(context.callback.data) return # 任务执行成功,本次调用成功 # 如果有其他回调,也可以处理其相应逻辑 else: do_else_something(context.callback.data) # 处理完成之后,可以选择继续回调,还是return 插件执行完成 self.wait_callback() ``` -------------------------------- ### Defining Plugin Metadata with Meta Class (Python) Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Illustrates how to define plugin-level metadata using an inner `Meta` class within the plugin class. The `version` attribute is mandatory and must follow semantic versioning. ```python from bk_plugin_framework.kit import Plugin class SopsExecPlugin(Plugin): class Meta: version = "1.0.0" ``` -------------------------------- ### Defining Plugin Inputs Model (Python) Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Demonstrates how to define the input model for a plugin using an inner `Inputs` class inheriting from `InputsModel`. This class declares the expected input fields, their types, and optional default values or descriptions using `Field`. ```python from bk_plugin_framework.kit import Plugin, InputsModel, Field class SopsExecPlugin(Plugin): ... class Inputs(InputsModel): template_id: int task_name: str constants: dict = Field(default={}, description="任务全局变量") ... ``` -------------------------------- ### Enabling Plugin Callback in bk-plugin-framework Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Configures a plugin to support callbacks from the consuming system. This involves setting `enable_plugin_callback = True` in the `Meta` class and adding a `plugin_callback_info` field of type `PluginCallbackModel` to the `ContextInputs` class to receive callback details. ```python from bk_plugin_framework.kit import Plugin, ContextRequire, Field from bk_plugin_framework.kit.plugin import PluginCallbackModel class SopsExecPlugin(Plugin): ... class Meta: ... enable_plugin_callback = True ... class ContextInputs(ContextRequire): ... plugin_callback_info: PluginCallbackModel = Field(title="任务回调信息") ... ... ``` -------------------------------- ### Accessing Plugin Settings in Plugin Logic Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Demonstrates how to access configuration settings defined in `settings.py` within the plugin's execution logic. It uses `django.conf.settings` to retrieve the `TEST_ENV` value and assigns it to the plugin's output context. Requires `django.conf.settings`. ```py from django.conf import settings class MyPlugin(Plugin): ... def execute(self, inputs: Inputs, context: Context): context.outputs["env"] = settings.TEST_ENV ``` -------------------------------- ### Using Temporary Storage in Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Describes how to use `context.storage`, a dictionary, to store temporary data that needs to persist between different states (`EMPTY`, `POLL`, `CALLBACK`) of a plugin invocation. Data stored here must be JSON serializable. ```python def execute(self, inputs: Inputs, context: Context): if context.state is State.EMPTY: context.storage["task_id"] = 123 elif context.state is State.POLL: task_id = context.storage["task_id"] ``` -------------------------------- ### Project Dependencies - Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/bk-plugin-framework/dev-requirements.txt Specifies the required Python packages and their version constraints for the project, including core dependencies, services, runtime, testing, and code checking tools. ```Python werkzeug>=2.0.0,<3.0.0 pydantic>1.0,<2.0 jsonschema>=2.5.0,<5.0 # services Django>=2.2,<3.0 djangorestframework==3.12.4 drf-yasg==1.20.0 apigw-manager==0.1.8 # runtime celery==3.1.25 # test pytest==6.2.4 tox==3.24.0 tox-pyenv==1.1.0 coverage==5.5 pytest-django==4.4.0 # code check flake8 black ``` -------------------------------- ### Defining Plugin Frontend Form Structure in JavaScript Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Provides the basic JavaScript structure required for defining a plugin's frontend form within the `form.js` file. The form definition is registered under `$.atoms` using the plugin's app code. ```javascript (function () { $.atoms["{{your plugin app code}}"] = [ ... ] })(); ``` -------------------------------- ### Defining and Accessing Nested Input Models (Python) Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Shows how to define nested input models by including an `InputsModel` subclass as a field within another `InputsModel`. It also demonstrates how to access fields within the nested model from the plugin's `execute` method. ```python class Inputs(InputsModel): class Options(InputsModel): name: str value: str action: str options: Options def execute(self, inputs: InputsModel, context: ContextRequire): option_name = inputs.options.name option_value = inputs.options.value ``` -------------------------------- ### Checking Execution State in Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Explains how to check the current state of the plugin execution using `context.state`. The state can be `EMPTY`, `POLL`, or `CALLBACK`, allowing the plugin's `execute` method to implement state-specific logic. ```python def execute(self, inputs: Inputs, context: Context): if context.state is State.EMPTY: # create task pass elif context.state is State.POLL: # poll task pass ``` -------------------------------- ### Accessing Context Data in Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Describes how to access context inputs defined in the plugin's ContextInputs model via the `context.data` object. The framework ensures the validity and existence of these fields at runtime. This snippet shows accessing specific fields like `biz_cc_id` and `executor`. ```python class ContextInputs(ContextRequire): biz_cc_id: int = Field(title="业务 cc id", description="业务在 cmdb 中的 id") executor: str = Field(title="任务执行人") def execute(self, inputs: Inputs, context: Context): bk_biz_id = context.data.biz_cc_id executor = context.data.executor ``` -------------------------------- ### Accessing Plugin Inputs in bk-plugin-framework Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Shows how to define and access input parameters for a plugin using an `Inputs` class inheriting from `InputsModel`. Input fields are defined as class attributes with type hints. The framework ensures the validity and presence of these fields, allowing direct access via `inputs.field_name` within the `execute` method. ```python class SopsExecPlugin(Plugin): ... class Inputs(InputsModel): template_id: int task_name: str constants: dict = Field(default={}, description="任务全局变量") def execute(self, inputs: Inputs, context: Context): template_id = inputs.template_id task_name = inputs.task_name constants = inputs.constants ... ``` -------------------------------- ### Specify bk-plugin-framework Dependency (Python) Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/template/{{cookiecutter.project_name}}/requirements.txt Specifies the required version of the `bk-plugin-framework` package for the project. This package is listed under the 'base' section, indicating it is a core dependency. ```Python bk-plugin-framework==2.2.9 ``` -------------------------------- ### Implementing Polling Logic in bk-plugin-framework Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Illustrates how to use `self.wait_poll(interval)` to pause execution and be rescheduled after a specified interval. The `context.state` is used to track the current phase (EMPTY or POLL), and `context.storage` allows passing data between polling cycles. The plugin can check the status of an external task and either succeed, fail, or continue polling. ```python def execute(self, inputs: Inputs, context: Context): if context.state is State.EMPTY: context.storage["task_id"] = create_task() # 在这里调用self.wait_poll()进入调度状态 # 此时context.state由引擎负责调整变为State.POLL self.wait_poll(5) if context.state is State.POLL: state = get_task_state(context.storage["task_id"]) if state == "SUCCESS": return # 任务执行成功,本次调用成功 elif state == "FAIL": raise self.Error("task fail") # 任务执行失败,本次调用失败 elif state == "RUNNING": self.wait_poll(5) # 五秒后再次执行 ``` -------------------------------- ### Specify celery-prometheus-exporter Dependency (Python) Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/template/{{cookiecutter.project_name}}/requirements.txt Specifies the required version of the `celery-prometheus-exporter` package. This package is listed under the 'opentelemetry' section, suggesting its use for monitoring or tracing integration. ```Python celery-prometheus-exporter==1.7.0 ``` -------------------------------- ### Restricting Plugin Usage Scope in bk-plugin-framework Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Defines a dictionary `allow_scope` in `meta.py` to restrict plugin execution to specific consuming systems (`app_code`) and their associated business scopes (`type`, `value`). Requests from systems or scopes not listed will receive a 403 error. Requires consuming system support for `Bkplugin-Scope-Type` and `Bkplugin-Scope-Value` headers. ```python allow_scope = { "[插件使用系统的app_code]": { "type": "[业务概念的类型值,如 project]", # str "value": ["1", "2"] # List[str] } } ``` -------------------------------- ### Accessing Trace ID in bk-plugin-framework Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Illustrates how to access the unique `trace_id` associated with a plugin execution context via `context.trace_id`. This ID remains constant throughout a single execution call and is useful for logging and tracing purposes. ```python def execute(self, inputs: Inputs, context: Context): logger.info("[%s] execute" % context.trace_id) ``` -------------------------------- ### Raising Execution Error in bk-plugin-framework Python Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/README.md Shows how to signal a failure during plugin execution by raising `self.Error`. This causes the plugin task to enter a failed state. The error message provided will be associated with the failure. ```python def execute(self, inputs: Inputs, context: Context): success = False if not success: raise self.Error("error message") ``` -------------------------------- ### Form Item Validation Configuration - JavaScript Source: https://github.com/tencentblueking/bk-plugin-framework-python/blob/master/docs/tags.md Defines the structure for the 'validation' property of a form item. It supports 'required', 'regex', and 'custom' validation types. The 'custom' type requires an 'args' function that returns an object indicating the validation result and an optional error message. ```JavaScript { // ... validation: [ { type: 'required' }, { type: 'regex', args: RegExp, //例如 /\d{3}/ error_message: String //例如 '请输入3个数字' }, { type: 'custom', args (value, parentValue) { //... return { // 校验方法必须返回如下格式对象 result: Boolean, error_message: String } } }, ] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.