123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- // app.js
- var http = require('utils/util.js');
- var md5 = require('utils/md5.js');
- var commonJs = require('utils/common.js')
- var api = require('utils/api.js')
- App({
- data:{
- windowWidth:0,//屏幕的宽度
- windowHeight:0,//屏幕的高度
- systemInfo:{isIpx:false},
- safeAreaTop:30,//距离上面的安全距离
- isOnshow:false,
- loginCount:0,
- statusNavBarHeight:0
- },
- onLaunch() {
- this.data.isOnshow = true
- var _this = this;
- this.getNavBarHeight()
- wx.getSystemInfo({
- success (res) {
- _this.data.systemInfo = res
- _this.data.windowWidth = res.windowWidth
- _this.data.windowHeight = res.windowHeight
- if(_this.data.systemInfo.platform == "ios"){
- _this.data.safeAreaTop = _this.data.systemInfo.statusBarHeight + 10
- }else if(_this.data.systemInfo.platform == "android"){
- _this.data.safeAreaTop = _this.data.systemInfo.statusBarHeight + 10
- }else{
- _this.data.safeAreaTop = _this.data.systemInfo.statusBarHeight + 10
- }
- let modelmes = res.model; //手机品牌
- var fringeScreenModels = [
- "iPhone 12","iPhone 11","iPhone X", "iPhone x", "vivo X21A", "ASUS Zenfone 5",
- "Ulefone T2 Pro", "Leagoo S9", "HUAWEI P20", "DooGee V",
- "OPPO R15", "LG G7", "SAMSUNG S9", "COR-AL00",
- "vivo Y83A", "LLD-AL20", "vivo Z1", "PACM00", "PAAM00"]
- fringeScreenModels.forEach((item)=>{
- if (modelmes.indexOf(item) != -1) {
- _this.data.systemInfo.isIpx = true
- }
- })
-
- }
- })
- this.verified();//版本控制(过审用)
- },
- onShow:function(){
- if(!wx.getStorageSync('isLogin')){//解决未登录情况下,点击左上角home
- if(this.data.isOnshow){
- this.data.isOnshow = false
- }else{
- this.verified();//版本控制(过审用)
- }
- }
- },
- getNavBarHeight(){
- // 获取状态栏高度
- const { statusBarHeight } = wx.getSystemInfoSync();
- // 得到右上角菜单的位置尺寸
- const menuButtonObject = wx.getMenuButtonBoundingClientRect();
- const { top, height } = menuButtonObject;
- // 计算导航栏的高度
- // 此高度基于右上角菜单在导航栏位置垂直居中计算得到
- const navBarHeight = height + (top - statusBarHeight) * 2;
- // 计算状态栏与导航栏的总高度
- this.data.statusNavBarHeight = statusBarHeight + navBarHeight
- },
- verified(cb){//版本控制
- var _this = this;
- http.req(api.api.verified, 'get', {
- version: 'v1.2'
- }, function (res) {
- if(res && res.errno == 0){
- wx.setStorageSync('isLogin',false)
- wx.setStorageSync('admin_id',res.rst.data.id)
- if(!wx.getStorageSync('ttl')||wx.setStorageSync('ttl')!=res.rst.data.ttl) {
- wx.setStorageSync('ttl',res.rst.data.ttl)
- var sign=md5.hex_md5("random="+res.rst.data.random+"&ttl="+res.rst.data.ttl+"&user_id="+res.rst.data.id);
- wx.setStorageSync('sign',sign)
- }
- wx.setStorageSync('doneLogin', false)
- if (getCurrentPages().length != 0) {
- //刷新当前页面的数据
- getCurrentPages()[getCurrentPages().length - 1].onLoad()
- }
- }else{
- _this.login({})
- }
- },(err)=>{
- })
- },
- // 登录
- login({encryptedData,iv,cb}){
- var _this = this;
- wx.login({
- success (res) {
- if (res.code) {
- var params = {code: res.code,}
- if(encryptedData){
- params.encrypted_data = encryptedData;
- params.iv = iv;
- }
- http.req(api.api.Login, 'get', params, function (res) {
- wx.hideLoading()
- if(res && res.errno == 0){
- var session_key = res.rst.session_key;
- wx.setStorageSync('session_key',session_key)
- wx.setStorageSync('userInfo',res.rst.info)
- wx.setStorageSync('admin_id',res.rst.info.id)
- wx.setStorageSync('ttl',res.rst.ttl)
- var sign=md5.hex_md5("random="+res.rst.random+"&ttl="+res.rst.ttl+"&user_id="+res.rst.info.id);
- wx.setStorageSync('sign',sign)
- wx.setStorageSync('isLogin',true)
- cb?cb():''
- let pages = getCurrentPages(); //页面对象
- let currentPage = pages[0];
- if(Object.keys(currentPage.options).length>0) {
- currentPage.onShow();
- }else {
- currentPage.onLoad();
- }
- }else if(res.errno == 1303){//新用户
- wx.redirectTo({
- url: '/pages/welcome/welcome',
- })
- }else{
- if(_this.data.loginCount==0){//第一次请求失败,再来一次
- setTimeout(()=>{
- _this.login({})
- _this.data.loginCount = 1
- },500)
- }
- }
- },()=>{
- wx.hideLoading()
- })
- } else {
- console.log('登录失败!' + res.errMsg)
- }
- }
- })
- },
- shareEvent(res){//分享
- if(res.from === 'button'){
- //来自页面内转发按钮
- }
- return{
- title:'问星赚赚-帮助视频号创业者更快变现的服务平台',
- imageUrl:'https://kx-bigdata.oss-cn-beijing.aliyuncs.com/Applet/recevice/recevice_share.png',
- path: '/pages/index/index'
- }
- },
- shareTimeline(res){//分享到朋友圈
- let img = 'https://kx-bigdata.oss-cn-beijing.aliyuncs.com/Applet/recevice/recevice_share.png'
- return {
- title: '问星赚赚-帮助视频号创业者更快变现的服务平台', //字符串 自定义标题
- query: `source=pyq`, //页面携带参数
- imageUrl:img //图片地址
- }
- },
- func: {
- req: http.req,
- md5: md5.hex_md5,
- getDay: commonJs.getDay,
- NumberHandle: commonJs.NumberHandle,
- api:api.api
- }
- })
|