zoukankan      html  css  js  c++  java
  • 微信小程序 获取剪切板上的内容

    前言:

    为了开发一个去水印的小程序,用到了读取剪切板复制粘贴的功能

    开发思路:

    1、获取剪切板
    2、正则判断并截取视频URL
    3、弹出对话框是否粘贴

    用到的技术:

    1、微信官方文档(剪切板)

    wx.setClipboardData({   //设置剪切板
      data: 'data',
      success (res) {
        wx.getClipboardData({ //获取剪切板
          success (res) {
            console.log(res.data) // data
          }
        })
      }
    })
    

    2、正则

    handleUrl(t) {var e = /(http://|https://)((w|=|?|.|/|&|-)+)/g;return !!(t = t.match(e)) && t[0];)
    

    3、全部代码

     data:{
       value:null
     }
    handleUrl(t) {var e = /(http://|https://)((w|=|?|.|/|&|-)+)/g;return !!(t = t.match(e)) && t[0];
    onShow: function () {
     let that = this
     wx.getClipboardData({
       success: function (res) { // 匹配地址
         let result = handleUrl(res.data);
         // 如果地址相同则不在显示
         if (result == that.data.value) {
           return;
         }
         wx.showModal({
           title: '检测到视频链接,是否粘贴?',
           content: result,   //这个地方会提示报错改成string格式就行
           showCancel: true, //是否显示取消按钮cancelText: "取消",//默认是“取消”
           cancelColor: '#8799a3', //取消文字的颜色
           confirmText: "粘贴", //默认是“确定”
           confirmColor: '#3385FF', //确定文字的颜色
           success: function (res) {
             if (res.cancel) {
    
             } else {
               that.setData({
                 value: result,  //赋值到输入框
               })
             }
           },
         })
       },
       fail: function (res) {},
       complete: function (res) {},
     })
    }
    

  • 相关阅读:
    [背包]JZOJ 3232 【佛山市选2013】排列
    内核空间、用户空间、虚拟地址
    进程与线程的概念
    Python中字符串颜色
    socket编程
    模块与包
    常用模块
    面向对象进阶
    面向对象编程
    函数式编程
  • 原文地址:https://www.cnblogs.com/yx-liu/p/15206472.html
Copyright © 2011-2022 走看看