Mini-program processing method, device, equipment and storage medium

By passing events and data in the applet, decoupling the running environment of applets and third-party components, and generating the entry files of applets to realize component reuse, it solves the problem of tight coupling between applets and operating environments and improves development Efficiency and ease of debugging.

CN112114890BActive Publication Date: 2024-12-03TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910538843.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-06-20
Publication Date
2024-12-03
Estimated Expiration
2039-08-14

AI Technical Summary

Technical Problem

The existing applets are tightly coupled with the operating environment, resulting in the inability to reuse applets and components in different projects, affecting development efficiency.

Method used

By creating instances of third-party components and passing events and data in the applet, the running environment of applets and third-party components is decoupled, and the entrance file of applets is generated to achieve component reuse.

Benefits of technology

It realizes the decoupling of the applet and third-party components, allowing the reuse of various third-party components in the applet, improving development efficiency and simplifying the debugging process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112114890B_ABST
    Figure CN112114890B_ABST
Patent Text Reader

Abstract

The present invention provides a method, device, equipment and storage medium for processing a mini-program; the method includes: running the mini-program in a client; creating an instance corresponding to the third-party component of the mini-program by calling an entry file constructed corresponding to the mini-program; obtaining an event corresponding to the third-party component in the mini-program, and passing the event to the instance of the third-party component through a sub-component; obtaining data generated by the instance of the third-party component corresponding to the event, and rendering the data through the rendering environment of the mini-program. Through the present invention, the processing of the third-party component in the operating environment of the third-party component can be converted into the operation of the sub-component, realizing the decoupling between the development framework of the mini-program and the third-party component, and then various third-party components can be reused in the mini-program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to electronic digital data processing technology, and in particular to a small program processing method, device, equipment and storage medium. Background Art

[0002] A Web Application, also known as an applet, is a program that can be downloaded over the Internet and run directly in a browser environment. Compared with a dedicated client, it saves the installation process and can flexibly expand and upgrade the client's functions.

[0003] The page of the mini program implements different functions by calling various components. The relevant technology provides a component development framework and a component operating environment to provide component calls to the page of the mini program to implement the corresponding functions of the components in the page.

[0004] Since the operating environment provided by related technologies is tightly coupled with the mini program, the mini program needs to be encapsulated as a whole with the operating environment in order to run normally. The mini program and its components cannot be reused in the development process of different projects, which affects development efficiency. Summary of the invention

[0005] The embodiments of the present invention provide a method, apparatus, device and storage medium for processing a mini-program, which can decouple the mini-program from the operating environment of a third-party component so as to flexibly run various third-party components in the mini-program.

[0006] The technical solution of the embodiment of the present invention is achieved as follows:

[0007] An embodiment of the present invention provides a method for processing a mini-program, including:

[0008] Run the applet in the client;

[0009] Creating an instance corresponding to the third-party component of the mini-program by calling an entry file constructed corresponding to the mini-program;

[0010] Obtaining an event corresponding to the third-party component in the mini-program, and transmitting the event to an instance of the third-party component through a sub-component of the mini-program;

[0011] The data generated by the instance of the third-party component corresponding to the event is obtained, and the data is rendered through the rendering environment of the mini program.

[0012] The embodiment of the present invention further provides a device for processing a small program, including:

[0013] A running unit, used to run the applet in the client;

[0014] A creation unit, configured to create an instance corresponding to a third-party component of the mini-program by calling an entry file constructed corresponding to the mini-program;

[0015] An acquisition unit, used for acquiring an event corresponding to the third-party component in the mini-program, and transmitting the event to an instance of the third-party component through a sub-component;

[0016] The rendering unit is used to obtain the data generated by the instance of the third-party component corresponding to the event, and render the data through the rendering environment of the mini program.

[0017] In the above scheme, the creation unit is also used to obtain the virtual node corresponding to the custom component by calling the entry file of the custom component of the mini program, and create an instance of the third-party component in the instance of the custom component according to the virtual node.

[0018] In the above scheme, the creation unit is further used to take the page of the mini-program as the parent component and the custom component as the child component, and create an instance of the child component in the instance of the parent component;

[0019] Passing an event to the parent component through the instance of the child component and the event interface of the applet, wherein the event carries a callback function;

[0020] Searching for a virtual node corresponding to the identifier of the child component through the instance of the parent component, and passing the data of the virtual node into the callback function;

[0021] Obtaining data of the virtual node from the callback function through the instance of the subcomponent;

[0022] And, based on the data of the virtual node, an instance of the third-party component is created in the instance of the custom component.

[0023] In the above solution, the rendering unit is further used to compare the data with the data used for the previous rendering of the rendering environment through the instance of the subcomponent, and pass the difference data obtained by comparison into the rendering environment for rendering.

[0024] In the above solution, the creation unit is further used to construct a reference relationship graph according to the reference relationship between the third-party component and the native component of the mini program;

[0025] The reference relationship graph is recursively parsed according to the reference scenario of the third-party component, and the entry file of the mini-program is generated according to the recursively parsed reference relationship.

[0026] In the above solution, the creation unit is also used to update the construction tool in the development project of the third-party component through the plug-in;

[0027] The syntax of the third-party component is parsed by the updated construction tool to obtain the syntactic reference relationship between the third-party component and the mini-program, the page of the mini-program, and the custom component of the mini-program.

[0028] In the above solution, the creation unit is further used to recursively parse the reference relationship in the reference relationship graph starting from the construction entry of the reference relationship graph;

[0029] When the reference scenario of the reference relationship is that the mini-program, the page of the mini-program, or the custom component of the mini-program references the third-party component, the following target files are generated:

[0030] The entry file of the applet, the entry file of the page of the applet, the entry file of the third-party component, the configuration file of the applet, the template file of the applet and the style sheet of the applet.

