0602
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
loading: {
|
||||
show: false,
|
||||
text: '加载中...'
|
||||
},
|
||||
settings: {
|
||||
autoSync: true,
|
||||
syncInterval: 5, // 分钟
|
||||
scanContinuous: true,
|
||||
scanBeep: true,
|
||||
scanVibrate: true
|
||||
},
|
||||
systemInfo: null,
|
||||
appVersion: '1.0.0'
|
||||
},
|
||||
mutations: {
|
||||
SET_LOADING(state, { show, text }) {
|
||||
state.loading.show = show
|
||||
if (text) {
|
||||
state.loading.text = text
|
||||
}
|
||||
},
|
||||
SET_SETTINGS(state, settings) {
|
||||
state.settings = { ...state.settings, ...settings }
|
||||
},
|
||||
SET_SYSTEM_INFO(state, info) {
|
||||
state.systemInfo = info
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async initAppData({ commit, dispatch }) {
|
||||
try {
|
||||
// 初始化系统信息
|
||||
await dispatch('loadSystemInfo')
|
||||
|
||||
// 初始化设置
|
||||
await dispatch('initSettings')
|
||||
|
||||
} catch (error) {
|
||||
console.error('初始化应用数据失败:', error)
|
||||
throw error
|
||||
}
|
||||
},
|
||||
|
||||
async loadSystemInfo({ commit }) {
|
||||
try {
|
||||
const systemInfo = uni.getSystemInfoSync()
|
||||
commit('SET_SYSTEM_INFO', systemInfo)
|
||||
return systemInfo
|
||||
} catch (error) {
|
||||
console.error('获取系统信息失败:', error)
|
||||
return null
|
||||
}
|
||||
},
|
||||
|
||||
async initSettings({ commit, state }) {
|
||||
try {
|
||||
// 从本地存储加载设置
|
||||
const savedSettings = uni.getStorageSync('appSettings')
|
||||
|
||||
if (savedSettings) {
|
||||
commit('SET_SETTINGS', savedSettings)
|
||||
} else {
|
||||
// 保存默认设置
|
||||
uni.setStorageSync('appSettings', state.settings)
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('初始化设置失败:', error)
|
||||
}
|
||||
},
|
||||
|
||||
async saveSettings({ commit, state }, settings) {
|
||||
try {
|
||||
commit('SET_SETTINGS', settings)
|
||||
uni.setStorageSync('appSettings', state.settings)
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('保存设置失败:', error)
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
||||
async logError({ }, errorInfo) {
|
||||
try {
|
||||
const errorLog = {
|
||||
...errorInfo,
|
||||
timestamp: new Date().toISOString(),
|
||||
deviceId: this.state.app.systemInfo?.deviceId || 'unknown'
|
||||
}
|
||||
|
||||
const logs = uni.getStorageSync('errorLogs') || []
|
||||
logs.unshift(errorLog)
|
||||
|
||||
// 只保留最近100条错误日志
|
||||
if (logs.length > 100) {
|
||||
logs.splice(100)
|
||||
}
|
||||
|
||||
uni.setStorageSync('errorLogs', logs)
|
||||
|
||||
} catch (error) {
|
||||
console.error('记录错误日志失败:', error)
|
||||
}
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
isLoading: state => state.loading.show,
|
||||
loadingText: state => state.loading.text,
|
||||
appSettings: state => state.settings
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user