當(dāng)前位置:首頁 > IT技術(shù) > 微信平臺(tái) > 正文

微信小程序掃描二維碼的內(nèi)容,作為參數(shù)跳轉(zhuǎn)填入到下一個(gè)頁面input框
2021-07-28 14:46:54

scan.wxml

<view class="container">
    <view class='imagesize'>
        <image class='img' bindtap='getScancode' src="{{back}}"></image>
    </view>
    <view style="display: flex;justify-content: center;">請掃描卡號(hào)</view>
    <!-- <view wx:if="{{result !=''}}">
        <view>掃碼的內(nèi)容:{{result}}</view>
    </view> -->
    <navigator url="/pages/card/card" hover-class="changestyle">
        <view class='imagesizehand'>
            <image src="{{hand}}"></image>
        </view>
        <view style="display: flex;justify-content: center;">手動(dòng)輸入卡號(hào)</view>
    </navigator>
</view>

scan.js

//index.js
//獲取應(yīng)用實(shí)例
const app = getApp()

Page({
    data: {
        back: "../../images/scanning.png",
        hand: "../../images/hand.png",
        result: ''
    },

    onLoad: function() {
    },
    getScancode: function() {
        var _this = this;
        // 允許從相機(jī)和相冊掃碼
        wx.scanCode({
            success: (res) => {
                var result = res.result;
                _this.setData({
                    result: result,
                })

        //在回調(diào)函數(shù)里面,將獲得的返回值,帶到下一個(gè)界面里面去
       
        //三秒鐘之后跳轉(zhuǎn)到主界面
        setTimeout(function () {
          wx.navigateTo({
            url: '../card/card?result=' + result
          })
        }, 3000)

            }

      
        })
    }
})

card.wxml

<form catchsubmit="confirmPublish">
    <view class="search_arr">
        <input maxlength="15" placeholder="請輸入卡號(hào)" value="{{deviceId}}" data-name="deviceId" bindblur="setInput"></input>
    </view>
    <button class='btn1' bindtap="bindViewTap" form-type="submit">綁定</button>
</form>

card.js

// pages/card/card.js
Page({

    /**
     * 頁面的初始數(shù)據(jù)
     */
    data: {
        id: 1,
        deviceId: '',
    },

    //事件處理函數(shù)

    bindViewTap: function() {
        wx.navigateTo({
            url: '../cardsuccess/cardsuccess'
        })
        //三秒鐘之后跳轉(zhuǎn)到主界面
        setTimeout(function() {
            wx.switchTab({
                url: '../index/index'
            })
        }, 3000)
    },

    /**
     * 生命周期函數(shù)--監(jiān)聽頁面加載
     */
    onLoad: function(options) {
    console.log(options)
    // 生命周期函數(shù)--監(jiān)聽頁面加載
    this.setData({
      deviceId: options.result,
  
    })
    },

    confirmPublish: function() {
        // if (!this.data.taskName) {
        //   this.setData({ errortip: true, errorMsg: '任務(wù)名不能為空' })
        //   setTimeout(() => {
        //     this.setData({ errortip: false, errorMsg: '' })
        //   }, 2000)
        //   return
        // }


        // const data = {}
        // data.id = this.data.id
        // data.deviceId = this.data.deviceId
        var params = {

            id: 1,
            deviceId: "12345678",
        }


        wx.request({
            url: 'http://192.xxx.4.103:8093/cs-applet/subscribe/bindingCard',
            method: 'PUT',
            data: params,
            dataType: "json",
            success: function(res) {
                // console.log(res)
                // if (res.data.code === "0001") {
                //   wx.showToast({
                //     title: res.data.msg,
                //     icon: 'none',
                //     duration: 2000
                //   })
                //   return;
                // }
                // wx.showToast({
                //   title: '添加成功',
                //   icon: 'success',
                //   duration: 2000
                // })
                // setTimeout(() => {
                //   wx.switchTab({
                //     url: "/pages/index/index?refresh=true",
                //   });
                // }, 1000);
            },
            fail: function(error) {
                wx.showToast({
                    title: error.message || '保存失敗'
                })
                console.log(error)
            }
        })
    },

    /**
     * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函數(shù)--監(jiān)聽頁面顯示
     */
    onShow: function() {

    },

    /**
     * 生命周期函數(shù)--監(jiān)聽頁面隱藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函數(shù)--監(jiān)聽頁面卸載
     */
    onUnload: function() {

    },

    /**
     * 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 頁面上拉觸底事件的處理函數(shù)
     */
    onReachBottom: function() {

    },

    /**
     * 用戶點(diǎn)擊右上角分享
     */
    onShareAppMessage: function() {

    }
})
微信小程序掃描二維碼的內(nèi)容,作為參數(shù)跳轉(zhuǎn)填入到下一個(gè)頁面input框_easyui
微信小程序掃描二維碼的內(nèi)容,作為參數(shù)跳轉(zhuǎn)填入到下一個(gè)頁面input框_easyui_02

本文摘自 :https://blog.51cto.com/u

開通會(huì)員,享受整站包年服務(wù)立即開通 >