2020-08-13 08:12:57 +00:00
|
|
|
|
<script>
|
2023-06-26 16:06:02 +00:00
|
|
|
|
import { HTTP_REQUEST_URL } from './config/app';
|
2021-06-11 09:41:16 +00:00
|
|
|
|
import Auth from './libs/wechat.js';
|
|
|
|
|
import Routine from './libs/routine.js';
|
2020-08-13 08:12:57 +00:00
|
|
|
|
export default {
|
|
|
|
|
globalData: {
|
|
|
|
|
spid: 0,
|
2021-06-11 09:41:16 +00:00
|
|
|
|
code: 0,
|
|
|
|
|
isLogin: false,
|
|
|
|
|
userInfo: {},
|
|
|
|
|
MyMenus: [],
|
|
|
|
|
windowHeight: 0,
|
|
|
|
|
id: 0
|
|
|
|
|
},
|
2020-08-13 08:12:57 +00:00
|
|
|
|
onLaunch: function(option) {
|
|
|
|
|
let that = this;
|
2023-06-26 16:06:02 +00:00
|
|
|
|
// 获得全局的 window 高度
|
2021-06-11 09:41:16 +00:00
|
|
|
|
// #ifdef H5
|
|
|
|
|
uni.getSystemInfo({
|
|
|
|
|
success: function(res) {
|
|
|
|
|
// 首页没有title获取的整个页面的高度,里面的页面有原生标题要减掉就是视口的高度
|
|
|
|
|
// 状态栏是动态的可以拿到 标题栏是固定写死的是44px
|
|
|
|
|
let height = res.windowHeight - res.statusBarHeight - 44
|
|
|
|
|
// #ifdef H5
|
|
|
|
|
that.globalData.windowHeight = res.windowHeight + 'px'
|
|
|
|
|
// #endif
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-06-26 16:06:02 +00:00
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
// 获取导航高度;
|
|
|
|
|
uni.getSystemInfo({
|
|
|
|
|
success: function(res) {
|
|
|
|
|
that.globalData.navHeight = res.statusBarHeight * (750 / res.windowWidth) + 91;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// #ifdef MP
|
|
|
|
|
let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
|
|
|
|
|
that.globalData.navH = menuButtonInfo.top * 2 + menuButtonInfo.height / 2;
|
|
|
|
|
// #endif
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
2020-08-13 08:12:57 +00:00
|
|
|
|
// #ifdef MP
|
2023-06-26 16:06:02 +00:00
|
|
|
|
if (HTTP_REQUEST_URL === '') {
|
2021-06-11 09:41:16 +00:00
|
|
|
|
console.error(
|
|
|
|
|
"请配置根目录下的config.js文件中的 'HTTP_REQUEST_URL'\n\n请修改开发者工具中【详情】->【AppID】改为自己的Appid\n\n请前往后台【小程序】->【小程序配置】填写自己的 appId and AppSecret"
|
|
|
|
|
);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-06-26 16:06:02 +00:00
|
|
|
|
// TODO 芋艿: 分销
|
2021-06-11 09:41:16 +00:00
|
|
|
|
if (option.query.hasOwnProperty('scene')) {
|
|
|
|
|
switch(option.scene){
|
2023-06-26 16:06:02 +00:00
|
|
|
|
case 1047: // 扫描小程序码
|
|
|
|
|
case 1048: // 长按图片识别小程序码
|
|
|
|
|
case 1049: // 手机相册选取小程序码
|
|
|
|
|
case 1001: // 直接进入小程序
|
2021-06-11 09:41:16 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// #endif
|
|
|
|
|
|
2023-06-26 16:06:02 +00:00
|
|
|
|
// #ifdef H5
|
|
|
|
|
// TODO 芋艿:公众号的静默授权
|
2021-06-11 09:41:16 +00:00
|
|
|
|
let snsapiBase = 'snsapi_base';
|
|
|
|
|
let urlData = location.pathname + location.search;
|
|
|
|
|
if (!that.$store.getters.isLogin && Auth.isWeixin()) {
|
2023-06-26 16:06:02 +00:00
|
|
|
|
const { code, state, scope } = option.query;
|
|
|
|
|
if (code && code != uni.getStorageSync('snsapiCode')
|
|
|
|
|
&& location.pathname.indexOf('/pages/users/wechat_login/index') === -1) {
|
2021-06-11 09:41:16 +00:00
|
|
|
|
// 存储静默授权code
|
|
|
|
|
uni.setStorageSync('snsapiCode', code);
|
|
|
|
|
let spread = that.globalData.spid ? that.globalData.spid : 0;
|
|
|
|
|
Auth.auth(code, that.$Cache.get('spread'))
|
|
|
|
|
.then(res => {
|
|
|
|
|
uni.setStorageSync('snRouter', decodeURIComponent(decodeURIComponent(option.query
|
|
|
|
|
.back_url)));
|
|
|
|
|
if (res.type === 'register') {
|
|
|
|
|
this.$Cache.set('snsapiKey', res.key);
|
|
|
|
|
}
|
|
|
|
|
if (res.type === 'login') {
|
|
|
|
|
this.$store.commit('LOGIN', {
|
|
|
|
|
token: res.token
|
|
|
|
|
});
|
|
|
|
|
this.$store.commit("SETUID", res.uid);
|
|
|
|
|
location.replace(decodeURIComponent(decodeURIComponent(option.query.back_url)));
|
|
|
|
|
}
|
2023-06-26 16:06:02 +00:00
|
|
|
|
}).catch(error => {
|
2021-06-11 09:41:16 +00:00
|
|
|
|
if (!this.$Cache.has('snsapiKey')) {
|
|
|
|
|
if (location.pathname.indexOf('/pages/users/wechat_login/index') === -1) {
|
|
|
|
|
Auth.oAuth(snsapiBase, option.query.back_url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
if (!this.$Cache.has('snsapiKey')) {
|
|
|
|
|
if (location.pathname.indexOf('/pages/users/wechat_login/index') === -1) {
|
|
|
|
|
Auth.oAuth(snsapiBase, urlData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (option.query.back_url) {
|
|
|
|
|
location.replace(uni.getStorageSync('snRouter'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
// #ifdef MP
|
2023-06-26 16:06:02 +00:00
|
|
|
|
// 小程序静默授权 TODO 芋艿:
|
2021-06-11 09:41:16 +00:00
|
|
|
|
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);
|
|
|
|
|
})
|
2023-06-26 16:06:02 +00:00
|
|
|
|
}).catch(res => {
|
2021-06-11 09:41:16 +00:00
|
|
|
|
uni.hideLoading();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// #endif
|
|
|
|
|
},
|
|
|
|
|
async mounted() {
|
2023-06-26 16:06:02 +00:00
|
|
|
|
// 读取用户的基本信息
|
|
|
|
|
if (this.$store.getters.isLogin && !this.$Cache.get('USER_INFO')) {
|
|
|
|
|
await this.$store.dispatch('USERINFO');
|
|
|
|
|
}
|
2020-08-13 08:12:57 +00:00
|
|
|
|
},
|
2020-11-05 08:21:06 +00:00
|
|
|
|
onShow: function() {
|
2021-06-11 09:41:16 +00:00
|
|
|
|
// #ifdef H5
|
|
|
|
|
uni.getSystemInfo({
|
|
|
|
|
success(e) {
|
2023-06-26 16:06:02 +00:00
|
|
|
|
// TODO 芋艿:这样是否合理???
|
2021-06-11 09:41:16 +00:00
|
|
|
|
/* 窗口宽度大于420px且不在PC页面且不在移动设备时跳转至 PC.html 页面 */
|
|
|
|
|
if (e.windowWidth > 420 && !window.top.isPC && !/iOS|Android/i.test(e.system)) {
|
|
|
|
|
// window.location.pathname = 'https://java.crmeb.net/';
|
|
|
|
|
/* 若你的项目未设置根目录(默认为 / 时),则使用下方代码 */
|
|
|
|
|
window.location.pathname = '/static/html/pc.html';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// #endif
|
2020-08-13 08:12:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<style>
|
|
|
|
|
@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';
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
2020-11-05 08:21:06 +00:00
|
|
|
|
/* 条件编译,仅在H5平台生效 */
|
|
|
|
|
// #ifdef H5
|
2021-06-11 09:41:16 +00:00
|
|
|
|
body::-webkit-scrollbar,
|
|
|
|
|
html::-webkit-scrollbar {
|
|
|
|
|
display: none;
|
2020-11-05 08:21:06 +00:00
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
2020-11-05 08:21:06 +00:00
|
|
|
|
// #endif
|
2021-06-11 09:41:16 +00:00
|
|
|
|
view {
|
2020-08-13 08:12:57 +00:00
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
2020-08-13 08:12:57 +00:00
|
|
|
|
.bg-color-red {
|
2021-06-11 09:41:16 +00:00
|
|
|
|
background-color: #E93323 !important;
|
2020-08-13 08:12:57 +00:00
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
|
|
|
|
.syspadding {
|
2020-08-13 08:12:57 +00:00
|
|
|
|
padding-top: var(--status-bar-height);
|
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
|
|
|
|
.flex {
|
2020-08-13 08:12:57 +00:00
|
|
|
|
display: flex;
|
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
2020-08-13 08:12:57 +00:00
|
|
|
|
.uni-scroll-view::-webkit-scrollbar {
|
|
|
|
|
/* 隐藏滚动条,但依旧具备可以滚动的功能 */
|
|
|
|
|
display: none
|
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
|
2020-08-13 08:12:57 +00:00
|
|
|
|
::-webkit-scrollbar {
|
2021-06-11 09:41:16 +00:00
|
|
|
|
width: 0;
|
|
|
|
|
height: 0;
|
|
|
|
|
color: transparent;
|
2020-08-13 08:12:57 +00:00
|
|
|
|
}
|
2021-06-11 09:41:16 +00:00
|
|
|
|
</style>
|