小程序实现点击弹出编辑框

我的想法是点击头像的时候弹出编辑框进行修改数据,所以就有了以下的内容;

这个是我点击头像的时候弹出的修改框的效果图;代码如下;

 <span class="item-data">
                <i bindtap="modalinput">
                <image class="userinfo-avatar" src="{{userInfo.picture}}"></image>
                </i>
              </span>

这里我使用了span标签包着,用i标签进行点击事件。

<modal hidden="{{hiddenmodalput}}" title="修改个人信息" confirm-text="提交" cancel-text="重置" bindcancel="cancel" bindconfirm="confirm">

  <view> <text style="color:blue">昵称:</text> <input type='text'placeholder="请输入内容" auto-focus/></view>
   <view><text style="color:blue">省份:</text> <input type='text'placeholder="请输入内容" auto-focus/></view>
   <view><text style="color:blue">省份:</text> <input type='text'placeholder="请输入内容" auto-focus/></view>
    <view><text style="color:blue">城市:</text> <input type='text'placeholder="请输入内容" auto-focus/></view>
    <view><text style="color:blue">城市:</text> <input type='text'placeholder="请输入内容" auto-focus/></view>
    <view><text style="color:blue">性别:</text> <input type='text'placeholder="请选择性别" auto-focus/></view>
    <view><text style="color:blue">个性签名:</text> <input type='text'placeholder="请编辑个性签名" auto-focus/></view>
</modal>

这个是编辑框的内容的,这个可以放在最外面,我的是放在最外面,不影响,

接下来就是在js那里进行添加逻辑了;

 data: {
   
    userInfo: null,  
    hidden:false,
    hiddenmodalput: true,

        //可以通过hidden是否掩藏弹出框的属性,来指定那个弹出框
  },
  modalinput: function () {

    this.setData({

      hiddenmodalput: !this.data.hiddenmodalput

    })

  },

  //取消按钮

  cancel: function () {

    this.setData({

      hiddenmodalput: true

    });

  },

  //确认

  confirm: function () {

    this.setData({

      hiddenmodalput: true

    })

  },
  onChangeShowState: function () {

    var that = this;

    that.setData({

      showView: (!that.data.showView)

    })

  },
  // 弹框
  powerDrawer: function (e) {

    var currentStatu = e.currentTarget.dataset.statu;
    console.log(currentStatu);
    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
        });
        wx.showToast({
          title: '添加成功',
          icon: 'succes',
          duration: 1000,
          mask: true
        })
      }
    }.bind(this), 200)
    // 显示  
    if (currentStatu == "open") {
      this.setData({
        showModalStatus: true
      });
    }
  },

这个不需要写在生命周期函数,这样就可以实现了我第一张图的效果了,至于你的编辑框你要做成多好看,就看你自己了。

  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
实现这个功能可以采用以下步骤: 1. 在页面中添加一个图片组件,并为其绑定点击事件。 2. 点击事件触发后,弹出一个输入框组件,让用户输入文字批注。 3. 用户输入完成后,将输入的内容保存到一个数组中,并在图片上添加一个标记,标记可以是一个图标或者一个文字标签。 4. 再次点击标记时,弹出一个编辑框组件,让用户对输入的文字进行编辑。 5. 用户编辑完成后,更新保存在数组中的文本内容,并更新标记展示的内容。 具体实现可以参考以下代码: ```html <template> <view> <image src="图片地址" @click="showInput"></image> <view v-for="(note, index) in notes" :key="index"> <text class="note" :style="{left: note.left + 'px', top: note.top + 'px'}" @click="editNote(index)">{{ note.text }}</text> </view> <input v-show="show" v-model="inputValue" @confirm="addNote" placeholder="请输入文字批注"></input> <input v-show="showEdit" v-model="editValue" @confirm="updateNote" placeholder="请输入编辑后的内容"></input> </view> </template> <script> export default { data() { return { show: false, // 是否显示输入框 showEdit: false, // 是否显示编辑框 notes: [], // 存储批注信息的数组 inputValue: '', // 输入框中的值 editValue: '', // 编辑框中的值 editIndex: -1 // 当前编辑的批注在数组中的下标 } }, methods: { // 点击图片,打开输入框 showInput() { this.show = true }, // 点击输入框确定按钮,添加批注 addNote() { const left = 100 // 标记左上角距离图片左上角的横坐标 const top = 100 // 标记左上角距离图片左上角的纵坐标 const note = { text: this.inputValue, left, top } this.notes.push(note) this.show = false this.inputValue = '' }, // 点击批注,打开编辑框 editNote(index) { this.editIndex = index this.editValue = this.notes[index].text this.showEdit = true }, // 点击编辑框确定按钮,更新批注 updateNote() { this.notes[this.editIndex].text = this.editValue this.showEdit = false this.editValue = '' this.editIndex = -1 } } } </script> <style> .note { position: absolute; } </style> ``` 需要注意的是,标记的位置需要根据用户点击的位置进行计算,可以使用 `event.touches[0].pageX` 和 `event.touches[0].pageY` 获取用户点击的坐标,然后计算标记的位置。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值