Commit 5fe3a853 authored by yanghailong's avatar yanghailong

用户信息管理

parents
Pipeline #317 failed with stages
var netTool = require("../tools/APIurl")
var rootUrl = "capi/V2/shUser/memberUser/"
var storageName = "userInfo";
var wx_synchronization_flag = 0;
var checkdata = require('../utils/dataCheek')
var page = {
pageSize: 10,
total: 0,
currentPage: 1
}
/**
* wx_synchronization_flag = 1表示已经拉取用户信息
*/
function UserInfo() {
// 用户登录
this.login = function (data) {
console.log(data)
var that = this;
if (checkdata.isEmpty(data.mobile) || checkdata.isEmpty(data.password)) {
wx.showToast({
title: '请输入信息',
icon: "none"
})
return
}
// if (!apis.verify(data.password, '密码不能为空')) return
netTool.getAjaxUrlValue('capi/V2/permissionV2/memberUser/login', { // mark: xxx
is_deleted: 0,
...data
},
function (res) {
if (res.token) {
wx.setStorageSync('isLogin', 1)
wx.setStorageSync('token', res.token),
wx.setStorageSync('user_id', res.rows[0].id),
// wx.navigateTo({
// url: '/pages/usercenter/index/index',
// })
wx.showToast({
title: '登陆成功',
})
wx.navigateBack({
delta: 0,
})
}
else {
wx.showToast({
title: '用户名密码错误',
})
wx.setStorageSync('isLogin', 0)
}
})
}
this.getInfo = function (data, fn) {
netTool.getAjaxUrlValue(rootUrl + 'findById', {
id: wx.getStorageSync('user_id'),
...data
}, function (res) {
typeof fn == 'function' && fn(res);
})
}
this.update = function (netTool, data, fn) {
if (data.real_name == 'undefined') {
data.real_name = ''
}
var that = this;
netTool.getAjaxUrlValue('capi/V2/recruitxcx/memberUser/update', data, function (res) {
let _chache = that.get()
_chache.id
if (_chache) {
let _cache1 = { id: _chache.id, ..._chache, ...data }
debugger
wx.setStorageSync('userInfo', _cache1)
_chache = that.get()
typeof fn == "function" && fn(_chache);
} else {
netTool.getAjaxUrlValueBackground('capi/V2/recruitxcx/memberUser/list', { id: data.id }, function (res) {
wx.setStorageSync('userInfo', res.rows[0])
typeof fn == "function" && fn(res.rows[0]);
})
}
})
}
this.getUserProfile = function () {
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
let _cache = wx.getStorageSync(storageName)
if (_cache) {
wx_synchronization_flag = _cache.wx_synchronization_flag
}
if (wx_synchronization_flag) {
return true
}
let that = this;
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
wx_synchronization_flag = 1
let rawData = JSON.parse(res.rawData)
that.updateSycn({ avatar: rawData.avatarUrl, wx_synchronization_flag: 1, nick_name: rawData.nickName })
}
})
}
this.get = function () {
return wx.getStorageSync('userInfo')
}
this.getMyId = function () {
return wx.getStorageSync('userInfo').id
}
this.getOpenId = function () {
return wx.getStorageSync('userInfo').open_id
}
}
module.exports = UserInfo;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment