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.

103 lines
2.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<script>
// 平台检测和plus API兼容性处理
let main = null;
// 检查是否为App端避免H5端调用plus API报错
// #ifdef APP-PLUS
if (typeof plus !== 'undefined' && plus.android) {
main = plus.android.runtimeMainActivity();
// 为了保证UHF正常关闭下电延迟退出APP
if (uni.getSystemInfoSync().platform == 'android') {
plus.runtime.quit = function() {
setTimeout(() => {
main.finish()
}, 10)
};
}
}
// #endif
var hhwUHFController;
export default {
globalData: {
// 原生插件只在App端可用H5端需要做兼容处理
hhwUHFController: null,
globalEvent: null
},
onLaunch: function() {
console.log('App Launch')
// 初始化原生插件只在App端有效
// #ifdef APP-PLUS
this.globalData.hhwUHFController = uni.requireNativePlugin('HL-HHWUHFController');
this.globalData.globalEvent = uni.requireNativePlugin('globalEvent');
// #endif
hhwUHFController = this.globalData.hhwUHFController;
const token = uni.getStorageSync('token');
if (!token) {
uni.reLaunch({ url: '/pages/login/login' });
console.log('App Launch token1234',token)
} else {
uni.reLaunch({ url: '/pages/index/index' });
}
},
onShow: function() {
console.log('App Show')
// UHF控制器只在App端有效H5端跳过相关操作
// #ifdef APP-PLUS
if (hhwUHFController) {
// 开启插件java接口的日志打印
hhwUHFController.setDebuggable(true, result => {
console.log("App Show", "setDebuggable: " + result);
});
// 初始化超高频UHF上电
var enterTime = Date.now();
var outTime = enterTime;
hhwUHFController.initUhf(result => {
outTime = Date.now();
console.log("App Show", "initUHF: " + result, "cusTime: " + (outTime - enterTime));
uni.showToast({
title: '初始化成功',
icon: "none",
duration: 1000
});
});
}
// #endif
// #ifdef H5
console.log('H5端跳过UHF初始化操作');
// #endif
},
onHide: function() {
console.log('App Hide')
// UHF控制器只在App端有效H5端跳过相关操作
// #ifdef APP-PLUS
if (hhwUHFController) {
// 关闭超高频UHF下电
hhwUHFController.closeUhf(result => {
console.log("App Hide", "closeUhf: " + result);
uni.showToast({
title: '关闭成功',
icon: "none",
duration: 1000
});
});
}
// #endif
// #ifdef H5
console.log('H5端跳过UHF关闭操作');
// #endif
}
}
</script>
<style>
/*每个页面公共css */
</style>