CN117251160A - Code generation method, device, electronic equipment and storage medium - Google Patents

Code generation method, device, electronic equipment and storage medium Download PDF

Info

Publication number
CN117251160A
CN117251160A CN202311219717.0A CN202311219717A CN117251160A CN 117251160 A CN117251160 A CN 117251160A CN 202311219717 A CN202311219717 A CN 202311219717A CN 117251160 A CN117251160 A CN 117251160A
Authority
CN
China
Prior art keywords
description
content
item
description item
code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311219717.0A
Other languages
Chinese (zh)
Inventor
张飞宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Du Xiaoman Technology Beijing Co Ltd
Original Assignee
Du Xiaoman Technology Beijing Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Du Xiaoman Technology Beijing Co Ltd filed Critical Du Xiaoman Technology Beijing Co Ltd
Priority to CN202311219717.0A priority Critical patent/CN117251160A/en
Publication of CN117251160A publication Critical patent/CN117251160A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/38Creation or generation of source code for implementing user interfaces
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/34Graphical or visual programming
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Stored Programmes (AREA)

Abstract

The invention provides a code generation method, a device, electronic equipment and a storage medium, wherein the method comprises the following steps: acquiring description data of a target interface, wherein the description data comprises component descriptions and interface descriptions, one component description or one interface description comprises a plurality of description items, one description item comprises a description item identification and description item content, at least one description item content comprises a content identification and a description value, and the description value corresponds to the content identification; respectively calling a template generator to generate a template code, calling a script generator to generate a script code, and calling a style generator to generate a style code, wherein one generator analyzes description item identifiers, description item contents, content identifiers and description values related to the description item identifiers, the description item contents, the content identifiers and the description values in the description data, and converts the description item identifiers, the description item contents, the content identifiers and the description values related to the description data into corresponding codes; integrating to obtain the code of the target interface. The invention can produce template codes, script codes and style codes to obtain more complete codes.

Description

