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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
| import { defineStore } from 'pinia'
| import storage from '@/utils/storage'
|
| // 缓存的主题
| const THEME_KEY = 'app-theme'
|
| const useAppStore = defineStore('app', {
| state: () => ({
| systemInfo: {}, // 原本 TS: {} as UniApp.GetSystemInfoResult
| theme: storage.get(THEME_KEY) || 'light',
| deviceUpdateKey: 0, //设备刷新key
| jobUpdateKey: 0, //任务刷新key
| // 字典
| taskType: [], // 任务类型
| flightMode: [], // 飞行模式
| flightRules: [], // 飞行规则
| flightPlan: [], // 飞行计划
| flyActivityStatus: [], // 飞行活动状态
| proType: [], // 飞行器类型
| }),
| getters: {
| getSystemInfo (state) {
| return state.systemInfo
| },
| getTheme (state) {
| return state.theme
| },
| // 字典
| getTaskType (state) {
| return state.taskType
| },
| getFlightMode (state) {
| return state.flightMode
| },
| getFlightRules (state) {
| return state.flightRules
| },
| getFlightPlan (state) {
| return state.flightPlan
| },
| getFlyActivityStatus (state) {
| return state.flyActivityStatus
| },
| getProType (state) {
| return state.proType
| },
| },
| actions: {
| // 设置字典
| setTaskType (data) {
| this.taskType = data
| },
| setFlightMode (data) {
| this.flightMode = data
| },
| setFlightRules (data) {
| this.flightRules = data
| },
| setFlightPlan (data) {
| this.flightPlan = data
| },
| setFlyActivityStatus (data) {
| this.flyActivityStatus = data
| },
| setProType (data) {
| this.proType = data
| },
|
|
| setSystemInfo (info) {
| this.systemInfo = info
| },
| setDeviceUpdateKeyAdd () {
| this.deviceUpdateKey = this.deviceUpdateKey + 1
| },
| setJobUpdateKeyAdd (state, data) {
| this.deviceUpdateKey = this.deviceUpdateKey + 1
| },
| initSystemInfo () {
| uni.getSystemInfo({
| success: (res) => {
| this.setSystemInfo(res)
| },
| fail: (err) => {
| console.error(err)
| }
| })
| },
| /**
| * 设置主题
| */
| setTheme (theme) {
| this.theme = theme
| // 保存到本地存储
| storage.set(THEME_KEY, this.theme)
| },
| checkUpdate () {
| const updateManager = uni.getUpdateManager()
| updateManager.onCheckForUpdate((res) => {
| // 请求完新版本信息的回调
| console.log(res.hasUpdate)
| })
| updateManager.onUpdateReady(() => {
| uni.showModal({
| title: '更新提示',
| content: '新版本已经准备好,是否重启应用?',
| success (res) {
| if (res.confirm) {
| // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
| updateManager.applyUpdate()
| }
| }
| })
| })
| updateManager.onUpdateFailed((res) => {
| console.error(res)
| // 新的版本下载失败
| uni.showToast({
| title: '更新失败',
| icon: 'error'
| })
| })
| }
|
| }
| })
|
| export default useAppStore
|
|