[0031] In the above scheme, the creation unit is also used to assign identifiers to the labels of the non-native components of the mini-program and the labels with time binding attributes in the template of the mini-program, and add event detection functions for the non-native components.

[0032] The embodiment of the present invention further provides a device for processing a small program, including:

[0033] A memory for storing executable instructions;

[0034] The processor is used to implement the processing method of the mini-program provided by the embodiment of the present invention when executing the executable instructions stored in the memory.

[0035] An embodiment of the present invention provides a storage medium storing executable instructions for causing a processor to execute the mini-program processing method provided by the embodiment of the present invention.

[0036] The embodiments of the present invention have the following beneficial effects:

[0037] By calling the entry file built by the corresponding mini-program to create an instance of the third-party component, and through the transmission of events and data between the sub-component and the third-party component, the processing of the third-party component in the running environment of the third-party component can be converted into the running of the sub-component, thereby realizing the decoupling between the mini-program and the development framework of the third-party component, and then various third-party components can be reused in the mini-program. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 This is a schematic diagram of the operating principle of the applet built by the mpvue project provided by the relevant technology;

[0039] Figure 2 It is a schematic diagram of a scenario 100 of building and running a mini-program provided by an embodiment of the present invention;

[0040] Figure 3 is a schematic diagram of the structure of a mini-program processing device 50 provided in an embodiment of the present invention;

[0041] Figure 4 It is an optional flowchart diagram of the mini-program processing method provided by an embodiment of the present invention;

[0042] Figure 5 is a schematic diagram of an optional reference relationship diagram provided by an embodiment of the present invention;

[0043] Figure 6 An optional schematic diagram of generating an entry file of a mini-program according to a reference relationship provided by an embodiment of the present invention;

[0044] Figure 7 It is an optional flowchart diagram of the mini-program processing method provided by an embodiment of the present invention;

[0045] Figure 8 It is a flowchart of creating an instance of a child component in an instance of a parent component and creating a Vue.js instance on the instance of the child component, provided by an embodiment of the present invention;

[0046] Fig. 9 A schematic diagram of data flow provided by an embodiment of the present invention;

[0047] Fig.10 A schematic diagram of a user interface of a mini-program processing method provided by an embodiment of the present invention;

[0048] Fig.11 A schematic diagram of the structure of a mini-program processing device 50 provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present invention. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present invention.

[0050] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it can be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which the present invention belongs. The terms used herein are only for the purpose of describing the embodiments of the present invention and are not intended to limit the present invention.

[0052] Before further describing the embodiments of the present invention in detail, the nouns and terms involved in the embodiments of the present invention are described. The nouns and terms involved in the embodiments of the present invention are subject to the following interpretations.

[0053] 1. Mini Program is a program developed based on a front-end language (such as JavaScript) to implement services in a Hyper Text Markup Language (HTML) page. It is downloaded by a client (such as a browser or any client with a built-in browser core) via a network (such as the Internet) and interpreted and executed in the client's browser environment, saving the steps of installation in the client. For example, in a social network client, you can download and run mini programs for various services such as ticket purchase and ride code.

[0054] 2. The operating environment is an engine used to interpret and execute code. For example, for the operating environment of a mini-program, it can be JavaScriptCore on the iOS platform or X5 JSCore on the Android platform.

[0055] 3. Rendering environment: a control used for view rendering. For example, for the rendering environment of a mini-program, it can be WKWebView on the iOS platform or X5 on the Android platform (based on the Chrome 53 / 57 kernel).

[0056] 4. Component is the functional module of the mini program's view, also known as the front-end component, including buttons, titles, tables, sidebars, content and footers on the page. Components include modular codes for easy reuse in different pages of the mini program.

[0057] 5. Third-party components: components developed for mini-programs based on a third-party development framework (such as the Vue development framework) and that can be used by mini-programs.

[0058] 6. Custom components are components that are defined and run in the running environment of the mini program and are used to implement the functions of third-party components.

[0059] 7. Building (Webpack) is the process of packaging the source files of the mini program into target files (such as JavaScript files) that can be recognized and run in the client browser environment.

[0060] 8. Reference relationship, also known as dependency relationship, is the syntactic reference or referenced relationship between components. The graphical representation of reference relationship is called reference relationship diagram or reference relationship diagram.

[0061] 9. Document Object Model (DOM) is a copy of the DOM node of the page recorded by JS object. When data needs to be rendered, the virtual DOM corresponding to the rendered data will be used to perform differential calculation with the real DOM to obtain the difference. The difference will be batch modified in the real DOM at one time to speed up the display refresh speed of the page.

[0062] 10. Template: The structure and style of the data to be rendered in the mini program. It is used to fill in different data and then render it in the rendering environment, so that the structure and style can be reused.

[0063] For example, the template of the mini-program page uses an extensible markup language (XML) file to describe the structure, and a cascading style sheet (CSS) file to describe the component style, which can be used to reuse the layout and style of the mini-program page, and the component template can be used to reuse the layout and style of the component.

[0064] The following first analyzes and explains the processing solutions for mini-programs provided by related technologies, including the construction solutions and operation solutions for mini-programs.

[0065] The Vue development framework provided by the related technology is a view development framework for mini-programs. It provides a running environment for components (since the components are implemented in the front-end scripting language JavaScript, they are also referred to as Vue.js components below), allowing components to be reused in the pages of mini-programs, and provides a Webpack tool that can build the source code of projects developed based on the Vue development framework into JavaScript files that run in a browser environment.

