小程序实现弹出输入框

1.微信自带组件

样式:

wxml

<view class="close" bindtap="close">拒绝</view>

js

Page({
  //拒绝
  close(e) {
    wx.showModal({
      editable:true,//显示输入框
      placeholderText:'输入拒绝原因',//显示输入框提示信息
      success: res => {
        if (res.confirm) { //点击了确认
          console.log(res.content)//用户输入的值
        } else {
          console.log('用户点击了取消')
        }
      }
    })
  },
})

详见:wx.showModal(Object object) | 微信开放文档

2.自定义组件

样式:

wxml

<view class="close" bindtap="close">拒绝</view><!--点击拒绝弹出-->
<block wx:if="{{isShowConfirm}}">
      <view class='toast-box'>
        <view class='toastbg'></view>
        <view class='showToast'>
            <view class='toast-main'>
                <view class='toast-input'>
                    <input type='text'  bindinput='setValue' placeholder="请输入拒绝原因" data-name='stuEidtName'></input>
                </view>
            </view>
            <view class='toast-button'>
                <view class='button1'>
                    <view catchtap='cancel'>取消</view>
                </view> 
                 <view class='button2'>
                    <view  catchtap='confirmAcceptance'>确定</view>
                </view>
            </view>
        </view>
    </view>
  </block>

 wxss

/* 弹出窗 */
.toast-box {
  width: 100%;
  height: 100%;
  opacity: 1;
  position: fixed;
  top: 0px;
  left: 0px;
}
.toastbg {
  opacity: 0.5;
  background-color: black;
  position: absolute;
  width: 100%;
  min-height: 100vh;
}

.showToast {
  position: absolute;
  opacity: 1;
  width: 80%;
  margin-left: 10%;
  margin-top: 70%;
}
.toast-main {
  padding-top: 2vh;
  padding-bottom: 2vh;
  background-color: white;
  text-align: center;
  border-top-left-radius: 16rpx;
  border-top-right-radius: 16rpx;
}

.toast-input {
  margin-left: 5%;
  margin-right: 5%;
  margin-top:10%;
  margin-bottom:10%;
  background-color: rgb(240, 240, 240);
  padding-left: 2vh;
  padding-right: 2vh;
  padding-top: 1vh;
  padding-bottom: 1vh;
}
.toast-input input{
  background-color: rgb(240, 240, 240);
}
.toast-button {
  display: flex;
  background-color: white;
  height:50px;
  width:100%;
  border-radius: 0px;
  border-bottom-left-radius: 16rpx;
  border-bottom-right-radius: 16rpx;
  border-top:1px solid rgb(211, 211, 211);
}

.button1 {
  width: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0px;
  border-bottom-left-radius: 16rpx;
}

.button2 {
  width: 50%;
  border-left:1px solid rgb(211, 211, 211);
  display: flex;
  align-items: center;
  justify-content: center;
  color:#40A4D6;
}

js

Page({
  data: {
    isShowConfirm:false
  },
  //输入框中的值
  setValue: function (e) {
    this.setData({
      walletPsd: e.detail.value
    })
  },
  //点击取消按钮
  cancel: function () {
    var that = this
    that.setData({
      isShowConfirm: false,
    })
  },
  //点击确认按钮
  confirmAcceptance:function(){
    var that = this
    that.setData({
      isShowConfirm: false,
    })
  },
  //拒绝
  close(e) {
    this.setData({
      isShowConfirm: true,
    }) 
  },
})

3.多文本框

样式:

 wxml

