feat:v1.4前端更新
This commit is contained in:
188
app/App.vue
188
app/App.vue
@@ -8,70 +8,121 @@
|
||||
import Auth from './libs/wechat.js';
|
||||
import Routine from './libs/routine.js';
|
||||
import Apps from './libs/apps.js';
|
||||
import Cache from './utils/cache.js';
|
||||
import {
|
||||
getTheme,
|
||||
loginConfigApi,
|
||||
tokenIsExistApi
|
||||
} from './api/api.js';
|
||||
import {
|
||||
mapActions
|
||||
} from 'vuex'
|
||||
|
||||
import {
|
||||
spread
|
||||
} from "@/api/user";
|
||||
var statusBarHeight = uni.getSystemInfoSync().statusBarHeight; //手机端头部手机时间位置高度
|
||||
// const app = getApp();
|
||||
export default {
|
||||
globalData: {
|
||||
spid: 0,
|
||||
statusBarHeight: statusBarHeight, //手机端头部手机时间位置高度
|
||||
spread: 0, //推广人id
|
||||
code: 0,
|
||||
isLogin: false,
|
||||
userInfo: {},
|
||||
MyMenus: [],
|
||||
windowHeight: 0,
|
||||
id: 0
|
||||
navHeight: 0,
|
||||
navH: 0,
|
||||
id: 0, //商品id
|
||||
isIframe: false,
|
||||
theme: 'theme1', //主题色
|
||||
publicLoginType: Cache.get('publicLoginType') ? Cache.get('publicLoginType') : '', //公众号登录方式(单选),1微信授权,2手机号登录
|
||||
routinePhoneVerification: '', //小程序手机号校验类型(多选)1微信小程序验证 2短信验证
|
||||
companyName: uni.getStorageSync('companyName') ? uni.getStorageSync('companyName') : '欢迎你', //公司名称
|
||||
tokenIsExist: false, //登录是否失效 false 失效,true没失效
|
||||
mobileLoginLogo: uni.getStorageSync('mobileLoginLogo') || `${Cache.get("imgHost")}crmebimage/perset/staticImg/logo2.png` //登录页logo
|
||||
},
|
||||
onLaunch: function(option) {
|
||||
//获取登录配置
|
||||
this.getLoginConfig();
|
||||
|
||||
//校验token是否有效,true为有效,false为无效
|
||||
tokenIsExistApi().then(res => {
|
||||
this.globalData.tokenIsExist = res.data;
|
||||
})
|
||||
|
||||
let that = this;
|
||||
// #ifdef H5
|
||||
// #ifdef APP-PLUS || H5
|
||||
uni.getSystemInfo({
|
||||
success: function(res) {
|
||||
// 首页没有title获取的整个页面的高度,里面的页面有原生标题要减掉就是视口的高度
|
||||
// 首页没有title获取的整个页面的高度,里面的页面有原生标题要减掉就是视口的高度
|
||||
// 状态栏是动态的可以拿到 标题栏是固定写死的是44px
|
||||
let height = res.windowHeight - res.statusBarHeight - 44
|
||||
// #ifdef H5
|
||||
// #ifdef H5 || APP-PLUS
|
||||
that.globalData.windowHeight = res.windowHeight + 'px'
|
||||
// #endif
|
||||
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
|
||||
// #ifdef MP
|
||||
const updateManager = uni.getUpdateManager();
|
||||
updateManager.onCheckForUpdate(function(res) {
|
||||
// 请求完新版本信息的回调
|
||||
if (res.hasUpdate) {
|
||||
updateManager.onUpdateReady(function(res2) {
|
||||
uni.showModal({
|
||||
title: '更新提示',
|
||||
content: '发现新版本,是否重启应用?',
|
||||
cancelColor: '#eeeeee',
|
||||
confirmColor: '#FF0000',
|
||||
success(res2) {
|
||||
if (res2.confirm) {
|
||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
updateManager.applyUpdate();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
updateManager.onUpdateFailed(function(res) {
|
||||
// 新的版本下载失败
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '检查到有新版本,但下载失败,请检查网络设置',
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
updateManager.applyUpdate();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (HTTP_REQUEST_URL == '') {
|
||||
console.error(
|
||||
"请配置根目录下的config.js文件中的 'HTTP_REQUEST_URL'\n\n请修改开发者工具中【详情】->【AppID】改为自己的Appid\n\n请前往后台【小程序】->【小程序配置】填写自己的 appId and AppSecret"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
//小程序扫码进入场景
|
||||
if (option.query.hasOwnProperty('scene')) {
|
||||
switch(option.scene){
|
||||
switch (option.scene) {
|
||||
case 1047: //扫描小程序码
|
||||
case 1048: //长按图片识别小程序码
|
||||
case 1049: //手机相册选取小程序码
|
||||
case 1001: //直接进入小程序
|
||||
|
||||
let value = this.$util.getUrlParams(decodeURIComponent(option.query.scene));
|
||||
let values = value.split(',');
|
||||
if(values.length === 2){
|
||||
let v1 = values[0].split(":");
|
||||
if (v1[0] === 'pid') {
|
||||
that.globalData.spid = v1[1];
|
||||
} else{
|
||||
that.globalData.id = v1[1];
|
||||
}
|
||||
let v2 = values[1].split(":");
|
||||
if (v2[0] === 'pid') {
|
||||
that.globalData.spid = v2[1];
|
||||
}else{
|
||||
that.globalData.id = v2[1];
|
||||
}
|
||||
}else{
|
||||
that.globalData.spid = values[0].split(":")[1];
|
||||
}
|
||||
break;
|
||||
let mapeMpQrCodeValue = this.$util.formatMpQrCodeData(value);
|
||||
// that.globalData = mapeMpQrCodeValue;
|
||||
that.globalData = Object.assign(that.globalData,mapeMpQrCodeValue);
|
||||
that.globalData.spread = mapeMpQrCodeValue.spread ? mapeMpQrCodeValue.spread : '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (option.spread) that.globalData.spread = option.spread;
|
||||
// #endif
|
||||
// 获取导航高度;
|
||||
uni.getSystemInfo({
|
||||
@@ -84,10 +135,19 @@
|
||||
that.globalData.navH = menuButtonInfo.top * 2 + menuButtonInfo.height / 2;
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
// #ifdef H5
|
||||
if (option.query.hasOwnProperty('type') && option.query.type == "iframeVisualizing") {
|
||||
this.globalData.isIframe = true;
|
||||
} else {
|
||||
this.globalData.isIframe = false;
|
||||
}
|
||||
|
||||
// wx公众号自动授权登录
|
||||
let snsapiBase = 'snsapi_base';
|
||||
let urlData = location.pathname + location.search;
|
||||
if (!that.$store.getters.isLogin && Auth.isWeixin()) {
|
||||
//publicLoginType,公众号登录方式(单选),1微信授权,2手机号登录
|
||||
if (!that.$store.getters.isLogin && Auth.isWeixin() && this.globalData.publicLoginType == 1 && !that
|
||||
.globalData.tokenIsExist) {
|
||||
const {
|
||||
code,
|
||||
state,
|
||||
@@ -97,8 +157,8 @@
|
||||
'/pages/users/wechat_login/index') === -1) {
|
||||
// 存储静默授权code
|
||||
uni.setStorageSync('snsapiCode', code);
|
||||
let spread = that.globalData.spid ? that.globalData.spid : 0;
|
||||
Auth.auth(code, that.$Cache.get('spread'))
|
||||
let spread = that.globalData.spread ? that.globalData.spread : 0;
|
||||
Auth.auth(code, that.$Cache.get('SPREAD'))
|
||||
.then(res => {
|
||||
uni.setStorageSync('snRouter', decodeURIComponent(decodeURIComponent(option.query
|
||||
.back_url)));
|
||||
@@ -114,9 +174,6 @@
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
// this.$util.Tips({
|
||||
// title: error
|
||||
// });
|
||||
if (!this.$Cache.has('snsapiKey')) {
|
||||
if (location.pathname.indexOf('/pages/users/wechat_login/index') === -1) {
|
||||
Auth.oAuth(snsapiBase, option.query.back_url);
|
||||
@@ -139,33 +196,56 @@
|
||||
|
||||
// #ifdef MP
|
||||
// 小程序静默授权
|
||||
if (!this.$store.getters.isLogin) {
|
||||
let spread = that.globalData.spid ? that.globalData.spid : 0;
|
||||
Routine.getCode()
|
||||
.then(code => {
|
||||
Routine.authUserInfo(code, {
|
||||
'spread_spid': spread
|
||||
}).then(res => {
|
||||
// that.$store.commit('AuthorizeType', res.data.type);
|
||||
})
|
||||
if (!this.$store.getters.isLogin && !this.globalData.tokenIsExist) {
|
||||
Routine.getCode().then(code => {
|
||||
Routine.authUserInfo(code)
|
||||
})
|
||||
.catch(res => {
|
||||
uni.hideLoading();
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
// 主题变色
|
||||
getTheme().then(resP => {
|
||||
that.globalData.theme = `theme${Number(resP.data.value)}`
|
||||
that.$Cache.set('theme', that.globalData.theme);
|
||||
// #ifdef H5
|
||||
window.document.documentElement.setAttribute('data-theme', that.globalData.theme);
|
||||
// #endif
|
||||
})
|
||||
},
|
||||
async mounted() {
|
||||
if(this.$store.getters.isLogin && !this.$Cache.get('USER_INFO'))await this.$store.dispatch('USERINFO');
|
||||
if (this.$store.getters.isLogin && !this.$Cache.get('USER_INFO')) await this.$store.dispatch('USERINFO');
|
||||
},
|
||||
methods: {
|
||||
//获取登录配置
|
||||
getLoginConfig() {
|
||||
loginConfigApi().then(res => {
|
||||
let data = res.data;
|
||||
//公众号登录方式(单选),1微信授权,2手机号登录
|
||||
this.globalData.publicLoginType = data.publicLoginType;
|
||||
this.$Cache.set('publicLoginType', data.publicLoginType);
|
||||
//小程序手机号校验类型(多选)1微信小程序验证 2短信验证
|
||||
this.globalData.routinePhoneVerification = data.routinePhoneVerification;
|
||||
//公司名称
|
||||
this.globalData.companyName = data.siteName || '欢迎你';
|
||||
uni.setStorageSync('companyName', data.siteName);
|
||||
//登录页logo
|
||||
this.globalData.mobileLoginLogo = data.mobileLoginLogo;
|
||||
uni.setStorageSync('mobileLoginLogo', data.mobileLoginLogo);
|
||||
//版权title
|
||||
uni.setNavigationBarTitle({
|
||||
title:data.siteName
|
||||
});
|
||||
})
|
||||
}
|
||||
},
|
||||
onShow: function() {
|
||||
// #ifdef H5
|
||||
uni.getSystemInfo({
|
||||
success(e) {
|
||||
/* 窗口宽度大于420px且不在PC页面且不在移动设备时跳转至 PC.html 页面 */
|
||||
if (e.windowWidth > 420 && !window.top.isPC && !/iOS|Android/i.test(e.system)) {
|
||||
if (e.windowWidth > 430 && !window.top.isPC && !/iOS|Android/i.test(e.system)) {
|
||||
// window.location.pathname = 'https://java.crmeb.net/';
|
||||
/* 若你的项目未设置根目录(默认为 / 时),则使用下方代码 */
|
||||
window.location.pathname = '/static/html/pc.html';
|
||||
@@ -174,23 +254,17 @@
|
||||
})
|
||||
// #endif
|
||||
},
|
||||
onHide: function() {
|
||||
//console.log('App Hide')
|
||||
}
|
||||
onHide: function() {}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
<style lang="scss">
|
||||
@import url("@/plugin/animate/animate.min.css");
|
||||
@import 'static/css/base.css';
|
||||
@import 'static/iconfont/iconfont.css';
|
||||
@import 'static/css/guildford.css';
|
||||
@import 'static/css/style.scss';
|
||||
|
||||
// #ifdef APP
|
||||
@import 'static/iconfont/iconfont.css';
|
||||
@import 'static/iconfont/iconfont-app.css';
|
||||
// #endif
|
||||
@import 'static/css/unocss.css';
|
||||
@import 'static/fonts/font.css';
|
||||
|
||||
/* 条件编译,仅在H5平台生效 */
|
||||
// #ifdef H5
|
||||
@@ -205,7 +279,7 @@
|
||||
}
|
||||
|
||||
.bg-color-red {
|
||||
background-color: #E93323 !important;
|
||||
background-color: #E93323;
|
||||
}
|
||||
|
||||
.syspadding {
|
||||
@@ -226,4 +300,4 @@
|
||||
height: 0;
|
||||
color: transparent;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
Reference in New Issue
Block a user