[0066] Various types of development frameworks have been derived from the Vue development framework, such as the mpvue development framework and the megalo development framework, which respectively implement the function of running Vue.js components in the mini-program environment. Its working principle is: the function of generating mini-program related files is added to the native construction process of the Vue framework, and the function of mini-program template reference is used, that is, the template of the Vue.js component is referenced in the mini-program page to implement the function of the Vue.js component.

[0067] During the construction phase, only the corresponding entry file is generated for the mini program page, and only the corresponding templates are generated for other Vue.js components to call the Vue.js components in the mini program page.

[0068] When the mini program is running, the instance of the Vue.js component runs in the Vue runtime environment, and in the mini program environment the Vue.js component exists in the form of a template reference.

[0069] When the Vue.js component renders, the Vue.js component reports the data it uses for rendering to the instance of the mini-program page to which the component belongs. The instance of the mini-program page then aggregates the data and sends it to the mini-program's rendering environment. In the mini-program's rendering environment, the data is sent down layer by layer between the mini-program's templates to the corresponding templates, and rendered using the templates filled with the corresponding data.

[0070] Take the mpvue project as an example, see Figure 1 , Figure 1 It is a schematic diagram of the operating principle of the mini program built by the mpvue project provided by related technologies. The mini program page calls two sub-components A and B (Vue.js component A and Vue.js component B) running in the Vue running environment, and sub-component B contains sub-component C (Vue.js component C); the corresponding templates in the mini program are: mini program template A, mini program template B and mini program template C.

[0071] When rendering the view of a Vue.js component, the instance of the Vue.js component reports the data used for rendering to the instance of the mini-program page to which it belongs. The instance of the mini-program page then aggregates the relevant rendering data and sends it to the rendering environment of the mini-program. The rendering environment of the mini-program takes out the data used for rendering the sub-component from the received data based on the logic in the sub-component's template (i.e., the structure and style of the data), and passes the data to the template of the sub-component (mini-program page template A, mini-program template B, and mini-program template C). The rendering environment performs rendering in combination with the template based on the filled data to implement view updates of the components in the page.

[0072] After analysis, the relevant technologies have the following problems:

[0073] 1. The rendering of mini program pages and mini program components depends on the mini program page to send rendering data, resulting in the generated mini program pages and components can only run in the Vue runtime environment, and cannot be introduced into other projects that do not use the Vue development framework for reuse, which greatly increases the development cost.

[0074] 2. In the build process, the target file of the mini program is output in the form of an additional resource file, which makes it impossible for the mini program file to be displayed in the reference relationship graph of the build tool, making it difficult to generate the mini program file based on the reference relationship graph.

[0075] 3. Use the template reference of the mini program to implement the functions of the Vue.js component in the page. Since the template is very different from the native code file of the mini program, it is difficult to debug and unpredictable exceptions may occur. For example, the template calling method requires the caller to explicitly specify the data used by the component and template when rendering. This also causes the mini program to encounter a situation where the list data cannot be accessed in certain scenarios during actual operation.

[0076] In response to the above-mentioned problems in the related technology, an embodiment of the present invention provides a method, apparatus, device and storage medium for processing a mini-program, which can achieve decoupling between the mini-program and the development framework of a third-party component, so that various third-party components can be reused in the mini-program. The following first describes an exemplary application scenario of the mini-program processing method provided by an embodiment of the present invention.

[0077] See also Figure 2 , Figure 2 This is a schematic diagram of a scenario 100 for building and running a mini-program provided by an embodiment of the present invention. The developer of the mini-program deploys a development framework of the mini-program (for example, a Vue development framework) on a development device 200 (for example, a user terminal such as a computer, or a server) to complete the project development for the mini-program. The mini-program can be used to implement services provided by various service providers, such as ride code services, express delivery services, and online shopping.

[0078] The development framework provides a mini-program construction tool for executing the construction function in the mini-program processing method provided in the embodiment of the present invention, so as to encapsulate the code in the mini-program project into one or more JavaScript files that can run in the client's browser environment, and upload them to the server 300. The server 300 can be a server that carries the business logic of the business party, for example, a backend server that carries the ride service of a ride service provider, or it can be a dedicated storage server, for example, a node in the content distribution network (CDN) with the shortest link to the user's terminal.

[0079] Various types of clients can be run in the terminal 400 held by the user, and various applets can be provided in the client for the user to choose to use. For example, the social network client can provide the user with a ride code applet and a shopping application, so that the user can flexibly use various functions in the social network client without installing a dedicated ride code client or an online shopping client. Once the user confirms to download the applet in the terminal 400, the client will request the application server to download the Java Script file of the applet through the network 500, and execute the running function in the applet processing method provided in the embodiment of the present invention: interpret and execute the JavaScript file in the browser environment of the client, thereby running an instance of the applet.

[0080] As an example of the running function of the mini-program processing method, the instance of the mini-program first initializes the page, and can request page data from the server 300 and render it in the page. The page is composed of a series of components. When the user operates the component, the operating system of the terminal will pass the corresponding event to the instance of the mini-program, and the component will be re-rendered according to its own logic. For example, when the component is a button in the page of the mini-program, the rendering can be reproduced to display the dynamic effect of the button being pressed and the corresponding content. When the instance of the mini-program receives the data of the page updated by the server 300, the component will also be re-rendered according to the data to update the page.

[0081] The following describes an apparatus for implementing the applet processing method of the embodiment of the present invention. In some embodiments, the functions of the applet processing apparatus provided by the embodiment of the present invention can be distributed and deployed in different devices. For example, the construction function in the applet processing apparatus can be deployed in Figure 1 In the development device 200 shown in FIG. 1 , the running function in the applet processing device can be Figure 2 Of course, in other embodiments, the functions of the applet processing device can also be centrally deployed in the same device, for example, Figure 2 The development device 200 and the terminal 400 shown may be the same device.

