Text restoration method and device, electronic equipment and readable storage medium
By setting virtual boxes with the same width on the front end and monitoring their height changes, marking the style changes in text input, and transmitting this information to the back end, the problem of being unable to restore the text input style of the front end page in the existing technology is solved, and the back end is able to accurately restore and display the front end text style.
Patent Information
- Application Number
- CN202510253606.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-05
- Publication Date
- 2025-06-13
AI Technical Summary
The prior art cannot truly restore the input style of text on the front-end page, especially when transmitting text information, the back-end cannot know the display style of text on the front-end page, resulting in the inability to accurately restore the input style of user on the front-end page.
Set a virtual box with the same width as the text box in the front end, place the characters in the text box in the virtual box, and listen to the height of the virtual box. When the height of the virtual box changes, the characters that cause the change are marked. When text input is finished, all characters and marks in the virtual box are transferred to the backend, so that the backend can restore and display the input text on the frontend based on this information.
By setting virtual boxes on the front end and monitoring their height changes, line breaks and other style changes can be accurately marked, so that the backend can truly restore the text input style of the front end page, improving the accuracy and user experience of electronic contract processing.
Smart Images

Figure CN120145995A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of displays, and particularly to a text restoration method, apparatus, electronic device, and readable storage medium. Background Art
[0002] User A drags a service control to the front-end page. The control actually presents in a box form, and sends the page with the service control to User B. User B clicks on the link to open the corresponding page, enters text information in the box and transmits it to the backend, and the backend displays it on the front-end page. Since the text information transmitted to the backend currently is in the form of a long string of continuous characters, the backend cannot know the original display style of the text on the front-end of the page, and it is difficult to accurately restore the input style of User B on the front-end page.
[0003] Therefore, how to truly restore the input style of text on the front-end page is a technical problem that urgently needs to be solved currently. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide a text restoration method, apparatus, device, and storage medium, which solves the problem in the prior art that the input style of text cannot be truly restored on the front-end page.
[0005] To solve the above technical problem, the present invention provides a text restoration method, including:
[0006] Set a virtual box corresponding to the text box at the front end, place the characters in the text box in the virtual box, and monitor the height of the virtual box; the width of the virtual box is the same as the width of the text box;
[0007] When it is monitored that the height of the virtual box changes, mark the characters that cause the height change of the virtual box;
[0008] When the text input ends, transmit all the characters and marks in the virtual box to the backend, so that the backend restores and displays the input text on the front end based on the characters and marks.
[0009] Optionally, the step of setting a virtual box corresponding to the text box at the front end, placing the characters in the text box in the virtual box, and monitoring the height of the virtual box; the width of the virtual box is the same as the width of the text box includes:
[0010] Use a front-end development language to build the virtual box and event listening mechanism at the front end;
[0011] Obtain the width value of the text box from the cascading style sheet of the text box;
[0012] Set a width value equal to the virtual box according to the width value;
[0013] When a character appears in the text box, input the character into the virtual box, and use the event listening mechanism to monitor whether the height of the virtual box changes.
[0014] Optionally, when it is monitored that the height of the virtual box changes, the character that causes the height change of the virtual box is marked, including:
[0015] When the input character causes the height of the virtual box to change and the input character is the first character of the text box, record the input character as a normal text identifier;
[0016] When the input character causes the height of the virtual box to change and the input character is not the first character of the text box, record the input character as a line break identifier;
[0017] When the input character does not cause the height of the virtual box to change, continue to monitor.
[0018] Optionally, the data structure of the line break identifier is an object array containing a character position index and a line break type flag.
[0019] Optionally, when the text input is completed, all characters and marks in the virtual box are transmitted to the backend, so that the backend restores and displays the input text on the frontend based on the characters and marks, including:
[0020] When the text input is completed, sort all characters and marks in the virtual box in a preset format;
[0021] Use the Ajax method to transmit the sorted data to the backend, so that the backend parses the data to be transmitted and restores the line break style of the text on the frontend.
[0022] Optionally, it further includes:
[0023] When the sum of the widths of all characters in the current virtual box exceeds the width of the text box due to the input character, record the input character as a line break identifier.
[0024] Optionally, it further includes:
[0025] When there are special characters in the virtual box, use regular matching to determine the positions of the special characters, and record the special characters as line break identifiers; the special characters include line break characters.
[0026] The present invention also provides a text restoration device, including:
[0027] A monitoring module, configured to set a virtual box corresponding to a text box at the front end, place the characters in the text box into the virtual box, and monitor the height of the virtual box; the width of the virtual box is the same as the width of the text box;
[0028] A marking module, configured to mark the characters that cause the height change of the virtual box when it is monitored that the height of the virtual box changes;
[0029] A restoration module, configured to transmit all the characters and marks in the virtual box to the back end when the text input ends, so that the back end restores and displays the input text at the front end based on the characters and marks.
[0030] The present invention further provides an electronic device, including:
[0031] A memory, configured to store a computer program;
[0032] A processor, configured to implement the text restoration method as described above when executing the computer program.
[0033] The present invention further provides a computer-readable storage medium, in which computer-executable instructions are stored, and when the computer-executable instructions are loaded and executed by a processor, the text restoration method as described above is implemented.
[0034] It can be seen that the present invention sets a virtual box corresponding to a text box at the front end, places the characters in the text box into the virtual box, and monitors the height of the virtual box; the width of the virtual box is the same as the width of the text box; when it is monitored that the height of the virtual box changes, the characters that cause the height change of the virtual box are marked; when the text input ends, all the characters and marks in the virtual box are transmitted to the back end, so that the back end restores and displays the input text at the front end based on the characters and marks. By setting a virtual box with the same width as the text box at the front end and marking the characters by monitoring the height change of the virtual box in real time, the back end can truly restore and display the text at the front end.
[0035] In addition, the present invention further provides a text restoration device, an electronic device and a readable storage medium, which also have the above beneficial effects. Description of the Drawings
[0036] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained according to the provided drawings without creative efforts.
[0037] Figure 1 is a display method of the prior art;
[0038] Figure 2 is a flowchart of a text restoration method provided by an embodiment of the present invention;
[0039] Figure 3 is a flow example diagram of a text restoration method provided by an embodiment of the present invention;
[0040] Figure 4 is a schematic structural diagram of a text restoration device provided by an embodiment of the present invention;
[0041] Figure 5 is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. Detailed implementation manners
[0042] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are only a part rather than all of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0043] In the application scenario of electronic contracts, user A can drag a service control to the front-end page, and the control actually presents in the form of a box. After user A sends the page with the service control to user B, user B clicks on the link to open the corresponding page and enters text information in the box. For example, user B enters 8 lines of text content. However, currently when transmitting this information to the backend, it is only transmitted in the form of a long string of continuous characters, and the backend cannot know the line break positions when the text is displayed on the front end. This brings many inconveniences to subsequent data processing, contract presentation, and the accurate execution of related business logics, making it difficult to accurately restore the input style of user B on the front-end page and reducing the accuracy of electronic contract processing and the user experience. As Figure 1 shown, Figure 1 is a display method of the prior art.
[0044] To solve the above problems, the present invention provides a text restoration method. Specifically, please refer to Figure 2 , Figure 2 is a flowchart of a text restoration method provided by an embodiment of the present invention. The method may include:
[0045] S101: Set a virtual box corresponding to the text box at the front end, place the characters in the text box into the virtual box, and monitor the height of the virtual box; the width of the virtual box is the same as the width of the text box.
[0046] The execution subject of this embodiment is a terminal. This embodiment does not limit the type of the terminal, as long as it can complete the operations of the text restoration method. This method can be specifically applied to the application scenario of electronic contracts. It solves the problem that when the text information on the front-end page of an electronic contract is transmitted to the back-end, the line break position cannot be accurately recorded and transmitted. This method can enable the back-end to accurately obtain the line break situation of the string on the front-end page, improve the accuracy and integrity of electronic contract data processing, and optimize the user experience. The actual presentation of the business control is in the form of a text box, and the user inputs text in the text box, and the computer can recognize the characters. It can be understood that text focuses on the expression of human language and the transmission of information; characters are a basic data type used to process text data in computer programming. The two only target different objects, but have the same meaning and both refer to the content input by the user.
[0047] In this embodiment, a virtual box with the same width as the business control (i.e., the text box / input box) operated by the user is created at the front-end. This virtual box is not directly presented to the user on the front-end page and is only used to assist in detecting the line break position of the characters. It should be noted that the front-end and the front-end page in this embodiment refer to the same thing. When the user inputs text in the business control, the front-end program will split the input string character by character and sequentially "put" the split characters into the virtual box. At the same time, the front-end technology is used to monitor the height change of the virtual box in real time.
[0048] Further, setting the virtual box corresponding to the text box at the front-end, placing the characters in the text box into the virtual box, and monitoring the height of the virtual box; the width of the virtual box is the same as the width of the text box, and the following steps can be included:
[0049] Step 21: Use the front-end development language to construct a virtual box and an event listening mechanism at the front-end;
[0050] Step 22: Obtain the width value of the text box from the cascading style sheet of the text box;
[0051] Step 23: Set the width value of the same width for the virtual box according to the width value;
[0052] Step 24: When a character appears in the text box, input the character into the virtual box, and use the event listening mechanism to monitor whether the height of the virtual box changes.
[0053] Specifically, a virtual box is constructed using a front-end development language such as JavaScript. By obtaining the width value in the CSS (Cascading Style Sheets) style attributes of the text box, a virtual box of the same width is created based on this, ensuring that the widths of the two match, providing a basis for accurately detecting line breaks subsequently. At the same time, the event listening mechanism of JavaScript is also utilized to listen for input events of the user within the text box. Whenever a character is input, the operations of splitting the character and placing it into the virtual box are triggered, and the height detection function is called in real-time to listen for the height of the virtual box.
[0054] S102: When it is detected that the height of the virtual box has changed, then mark the character that caused the change in the height of the virtual box.
[0055] During the process of listening for the height of the virtual box, once a character enters the virtual box, thereby causing the height of the virtual box to change, immediately add an identifier to mark that there may be a starting point of a line break or a change point of a text paragraph here. Specifically, for height listening, the height attribute of the DOM element of the virtual box can be obtained, and the change in the height values before and after can be compared. If it is found that the height has changed, then in combination with the current character input situation, it is judged whether the change in height is caused by the filling of ordinary text or a line break, and then the corresponding identifier is recorded.
[0056] Further, the above-mentioned when it is detected that the height of the virtual box has changed, then mark the character that caused the change in the height of the virtual box may include the following steps:
[0057] Step 31: When the input character causes the height of the virtual box to change, and the input character is the first character of the text box, then record the input character as an ordinary text identifier;
[0058] Step 32: When the input character causes the height of the virtual box to change, and the input character is not the first character of the text box, then record the input character as a line break identifier;
[0059] Step 33: When the input character does not cause the height of the virtual box to change, then continue to listen.
[0060] Specifically, considering that the change in height may be caused by the first character, or it may also be caused by a line break. Therefore, it is necessary to mark the non-first character that causes the change in height. It should be noted that the first character refers to the first character in the text box. Specifically, the above identifier can adopt a custom data structure. For example, the line break identifier can be an object array containing the character position index (to determine the position of the character) and the line break type marker. The index of the character position is used to determine the position of the character, and the line break type marker is used to determine the type of the character; the data structure of the object array is clearer.
[0061] S103: When the text input is completed, all characters and marks in the virtual frame are transmitted to the back end, so that the back end restores and displays the input text on the front end based on the characters and marks.
[0062] In this embodiment, the sign of the end of text input can be the receipt of the user's submission instruction. After completing the user input and recording all line break identifiers, the front end transmits the string data with line break identifiers as a whole to the back end. After the back end receives the data, it can accurately restore the line break situation of the front end page string based on these identifiers, so as to perform accurate subsequent processing, such as contract text typesetting, data storage and other operations that conform to the front end display logic.
[0063] Furthermore, when the text input is finished, all characters and marks in the virtual box are transmitted to the back end so that the back end restores and displays the input text on the front end based on the characters and marks, which may include the following steps:
[0064] Step 41: When the text input is finished, all characters and marks in the virtual frame are sorted according to a preset format;
[0065] Step 42: Transmit the sorted data to the back end by using Ajax, so that the back end parses the data to be transmitted and restores the line break style of the text at the front end.
[0066] Specifically, when the user completes input and submits the data, the front end sends the string data with complete line break identifiers to the back end in the agreed format through Ajax or other data transmission methods. After receiving the data, the back end uses a parser to interpret the identifiers and restores the line break style of the string in the front end according to the identifiers, which is used for text processing, storage and other links in the contract processing process to ensure the consistency between the back end processing and the front end display.
[0067] Furthermore, the following steps may be included:
[0068] When the input characters cause the sum of the widths of all characters in the current virtual box to exceed the width of the text box, the input characters are recorded as line break markers.
[0069] Specifically, when the input character makes the sum of the widths of all characters in the current virtual box reach the critical value of the virtual box width, that is, when another character is put in, a new line will be opened. At this time, a height change is detected and a mark is recorded to clarify the line break position. By repeating this process continuously, the line break related marks of the character string in the virtual box are continuously recorded.
[0070] Furthermore, in order to improve the accuracy of the detection, the following steps may also be included:
[0071] When there are special characters in the virtual box, use regular expression matching to determine the positions of the special characters, and record the special characters as line break identifiers; the special characters include line break characters.
[0072] Specifically, if the text format at the front end is more complex, such as including tab button codes, \n, etc., it may be necessary to use regular expression matching to determine the positions of the special characters and identify the special characters. When there are special characters such as tab button codes, \n, etc. in the text, regular expressions can be used to match and determine their positions, and these special characters are recorded as line break identifiers. Further, the specific types of the special characters can also be recorded, so that the front end can be restored based on the identifiers and character types, making the front-end restoration more real and reliable. Regular expressions are a powerful text processing tool that can identify and locate text parts that conform to specific patterns through specific syntax rules. Here, it is necessary to find the positions of special characters such as \t and \n in the text. After finding these special characters, corresponding processing needs to be performed on them. For example, for \n, it can be directly converted into a line break tag in HTML, so that the line break effect can be achieved on the front-end page; for \t, it can be processed according to specific requirements, such as converting it into a certain number of spaces or special style identifiers, etc.
[0073] Applying the text restoration method provided by the embodiments of the present invention, by setting a virtual box corresponding to the text box at the front end, placing the characters in the text box in the virtual box, and monitoring the height of the virtual box; the width of the virtual box is the same as the width of the text box; when it is monitored that the height of the virtual box changes, the characters that cause the height change of the virtual box are marked; when the text input ends, all the characters and marks in the virtual box are transmitted to the back end, so that the back end restores and displays the input text at the front end based on the characters and marks. By setting a virtual box with the same width as the text box at the front end and marking the characters by monitoring the height change of the virtual box in real time, the back end can truly restore and display the text at the front end.
[0074] To make the present invention easier to understand, please specifically refer to Figure 3 , Figure 3 which is a flowchart example of a text restoration method provided by the embodiments of the present invention, and specifically may include:
[0075] Use JavaScript and other front-end development languages to build a virtual box. By obtaining the width value in the CSS (Cascading Style Sheets) style attribute of the text box, a virtual box of the same width is created based on this. Use JavaScript's event monitoring mechanism to monitor the user's input events in the text box. Whenever a character is input, the character splitting and placing in the virtual box are triggered, and the height value changes before and after are compared by obtaining the DOM element height attribute of the virtual box. If the height changes, it is determined whether the height change is caused by ordinary text filling or line breaking in combination with the current character input situation, and then the corresponding mark is recorded. When the user completes the input and submits the data, the front-end sends the string data with complete line break marks to the back-end in the agreed format through Ajax or other data transmission methods. After receiving the data, the back-end uses the parser to interpret the mark, and restores the line break style of the string in the front-end according to the mark, which is used for text processing, storage and other links in the contract processing process to ensure the consistency between the back-end processing and the front-end display.
[0076] The specific code implementation logic is as follows: create a span tag (virtual box), set it to be hidden, and its width is the same as the text box width, and the font size inside is also the same as the text box font; break up the statements inside the text box, insert them one by one, and compare the height of the current span tag with the height before insertion. If it is greater than the previous one, then record the index of the current text and put it into the array. If it is equal, ignore it and continue to loop the above operation. Use the index array recorded above to traverse the original statement again. If the current index exists in the array, add a line break at this place. Since the virtual span does not set the height at the beginning, the height will change when the first character is entered. According to the above logic, the current index will be put into the array, but there is actually no need to wrap at this time, so when adding a line break, exclude index=== 0 to achieve the line break mark.
[0077] The text restoration device provided by an embodiment of the present invention is introduced below. The text restoration device described below and the text restoration method described above can be referenced to each other.
[0078] Please refer to Figure 4 , Figure 4 A structural diagram of a text restoration device provided by an embodiment of the present invention may include:
[0079] The monitoring module 100 is used to set a virtual box corresponding to the text box at the front end, place the characters in the text box in the virtual box, and monitor the height of the virtual box; the width of the virtual box is the same as the width of the text box;
[0080] A marking module 200, configured to mark the characters that cause the change in the height of the virtual box when it is monitored that the height of the virtual box changes;
[0081] A restoration module 300, configured to transfer all the characters and marks in the virtual box to the backend when the text input ends, so that the backend restores and displays the input text on the frontend based on the characters and marks;
[0082] Based on the above embodiments, the monitoring module 100 may include:
[0083] A construction unit, configured to construct the virtual box and the event monitoring mechanism on the frontend using a frontend development language;
[0084] A width value acquisition unit, configured to acquire the width value of the text box from the cascading style sheet of the text box;
[0085] A width value setting unit, configured to set a width value equal to the width value for the virtual box according to the width value;
[0086] A height monitoring unit, configured to input the character into the virtual box when a character appears in the text box, and use the event monitoring mechanism to monitor whether the height of the virtual box changes.
[0087] Based on the above embodiments, the marking module 200 may include:
[0088] A first marking unit, configured to record the input character as a normal text identifier when the input character causes the height of the virtual box to change and the input character is the first character of the text box;
[0089] A second marking unit, configured to record the input character as a line break identifier when the input character causes the height of the virtual box to change and the input character is not the first character of the text box;
[0090] A monitoring unit, configured to continue monitoring when the input character does not cause the height of the virtual box to change.
[0091] Based on the above embodiments, the data structure of the line break identifier is an object array including a character position index and a line break type mark.
[0092] Based on the above embodiments, the restoration module 300 may include:
[0093] An arrangement unit, configured to arrange all the characters and marks in the virtual box in a preset format when the text input ends;
[0094] A transmission unit, configured to transmit the sorted data to the backend in an Ajax manner, so that the backend can parse the data to be transmitted and restore the line break style of the text at the frontend.
[0095] Based on the above embodiments, the text restoration device may further include:
[0096] A first marking module, configured to record the input character as a line break identifier when the sum of the widths of all characters in the current virtual box exceeds the width of the text box due to the input character.
[0097] Based on the above embodiments, the text restoration device may further include:
[0098] A second marking module, configured to determine the position of the special character by regular matching when there is a special character in the virtual box, and record the special character as a line break identifier; the special character includes a line break character.
[0099] It should be noted that the order of the modules and units in the above text restoration device can be changed before and after without affecting the logic.
[0100] Applying the text restoration device provided by the embodiments of the present invention, a monitoring module 100 is configured to set a virtual box corresponding to a text box at the frontend, place the characters in the text box in the virtual box, and monitor the height of the virtual box; the width of the virtual box is the same as the width of the text box; a marking module 200 is configured to mark the character that causes the height change of the virtual box when it is monitored that the height of the virtual box changes; a restoration module 300 is configured to transmit all the characters and marks in the virtual box to the backend when the text input ends, so that the backend restores and displays the input text at the frontend based on the characters and marks. This device sets a virtual box with the same width as the text box at the frontend, and marks the characters by real-time monitoring of the height change of the virtual box, so that the backend can truly restore and display the text at the frontend.
[0101] Next, the electronic device provided by the embodiments of the present invention will be introduced. The electronic device described below can be correspondingly referred to the text restoration method described above.
[0102] Please refer to Figure 5 , Figure 5 , which is a schematic structural diagram of an electronic device provided by an embodiment of the present invention, and may include:
[0103] A memory 10, configured to store a computer program;
[0104] A processor 20, configured to execute the computer program to implement the above text restoration method.
[0105] The memory 10, the processor 20, and the communication interface 31 all complete their mutual communication through the communication bus 32.
[0106] In the embodiment of the present invention, the memory 10 is used to store one or more programs. The program may include program codes, and the program codes include computer operation instructions. In the embodiment of the present invention, the memory 10 may store a program for implementing the following functions:
[0107] Set a virtual box corresponding to the text box at the front end, place the characters in the text box in the virtual box, and monitor the height of the virtual box; the width of the virtual box is the same as the width of the text box;
[0108] When it is monitored that the height of the virtual box changes, mark the characters that cause the change in the height of the virtual box;
[0109] When the text input ends, transmit all the characters and marks in the virtual box to the back end, so that the back end restores and displays the input text at the front end based on the characters and marks.
[0110] In a possible implementation manner, the memory 10 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system and application programs required for at least one function, etc.; the data storage area may store the data created during use.
[0111] In addition, the memory 10 may include a read-only memory and a random access memory, and provide instructions and data to the processor. A part of the memory may also include NVRAM. The memory stores an operating system and operation instructions, executable modules or data structures, or subsets thereof, or extended sets thereof. Among them, the operation instructions may include various operation instructions for implementing various operations. The operating system may include various system programs for implementing various basic tasks and processing hardware-based tasks.
[0112] The processor 20 may be a central processing unit (CPU), an application-specific integrated circuit, a digital signal processor, a field programmable gate array, or other programmable logic devices. The processor 20 may be a microprocessor or any conventional processor, etc. The processor 20 may call the program stored in the memory 10.
[0113] The communication interface 31 may be an interface of a communication module for connecting to other devices or systems.
[0114] Of course, it should be noted that Figure 5 the shown structure does not limit the electronic device in the embodiment of the present invention. In practical applications, the electronic device may include more Figure 5more or fewer components shown, or combining certain components.
[0115] The computer-readable storage medium provided by the embodiments of the present invention will be introduced below. The computer-readable storage medium described below can be correspondingly referred to the text restoration method described above.
[0116] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned text restoration method are implemented.
[0117] The computer-readable storage medium may include: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc that can store program codes.
[0118] In the present specification, the embodiments are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The same or similar parts among the embodiments can be referred to each other. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple. For the relevant parts, refer to the description of the method part.
[0119] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in this article can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in the form of hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.
[0120] Finally, it should also be noted that in this article, relationships such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device.
[0121] The above has introduced in detail a text restoration method, device, electronic device, and computer-readable storage medium provided by the present invention. Specific examples are used in this article to elaborate on the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention; at the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present invention.
Claims
1. A text restoration method, characterized in that: include: A virtual box corresponding to the text box is set at the front end, characters in the text box are placed in the virtual box, and the height of the virtual box is monitored; the width of the virtual box is the same as the width of the text box; When a change in the height of the virtual frame is detected, marking the characters that cause the change in the height of the virtual frame; When the text input is finished, all characters and marks in the virtual frame are transmitted to the back end, so that the back end restores and displays the input text on the front end based on the characters and marks.
2. The text restoration method according to claim 1, characterized in that: The virtual frame corresponding to the text frame is set at the front end, the characters in the text frame are placed in the virtual frame, and the height of the virtual frame is monitored; The width of the virtual frame is the same as the width of the text frame, including: Using a front-end development language to construct the virtual frame and event monitoring mechanism on the front end; Obtaining a width value of the text box from a cascading style sheet of the text box; Setting a width value of the same width for the virtual frame according to the width value; When characters appear in the text box, the characters are input into the virtual box, and the event monitoring mechanism is used to monitor whether the height of the virtual box changes.
3. The text restoration method according to any one of claims 1 to 2, characterized in that: When it is detected that the height of the virtual frame changes, marking the characters that cause the height of the virtual frame to change includes: When the input character causes the height of the virtual box to change, and the input character is the first character of the text box, the input character is recorded as a common text mark; When the input character causes the height of the virtual box to change, and the input character is not the first character of the text box, the input character is recorded as a line break mark; When the input characters do not cause the height of the virtual frame to change, the monitoring continues.
4. The text restoration method according to claim 3, characterized in that: The data structure of the line break identifier is an object array including character position indexes and line break type tags.
5. The text restoration method according to claim 1, characterized in that: When the text input is finished, all characters and marks in the virtual frame are transmitted to the back end, so that the back end restores and displays the input text on the front end based on the characters and marks, including: When the text input is finished, all characters and marks in the virtual frame are sorted according to a preset format; The sorted data is transmitted to the back end by using Ajax, so that the back end parses the data to be transmitted and restores the line break style of the text at the front end.
6. The text restoration method according to claim 1, characterized in that: Also includes: When the input characters cause the sum of the widths of all characters in the current virtual box to exceed the width of the text box, the input characters are recorded as line break markers.
7. The text restoration method according to claim 1, characterized in that: Also includes: When there are special characters in the virtual frame, the position of the special characters is determined by regular matching, and the special characters are recorded as line break marks; The special characters include line breaks.
8. A text restoration device, characterized in that: include: A monitoring module, used for setting a virtual box corresponding to the text box at the front end, placing the characters in the text box in the virtual box, and monitoring the height of the virtual box; the width of the virtual box is the same as the width of the text box; A marking module, for marking the characters causing the height change of the virtual frame when it is detected that the height of the virtual frame changes; The restoration module is used to transmit all characters and marks in the virtual frame to the back end when the text input is completed, so that the back end can restore and display the input text on the front end based on the characters and marks.
9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the text restoration method as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are loaded and executed by the processor, the text restoration method according to any one of claims 1 to 7 is implemented.