1 Star 0 Fork 0

wengcy/mirror-motorbike

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
App.vue 3.03 KB
一键复制 编辑 原始数据 按行查看 历史
wengcy 提交于 2023-07-15 09:20 . first commit
<script>
import {
checkRegisterAPI,
getTokenAPI,
refreshTokenFun
} from "@/api/api/user"
import {
baseUrl
} from '@/api/http/setting'
import {
bluetoothStart,
closeBLEConnection
} from "@/static/bluetooth/core.js"
import loginMixins from "@/pages/loginMixins.js"
import {client} from "@/utils/utils.js"
export default {
mixins: [loginMixins],
//小程序启动的时候
onLaunch: function(option) {
console.log("onLaunch")
//#ifdef MP-WEIXIN
if(baseUrl.indexOf("https://car.cq-ct.com") == -1){
uni.setEnableDebug({
enableDebug: true
})
this.$store.commit("setIsProduct",false);
}else{
this.$store.commit("setIsProduct",true);
}
//#endif
// if (uni.getSystemInfoSync().platform !== "devtools") {
// console.log = () => {};
// }
},
onShow: function() {
let option = uni.getLaunchOptionsSync();
console.log("option",option);
if (!this.$store.state.specialAppOnShow) {
//#ifdef MP-WEIXIN
this.initOnLoad();
//#endif
//#ifdef H5
this.initIndex();
//#endif
}
},
onHide: function() {
if (!this.$store.state.specialAppOnShow) {
//取消连接
if (!this.$validatenull(client)) {
client.end();
}
//断开蓝牙连接
if (!this.$validatenull(this.$store.state.bluetoothDevice)) {
closeBLEConnection(this.$store.state.bluetoothDevice);
}
if (!this.$validatenull(this.$store.state.blueConnectTimer)) {
clearInterval(this.$store.state.blueConnectTimer);
}
// if (!this.$validatenull(this.refreshTime)) {
// clearInterval(this.refreshTime);
// }
}
},
methods: {
initOnLoad() {
let that = this;
uni.login({
success: (loginRes) => {
checkRegisterAPI({
code: loginRes.code
}).then(([err, data]) => {
if (err) return;
if (data.registered == true) {
getTokenAPI({
oauthId: data.oauthId
}).then(([err2, data2]) => {
if (err2) return;
let loginUser = {
access_token: data2.access_token,
avatar: data2.avatar,
expires_in: data2.expires_in,
nick_name: data2.nick_name,
phone: data2.phone,
refresh_token: data2.refresh_token,
user_id: data2.user_id
}
this.$store.commit("setLoginUser",loginUser);
//this.$u.vuex('datetime', new Date().getTime());
refreshTokenFun();
this.initIndex();
})
} else {
this.$reLaunch("/pages/views/home/login");
}
})
},
fail:(res)=>{
console.log("uni.login-fail",res);
that.$showModal(res.errMsg == "login:fail Failed to fetch" ? "当前无网络信号,请稍后重试":res.errMsg);
}
});
}
}
}
</script>
<style lang="scss">
/*uview全局样式*/
@import "uview-ui/index.scss";
@import 'static/text_font/font.css';
@import 'uview-ui/libs/css/flex.scss';
/*common全局样式*/
@import 'static/style/common.scss';
</style>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wengcy/mirror-motor.git
git@gitee.com:wengcy/mirror-motor.git
wengcy
mirror-motor
mirror-motorbike
master

搜索帮助