Home Web Front-end JS Tutorial Angularjs integrates WeChat UI (weui)

Angularjs integrates WeChat UI (weui)

Mar 16, 2017 am 09:35 AM
angularjs

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.

  1. Use angular.min.js 1.4.9

  2. Use angular-route.min.js 1.4.9

  3. Use angular-animate.min.js 1.4.9

  4. 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(&#39;button&#39;)">
        <p class="weui_grid_icon">
          <img src="./images/icon_nav_button.png" alt="">
        </p>
        <p class="weui_grid_label">
          Button
        </p>
      </a>
      <a href="#/cell" class="weui_grid js_grid" data-id="cell" ng-click="showBlock(&#39;cell&#39;)">
        <p class="weui_grid_icon">
          <img src="./images/icon_nav_cell.png" alt="">
        </p>
        <p class="weui_grid_label">
          Cell
        </p>
      </a>
      <a href="#/toast" class="weui_grid js_grid" data-id="toast" ng-click="showBlock(&#39;toast&#39;)">
        <p class="weui_grid_icon">
          <img src="./images/icon_nav_toast.png" alt="">
        </p>
        <p class="weui_grid_label">
          Toast
        </p>
      </a>
      <a href="javascript:;" class="weui_grid js_grid" data-id="dialog" ng-click="showBlock(&#39;dialog&#39;)">
        <p class="weui_grid_icon">
         <img src="./images/icon_nav_dialog.png" alt="">
        </p>
        <p class="weui_grid_label">
          Dialog
        </p>
      </a>
      <a href="javascript:;" class="weui_grid js_grid" data-id="progress" ng-click="showBlock(&#39;progress&#39;)">
        <p class="weui_grid_icon">
          <img src="./images/icon_nav_progress.png" alt="">
        </p>
        <p class="weui_grid_label">
         Progress
        </p>
      </a>
      <a href="#/msg" class="weui_grid js_grid" data-id="msg" ng-click="showBlock(&#39;msg&#39;)">
        <p class="weui_grid_icon">
          <img src="./images/icon_nav_msg.png" alt="">
        </p>
        <p class="weui_grid_label">
          Msg
        </p>
      </a>
      <a href="#/article" class="weui_grid js_grid" data-id="article" ng-click="showBlock(&#39;article&#39;)">
        <p class="weui_grid_icon">
          <img src="./images/icon_nav_article.png" alt="">
        </p>
        <p class="weui_grid_label">
          Article
        </p>
      </a>
      <a href="javascript:;" class="weui_grid js_grid" data-id="actionsheet" ng-click="showBlock(&#39;actionsheet&#39;)">
        <p class="weui_grid_icon">
          <img src="./images/icon_nav_actionSheet.png" alt="">
        </p>
        <p class="weui_grid_label">
          ActionSheet
        </p>
      </a>
      <a href="#/icons" class="weui_grid js_grid" data-id="icons" ng-click="showBlock(&#39;icons&#39;)">
        <p class="weui_grid_icon">
          <img src="./images/icon_nav_icons.png" alt="">
        </p>
        <p class="weui_grid_label">
          Icons
        </p>
      </a>
      <a href="#/panel" class="weui_grid js_grid" data-id="panel" ng-click="showBlock(&#39;panel&#39;)">
        <p class="weui_grid_icon">
          <img src="./images/icon_nav_panel.png" alt="">
        </p>
        <p class="weui_grid_label">
          Panel
        </p>
      </a>
      <a href="javascript:;" class="weui_grid js_grid" data-id="tab" ng-click="showBlock(&#39;tab&#39;)">
        <p class="weui_grid_icon">
          <img src="./images/icon_nav_tab.png" alt="">
        </p>
        <p class="weui_grid_label">
          Tab
        </p>
      </a>
      <a href="#/searchbar" class="weui_grid js_grid" data-id="searchbar" ng-click="showBlock(&#39;searchbar&#39;)">
        <p class="weui_grid_icon">
          <img src="./images/icon_nav_search_bar.png" 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>
Copy after login


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(&#39;weuiapp&#39;, [&#39;ngAnimate&#39;, &#39;ngRoute&#39;])
  .config(function($routeProvider) {
    $routeProvider
      .when(&#39;/&#39;, {
        controller: &#39;home&#39;,
        templateUrl: &#39;&#39;
      })
      .when(&#39;/button&#39;,{
        controller: &#39;button&#39;,
        templateUrl: &#39;button.html&#39;
      })
      .when(&#39;/cell&#39;, {
        controller: &#39;cell&#39;,
        templateUrl: &#39;cell.html&#39;
      })
      .when(&#39;/toast&#39;, {
        controller: &#39;toast&#39;,
        templateUrl: &#39;toast.html&#39;
      })
      .when(&#39;/msg&#39;, {
        controller: &#39;msg&#39;,
        templateUrl: &#39;msg.html&#39;
      })
      .when(&#39;/article&#39;, {
        controller: &#39;article&#39;,
        templateUrl: &#39;article.html&#39;
      })
      .when(&#39;/icons&#39;, {
        controller: &#39;icons&#39;,
        templateUrl: &#39;icons.html&#39;
      })
      .when(&#39;/panel&#39;, {
        controller: &#39;panel&#39;,
        templateUrl: &#39;panel.html&#39;
      })
      .otherwise({
        redirectTo: &#39;/&#39;
      })

  })
  .controller(&#39;home&#39;, function($scope) {
    $scope.homeShow = true;
    $scope.viewShow = false;

    $scope.showBlock = function() {
      $scope.homeShow = false;
      $scope.viewShow = true;
    }
  })
  .controller(&#39;toast&#39;, [&#39;$scope&#39;, &#39;$interval&#39;, toast])
  .animation(&#39;.aweui-show&#39;, [&#39;$animateCss&#39;, toastAnimate])
  .animation(&#39;.home&#39;, [&#39;$animateCss&#39;, function($animateCss) {
    return {
      enter: function(element, doneFn) {
        return $animateCss(element, {
          from: { left: &#39;100%&#39;, 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: &#39;-100%&#39;, top: 0, opacity: 0 },
          duration: .3
        });
      }
    }
  }])
  .animation(&#39;.view&#39;, [&#39;$animateCss&#39;, function($animateCss) {
    return {
      enter: function(element, doneFn) {
        return $animateCss(element, {
          from: { left: &#39;100%&#39;, 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: &#39;-100%&#39;, top: 0, opacity: 0 },
          duration: .3
        });
      }
    }
  }])
