144 lines
4.6 KiB
TypeScript
144 lines
4.6 KiB
TypeScript
/**
|
|
* 全局文件配置
|
|
*/
|
|
import { store } from '@/store'
|
|
import { setStorage, getStorage } from "@/utils/storage";
|
|
import Bluetooth from '@/utils/bluetoothPrinter/bluetooth'
|
|
import useGlobalFunc from './composables/useGlobalFunc';
|
|
import { onShow, onLaunch } from '@dcloudio/uni-app';
|
|
|
|
|
|
function App() {
|
|
// const bluetooth = new Bluetooth()
|
|
const bluetooth: any = getStorage('deviceName') ? new Bluetooth() : null
|
|
const { setPrinterStatus } = useGlobalFunc()
|
|
/**
|
|
* 小程序冷启动
|
|
*/
|
|
onLaunch(async (params: any) => {
|
|
// 订单管理-新订单通知
|
|
if (params.query && params.query.jxStoreId) {
|
|
setStorage("storeID", +params.query.jxStoreId)
|
|
if (getStorage('token')) await store.dispatch('storeInfo/getOneStore', +params.query.jxStoreId)
|
|
}
|
|
})
|
|
|
|
/*************************************************
|
|
* 页面出现 热启动
|
|
*/
|
|
let reconnectTime1: any = null
|
|
onShow(async (params: any) => {
|
|
// 订单管理-新订单通知
|
|
if (params.query && params.query.jxStoreId) {
|
|
setStorage("storeID", +params.query.jxStoreId)
|
|
if (getStorage('token')) await store.dispatch('storeInfo/getOneStore', +params.query.jxStoreId)
|
|
}
|
|
if (getStorage('deviceName')) {
|
|
reconnectTime1 = setTimeout(async () => {
|
|
await bluetooth.reconnect()
|
|
clearTimeout(reconnectTime1)
|
|
}, 1500)
|
|
}
|
|
})
|
|
|
|
|
|
/**
|
|
* 获取设备信息
|
|
*/
|
|
async function SystemInfo() {
|
|
uni.getSystemInfo({
|
|
success(res) {
|
|
// 保存本机系统信息
|
|
// 详细字段信息参考 https://uniapp.dcloud.net.cn/api/system/info.html#%E7%B3%BB%E7%BB%9F%E4%BF%A1%E6%81%AF%E7%9A%84%E6%A6%82%E5%BF%B5
|
|
store.commit('serveInfo/setSystemInfo', JSON.stringify(res))
|
|
},
|
|
})
|
|
}
|
|
|
|
|
|
/*************************************************
|
|
* 监听网络类型
|
|
*/
|
|
function onNetWorkStatusChange() {
|
|
uni.onNetworkStatusChange((res) => {
|
|
store.commit('serveInfo/setIsNetWorkS', res.isConnected)
|
|
})
|
|
}
|
|
|
|
|
|
/**
|
|
* 微信小程序更新机制
|
|
*/
|
|
function autoUpdate() {
|
|
// 获取小程序更新机制兼容
|
|
if (uni.canIUse('getUpdateManager')) {
|
|
const updateManager = uni.getUpdateManager()
|
|
// 检查是否有新版本发布
|
|
updateManager.onCheckForUpdate(function (res) {
|
|
if (res.hasUpdate) {
|
|
//小程序有新版本,则静默下载新版本,做好更新准备
|
|
updateManager.onUpdateReady(function () {
|
|
uni.jxAlert({
|
|
title: '更新提示',
|
|
content: '应用已经升级到新版本了请及时更新',
|
|
success: () => {
|
|
updateManager.applyUpdate()
|
|
}
|
|
})
|
|
})
|
|
// 新的版本下载失败
|
|
updateManager.onUpdateFailed(function () {
|
|
uni.showModal({
|
|
title: '温馨提示',
|
|
content: '新版本已经上线,请您删除当前小程序,重新搜索打开',
|
|
})
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
// 提示用户在最新版本的客户端上体验
|
|
uni.showModal({
|
|
title: '温馨提示',
|
|
content: '当前微信版本过低,可能无法使用该功能,请升级到最新版本后重试。'
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
/*************************************************
|
|
* 判断用户是否为IOS系统
|
|
* @param {}
|
|
* @return {boolean} // 是否为IOS系统
|
|
*/
|
|
function isIosSystem() {
|
|
setStorage('isIosSystem', true)
|
|
}
|
|
|
|
|
|
/*************************************************
|
|
* 打印机检测
|
|
*/
|
|
let reconnectTime: any = null
|
|
function onPrinterChange() {
|
|
if (getStorage('deviceName')) {
|
|
setPrinterStatus()
|
|
reconnectTime = setTimeout(async () => {
|
|
await bluetooth.reconnect()
|
|
clearTimeout(reconnectTime)
|
|
}, 1500)
|
|
}
|
|
}
|
|
|
|
|
|
return {
|
|
SystemInfo, // 获取本机系统信息
|
|
onNetWorkStatusChange, // 监听网络状态
|
|
autoUpdate, // 小程序更新
|
|
isIosSystem, // 是否为IOS
|
|
onPrinterChange, // 监听打印机状态
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export default App |