[更新]
This commit is contained in:
174
pages/user/user.js
Normal file
174
pages/user/user.js
Normal file
@@ -0,0 +1,174 @@
|
||||
|
||||
/*
|
||||
* 本时生活
|
||||
*/
|
||||
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
isUser : false, //用户登录状态
|
||||
currentId : '', //轮播下标
|
||||
infos : '', //用户信息
|
||||
order : '', //订单信息
|
||||
account : '',
|
||||
// 卡轮播
|
||||
swiper: {
|
||||
imgUrls: [
|
||||
{
|
||||
id : 0,
|
||||
src : '/static/img/user_card_00.png',
|
||||
color : '#676869',
|
||||
type : 'silver'
|
||||
},
|
||||
{
|
||||
id : 2,
|
||||
src : '/static/img/user_card_02.png',
|
||||
color : '#192b4c',
|
||||
type : 'drill'
|
||||
}
|
||||
],
|
||||
autoplay: false,
|
||||
interval: 5000,
|
||||
duration: 1000,
|
||||
current : 0
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad (options) {
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow () {
|
||||
// 检查用户是否已登录
|
||||
const current = wx.getStorageSync("current")
|
||||
this.setData({
|
||||
currentId: current
|
||||
})
|
||||
|
||||
if(wx.getStorageSync("token") == ""){
|
||||
this.setData({
|
||||
infos : '',
|
||||
order : '',
|
||||
account : '',
|
||||
isUser : false
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
isUser : getApp().globalData.isUser
|
||||
})
|
||||
|
||||
// 获取用户信息
|
||||
this.userInfo();
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
userInfo() {
|
||||
wx.$api.user.index().then(res=>{
|
||||
this.setData({
|
||||
infos : res.data.info,
|
||||
order : res.data.order,
|
||||
account : res.data.info.account
|
||||
})
|
||||
}).catch(err=>{
|
||||
if(!err.login){
|
||||
this.setData({
|
||||
infos : '',
|
||||
order : '',
|
||||
account : '',
|
||||
isUser : false
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理未登录时的转跳
|
||||
*/
|
||||
userNav(e){
|
||||
let pageUrl = e.currentTarget.dataset.url
|
||||
if(this.data.isUser){
|
||||
wx.navigateTo({
|
||||
url: pageUrl
|
||||
})
|
||||
}else{
|
||||
// 去登录
|
||||
wx.navigateTo({
|
||||
url: "/pages/login/login"
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 判断是否新用户
|
||||
*/
|
||||
userLogin(){
|
||||
if(app.globalData.token != '') {
|
||||
wx.navigateTo({
|
||||
url: '/pages/chooseTel/chooseTel'
|
||||
})
|
||||
}else {
|
||||
wx.navigateTo({
|
||||
url: '/pages/login/login',
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 切换用户
|
||||
*/
|
||||
switchParty() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/chooseTel/chooseTel?type=mobiles'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 左箭头
|
||||
*/
|
||||
prevImg () {
|
||||
var swiper = this.data.swiper;
|
||||
var current = swiper.current;
|
||||
|
||||
swiper.current = current > 0 ? current - 1 : swiper.imgUrls.length - 1;
|
||||
this.setData({
|
||||
swiper: swiper,
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 右箭头
|
||||
*/
|
||||
nextImg () {
|
||||
var swiper = this.data.swiper;
|
||||
var current = swiper.current;
|
||||
swiper.current = current < (swiper.imgUrls.length - 1) ? current + 1 : 0;
|
||||
this.setData({
|
||||
swiper: swiper,
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 敬请期待
|
||||
*/
|
||||
await() {
|
||||
wx.showToast({
|
||||
title : '努力开发中~',
|
||||
icon : 'none',
|
||||
duration: 1000
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user