$scope.showBlock = function() {
  $scope.homeShow = false;
  $scope.viewShow = true;
}
Copy after login


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(&#39;.home&#39;, [&#39;$animateCss&#39;, function($animateCss) {
  return {
    enter: function(element, doneFn) {
      return $animateCss(element, {
        from: { left: &#39;100%&#39;, 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: &#39;-100%&#39;, top: 0, opacity: 0 },
        duration: .3
      });
    }
  }
}])
Copy after login


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(&#39;/&#39;, {
    controller: &#39;home&#39;,
    templateUrl: &#39;&#39;
  })
  .when(&#39;/button&#39;,{
    controller: &#39;button&#39;,
    templateUrl: &#39;button.html&#39;
  })
  .when(&#39;/cell&#39;, {
    controller: &#39;cell&#39;,
    templateUrl: &#39;cell.html&#39;
  })
  .when(&#39;/toast&#39;, {
    controller: &#39;toast&#39;,
    templateUrl: &#39;toast.html&#39;
  })
  .when(&#39;/msg&#39;, {
    controller: &#39;msg&#39;,
    templateUrl: &#39;msg.html&#39;
  })
  .when(&#39;/article&#39;, {
    controller: &#39;article&#39;,
    templateUrl: &#39;article.html&#39;
  })
  .when(&#39;/icons&#39;, {
    controller: &#39;icons&#39;,
    templateUrl: &#39;icons.html&#39;
  })
  .when(&#39;/panel&#39;, {
    controller: &#39;panel&#39;,
    templateUrl: &#39;panel.html&#39;
  })
  .otherwise({
    redirectTo: &#39;/&#39;
  })
Copy after login


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 class="page_title">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>
Copy after login


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
      });
    }
  }
}
Copy after login


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

