Frontend Development
The plugin frontend is mainly responsible for page rendering and interaction. It sends the data filled in by users back to the backend through interfaces for generating correct scripts.
This document introduces how to develop the frontend part of a plugin. The frontend plugin is built on Vue 2 + TypeScript and interacts with the main service through the @aubo/wcaps/lib/frontend SDK.
Core File Structure
A complete frontend plugin consists of the following components:
- Plugin entry (
src/index.ts) - defines the plugin export interface and registers all node components - Program node components (
src/programModules/xx.vue) - node UI executed in the program tree - Configuration node components (
src/installModules/xx.vue) - node UI for the plugin configuration page - Global components (
src/globalModules/xx.vue) - global logic components that persist across pages
After installing @aubo/wcaps, you can jump to the declarations directly in the IDE to view the methods, parameters and return types that are actually available in the target version.
Plugin Entry (src/index.ts)
The plugin entry is the only bundling entry point of the frontend and is responsible for registering all available node components with the main service.
Main Interfaces
programModules
- Purpose: Register the list of program node components
- Properties:
id: Unique node identifier, must be consistent with the plugin backendname: Node display namecomponent: Vue componenticon: List node iconactivatedIcon?: Node activated icon, supports multi-theme configurationorangeTheme?: Activated icon under the orange themeredTheme?: Activated icon under the red themeblueTheme?: Activated icon under the blue theme
deactivatedIcon?: Node deactivated iconneedParentData?: Whether parent node data is neededneedChildrenData?: Whether child node data is needed
- Usage: Nodes displayed and executed in the program tree
installModules
- Purpose: Register the list of configuration node components
- Properties:
id: Unique node identifiername: Node display nameicon: Node iconcomponent: Vue component
- Usage: Nodes displayed on the plugin configuration page
globalModules
- Purpose: Register the list of global components
- Properties:
id: Unique component identifiername: Component namecomponent: Vue component
- Usage: Persists after the plugin is loaded and can be used to listen to global state
install({ publicPath, name }): void
- Purpose: Initialization method called when the plugin is installed
- Parameters:
publicPath- the plugin's public resource pathname- the plugin name
- Usage: Executes plugin-level initialization logic, usually used to initialize
GlobalConfigandcallPluginFunc
unmount?(): void
- Purpose: Cleanup method called when the plugin is unloaded (optional)
- Usage: Performs resource release, listener removal and other cleanup work
Configuration Node Components (installModules/xx.vue)
Configuration nodes run on the plugin configuration page to display settings UI and interaction logic.
Features
- No fixed props, freely define internal component state
- Can call the main service capabilities and backend interfaces through the SDK
Program Node Components (programModules/xx.vue)
Program nodes run in the program tree and receive props data injected by the main service.
Received Props
nodeType: string
- Purpose: The node's type identifier
- Usage: Used to distinguish different types of program nodes
jsonData: object
- Purpose: The JSON configuration data saved by the node
- Usage: Reads the parameters saved by the node during configuration
programNode: object
- Purpose: The complete information of the program node
- Usage: Gets the node's context information in the program tree
parentNodeList: array
- Purpose: Parent node list
- Usage: Accesses the data of the parent node
childNodeList: array
- Purpose: Child node list
- Usage: Accesses the data of the child node
disabledBtnAll: boolean
- Purpose: Whether to disable all buttons
- Usage: Controls UI interaction based on the program running state
updateNode: function
- Purpose: Function to update node data
- Usage: Saves the modified data to the node
Development Points
- Receive data passed by the main service through
props - Persist changes through
updateNode - Styles are recommended to use
scopedto avoid affecting other plugins
Global Components (globalModules/xx.vue)
Global components persist as soon as the plugin is loaded and are not destroyed when pages switch.
Features
- The lifecycle is consistent with the plugin, from loading to unloading
- Suitable for listening to global state and executing cross-page logic
- Can render visible DOM, or only perform logic control
Development Points
- Be sure to clean up timers, listeners, etc. in
beforeDestroyto avoid memory leaks
Development Flow
- Create node components: Create new
.vuefiles under theprogramModules/,installModules/orglobalModules/directories - Implement component logic: Write templates, scripts and styles, and interact with the main service using the SDK
- Register components: Add the components to the corresponding module arrays in
index.ts - Configure icons: Place icon resources under the
src/assets/directory and import them viarequire() - Build the plugin: Run
npm run buildto producedist/frontend/plugin.umd.min.js
Key Notes
- Unique entry: The production build entry is fixed at
src/index.ts, do not modify it - External dependencies not bundled: Vue, Element UI, etc. are excluded through the
externalsconfiguration invue.config.jsand provided by the main program - Icon resources: It is recommended to import node icons via
require('./assets/icon/xxx.png'), which supports hot updates - Style isolation: It is recommended to add the
scopedattribute to all component styles to avoid affecting the main program or other plugins - Global component lifecycle: Global components must clean up listeners and timers in
beforeDestroy - SDK calls: Actions and RpcManager may not be available during local development preview (requires the main service host environment); they run normally in the production environment
- UI component library (aubo_design): The template has the
@aubo/aubo_designcomponent library built in; the main program automatically completes global registration at runtime, and plugins can use it directly. It is recommended to use it to keep a consistent visual style with the main program - Type declarations:
src/global.d.tsandsrc/vue.d.tsprovide the necessary module and instance property declarations
