import Vue from 'vue'
import App from './App'
import { config } from './config/config'
import store from './store' 
import Request from '@/js_sdk/luch-request/luch-request/index.js';
const http = new Request();
import './utils/filter' 

Vue.config.productionTip = false

//栏目标题设置
const setNavbarTitle = (title,defaultTitle) => {
	uni.setNavigationBarTitle({
		title:title || defaultTitle
	})
}

//封装全局登录检查函数:backpage为登录后返回的页面；backtype为打开页面的类型[1 : redirectTo 2 : switchTab]
//3种页面跳转方式：NavigationTo(直接打开新页面),RedirectTo(覆盖原页面后打开新页面),SwitchTo(切换顶部导航的方式来切换页面)
Vue.prototype.checkLogin = function(backpage, backtype){
    var TOKEN  = uni.getStorageSync('token');//本地持久化存储
	var TOKENHEAD = uni.getStorageSync('tokenhead');
	var USERINFO = uni.getStorageSync('userInfo');
    if(TOKEN == '' || TOKENHEAD == '' || USERINFO == ''){
        uni.redirectTo({url:'/pages/login/login?backpage='+backpage+'&backtype='+backtype});
        return false;
    }
    return [TOKEN,TOKENHEAD,USERINFO];//已经登录返回数组TOKEN等用户信息
}

import $wxApi from "./wxapi.js";
Vue.prototype.$wxApi = $wxApi;

Vue.prototype.$api = {http,setNavbarTitle}
Vue.prototype.$getimg = config.imgUrl
Vue.prototype.$placeImg = config.placeImg
Vue.prototype.$store = store
Vue.prototype.config = config
App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()
