Cross-platform data front-end display method
Through the CSS framework and the mobile adaptation framework, combined with JavaScript and Service Workers, the compatibility and offline access problems of cross-platform data display are solved, responsive design and offline caching are realized, and the consistency and stability of data display are improved. Reduces development complexity and cost.
Patent Information
- Application Number
- CN202410920656.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-11-05
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing technology has compatibility problems in cross-platform data display, resulting in inconsistent display between different browsers, mobile devices and operating systems, increasing development costs and complexity, and unable to effectively solve data discontinuity during offline access.
Using CSS framework and mobile adaptation framework, the device characteristics and browser rendering style are determined through media queries and user-agent string detection, combined with JavaScript and Service Workers to realize responsive design and offline caching, ensuring data on different platforms and offline states Consistency display under.
It improves cross-platform consistency and stability of data display, reduces development and maintenance costs, enhances user experience, and ensures correct display and offline access to data on different devices and platforms.
Smart Images

Figure CN118897923A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a cross-platform data front-end display method. Background Art
[0002] In today's data-driven era, data visualization and front-end presentation are essential for users to understand and analyze information. With the development of technology and the increase in the variety of devices, users want to get the same data operation experience and visual effects on different devices and platforms.
[0003] There are many data display methods in the prior art, including but not limited to web page charts, mobile application interfaces, and desktop applications. These methods are usually optimized for specific platforms, but they have many limitations in cross-platform compatibility. For example, a chart designed for a web page may not display well on a mobile device, and an interface developed specifically for a mobile application may not be presented in a suitable way in a desktop environment. Therefore, it is necessary to solve the compatibility issues between different browsers, mobile devices, and operating systems to ensure that data can be displayed correctly in various environments without misalignment or display anomalies due to platform differences.
[0004] In addition, due to the differences in screen size, resolution, operating system and browser of different devices, existing solutions often require developers to develop and maintain a set of codes for each target platform separately, which not only increases the development cost, but also makes it more difficult and complicated to maintain consistency between different platforms. At the same time, with the emergence of new platforms and new devices, developers need to constantly update and adapt their codes, which further exacerbates the complexity of development and maintenance. Therefore, although the existing technologies provide a variety of data display solutions, they still have shortcomings in cross-platform consistency, development efficiency and maintenance convenience. At the same time, it is necessary to consider the situation of offline access, that is, users can still access the application and view data when there is no network connection. This means that the data needs to be stored on the local device so that the data can be loaded from the local database or cache when there is no network connection to ensure the continuity of the user experience. Therefore, a cross-platform data front-end display method is urgently needed. To overcome these limitations and improve the overall data display effect. Summary of the invention
[0005] The purpose of the present invention is to provide a cross-platform data front-end display method to solve the compatibility problem between different browsers, mobile devices and operating systems and the problem of data discontinuity during offline access.
[0006] The present invention provides a cross-platform data front-end display method, the method comprising:
[0007] Using a CSS framework, wherein a media query in the CSS framework is provided with a data application style corresponding to device characteristics;
[0008] Detecting a user agent string, and determining the type of device, browser, and operating system used by the user based on the user agent string;
[0009] Get device information based on JavaScript navigator object and device API;
[0010] Determining the device characteristics based on the device information, and determining the data application style based on the device characteristics;
[0011] Use CSS prefixes to determine the correct rendering style for said browser;
[0012] Use the mobile adaptation framework, based on the design specifications of the operating system, and use corresponding UI components to display data according to the data application style and the correct rendering style.
[0013] Preferably, the device characteristics include screen width, screen resolution and orientation.
[0014] Preferably, the device information includes device type, device identification, and device hardware information.
[0015] Preferably, the mobile terminal adaptation framework is one of Bootstrap, Ant Design Mobile, and Vant.
[0016] Preferably, determining the device characteristics based on the device information includes:
[0017] A device information library is set, wherein the device information library includes a device type and a device identifier, and the device type is set with a corresponding screen width, screen resolution and orientation;
[0018] Based on the device type and device identification in the device information, the device characteristics are determined according to the device information library.
[0019] Preferably, before the data is displayed on the front end, it includes:
[0020] Use JavaScript to monitor the network status and detect whether the user is offline through the navigator.onLine property.
[0021] Preferably, the method further comprises:
[0022] Use application cache to cache the application's data resources locally, and use IndexedDB or Web Storage to store the cached data resources locally. When the user is offline, use Service Workers to provide the stored data resources.
[0023] The present invention also discloses a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are loaded and executed by a processor to implement the above-mentioned cross-platform data front-end display method.
[0024] The present invention also discloses a front end, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-mentioned cross-platform data front-end display method.
[0025] Compared with the prior art, the beneficial effect of the present invention is that, by using the CSS framework and the mobile adaptation framework, the present invention enables the display page to automatically adapt to different devices and screen sizes, providing a consistent user experience. And load adaptive data application styles according to device characteristics to improve page readability and usability. According to the device type, browser and operating system, select the appropriate data application style and rendering style, adjust the page layout and function, provide an interactive experience that is more in line with the user's device, and improve page consistency. And provide offline data resource caching and loading to enhance the user experience when offline. The present invention improves development efficiency as a whole, ensures the consistency and stability of data display on different platforms, and reduces the cost and complexity of multi-platform development and maintenance interfaces. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0027] Figure 1 It is a flow chart of a cross-platform data front-end display method of the present invention. DETAILED DESCRIPTION
[0028] The technical solutions in the embodiments of the present invention are described clearly and completely below. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] Example
[0030] With the development of mobile Internet and multi-terminal devices, users hope to get the same data operation experience and visual effects on different devices. However, due to the differences in screen size, resolution, operating system and browser of different devices, the method of cross-platform data display needs to solve the compatibility issues between different browsers, mobile devices and operating systems to ensure that data can be displayed correctly in various environments without dislocation or display abnormality due to platform differences. However, there are some disadvantages of traditional front-end display methods: 1. Complexity: The existing technology requires the use of multiple technical means, which increases the complexity and difficulty of development. 2. Performance issues: Some technical means will affect the performance of the application, such as offline caching may cause excessive resource occupation, affecting the response speed and loading time of the application. 3. Compatibility: The existing technology cannot completely solve the compatibility issues of all platforms and devices, and unknown compatibility bugs may occur. 4. Maintenance cost: The use of multiple technical means increases the amount and complexity of the application code, and increases the maintenance cost and risk. 5. Security: Some technical means may have security vulnerabilities, such as local storage may cause data leakage or illegal acquisition, and additional security measures need to be taken to protect the security of user data.
[0031] The purpose of this solution is to solve the above technical problems and provide a comprehensive solution. By adopting a variety of core methods, such as responsive design, mobile adaptation, offline caching, etc., it can optimize the user experience of data front-end display, improve the performance, availability and security of the application, and thus achieve consistency and stability when displaying data on different devices and platforms.
[0032] The present invention provides a cross-platform data front-end display method, such as Figure 1 As shown, the method includes:
[0033] Step S1, using a CSS framework, wherein a media query in the CSS framework is provided with a data application style corresponding to device characteristics.
[0034] Preferably, the device characteristics include screen width, screen resolution and orientation.
[0035] In this embodiment, responsive design can be achieved by using a CSS framework, or by using technologies such as CSS Grid / Flexbox.
[0036] A CSS framework is a set of pre-written code libraries designed to help developers quickly build web page layouts and user interfaces. CSS frameworks can be Bootstrap: an open source front-end framework launched by Twitter, which contains design templates for HTML and CSS, as well as extensions to JavaScript. Bootstrap is known for its mobile-first responsive design, which is ideal for rapid development of prototypes and production-ready web projects. Tailwind CSS: This is a pragmatic CSS framework that provides a set of highly customizable low-level utility classes that allow developers to build customized designs by combining these classes. The characteristic of Tailwind CSS is that it emphasizes flexibility and ease of use.
[0037] Responsive design is a website design method that can adapt to different devices and screen sizes. With the characteristics of fluid layout, media query, adaptive images and segmented display, the core of responsive design is to provide a consistent user experience, ensuring the complete display and ease of use of content no matter what device the user uses to access the website. It not only helps to improve the user experience, but also simplifies the website development and maintenance process.
[0038] In the present invention, a CSS framework is used to implement responsive design, and media queries in CSS are a powerful feature that allows developers to apply different styles based on different device characteristics. It enables websites to provide user experiences that adapt to different screen sizes and resolutions. Media queries select different style sheets by adding expressions to check media types and media characteristics. These expressions can be included in link tags to reference different CSS style files based on the size of the device. Media queries can be used to check the width and height of the viewport, the width and height of the device, the direction (such as whether a tablet or mobile phone is in landscape or portrait mode), resolution, etc. Media queries are a key tool for achieving flexibility in modern website design, which enables websites to better adapt to different browsing environments, thereby providing a better user experience.
[0039] Step S2, detecting a user agent string, and determining the device type, browser, and operating system used by the user according to the user agent string.
[0040] In this embodiment, User-Agent detection is a method for identifying the client device, operating system, and browser type used to access a website or application. By analyzing the User-Agent string, the device (such as a mobile phone, tablet, or desktop computer), operating system (such as Windows, macOS, Android, or iOS), and browser (such as Chrome, Firefox, Safari, etc.) used by the user can be determined. Among them, the User-Agent String is a string that identifies the browser and its operating environment information.
[0041] Step S3, obtaining device information according to the JavaScript navigator object and the device API.
[0042] Preferably, the device information includes device type, device identification, and device hardware information.
[0043] In this embodiment, the JavaScript navigator object is a built-in object that provides information about the user's browser. The navigator object can provide detailed information about the user's browser, which is very useful for developers. For example, through the navigator object, developers can obtain information such as the user's browser name, version, operating system platform, etc. This information can be used to optimize the display effect of the web page, or adjust the function and layout of the website according to different platforms and browser characteristics. It is convenient for subsequent determination of device characteristics.
[0044] Step S4, determining the device characteristics based on the device information, and determining the data application style based on the device characteristics.
[0045] Preferably, determining the device characteristics based on the device information includes:
[0046] A device information library is set, which includes a device type and a device identifier. The device type is set with a corresponding screen width, screen resolution and direction.
[0047] Based on the device type and device identification in the device information, the device characteristics are determined according to the device information library.
[0048] In this embodiment, the device characteristics of the device used are determined by the device information, and different data application styles are applied according to the device characteristics according to the media query. The role of media queries in CSS is to apply different style rules according to the characteristics of the device or browser to achieve responsive design. Through media queries, the viewport width and height of the device can be detected to provide suitable layouts and styles for screens of different sizes. Media queries can determine whether the device is in landscape or portrait mode, which is very useful for designing pages that present different layouts in different directions. Because different devices have different resolutions, media queries can help developers adjust font size, image size, etc. according to the resolution to optimize the visual effect.
[0049] Step S5, using the CSS prefix to determine the correct rendering style of the browser.
[0050] In this embodiment, the CSS prefix is a method of adding a browser-specific prefix before the CSS property name to ensure that the style is correctly rendered on different browsers. Some common CSS prefixes include -webkit-, -moz-, -ms-, -o-.
[0051] By using CSS prefixes to ensure that styles are rendered correctly on different browsers, cross-browser compatibility can be effectively improved: by adding specific prefixes, you can ensure that new CSS properties are supported in different browser engines, thereby avoiding layout or style issues caused by browsers not supporting certain CSS3 properties. Maintain visual consistency: Using CSS prefixes can ensure that the website or application maintains visual consistency in various browsers, which is crucial to maintaining brand image and user experience. Reduce development and maintenance costs: Although prefixes need to be added for different browsers, this helps reduce maintenance costs and time caused by compatibility issues in the later stage. Using CSS prefixes is an important strategy for front-end developers when facing a diverse browser market. It helps to improve the compatibility, stability and user experience of web pages.
[0052] Step S6, using the mobile adaptation framework, based on the design specifications of the operating system, using corresponding UI components to display the data according to the data application style and the correct rendering style.
[0053] Preferably, the mobile terminal adaptation framework is one of Bootstrap, Ant Design Mobile, and Vant.
[0054] In this embodiment, after determining the data application style and rendering style according to the device characteristics and the browser, the corresponding UI components are used to display the data according to the detected operating system to achieve mutual compatibility between different devices, browsers and operating systems and improve page consistency.
[0055] In some embodiments of the present application, before the data is displayed on the front end, it includes: using JavaScript to monitor the network status and detecting whether the user is offline through the navigator.onLine property.
[0056] In this embodiment, JavaScript is used to monitor the network status. The navigator.onLine property can be used to detect whether the user is offline. The navigator.onLine property returns a Boolean value indicating whether the user's system is connected to the network. When the user is offline, the property returns false; when the user is online, it returns true.
[0057] Here is a simple example:
[0058] function checkOnlineStatus(){
[0059] if(navigator.onLine){
[0060] console.log("User is online");
[0061] }else{
[0062] console.log("User is offline");
[0063] }
[0064] }
[0065] window.addEventListener("online",checkOnlineStatus);
[0066] window.addEventListener("offline",checkOnlineStatus);
[0067] checkOnlineStatus();
[0068] In this example, we define a function called checkOnlineStatus to check the user's network status. Then, we use the window.addEventListener method to listen for online and offline events and call the checkOnlineStatus function when the network status changes. Finally, we call the checkOnlineStatus function when the page loads to initialize the network status.
[0069] In some embodiments of the present application, the method further includes: using application cache to cache the application's data resources locally, and using IndexedDB or Web Storage to store the cached data resources locally, and when the user is offline, using Service Workers to provide the stored data resources.
[0070] In this embodiment, in a computer, cache and storage are two different technologies that work together to save and access data, but have different characteristics and uses. Cache is a high-speed memory used to temporarily store frequently accessed data to reduce processing time. It is usually located inside or close to the CPU for quick access. The cache has a small capacity but is very fast and can significantly improve the performance of the computer. Storage generally refers to the long-term data preservation facilities of a computer, including main memory (RAM), hard disk drive (HDD), solid-state drive (SSD), etc. These storage devices are relatively slow, but can provide a large amount of storage space to save programs, files, and user data. The storage device is far away from the CPU, and the data transmission speed is limited by the speed of the interface and bus.
[0071] First, use the application cache to cache the used data resources locally, and use IndexedDB or WebStorage to store the cached data resources for subsequent offline calls. IndexedDB is a low-level API for clients to store large amounts of structured data (including files and Blob objects). It provides all the functions of a transactional database system, including data read and write operations, key-value storage, indexing, and searching. Web Storage includes localStorage and sessionStorage, which allow key-value data to be stored in the browser. The data in localStorage is persisted, while the data in sessionStorage is cleared at the end of the page session. Service Workers is a script running in the background of the browser that can intercept network requests and provide cached resources when offline according to the cache strategy. Service Workers can be used to implement offline caching, message push, and other functions to improve the performance and user experience of the application. Through Service Workers, the data resources stored locally can be loaded when offline, so that users can still access the application and view data when there is no network connection, enhance the user experience when offline, and ensure the continuity of the user experience.
[0072] The present invention also discloses a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are loaded and executed by a processor to implement the above-mentioned cross-platform data front-end display method.
[0073] It should be understood that, as is known to those of ordinary skill in the art, the term computer-readable storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules or other data). Computer-readable storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is known to those of ordinary skill in the art that communication media typically contain computer-readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and may include any information delivery medium.
[0074] The present invention also discloses a front end, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-mentioned cross-platform data front-end display method.
[0075] It should be understood that the processor may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0076] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that they can still modify or replace the technical solution of the present invention with equivalents, and these modifications or equivalent replacements cannot cause the modified technical solution to deviate from the spirit and scope of the technical solution of the present invention.
[0077] The system provided in the above embodiment is only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the modules or steps in the embodiments of the present invention can be decomposed or combined. For example, the modules in the above embodiment can be combined into one module, or further divided into multiple sub-modules to complete all or part of the functions described above. The names of the modules and steps involved in the embodiments of the present invention are only for distinguishing the modules or steps, and are not regarded as improper limitations of the present invention.
[0078] Those skilled in the art should be able to appreciate that the modules and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software or a combination of the two, and the programs corresponding to the software modules and method steps can be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disks, removable disks, CD-ROMs, or any other form of storage medium known in the technical field. In order to clearly illustrate the interchangeability of electronic hardware and software, the composition and steps of each example have been generally described in the above description according to the function. Whether these functions are performed in electronic 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.
Claims
1. A cross-platform data front-end display method, It is characterized in that The method comprises: Using a CSS framework, wherein a media query in the CSS framework is provided with a data application style corresponding to device characteristics; Detecting a user agent string, and determining the type of device, browser, and operating system used by the user based on the user agent string; Get device information based on JavaScript navigator object and device API; Determining the device characteristics based on the device information, and determining the data application style based on the device characteristics; Use CSS prefixes to determine the correct rendering style for said browser; Use the mobile adaptation framework, based on the design specifications of the operating system, and use corresponding UI components to display data according to the data application style and the correct rendering style.
2. The cross-platform data front-end display method according to claim 1, It is characterized in that The device characteristics include screen width, screen resolution, and orientation.
3. The cross-platform data front-end display method according to claim 1, It is characterized in that The device information includes device type, device identification, and device hardware information.
4. The cross-platform data front-end display method according to claim 1, It is characterized in that The mobile terminal adaptation framework is one of Bootstrap, Ant Design Mobile, and Vant.
5. The cross-platform data front-end display method according to claim 1, It is characterized in that Determining the device characteristics based on the device information includes: A device information library is set, wherein the device information library includes a device type and a device identifier, and the device type is set with a corresponding screen width, screen resolution and orientation; Based on the device type and device identification in the device information, the device characteristics are determined according to the device information library.
6. The cross-platform data front-end display method according to claim 1, It is characterized in that Before the data is displayed on the front end, it includes: Use JavaScript to monitor the network status and detect whether the user is offline through the navigator.onLine property.
7. The cross-platform data front-end display method according to claim 6, It is characterized in that The method further comprises: Use application cache to cache the application's data resources locally, and use IndexedDB or Web Storage to store the cached data resources locally. When the user is offline, use Service Workers to provide the stored data resources.
8. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are loaded and executed by a processor to implement the cross-platform data front-end display method according to any one of claims 1 to 7.
9. A front end, It is characterized in that The front end includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement the cross-platform data front-end display method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Method and system for developing cross-platform mobile terminal application
CN106445518A
Multi-terminal adaptation method based on configuration visualization product
CN115098163A
Front-end processing method and device, terminal equipment and storage medium
CN117421499A
