Multi-person collaborative online document editing method and deviceTechnical Field
The invention relates to the technical field of computer internet, in particular to a multi-person collaborative online document editing method and a device thereof.
Background
The multi-user online collaborative document editor is widely used nowadays, but the multi-user online collaborative document editors all have some obvious disadvantages, the use authority of each user for the document, which is not capable of controlling each chapter of the document, of the existing multi-user online collaborative document editor is the same, and when multiple users edit the same document at the same time, all users can edit the same chapter, which may cause content conflict. Some users can lock a document chapter when editing a certain chapter by controlling the editing authority, and at this time, other users cannot perform editing operation on the chapter, but cannot perform editing operation for adding or deleting other chapters, and only after the user finishes editing, other users can perform editing operation on other chapters. Therefore, the waiting time of the user who needs to add, delete or edit other chapters of the document is too long, so that the time of the subsequent user is wasted, and even the important document cannot be edited in time, so that the work is affected. Meanwhile, the prior art does not support the operation of arbitrarily dragging and sequencing document chapters, and in addition, the prior art cannot store the contents of the document chapters being edited in real time, so that document data is often lost.
Disclosure of Invention
The invention aims to solve the problem that the traditional document can not be edited by multiple persons on line in a coordinated manner at the same time to cause conflict, and provides a method and a device for editing a multi-person coordinated on-line document. The invention also provides the functions of arbitrarily dragging and sequencing the document chapters and automatically saving the document editing.
One of the technical schemes of the invention provides a multi-user collaborative online document editing method which is characterized in that the method comprises the steps of creating an initial document, splitting the document into a plurality of chapters, designing each chapter of the document with a unique identification ID and a position identification of the chapter, simultaneously inputting a plurality of users with operation authority, and carrying out addition, editing or deletion operation on the chapters of the document by multiple users in a collaborative online manner; the editing operation steps are as follows:
1) a user A applies for a request for editing a certain chapter of a document to a server, the server judges whether the chapter of the document is operated by other users through long connection after receiving the request, if not, the information is returned to the user A to inform the user A that the chapter of the document can be edited, and an exclusive lock is added to the long connection while the long connection is established between the user A and the chapter;
2) when a user B sends an editing request to a server for the same chapter of a document, after the server receives the request, the server finds that the chapter of the document is added with a long connection exclusive lock according to the unique identification ID of the chapter of the document, and the server returns the information to the user B to inform the user B that the chapter of the document is being edited by the user A, and other users are not allowed to edit the chapter;
3) after the user A finishes editing the chapters of the document, initiating an automatic real-time saving request to a server, after the server receives the request, automatically storing and updating the chapter contents of the document edited and modified by the user A, pushing an editing operation request of the user A to the user B, releasing a long connection exclusive lock with the chapters to disconnect the long connection, and after the user B receives the operation of editing the chapters of the document pushed by the server, locally executing the operation of editing the chapters of the document and updating the contents of the chapters;
4) the method comprises the steps that a user B sends a request of a certain chapter of a newly added document to a server, after the server receives the request, the chapter content of the newly added document is stored and a newly added operation request is pushed to the user A according to the content sent by the user B, and after the user A receives the chapter request of the newly added document pushed by the server, the operation of the chapter of the newly added document is executed locally and the chapter of the newly added document is inserted;
5) the method comprises the steps that a user B sends a request for deleting a certain chapter of a document to a server, after the server receives the request, the chapter is found through a unique identification ID of the chapter of the document according to the content sent by the user B, the chapter is deleted, the chapter operation request for deleting the document is pushed to the user A, and after the user A receives the chapter deletion operation request pushed by the server, the chapter operation for deleting the document is executed locally, and the chapter of the document is deleted.
Further, the method also comprises the operation of carrying out any dragging and sequencing on the document chapters; when the user B sends a sequencing request for dragging a certain chapter of a document to the lower part of a target chapter to the server, after the server receives the request, a source chapter and the target chapter are found through the unique identification ID of the chapter of the document according to the content sent by the user B, the sequencing of the source chapter is modified according to the target chapter, the chapter of the document is reordered, the dragging operation request is pushed to the user A, and after the user A receives the dragging chapter request pushed by the server, the dragging operation is executed locally and the chapter of the document is reordered.
The users simultaneously entered when the initial document is created have the operation permission of adding, editing, deleting, dragging and the viewing permission, and other users which are not entered only have the viewing permission.
The document content is stored in the database by taking the chapters of the document as a unit, each chapter is data which comprises the unique identification ID of the chapter, the position identification of the chapter, the document to which the chapter belongs, the content of the chapter, the upper level of the chapter, the sequence number of the chapter and other fields, and long connection is established between the client and the server through the data.
The user establishes long connection with the document when creating the document and establishes long connection with the chapters when editing the chapters; the long connection is used for judging whether the document chapter is being edited by other clients and whether an exclusive lock is added or disconnected, and sending information whether the document chapter can be edited to a user applying an editing operation authority request to the server through the long connection.
After receiving a real-time storage request, the server monitors the change of the chapter content of the document in real time in the process of automatically storing and updating the chapter content of the document edited and modified by a user, and continuously sends the real-time storage request to the server after the chapter content is sent for 1-5 seconds; and after the real-time storage request is executed, when the next content transmission change is monitored, the real-time storage request is transmitted after 1-5 seconds.
The invention provides a multi-person collaborative online document editing device, which is characterized by comprising an authority verification module, a document editing synchronization module, a document adding synchronization module, a document deleting synchronization module and a document dragging synchronization module; wherein,
an authority verification module: the method comprises the steps that the editing operation authority of a user is verified, when the user requests to add, edit, delete and drag a certain chapter of a document to be modified, whether the user has the operation authority of the document is verified firstly, and if not, the user can only check the operation authority of the document; if yes, further verifying whether the chapters of the document requested to be modified are edited by other users, if not, establishing long connection between the client and the server between the user and the chapters of the document, and adding an exclusive lock to the long connection, wherein at the moment, other users do not have the right to edit the chapters of the document;
the document editing synchronization module: in the process of editing the document, a client monitors the modification change of the chapter content of the document in real time and sends the modified chapter content to a server for automatic real-time storage, the server stores the chapter content of the document modified by the user after receiving an automatic real-time storage request and pushes the real-time storage request to other users through the long connection, and the other users execute local editing and storage operation to complete updating after receiving the request; when the chapter content of the document continuously changes, the client sends a real-time storage request to the server after monitoring is performed for 1-5 seconds each time; after editing is finished, pushing an edited message to the server through the long connection, disconnecting the long connection by the server and releasing the exclusive lock, and at the moment, editing the chapter by other users;
a document newly-added synchronization module: a user sends a request for adding a document chapter to a server, the server stores the chapter content of the added document after receiving the request, and pushes the chapter operation request of the added document to other users through the long connection, and after receiving the request, the other users locally execute the chapter operation of the added document and insert the added chapter into the document;
the document deletion synchronization module: the method comprises the steps that a user sends a request for deleting chapters of a document to a server, the server deletes the chapters of the document in a database of the server after receiving the request, pushes chapter operation requests for deleting the document to other users through the long connection, and after receiving the request, the other users locally execute operation for deleting the chapters and delete the chapters in the document.
A document dragging synchronization module: a user sends a request for dragging a certain chapter of a document to a position below a target chapter to a server, the server judges whether the upper chapters of the two chapters of the document are the same or not after receiving the request, if yes, the sequence number of the chapter is modified in a database of the server according to the sequence number of the target chapter, the brother chapters of the chapter are reordered, the chapter dragging operation request of the chapter is pushed to other users through the long connection, and after the other users receive the request, the operation of dragging the chapter to the position below the target chapter is executed, and the brother chapters of the chapter are reordered; and if the upper chapters of the two chapters of the document are different, modifying the upper chapters and the sequence numbers of the chapters according to the target chapters in a database of the server, reordering the chapters, the original brother chapters of the chapters and the new brother chapters of the chapters at the moment, pushing the dragging and ordering operation to other users through the long connection, and after the other users receive the request, locally executing the operation of dragging the chapters to the lower part of the target chapters and reordering the original brother chapters and the new brother chapters of the chapters. The sibling chapter in the document dragging and synchronizing module refers to the previous chapter or the next chapter of the dragged chapter.
The method can be used for simultaneously carrying out adding, editing, deleting or dragging sequencing operations on different chapters of the same document on line by a plurality of users with operation authority, and can carry out real-time storage and updating on respective user terminals.
The method and the device are applied to a server side, and the server side can be one or more servers; the client or the user can be a notebook computer, a desktop computer and other devices.
The method has the advantages that the server receives the request sent by the client user for editing the document chapters and pushes the editing operation to other client users, so that the editing operation generated by each client can be synchronized to other clients in time among a plurality of users or client users who cooperate with each other, the users of each client can correspondingly adjust or modify the editing content of the client according to the editing content of each client in time, the sharing, the uniformity and the effectiveness of the editing content are guaranteed as much as possible, and the efficiency of cooperative work is improved.
Drawings
FIG. 1 is a schematic flow diagram of the process of the present invention; wherein "Y" in the connecting line represents "yes", and "N" in the connecting line represents "no";
FIG. 2 is a diagram illustrating an exemplary content structure of the present invention in which a document is divided into sections;
FIG. 3 is a schematic diagram of the structure of the apparatus of the present invention;
FIG. 4 is a schematic diagram of the authentication rights module of the apparatus of the present invention;
FIG. 5 is a schematic diagram of a document editing synchronization module of the apparatus of the present invention;
FIG. 6 is a schematic diagram of a document adding module of the apparatus of the present invention;
FIG. 7 is a schematic diagram of a document deletion module of the apparatus of the present invention;
FIG. 8 is a schematic diagram of a drag document synchronization module of the apparatus of the present invention.
Detailed Description
The following detailed description of specific embodiments of the present invention and the detailed description of the technical solutions in the embodiments of the present invention are described in detail with reference to the accompanying drawings and exemplary embodiments. The embodiments described herein are only some of the preferred embodiments of the present invention. These preferred embodiments do not limit other embodiments of the invention. The technical solution of the present invention is fully embodied in the following examples.
Example 1
Embodiment 1 provides a method for editing a multi-user collaborative online document, which is shown in fig. 1. The method can realize the collaborative document editing among a plurality of client users, namely simultaneously editing each chapter of the same online document and reasonably dragging and sequencing each chapter of the document. The user establishes a long connection with the document when creating the document and a long connection with the chapter when editing the chapter. The sibling section described in the document drag operation refers to the section immediately preceding or immediately following the dragged section. The client user of the embodiment adopts a desktop computer.
The specific implementation of the embodiment includes the following operation steps:
referring to fig. 1 and 2, according to the method steps of the present invention, an initial document is first created, and the document is broken into sections. As shown in fig. 2, the present embodiment decomposes a document into two chapters, i.e., a first chapter and a second chapter, the first chapter being further decomposed into 4 sub-chapters, and the second chapter being decomposed into 3 sub-chapters, each of which contains respective contents. Each chapter of the document is designed with a unique identification ID and a position identification of the chapter, and a plurality of client users with the operation permission of adding, editing, deleting and dragging are input at the same time. In the embodiment, the user A and the user B are entered while the initial document is created, the user A and the user B have the operation permission of addition, editing, deletion, dragging and the viewing permission, and other client-side users which are not entered only have the viewing permission.
The document content is stored in the database by taking the chapters of the document as a unit, each chapter is a piece of data, the data comprises the unique identification chapterID of the chapter, the document documentID of the chapter, the content of the chapter, the upper parentID of the chapter, the serial number sort of the chapter and other fields, and long connection is established between the client and the server through the chapter data.
The long connection established by the chapter data of the document is used for judging whether the chapter of the document is being edited by other clients and whether an exclusive lock is added or disconnected, and sending information whether the editing can be carried out to a user applying an editing operation authority request to the server through the long connection.
When a user A opens a document, a request for inquiring document content is applied to a server, the server receives the request, the document is divided into two chapters and a plurality of sub-chapters under the chapters, content contents of all the chapters and the chapters of the document are inquired according to document documentIDs to which the chapters belong, the documents are orderly combined and returned to the user A according to fields such as upper-level parentIDs of the chapters and sequence numbers of the chapters, and meanwhile, a long connection is established between the client and the server between the user A and the document through websocket and is used for information communication between the client and the server.
Referring to fig. 1, 4, and 5, when the user a sends an edit modification authority request for the first section of the document to the server, the request content is { "document id":15, chapterID: "b4a73d9129cb99e0c933e561f0b415b4", userID: "a415777d2b4418bdab28744602a719b5", where document represents the document identifier being edited, chapterID represents the section identifier being edited, and userID represents the current user identifier.
After receiving the editing and modifying authority request of the user A, the server judges that the first chapter is not connected with other clients according to the document documentID and the chapter chapterID, namely judges that no other clients edit the first chapter of the document through long connection, and returns the information to the user A, informs the user A that the first chapter of the document can be edited, and adds an exclusive lock to the long connection while the user A establishes connection with the chapter. The server will refuse the authorization request of other users for the first chapter application editing. If the user C sends a delete authorization request to the server for the same first chapter of the document and the user D sends a drag authorization request, the server receives the requests of the user C and the user D and then analyzes the document documentID and the chapter chapterID in the requests, finds that the first chapter and the user A have established long connection in the process, namely finds that the chapter of the document has added a long connection exclusive lock according to the unique identification ID of the chapter of the document, rejects the requests of the user C and the user D, informs the user C and the user D that the first chapter of the document is being edited by the user A, and other clients are not allowed to edit the chapter, so that both the user C and the user D are rejected by the server and are returned with information only capable of viewing the chapter. Only when the user a sends a request to disconnect the long connection of the chapter, the server releases the exclusive lock to disconnect the long connection of the chapter. If the user B sends an editing authorization request after the server releases the exclusive lock and disconnects the long connection, the server returns the information that the first chapter can be edited, and the user B can perform the operation of editing the first chapter.
Referring to fig. 5, after the user a completes editing the document, initiating an automatic real-time saving request to a server, after receiving the user a automatic real-time saving request, automatically updating and storing the first chapter content of the document edited and modified by the user a, and meanwhile pushing the real-time saving request operation of the user a to the user B, after receiving the operation pushed by the server, the user B locally executes the real-time saving operation, extracts the document documentID and chapters id in the operation, finds the position of the first chapter according to the chapters id, and updates the content of the first chapter.
The document editing and modifying request contents are { type: "edit", "documentID":15, "chapterID":
"ee1df267ed78c68cbe6ba 6 359b631332a", "content": "content", userID: "
f29bb9c64155cbe3d1863b2309914d78", where documentID denotes the document identifier being edited, chapterID denotes the identifier of the first section, content denotes the modified content, and userID denotes the current user identifier.
The method comprises the steps that after a user A finishes an editing task of a first chapter, focus is lost in an editing area of the first chapter, an edited message is pushed to a server through long connection, the server analyzes document documentID, chapter chapterID and user identifier userID completion information in the message, a long connection exclusive lock is released, and long connection between the user A and the first chapter is disconnected. At this point, other users may edit the chapter.
In the editing process of the user A, the client side can monitor the content edited by the first chapter, and when the content changes, a real-time storage request can be sent to the server. When a user continuously inputs edited contents, in order to prevent the condition that a request is sent to a server at a high frequency for real-time storage, which causes overlarge server pressure, when a client monitors a real-time storage request sent when the edited contents continuously change, the client sends the request to the server within 1-5 seconds, and when the client monitors the next content change after executing the sending request, the client sends the request for real-time storage after 1-5 seconds, namely when the document contents continuously change, the client sends a real-time storage request to the server after executing the monitoring for 1-5 seconds every time, so as to reduce the pressure of the server. The automatic real-time document editing storage function effectively avoids the loss of document editing data under unexpected conditions.
Referring to fig. 6, the user B sends a request for adding a second section of the document to the server, and after receiving the request for adding the second section of the document to the user B, the server adds a new content, which is { type: "add", "document id":15, "parentID": "646f755a45b6ba36977f35f77974e0c5", "content": content ", userID: "8a19e0254900761367009da74178c414", where documentID denotes the document identifier being edited, parentID denotes the superior identifier of the second section, content denotes the content of the second section, and userID denotes the current user identifier.
And storing the newly added second chapter in a database, simultaneously pushing an operation request of the newly added second chapter of the user B to the user A through long connection, after receiving a new document request operation pushed by the server, the user A locally executes the operation of the newly added second chapter, extracts the document documentID and the superior parentID in the operation, finds the position of the second chapter according to the superior parentID and inserts the second chapter of the newly added document.
Referring to fig. 7, user B sends a request to the server to delete the third section of the document. The request contents are { type: "delete", "documentID":15, "chapterID": 2d1a0afd15911adbf372cb532138d499"}, wherein type represents the request operation type, documentID represents the document ID being edited, and chapterID represents the identifier of the third section.
After receiving a request of a user B for deleting a third chapter of a document, a server finds the third chapter in a database and deletes the content of the third chapter according to the content sent by the user B through the unique identifier chapterID of the chapter, meanwhile, pushes the operation of deleting the document chapter to the user A through long connection, and after receiving the operation information of deleting the document chapter pushed by the server, the user A also locally executes the operation of deleting the third chapter of the document, extracts the document documentID and the chapter chapterID in the operation, finds the position of the third chapter according to the chapterID and deletes the third chapter of the document.
Referring to fig. 2 and 8, a user B sends a request for dragging a document chapter to the server, that is, sends a request for dragging a first chapter to a position below a second chapter, where the request includes:
{ type: "sort", "documentID":15 "," sourceID ": dc29f988be3da2e690304cdad947743d" }, targetID: "0946c17f95ee783fc24818a410ea8204" }, where type denotes a request operation type, documentID denotes a document ID being edited, sourceID denotes a first chapter identifier, and targetID denotes a second chapter identifier.
After receiving a request that a user B drags a first chapter to the lower part of a second chapter, according to the content sent by the user B, the server firstly judges whether the parentIDs of the upper chapters of the two chapters of the document are the same or not after receiving the request, if so, the server modifies the sequence numbers of the chapters in a database of the server according to the sequence numbers of the target chapters, and reorders the brother chapters of the chapters; and if the upper chapters of the two chapters of the document are different, modifying the upper chapters and the sequence numbers of the chapters in a database of the server according to the target chapters, reordering the original brother chapters of the chapters and the new brother chapters of the chapters, pushing the dragging and ordering operation to other users, and after the other users receive the request, locally executing the operation of dragging the chapters to the lower part of the target chapters and reordering the original brother chapters and the new brother chapters of the chapters.
The first chapter and the second chapter are found in the database through the unique identifiers sourceID and the targetID of the two chapters, the sequence of the first chapter is modified according to the sequence number of the second chapter, then the brother chapters of the first chapter and the second chapter are reordered, meanwhile, the operation of dragging the document chapters is pushed to a user A through long connection, after the user A receives operation information of the dragging document chapters pushed by the server, the operation of dragging the first chapter to the lower part of the second chapter is executed locally, document documentID, sourceID and targetID in the operation are extracted, the first chapter and the second chapter are found according to the sourceID and the targetID, the sequence number of the first chapter is modified, the brother chapters of the first chapter and the second chapter are reordered, and the updating operation is stored locally in real time.
The embodiment receives the specific implementation operations sent by the client side for editing operation, real-time storage and the like through the server side, and completely realizes the technical scheme of the invention, so that a plurality of client sides can cooperate with one another to carry out multi-user collaborative online document editing work, the editing operations generated by the respective client sides are synchronized to other client sides, each client side user can adjust and modify own editing content in time according to the editing content of the document, a plurality of users can edit the same document online at the same time, the uniformity, the effectiveness and the sharing performance of the editing content are ensured as much as possible, and the efficiency of the document editing work is effectively improved.
Example 2
Embodiment 2 is a specific embodiment of a module composition of a multi-person collaborative online document editing apparatus, and reference is made to fig. 3. The multi-person collaborative online document editing device comprises a permission verification module, a document editing synchronization module, a document adding synchronization module, a document deleting synchronization module and a document dragging synchronization module. The device is applied to a server side, and the server side can be one server or a plurality of servers. The client of the device can be computer equipment such as a notebook computer, a desktop computer and the like.
When a user A and a user B open a document, each client establishes a long connection between the client and the server through the websocket by using a client user ID and a document ID, and the server communicates with each client through the long connection. If user A establishes a long connection with the document, user B also establishes a long connection with the document. Wherein each module performs its respective function.
An authority verification module: the method is used for verifying the editing operation authority of a client user, when the user requests to add, edit, delete and drag a chapter to modify, whether the user has the editing operation authority of the document is verified firstly, if not, the user can only check the editing operation authority, if yes, the user further verifies whether the chapter of the document requested to be modified has other users editing, if not, the long connection is established between the client user and the document chapter and the server, an exclusive lock is added to the long connection, and at the moment, the other users do not have the authority to edit the chapter of the document.
As shown in fig. 4, when creating a document, in addition to the basic information of the document, a client user who has an operation right of adding, modifying, deleting, and dragging to the document needs to be entered, only the user with the right can operate the document, and other users can only view the document.
The present embodiment enters user a and user B at the time of creating a document. When a user A initiates an editing request for a first chapter of a document, after receiving the request, a server analyzes the ID of the user A through the content of the first chapter, matches the ID stored in a database, and verifies whether the first chapter establishes long connection with other users after matching is successful; if not, a long connection is established between the client and the server by the user A and the first section through the websocket, and an exclusive lock is added to the long connection. At this time, the server will refuse the authorization request of other users for the first chapter application editing. When the user B initiates an authorization request of adding chapters, the server also matches the ID of the user B with the ID stored in the database, and the user B has the authority to add chapters after the matching is successful. And when the user C initiates a request for adding a new chapter, the server judges that the ID of the user C is not matched with the ID stored in the database, and the user C directly returns to the state of only viewing the information. When the user D initiates a request for dragging the chapter, the server judges that the ID of the user D is not matched with the ID stored in the database, and the user D directly returns to the state of being only capable of viewing the information.
The document editing synchronization module: in the process of editing the document, the client monitors the change of the chapter content of the document in real time, sends the modified chapter content to the server for automatic real-time storage, the server receives the automatic real-time storage request, stores the document content edited and modified by the user and pushes the real-time storage operation request to other users through long connection, and the other users locally execute the same operation to complete chapter updating after receiving the operation request. When the content of the document changes continuously, a real-time storage request is sent to the server after monitoring is performed for 1-5 seconds each time; after editing is finished, pushing an edited message to the server through the long connection, disconnecting the long connection by the server and releasing the exclusive lock, and at the moment, editing the section by other users;
as shown in fig. 5, the user a monitors the edited content of the first chapter during the process of editing the first chapter, and when the content changes, the user a sends a real-time storage request to the server; when the user A continuously inputs the changed content, in order to prevent the server from being excessively stressed due to the fact that the server is frequently sent to the server for real-time storage, when the client monitors the content sending change, the client sends a request to the server within 1-5 seconds, and after the sending request is executed, the client sends the request again for real-time storage after monitoring the next content change for 1-5 seconds. And the server receives the request of the user A, stores the modified content in the database and pushes the operation of the user A to the user B through long connection, and the user B locally executes the operation of requesting real-time storage and updates the content of the first chapter. And after the user A finishes editing, the focus is lost in the first chapter area, and the server releases the long connection exclusive lock and disconnects the long connection between the user A and the first chapter. At this point, user B may edit the first chapter, with which user B has established a long connection.
A document newly-added synchronization module: the method comprises the steps that a user sends a request for adding a document chapter to a server, the server stores chapter content of a newly added document after receiving the request, the operation of requesting the newly added document chapter is pushed to other users through long connection, and after the other users receive the operation, the operation of adding the document chapter is executed locally and the newly added chapter is inserted into the document.
As shown in fig. 6, the user B sends a request for adding a second section of the document to the server, the server parses the document documentID, the superior parentID, and the content in the request, inserts the second section of the document in the database according to the parentID, and pushes the operation of adding the section of the user B to the user a through the long connection, and the user a executes the operation of adding the second section, finds the position of the new section through the imported superior parentID, and inserts the position of the new section into the second section of the document.
The document deletion synchronization module: the method comprises the steps that a user sends a request for deleting chapters of a document to a server, the server deletes the chapters of the document in a database of the server after receiving the request, and pushes chapter deleting request operation to other users through long connection, and after the other users receive the operation, the operation of deleting the chapters is executed locally, and the chapters are deleted in the document.
As shown in fig. 7, a user B sends a request for deleting the third chapter of the document to the server, the server parses the document documentID and the chapter chapterID in the request, deletes the third chapter of the document in the database by the chapter chapterID, and pushes an operation request for deleting the third chapter by the user B to the user a through the long connection, and the user a executes an operation of deleting the request for deleting the third chapter and deletes the third chapter of the document by the chapter chapterID.
A document dragging synchronization module: the method comprises the steps that a user sends a request for dragging a certain chapter to the lower portion of a target chapter to a server, the server judges whether superior chapter parentIDs of the two chapters are the same or not after receiving the request, if the superior chapter parentIDs of the two chapters are the same, the sequence number of the chapter is modified in a database of the server according to the sequence number of the target chapter, brother chapters of the chapter are reordered, dragging operation is pushed to other users through long connection, and the other users execute operation of dragging the chapter to the lower portion of the target chapter and reorder the brother chapters of the chapter after receiving the drag operation. And if the two chapters are different, modifying the superior parentID and the serial number sort of the chapter according to the target chapter in a database of the server, reordering the original brother chapter of the chapter and the new brother chapter of the chapter at the moment, pushing the dragging operation to other users through long connection, and locally executing the operation of dragging the chapter to the lower part of the target chapter and reordering the original brother chapter and the new brother chapter of the chapter after the other users receive the operation. The sibling chapter described in this embodiment refers to the previous chapter or the next chapter of the dragged chapter.
As shown in fig. 2 and 8, the whole document is displayed in units of chapters, the document is divided into two parts, the left side is a chapter directory, and the directory is rendered by a draggable tree component according to data stored in a database. The right side is the chapter content, and the content corresponds to the catalogue one by one. The user A can sort by dragging the chapter directory, and the attribute of each chapter comprises a chapter ID, a serial number sort and an upper parentID.
Example 1: when the user A executes the operation of dragging the first chapter to the lower part of the second chapter, the sort of the first chapter is 1, the sort of the second chapter is 2, and a dragging operation request is sent to the service. The server analyzes the sourceID and the targetID in the request, finds the first chapter and the second chapter through the sourceID and the targetID, adds 0.5 to the sort of the first chapter on the basis of the sort of the second chapter, namely 2.5, and then reorders the first chapter and the second chapter according to the size of the sort, wherein the sort of the second chapter is 1, and the sort of the first chapter is 2. And pushing the dragging operation to a user B after the sequencing is finished, and carrying out the same dragging request operation locally by the user B and reordering the first chapter and the second chapter through the chapter sourceID and the targetID.
Example 2: when the user A carries out the operation of dragging the sub-chapter 1 of the first chapter to the position below the sub-chapter 2 of the second chapter, the sort of the sub-chapter 1 of the first chapter is 1, the sort of the sub-chapter 2 of the second chapter is 2, and a dragging operation request is sent to the service. The server analyzes the sourceID and the targetID in the request, finds the sub-chapter 1 of the first chapter and the sub-chapter 2 of the second chapter through the sourceID and the targetID, finds that the sub-chapter 1 and the sub-chapter 2 do not belong to the same catalogue by comparing the parentIDs of the two chapters, modifies the parentID of the sub-chapter 1 into the second chapter in the database, adds 0.5 to the sort of the sub-chapter 1 on the basis of the sort of the sub-chapter 2 to obtain 2.5, and then reorders and rounds the original brother chapter of the sub-chapter 1 and the brother chapter of the sub-chapter 2 according to the size of the sort, wherein the sub-chapter 1 and the sub-chapter 2 both belong to the second chapter, the sort of the sub-chapter 2 is 2, and the sort of the sub-chapter 1 is 3. And pushing the dragging operation to the user B after the sequencing is finished, and locally executing the same dragging request operation by the user B, and reordering the original sibling chapter and the new sibling chapter of the sub-chapter 1 through the chapter sourceID and the targetID.
The two embodiments completely realize the technical scheme of the method and the device, so that a plurality of clients can collaborate with each other to perform multi-user collaborative online document editing work, a plurality of users can simultaneously perform the editing of the same document online, the uniformity, the effectiveness and the sharing of the editing content are ensured as much as possible, the efficiency of the document editing work is greatly improved, the security of the document is effectively improved, and the loss of data caused by accidents is effectively avoided.
The above examples are only preferred embodiments of the present invention, and are not intended to limit the technical solutions of the present invention. Various modifications may be made by those skilled in the art without departing from the principles of the invention and are intended to be within the scope of the invention.