init.js
2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* @Descripttion:
* @version: 1.0.0
* @Author: limin
* @Date: 2025-01-03 18:53:43
* @LastEditors: limin
* @LastEditTime: 2025-12-25 14:49:12
* @FilePath: \simgle_app\init.js
*/
import utils from './utils/utils'
import { Storage } from './utils/cache/index'
// import Track from './utils/Track'
console.warn('[boot] init.js start')
uni.$storage = new Storage()
uni.$throttle = utils.throttle
uni.$isNetWork = utils.isNetWork
uni.$api = {}
uni.$logger = {
info: (...args) => console.log('[boot][logger][info]', ...args),
warn: (...args) => console.warn('[boot][logger][warn]', ...args),
error: (...args) => console.error('[boot][logger][error]', ...args),
debug: (...args) => console.log('[boot][logger][debug]', ...args),
local: {
info: (...args) => console.log('[boot][local][info]', ...args),
warn: (...args) => console.warn('[boot][local][warn]', ...args),
error: (...args) => console.error('[boot][local][error]', ...args),
debug: (...args) => console.log('[boot][local][debug]', ...args)
}
}
console.warn('[boot] init.js async load start -> api/logger')
Promise.all([import('./api/index'), import('./utils/logger')])
.then(([apiMod, loggerMod]) => {
uni.$api = (apiMod && apiMod.default) || apiMod
uni.$logger = (loggerMod && loggerMod.default) || loggerMod
console.warn('[boot] init.js async load done -> api/logger')
})
.catch((e) => {
console.warn('[boot] init.js async load failed -> api/logger', e)
})
// uni.$dbTempRecord = new DBTempRecord() // 已废弃,合并至 dbRecord
// uni.$track = new Track()
// DBRecord 异步加载,避免 init 阶段同步 import 触发 SQLite/recordManager 链阻塞冷启动
if (!uni.$dbReady) {
uni.$dbReady = (async () => {
try {
const { default: DBRecord } = await import('./utils/recordManager/dbRecord.js')
if (!uni.$dbRecord) {
uni.$dbRecord = new DBRecord()
}
await uni.$dbRecord.init()
uni.$logger.local.info('数据库初始化完成')
return true
} catch (e) {
uni.$logger.local.error('数据库初始化失败: ' + (e.message || e))
return false
}
})()
}
console.warn('[boot] init.js done')