You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xzjl-ui/pages/index/index.js

163 lines
3.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// pages/index/index.js
const app = getApp();//新建页面时 默认引入
const req = app.simpleReq();//初始化一个的request() 实例
// 导入包
import WxmpRsa from 'wxmp-rsa'
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
},
toUrl(){
wx.switchTab({
url: '/pages/home/xy/index'
})
},
go2Get(){
wx.navigateTo({
url: '/pages/index/out/out'
})
},
scanCodeEvent(){
var that = this;
var DEV_CODE = "34ADE4201285"
//扫码代码
wx.scanCode({
onlyFromCamera: true,// 只允许从相机扫码
success(res){
console.log("扫码成功:"+JSON.stringify(res))
DEV_CODE = res.result
},
fail (err) {
// console.log(err)
wx.showToast({
title:'扫描失败',
icon: 'none',
duration: 1000
})
}
})
var PUBLIC_KEY = ""
req.getRequest('/api/dict/value/login-public-key',{}).then((res)=>{
if(res.data.code==200){//扫码登录成功
PUBLIC_KEY = res.data.data
console.log(PUBLIC_KEY)
// 实例化rsa
const rsa = new WxmpRsa()
// 设置公钥
rsa.setPublicKey(PUBLIC_KEY)
// 加密
const mac = rsa.encryptLong(DEV_CODE)
console.log('加密后的结果:', mac)
// 此处执行登录获取token操作
req.postRequest('/api/user/login',{'mac':mac}).then((res)=>{
wx.setStorageSync('token', res.data.data)
console.log('token是'+res.data.data)
wx.showToast({
title:'扫描登录成功',
icon: 'none',
duration: 1000
})
wx.switchTab({
url: '/pages/home/xy/index'
})
}
)
}
console.log(res);
}).catch((err)=>{
console.log(err);
})
//调用RSA加密
/*wx.scanCode({
onlyFromCamera: true,// 只允许从相机扫码
success(res){
console.log("扫码成功:"+JSON.stringify(res))
// 扫码成功后 在此处理接下来的逻辑
that.setData({
scanCode: res.result//扫描得到的结果
})
//that.query();//扫描成功后调用查询方法
},
fail (err) {
// console.log(err)
wx.showToast({
title:'扫描失败',
icon: 'none',
duration: 1000
})
// 扫码成功后 在此处理接下来的逻辑
that.setData({
scanCode: '',c:0,cc:0,ccc:0,t:0
})
}
})*/
}
})