65 lines
1.3 KiB
Vue
65 lines
1.3 KiB
Vue
|
|
<script>
|
||
|
|
import config from '@/config';
|
||
|
|
import { getToken } from '@/utils/auth';
|
||
|
|
|
||
|
|
export default {
|
||
|
|
onLaunch: function() {
|
||
|
|
this.initApp();
|
||
|
|
const isDev = getDevelopment();
|
||
|
|
if (isDev) {
|
||
|
|
console.log('developing...');
|
||
|
|
}
|
||
|
|
},
|
||
|
|
methods: {
|
||
|
|
// 初始化应用
|
||
|
|
initApp() {
|
||
|
|
// 初始化应用配置
|
||
|
|
this.initConfig()
|
||
|
|
// 检查用户登录状态
|
||
|
|
//#ifdef H5
|
||
|
|
this.checkLogin()
|
||
|
|
//#endif
|
||
|
|
},
|
||
|
|
initConfig() {
|
||
|
|
this.globalData.config = config;
|
||
|
|
if (!uni.getStorageSync("base_url")) {
|
||
|
|
uni.setStorage({
|
||
|
|
key: 'base_url',
|
||
|
|
data: config.baseUrl
|
||
|
|
})
|
||
|
|
}
|
||
|
|
if (!uni.getStorageSync("wms_url")) {
|
||
|
|
uni.setStorage({
|
||
|
|
key: 'wms_url',
|
||
|
|
data: config.wmsUrl
|
||
|
|
})
|
||
|
|
}
|
||
|
|
},
|
||
|
|
checkLogin() {
|
||
|
|
if (!getToken()) {
|
||
|
|
console.log('check login');
|
||
|
|
this.$tab.reLaunch('/pages/login')
|
||
|
|
}
|
||
|
|
},
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* 判断是开发环境还是生产环境
|
||
|
|
*/
|
||
|
|
function getDevelopment() {
|
||
|
|
if (process.env.NODE_ENV === 'development') {
|
||
|
|
return true;
|
||
|
|
} else {
|
||
|
|
// 生产环境不应该打印console.log
|
||
|
|
console.log = () => {};
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<style lang="scss">
|
||
|
|
@import "@/static/scss/index.scss";
|
||
|
|
@import "@/static/iconfont.css";
|
||
|
|
@import "@/static/iconfont/iconfont.css";
|
||
|
|
// @import url("https://at.alicdn.com/t/c/font_4828189_g8nazs212r6.css");
|
||
|
|
</style>
|