[0082] See also Figure 3 , Figure 3 is a schematic diagram of the structure of a small program processing device 50 provided in an embodiment of the present invention, Figure 3 The applet processing device 50 shown includes: at least one processor 510, a memory 550, at least one network interface 520 and a user interface 530. The various components in the applet processing device 50 are coupled together via a bus system 540. It is understood that the bus system 540 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 540 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 540 is not shown in FIG. Figure 3 Various buses are labeled as bus system 540 .

[0083] The processor 510 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.

[0084] The user interface 530 includes one or more output devices 531 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 530 also includes one or more input devices 532, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.

[0085] The memory 550 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. The memory 550 may optionally include one or more storage devices that are physically remote from the processor 510.

[0086] The memory 550 includes a volatile memory or a nonvolatile memory, and may also include both volatile and nonvolatile memories. The nonvolatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 550 described in the embodiment of the present invention is intended to include any suitable type of memory.

[0087] In some embodiments, the memory 550 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.

[0088] Operating system 551, including system programs for processing various basic system services and performing hardware-related tasks, such as framework layer, core library layer, driver layer, etc., for implementing various basic services and processing hardware-based tasks;

[0089] A network communication module 552, for reaching other computing devices via one or more (wired or wireless) network interfaces 520, exemplary network interfaces 520 include: Bluetooth, Wireless Compatibility Certification (WiFi), and Universal Serial Bus (USB);

[0090] a presentation module 553 for enabling presentation of information via one or more output devices 531 (e.g., display screen, speaker, etc.) associated with the user interface 530 (e.g., a user interface for operating peripherals and displaying content and information);

[0091] The input processing module 554 is used to detect one or more user inputs or interactions from one of the one or more input devices 532 and translate the detected inputs or interactions.

[0092] In some embodiments, the memory 550 may be used to store a construction module 4551 and an operation module 4552 of the mini-program, which are respectively used to implement the construction function and the operation function of the mini-program, as will be exemplified below.

[0093] Next, the method for processing a mini-program provided by an embodiment of the present invention is described in combination with the exemplary application scenario and structure of the mini-program processing device described above.

[0094] First, the mini-program processing method provided by the embodiment of the present invention is described by taking the execution of the mini-program processing method to realize the mini-program construction function as an example. Figure 4 is an optional flowchart of the applet processing method provided by the embodiment of the present invention, see Figure 4 The mini-program processing method provided by the embodiment of the present invention includes:

[0095] Step 401: construct a reference relationship graph based on the reference relationship between the third-party components and the native components of the mini-program;

[0096] Step 402: recursively parse the reference relationship graph according to the reference scenario of the third-party component, and generate the entry file of the mini-program according to the recursively parsed reference relationship.

[0097] In some embodiments, based on the reference relationship between third-party components and native components of the mini-program, the construction of the reference relationship graph can be implemented in the following manner:

[0098] The build tool in the development project of the third-party component is updated through the plug-in; the syntax of the third-party component is parsed through the updated build tool to obtain the syntactic reference relationship between the third-party component and the mini-program, the page of the mini-program, and the custom component of the mini-program.

[0099] In actual implementation, the code merging and generation logic of the native build tool of the Vue project is replaced by the plug-in to implement the following code merging and generation processing:

[0100] Starting from the build entry, recursively traverse the reference relationships in the reference relationship graph, and convert the source files of the referenced components in the reference relationship (including source code, images, configuration and other static resources) into files that can be recognized and executed in the browser environment, namely the target files. For example, convert the JavaScript modules in the source files and some extended languages ​​(Scss, TypeScript, etc.) that cannot be directly run in the browser environment into JavaScript files.

[0101] In some embodiments, the entry file of the mini-program may be generated in the following manner:

[0102] Recursively parse the reference relationships in the reference relationship graph starting from the construction entry of the reference relationship graph; when the reference scenario of the reference relationship is a mini program, a mini program page, or a custom component of a mini program that references a third-party component, generate the following target files:

[0103] The entry file of the mini program, the entry file of the mini program page, the entry file of the third-party component, the configuration file of the mini program, the template file of the mini program and the style sheet of the mini program.

[0104] Here, in actual implementation, when generating the template file (JSON file) of the mini program, in the template of the mini program, identifiers (IDs) are assigned to the labels of the non-native components of the mini program (such as veu, js components) and labels with time binding attributes, and event detection functions are added to the non-native components.

[0105] Next, we will take the third-party component Vue.js component as an example to explain the construction function of the mini program.

[0106] For the construction of the reference relationship graph, the code parsing logic of the construction tool of the Vue development framework is replaced by a plug-in, so that the plug-in can be used to parse the Vue.js component, determine the reference relationship between the Vue.js component and the mini program, and the mini program page, and form a reference relationship graph.

[0107] Here, the build entry in the reference graph is the main.js file of the Vue project. The build entry is the starting point of the reference graph and defines the instance of Vue.

[0108] The reference relationship graph generated in the embodiment of the present invention has nothing to do with the actual reference scenario of the component (that is, the reference subject is a mini program, a mini program page or vue.js), and only represents the relationship between components based on syntactic references.

[0109] Figure 5 is a schematic diagram of an optional reference relationship diagram provided by an embodiment of the present invention, see Figure 5, where A.vue, B.vue, C.vue and D.vue are the encapsulation files corresponding to vue.js component A, vue.js component B, vue.js component C and vue.js component D respectively. Vue.js components use the .vue file format, which can encapsulate html, css, js, thus realizing the encapsulation of a component. A .vue file is a separate component. Figure 5 When generating the reference relationship graph, the reference relationship between components is determined only by the syntax of the components. At this time, the construction tool does not need to obtain the reference scenario of the component in the overall application; that is, for the A.vue component, there is no need to know whether the mini program references the A.vue component or the mini program page references the A.vue component. It only parses the syntax of A.vue and finds that it references C.vue and D.vue, then generates the next level component of a.vue in the reference relationship graph.

