[关闭]
@PheonixHkbxoic 2017-05-03T13:50:26.000000Z 字数 4095 阅读 1107

MUI使用笔记

AnQuan



1. mui.init

  1. mui.init({
  2. gestureConfig:{
  3. tap: true, //默认为true
  4. doubletap: true, //默认为false
  5. longtap: true, //默认为false
  6. swipe: true, //默认为true
  7. drag: true, //默认为true
  8. hold:false,//默认为false,不监听
  9. release:false//默认为false,不监听
  10. }
  11. })

2. 日期

css:

  1. <link rel="stylesheet" type="text/css" href="../css/mui.picker.css"/>
  2. <link rel="stylesheet" type="text/css" href="../css/mui.dtpicker.min.css"/>

js:

  1. <script type="text/javascript" src="../js/mui.picker.js" ></script>
  2. <script type="text/javascript" src="../js/mui.dtpicker.min.js" ></script>
  3. <script src="../js/custom.js" ></script>

code:

  1. 开始时间,结束时间
  2. mui.each(['start_time','end_time'],function(i,id){
  3. //默认时间
  4. mui.byId(id).value = (new Date()).pattern("yyyy-MM-dd hh:mm:ss");
  5. //手动选择时间
  6. mui.byId(id).addEventListener('tap',function(e){
  7. var picker = new mui.DtPicker({});
  8. picker.show(function(rs) {
  9. mui.byId(id).value = rs.text+":"+(new Date()).pattern("yyyy-MM-dd hh:mm:ss").split(":")[2];
  10. picker.dispose();
  11. });
  12. });
  13. });

3. ActionSheet 底部弹出框选择器

初始化设置数据:

  1. var arr = new Array();
  2. var ciType = json.ciType;
  3. mui.each(ciType,function(i,type){
  4. arr.push({
  5. value:type['VALUE'],
  6. text:type['TEXT']
  7. })
  8. })
  9. catagoryPicker.setData(arr);

获取选中数据:

  1. //分类 actionsheet
  2. mui.byId("selectCatagory").addEventListener('tap', function(event) {
  3. catagoryPicker.show(function(items) {
  4. var itemCallBack=catagoryPicker.getSelectedItems();
  5. // 获取选中的键值对
  6. $('#selectCatagory').val(itemCallBack[0].text);
  7. info.data.CI_TYPE = itemCallBack[0].value;
  8. // var text = items[0]["text"];
  9. // 返回 false 可以阻止选择框的关闭
  10. //return false;
  11. });
  12. }, false);

4. ArtTemplate模板使用

js:

  1. <script src="../js/arttemplate.min.js" type="text/javascript" charset="utf-8"></script>

自己编写模板:

  1. <script id="zrdw_template" type="text/html">
  2. {{if items}}
  3. <ul class="mui-table-view">
  4. {{each items as item i}}
  5. <li class="mui-table-view-cell zrdw_bg">
  6. <a class="" href="#"><span class="mui-hidden">{{item["ID"]}}</span><span>{{item["NAME"]}}</span></a>
  7. </li>
  8. {{/each}}
  9. </ul>
  10. {{/if}}
  11. </script>

模板填充数据:

  1. var html = template("zrdw_template",{'items':info.stations})
  2. mui.byId("zrdw_wrapper").innerHTML = html;

其他非必须语法:

  1. //template 自定义helper 函数
  2. template.helper("toJsonString",function(item){
  3. return JSON.stringify(item);
  4. });
  5. 使用:
  6. {{#toJsonString(item)}}

5. scroll区域滚动

code:

  1. //区域滚动
  2. var options = {
  3. scrollY: true, //是否竖向滚动
  4. scrollX: false, //是否横向滚动
  5. startX: 0, //初始化时滚动至x
  6. startY: 0, //初始化时滚动至y
  7. indicators: true, //是否显示滚动条
  8. deceleration:0.0010, //阻尼系数,系数越小滑动越灵敏
  9. bounce: true //是否启用回弹
  10. };
  11. var scroll = mui('.mui-scroll-wrapper').scroll(options);
  12. 或者使用custom.js中已定义好的options
  1. var scroll = mui('.mui-scroll-wrapper').scroll(mui.scrollOptions);

6. textarea语音输入

html:

  1. <textarea id="textarea" rows="5" placeholder="手动输入或语音输入"
  2. class="mui-input-speech">
  3. </textarea>

code:

  1. //语音输入
  2. mui('.mui-input-row textarea').input();
  3. //获得焦点时清除里面的空白内容,不知为何有空白字符
  4. document.getElementById("textarea").onfocus = function(){
  5. this.value = this.value.replace(/[ \t]+/g,"");
  6. }
  7. //不区分全角半角重复加载 问题 转换
  8. document.getElementById("textarea").addEventListener('recognized',function(e){
  9. console.log(e.detail.value);
  10. this.value = e.detail.value.replace(/,/g,'').replace(/,。/g,'。');
  11. });

7. 重写back

  1. //重写back
  2. var bk = mui.back;
  3. mui.back = function(){
  4. if(info.saved){
  5. bk();
  6. }else{
  7. mui.confirm("信息未保存!确定要退出?","提示:",["取消","确定"],function(obj){
  8. if(obj.index==0){
  9. }else{
  10. bk();
  11. }
  12. });
  13. }
  14. }

8. Ajax

mui.ajax:

  1. var url = mui.serverAdddress+"app/appaqcheckinfo/AppAqCheckInfo.do?method=saveUpdateCheckInfo";
  2. mui.ajax(url,{
  3. //async:false,//同步
  4. dataType:'json',//服务器返回json格式数据
  5. type:'post',//HTTP请求类型
  6. data:checkInfo,
  7. success:function(json){
  8. if(!json){
  9. mui.toast("网络错误!");
  10. return;
  11. }
  12. if(json.msg=="true"){
  13. callback(json);
  14. }else{
  15. mui.toast(json.msg);
  16. }
  17. },
  18. error: function(xhr, type, errorThrown) {
  19. error = "网络错误!请重试!";
  20. mui.toast(error);
  21. console.log(xhr.readyState+"--"+type+"--"+errorThrown);
  22. }
  23. })

mui.getJSON:

  1. var url = mui.serverAdddress+"app/appaqcheckinfo/AppAqCheckInfo.do?method=queryUserNameStationNameById"
  2. mui.getJSON(url,{
  3. 'user_id':user_id,
  4. 'station_id':station_id
  5. },function(json){
  6. console.log(JSON.stringify(json));
  7. if(json&&json.msg=="true"){
  8. $(dataTomodals[1]).val(json['STATION_NAME']);
  9. $(dataTomodals[2]).val(json['USER_NAME']);
  10. info.data.CI_USER_ID = user_id;
  11. info.data.CI_DEPTMENT = station_id;
  12. }
  13. });

custom.js

  • mui.md5()
  • mui.uuid()
  • mui.myAjax()
  • String.prototype.replaceAll
  • Date.prototype.pattern
  • mui.byId()

httputil.js

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注