<view class="update" bindtap="update" data-statu="open">修改</view>
<!--弹出框-->
<view class="drawer_screen" bindtap="update" data-statu="close" wx:if="{{showModalStatus}}"></view>
<!--content-->
<!--使用animation属性指定需要执行的动画-->
<view class="animation_position">
  <view animation="{{animationData}}" class="drawer_box" wx:if="{{showModalStatus}}">
    <!--drawer content-->
    <view class="drawer_title">修改信息</view>
    <view class="drawer_content">
      <view class="grid">
        <label class="title col-0">报修人员:</label>
        <input class="input_base input_h30 col-1" bindblur="name" placeholder="请输入报修人员姓名"></input>
      </view>
      <view class="grid">
        <label class="title col-0">联系电话:</label>
        <input class="input_base input_h30 col-1" bindblur="phone" placeholder="请输入报修人员电话"></input>
      </view>
      <view class="grid">
        <label class="title col-0">维修产品:</label>
        <input class="input_base input_h30 col-1" bindblur="product" placeholder="请输入维修产品名称"></input>
      </view>
      <view class="grid">
        <label class="title col-0">故障类型:</label>
        <input class="input_base input_h30 col-1" bindblur="type" placeholder="请输入故障类型"></input>
      </view>
      <view class="bottom grid">
        <label class="title col-0">故障地点:</label>
        <input class="input_base input_h30 col-1" bindblur="address" placeholder="请输入地点"></input>
      </view>
      <view class="bottom grid">
        <label class="title col-0">故障描述:</label>
        <input class="input_base input_h30 col-1" bindblur="description" placeholder="请输入故障描述"></input>
      </view>
    </view>
    <view class="btn_ok" bindtap="update" data-statu="close">确定</view>
  </view>
  
</view>

wxss

/* 隐藏内容样式 */
/*mask*/
.drawer_screen {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  background: #000;
  opacity: 0.5;
  overflow: hidden;
}
/*content*/
.animation_position{
  display: flex;
  width:100%;
  justify-content: center;
}
.drawer_box{
  overflow: hidden;
  position: fixed;
  /* top:80px; */
  bottom:90px;
  z-index: 1001;
  background: #FAFAFA;
  border-radius: 3px;
  width: 90%;
}
.drawer_title {
  padding: 15px;
  font: 20px "microsoft yahei";
  text-align: center;
}
.drawer_content {
  overflow-y: scroll;
  /*超出父盒子高度可滚动*/
}
.btn_ok {
  margin-top:5%;
  padding: 10px;
  font: 20px "microsoft yahei";
  text-align: center;
  border-top: 1px solid #E8E8EA;
  color: #40A4D6;
}
.bottom {
  padding-bottom: 8px;
}
.title {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 25%;
  margin:5% 0 0 0;
  border-bottom: 2rpx solid #ccc;
}
.input_base {
  width:75%;
  margin:5% 0 0 0;
  padding-left:5%;
  border-bottom: 2rpx solid #ccc;
}
input {
  font: 15px "microsoft yahei";
  background: #fff;
  color: #000;
}
.grid {
  display: flex;
  margin:20px;
}

js