What knowledge can be learned through WeUI on WeChat?

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The latest 5 angularjs tutorials in 2022, from entry to mastery The latest 5 angularjs tutorials in 2022, from entry to mastery Jun 15, 2017 pm 05:50 PM

Javascript is a very unique language. It is unique in terms of the organization of the code, the programming paradigm of the code, and the object-oriented theory. The issue of whether Javascript is an object-oriented language that has been debated for a long time has obviously been There is an answer. However, even though Javascript has been dominant for twenty years, if you want to understand popular frameworks such as jQuery, Angularjs, and even React, just watch the "Black Horse Cloud Classroom JavaScript Advanced Framework Design Video Tutorial".

Use PHP and AngularJS to build a responsive website to provide a high-quality user experience Use PHP and AngularJS to build a responsive website to provide a high-quality user experience Jun 27, 2023 pm 07:37 PM

In today's information age, websites have become an important tool for people to obtain information and communicate. A responsive website can adapt to various devices and provide users with a high-quality experience, which has become a hot spot in modern website development. This article will introduce how to use PHP and AngularJS to build a responsive website to provide a high-quality user experience. Introduction to PHP PHP is an open source server-side programming language ideal for web development. PHP has many advantages, such as easy to learn, cross-platform, rich tool library, development efficiency

Build web applications using PHP and AngularJS Build web applications using PHP and AngularJS May 27, 2023 pm 08:10 PM

With the continuous development of the Internet, Web applications have become an important part of enterprise information construction and a necessary means of modernization work. In order to make web applications easy to develop, maintain and expand, developers need to choose a technical framework and programming language that suits their development needs. PHP and AngularJS are two very popular web development technologies. They are server-side and client-side solutions respectively. Their combined use can greatly improve the development efficiency and user experience of web applications. Advantages of PHPPHP

Build a single-page web application using Flask and AngularJS Build a single-page web application using Flask and AngularJS Jun 17, 2023 am 08:49 AM

With the rapid development of Web technology, Single Page Web Application (SinglePage Application, SPA) has become an increasingly popular Web application model. Compared with traditional multi-page web applications, the biggest advantage of SPA is that the user experience is smoother, and the computing pressure on the server is also greatly reduced. In this article, we will introduce how to build a simple SPA using Flask and AngularJS. Flask is a lightweight Py

Use PHP and AngularJS to develop an online file management platform to facilitate file management Use PHP and AngularJS to develop an online file management platform to facilitate file management Jun 27, 2023 pm 01:34 PM

With the popularity of the Internet, more and more people are using the network to transfer and share files. However, due to various reasons, using traditional methods such as FTP for file management cannot meet the needs of modern users. Therefore, establishing an easy-to-use, efficient, and secure online file management platform has become a trend. The online file management platform introduced in this article is based on PHP and AngularJS. It can easily perform file upload, download, edit, delete and other operations, and provides a series of powerful functions, such as file sharing, search,

How to use AngularJS in PHP programming? How to use AngularJS in PHP programming? Jun 12, 2023 am 09:40 AM

With the popularity of web applications, the front-end framework AngularJS has become increasingly popular. AngularJS is a JavaScript framework developed by Google that helps you build web applications with dynamic web application capabilities. On the other hand, for backend programming, PHP is a very popular programming language. If you are using PHP for server-side programming, then using PHP with AngularJS will bring more dynamic effects to your website.

Introduction to the basics of AngularJS Introduction to the basics of AngularJS Apr 21, 2018 am 10:37 AM

The content of this article is about the basic introduction to AngularJS. It has certain reference value. Now I share it with you. Friends in need can refer to it.

How to use PHP and AngularJS for front-end development How to use PHP and AngularJS for front-end development May 11, 2023 pm 05:18 PM

With the popularity and development of the Internet, front-end development has become more and more important. As front-end developers, we need to understand and master various development tools and technologies. Among them, PHP and AngularJS are two very useful and popular tools. In this article, we will explain how to use these two tools for front-end development. 1. Introduction to PHP PHP is a popular open source server-side scripting language. It is suitable for web development and can run on web servers and various operating systems. The advantages of PHP are simplicity, speed and convenience

See all articles