zoukankan      html  css  js  c++  java
  • 九: 操作提示(js版本)

    一、toast 消息提示框
    他用到了一个wx.showToast(object) 这样一个方法。作用是显示提示框。
    /* ---page/test/test.wxml----*/
     
    <button bindtap="binToast">toast<button/>
     
    /* ---page/test/test.wxml----*/
    /* ---page/test/test.js----*/
    Page({
     
      binToast:function(){
        wx.showToast({
          title: '成功',
          icon: 'success',
          duration: 2000
        })
      },
     
    })
    /* ---page/test/test.js----*/
    参数类型必填说明
    title String 提示的内容
    icon String 图标,只支持"success"、"loading"
    duration Number 提示的延迟时间,单位毫秒,默认:1500, 最大为10000
    success Function 接口调用成功的回调函数
    fail Function 接口调用失败的回调函数
    complete Function 接口调用结束的回调函数(调用成功、失败都会执行)
    如果是wxml的写法 那么loading和toast会写两个标签 其实他们使用的方法都是一样的。。所以那种写法很难受。不过js的这种写法很好的解决了这个问题。来看一下loading
     
    二、loading 加载
    他用到了一个wx.hideToast()作用是隐藏提示框。我们展示了提示框之后。可以选择什么时候关掉他。。这样就起到了加载的作用。
    /* ---page/test/test.wxml----*/
    <button bindtap="binLoading">binLoading<button/>
    /* ---page/test/test.wxml----*/
    /* ---page/test/test.js----*/
    Page({
     
      binLoading:function(){
        wx.showToast({
          title: '加载中',
          icon: 'loading',
          duration: 10000
        })
     
        setTimeout(function(){
          wx.hideToast()
        },2000)
     
      },
     
    })
     
    /* ---page/test/test.js----*/
    可以看到这个方法。。。虽然给了duration:10000毫秒后自动消失的属性,可是用了一个用setTimeout来控制时间2秒后关闭 toast 。所以时间就不用等10秒那么麻烦了。
    其实 可以把setTimeout 换成ajax 取值。这样等异步取值完之后在执行wx.hideToast()那么就形成了一个加载的样子。
     
    三、modal 对话框
    参数类型必填说明
    title String 提示的标题
    content String 提示的内容
    showCancel Boolean 是否显示取消按钮,默认为 true
    cancelText String 取消按钮的文字,默认为"取消",最多 4 个字符
    cancelColor HexColor 取消按钮的文字颜色,默认为"#000000"
    confirmText String 确定按钮的文字,默认为"确定",最多 4 个字符
    confirmColor HexColor 确定按钮的文字颜色,默认为"#3CC51F"
    success Function 接口调用成功的回调函数,返回res.confirm为true时,表示用户点击确定按钮
    fail Function 接口调用失败的回调函数
    complete Function 接口调用结束的回调函数(调用成功、失败都会执行)
    /* ---page/test/test.wxml----*/
    <button bindtap="bindModal">Modal<button/>
    /* ---page/test/test.wxml----*/
    /* ---page/test/test.js----*/
    Page({
     
      bindModal:function(){
        wx.showModal({
          title: '提示',
          content: '这是一个模态弹窗',
          success: function(res) {
            if (res.confirm) {
              console.log('用户点击确定')
            }
          }
        })
      },
     
    })
    /* ---page/test/test.js----*/
    需要注意的就是success毁掉函数的 res.confirm了 当为true的时候 则表示用户点击了确定。
     
    四、action-sheet 操作菜单
    参数类型必填说明
    itemList String Array 按钮的文字数组,数组长度最大为6个
    itemColor HexColor 按钮的文字颜色,默认为"#000000"
    success Function 接口调用成功的回调函数,详见返回参数说明
    fail Function 接口调用失败的回调函数
    complete Function 接口调用结束的回调函数(调用成功、失败都会执行)
    /* ---page/test/test.wxml----*/
    <button bindtap="bindActionSheet">ActionSheet<button/>
    /* ---page/test/test.wxml----*/
    /* ---page/test/test.js----*/
    Page({
     
      bindActionSheet:function(){
        wx.showActionSheet({
          itemList: ['A''B''C'],
          success: function(res) {
            if (!res.cancel) {
              console.log(res.tapIndex)
            }
          }
        })
      },
     
    })
    /* ---page/test/test.js----*/
    这里则跟wxml完全不一样  。这里则是利用res.tapIndex 来获取 用户选的是那个选项。而且也不用像wxml那么麻烦每次还要手动去隐藏。。不过看需求。有利也有弊。

     
     
  • 相关阅读:
    SQL操作全集 sql精典收藏
    sql中全角字符与半角字符检验问题
    asp.net目录权限设置图文综合[转]
    XPath 语法
    XPath学习
    接口使用例子,阐述接口的优点、作用
    sql查询出表中所有列名 判断两个表中的列是否相同
    指定键让指定的按钮提交
    C#.Net网络程序开发Socket篇
    ASP.NET中异常处理使用
  • 原文地址:https://www.cnblogs.com/dandingjun/p/6088226.html
Copyright © 2011-2022 走看看