123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- const { getUserInfo, getSystemConfig } = require('./api/common')
- const { isMobile } = require('./utils/validate')
- const { checkUpdateVersion } = require('./utils/util')
- App({
- onLaunch() {
- const that = this
- // 获取系统信息
- const systemInfo = wx.getSystemInfoSync()
- // 胶囊按钮位置信息
- const menuButtonInfo = wx.getMenuButtonBoundingClientRect()
- // 导航栏高度 = 状态栏到胶囊的间距(胶囊距上距离-状态栏高度) * 2 + 胶囊高度 + 状态栏高度
- that.globalData.navBarHeight = (menuButtonInfo.top - systemInfo.statusBarHeight) * 2 +
- menuButtonInfo.height + systemInfo.statusBarHeight
- that.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right
- that.globalData.menuBottom = menuButtonInfo.top - systemInfo.statusBarHeight
- that.globalData.menuHeight = menuButtonInfo.height
- that.fetchSystemConfig()
- that.fetchUserData()
- checkUpdateVersion()
- },
- globalData: {
- wxMiniversion: 'v0.0.0',
- userInfo: {},
- navBarHeight: 0, // 导航栏高度
- menuRight: 0, // 胶囊距右方间距(方保持左、右间距一致)
- menuBottom: 0, // 胶囊距底部间距(保持底部间距一致)
- menuHeight: 0, // 胶囊高度(自定义内容可与胶囊高度保证一致)
- tabBarList: [
- {
- 'pagePath': 'pages/home/home',
- 'text': '首页',
- 'iconPath': 'image/tabBar/home_0@2x.png',
- 'selectedIconPath': 'image/tabBar/home_1@2x.png'
- },
- {
- 'pagePath': 'pages/partner/partner',
- 'text': '合作社',
- 'iconPath': 'image/tabBar/partner_0@2x.png',
- 'selectedIconPath': 'image/tabBar/partner_1@2x.png'
- },
- {
- 'pagePath': 'pages/mine/mine',
- 'text': '我的',
- 'iconPath': 'image/tabBar/mine_0@2x.png',
- 'selectedIconPath': 'image/tabBar/mine_1@2x.png'
- }
- ],
- asyncTabBarList: [
- {
- 'pagePath': 'pages/news/news',
- 'text': '农事天地',
- 'iconPath': 'image/tabBar/news_0@2x.png',
- 'selectedIconPath': 'image/tabBar/news_1@2x.png'
- }
- ],
- objSystemConfig: {}
- },
- async fetchUserData() {
- try {
- const { status, data } = await getUserInfo()
- if (status && Object.prototype.toString.call(data) === '[object Object]' && isMobile(data.user_phone)) {
- const temp = {
- ...data
- }
- // 设置默认昵称
- if (!temp.user_nickname) {
- temp.user_nickname = 'bbs' + temp.user_phone.replace(/(\d{7})(.*)/, '$2')
- }
- if (temp.user_address && temp.user_address.indexOf('/') > -1) {
- temp.user_address = temp.user_address.split('/')
- }
- if (temp.shop_status === 1) {
- this.hasPermission()
- }
- this.globalData.userInfo = temp
- }
- } catch (e) {}
- if (this.fetchUserDataCallback) {
- this.fetchUserDataCallback()
- this.fetchUserDataCallback = null
- }
- },
- // 根据权限配置tabbar
- hasPermission() {
- const tabBarList = this.globalData.tabBarList
- if (tabBarList.findIndex(item => item.text === '农事天地') === -1) {
- tabBarList.splice(2, 0, ...this.globalData.asyncTabBarList)
- if (this.addTabBarList) {
- this.addTabBarList(tabBarList)
- }
- }
- },
- async fetchSystemConfig() {
- try {
- const { status, data } = await getSystemConfig()
- if (status && Object.prototype.toString.call(data) === '[object Object]') {
- this.globalData.objSystemConfig = data
- }
- } catch (err) {}
- if (this.fetchSystemConfigCallback) {
- this.fetchSystemConfigCallback()
- this.fetchSystemConfigCallback = null
- }
- }
- })
|