wepy - 与原生有什么不同(x.wpy)使用实例

 

 

源码

  1 <template>
  2   <view class='mark' wx:if="{{showMark}}">
  3     <view animation="{{animationData}}" class="animCat">
  4       <image src="http://osk1hpe2y.bkt.clouddn.com/18-5-30/34559443.jpg"></image>
  5     </view>
  6     <button open-type="getUserInfo" lang="zh_CN" @getuserinfo="onGotUserInfo" class="css-button">开始吧!</button>
  7   </view>
  8   <!-- test-tab -->
  9   <view>
 10     <scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}">
 11       <view class="tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="swichNav">快递</view>
 12       <view class="tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="swichNav">身份证</view>
 13       <view class="tab-item {{currentTab==2?'active':''}}" data-current="2" bindtap="swichNav">银行卡号</view>
 14       <view class="tab-item {{currentTab==3?'active':''}}" data-current="3" bindtap="swichNav">手机号码</view>
 15       <view class="tab-item {{currentTab==4?'active':''}}" data-current="4" bindtap="swichNav">身材计算</view>
 16     </scroll-view>
 17     <swiper class="tab-content" current="{{currentTab}}" duration="300" bindchange="switchTab" style="height:{{winHeight}}rpx">
 18       <!-- 快递查询 -->
 19       <swiper-item wx:for="{{[0,1,2,3,4]}}" wx:key="*this">
 20         <scroll-view scroll-y="true" class="scoll-h" wx:if="{{index==0}}">
 21           <ForexpressItem :history.sync='history'></ForexpressItem>
 22         </scroll-view>
 23         <scroll-view scroll-y="true" class="scoll-h" wx:elif="{{index==1}}">
 24           <PeoPleCard></PeoPleCard>
 25         </scroll-view>
 26         <scroll-view scroll-y="true" class="scoll-h" wx:elif="{{index==2}}">
 27           <IdCard></IdCard>
 28         </scroll-view>
 29         <scroll-view scroll-y="true" class="scoll-h" wx:elif="{{index==3}}">
 30           <MobileHome></MobileHome>
 31         </scroll-view>
 32         <scroll-view scroll-y="true" class="scoll-h" wx:elif="{{index==4}}">
 33           <Figure></Figure>
 34         </scroll-view>
 35       </swiper-item>
 36     </swiper>
 37   </view>
 38 </template>
 39 
 40 <script>
 41   import wepy from 'wepy';
 42   import ForexpressItem from '@/components/express/index';
 43   import IdCard from '@/components/querys/idCard';
 44   import Figure from '@/components/querys/figure';
 45   import MobileHome from '@/components/querys/mobileHome';
 46   import PeoPleCard from '@/components/querys/peoPleCard';
 47   import {
 48     formatTime
 49   } from '@/utils/util';
 50   export default class Forexpress extends wepy.page {
 51     config = {
 52       navigationBarTitleText: '快递查询'
 53     };
 54     components = {
 55       ForexpressItem,
 56       IdCard,
 57       Figure,
 58       MobileHome,
 59       PeoPleCard
 60     };
 61     data = {
 62       showMark: false,
 63       winHeight: '', //窗口高度
 64       currentTab: 0, //预设当前项的值
 65       scrollLeft: 0, //tab标题的滚动条位置,
 66       searchArr: ['快递', '身份证', '银行卡号', '手机号码', '身材'],
 67       history: []
 68     };
 69     methods = {
 70       switchTab: function(e) {
 71         let title = `${this.searchArr[e.detail.current]}查询`;
 72         wx.setNavigationBarTitle({
 73           title: title
 74         });
 75         this.currentTab = e.detail.current;
 76         this.$apply();
 77         this.methods.checkCor.call(this);
 78       },
 79       // 点击标题切换当前页时改变样式
 80       swichNav: function(e) {
 81         let title = `${this.searchArr[e.detail.current]}查询`;
 82         wx.setNavigationBarTitle({
 83           title: title
 84         });
 85         var cur = e.target.dataset.current;
 86         if (this.data.currentTaB == cur) {
 87           return false;
 88         } else {
 89           this.currentTab = cur;
 90         }
 91       },
 92       //判断当前滚动超过一屏时,设置tab标题滚动条。
 93       checkCor: function() {
 94         if (this.data.currentTab > 3) {
 95           this.scrollLeft = 300;
 96         } else {
 97           this.scrollLeft = 0;
 98         }
 99       },
100       onShareAppMessage() {
101         return {
102           title: '武侯的猫-打造最简小工具',
103           path: 'pages/forexpress',
104           success(res) {
105             console.log(res);
106           },
107           fail(res) {
108             console.log(res);
109           }
110         };
111       },
112       onGotUserInfo(e) {
113         if (e.detail.userInfo) {
114           this.showMark = false;
115           wx.setStorage({
116             key: 'user',
117             data: e.detail.userInfo
118           });
119         }
120       }
121     };
122     onLoad() {
123       let that = this;
124       //动画
125       var animation = wx.createAnimation({
126         duration: 1200,
127         timingFunction: 'linear'
128       });
129       this.animation = animation;
130       // animation.scale(2, 2).rotate(45).step()
131       this.setData({
132         animationData: animation.export()
133       });
134       try {
135         var res = wx.getSystemInfoSync();
136         //start
137         var clientHeight = res.windowHeight,
138           clientWidth = res.windowWidth,
139           rpxR = 750 / clientWidth;
140         var calc = (clientHeight - (1 / rpxR) * 80) * rpxR;
141         console.log(calc);
142         this.winHeight = calc;
143         //end
144       } catch (e) {
145         console.log('获取设备信息失败' + e);
146       }
147     }
148     onShow() {
149       let self = this;
150       try {
151         var res = wx.getStorageSync('user');
152         console.log(res);
153         if (res) this.showMark = false;
154         if (!res) this.showMark = true;
155         self.$apply();
156       } catch (e) {
157         this.showMark = true;
158       }
159       //快递历史
160       this.history = wx.getStorageSync('saveList');
161       this.$apply();
162     }
163   }
164 </script>
165 
166 <style lang="less" scoped>
167   .save {
168     position: fixed;
169     top: 20rpx;
170     left: 20rpx;
171     border: 2rpx solid #43cd80;
172     border-radius: 8rpx;
173     font-size: 26rpx;
174     text-align: center;
175     line-height: 30rpx;
176     padding: 8rpx;
177     background-color: #43cd80;
178     z-index: 9999;
179     color: #fff;
180     box-shadow: 2rpx 2rpx 1rpx 0 grey;
181   }
182   .animCat {
183     height: 50px;
184     width: 50px;
185     image {
186       height: 50px;
187       width: 50px;
188     }
189   }
190   .css-button {
191     width: 150px;
192     margin: 50% auto;
193     background: #138cff;
194     color: #fff;
195   }
196   .scan-code {
197     margin-right: 20rpx;
198     width: 80rpx;
199     height: 80rpx;
200     text-align: center;
201     line-height: 55rpx;
202     color: #138cff;
203     font-size: 24px;
204   }
205   .iconfont {
206     color: #4cc0e9;
207   }
208   page {
209     background-color: #fff; //background-image: linear-gradient(#7FC06E, #fff, #fff);
210   }
211   .express-img-wrap {
212     height: 200rpx; //   background-image: linear-gradient(#138cff, #fff);
213   }
214   .express-img {
215     width: 100%; //   height: 200rpx;
216     position: absolute;
217     top: 10%;
218     left: 50%;
219     transform: translateX(-50%);
220   }
221   .express-input-wrap {
222     position: relative;
223     display: flex;
224     align-items: center;
225     justify-content: center; //margin-top: 210rpx;
226     //background-image: linear-gradient(#7FC06E, #fff);
227     height: 100rpx; //border-bottom: 4rpx solid #7FC06E;
228     .express-input {
229       width: 60%;
230       height: 80rpx;
231       line-height: 80rpx;
232       font-size: 35rpx;
233       padding: 0 40rpx; //padding-left: rpx;
234       border: 3rpx solid #4cc0e9;
235       border-radius: 10rpx;
236       color: #666;
237     }
238   }
239   .express-input-wrap::before {
240     transform: translatex(40rpx); //line-height: 60rpx;
241     color: #999;
242   }
243   .express-input-wrap .icon-saoma {
244     height: 80rpx;
245     position: relative;
246     font-size: 80rpx;
247     line-height: 80rpx;
248     margin-left: 10rpx;
249   }
250   .del {
251     animation: dl 1s forwards; //margin: 0;
252   }
253   @keyframes dl {
254     0% {
255       transform: translate(0, 0);
256     }
257     10% {
258       transform: translate(-100rpx, 0);
259     }
260     100% {
261       transform: translate(1000rpx, -50rpx);
262       opacity: 0;
263     }
264   }
265   .history {
266     padding: 20rpx 10rpx;
267     box-sizing: border-box; //background-color: #f00;
268     //width: 100%;
269     height: auto;
270     margin: 0rpx 10rpx;
271     margin-bottom: 20rpx;
272     overflow: hidden;
273     position: relative;
274     display: flex;
275     align-items: center;
276     border: 1rpx solid #138cff;
277     border-radius: 20rpx;
278     box-shadow: 4rpx -2rpx 4rpx #ccc;
279     background: rgba(255, 255, 255, 0.8);
280     .info-wrap {
281       display: flex;
282       width: 180rpx;
283       flex-direction: column;
284       text-align: left;
285       margin-right: 8rpx;
286       .company {
287         font-size: 30rpx;
288       }
289       .number {
290         font-size: 24rpx;
291       }
292     }
293     .last-info-wrap {
294       font-size: 24rpx;
295       color: #666;
296     }
297     .phone {
298       font-size: 40rpx; //transform: translateY(-10rpx);
299     }
300     .delete {
301       width: 40rpx;
302       height: 40rpx;
303       position: absolute;
304       top: 5rpx;
305       right: 20rpx;
306       border: 1rpx solid #ccc;
307       border-radius: 10rpx;
308       padding: 5rpx 5rpx 5rpx 12rpx;
309       background: #63b8ff;
310       color: #cd5555;
311       font-size: 16px;
312     }
313   }
314   .time {
315     padding: 8rpx 0 0;
316   }
317   .mark {
318     width: 100%;
319     height: 100%;
320     position: fixed;
321     background: rgba(0, 0, 0, 0.8);
322     top: 0;
323     z-index: 100;
324     overflow: hidden;
325   }
326   // .container .icon-sousuo-copy {
327   //   color: #138cff;
328   // }
329   //test-tab start
330   .tab-h {
331     height: 80rpx;
332     width: 100%;
333     box-sizing: border-box;
334     overflow: hidden;
335     line-height: 80rpx;
336     background: #f7f7f7;
337     font-size: 16px;
338     white-space: nowrap;
339     position: fixed;
340     top: 0;
341     left: 0;
342     z-index: 99;
343   }
344   .tab-item {
345     margin: 0 36rpx;
346     display: inline-block;
347   }
348   .tab-item.active {
349     color: #4675f9;
350     position: relative;
351   }
352   .tab-item.active:after {
353     content: '';
354     display: block;
355     height: 8rpx;
356     width: 100%;
357     background: #4675f9;
358     position: absolute;
359     bottom: 0;
360     left: 5rpx;
361     border-radius: 16rpx;
362   }
363   .item-ans {
364     width: 100%;
365     display: flex;
366     flex-grow: row no-wrap;
367     justify-content: space-between;
368     padding: 30rpx;
369     box-sizing: border-box;
370     height: 180rpx;
371     align-items: center;
372     border-bottom: 1px solid #f2f2f2;
373   }
374   .avatar {
375     width: 100rpx;
376     height: 100rpx;
377     position: relative;
378     padding-right: 30rpx;
379   }
380   .avatar .img {
381     width: 100%;
382     height: 100%;
383   }
384   .avatar .doyen {
385     width: 40rpx;
386     height: 40rpx;
387     position: absolute;
388     bottom: -2px;
389     right: 20rpx;
390   }
391   .expertInfo {
392     font-size: 12px;
393     flex-grow: 2;
394     color: #b0b0b0;
395     line-height: 1.5em;
396   }
397   .expertInfo .name {
398     font-size: 16px;
399     color: #000;
400     margin-bottom: 6px;
401   }
402   .askBtn {
403     width: 120rpx;
404     height: 60rpx;
405     line-height: 60rpx;
406     text-align: center;
407     font-size: 14px;
408     border-radius: 60rpx;
409     border: 1px solid #4675f9;
410     color: #4675f9;
411   }
412   .tab-content {
413     margin-top: 80rpx;
414   }
415   .scoll-h {
416     height: 100%;
417   }
418 </style>
View Code

 

页面模板

<style>
</style><template><view>监听值:{{num}}</view>
</template><script>
import wepy from 'wepy';let _page,_this;export default class ep extends wepy.page {data = {num: 1};// 新的,引入了例如监听watch,还有组件通讯等新概念...watch = {num(newValue, oldValue) {console.log(`num value: ${oldValue} -> ${newValue}`);}};onLoad() {console.log('页面加载');}onShow(){console.log('页面显示!');}onHide(){console.log('页面隐藏');}onUnload(){console.log('页面卸载');}
}
</script>

 

 

引入了组件化导入(相比小程序原生来说,强大很多) -> 源码在上,演示如下

 

 

 

 

转载于:https://www.cnblogs.com/cisum/p/9880068.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/249109.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vue从入门到精通之高级篇(一)vue-router的高级用法

今天要介绍的是路由元信息&#xff0c;滚动行为以及路由懒加载这几个的使用方法。 1.路由元信息 什么是路由元信息&#xff0c;看看官网的解释&#xff0c;定义路由的时候可以配置 meta 字段可以匹配meta字段&#xff0c;那么我们该如何使用它&#xff0c;一个简单的例子&…

Java 数组实现堆栈操作

class Stack {private int stck[] ; private int tos ; Stack(int size) { // 一个参数的构造参数stck new int[size] ; // 创建数组&#xff08;创建堆栈&#xff09;tos -1 ; // 空堆栈标识 -1}// 堆栈操作的特性&#xff1a;先进后出、后进先出void push(int…

re模块

什么是正则表达式 一组特殊符号组成的表达式&#xff0c;用于描述某种规则。该应用场景生活中随处可见。 例如&#xff1a;让有志青年过上体面的生活&#xff0c;这里面就由规则&#xff0c;即有志青年。 正则表达式的作用&#xff0c;以及使用场景 用于从字符串中匹配满足某种…

CSS实现div梯形分割

原理 使用的border边框属性结合svg 转换 详见代码 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>css实现div边框斜角</title><style type"text/css"> .labels {display: i…

算法学习——决策单调性优化DP

update in 2019.1.21 优化了一下文中年代久远的代码 的格式…… 什么是决策单调性&#xff1f; 在满足决策单调性的情况下&#xff0c;通常决策点会形如1111112222224444445555588888..... 即不可能会出现后面点的决策点小于前面点的决策点这种情况。 那么这个性质应该如何使用…

SVG画一个箭头

参考菜鸟手册&#xff1a; https://www.runoob.com/svg/svg-tutorial.html 打开菜鸟中的在线工具 在可视化截图拖拉元素绘制箭头 点击command U 查看源码 将源码拷入html代码中&#xff0c;查看效果 最后&#xff0c;贴出源码供大家参考 <!DOCTYPE html> <…

HP Instant Information

HP Instant Information before HP-UX 11i v3 《管理系统和工作组&#xff1a;HP-UX系统管理员指南》 After HP-UX 11i v3 《HP-UX系统管理指南》(由多个文档组成的文档集) 《HP-UX系统管理员指南&#xff1a;概述》 《HP-UX系统管理员指南&#xff1a;配置管理》 《HP-UX系统管…

CodeForces 258D Little Elephant and Broken Sorting(期望)

CF258D Little Elephant and Broken Sorting 题意 题意翻译 有一个\(1\sim n\)的排列&#xff0c;会进行\(m\)次操作&#xff0c;操作为交换\(a,b\)。每次操作都有\(50\%\)的概率进行。 求进行\(m\)次操作以后的期望逆序对个数。 \(n,m\le 1000\) 输入输出格式 输入格式&#x…

记一次vue项目yarn打包环境配置失效的解决方案

项目中使用到了yarn打包工程&#xff0c;主要有以下几个命名。 # build for production with minification yarn run build# build for production and view the bundle analyzer report yarn run build --report# 自定义API地址 baseurl"http://127.0.0.1:8080/api/&quo…

数字签名与HTTPS详解

因为HTTP协议本身存在着明文传输、不能很好的验证通信方的身份和无法验证报文的完整性等一些安全方面的确点&#xff0c;所以才有了HTTPS的缺陷。HTTPS确切的的说不是一种协议&#xff0c;而是HTTP SSL (TSL)的结合体。HTTP报文经过SSL层加密后交付给TCP层进行传输。SSL(安全套…

[BZOJ4320][ShangHai2006]Homework(根号分治+并查集)

对于<sqrt(300000)的询问&#xff0c;对每个模数直接记录结果&#xff0c;每次加入新数时暴力更新每个模数的结果。 对于>sqrt(300000)的询问&#xff0c;枚举倍数&#xff0c;每次查询大于等于这个倍数的最小数是多少&#xff0c;这个操作通过将询问逆序使用并查集支持。…

VScode 结局插件prettier和vetur格式化冲突

先上配置代码 {"workbench.iconTheme": "vscode-icons","workbench.startupEditor": "newUntitledFile","workbench.colorTheme": "One Dark Pro","editor.fontSize": 14,"editor.tabSize":…

WPF效果(GIS三维续篇)

去年这个时候简单的摸索了一下三维的GIS相关的东西,也就是仅仅玩耍了一把,这次来点真正用的上的干货效果效果&#xff1a; 1、加载自定义百度样式的瓦片效果 2、加载自定义百度样式的缩放效果 3、快速手动进去咱的大帝都 4、加载海量Mark效果 5、加载海量Mark和简单模型效果 6、…

vue 表单 验证 async-validator

1、使用插件async-validator async-validator 地址&#xff1a;https://github.com/yiminghe/async-validator 2、示例&#xff08;vueelement-ui&#xff09; <el-form :model"numberValidateForm" ref"numberValidateForm" label-width"100px&qu…

[19/04/23-星期二] GOF23_创建型模式(工厂模式、抽象工厂模式)

一、工厂模式(分为&#xff1a;简单工厂模式、工厂方法模式、抽象工厂模式) 实现了创建者和调用者的分离 核心本质&#xff1a;1、实例化对象&#xff0c;用工厂方法代替new操作&#xff1b;2、将选择实现类、创建对象统一管理和控制&#xff0c;从而将调用者跟实现类解耦。 简…

Chrome浏览器12px问题-webkit-text-size-adjust: none 已失效的解决方案

对于早期的chrome, 如果要想显示12px以下的字体&#xff0c;一般通用的方案都是在对应的元素中添加 div {-webkit-text-size-adjust: none; }但是我今天遇到的需求&#xff0c;添加了之后没有反应&#xff0c;而且浏览就根本不支持这种写法。 在网上看到了博客《Chrome浏览器…

CSRFGuard工具介绍

理解CSRFGuard的基础&#xff1a;http://www.runoob.com/jsp/jsp-tutorial.html 1&#xff1a;您需要做的第一件事是将OWASP.CSRFARGAD.JAR库复制到类路径中。放置Owasp.CsrfGuard.jar最常见的类路径位置在Web应用程序的WEB-INF文件夹的lib目录中。 OWASP CSRFGARD 3在传统Java…

[19/04/24-星期三] GOF23_创建型模式(建造者模式、原型模式)

一、建造者模式 本质&#xff1a;分离了对象子组件的单独构造(由Builder负责)和装配的分离(由Director负责)&#xff0c;从而可以构建出复杂的对象&#xff0c;这个模式适用于&#xff1a;某个对象的构建过程十分复杂 好处&#xff1a;由于构建和装配的解耦&#xff0c;不同的构…

深入理解vue中的slot与slot-scope

写在前面 vue中关于插槽的文档说明很短&#xff0c;语言又写的很凝练&#xff0c;再加上其和methods&#xff0c;data&#xff0c;computed等常用选项在使用频率、使用先后上的差别&#xff0c;这就有可能造成初次接触插槽的开发者容易产生“算了吧&#xff0c;回头再学&#…

js 转义

1. JavaScript 特殊字符 2. 正反斜杠互相替换 a/b/c.replace(/\//g,\\) // "a\b\c" $0.value.replace(/\\/g,\/) // a/b/c 获取到 而不提取出 某个值后进行直接处理 \ 有转义功能&#xff0c;所以一旦解析必然转义&#xff0c;通常是直接获取到数据源…