const app = getApp()
let id = ''
let name = ''
let phone = ''
let product = ''
let type = ''
let address = ''
let description = ''
Page({
  data: {
    showModalStatus: false,
  }, 
  //信息修改
  //获取用户输入信息
  name(event) { //获取报修人员姓名
    name = event.detail.value
    console.log("name", name)
  },
  phone(event) { //获取手机号
    phone = event.detail.value
    console.log("phone", phone)
  },
  product(event) { //维修产品
    product = event.detail.value
    console.log("produc", product)
  },
  type(event) { //故障类型
    type = event.detail.value
    console.log("type", type)
  },
  address(event) { //地址
    address = event.detail.value
    console.log("address", address)
  },
  description(event) { //描述
    description = event.detail.value
    console.log("description", description)
  },
  update: function (e) {
    var currentStatu = e.currentTarget.dataset.statu;
    this.util(currentStatu)
  },
  util: function (currentStatu) {
    /* 动画部分 */
    // 第1步:创建动画实例  
    var animation = wx.createAnimation({
      duration: 200, //动画时长 
      timingFunction: "linear", //线性 
      delay: 0 //0则不延迟 
    });
    // 第2步:这个动画实例赋给当前的动画实例 
    this.animation = animation;

    // 第3步:执行第一组动画 
    animation.opacity(0).rotateX(-100).step();

    // 第4步:导出动画对象赋给数据对象储存 
    this.setData({
      animationData: animation.export()
    })

    // 第5步:设置定时器到指定时候后,执行第二组动画 
    setTimeout(function () {
      // 执行第二组动画 
      animation.opacity(1).rotateX(0).step();
      // 给数据对象储存的第一组动画,更替为执行完第二组动画的动画对象 
      this.setData({
        animationData: animation
      })
      //关闭 
      if (currentStatu == "close") {
        this.setData({
          showModalStatus: false
        });
      }
    }.bind(this), 200)
    // 显示 
    if (currentStatu == "open") {
      this.setData({
        showModalStatus: true
      });
    }
  },
})

  • 14
    点赞
  • 67
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 微信小程序中可以使用wx.showModal()方法来弹出提示框。该方法接收一个对象作为参数,对象中可以设置提示框的标题、内容、按钮等信息。示例代码如下: ``` wx.showModal({ title: '提示', content: '这是一个弹窗提示框', success(res) { if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log('用户点击取消') } } }) ``` 其中,success回调函数中可以判断用户点击的是确定还是取消按钮,并进行相应的操作。 ### 回答2: 微信小程序的弹窗提示框是一种常用的交互方式,用于在用户与小程序交互时提供必要的提示信息或警示。通过弹窗提示框,开发者可以向用户展示文本内容、图标、按钮等交互元素。 在开发过程中,首先需要使用小程序提供的API,如wx.showModal()来实现弹窗功能。开发者可以通过设置参数,包括title(标题)、content(内容)、showCancel(是否显示取消按钮)、cancelText(取消按钮文本)、confirmText(确认按钮文本)等来控制弹窗的样式和交互行为。 弹窗提示框可以用于多种场景,比如在用户提交表单时,确认是否继续操作;在某些操作存在风险时,给予用户警示;在某些信息需要确认时,让用户选择是否继续等等。 此外,开发者还可以通过自定义组件等方式对弹窗提示框进行个性化定制,以满足特定的设计需求。 总而言之,微信小程序弹窗提示框作为一种常见的交互方式,提供了向用户展示必要信息和获取确认的功能。它在小程序开发中广泛使用,能够有效地引导用户操作,并提升用户体验。 ### 回答3: 微信小程序弹窗提示框是一个用来向用户展示提示信息的组件。它在小程序界面上以弹窗的形式出现,可用于提醒用户关键信息、警告或错误提示。弹窗提示框通常包含一个标题以及一段文字内容,并且可以通过设置不同的配置参数来满足不同的需求。 在使用弹窗提示框的过程中,我们可以通过调用wx.showModal()来弹出一个提示框。这个API接收一个对象作为参数,其中包含了标题、内容、按钮文本等相关配置信息。在用户点击弹窗按钮后,我们可以通过回调函数来处理相应的业务逻辑,如确定按钮的回调函数中处理用户确认后的操作,取消按钮的回调函数中处理用户取消后的操作。 弹窗提示框在小程序中广泛应用,它可以用于提醒用户输入错误、操作异常或者确认某种操作。通过合理地设置标题和内容,我们可以向用户传达清晰的信息,帮助用户更好地理解发生了什么以及应该如何处理。 需要注意的是,在使用弹窗提示框时,我们应该遵守用户界面设计的最佳实践,避免滥用弹窗,以免用户感到干扰和疲惫。同时,在设置弹窗内容时,应该保持简洁明了,不要过于冗长,以免用户阅读困难或疏忽重要信息。 总之,微信小程序弹窗提示框是一个非常实用的组件,在与用户进行交互和信息传递时起到了重要的作用。通过合理运用,我们可以提升用户体验,提醒用户关键信息,帮助用户更好地使用小程序

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值