代码拉取完成,页面将自动刷新
<script>
export default {
globalData: {
haveLoading: false,
firstLoading: false,
loading: false,
showTickTip: false, //显示提示框
isFirstLogin: false,
subscribe: false,
isConcern: false,
successPa: false,
toLogin: false,
header: {
Authority: ''
},
isHaiZhu: true,
isPasswordError: false,
isSameDay: false,
navBarHeight: 0, // 导航栏高度
menuBotton: 0, // 胶囊距底部间距(保持底部间距一致)
menuRight: 0, // 胶囊距右方间距(方保持左、右间距一致)
menuHeight: 0, // 胶囊高度(自定义内容可与胶囊高度保证一致)
pageHeight: 0, //页面高度
menuWidth: 0,
statusBarHeight: 0, //底部tabbar高度
screenWidth: 0, //屏幕高度
isLogin: false,
newPerson: false,
firstIn: true,
toDetail: false,
tabbarList: [],
backFromCourseConcern: false,
updateTime: 0
},
async onLaunch() {
uni.setStorageSync('showTickTip',false);
// console.log(uni.getStorageSync('showTickTip'))
// uni.hideTabBar()
let vm = this;
wx.cloud.init({
env: " course-service-0gf7qv1h7d7d6aae"
});
// const c1 = new wx.cloud.Cloud({
// resourceEnv: 'prod-0g5m8v40aeec4be5',
// })
console.log('c1--------', wx.cloud)
// await c1.init()
// uni.setTabBarBadge({
// index: 1,
// text: ''
// })
// setTimeout(() => {
// uni.hideTabBar()
// // uni.setTabBarItem({
// // index: 1,
// // iconPath: '/static/icon/shop.png',
// // selectedIconPath: 'static/icon/shop_selected.png',
// // success() {
// // console.log('成功')
// // },
// // fail(error) {
// // console.log('失败',error)
// // }
// // })
// // uni.setTabBarStyle({
// // color: '#FF0000',
// // selectedColor: '#FF0000',
// // borderStyle: 'white'
// // })
// }, 1000)
let pastDueDate = uni.getStorageSync('pastDueDateNew');
let currentTime = Date.parse(new Date());
if (!pastDueDate || pastDueDate < currentTime) {
console.log('没有缓存时间或者时间过期')
this.quickLogin();
} else {
let header = new Object()
header.Authority = uni.getStorageSync('Authority')
this.globalData.haveLoading = true
// this.globalData.
// getApp().globalData.isLogin = true
// console.log('登录',getApp().globalData.isLogin)
this.globalData.header = header
this.globalData.subscribe = uni.getStorageSync('subscribe');
this.globalData.isHaiZhu = uni.getStorageSync('isHaiZhu');
// console.log(this.globalData.header)
// console.log('海珠',this.globalData.isHaiZhu)
// console.log(111,this.globalData.subscribe)
}
// console.log('登录缓存时间',pastDueDate)
this.setNavBarInfo()
this.getPagesHeight();
// this.tabbar()
},
onShow: function() {},
onHide: function() {},
methods: {
async tabbar(){
// this.showTickTip = trues
// console.log(this.showTickTip )
// let header = getApp().globalData.header
let data = await this.UniRequest("/goods/m/tabbarAndTagShowA","GET","","")
console.log(data,'展示tabbar')
if (data.data.data == 0) {
// console.log(data.data.data)
uni.hideTabBar()
} else {
uni.showTabBar();
uni.setStorageSync('showTickTip',true);
}
},
watch: function(key, method,config) {
var obj = this.globalData;
//加个前缀生成隐藏变量,防止死循环发生
getApp().globalData[key + 'tmp'] = obj[key]; //obj[key]这个不能放在Object.defineProperty里
if (getApp().globalData[key + 'tmp']) { //处理已经声明的变量,绑定处理
method(getApp().globalData[key + 'tmp']);
}
let tempData = []
Object.defineProperty(obj, key, {
configurable: true,
enumerable: true,
set: function(value) {
tempData = value
getApp().globalData[key + 'tmp'] = value;
method(value);
},
get: function() {
return getApp().globalData[key + 'tmp']
}
})
if (config && config.immediate) {
// console.log('立刻执行')
getApp().globalData[key] = tempData;
console.log(getApp().globalData[key])
}
},
async UniRequest(path, method, body, header) {
// let dataReq = new Object()
// dataReq.config = {
// env: 'course-service-0gf7qv1h7d7d6aae'
// }
// dataReq.path = "/zkCourse"+path
// dataReq.method = method
// if (body) {
// dataReq.data = body
// }
// dataReq.header = {
// 'X-WX-SERVICE': 'course'
// }
// if (header) {
// dataReq.header.Authority = header.Authority
// }
// // console.log(dataReq)
// let {
// data
// } = await wx.cloud.callContainer(dataReq);
// // console.log('ffff',data)
// return data
let data
let request = new Object
// request.url = "http://119.91.78.179:9001"+path
// request.url = "http://119.91.78.179:9001"+path;
// request.url = "http://112.74.188.40:9001/zkCourse" + path;
request.url = "https://www.zcjn.top/zkCourse" + path
//request.url = "http://localhost:9001/zkCourse" + path
// request.url = "https://course-1383871-1308162715.ap-shanghai.run.tcloudbase.com"+path
// request.url = "http://159.75.241.252:9001/zkCourse"+path
request.method = method
if (body) {
request.data = body;
// console.log(request.data,'请求参数')
}
if (header) {
request.header = header
}
await uni.request(request).then(res => {
data = res
})
return data[1].data
},
async officailRequest(path, method, body, header) {
let data
let request = new Object
//request.url = "https://127.0.0.1"+path
request.url = "https://www.zcjn.top/official" + path
request.method = method
if (body) {
request.data = body
}
if (header) {
request.header = header
}
await uni.request(request).then(res => {
data = res
})
return data[1].data
},
async quickLogin(userInfo) {
let vm = this
console.log('quickLogin')
wx.login().then(async (res) => {
let body = new Object()
body.code = res.code;
console.log(res, '登录结果')
if (userInfo) {
body.nickName = userInfo.nickName
body.avatarUrl = userInfo.avatarUrl
body.gender = userInfo.gender
}
let data = await getApp().UniRequest("/user/login", "POST", body, "")
/* let data1 = await getApp().UniRequest("/twohandbook/user/quicklyLogin","POST",body,"");
console.log('data1',data1) */
//快捷登录失败则跳转到登录页
if (data.code == 20002) {
//console.log("跳转登录页")
// uni.navigateTo({
// url: "../login/login"
// })
getApp().globalData.haveLoading = false
uni.reLaunch({
url: "../../page_login/login/login",
fail(error) {
console.log('错误信息',error)
}
})
// uni.reLaunch({
// url: "../maintainTip/maintainTip"
// })
} else {
console.log('结果11', data);
let authority = data.data.Authority;
uni.setStorageSync("Authority", authority);
let pastDueDate = Date.parse(new Date()) + 82800000;
uni.setStorageSync('pastDueDateNew',pastDueDate)
// console.log(pastDueDate,'过期时间')
getApp().globalData.firstIn = false;
let header = new Object()
header.Authority = authority
// getApp().globalData.isLogin = true
// console.log('登录',getApp().globalData.isLogin)
getApp().globalData.header = header
console.log(getApp().globalData.header,'数据222')
getApp().globalData.haveLoading = true
// let res = await getApp().UniRequest("/user/deleteLoginCache", "Get", {openid: 'ohpVk5SF3oodWNsodPzlmbiiHPXY'},header)
// console.log('删除',res)
// uni.request({
// url: 'http://119.91.78.179:9001/countDown/insertRenWenCountDown?xueHao=202010244304', //仅为示例,并非真实接口地址。
// header: getApp().globalData.header,
// method: 'GET',
// success: (res) => {
// console.log('人文',res);
// // this.text = 'request success';
// }
// });
vm.passwordCheck() //快捷登录,但是可能出现密码错误
let userInfo = new Object()
userInfo.avatarUrl = data.data.avatarUrl
userInfo.nickName = data.data.nickName
userInfo.gender = data.data.gender
uni.setStorageSync("userInfo", userInfo)
console.log(data.data.subscribe,22)
console.log( data.data.isHaiZhu,222)
let isHaiZhu = data.data.isHaiZhu
getApp().globalData.subscribe = data.data.subscribe
getApp().globalData.isHaiZhu = data.data.isHaiZhu
uni.setStorageSync("subscribe", data.data.subscribe)
uni.setStorageSync("openid", data.data.openid)
uni.setStorageSync("isHaiZhu", isHaiZhu)
//console.log("isHaizhu:"+getApp().globalData.isHaiZhu)
if (data.code == 20005) {
//重新获取用户信息
uni.showModal({
title: '小程序需要您的信息',
showCancel: false
}).then(res => {
uni.getUserProfile({
desc: '获取用户基本信息'
}).then(async (res) => {
uni.setStorageSync("userInfo", res[1].userInfo);
})
})
}
}
})
},
// async triCountDown() {
// uni.showLoading({
// title: '请稍等..',
// // mask: true
// })
// let header = getApp().globalData.header
// let data = await getApp().UniRequest("/countDown/authority/triCountDown", "POST", "", header);
// console.log('课程', data)
// if (data.code == 20003) {
// getApp().globalData.isPasswordError = true
// }
// uni.hideLoading()
// },
async passwordCheck() {
let header = getApp().globalData.header
let data = await getApp().UniRequest("/user/passwordCheck/authority", "POST", "", header)
if (data.code == 20003) {
getApp().globalData.isPasswordError = true
} else {
console.log("密码是对的")
}
},
setNavBarInfo() {
// 获取系统信息
const systemInfo = wx.getSystemInfoSync();
// 胶囊按钮位置信息
const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
// 导航栏高度 = 状态栏到胶囊的间距(胶囊距上距离-状态栏高度) * 2 + 胶囊高度 + 状态栏高度
this.globalData.navBarHeight = (menuButtonInfo.top - systemInfo.statusBarHeight) * 2 + menuButtonInfo
.height + systemInfo.statusBarHeight;
this.globalData.navBarHeight = this.globalData.navBarHeight * 750 / wx.getSystemInfoSync().windowWidth;
console.log(this.globalData.navBarHeight)
this.globalData.menuBotton = menuButtonInfo.top - systemInfo.statusBarHeight;
this.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
this.globalData.menuHeight = menuButtonInfo.height;
this.globalData.menuWidth = menuButtonInfo.width;
this.statusBarHeight = systemInfo.statusBarHeight;
this.screenWidth = systemInfo.screenWidth;
console.log(111, this.screenWidth)
// var rpx = px * 750 / wx.getSystemInfoSync().windowWidth;
// console.log( this.globalData.navBarHeight);
// console.log( this.globalData.menuBotton);
// console.log( this.globalData.menuRight);
// console.log(this.globalData.menuHeight)
},
getPagesHeight() {
let that = this;
uni.getSystemInfo({
success: function(res) {
let pxToRpxScale = 750 / res.windowWidth;
that.globalData.pageHeight = res.windowHeight * pxToRpxScale;
}
});
console.log(this.globalData.pageHeight, '页面高度')
}
}
}
</script>
<style lang="scss">
/*每个页面公共css */
@import "uview-ui/index.scss";
@import "./static/icon/iconfont/iconfont.css";
page {
-webkit-overflow-scrolling : touch;
}
button {
background-color: #fff;
border: 0rpx;
padding-right: 10rpx;
padding-left: 10rpx;
}
</style>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。