[0110] For the generation of the entry file, i.e., the target file, of the mini-program, the reference scenario is combined and the generated reference relationship graph is traversed. According to each reference relationship in the reference relationship graph, a corresponding entry file, i.e., the target file, is formed.

[0111] Exemplarily, for reference scenarios such as mini-program applications, mini-program pages, and custom components (Vue.js components), the following reference relationships are generated: reference to the mini-program's entry file, reference to the mini-program page's entry file, and reference to the Vue.js component's entry file; reference to the mini-program's configuration file (JSON file), reference to the mini-program's template file (i.e., XML file), and reference to the mini-program style sheet, to generate the corresponding entry file based on the reference relationship.

[0112] See also Figure 5 , C.vue is referenced by the mini-program page. For this reference relationship, the entry file of the mini-program page will be generated according to the source file of C.vue; suppose that when traversing to B.vue, it is found that it also references C.vue. For this reference relationship, the entry file of the vue.js component will be generated according to the source file of C.vue. In other words, one vue file can generate entry files in multiple scenarios (such as pages / components).

[0113] In actual applications, the entry files of the Vue.js component include: main.js, which is the entry file of the project, defines the Vue instance, and introduces the root component app.vue, which is mounted on the node with id 'app' in the directory file index.html.

[0114] The entry file of the mini program is named app, which includes: app.js, which is the overall logic of the mini program; app.json, the common configuration of the mini program, which determines the path of the page file, the overall window performance, sets the network timeout, sets multiple tabs, etc.; app.wxss, the common style sheet of the mini program, which describes the display properties of various elements in the component.

[0115] The entry file of the mini program page, taking the page name as "page" as an example, includes: page.js, the logic of this page; page.wxml, the page structure; page.wxss, the page style sheet; page.json, the page configuration.

[0116] Take webpack as an example, Figure 6 An optional schematic diagram of generating an entry file of a mini-program according to a reference relationship provided by an embodiment of the present invention, see Figure 6 In actual implementation, static analysis will be performed based on the reference relationship of the modules, and then these modules will generate corresponding static resources according to the specified rules. For example, if A.vue is to generate the application of the mini program, the corresponding entry file will be generated according to the rules of the mini program application, and C.vue and D.vue are to generate the mini program page, and the corresponding entry file will be generated according to the rules of the page. Figure 6 As can be seen, Webpack can convert multiple static resources js, css, and less into a static file, reducing page requests.

[0117] Continuing to take the execution of the applet processing method to realize the execution function of the applet as an example, the applet processing method provided by the embodiment of the present invention is described. Figure 7 , Figure 7 is an optional flowchart of the applet processing method provided by the embodiment of the present invention, see Figure 7 The mini-program processing method provided by the embodiment of the present invention includes:

[0118] Step 701: Run the applet in the client.

[0119] In some embodiments, the mini program acts as a sub-application and the client acts as a parent application. The mini program runs in the browser environment of the client. In actual applications, the client downloads the JavaScript file of the mini program from the server and runs an instance of the mini program in the browser environment: the mini program is interpreted and executed by the interpretation engine of the JavaScript file included in the browser environment, and the view of the mini program is rendered in the client by the rendering engine included in the browser environment.

[0120] Here, the creation of an instance of a mini program is explained.

[0121] In actual applications, the mini program is downloaded by the client, and the entry file (app.js) of the mini program is interpreted by the client's JS interpretation engine (core component of the browser), and the mini program page is rendered in the client through the client's rendering engine (core component of the browser). In actual implementation, the execution environment and rendering environment of the mini program in different terminals are different. For example, on iOS, the javascript code of the mini program is run in JavaScriptCore and rendered by WKWebView, and the environment is iOS8, iOS9, and iOS10; on Android, the javascript code of the mini program is parsed by X5 JSCore and rendered by X5 based on the Mobile Chrome 53 / 57 kernel; in the development tool, the javascript code of the mini program is run in nwjs and rendered by Chrome Webview.

[0122] Step 702: Create an instance corresponding to the third-party component of the mini-program by calling the entry file constructed by the corresponding mini-program.

[0123] In some embodiments, the instance corresponding to the third-party component of the mini program can be a global instance of the third-party component. Accordingly, by calling the entry file of the mini program, a global instance of the third-party component is created in the instance of the mini program to configure and share the third-party component through the global instance.

[0124] In some embodiments, the instance corresponding to the third-party component of the mini-program can be an instance of the third-party component. Accordingly, by calling the entry file of the mini-program's page, an instance of the third-party component is created in the instance of the mini-program's page, and the instance of the third-party component points to the global instance of the mini-program.

[0125] In some embodiments, when the instance corresponding to the third-party component is an instance of the third-party component, it is also possible to obtain the virtual node corresponding to the custom component by calling the entry file of the custom component of the mini-program, and create an instance of the third-party component in the instance of the custom component according to the virtual node.

[0126] Here, in actual implementation, the virtual node corresponding to the custom component can be obtained in the following way:

[0127] Take the page of the mini-program as the parent component and the custom component as the child component, create an instance of the child component in the instance of the parent component; pass the event to the parent component through the event interface of the mini-program through the instance of the child component, and the event carries a callback function; find the virtual node corresponding to the identifier of the child component through the instance of the parent component, and pass the data of the virtual node to the callback function; obtain the data of the virtual node from the callback function through the instance of the child component.

