suke-mp/src/App.vue
2024-05-22 18:02:54 +08:00

219 lines
6.1 KiB
Vue

<script lang='ts'>
import { mpUpdate, setCompanyId, setReferrerUserId, setRegisterStoreId } from '@/utils';
import { Logger } from '@/utils/common/logger';
const logger = new Logger();
export default {
onLaunch: async (options: any) => {
console.log('App Launch options ', options);
const miniProgram = uni.getAccountInfoSync().miniProgram;
const env = miniProgram.envVersion;
//生产
if(env === 'release' || env === 'trial') {
logger.info(`launch options ${env}: `, options);
async function getVersionStatus() {
return new Promise((resolve, reject) => {
uni.request({
url: 'https://api.lakeapp.cn/wechat/version_info',
success(res) {
console.log(res);
resolve(res);
},
fail(exception) {
reject(exception);
}
});
}).then((res) => {
const { version, audit } = res.data;
// if(miniProgram.version === version && audit == 1) {
if(audit == 1) {
setCompanyId('1150930317231112193');
setRegisterStoreId('1150930317436633090');
}
});
}
await getVersionStatus();
}
//测试、开发 trial,develop
else {
// setCompanyId('1724629180555919361');
// setRegisterStoreId('1725026299888406529');
// setCompanyId('1471673498334113794');
// setRegisterStoreId('1471673498413805570');
setCompanyId('1150930317231112193');
setRegisterStoreId('1150930317436633090');
}
if(options?.query) {
// options.query.scene = 'companyId%3D1150930317231112193%26wxOpenId%3D111%26ticketId%3D123456%26storeId%3D1150930317436633090'
//保存登录邀请员工id
if(options.query.referrerUserId) {
setReferrerUserId(options.query.referrerUserId);
}
//保存注册门店id
if(options.query.companyId) {
setCompanyId(options.query.companyId);
}
//保存注册门店id
if(options.query.storeId) {
setRegisterStoreId(options.query.storeId);
}
if(options?.query.scene) {
function getQueryParam(queryParams: string, key: string) {
let regex = new RegExp('(?:[?&]|^)' + key + '=([^&]+)'),
match = queryParams.match(regex);
return match && match[1];
}
//保存注册门店id
const params = decodeURIComponent(options?.query.scene);
if(params.includes('companyId')) {
setCompanyId(getQueryParam(params, 'companyId') || '');
}
if(params.includes('storeId')) {
setRegisterStoreId(getQueryParam(params, 'storeId') || '');
}
if(options?.query.scene === 'edit_avatar_nickname') {
setTimeout(() => {
uni.reLaunch({
url: '/pages/mine/subs/profile/index'
});
}, 500);
}
}
}
// #ifdef MP
mpUpdate();
// #endif
},
onShow: async () => {
console.log('App Show');
},
onHide: async () => {
console.log('App Hide');
},
globalData: {
logger: logger
}
};
// onLaunch(async (options) => {
// console.log('App Launch options ', options);
// // globalData.logger.info('launch options : ', options);
//
// const miniProgram = uni.getAccountInfoSync().miniProgram;
// const env = miniProgram.envVersion;
//
// logger.info('launch options env : ', `${env} ${options}`);
// //生产
// if(env === 'release' || env === 'trial') {
// async function getVersionStatus() {
// return new Promise((resolve, reject) => {
// uni.request({
// url: 'https://api.lakeapp.cn/wechat/version_info',
// success(res) {
// console.log(res);
// resolve(res);
// },
// fail(exception) {
// reject(exception);
// }
// });
// }).then((res) => {
// const { version, audit } = res.data;
// // if(miniProgram.version === version && audit == 1) {
// if(audit == 1) {
// setCompanyId('1150930317231112193');
// setRegisterStoreId('1150930317436633090');
// }
// });
// }
//
// await getVersionStatus();
// }
//
// //测试、开发 trial,develop
// else {
// // setCompanyId('1724629180555919361');
// // setRegisterStoreId('1725026299888406529');
// setCompanyId('1471673498334113794');
// setRegisterStoreId('1471673498413805570');
// }
//
// if(options?.query) {
//
// // options.query.scene = 'companyId%3D1150930317231112193%26wxOpenId%3D111%26ticketId%3D123456%26storeId%3D1150930317436633090'
//
// //保存登录邀请员工id
// if(options.query.referrerUserId) {
// setReferrerUserId(options.query.referrerUserId);
// }
//
// //保存注册门店id
// if(options.query.companyId) {
// setCompanyId(options.query.companyId);
// }
//
// //保存注册门店id
// if(options.query.storeId) {
// setRegisterStoreId(options.query.storeId);
// }
//
// if(options?.query.scene) {
// function getQueryParam(queryParams: string, key: string) {
// let regex = new RegExp('(?:[?&]|^)' + key + '=([^&]+)'),
// match = queryParams.match(regex);
// return match && match[1];
// }
//
// //保存注册门店id
// const params = decodeURIComponent(options?.query.scene);
// if(params.includes('companyId')) {
// setCompanyId(getQueryParam(params, 'companyId') || '');
// }
// if(params.includes('storeId')) {
// setRegisterStoreId(getQueryParam(params, 'storeId') || '');
// }
// if(options?.query.scene === 'edit_avatar_nickname') {
// setTimeout(() => {
// uni.reLaunch({
// url: '/pages/mine/subs/profile/index'
// });
// }, 500);
// }
// }
// }
//
// // #ifdef MP
// mpUpdate();
// // #endif
// });
// onShow(() => {
// console.log('App Show');
// });
// onHide(() => {
// console.log('App Hide');
// });
</script>
<style lang='scss'>
/* 每个页面公共css */
@import 'uview-plus/index.scss';
@import '@/static/styles/common.scss';
</style>