TALL renderjs vue3版本
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.
 
 
 
 

84 lines
2.2 KiB

<script>
import { ref, computed } from 'vue';
import store from '@/store/index.js';
import ui from '@/utils/ui.js';
import storage from '@/utils/storage.js';
export default {
setup() {
return {
}
},
async onLaunch(options) {
console.log('options: ', options);
this.checkNetwork(); // 监听网络状态
this.getSystemInfo(); // 获取系统设备信息
// 登录 - H5、APP
/* #ifndef MP-WEIXIN */
if (!store.state.user.token) {
// 不论有没有token都直接从userId获取token
// token有过期时间 从本地获取可能是过期 干脆直接从userId获取
if (!options.query || !options.query.u) {
// 参数里没有u (userId)提示
ui.showToast('缺少用户信息参数');
} else {
const data = await store.dispatch('user/getTokenByUserId', options.query.u);
this.noPhone(data.phone);
}
}
/* #endif */
store.dispatch('socket/initSocket');
},
methods: {
// 检查网络状态 设置store里的网络状态变量
// 网络连接 且 不是2g 不是3g 才算是网络连接; 否则不是 将启用本地存储
checkNetwork() {
uni.getNetworkType({
success: ({ networkType }) => {
store.commit('setNetworkConnected', !(networkType === 'none' || networkType === '2g' || networkType === '3g'));
},
});
// 监听网络状态的变化
uni.onNetworkStatusChange(({ isConnected, networkType }) => {
store.commit('setNetworkConnected', isConnected && !(networkType === '2g' || networkType === '3g'));
});
},
// 获取系统设备信息
getSystemInfo() {
uni.getSystemInfo({
success: result => {
store.commit('setSystemInfo', result);
},
fail: error => {
console.error('getSystemInfo fail:', error);
},
});
},
/**
* 没有手机号 跳转绑定手机号的界面
* @param {string} phone
*/
async noPhone(phone) {
if (!phone) {
this.$u.route('/pages/phone-bind/phone-bind');
}
},
}
}
</script>
<style lang="scss">
/*每个页面公共css */
@import "@/uni_modules/vk-uview-ui/index.scss";
@import '@/common/styles/iconfont.scss';
@import '@/common/styles/app.scss';
</style>