[0128] Here, we will explain the virtual node. In practical applications, the virtual node can be understood as a virtual DOM. The virtual DOM uses a JS object to record a copy of a DOM node, which retains the hierarchical relationship between elements and some basic properties. When the DOM changes, the virtual DOM is used for diffing to calculate the minimum difference, and then the real DOM is modified in batches at one time to speed up the display refresh speed.

[0129] The rendering of a real DOM tree requires parsing the CSS style and DOM tree first, then integrating them into a rendering tree, and then using the layout algorithm to calculate the position of each node in the browser, and finally outputting it to the display. The virtual DOM can be understood as saving all the information contained in a DOM tree before it is rendered. This information can be kept in the memory in the form of objects and maintained through JavaScript operations.

[0130] Accordingly, an instance of a third-party component may be created in an instance of a custom component according to a virtual node in the following manner: an instance of a third-party component is created in an instance of a custom component according to data of the virtual node.

[0131] Taking the third-party component as a Vue.js component as an example, calling the entry file to create a Vue.js instance corresponding to the Vue.js component of the mini program may include the following situations:

[0132] 1) In the case of calling the entry file of the mini-program application, a unique global instance (Vue.js instance) corresponding to the Vue.js component is created on the mini-program application instance. The Vue.js instance is used to implement global configuration sharing.

[0133] 2) In the case of calling the mini-program page entry file, a Vue.js instance of the corresponding Vue.js component is created on the mini-program page instance, and the parent component of the Vue.js component points to the global instance of the mini-program application.

[0134] 3) In the case of calling the entry file of a custom component, obtain the virtual node corresponding to the custom component, create a Vue.js instance of the corresponding Vue.js component on the instance of the mini-program custom component, and return the Vue.js instance of the Vue.js component.

[0135] Next, taking the mini program as the mini program, the mini program's page as the parent component, and the custom component as the child component as an example, the Vue.js instance of creating a corresponding Vue.js component on the instance of the mini program's custom component is explained. Figure 8 This is a flowchart of creating a subcomponent instance in a parent component instance and creating a Vue.js instance on the subcomponent instance provided by an embodiment of the present invention, which will be combined with Figure 8 The steps shown are explained.

[0136] First, before creating an instance of a child component in an instance of a parent component, you need to create a mini-program application instance to create a global instance on the mini-program application instance for global configuration sharing.

[0137] After creating a mini-program application instance, you can create an instance of a child component in the instance of the parent component, and create a Vue.js instance on the instance of the child component, including:

[0138] Step 801: The parent component (i.e., the entity that references the Vue.js component in the mini program) creates an instance of the child component.

[0139] Step 802: The child component sends an internal event to the parent component.

[0140] Here, the child component sends an internal event to the parent component through the custom event interface provided by the mini-program, along with a corresponding callback function; the internal event can be a pre-agreed event used to obtain virtual node data.

[0141] Step 803: The parent component searches for the virtual node according to the child component ID.

[0142] In actual implementation, the parent component detects the internal event sent by the child component. If the parent component is not a Vue.js component, the internal event is ignored. Otherwise, the corresponding virtual node is found from the component instance based on the unique ID of the sender, and the virtual node data is passed to the callback function of the event.

[0143] Step 804: The parent component returns the virtual node data to the child component.

[0144] The parent component obtains the virtual node data from the callback function and returns the virtual node data to the child component.

[0145] Step 805: The subcomponent creates a Vue.js instance on the instance of the subcomponent according to the virtual node data.

[0146] In actual applications, after creating a Vue.js instance on an instance of a subcomponent, events and data need to be bound to the subcomponent.

[0147] Specifically, when an event targeting a Vue.js component is received in the mini-program environment, the sub-component passes the event to the instance of the Vue.js component with a callback function.

[0148] For data binding of subcomponents, the following steps may be included:

[0149] 1. During the initial rendering of vue.js by the mini-program's rendering environment, the sub-component runs the sub-component rendering function, passes the rendering data returned by the function to the mini-program's rendering function, and the mini-program's rendering environment performs the rendering, while saving the data in the mini-program instance.

[0150] During the construction phase, the rendering function of the sub-component has been pre-generated according to the template of the Vue.js component. In addition to the data required for rendering the mini-program application (i.e., DOM data), the rendering function of the sub-component also includes the logical structure (structure and style) of the Vue.js component, so as to compare the data rendered for the first time and the newly generated data that needs to be rendered based on the logical structure.

[0151] 2. An event for the vue.js component occurs in the view, and the instance of the vue.js component generates new data that needs to be rendered according to the business logic.

[0152] In actual applications, when a user clicks on a vue.js component in a mini-program page, the subcomponent passes an event to Vue.js; the instance of the vue.js component generates the data that needs to be rendered based on its own business logic, passes it into the callback function, and the subcomponent retrieves the rendering data from the callback function.

[0153] 3. The subcomponent runs the rendering function again, compares the new data to be rendered returned by the vue.js instance with the data rendered last time, and passes the difference data to the rendering function of the mini program for rendering, so as to achieve incremental update.

[0154] Through the mini-program components and Vue.js components bound in the above steps, the data that the Vue.js component needs to render will be directly passed to the mini-program components through the corresponding callback function and filled into the template of the mini-program components for rendering. The component rendering data is independent of the upper-level page, and the related pages and components can run independently.

[0155] Fig. 9 For a schematic diagram of data flow provided by an embodiment of the present invention, see Fig. 9, the Vue.js component A referenced by page A, the data required for rendering of Vue.js component A is directly passed from the instance of the Vue.js component to the instance of the parent component, that is, the instance of mini program page A (child component). The instance of mini program page A retrieves the data according to the logic in mini program page template A and passes it to the rendering environment of the mini program for rendering; Fig. 9 In the example, the data required for page A rendering is directly passed from the instance of the Vue.js component to the instance of the mini program page A (subcomponent). The instance of the mini program page A retrieves the data according to the logic in the mini program page template A and passes it to the mini program's rendering environment for rendering. The operation of component B no longer depends on the logic of the upper-level page. Fig. 9 In the example, the relevant data required for rendering page A and component B are directly passed from the Vue.js instance to the relevant instance of the mini program, and the operation of component B no longer depends on the logic of the upper page.

