What this article recommends is to use angularjs to implement the entire process of integrating WeChat’s newly launched UI (weui). Friends who have the same needs can refer to the following
Introduction
Not long ago, WeChat launched its own set of UI. I see that many developers have applied it to some front-end frameworks, such as react and vue. . Recently I am learning Angularjs, so I also want to integrate this UI into this framework. I have tried it in the past few days and simply applied a function. Now I will share it with you. If the separation is not done well, please give some advice from an expert.
Suitable for readers
who have a certain foundation of Angularjs and understand ngRoute and ngAnimate.
Includes files
When integrating, refer to the official demo page and made a demo page myself, completely using Angularjs Made without referencing other frameworks. Let's first explain the imported files.
Use angular.min.js 1.4.9
Use angular-route.min.js 1.4.9
Use angular-animate.min.js 1.4.9
Use weui.min.css 0.4.0
At first, I wanted to make a single page like the official demo page. After development, I found that putting all the content into one file was too messy. Therefore, I used the routing function of Angularjs to separate each small function into separate pages. Load in when needed. This is achieved using the template loading function. Therefore, the navigation page code is displayed very cleanly. If you want to use which part of the function code, you can directly use the corresponding html page and js script file, which is convenient and fast.
The following is the code for the navigation page:
<!DOCTYPE html> <html lang="en" ng-app="weuiapp"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0"> <title>WeUI</title> <link rel="stylesheet" href="./css/weui.css" /> </head> <style type="text/css"> .home, .view { position: absolute; width: 100%; left: 0; top: 0; } </style> <body ng-controller="home"> <p class="home" ng-if="homeShow"> <p class="weui_grids"> <a href="#/button" class="weui_grid js_grid" data-id="button" ng-click="showBlock('button')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_button.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> Button </p> </a> <a href="#/cell" class="weui_grid js_grid" data-id="cell" ng-click="showBlock('cell')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_cell.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> Cell </p> </a> <a href="#/toast" class="weui_grid js_grid" data-id="toast" ng-click="showBlock('toast')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_toast.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> Toast </p> </a> <a href="javascript:;" class="weui_grid js_grid" data-id="dialog" ng-click="showBlock('dialog')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_dialog.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> Dialog </p> </a> <a href="javascript:;" class="weui_grid js_grid" data-id="progress" ng-click="showBlock('progress')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_progress.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> Progress </p> </a> <a href="#/msg" class="weui_grid js_grid" data-id="msg" ng-click="showBlock('msg')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_msg.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> Msg </p> </a> <a href="#/article" class="weui_grid js_grid" data-id="article" ng-click="showBlock('article')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_article.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> Article </p> </a> <a href="javascript:;" class="weui_grid js_grid" data-id="actionsheet" ng-click="showBlock('actionsheet')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_actionSheet.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> ActionSheet </p> </a> <a href="#/icons" class="weui_grid js_grid" data-id="icons" ng-click="showBlock('icons')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_icons.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> Icons </p> </a> <a href="#/panel" class="weui_grid js_grid" data-id="panel" ng-click="showBlock('panel')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_panel.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> Panel </p> </a> <a href="javascript:;" class="weui_grid js_grid" data-id="tab" ng-click="showBlock('tab')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_tab.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> Tab </p> </a> <a href="#/searchbar" class="weui_grid js_grid" data-id="searchbar" ng-click="showBlock('searchbar')"> <p class="weui_grid_icon"> <img src="/static/imghwm/default1.png" data-src="./images/icon_nav_search_bar.png" class="lazy" alt=""> </p> <p class="weui_grid_label"> SearchBar </p> </a> </p> </p> <p class="view" ng-view ng-if="viewShow"></p> <script type="text/javascript" src="./js/angular.min.js"></script> <script type="text/javascript" src="./js/angular-animate.min.js"></script> <script type="text/javascript" src="./js/angular-route.min.js"></script> <script type="text/javascript" src="./js/toast.js"></script> <script type="text/javascript" src="./js/example.js"></script> </body> </html>
Most of the above codes come from the official homepage code. Since Angularjs is used, corresponding attributes are added, including ngApp, ngController, ngClick, ngIf and ngView that displays the function demonstration page.
In the code, the showBlock function is used in ngClick. The parameter is the function string of the current click. The parameters of this function are not used after using the routing function. Only the hidden and displayed navigation is added to this function. part and function demonstration part of the code, please see the script code below for details.
angular.module('weuiapp', ['ngAnimate', 'ngRoute']) .config(function($routeProvider) { $routeProvider .when('/', { controller: 'home', templateUrl: '' }) .when('/button',{ controller: 'button', templateUrl: 'button.html' }) .when('/cell', { controller: 'cell', templateUrl: 'cell.html' }) .when('/toast', { controller: 'toast', templateUrl: 'toast.html' }) .when('/msg', { controller: 'msg', templateUrl: 'msg.html' }) .when('/article', { controller: 'article', templateUrl: 'article.html' }) .when('/icons', { controller: 'icons', templateUrl: 'icons.html' }) .when('/panel', { controller: 'panel', templateUrl: 'panel.html' }) .otherwise({ redirectTo: '/' }) }) .controller('home', function($scope) { $scope.homeShow = true; $scope.viewShow = false; $scope.showBlock = function() { $scope.homeShow = false; $scope.viewShow = true; } }) .controller('toast', ['$scope', '$interval', toast]) .animation('.aweui-show', ['$animateCss', toastAnimate]) .animation('.home', ['$animateCss', function($animateCss) { return { enter: function(element, doneFn) { return $animateCss(element, { from: { left: '100%', top: 0, opacity: 0 }, to: { left: 0, top: 0, opacity: 1 }, duration: .3 }); }, leave: function(element, doneFn) { return $animateCss(element, { from: { left: 0, top: 0, opacity: 1 }, to: { left: '-100%', top: 0, opacity: 0 }, duration: .3 }); } } }]) .animation('.view', ['$animateCss', function($animateCss) { return { enter: function(element, doneFn) { return $animateCss(element, { from: { left: '100%', top: 0, opacity: 0 }, to: { left: 0, top: 0, opacity: 1 }, duration: .3 }); }, leave: function(element, doneFn) { return $animateCss(element, { from: { left: 0, top: 0, opacity: 1 }, to: { left: '-100%', top: 0, opacity: 0 }, duration: .3 }); } } }]) $scope.showBlock = function() { $scope.homeShow = false; $scope.viewShow = true; }
This section is the functional code to be implemented by the function. It controls the variables homeShow and viewShow respectively to implement navigation and function demonstration. Showing and hiding the two parts.
.animation('.home', ['$animateCss', function($animateCss) { return { enter: function(element, doneFn) { return $animateCss(element, { from: { left: '100%', top: 0, opacity: 0 }, to: { left: 0, top: 0, opacity: 1 }, duration: .3 }); }, leave: function(element, doneFn) { return $animateCss(element, { from: { left: 0, top: 0, opacity: 1 }, to: { left: '-100%', top: 0, opacity: 0 }, duration: .3 }); } } }])
The above is the animation effect code when the navigation part is displayed. The navigation part is initialized to absolute positioning, so that it moves out of the display area to the left and fades out before disappearing. After viewing the function demonstration and returning to the navigation, the animation is reversed. The $animateCss service of ngAnimate is used here, and the entry event enter and the exit event leave provided by this service are used. Other animation functions are the same.
$routeProvider .when('/', { controller: 'home', templateUrl: '' }) .when('/button',{ controller: 'button', templateUrl: 'button.html' }) .when('/cell', { controller: 'cell', templateUrl: 'cell.html' }) .when('/toast', { controller: 'toast', templateUrl: 'toast.html' }) .when('/msg', { controller: 'msg', templateUrl: 'msg.html' }) .when('/article', { controller: 'article', templateUrl: 'article.html' }) .when('/icons', { controller: 'icons', templateUrl: 'icons.html' }) .when('/panel', { controller: 'panel', templateUrl: 'panel.html' }) .otherwise({ redirectTo: '/' })
This is a routing service, corresponding to the href attribute of the a tag in html, so the showBlock function is not used in this program The parameters are no longer useful. This function was only created to add dynamic effects.
Next, let’s take a look at the page code of the function demonstration part.
<p class="page"> <p class="hd"> <h1 id="Toast">Toast</h1> </p> <p class="bd spacing"> <a href="javascript:;" class="weui_btn weui_btn_primary" ng-click="showToast()">点击弹出Toast</a> <a href="javascript:;" class="weui_btn weui_btn_primary" ng-click="showLoadingToast()">点击弹出Loading Toast</a> </p> <!--BEGIN toast--> <p id="toast" ng-if="toastHide" class="aweui-show"> <p class="weui_mask_transparent"></p> <p class="weui_toast"> <i class="weui_icon_toast"></i> <p class="weui_toast_content">已完成</p> </p> </p> <!--end toast--> <!-- loading toast --> <p id="loadingToast" ng-if="loadingToastHide" class="weui_loading_toast aweui-show"> <p class="weui_mask_transparent"></p> <p class="weui_toast"> <p class="weui_loading"> <p class="weui_loading_leaf weui_loading_leaf_0"></p> <p class="weui_loading_leaf weui_loading_leaf_1"></p> <p class="weui_loading_leaf weui_loading_leaf_2"></p> <p class="weui_loading_leaf weui_loading_leaf_3"></p> <p class="weui_loading_leaf weui_loading_leaf_4"></p> <p class="weui_loading_leaf weui_loading_leaf_5"></p> <p class="weui_loading_leaf weui_loading_leaf_6"></p> <p class="weui_loading_leaf weui_loading_leaf_7"></p> <p class="weui_loading_leaf weui_loading_leaf_8"></p> <p class="weui_loading_leaf weui_loading_leaf_9"></p> <p class="weui_loading_leaf weui_loading_leaf_10"></p> <p class="weui_loading_leaf weui_loading_leaf_11"></p> </p> <p class="weui_toast_content">数据加载中</p> </p> </p> </p>
This is the demo page code for loading the waiting prompt function. There are two styles in total. One is to display text; Second, there is a loading waiting animation and prompt text is displayed.
There are two buttons on the page. Their function is to exhale these two styles respectively. After each style is exhaled, it will automatically disappear after 3 seconds.
In the js of the navigation page, there is a controller and an animation function that call the functions in the script code of this function page, namely the controller function toast() and the animation function toastAnimate(). The code of the script file is as follows.
//toast控制器 function toast($scope, $interval) { $scope.toastHide = 0; $scope.loadingToastHide = 0; $scope.showToast = function() { $scope.toastHide = 1; $interval(function() { $scope.toastHide = 0; }, 3000, 1); } $scope.showLoadingToast = function() { $scope.loadingToastHide = 1; $interval(function() { $scope.loadingToastHide = 0; }, 3000, 1); } } //显示与隐藏时的动画,使用ngAnimate中的$animateCss服务 function toastAnimate($animateCss) { return { enter: function(element, doneFn) { return $animateCss(element, { from: { opacity: 0 }, to: { opacity: 1 }, duration: .3 }); }, leave: function(element, doneFn) { return $animateCss(element, { from: { opacity: 1 }, to: { opacity: 0 }, duration: .3 }); } } }
At this point, navigation and a function demonstration page have been implemented. Since most of the UI is static and not dynamic, you only need to copy the official demo. If it is necessary to add dynamic code, we have only done this one now, and will continue to add it to completion in the future.
Related articles:
How to upload images through WeChat WEUI, how to handle it with PHP in the background?
Encapsulation of JS pop-up layers for commonly used information prompts in WEUI applications

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version