Code generation method, device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of internet front-end technologies, and in particular, to a code generation method, a code generation device, an electronic device, and a storage medium.
Background
Automatic generation of code is one of the important functions in the front-end low-code. With the richness of the front-end interface display and interaction, the development work of the front-end becomes more complex. To free front-end developers, front-end low-code techniques have evolved. The low code technology is a technology for rapidly designing and developing software applications, and can rapidly provide reliable codes for technicians. By using visual modeling to assemble and configure the application in the graphical interface, a developer can skip all the infrastructures to increase the development speed, so that the development efficiency is improved by writing little or no code by the developer. The existing low-code platform focuses on the structural design of the whole interface, only supports template codes and script codes, cannot produce style codes, and the produced codes are not complete enough.
Disclosure of Invention
In view of this, the embodiments of the present invention provide a code generation method, apparatus, electronic device, and storage medium, which can generate template codes, script codes, and style codes to obtain more complete codes.
According to an aspect of the present invention, there is provided a code generation method including: acquiring description data of a target interface, wherein the description data comprises component descriptions and interface descriptions, one component description or one interface description comprises a plurality of description items, one description item comprises a description item identifier and description item content, at least one description item content comprises a content identifier and a description value, and the description value corresponds to the content identifier;
Respectively calling a template generator to generate a template code, calling a script generator to generate a script code, and calling a style generator to generate a style code, wherein one generator analyzes the description item identification, the description item content, the content identification and the description value related to the description data, and converts the description item identification, the description item content, the content identification and the description value related to the description data into corresponding codes;
and integrating the template code, the script code and the style code to obtain the code of the target interface.
Preferably, the component description includes a component event description item for describing a set of events in a component;
the template generator analyzes description item identifiers, description item contents, content identifiers and description values related to the description items in the event description items of the components and converts the description item identifiers, the description item contents, the content identifiers and the description values into corresponding codes;
the script generator analyzes description item identification, description item content, content identification and description value related to the description item in the event description item and converts the description item identification, the description item content, the content identification and the description value into corresponding codes.
Preferably, the interface description includes a lifecycle description item for describing different lifecycles of the interface;
The script generator analyzes the description item identification, the description item content, the content identification and the description value of the life cycle description item and converts the description item identification, the description item content, the content identification and the description value into corresponding codes.
Preferably, the component description includes a component style description item for describing a style set of the component; the interface description comprises an interface style description item, wherein the interface style description item is used for describing a style set of an interface;
the style generator parses the component style description item and the description item identification, description item content, content identification and description value of the interface style description item and converts the component style description item and the interface style description item into corresponding codes.
Preferably, the description item content of the component event description item comprises component event function content identification; component event function fields in the description data are all arranged in the component event function content identification;
the component description also comprises a component attribute description item, and the description item content of the component attribute description item comprises a component attribute function content identifier; and component attribute function fields in the description data are all arranged in the component attribute function content identification.
Preferably, the description item content of the life cycle description item comprises life cycle function content identification; the life cycle function fields in the description data are all arranged in the life cycle function content identification;
The interface description also comprises an interface attribute description item, and the description item content of the interface attribute description item comprises an interface attribute function content identifier; and interface attribute function fields in the description data are all arranged in the interface attribute function content identifier.
Preferably, the calling the template generator to generate the template code, the calling the script generator to generate the script code, and the calling the style generator to generate the style code respectively include:
and acquiring version parameters, respectively calling a template generator to generate template codes corresponding to the version parameters, calling a script generator to generate script codes corresponding to the version parameters, and calling a style generator to generate style codes.
According to another aspect of the present invention, there is provided a code generating apparatus including:
the data acquisition module is used for acquiring description data of a target interface, wherein the description data comprises component descriptions and interface descriptions, one component description or one interface description comprises a plurality of description items, one description item comprises a description item identifier and description item content, at least one description item content comprises a content identifier and a description value, and the description value corresponds to the content identifier;
The compiling module is used for respectively calling the template generator to generate template codes, calling the script generator to generate script codes and calling the style generator to generate style codes, wherein one generator analyzes description item identifiers, description item contents, content identifiers and description values related to the description data and converts the description item identifiers, the description item contents, the content identifiers and the description values related to the description data into corresponding codes;
and the code integration module is used for integrating the template code, the script code and the style code to obtain the code of the target interface.
According to another aspect of the present invention, there is provided an electronic apparatus including:
a processor; and
a memory in which a program is stored,
wherein the program comprises instructions which, when executed by the processor, cause the processor to perform the method described above.
According to another aspect of the present invention, there is provided a non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform the above-described method.
The embodiment of the application provides a code generation method, a code generation device, electronic equipment and a storage medium, corresponding template codes, script codes and style codes can be generated by analyzing the configuration mode of a target interface, and the generated codes are more complete.
Drawings
Further details, features and advantages of the invention are disclosed in the following description of exemplary embodiments with reference to the following drawings, in which:
FIG. 1 shows a flow diagram of a code generation method according to an exemplary embodiment of the invention;
fig. 2 shows a schematic diagram of data acquired by TemplateGenerator, scriptGenerator, styleGenerator according to an exemplary embodiment of the invention;
FIG. 3 illustrates another flow diagram of a code generation method according to an exemplary embodiment of the present invention;
FIG. 4 shows a schematic block diagram of a code generating apparatus according to an exemplary embodiment of the present invention;
fig. 5 shows a block diagram of an exemplary electronic device that can be used to implement an embodiment of the invention.
Detailed Description
Embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While the invention is susceptible of embodiment in the drawings, it is to be understood that the invention may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided to provide a more thorough and complete understanding of the invention. It should be understood that the drawings and embodiments of the invention are for illustration purposes only and are not intended to limit the scope of the present invention.
It should be understood that the various steps recited in the method embodiments of the present invention may be performed in a different order and/or performed in parallel. Furthermore, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the invention is not limited in this respect.
The term "including" and variations thereof as used herein are intended to be open-ended, i.e., including, but not limited to. The term "based on" is based at least in part on. The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments. Related definitions of other terms will be given in the description below. It should be noted that the terms "first," "second," and the like herein are merely used for distinguishing between different devices, modules, or units and not for limiting the order or interdependence of the functions performed by such devices, modules, or units.
It should be noted that references to "one", "a plurality" and "a plurality" in this disclosure are intended to be illustrative rather than limiting, and those skilled in the art will appreciate that "one or more" is intended to be construed as "one or more" unless the context clearly indicates otherwise.
The names of messages or information interacted between the devices in the embodiments of the present invention are for illustrative purposes only and are not intended to limit the scope of such messages or information.
The following describes an aspect of the present invention with reference to the accompanying drawings, and as shown in fig. 1, an exemplary embodiment of the present invention provides a code generating method, including the steps of:
s1, acquiring description data of a target interface, wherein the description data comprises component description and interface description. Wherein, a component description or an interface description comprises a plurality of description items, a description item comprises a description item identification and description item content, at least one description item content comprises a content identification and a description value, and the description value corresponds to the content identification;
s2, respectively calling a template generator to generate template codes, calling a script generator to generate script codes, and calling a style generator to generate style codes. The method comprises the steps that a generator analyzes description item identifiers, description item contents, content identifiers and description values related to the description item identifiers, the description item contents, the content identifiers and the description values in the description data, and converts the description item identifiers, the description item contents, the content identifiers and the description values related to the description item identifiers, the content identifiers and the description values into corresponding codes;
and S3, integrating the template code, the script code and the style code to obtain the code of the target interface.
The interface is composed of static UI and dynamic events, the UI of one interface includes a plurality of components, and the events of one interface include the events of the components and the events of the interface. In the exemplary embodiment of the invention, the description data of the target interface comprises component description and interface description, so that the composition content of one interface can be accurately described.
In the exemplary embodiment of the invention, the description data of the target interface is acquired, and template codes, script codes and style codes are respectively generated by the description data through a template generator, a script generator and a style generator, so that the generated codes are more complete. The developer can use through the form of duplicate code or export code file at last, has improved work efficiency.
In some embodiments, the method for obtaining the description data of the target interface includes:
and generating a target interface through the low-code platform, and generating description data of the target interface.
In other embodiments, the method for acquiring the description data of the target interface includes:
and manually generating the description data of the target interface according to the requirements of the description data specification.
As one embodiment, the description of the assembly includes:
wherein, the explanation of the component description is as follows:
document: the demonstration examples of the components are mainly used for embedding demonstration addresses of the components in a low-code platform;
source: a source of the component;
type: types, used to distinguish between components or interfaces;
name: chinese name of the component;
tagName: a tag name of the component;
tagIcon: a presentation icon of the component in the low code platform;
desc: a simple description of the components;
layout: a layout mode;
className: configuring class names of the styles;
slot: the slot set of a component is a description of the sub-component. The description of the sub-assembly is consistent with the description of the assembly;
style: a style set of components;
extra: an extended attribute of the component;
event: an event set of components, since there are multiple events for one component, this field is in the form of a group, comprising:
(1) name: the Chinese name of the event;
(2) callbackFunc: a function body of events;
(3) functionName: invoking a function name of the event;
(4) desc: description of the event;
tips: attributes of the component. Since there may be multiple attributes for a component, this field is in the form of an array. For one field, there is mainly the following description:
(1) name: chinese name of the attribute;
(2) key: english names of attributes;
(3) type: the types of attributes, enumerated values are: number, string, boolean, function, object, array;
(4) value: the value of the attribute;
(5) default: default values for the attributes.
The description of the interface includes:
wherein, the explanation of the interface description is as follows:
type: a description labeled interface;
desc: a simple description of the interface;
title: the name of this interface;
import: the dependence required to construct this interface;
attr: the key attribute in the interface code is an object, has higher expansibility, and mainly comprises: data: the interface needs to be set as a responsive field;
watch: monitoring;
computer-aided: calculating attributes;
tips: values from parent components;
methods of: an interaction event of the interface;
life cycle: the different life cycles of the interface mainly comprise:
(1) A creation stage;
(2) A mounting stage;
(3) An updating stage;
(4) A destroying stage;
style: a style set of the interface;
component: a set of all components of the component interface, the content being a description of all components;
extra: extending the attributes.
In yet other embodiments, the component description includes a component event description item that is used to describe a collection of events in the component. The template generator analyzes the description item identification, the description item content, the content identification and the description value related to the event description item in the component event description item and converts the description item identification, the description item content, the content identification and the description value into corresponding codes. The script generator analyzes the description item identification, the description item content, the content identification and the description value related to the description item in the event description item and converts the description item identification, the description item content, the content identification and the description value into corresponding codes.
As one embodiment, the component event description item includes a description item identifier event and description item content, where the description item content of the component event description item includes a content identifier funcnonname and a corresponding description value, a content identifier name and a corresponding description value, and a content identifier callbackFunc and a corresponding description value.
The template generator analyzes the description item identification event, the content identification functionName and the corresponding description value, the content identification name and the corresponding description value and converts the description item identification event, the content identification functionName and the corresponding description value into corresponding codes. The script generator analyzes the description item identification event, the content identification funcname and the corresponding description value, the content identification, the callbackFunc and the corresponding description value and converts the description item identification event, the content identification funcname and the corresponding description value into corresponding codes.
In yet other embodiments, the interface description includes a lifecycle description item that describes different lifecycles of the interface. The script generator parses the description item identification, description item content, content identification, description value of the lifecycle description item and converts into corresponding codes.
As one implementation, the life cycle description item comprises a description item identification life cycle and corresponding description item content, and the script generator analyzes the description item identification life cycle and the corresponding description item content and converts the description item identification life cycle and the corresponding description item content into corresponding codes.
In still other embodiments, the component description includes a component style description item for describing a style set of the component. The interface description includes an interface style description item for describing a style set of the interface. The style generator parses the description item identification, the description item content, the content identification and the description value of the component style description item and the interface style description item and converts the component style description item and the interface style description item into corresponding codes.
As one implementation, the component style description item comprises a description item identification style and corresponding description item content in the component description, and the interface style description item comprises a description item identification style and corresponding description item content in the interface description. The style generator parses the description item identification style and the corresponding description item content in the component description, and the description item identification style and the corresponding description item content in the interface description and converts the description item identification style and the corresponding description item content into corresponding codes.
When the prior art converts the interface into the code, only the structural design of the whole interface is concerned, and the configuration of events, life cycles and patterns is lacked, so that the prior art only supports template codes and script codes and can not produce codes related to the events, life cycles and patterns.
In the exemplary embodiment of the invention, the component description comprises a component event description item and a component style description item, the interface description comprises a life cycle description item and an interface style description item, and the data of the event, the life cycle and the style can be acquired and compiled into corresponding template codes, script codes and style codes to obtain a complete interface code. The description data of the exemplary embodiment of the invention is more complete and standard, is easy to be understood by research and development personnel, and can meet various service scenes and technical requirements.
In still other embodiments, the description item content of the component event description item includes a component event function content identifier, and component event function fields in the description data are each provided in the component event function content identifier.
As one embodiment, the component event function content identification includes callbackFunc, and the like. In this embodiment, the component event function fields are all set in the component event function content identifier, and when the code is generated, all the component event function fields can be obtained by obtaining the component event function content identifier.
In still other embodiments, the component description further includes a component attribute description item, and description item content of the component attribute description item includes a component attribute function content identifier, and component attribute function fields in the description data are all set in the component attribute function content identifier.
In this embodiment, the component attribute function fields are all set in the component attribute function content identifier, and when the code is generated, all the component attribute function fields can be obtained by obtaining the component attribute function content identifier.
In still other embodiments, the description item content of the lifecycle description item includes a lifecycle function content identification, and the lifecycle function fields in the description data are all disposed in the lifecycle function content identification.
As one implementation, the lifecycle function content identification includes created, mounted, etc. In this embodiment, the life cycle function fields are all set in the life cycle function content identifier, and when the code is generated, all the life cycle function fields can be obtained by obtaining the life cycle function content identifier.
In still other embodiments, the interface description further includes an interface attribute description item, and the description item content of the interface attribute description item includes an interface attribute function content identifier, and the interface attribute function fields in the description data are all set in the interface attribute function content identifier.
In this embodiment, the interface attribute function fields are all set in the interface attribute function content identifier, and when the code is generated, all the interface attribute function fields can be obtained by obtaining the interface attribute function content identifier.
The UI of one interface includes a plurality of components, and the event of one interface includes an event of a component and an event of an interface. The existing specification of descriptive data is convenient, and does not split the self-attribute of the component and the attribute needed for interaction between components, and cannot distinguish which attributes should be assigned to the components when generating code. Some special logic needs to be added when generating code.
In the exemplary embodiment of the present invention, based on the idea that the descriptions of the same type are concentrated together, component event function fields are all set in component event function content identifiers, component attribute function fields are all set in component attribute function content identifiers, lifecycle function fields are all set in lifecycle function content identifiers, and interface attribute function fields are all set in interface attribute function content identifiers, component event, component attribute, lifecycle and interface attribute are maintained separately, and the generator can obtain component event function fields, component attribute function fields, lifecycle function fields and interface attribute function fields by cycling through the component event function content identifiers, the component attribute function content identifiers, the lifecycle function content identifiers and the interface attribute function content identifiers, respectively, without adding special logic, thereby improving the working efficiency.
In some implementations, the component description further includes a component name description item, a component style name description item, and a sub-component description item of the component.
As one embodiment, the component name description item includes a component name description item identification tagName, the component style name description item includes a component style name description item identification className, and the sub-component description item of the component includes a sub-component description item identification slot of the component.
In this embodiment, the description data may obtain all information in the target interface, that is, all information including the interface itself and all the included components at the same time, so as to obtain a more complete code of the target interface.
In still other embodiments, respectively invoking the template generator to generate the template code, invoking the script generator to generate the script code, and invoking the style generator to generate the style code, comprises:
and acquiring the version parameters, respectively calling a template generator to generate template codes corresponding to the version parameters, calling a script generator to generate script codes corresponding to the version parameters, and calling a style generator to generate style codes.
As one embodiment, obtaining the version parameter, calling the template generator to generate the template code corresponding to the version parameter includes:
Acquiring description item identifiers, description item contents, content identifiers and description values related to the description items in the description data by using a template generator;
obtaining version parameters;
the data acquired by the Templete generator is compiled into template codes corresponding to the version parameters by using Templete render.
As another embodiment, obtaining the version parameter, calling the script generator to generate the script code corresponding to the version parameter includes:
acquiring description item identifiers, description item contents, content identifiers and description values related to the description items in the description data by using a script generator;
obtaining version parameters;
the script generator is used to compile the data acquired by the script generator into script codes corresponding to the version parameters.
As yet another embodiment, invoking the style generator to generate the style code includes:
acquiring description item identifiers, description item contents, content identifiers and description values related to the description items in the description data by using a Style generator;
the data acquired by the Style generator is compiled into style code using a LessStyle Render.
As another embodiment, as shown in fig. 2 and 3, the code generator vue-code-generator includes a template generator, a script generator, a style generator, and other generators. vue-code-generator receives the description data, and the template generator circularly traverses the content identifier name and the corresponding description value of the component event description item, the content identifier functionName and the corresponding description value of the component event description item, the component name description item identifier tagName and the corresponding description item content, the component attribute description item identifier tips and the corresponding description item content, the component style name description item identifier className and the corresponding description item content, the sub-component description item identifier slot and the corresponding description item content of the component, and generates a template code corresponding to the version parameter by using the template renderer after the version parameter is acquired.
As an example, as shown in table 1, the template generator compiles the component name description item identifier tagName and the corresponding description item content, the component style name description item identifier className and the corresponding description item content, the component attribute description item identifier tips and the corresponding description item content, and the sub-component description item identifier slot and the corresponding description item content in the component description into the corresponding code.
TABLE 1
The script generator circularly traverses the content identifier functionName and the corresponding description value of the component event description item, the content identifier callbackFunc and the corresponding description value of the component event description item, the life cycle description item identifier life cycle and the corresponding description item content, the content identifier data and the corresponding description value of the interface attribute description item, the content identifier watch and the corresponding description value of the interface attribute description item, the content identifier calculated and the corresponding description value of the interface attribute description item, the content identifier tips and the corresponding description value of the interface attribute description item, the content identifier methods and the corresponding description value of the interface attribute description item, and generates script codes corresponding to the version parameters by using the script Render after the version parameters are acquired.
And after the description item identification style and the corresponding description item content in the Style generator circulation traversing component description and the description item identification style and the corresponding description item content in the interface description, generating a corresponding style code by using the LessStyleRender.
The interface description also includes an interface dependency description item, which includes a description item identification import and corresponding description item content in the interface description. The OtherGenerator loops through description item identification imports and corresponding description item contents in the interface description, and corresponding codes are generated by utilizing the dependencylrender.
In this embodiment, through the combined action of TemplateGenerator, scriptGenerator, styleGenerator, otherGenerator, the code segments of different portions are finally produced, all the code segments are combined together, the code aggregate of the target interface is generated, and the developer can use the code through copying the code or exporting the code file, so that the working efficiency is improved.
In still other embodiments, the version parameters include parameters corresponding to a Vue2 frame, parameters corresponding to a Vue3 frame, parameters corresponding to a React frame, and the like.
As one implementation mode, when the target interface adopts the Vue1 frame, the parameters corresponding to the Vue1 frame can be selected to generate the code of the Vue 1; when the target interface adopts a Vue2 frame, selecting parameters corresponding to the Vue2 frame, and generating a code of the Vue 2; when the target interface adopts a Vue3 frame, selecting parameters corresponding to the Vue3 frame, and generating a code of the Vue 3; when the target interface adopts a compact frame, parameters corresponding to the compact frame can be selected to generate a compact code.
As another embodiment, the generator comprises a Vue 1-to-Vue 2 generation unit, a Vue 1-to-Vue 3 generation unit, a Vue 1-to-reaction generation unit, a Vue 2-to-Vue 1 generation unit, a Vue 2-to-Vue 3 generation unit, a Vue 2-to-reaction generation unit, a Vue 3-to-Vue 1 generation unit, a Vue 3-to-Vue 2 generation unit, a Vue 3-to-reaction generation unit, a reaction-to-Vue 1 generation unit, a reaction-to-Vue 2 generation unit and a reaction-to-Vue 3 generation unit.
Wherein the Vue 1-to-Vue 2 generating unit is used for compiling the target interface of the Vue1 frame to generate a Vue2 code, the Vue 1-to-Vue 3 generating unit is used for compiling the target interface of the Vue1 frame to generate a Vue3 code, the Vue 1-to-real generating unit is used for compiling the target interface of the Vue1 frame to generate a real code, the Vue 2-to-Vue 1 generating unit is used for compiling the target interface of the Vue2 frame to generate a Vue1 code, the Vue 2-to-Vue 3 generating unit is used for compiling the target interface of the Vue2 frame to generate a Vue3 code, the Vue 2-to-real generating unit is used for compiling the target interface of the Vue2 frame to generate a real code, the method comprises the steps that a Vue 3-to-Vue 1 generating unit is used for compiling a target interface of a Vue3 frame to generate a Vue1 code, a Vue 3-to-Vue 2 generating unit is used for compiling a target interface of the Vue3 frame to generate a Vue2 code, a Vue 3-to-real generating unit is used for compiling a target interface of the Vue3 frame to generate a real code, a real-to-Vue 1 generating unit is used for compiling a target interface of the real frame to generate a Vue1 code, a real-to-Vue 2 generating unit is used for compiling a target interface of the real frame to generate a Vue2 code, and a real-to-Vue 3 generating unit is used for compiling a target interface of the real frame to generate a Vue3 code.
As yet another embodiment, the generator includes a code version conversion module for inter-version conversion of code. The code version conversion module comprises a Vue1-Vue2 conversion unit, a Vue1-Vue3 conversion unit, a Vue 1-reaction conversion unit, a Vue2-Vue3 conversion unit, a Vue 2-reaction conversion unit and a Vue 3-reaction conversion unit.
The Vue1-Vue2 conversion unit is used for mutually converting the Vue1 code and the Vue2 code, the Vue1-Vue3 conversion unit is used for mutually converting the Vue1 code and the Vue3 code, the Vue 1-reaction conversion unit is used for mutually converting the Vue1 code and the reaction code, the Vue2-Vue3 conversion unit is used for mutually converting the Vue2 code and the Vue3 code, the Vue 2-reaction conversion unit is used for mutually converting the Vue2 code and the reaction code, and the Vue 3-reaction conversion unit is used for mutually converting the Vue3 code and the reaction code.
The method comprises the steps of obtaining version parameters, respectively calling a template generator to generate template codes corresponding to the version parameters, calling a script generator to generate script codes corresponding to the version parameters, and calling a style generator to generate style codes, and further comprises the following steps:
and acquiring the version parameters, judging whether the version parameters are the same as the version of the target interface, if not, calling a code version conversion module to convert the original codes after generating the original codes which are the same as the version of the target interface, and obtaining codes corresponding to the version parameters.
As an example, the target interface is a Vue2 frame, the obtained version parameter is Vue1, and if the version parameter is different from the version of the target interface, the original code of the Vue2 version is generated first, and the Vue1-Vue2 conversion unit is called to convert the original code of the Vue2 version, so as to obtain the code of Vue 1.
The implementation mode is not limited to the frame version of the target interface, codes corresponding to the version parameters can be generated, and flexibility is improved. In other embodiments, version parameters corresponding to other front end frameworks may also be selected, which is not limited herein.
In the prior art, the automatic generation logic of the code is only used as a functional module of a low-code platform and can be coupled with other modules in the system, and the files of changes involved in each optimization upgrading are more. In the embodiment of the application, the code generating function is regarded as an independent module, and is isolated from other low-code services such as rendering, configuration and the like by functional logic. Meanwhile, different code type generators, such as a template generator, a script generator, a style generator and the like, are distinguished, and code readability and subsequent maintainability are improved.
In the prior art, the code output function is used as a functional module of the low code platform, needs to be highly bound with the low code platform, and cannot be used as an independent service. In the embodiment of the application, the code output function is used as a single service, and the low code platform is not required to be completely relied on.
The exemplary embodiment of the present invention also provides a code generating apparatus 1100, as shown in fig. 4, including:
a data obtaining module 1101, configured to obtain description data of a target interface, where the description data includes a component description and an interface description, and one component description or one interface description includes a plurality of description items, one description item includes a description item identifier and a description item content, and at least one description item content includes a content identifier and a description value, where the description value corresponds to the content identifier;
the compiling module 1102 is configured to call the template generator to generate template codes, call the script generator to generate script codes, and call the style generator to generate style codes, where one generator analyzes description item identifiers, description item contents, content identifiers and description values related to the description item identifiers, description item contents, content identifiers and description values in the description data, and convert the description item identifiers, the description item contents, the content identifiers and the description values related to the description data into corresponding codes;
the code integrating module 1103 is configured to integrate the template code, the script code, and the style code to obtain a code of the target interface.
In some implementations, the component description includes a component event description item that describes a collection of events in the component;
The template generator analyzes the description item identification, the description item content, the content identification and the description value related to the description item in the event description item of the component and converts the description item identification, the description item content, the content identification and the description value into corresponding codes;
the script generator analyzes the description item identification, the description item content, the content identification and the description value related to the description item in the event description item and converts the description item identification, the description item content, the content identification and the description value into corresponding codes.
In other embodiments, the interface description includes a lifecycle description item for describing different lifecycles of the interface;
the script generator parses the description item identification, description item content, content identification, description value of the lifecycle description item and converts into corresponding codes.
In yet other implementations, the component description includes a component style description item that describes a style set of the component; the interface description comprises an interface style description item, wherein the interface style description item is used for describing a style set of the interface;
the style generator parses the description item identification, the description item content, the content identification and the description value of the component style description item and the interface style description item and converts the component style description item and the interface style description item into corresponding codes.
In still other embodiments, the description item content of the component event description item includes a component event function content identification; component event function fields in the description data are all arranged in component event function content identifiers;
The component description also comprises a component attribute description item, and the description item content of the component attribute description item comprises a component attribute function content identifier; component attribute function fields in the description data are all set in component attribute function content identifiers.
In still other embodiments, the description item content of the lifecycle description item includes a lifecycle function content identification; the life cycle function fields in the description data are all arranged in the life cycle function content identification;
the interface description also comprises an interface attribute description item, and the description item content of the interface attribute description item comprises an interface attribute function content identifier; interface attribute function fields in the description data are all arranged in the interface attribute function content identifier.
In still other embodiments, respectively invoking the template generator to generate the template code, invoking the script generator to generate the script code, and invoking the style generator to generate the style code, comprises:
and acquiring the version parameters, respectively calling a template generator to generate template codes corresponding to the version parameters, calling a script generator to generate script codes corresponding to the version parameters, and calling a style generator to generate style codes.
The exemplary embodiment of the invention also provides an electronic device, including: at least one processor; and a memory communicatively coupled to the at least one processor. The memory stores a computer program executable by the at least one processor for causing the electronic device to perform a method according to an embodiment of the invention when executed by the at least one processor.
The exemplary embodiments of the present invention also provide a non-transitory computer readable storage medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is for causing the computer to perform a method according to an embodiment of the present invention.
The exemplary embodiments of the invention also provide a computer program product comprising a computer program, wherein the computer program, when being executed by a processor of a computer, is for causing the computer to perform a method according to an embodiment of the invention.
With reference to fig. 5, a block diagram of an electronic device 1200 that may be a server or a client of the present invention will now be described, which is an example of a hardware device that may be applied to aspects of the present invention. Electronic devices are intended to represent various forms of digital electronic computer devices, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular telephones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the inventions described and/or claimed herein.
As shown in fig. 5, the electronic device 1200 includes a computing unit 1201 that can perform various appropriate actions and processes according to a computer program stored in a Read Only Memory (ROM) 1202 or a computer program loaded from a storage unit 1208 into a Random Access Memory (RAM) 1203. In the RAM 1203, various programs and data required for the operation of the electronic device 1200 may also be stored. The computing unit 1201, the ROM 1202, and the RAM 1203 are connected to each other via a bus 1204. An input/output (I/O) interface 1205 is also connected to the bus 1204.
Various components in the electronic device 1200 are connected to the I/O interface 1205, including: an input unit 1206, an output unit 1207, a storage unit 1208, and a communication unit 1209. The input unit 1206 may be any type of device capable of inputting information to the electronic device 1200, and the input unit 1206 may receive input numeric or character information and generate key signal inputs related to user settings and/or function controls of the electronic device. The output unit 1207 may be any type of device capable of presenting information, and may include, but is not limited to, a display, speakers, video/audio output terminals, vibrators, and/or printers. Storage unit 1208 may include, but is not limited to, magnetic disks, optical disks. The communication unit 1209 allows the electronic device 1200 to exchange information/data with other devices over computer networks, such as the internet, and/or various telecommunications networks, and may include, but is not limited to, modems, network cards, infrared communication devices, wireless communication transceivers and/or chipsets, such as bluetooth (TM) devices, wiFi devices, wiMax devices, cellular communication devices, and/or the like.
The computing unit 1201 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of computing unit 1201 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital Signal Processors (DSPs), and any suitable processor, controller, microcontroller, etc. The computing unit 1201 performs the various methods and processes described above. For example, in some embodiments, the code generation method may be implemented as a computer software program tangibly embodied on a machine-readable medium, such as storage unit 1208. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 1200 via the ROM 1202 and/or the communication unit 1209. In some embodiments, the computing unit 1201 may be configured to perform the code generation method by any other suitable means (e.g., by means of firmware).
Program code for carrying out methods of the present invention may be written in any combination of one or more programming languages. These program code may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the program code, when executed by the processor or controller, causes the functions/operations specified in the flowchart and/or block diagram to be implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of the present invention, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and/or device (e.g., magnetic discs, optical disks, memory, programmable Logic Devices (PLDs)) used to provide machine instructions and/or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal used to provide machine instructions and/or data to a programmable processor.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and pointing device (e.g., a mouse or trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), and the internet.
The computer system may include a client and a server. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other.

