You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
3.1 KiB
120 lines
3.1 KiB
<script>
|
|
import store from '@/store'
|
|
import StoreModel from '@/common/model/Store'
|
|
import { getSceneData } from './core/app'
|
|
import { isObject } from './utils/util'
|
|
|
|
export default {
|
|
|
|
/**
|
|
* 全局变量
|
|
*/
|
|
globalData: {},
|
|
|
|
/**
|
|
* 初始化完成时触发
|
|
*/
|
|
onLaunch({ path, query, scene }) {
|
|
console.log(this.$route);
|
|
// #ifdef H5
|
|
const storeId = this.$route.query.storeId || this.getQueryString('storeId') || '';
|
|
console.log(storeId);
|
|
if (storeId) {
|
|
uni.setStorageSync('storeId', storeId || '');
|
|
}
|
|
// #endif
|
|
// #ifdef MP
|
|
// 小程序主动更新
|
|
this.updateManager()
|
|
// #endif
|
|
// app启动参数
|
|
this.onStartupQuery(isObject(query) ? query : {})
|
|
// 获取商城基础信息
|
|
this.getStoreInfo()
|
|
},
|
|
onShow(options) {
|
|
console.log('app onShow', options);
|
|
if (options.referrerInfo) {
|
|
// wx.showToast({
|
|
// title: params.errStr,
|
|
// icon: 'none',
|
|
// });
|
|
uni.$emit('appShow', options.referrerInfo);
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
|
|
getQueryString(name) {
|
|
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
|
|
var r = window.location.search.substr(1).match(reg);
|
|
if (r != null) {
|
|
return unescape(r[2]);
|
|
}
|
|
return null;
|
|
},
|
|
|
|
// app启动参数
|
|
onStartupQuery(query) {
|
|
// 获取二维码场景值
|
|
const scene = getSceneData(query)
|
|
// 记录推荐人ID
|
|
const refereeId = query.refereeId ? query.refereeId : scene.uid
|
|
refereeId > 0 && (this.setRefereeId(refereeId))
|
|
},
|
|
|
|
// 记录推荐人ID
|
|
setRefereeId(refereeId) {
|
|
store.dispatch('setRefereeId', refereeId)
|
|
},
|
|
|
|
// 获取商城基础信息
|
|
getStoreInfo() {
|
|
StoreModel.data(false)
|
|
},
|
|
|
|
// 小程序主动更新
|
|
updateManager() {
|
|
const updateManager = uni.getUpdateManager()
|
|
updateManager.onCheckForUpdate(res => {
|
|
// 请求完新版本信息的回调
|
|
// console.log(res.hasUpdate)
|
|
})
|
|
updateManager.onUpdateReady(() => {
|
|
uni.showModal({
|
|
title: '更新提示',
|
|
content: '新版本已经准备好,即将重启应用',
|
|
showCancel: false,
|
|
success(res) {
|
|
if (res.confirm) {
|
|
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
updateManager.applyUpdate()
|
|
}
|
|
}
|
|
})
|
|
})
|
|
updateManager.onUpdateFailed(() => {
|
|
// 新的版本下载失败
|
|
uni.showModal({
|
|
title: '更新提示',
|
|
content: '新版本下载失败',
|
|
showCancel: false
|
|
})
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
/* uView库样式 */
|
|
@import "./uni_modules/vk-uview-ui/index.scss";
|
|
/* uni-icons样式*/
|
|
@import "./uni_modules/uni-icons/components/uni-icons/uniicons.css";
|
|
/* 项目基础样式 */
|
|
@import "./app.scss";
|
|
/* iconfont图标库 */
|
|
@import "./utils/iconfont.scss";
|
|
</style> |