[0156] Step 703: Obtain the event corresponding to the third-party component in the mini-program, and pass the event to the instance of the third-party component through the sub-component.

[0157] Step 704: Obtain data generated by the event corresponding to the instance of the third-party component, and render the data through the rendering environment of the mini program.

[0158] In some embodiments, after obtaining the data generated by the event corresponding to the instance of the third-party component, the data rendering in the rendering environment can be implemented in the following manner:

[0159] The data is compared with the data used in the previous rendering of the rendering environment through the instance of the subcomponent, and the difference data obtained by the comparison is passed to the rendering environment for rendering.

[0160] Take the example of a user triggering an event in a mini program to update data. Fig.10 A user interface diagram of a mini-program processing method provided by an embodiment of the present invention. In this example, the mini-program page is used as a parent component, and the selection box in the mini-program page is used as a child component. An instance of the selection box is created in the instance of the mini-program page, and a Vue.js instance of the corresponding Vue.js component is created on the instance of the selection box, such as Fig.10As shown in the figure, the current user interface is the mini program page for users to select devices. When the user clicks the selection box in the mini program page, an event for the Vue.js component is triggered. The subcomponent passes the event to the instance of the Vue.js component through the callback function. The instance of the Vue.js component generates new data that needs to be rendered according to its own business logic, and passes the data to the callback function. The subcomponent takes the rendering data from the callback function and runs the rendering function. The rendering function compares the new data that needs to be rendered returned by the vue.js instance with the data rendered last time, and passes the difference data to the rendering function of the mini program for rendering, thereby realizing data update, such as Fig.10 As shown, after the user clicks the selection box, the available options for the device are displayed.

[0161] The following will continue to describe exemplary functions of the mini-program processing device 50 provided in the embodiment of the present invention. Details not provided below can be understood based on the above description. Fig.11 The schematic diagram of the structure of the mini-program processing device 50 provided in the embodiment of the present invention is shown in FIG. Fig.11 , the mini-program processing device 50 provided in the embodiment of the present invention includes: a construction module 4551 and an operation module 4552;

[0162] The construction module 4551 is used to construct a reference relationship graph according to the reference relationship between the third-party component and the native component of the mini program;

[0163] And, it is used to recursively parse the reference relationship graph according to the reference scenario of the third-party component, and generate the entry file of the mini program according to the recursively parsed reference relationship.

[0164] The operation module 4552 is used to implement the operation function of the applet, including:

[0165] An operating unit 51 is used to operate the applet in the client;

[0166] A creation unit 52, configured to create an instance corresponding to a third-party component of the mini-program by calling an entry file constructed corresponding to the mini-program;

[0167] An acquisition unit 53, configured to acquire an event corresponding to the third-party component in the mini-program, and transmit the event to an instance of the third-party component through a sub-component;

[0168] The rendering unit 54 is used to obtain the data generated by the instance of the third-party component corresponding to the event, and render the data through the rendering environment of the mini program.

[0169] In some embodiments, the creation unit is further used to create a global instance of the third-party component in the instance of the mini-program by calling the entry file of the mini-program, so as to configure and share the third-party component through the global instance.

[0170] In some embodiments, the creation unit is also used to create an instance of the third-party component in the instance of the page of the mini-program by calling the entry file of the page of the mini-program, and the instance of the third-party component points to the global instance of the mini-program.

[0171] In some embodiments, the creation unit is further used to obtain a virtual node corresponding to the custom component by calling an entry file of the custom component of the mini-program, and create an instance of the third-party component in the instance of the custom component according to the virtual node.

[0172] In some embodiments, the creation unit is further used to take the page of the mini-program as a parent component and the custom component as a child component, and create an instance of the child component in the instance of the parent component;

[0173] Passing an event to the parent component through the instance of the child component and the event interface of the applet, wherein the event carries a callback function;

[0174] Searching for a virtual node corresponding to the identifier of the child component through the instance of the parent component, and passing the data of the virtual node into the callback function;

[0175] Obtaining data of the virtual node from the callback function through the instance of the subcomponent;

[0176] And, based on the data of the virtual node, an instance of the third-party component is created in the instance of the custom component.

[0177] In some embodiments, the rendering unit is further used to compare the data with the data used for the previous rendering of the rendering environment through the instance of the subcomponent, and transfer the difference data obtained by comparison to the rendering environment for rendering.

[0178] In some embodiments, the creation unit is further used to construct a reference relationship graph according to the reference relationship between the third-party component and the native component of the mini program;

[0179] The reference relationship graph is recursively parsed according to the reference scenario of the third-party component, and the entry file of the mini-program is generated according to the recursively parsed reference relationship.

[0180] In some embodiments, the creation unit is further used to update a build tool in the development project of the third-party component through a plug-in;

[0181] The syntax of the third-party component is parsed by the updated construction tool to obtain the syntactic reference relationship between the third-party component and the mini-program, the page of the mini-program, and the custom component of the mini-program.

[0182] In some embodiments, the creation unit is further used to recursively parse the reference relationship in the reference relationship graph starting from the construction entry of the reference relationship graph;

[0183] When the reference scenario of the reference relationship is that the mini program, the page of the mini program, or the custom component of the mini program references the third-party component, the following target files are generated:

[0184] The entry file of the applet, the entry file of the page of the applet, the entry file of the third-party component, the configuration file of the applet, the template file of the applet and the style sheet of the applet.