Claims (10)

1. A code generation method, comprising:
acquiring description data of a target interface, wherein the description data comprises component descriptions and interface descriptions, one component description or one interface description comprises a plurality of description items, one description item comprises a description item identifier and description item content, at least one description item content comprises a content identifier and a description value, and the description value corresponds to the content identifier;
respectively calling a template generator to generate a template code, calling a script generator to generate a script code, and calling a style generator to generate a style code, wherein one generator analyzes the description item identification, the description item content, the content identification and the description value related to the description data, and converts the description item identification, the description item content, the content identification and the description value related to the description data into corresponding codes;
and integrating the template code, the script code and the style code to obtain the code of the target interface.
2. The code generation method according to claim 1, wherein the component description includes a component event description item for describing a set of events in a component;
the template generator analyzes description item identifiers, description item contents, content identifiers and description values related to the description items in the event description items of the components and converts the description item identifiers, the description item contents, the content identifiers and the description values into corresponding codes;
the script generator analyzes description item identification, description item content, content identification and description value related to the description item in the event description item and converts the description item identification, the description item content, the content identification and the description value into corresponding codes.
3. The code generation method of claim 1, wherein the interface description includes a lifecycle description item for describing different lifecycles of the interface;
the script generator analyzes the description item identification, the description item content, the content identification and the description value of the life cycle description item and converts the description item identification, the description item content, the content identification and the description value into corresponding codes.
4. The code generation method according to claim 1, wherein the component description includes a component style description item for describing a style set of a component; the interface description comprises an interface style description item, wherein the interface style description item is used for describing a style set of an interface;
The style generator parses the component style description item and the description item identification, description item content, content identification and description value of the interface style description item and converts the component style description item and the interface style description item into corresponding codes.
5. The code generation method of claim 2, wherein the description item content of the component event description item includes a component event function content identification; component event function fields in the description data are all arranged in the component event function content identification;
the component description also comprises a component attribute description item, and the description item content of the component attribute description item comprises a component attribute function content identifier; and component attribute function fields in the description data are all arranged in the component attribute function content identification.
6. A code generation method according to claim 3, wherein the description item content of the lifecycle description item comprises a lifecycle function content identification; the life cycle function fields in the description data are all arranged in the life cycle function content identification;
the interface description also comprises an interface attribute description item, and the description item content of the interface attribute description item comprises an interface attribute function content identifier; and interface attribute function fields in the description data are all arranged in the interface attribute function content identifier.
7. The code generation method according to any one of claims 1 to 6, wherein the respectively calling the template generator to generate the template code, the script generator to generate the script code, and the style generator to generate the style code, comprises:
and acquiring version parameters, respectively calling a template generator to generate template codes corresponding to the version parameters, calling a script generator to generate script codes corresponding to the version parameters, and calling a style generator to generate style codes.
8. A code generating apparatus, comprising:
the data acquisition module is used for acquiring description data of a target interface, wherein the description data comprises component descriptions and interface descriptions, one component description or one interface description comprises a plurality of description items, one description item comprises a description item identifier and description item content, at least one description item content comprises a content identifier and a description value, and the description value corresponds to the content identifier;
the compiling module is used for respectively calling the template generator to generate template codes, calling the script generator to generate script codes and calling the style generator to generate style codes, wherein one generator analyzes description item identifiers, description item contents, content identifiers and description values related to the description data and converts the description item identifiers, the description item contents, the content identifiers and the description values related to the description data into corresponding codes;
And the code integration module is used for integrating the template code, the script code and the style code to obtain the code of the target interface.
9. An electronic device, comprising:
a processor; and
a memory in which a program is stored,
wherein the program comprises instructions which, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 7.
10. A non-transitory computer readable storage medium storing computer instructions, wherein the computer instructions are for causing a computer to perform the method of any one of claims 1 to 7.
CN202311219717.0A 2023-09-20 2023-09-20 Code generation method, device, electronic equipment and storage medium Pending CN117251160A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311219717.0A CN117251160A (en) 2023-09-20 2023-09-20 Code generation method, device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311219717.0A CN117251160A (en) 2023-09-20 2023-09-20 Code generation method, device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117251160A true CN117251160A (en) 2023-12-19

