初始化项目
This commit is contained in:
261
Web/pages/login/login.js
Normal file
261
Web/pages/login/login.js
Normal file
@@ -0,0 +1,261 @@
|
||||
// pages/login.js
|
||||
// app.js
|
||||
const app = getApp()
|
||||
import {
|
||||
settoken,
|
||||
Login,
|
||||
getopenid,
|
||||
AddLogin,
|
||||
Shuruusernamebyquanxian
|
||||
} from '../../lib/RequestingCenter.js'
|
||||
Page({
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
login: false,
|
||||
islong: false,
|
||||
Uid: null,
|
||||
Pwd: null,
|
||||
openid: "",
|
||||
show: false,
|
||||
option1: [
|
||||
{
|
||||
value: 0,
|
||||
text: "请选择数据库"
|
||||
},
|
||||
],
|
||||
// 数据库编号
|
||||
Sqlid: 0,
|
||||
//机型
|
||||
value1: 0,
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
//下拉框选择
|
||||
onConfirm(o) {
|
||||
var that = this;
|
||||
let pid = o.detail
|
||||
console.log(pid)
|
||||
console.log(o)
|
||||
|
||||
that.setData({
|
||||
Sqlid: pid
|
||||
});
|
||||
},
|
||||
onLoad: function (options) {
|
||||
|
||||
var that = this;
|
||||
wx.login({
|
||||
success: function (res) {
|
||||
if (res.code) {
|
||||
// 使用登录凭证 code、encryptedData 和 iv 调用后端接口解密获取用户的微信号码
|
||||
// 请根据自己的业务逻辑和后端接口进行处理s
|
||||
// console.log('用户的微信号码:', res.code);
|
||||
getopenid({
|
||||
js_code: res.code,
|
||||
}).then(res => {
|
||||
var str = JSON.parse(res)
|
||||
that.setData({
|
||||
openid: str.openid
|
||||
})
|
||||
// console.log(that.data.openid)
|
||||
}
|
||||
|
||||
);
|
||||
} else {
|
||||
console.log('登录失败!' + res.errMsg);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
//验证
|
||||
submitForm(e) {
|
||||
let that = this;
|
||||
// console.log( that.data.Sqlid)
|
||||
let type = e.currentTarget.dataset['type']
|
||||
if (type == "1") {
|
||||
that.setData({
|
||||
islong: true
|
||||
})
|
||||
}
|
||||
if (this.data.Uid == null || this.data.Uid == "" || this.data.Pwd == "" || this.data.Pwd == null || that.data.Sqlid == 0) {
|
||||
app.toast(2, "数据不完整")
|
||||
} else {
|
||||
Login({
|
||||
Password: that.data.Pwd,
|
||||
islong: that.data.islong,
|
||||
UserName: that.data.Uid,
|
||||
openid: that.data.openid
|
||||
}).then(res => {
|
||||
// console.log(res)
|
||||
if (res.Status == 200) {
|
||||
if (res.Data.userinfo == null) {
|
||||
wx.showModal({
|
||||
title: '提示信息',
|
||||
content: '未绑定帐号,如需绑定帐号,请点击(确定)继续',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
that.setData({
|
||||
show: true
|
||||
})
|
||||
} else {
|
||||
that.setData({
|
||||
show: false
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
settoken(res.Data.token)
|
||||
// console.log(res)
|
||||
if (that.data.islong) {
|
||||
wx.setStorageSync('xiaoxi_token', res.Data.token)
|
||||
wx.setStorageSync('sqlid', that.data.Sqlid)
|
||||
|
||||
}
|
||||
app.toast(1, "登录成功", wx.reLaunch({
|
||||
url: "/pages/index/index?Sqlid=" + that.data.Sqlid,
|
||||
}))
|
||||
}
|
||||
} else if (res.Status == 300) {
|
||||
app.toast(2, res.Message)
|
||||
} else {
|
||||
app.toast(2, "密码或用户名错误")
|
||||
}
|
||||
}, err => {
|
||||
app.toast(2, "网络繁忙")
|
||||
}).catch(
|
||||
err => {
|
||||
console.log(err)
|
||||
app.toast("异常", 'error')
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
//用户输入手机号码后取消事件
|
||||
qux: function () {
|
||||
var that = this
|
||||
that.setData({
|
||||
show: false
|
||||
})
|
||||
},
|
||||
//用户输入手机号码后确认事件
|
||||
qr: function () {
|
||||
var that = this;
|
||||
AddLogin({
|
||||
openid: that.data.openid,
|
||||
Uid: that.data.Uid
|
||||
}).then(res => {
|
||||
console.log(res)
|
||||
if (res.Status == 200) {
|
||||
that.setData({
|
||||
show: false
|
||||
})
|
||||
} else if (res.Status == 300) {
|
||||
app.toast(2, "这个账号被绑定了")
|
||||
that.setData({
|
||||
show: false
|
||||
})
|
||||
} else {
|
||||
app.toast(2, "你的微信已经绑定了")
|
||||
that.setData({
|
||||
show: false
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}, err => {
|
||||
app.toast(2, "网络繁忙")
|
||||
}).catch(
|
||||
err => {
|
||||
console.log(err)
|
||||
app.toast("异常", 'error')
|
||||
}
|
||||
);
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {},
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {},
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {},
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {},
|
||||
//搜索权限
|
||||
Shuruusernamebyquanxian: function (o) {
|
||||
var that = this;
|
||||
if(that.data.Uid==null || that.data.Uid==""){
|
||||
app.toast(2,"请输入用户名")
|
||||
var arrlist=[{
|
||||
value: 0,
|
||||
text: "请选择数据库"
|
||||
},
|
||||
]
|
||||
that.setData({
|
||||
option1: arrlist,
|
||||
value1: 0,
|
||||
Sqlid: 0,
|
||||
})}
|
||||
else{
|
||||
Shuruusernamebyquanxian({
|
||||
Uid: that.data.Uid
|
||||
}).then(res => {
|
||||
console.log(res)
|
||||
if(res=="on"){
|
||||
app.toast(2, "用户名输入错误!")
|
||||
}
|
||||
var arrlist=[{
|
||||
value: 0,
|
||||
text: "请选择数据库"
|
||||
},
|
||||
]
|
||||
res.forEach(element => {
|
||||
arrlist.push(element)
|
||||
});
|
||||
that.setData({
|
||||
option1: arrlist,
|
||||
value1: 0,
|
||||
Sqlid: 0,
|
||||
})
|
||||
}, err => {
|
||||
app.toast(2, "网络繁忙")
|
||||
}).catch(
|
||||
err => {
|
||||
console.log(err)
|
||||
app.toast("异常", 'error')
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user