[0185] In some embodiments, the creation unit is further used to assign identifiers to tags corresponding to non-native components of the mini-program and tags with time binding attributes in the template of the mini-program, and add event detection functions for the non-native components.

[0186] An embodiment of the present invention further provides a storage medium storing executable instructions, wherein the executable instructions are stored. When the executable instructions are executed by a processor, the processor will be caused to execute the processing method of the mini-program provided by the embodiment of the present invention.

[0187] In some embodiments, the storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EE PROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories.

[0188] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.

[0189] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).

[0190] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.

[0191] In summary, the embodiments of the present invention have the following beneficial effects:

[0192] 1. Decoupling the mini program from the running environment of the Vue.js component removes the limitation of the component rendering dependency on the corresponding page in the existing technology. The entry file of the mini program generated for the Vue.js component can be reused in the mini program, improving development efficiency.

[0193] 2. The template file of the mini program generated according to the reference scenario of the Vue.js component is consistent with the native user code structure of the mini program, which facilitates debugging and avoids problems such as inaccessible data in specific scenarios.

[0194] 3. According to the reference relationship diagram, the corresponding mini-program applications and plug-ins can be generated for the Vue project. Independent mini-program pages and components can also be generated based on separate Vue.js files to meet the personalized deployment needs of the production environment.

[0195] 4. The generated mini program pages and components can be referenced independently, and their performance is consistent with normal mini program pages and components, making the visual effect of the mini program unified, and enabling mutual calls between mini program components and Vue.js components.

[0196] The above description is only an embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement and improvement made within the spirit and scope of the present invention are included in the protection scope of the present invention.

Claims

1. A method for processing a small program, It is characterized in that include: Run the applet in the client; By calling the entry file of the custom component of the mini-program, taking the page of the mini-program as the parent component and the custom component as the child component, an instance of the child component is created in the instance of the parent component; Passing a callback function to the parent component via the event interface of the applet through the instance of the child component; Searching for a virtual node corresponding to the identifier of the child component through the instance of the parent component, and passing the data of the virtual node into the callback function; Obtaining the data of the virtual node from the callback function through the instance of the subcomponent, and creating an instance of the third-party component in the instance of the custom component according to the data of the virtual node; Obtaining an event corresponding to the third-party component in the mini-program, and transmitting the event to an instance of the third-party component through a sub-component of the mini-program; The data generated by the instance of the third-party component corresponding to the event is obtained, and the data is rendered through the rendering environment of the mini program.

2. The method according to claim 1, It is characterized in that The obtaining data generated by the instance of the third-party component corresponding to the event, and rendering the data through the rendering environment of the mini program, includes: The data is compared with the data used in the previous rendering of the rendering environment through the instance of the subcomponent, and the difference data obtained by the comparison is transmitted to the rendering environment for rendering.

3. The method according to claim 1, It is characterized in that The method further comprises: Constructing a reference relationship graph according to the reference relationship between the third-party components and the native components of the mini program; The reference relationship graph is recursively parsed according to the reference scenario of the third-party component, and the entry file of the mini-program is generated according to the recursively parsed reference relationship.

4. The method according to claim 3, It is characterized in that The constructing a reference relationship graph according to the reference relationship between the third-party component and the native component of the mini program includes: Updating the build tool in the development project of the third-party component through the plug-in; The syntax of the third-party component is parsed by the updated construction tool to obtain the syntactic reference relationship between the third-party component and the mini-program, the page of the mini-program, and the custom component of the mini-program.

5. The method according to claim 3, It is characterized in that The recursively parsing the reference relationship graph according to the reference scenario of the third-party component, and generating the entry file of the mini-program according to the recursively parsed reference relationship, includes: Recursively parsing the reference relationships in the reference relationship graph starting from the construction entry of the reference relationship graph; When the reference scenario of the reference relationship is that the mini-program, the page of the mini-program, or the custom component of the mini-program references the third-party component, the following target files are generated: The entry file of the applet, the entry file of the page of the applet, the entry file of the third-party component, the configuration file of the applet, the template file of the applet and the style sheet of the applet.

6. The method according to claim 5, It is characterized in that The method further comprises: In the template of the mini-program, identifiers are assigned to the tags of the non-native components of the mini-program and the tags with time binding attributes, and event detection functions are added to the non-native components.

7. A device for processing a small program, It is characterized in that include: A running unit, used to run the applet in the client; A creation unit, used to create an instance of the child component in the instance of the parent component by calling the entry file of the custom component of the applet, taking the page of the applet as the parent component and the custom component as the child component; passing a callback function to the parent component via the event interface of the applet through the instance of the child component; searching for a virtual node corresponding to the identifier of the child component through the instance of the parent component, and passing the data of the virtual node to the callback function; obtaining the data of the virtual node from the callback function through the instance of the child component, and creating an instance of a third-party component in the instance of the custom component according to the data of the virtual node; An acquisition unit, configured to acquire an event corresponding to the third-party component in the mini-program, and transmit the event to an instance of the third-party component through a sub-component of the mini-program; The rendering unit is used to obtain the data generated by the instance of the third-party component corresponding to the event, and render the data through the rendering environment of the mini program.

8. A small program processing device, It is characterized in that include: A memory for storing executable instructions; A processor, used to implement the processing method of the mini-program described in any one of claims 1 to 6 when executing the executable instructions stored in the memory.

9. A storage medium, It is characterized in that Executable instructions are stored, which are used to cause the processor to execute and implement the processing method of the mini-program described in any one of claims 1 to 6.

10. A computer program product comprising a computer program or instructions, It is characterized in that When the computer program or instruction is executed by a processor, the method according to any one of claims 1 to 6 is implemented.