Family

ID=89136335

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311219717.0A Pending CN117251160A (en) 2023-09-20 2023-09-20 Code generation method, device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117251160A (en)

Similar Documents

Publication Publication Date Title
US8490050B2 (en) Automatic generation of user interfaces
US9021440B1 (en) System and method for automated test script generation
US8312417B2 (en) Using dynamic call graphs for creating state machines
CN113010181B (en) Deployment method and device of operators in deep learning framework and electronic equipment
JP5396979B2 (en) Software development support device, system, software development support device function expansion method, and program
CN111694564B (en) Method, device, equipment and medium for compiling Flutter mixed mode
US9965257B2 (en) Automatic configuration of project system from project capabilities
WO2013018204A1 (en) Image processing software development method, image processing software development apparatus, and image processing software development program
CN112506854B (en) Page template file storage and page generation methods, devices, equipment and media
US20210117313A1 (en) Language agnostic automation scripting tool
CN112947914A (en) Code generation method and device based on model, computer equipment and medium
CN111309317A (en) Code automation method and device for realizing data visualization
CN114217789A (en) Function component expansion method, device, equipment, storage medium and program product
CN111159301A (en) Data creating method, device, equipment and storage medium based on intelligent contract
US7900191B1 (en) System and method of using an active link in a state programming environment to locate an element in a graphical programming environment
CN110018831B (en) Program processing method, program processing apparatus, and computer-readable storage medium
CN114721647B (en) Object-oriented programming method based on codeless application development
CN117251160A (en) Code generation method, device, electronic equipment and storage medium
CN114174983B (en) Method and system for optimized automatic verification of advanced constructs
CN114661274A (en) Method and device for generating intelligent contract
CN114296718A (en) Setting method and device of Windows system component
CN113342399A (en) Application structure configuration method and device and readable storage medium
CN113885841A (en) Script generation method and device, electronic equipment and readable medium
JP2013235508A (en) Object-oriented program generation device, method therefor, and program
CN111831317A (en) Method and device for acquiring dependency relationship between services, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination