├── .gitignore ├── LICENSE ├── README.md ├── app.js ├── app.json ├── app.wxss ├── images ├── arrowright.png └── demo.gif ├── pages ├── example │ ├── common │ │ └── header.wxml │ ├── example.js │ ├── example.json │ ├── example.wxml │ └── example.wxss └── index │ ├── index.js │ ├── index.wxml │ └── index.wxss └── utils └── wxquery.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2016 Stephen Yang, http://stephen.ml 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | wxQuery 2 | ------- 3 | 4 | 对 Page.prototype.setData() 函数的封装 5 | 6 | ![image](https://raw.githubusercontent.com/stephenml/wx-query/master/images/demo.gif) 7 | 8 | ## Thanks 9 | * 云淡风轻 -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | var wxQuery = require('./utils/wxquery.js'); 2 | 3 | App({ 4 | /** 全局引入wxQuery */ 5 | wxQuery : wxQuery, 6 | $ : wxQuery.$ 7 | }) -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages" : [ 3 | "pages/index/index", 4 | "pages/example/example" 5 | ], 6 | "window" : { 7 | "backgroundTextStyle" : "light", 8 | "navigationBarBackgroundColor" : "#1AAD16", 9 | "navigationBarTitleText" : "wxQuery", 10 | "navigationBarTextStyle" : "white" 11 | }, 12 | "debug" : true 13 | } -------------------------------------------------------------------------------- /app.wxss: -------------------------------------------------------------------------------- 1 | page { 2 | background-color : #FBF9FE; 3 | height : 100%; 4 | } 5 | 6 | .container { 7 | display : flex; 8 | flex-direction : column; 9 | min-height : 100%; 10 | justify-content : space-between; 11 | } 12 | 13 | .page-header { 14 | display : flex; 15 | font-size : 32rpx; 16 | color : #aaa; 17 | margin-top : 50rpx; 18 | flex-direction : column; 19 | align-items : center; 20 | } 21 | 22 | .page-header-text { 23 | padding : 20rpx 40rpx; 24 | } 25 | 26 | .page-header-line { 27 | width : 150rpx; 28 | height : 1px; 29 | border-bottom : 1px solid #CCCCCC; 30 | } 31 | 32 | .page-body { 33 | width : 100%; 34 | display : flex; 35 | flex-direction : column; 36 | align-items : center; 37 | flex-grow : 1; 38 | overflow-x : hidden; 39 | } -------------------------------------------------------------------------------- /images/arrowright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stephenml/wx-query/9a37e0275167a85d2b8be0f24da76b88acb652b9/images/arrowright.png -------------------------------------------------------------------------------- /images/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stephenml/wx-query/9a37e0275167a85d2b8be0f24da76b88acb652b9/images/demo.gif -------------------------------------------------------------------------------- /pages/example/common/header.wxml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pages/example/example.js: -------------------------------------------------------------------------------- 1 | var app = getApp(); 2 | 3 | Page({ 4 | name : 'example', /** 如果绑定事件 需要注册一个name属性 */ 5 | data : { 6 | methods : [ 7 | { 8 | id : '1', 9 | name : '隐藏' 10 | }, 11 | { 12 | id : '2', 13 | name : '显示' 14 | }, 15 | { 16 | id : '3', 17 | name : '显示/隐藏' 18 | }, 19 | { 20 | id : '4', 21 | name : '添加样式' 22 | }, 23 | { 24 | id : '5', 25 | name : '移除样式' 26 | }, 27 | { 28 | id : '6', 29 | name : '添加/移除样式' 30 | }, 31 | { 32 | id : '7', 33 | name : '添加class' 34 | }, 35 | { 36 | id : '8', 37 | name : '移除class' 38 | }, 39 | { 40 | id : '9', 41 | name : '添加/移除class' 42 | }, 43 | { 44 | id : '10', 45 | name : '绑定事件' 46 | }, 47 | { 48 | id : '11', 49 | name : '移除事件' 50 | }, 51 | { 52 | id : '12', 53 | name : '...' 54 | } 55 | ], 56 | modal : { 57 | hidden : true 58 | } 59 | }, 60 | onLoad : function () { 61 | /** 注册事件源 */ 62 | app.wxQuery.register(this); 63 | 64 | var $modal = app.$('modal'); 65 | $modal.bind('confirm', function (e) { 66 | $modal.setValue('hidden', true); 67 | }); 68 | 69 | var $block = app.$('block'); 70 | 71 | /** 隐藏 */ 72 | app.$('1').bind('tap', function (e) { 73 | $block .hide(); 74 | }); 75 | 76 | /** 显示 */ 77 | app.$('2').bind('tap', function (e) { 78 | $block .show(); 79 | }); 80 | 81 | /** 显示/隐藏 */ 82 | app.$('3').bind('tap', function (e) { 83 | $block .toggle(); 84 | }); 85 | 86 | /** 添加样式 */ 87 | app.$('4').bind('tap', function (e) { 88 | $block .addStyle({"background-color" : '#1AAD16'}).show(); 89 | }); 90 | 91 | /** 移除样式 */ 92 | app.$('5').bind('tap', function (e) { 93 | $block .removeStyle({"background-color" : '#1AAD16'}).show(); 94 | }); 95 | 96 | /** 添加/移除样式 */ 97 | app.$('6').bind('tap', function (e) { 98 | $block .toggleStyle({"background-color" : '#1AAD16'}).show(); 99 | }); 100 | 101 | /** 添加class */ 102 | app.$('7').bind('tap', function (e) { 103 | $block.addClass('round', 'transform').show(); 104 | }) 105 | 106 | /** 移除class */ 107 | app.$('8').bind('tap', function (e) { 108 | $block.removeClass('round', 'transform').show(); 109 | }) 110 | 111 | /** 添加/移除class */ 112 | app.$('9').bind('tap', function (e) { 113 | $block.toggleClass('round', 'transform').show(); 114 | }) 115 | 116 | /** 绑定事件 */ 117 | app.$('10').bind('tap', function (e) { 118 | $block.bind('tap', function (e) { 119 | $modal.text('我绑定了事件').setValue('hidden', false); 120 | }).show(); 121 | }) 122 | 123 | /** 移除事件 */ 124 | app.$('11').bind('tap', function (e) { 125 | $block.unbind('tap').show(); 126 | $modal.text('我的事件移除了').setValue('hidden', false); 127 | }) 128 | 129 | /** 待添加 */ 130 | app.$('12').bind('tap', function (e) { 131 | console.log('coding...'); 132 | }) 133 | }, 134 | onShow : function () { 135 | /** 重新注册事件源 */ 136 | app.wxQuery.register(this); 137 | }, 138 | /** 139 | * 事件处理 140 | */ 141 | eventManage : function (e) { 142 | app.wxQuery.callEvent(e); 143 | } 144 | }); -------------------------------------------------------------------------------- /pages/example/example.json: -------------------------------------------------------------------------------- 1 | { 2 | "navigationBarTitleText" : "样例" 3 | } -------------------------------------------------------------------------------- /pages/example/example.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |