cyywl_server/yudao-ui-app/App.vue

353 lines
11 KiB
Vue
Raw Normal View History

2022-04-06 16:08:26 +08:00
<script>
2023-05-16 18:00:52 +08:00
import {
checkLogin
} from "./libs/login";
import {
2023-05-18 18:07:27 +08:00
refreshToken,
2023-05-19 11:25:26 +08:00
getWeChatOpenId,
fetchTenantInfo,
fetchMemberChangeSpreadId
2023-05-16 18:00:52 +08:00
} from "@/api/api";
import {
HTTP_REQUEST_URL,
SPREAD_LINK,
WX_APP_ID
2023-05-16 18:00:52 +08:00
} from './config/app';
import Auth from './libs/wechat.js';
import Routine from './libs/routine.js';
import Apps from './libs/apps.js';
import {
2023-05-19 11:25:26 +08:00
mapActions,
mapGetters
2023-05-16 18:00:52 +08:00
} from 'vuex'
2023-05-19 11:34:07 +08:00
import {
memberGradeInfo
} from '@/api/member.js';
2023-05-16 18:00:52 +08:00
export default {
globalData: {
spid: 0,
code: 0,
isLogin: false,
userInfo: {},
MyMenus: [],
windowHeight: 0,
id: 0
},
onLaunch: function(option) {
let that = this;
// #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-05-15 10:12:22 +08:00
2023-05-16 18:00:52 +08:00
}
});
// #endif
2023-05-15 10:12:22 +08:00
2023-05-16 18:00:52 +08:00
// #ifdef MP
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) {
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;
}
}
// #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
2023-05-15 10:12:22 +08:00
2023-05-16 18:00:52 +08:00
// #ifdef H5
let snsapiBase = 'snsapi_base';
let urlData = location.pathname + location.search;
if (!that.$store.getters.isLogin && Auth.isWeixin()) {
const {
code,
state,
scope
} = option.query;
if (code && code != uni.getStorageSync('snsapiCode') && location.pathname.indexOf(
'/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'))
.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)));
}
})
.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);
}
}
});
} 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
2023-05-15 10:12:22 +08:00
2023-05-16 18:00:52 +08:00
// #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);
})
})
.catch(res => {
uni.hideLoading();
});
}
// #endif
},
computed: {
...mapGetters(['tenantId', 'uid', 'spreadId']),
spreadDataChange() {
return {
uid: this.uid,
spreadId: this.spreadId
}
}
},
2023-05-19 17:34:57 +08:00
mounted() {
2023-06-08 17:29:04 +08:00
console.log('query--print', this.$route.query)
2023-05-19 17:34:57 +08:00
this.initLoad()
2023-05-16 18:00:52 +08:00
},
watch: {
spreadDataChange: function() {
if (this.uid && this.spreadId) {
fetchMemberChangeSpreadId(this.spreadId)
}
}
},
2023-05-16 18:00:52 +08:00
methods: {
async initLoad() {
2023-05-19 17:34:57 +08:00
this.isQRCode()
2023-06-08 15:15:08 +08:00
this.isProperty()
2023-05-19 17:34:57 +08:00
this.setSpreadId()
if (this.$store.getters.isLogin && !this.$Cache.get('USER_INFO')) {
await this.$store.dispatch('USERINFO');
}
if (!this.$Cache.get('TENANT_ID') || this.$route.query.tenantId) {
this.getTenantId()
} else {
this.getTenantInfo()
}
if (!this.$Cache.get('OPEN_ID') && this.$route.query.code) {
this.getWxChatCode()
}
setInterval(() => {
if (this.$store.getters.isLogin) {
this.setRefreshToken()
}
}, 600000)
2023-05-19 17:34:57 +08:00
},
2023-05-19 16:10:03 +08:00
// 是否扫码跳转
isQRCode() {
const redirectUrl = this.$route.query.redirectUrl || ''
if (redirectUrl) {
const tenantId = this.$route.query.tenantId || ''
const spreadId = this.$route.query.spreadId || ''
const isProperty = this.$route.query.isProperty || ''
const wechatUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + WX_APP_ID
2023-06-08 17:29:04 +08:00
const url = encodeURIComponent(`${redirectUrl}${SPREAD_LINK}?tenantId=${tenantId}&spreadId=${spreadId}&isProperty=${isProperty}`)
location.href =
2023-06-08 17:29:04 +08:00
`${wechatUrl}&redirect_uri=${url}&response_type=code&scope=snsapi_base#wechat_redirect`
2023-05-19 16:10:03 +08:00
}
},
// 是否扫物业二维码
isProperty() {
2023-06-08 16:44:43 +08:00
const is_property = this.$route.query.isProperty || '0'
if(parseInt(is_property) === 1){
this.$store.commit("SET_IS_PROPERTY", !!is_property)
}
},
2023-05-19 11:25:26 +08:00
// 获取租户信息
getTenantInfo() {
fetchTenantInfo(this.tenantId).then(res => {
this.$store.commit("SET_TENANT_INFO", res.data);
})
},
2023-05-18 18:07:27 +08:00
// 获取租户ID
2023-05-18 14:56:38 +08:00
getTenantId() {
2023-05-19 16:10:03 +08:00
const tenantId = this.$route.query.tenantId || ''
2023-05-18 14:56:38 +08:00
if (tenantId) {
this.$store.commit("SET_TENANTID", tenantId);
2023-05-19 11:25:26 +08:00
this.getTenantInfo()
2023-05-18 14:56:38 +08:00
} else {
this.$util.Tips({
2023-05-18 18:07:27 +08:00
title: '请扫码物业公司二维码访问'
2023-05-18 14:56:38 +08:00
});
}
},
2023-05-18 18:07:27 +08:00
// 获取推广员ID
setSpreadId() {
2023-05-19 16:10:03 +08:00
const spreadId = this.$route.query.spreadId || ''
if (spreadId) {
2023-05-18 18:07:27 +08:00
this.$store.commit("SET_SPREADID", spreadId);
}
},
// 获取微信授权code
getWxChatCode() {
const code = this.$route.query.code
getWeChatOpenId(code).then(res => {
2023-05-19 11:25:26 +08:00
if (res.data) {
this.$store.commit("SET_OPENID", res.data);
2023-05-18 18:07:27 +08:00
}
})
},
2023-05-16 18:00:52 +08:00
setRefreshToken() {
refreshToken(this.$Cache.get("REFRESH_TOKEN"))
.then(res => {
let data = res.data;
this.$store.commit("LOGIN", {
'token': data.accessToken,
'refreshToken': data.refreshToken
});
})
.catch(res => {
this.$util.Tips({
title: res
});
});
}
},
onShow: async function() {
// const res = await memberGradeInfo()
// if(res.data.some((item) => !!parseInt(item.isExist))){
// uni.setTabBarItem({
// index: 0,
// pagePath: '/pages/member_equity/index'
// })
// uni.switchTab({
// url:'/pages/member_equity/index'
// })
// }
2023-05-16 18:00:52 +08:00
// #ifdef H5
uni.getSystemInfo({
success(e) {
/* 窗口宽度大于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
},
onHide: function() {
//console.log('App Hide')
}
}
2022-04-06 16:08:26 +08:00
</script>
2023-05-15 10:12:22 +08:00
<style>
2023-05-16 18:00:52 +08:00
@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';
2023-05-15 10:12:22 +08:00
2023-05-16 18:00:52 +08:00
/* 条件编译仅在H5平台生效 */
// #ifdef H5
body::-webkit-scrollbar,
html::-webkit-scrollbar {
display: none;
}
2023-05-15 10:12:22 +08:00
2023-05-16 18:00:52 +08:00
// #endif
view {
box-sizing: border-box;
}
2023-05-15 10:12:22 +08:00
2023-05-16 18:00:52 +08:00
.bg-color-red {
background-color: #E93323 !important;
}
2023-05-15 10:12:22 +08:00
2023-05-16 18:00:52 +08:00
.syspadding {
padding-top: var(--status-bar-height);
}
2023-05-15 10:12:22 +08:00
2023-05-16 18:00:52 +08:00
.flex {
display: flex;
}
2023-05-16 18:00:52 +08:00
.uni-scroll-view::-webkit-scrollbar {
/* 隐藏滚动条,但依旧具备可以滚动的功能 */
display: none
}
2023-05-16 18:00:52 +08:00
::-webkit-scrollbar {
width: 0;
height: 0;
color: transparent;
}
2023-05-29 17:31:52 +08:00
</style>