Avue Form Design

repository·master·Indexed 23 days ago

https://github.com/sscfaith/avue-form-design

A drag-and-drop form builder based on Avue that allows developers to construct complex forms and export configurations as JSON. It requires element-ui (2.13.2+) and @smallwei/avue (2.6.16+). The tool provides a visual editor with customizable toolbars, local storage support, and utility methods like getData() to retrieve form configurations in JSON or string formats.

Tokens
1.8K
Snippets
2
Records
12
Agent score
77%

What's inside @sscfaith/avue-form-design

  1. Install @sscfaith/avue-form-design

    master

    You can install the component via npm or yarn.

    Prerequisites This project requires the following dependencies:

    • element-ui (version 2.13.2+)
    • @smallwei/avue (version 2.6.16+)
    $ npm i element-ui
    $ npm i @smallwei/avue
    $ npm i @sscfaith/avue-form-design

    Or using yarn:

    $ yarn add @sscfaith/avue-form-design
    $ npm i @sscfaith/avue-form-design
  2. Integrate AvueFormDesign into Vue

    master

    To use the form designer, first register the component in your Vue application, then use the <avue-form-design> component in your templates.

    Registration

    import AvueFormDesign from '@sscfaith/avue-form-design'
    
    Vue.use(AvueFormDesign)

    Basic Usage

    <avue-form-design 
      style="height: 86vh;"
      :options="options"
      storage
      @submit="handleSubmit">
    </avue-form-design>
  3. How Avue options and Designer options relate

    master

    The designer uses an internal representation of the form to allow for easy editing (e.g., handling dicOption as static or remote). To use the designer with an existing Avue project, you must convert between the two formats:

    1. Avue $\rightarrow$ Designer: Use transAvueOptionsToFormDesigner(obj). This converts Avue's dicUrl, dicMethod, and group structures into the designer's editable format.
    2. Designer $\rightarrow$ Avue: Use transformToAvueOptions(obj). This converts the designer's internal state back into a valid Avue option object that can be passed to an <avue-form> component.

    When using the preview feature, transformToAvueOptions is called with isPreview = true, which performs additional transformations to ensure event handlers (like change or blur) work correctly within the preview iframe.

  4. Configure the options field

    master

    The options prop follows the Avue configuration schema. Use these keys to control the generated form's appearance and behavior:

    PropertyDescriptionTypeOptions/Default
    columnAvue field definitionsArray[]
    labelPositionPosition of the labelString'left', 'center', 'right'
    labelWidthWidth of the labelNumber-
    gutterSpacing between fieldsNumber0
    menuBtnShow menu buttonsBooleantrue
    submitBtnShow submit buttonBooleantrue
    submitTextText for the submit buttonString'提交'
    emptyBtnShow clear buttonBooleantrue
    emptyTextText for the clear buttonString'清空'
    tabsConvert multiple groups into tabsBooleanfalse
    detailDetail modeBooleanfalse
    readonlyGlobal read-only modeBooleanfalse
    disabledGlobal disabled modeBooleanfalse
  5. Install Avue Form Design as a Vue plugin

    master

    To use avue-form-design in your Vue project, install the package and use the Vue.use() method. This registers the Config plugin, registers the main component globally, and attaches utility methods to the Vue prototype.

    Upon installation, the main component is registered globally with the name Avue followed by the component's internal name (typically AvueFormDesign).

    Utility methods attached to Vue.prototype:

    • getAsVal: A utility for retrieving values.
    • avueVersion: Returns the current Avue version.
  6. Handle avue-form-design events and methods

    master

    Events

    EventDescriptionPayload
    submitCallback when the JSON configuration is generatedThe current configuration JSON

    Methods

    MethodParametersReturns
    getDatatype: 'string' or 'json'Promise (returns the current editor JSON)
  7. Configure JSON generation settings

    master

    When generating JSON via the UI, you can customize the output format using the configOption object:

    • generateType: 'json' or 'string'.
    • space: Indentation length (1 to 4 spaces).
    • quoteType: 'single' or 'double'.
    • dropQuotesOnKeys: Boolean to remove quotes from object keys.
    • dropQuotesOnNumbers: Boolean to remove quotes from numeric strings.
  8. Configure avue-form-design props

    master

    The <avue-form-design> component accepts several props to control its layout and behavior:

    PropDescriptionTypeDefault
    optionsField configurationObject/String{ column: [] }
    storageEnable local storage to prevent JSON loss on browser refreshBooleanfalse
    asideLeftWidthWidth of the left toolbarString/Number'270px'
    asideRightWidthWidth of the right toolbarString/Number'380px'
    showGithubStarWhether to show GitHub StarBooleantrue
    toolbarTop toolbar configurationArray['avue-doc', 'import', 'generate', 'preview', 'clear']
    undoRedoEnable undo/redo functionalityBooleantrue
    includeFieldsFields displayed on the left side (configured in fieldsConfig.js)Array-
    customFieldsCustom componentsArray-
  9. Configure the FormDesign component

    master

    The FormDesign component is the main entry point for the visual form designer. It allows users to drag and drop fields, configure field and form properties, and export the resulting configuration as JSON or a string.

    Props

    PropTypeDefaultDescription
    optionsObject or String{ column: [] }The initial Avue configuration. If a string is provided, it is parsed into an object.
    storageBooleanfalseIf true, the designer will load/save state to local storage.
    asideLeftWidthString or Number'270px'Width of the left field selection panel.
    asideRightWidthString or Number'380px'Width of the right configuration panel.
    showGithubStarBooleantrueWhether to show the GitHub star button in the header.
    toolbarArray['import', 'generate', 'preview', 'clear']List of buttons to show in the toolbar.
    undoRedoBooleantrueEnables/disables undo/redo functionality (supports Ctrl+Z / Ctrl+Y).
    includeFieldsArray(All field types)A filter list of field types to display in the left panel.
    customFieldsArrayundefinedCustom field definitions to be displayed in the left panel.
    defaultValuesObjectundefinedDefault values for field properties.
  10. Export form configuration with getData()

    master

    Use the getData method to retrieve the current form configuration from the designer. You can specify the output format.

    Parameters

    • type: 'json' (default), 'string', or 'app'.
    • option: Configuration object for the beautifier (used when type is 'string').

    Return Values

    • If type is 'json': Returns a Promise resolving to the Avue options object.
    • If type is 'string': Returns a Promise resolving to a beautified string.
    • If type is 'app': Returns a Promise resolving to the Avue options object with functions parsed into strings (useful for backend storage).