vue2-client 1.1.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +81 -81
- package/README.md +65 -63
- package/babel.config.js +15 -14
- package/docs/index.md +29 -29
- package/docs/notice.md +22 -0
- package/index.js +28 -0
- package/jest.config.js +3 -3
- package/package.json +1 -1
- package/public/index.html +27 -27
- package/src/App.vue +2 -2
- package/src/assets/img/SunClientDownload.png +0 -0
- package/src/assets/img/SunClientManual/1.png +0 -0
- package/src/assets/img/SunClientManual/2.png +0 -0
- package/src/assets/img/SunClientManual/3.png +0 -0
- package/src/assets/img/SunClientManual/4.png +0 -0
- package/src/assets/img/ToDeskDownload.png +0 -0
- package/src/assets/img/ToDeskManual/1.png +0 -0
- package/src/assets/img/ToDeskManual/2.png +0 -0
- package/src/assets/img/ToDeskManual/3.png +0 -0
- package/src/assets/img/ToDeskManual/4.png +0 -0
- package/src/assets/sound/newNote.mp3 +0 -0
- package/src/base-client/all.js +57 -57
- package/src/base-client/components/common/CreateQuery/CreateQuery.vue +1157 -1159
- package/src/base-client/components/common/CreateQuery/index.md +1 -1
- package/src/base-client/components/common/CreateSimpleFormQuery/CreateSimpleFormQuery.vue +540 -540
- package/src/base-client/components/common/CreateSimpleFormQuery/index.md +1 -1
- package/src/base-client/components/common/CustomColumnsDrawer/index.md +1 -1
- package/src/base-client/components/common/FormGroupEdit/FormGroupEdit.vue +150 -150
- package/src/base-client/components/common/FormGroupEdit/index.md +1 -1
- package/src/base-client/components/common/FormGroupQuery/index.md +1 -1
- package/src/base-client/components/common/XAddForm/XAddForm.vue +323 -323
- package/src/base-client/components/common/XAddForm/index.md +1 -1
- package/src/base-client/components/common/XBadge/index.md +1 -1
- package/src/base-client/components/common/XCard/index.md +1 -1
- package/src/base-client/components/common/XForm/XForm.vue +275 -275
- package/src/base-client/components/common/XForm/XFormItem.vue +217 -217
- package/src/base-client/components/common/XForm/index.md +196 -196
- package/src/base-client/components/common/XFormCol/index.md +1 -1
- package/src/base-client/components/common/XFormTable/XFormTable.vue +407 -405
- package/src/base-client/components/common/XFormTable/index.md +3 -3
- package/src/base-client/components/common/XTable/XTable.vue +262 -262
- package/src/base-client/components/common/XTable/index.md +255 -255
- package/src/base-client/components/common/XTreeOne/XTreeOne.vue +1 -1
- package/src/base-client/components/iot/CustomerDetailsView/CustomerDetailsView.vue +226 -226
- package/src/base-client/components/iot/CustomerDetailsView/index.md +2 -2
- package/src/base-client/components/iot/DataAnalysisUser/DataAnalysisUser.vue +1 -1
- package/src/base-client/components/iot/DataAnalysisViewGD/DataAnalysisViewGD.vue +548 -548
- package/src/base-client/components/iot/DeviceBrandDetailsView/DeviceBrandDetailsView.vue +453 -453
- package/src/base-client/components/iot/DeviceDetailsView/DeviceDetailsView.vue +231 -231
- package/src/base-client/components/iot/DeviceDetailsView/index.md +1 -1
- package/src/base-client/components/iot/DeviceDetailsView/part/DeviceDetailsCount.vue +330 -330
- package/src/base-client/components/iot/DeviceDetailsView/part/DeviceDetailsException.vue +1 -1
- package/src/base-client/components/iot/DeviceDetailsView/part/DeviceDetailsInstruct.vue +3 -3
- package/src/base-client/components/iot/DeviceDetailsView/part/DeviceDetailsInstructOperate.vue +122 -122
- package/src/base-client/components/iot/DeviceDetailsView/part/DeviceDetailsMain.vue +1 -1
- package/src/base-client/components/iot/DeviceDetailsView/part/DeviceDetailsRead.vue +3 -3
- package/src/base-client/components/iot/DeviceTypeDetailsView/DeviceTypeDetailsView.vue +277 -277
- package/src/base-client/components/iot/InstructDetailsView/InstructDetailsView.vue +472 -472
- package/src/base-client/components/iot/InstructDetailsView/index.md +1 -1
- package/src/base-client/components/iot/LogDetailsView/LogDetailsView.vue +380 -380
- package/src/base-client/components/iot/LogDetailsView/index.md +1 -1
- package/src/base-client/components/iot/MeterDetailsView/MeterDetailsView.vue +360 -360
- package/src/base-client/components/iot/MeterDetailsView/index.md +1 -1
- package/src/base-client/components/iot/MeterDetailsView/part/MeterDetailsCount.vue +335 -335
- package/src/base-client/components/iot/MeterDetailsView/part/MeterDetailsException.vue +185 -185
- package/src/base-client/components/iot/MeterDetailsView/part/MeterDetailsHandPlan.vue +292 -292
- package/src/base-client/components/iot/MeterDetailsView/part/MeterDetailsInstruct.vue +237 -237
- package/src/base-client/components/iot/MeterDetailsView/part/MeterDetailsMain.vue +257 -257
- package/src/base-client/components/iot/MeterDetailsView/part/MeterDetailsSellGas.vue +190 -190
- package/src/base-client/components/iot/WebmeterAnalysisView/WebmeterAnalysisView.vue +723 -723
- package/src/base-client/components/iot/WebmeterAnalysisView/index.md +1 -1
- package/src/base-client/components/system/DictionaryDetailsView/DictionaryDetailsView.vue +232 -232
- package/src/base-client/components/system/DictionaryDetailsView/index.md +1 -1
- package/src/base-client/components/system/QueryParamsDetailsView/QueryParamsDetailsView.vue +248 -248
- package/src/base-client/components/ticket/EmployeeDetailsView/EmployeeDetailsView.vue +371 -406
- package/src/base-client/components/ticket/TicketDetailsView/TicketDetailsView.vue +838 -486
- package/src/base-client/components/ticket/TicketDetailsView/part/TicketDetailsFlow.vue +261 -184
- package/src/base-client/components/ticket/TicketSubmitSuccessView/TicketSubmitSuccessView.vue +528 -303
- package/src/base-client/plugins/AppData.js +69 -69
- package/src/base-client/plugins/GetLoginInfoService.js +221 -221
- package/src/base-client/plugins/index.js +21 -21
- package/src/bootstrap.js +27 -27
- package/src/components/Ellipsis/Ellipsis.vue +1 -1
- package/src/components/Ellipsis/index.md +2 -2
- package/src/components/NumberInfo/index.md +1 -1
- package/src/components/STable/README.md +3 -3
- package/src/components/Trend/index.md +1 -1
- package/src/components/cache/AKeepAlive.js +1 -1
- package/src/components/checkbox/index.js +2 -2
- package/src/components/index.js +15 -15
- package/src/components/menu/menu.js +1 -1
- package/src/components/setting/Setting.vue +4 -4
- package/src/components/table/advance/AdvanceTable.vue +3 -3
- package/src/components/transition/PageToggleTransition.vue +1 -1
- package/src/config/default/setting.config.js +33 -33
- package/src/layouts/CommonLayout.vue +1 -1
- package/src/layouts/ComponentLayoutOne.vue +47 -47
- package/src/layouts/PageLayout.vue +2 -2
- package/src/layouts/SinglePageView.vue +1 -1
- package/src/layouts/header/AdminHeader.vue +2 -2
- package/src/layouts/header/HeaderAvatar.vue +1 -1
- package/src/layouts/header/HeaderNotice.vue +97 -97
- package/src/layouts/tabs/TabsHead.vue +1 -1
- package/src/layouts/tabs/TabsView.vue +6 -6
- package/src/main.js +20 -20
- package/src/mock/common/reportData.js +20 -20
- package/src/mock/goods/index.js +2 -2
- package/src/mock/index.js +6 -6
- package/src/mock/project/index.js +1 -1
- package/src/mock/user/current.js +1 -1
- package/src/mock/user/login.js +1 -1
- package/src/mock/user/routes.js +61 -61
- package/src/mock/workplace/index.js +1 -1
- package/src/pages/exception/403.vue +25 -25
- package/src/pages/exception/404.vue +25 -25
- package/src/pages/exception/500.vue +25 -25
- package/src/pages/login/Login.vue +194 -194
- package/src/pages/report/ReportTable.js +125 -125
- package/src/pages/report/ReportTableHome.vue +28 -28
- package/src/pages/resourceManage/resourceManageMain.vue +55 -55
- package/src/pages/system/applyInstallView/Core.vue +1 -1
- package/src/pages/system/applyInstallView/index.vue +1 -1
- package/src/pages/system/dictionary/index.vue +1 -1
- package/src/pages/system/queryParams/index.vue +1 -1
- package/src/router/async/config.async.js +1 -1
- package/src/router/async/router.map.js +59 -59
- package/src/router/guards.js +3 -3
- package/src/router/index.js +27 -27
- package/src/services/api/EmployeeDetailsViewApi.js +3 -1
- package/src/services/api/TicketDetailsViewApi.js +9 -1
- package/src/services/api/common.js +37 -39
- package/src/services/api/restTools.js +23 -23
- package/src/services/dataSource.js +1 -1
- package/src/services/user.js +2 -2
- package/src/store/index.js +5 -5
- package/src/store/modules/setting.js +5 -5
- package/src/theme/index.less +5 -5
- package/src/theme/reportTable.less +58 -58
- package/src/utils/i18n.js +2 -2
- package/src/utils/indexedDB.js +146 -146
- package/src/utils/request.js +197 -197
- package/src/utils/routerUtil.js +18 -5
- package/tests/unit/ReportTable.spec.js +15 -15
- package/vue.config.js +153 -152
- package/webpack.config.js +12 -12
- package/src/index.js +0 -28
- package/src/router/config.js +0 -23
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
#ReportTableHome {
|
|
2
|
-
// 一个div宽高
|
|
3
|
-
@height: 30px;
|
|
4
|
-
@width: 100px;
|
|
5
|
-
// 边框颜色
|
|
6
|
-
@boder-color: #000;
|
|
7
|
-
|
|
8
|
-
position: relative;
|
|
9
|
-
display: flex;
|
|
10
|
-
justify-items: center;
|
|
11
|
-
#reportTable {
|
|
12
|
-
border-left: 1px solid @boder-color;
|
|
13
|
-
border-top: 1px solid @boder-color;
|
|
14
|
-
div {
|
|
15
|
-
display: flex;
|
|
16
|
-
align-items: center;
|
|
17
|
-
justify-content: center;
|
|
18
|
-
position: absolute;
|
|
19
|
-
border-bottom: 1px solid @boder-color;
|
|
20
|
-
border-right: 1px solid @boder-color;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
// 循环编写
|
|
24
|
-
.generBase(@i) when (@i <= 20) {
|
|
25
|
-
.hs(@i);
|
|
26
|
-
.ws(@i);
|
|
27
|
-
.ts(@i);
|
|
28
|
-
.ls(@i);
|
|
29
|
-
.generBase(@i+1);
|
|
30
|
-
}
|
|
31
|
-
.hs(@size) {
|
|
32
|
-
.h-@{size} {
|
|
33
|
-
height: @height * @size
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
.ws(@size) {
|
|
37
|
-
.w-@{size} {
|
|
38
|
-
width: @width * @size
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
.ts(@size) {
|
|
42
|
-
.t-@{size} {
|
|
43
|
-
top: @height * @size
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
.ls(@size) {
|
|
47
|
-
.l-@{size} {
|
|
48
|
-
left: @width * @size
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
.generBase(0);
|
|
52
|
-
.title {
|
|
53
|
-
background: #80add9;
|
|
54
|
-
}
|
|
55
|
-
.bold {
|
|
56
|
-
font-weight: bold;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
1
|
+
#ReportTableHome {
|
|
2
|
+
// 一个div宽高
|
|
3
|
+
@height: 30px;
|
|
4
|
+
@width: 100px;
|
|
5
|
+
// 边框颜色
|
|
6
|
+
@boder-color: #000;
|
|
7
|
+
|
|
8
|
+
position: relative;
|
|
9
|
+
display: flex;
|
|
10
|
+
justify-items: center;
|
|
11
|
+
#reportTable {
|
|
12
|
+
border-left: 1px solid @boder-color;
|
|
13
|
+
border-top: 1px solid @boder-color;
|
|
14
|
+
div {
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
position: absolute;
|
|
19
|
+
border-bottom: 1px solid @boder-color;
|
|
20
|
+
border-right: 1px solid @boder-color;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// 循环编写
|
|
24
|
+
.generBase(@i) when (@i <= 20) {
|
|
25
|
+
.hs(@i);
|
|
26
|
+
.ws(@i);
|
|
27
|
+
.ts(@i);
|
|
28
|
+
.ls(@i);
|
|
29
|
+
.generBase(@i+1);
|
|
30
|
+
}
|
|
31
|
+
.hs(@size) {
|
|
32
|
+
.h-@{size} {
|
|
33
|
+
height: @height * @size
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
.ws(@size) {
|
|
37
|
+
.w-@{size} {
|
|
38
|
+
width: @width * @size
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
.ts(@size) {
|
|
42
|
+
.t-@{size} {
|
|
43
|
+
top: @height * @size
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
.ls(@size) {
|
|
47
|
+
.l-@{size} {
|
|
48
|
+
left: @width * @size
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
.generBase(0);
|
|
52
|
+
.title {
|
|
53
|
+
background: #80add9;
|
|
54
|
+
}
|
|
55
|
+
.bold {
|
|
56
|
+
font-weight: bold;
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/utils/i18n.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Vue from 'vue'
|
|
2
2
|
import VueI18n from 'vue-i18n'
|
|
3
|
-
import routesI18n from '
|
|
3
|
+
import routesI18n from '@vue2-client/router/i18n'
|
|
4
4
|
import './Objects'
|
|
5
|
-
import { getI18nKey } from '
|
|
5
|
+
import { getI18nKey } from '@vue2-client/utils/routerUtil'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* 创建 i18n 配置
|
package/src/utils/indexedDB.js
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
// indexDB 存储
|
|
2
|
-
import { post } from '
|
|
3
|
-
|
|
4
|
-
export const indexedDB = {
|
|
5
|
-
db: undefined,
|
|
6
|
-
indexedDB: window.indexedDB || window.webkitindexedDB,
|
|
7
|
-
IDBKeyRange: window.IDBKeyRange || window.webkitIDBKeyRange, // 键范围
|
|
8
|
-
openDB: function (callback) {
|
|
9
|
-
// 建立或打开数据库,建立对象存储空间(ObjectStore)
|
|
10
|
-
const self = this
|
|
11
|
-
if (self.db) {
|
|
12
|
-
callback(self.db)
|
|
13
|
-
} else {
|
|
14
|
-
const version = 1
|
|
15
|
-
const request = self.indexedDB.open('view', version)
|
|
16
|
-
|
|
17
|
-
request.onerror = function (e) {
|
|
18
|
-
console.error('打开数据库失败:' + e.currentTarget.error.message)
|
|
19
|
-
}
|
|
20
|
-
request.onsuccess = function (e) {
|
|
21
|
-
self.db = e.target.result
|
|
22
|
-
callback(self.db)
|
|
23
|
-
}
|
|
24
|
-
request.onupgradeneeded = function (e) {
|
|
25
|
-
const db = e.target.result
|
|
26
|
-
if (!db.objectStoreNames.contains('metaCache')) {
|
|
27
|
-
// 没有该对象空间时创建该对象空间
|
|
28
|
-
db.createObjectStore('metaCache', {
|
|
29
|
-
keyPath: 'key'
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
deleteDB: function (dbname) {
|
|
36
|
-
// 删除数据库
|
|
37
|
-
const self = this
|
|
38
|
-
self.indexedDB.deleteDatabase(dbname)
|
|
39
|
-
console.log(dbname + '数据库已删除')
|
|
40
|
-
},
|
|
41
|
-
closeDB: function () {
|
|
42
|
-
const self = this
|
|
43
|
-
if (!self.db) {
|
|
44
|
-
self.db.close()
|
|
45
|
-
}
|
|
46
|
-
console.log('数据库已关闭')
|
|
47
|
-
},
|
|
48
|
-
add: function (key, data) {
|
|
49
|
-
const self = this
|
|
50
|
-
self.openDB((res) => {
|
|
51
|
-
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').add({
|
|
52
|
-
key: key,
|
|
53
|
-
data: data
|
|
54
|
-
})
|
|
55
|
-
request.onerror = function () {
|
|
56
|
-
self.update(data)
|
|
57
|
-
}
|
|
58
|
-
request.onsuccess = function () {
|
|
59
|
-
console.log('数据已存入到数据库')
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
},
|
|
63
|
-
update: function (key, data) {
|
|
64
|
-
const self = this
|
|
65
|
-
self.openDB((res) => {
|
|
66
|
-
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').put({
|
|
67
|
-
key: key,
|
|
68
|
-
data: data
|
|
69
|
-
})
|
|
70
|
-
request.onerror = function () {
|
|
71
|
-
console.error('数据更新失败')
|
|
72
|
-
}
|
|
73
|
-
request.onsuccess = function () {
|
|
74
|
-
console.log('数据已更新到数据库')
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
},
|
|
78
|
-
get: function (key, callback) {
|
|
79
|
-
const self = this
|
|
80
|
-
self.openDB((res) => {
|
|
81
|
-
// 根据存储空间的键找到对应数据
|
|
82
|
-
const store = res.transaction('metaCache', 'readwrite').objectStore('metaCache')
|
|
83
|
-
const request = store.get(key)
|
|
84
|
-
request.onerror = function () {
|
|
85
|
-
console.log('读取数据失败,键:' + key)
|
|
86
|
-
}
|
|
87
|
-
request.onsuccess = function (e) {
|
|
88
|
-
const result = e.target.result
|
|
89
|
-
if (typeof (callback) === 'function') {
|
|
90
|
-
callback(result.data)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
},
|
|
95
|
-
getByWeb: function (key, url, params, callback) {
|
|
96
|
-
const self = this
|
|
97
|
-
self.openDB((res) => {
|
|
98
|
-
// 根据存储空间的键找到对应数据
|
|
99
|
-
const store = res.transaction('metaCache', 'readwrite').objectStore('metaCache')
|
|
100
|
-
const request = store.get(key)
|
|
101
|
-
request.onerror = function () {
|
|
102
|
-
console.log('读取数据失败,键:' + key)
|
|
103
|
-
}
|
|
104
|
-
request.onsuccess = function (e) {
|
|
105
|
-
const result = e.target.result
|
|
106
|
-
if (!result && url) {
|
|
107
|
-
post(url, params).then((res) => {
|
|
108
|
-
self.add(key, res)
|
|
109
|
-
callback(res)
|
|
110
|
-
})
|
|
111
|
-
} else {
|
|
112
|
-
callback(result.data)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
},
|
|
117
|
-
delete: function (key) {
|
|
118
|
-
const self = this
|
|
119
|
-
self.openDB((res) => {
|
|
120
|
-
// 删除某一条记录
|
|
121
|
-
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').delete(key)
|
|
122
|
-
|
|
123
|
-
request.onerror = function () {
|
|
124
|
-
console.error('数据删除失败')
|
|
125
|
-
}
|
|
126
|
-
request.onsuccess = function (event) {
|
|
127
|
-
console.log('已删除存储空间' + 'metaCache' + '中' + key + '记录')
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
},
|
|
131
|
-
clear: function (callback) {
|
|
132
|
-
const self = this
|
|
133
|
-
self.openDB((res) => {
|
|
134
|
-
// 删除存储空间全部记录
|
|
135
|
-
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').clear()
|
|
136
|
-
|
|
137
|
-
request.onerror = function () {
|
|
138
|
-
console.error('数据删除失败')
|
|
139
|
-
}
|
|
140
|
-
request.onsuccess = function (event) {
|
|
141
|
-
console.log('已删除存储空间' + 'metaCache' + '中所有记录')
|
|
142
|
-
callback()
|
|
143
|
-
}
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
}
|
|
1
|
+
// indexDB 存储
|
|
2
|
+
import { post } from '@vue2-client/services/api/restTools'
|
|
3
|
+
|
|
4
|
+
export const indexedDB = {
|
|
5
|
+
db: undefined,
|
|
6
|
+
indexedDB: window.indexedDB || window.webkitindexedDB,
|
|
7
|
+
IDBKeyRange: window.IDBKeyRange || window.webkitIDBKeyRange, // 键范围
|
|
8
|
+
openDB: function (callback) {
|
|
9
|
+
// 建立或打开数据库,建立对象存储空间(ObjectStore)
|
|
10
|
+
const self = this
|
|
11
|
+
if (self.db) {
|
|
12
|
+
callback(self.db)
|
|
13
|
+
} else {
|
|
14
|
+
const version = 1
|
|
15
|
+
const request = self.indexedDB.open('view', version)
|
|
16
|
+
|
|
17
|
+
request.onerror = function (e) {
|
|
18
|
+
console.error('打开数据库失败:' + e.currentTarget.error.message)
|
|
19
|
+
}
|
|
20
|
+
request.onsuccess = function (e) {
|
|
21
|
+
self.db = e.target.result
|
|
22
|
+
callback(self.db)
|
|
23
|
+
}
|
|
24
|
+
request.onupgradeneeded = function (e) {
|
|
25
|
+
const db = e.target.result
|
|
26
|
+
if (!db.objectStoreNames.contains('metaCache')) {
|
|
27
|
+
// 没有该对象空间时创建该对象空间
|
|
28
|
+
db.createObjectStore('metaCache', {
|
|
29
|
+
keyPath: 'key'
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
deleteDB: function (dbname) {
|
|
36
|
+
// 删除数据库
|
|
37
|
+
const self = this
|
|
38
|
+
self.indexedDB.deleteDatabase(dbname)
|
|
39
|
+
console.log(dbname + '数据库已删除')
|
|
40
|
+
},
|
|
41
|
+
closeDB: function () {
|
|
42
|
+
const self = this
|
|
43
|
+
if (!self.db) {
|
|
44
|
+
self.db.close()
|
|
45
|
+
}
|
|
46
|
+
console.log('数据库已关闭')
|
|
47
|
+
},
|
|
48
|
+
add: function (key, data) {
|
|
49
|
+
const self = this
|
|
50
|
+
self.openDB((res) => {
|
|
51
|
+
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').add({
|
|
52
|
+
key: key,
|
|
53
|
+
data: data
|
|
54
|
+
})
|
|
55
|
+
request.onerror = function () {
|
|
56
|
+
self.update(data)
|
|
57
|
+
}
|
|
58
|
+
request.onsuccess = function () {
|
|
59
|
+
console.log('数据已存入到数据库')
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
},
|
|
63
|
+
update: function (key, data) {
|
|
64
|
+
const self = this
|
|
65
|
+
self.openDB((res) => {
|
|
66
|
+
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').put({
|
|
67
|
+
key: key,
|
|
68
|
+
data: data
|
|
69
|
+
})
|
|
70
|
+
request.onerror = function () {
|
|
71
|
+
console.error('数据更新失败')
|
|
72
|
+
}
|
|
73
|
+
request.onsuccess = function () {
|
|
74
|
+
console.log('数据已更新到数据库')
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
},
|
|
78
|
+
get: function (key, callback) {
|
|
79
|
+
const self = this
|
|
80
|
+
self.openDB((res) => {
|
|
81
|
+
// 根据存储空间的键找到对应数据
|
|
82
|
+
const store = res.transaction('metaCache', 'readwrite').objectStore('metaCache')
|
|
83
|
+
const request = store.get(key)
|
|
84
|
+
request.onerror = function () {
|
|
85
|
+
console.log('读取数据失败,键:' + key)
|
|
86
|
+
}
|
|
87
|
+
request.onsuccess = function (e) {
|
|
88
|
+
const result = e.target.result
|
|
89
|
+
if (typeof (callback) === 'function') {
|
|
90
|
+
callback(result.data)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
},
|
|
95
|
+
getByWeb: function (key, url, params, callback) {
|
|
96
|
+
const self = this
|
|
97
|
+
self.openDB((res) => {
|
|
98
|
+
// 根据存储空间的键找到对应数据
|
|
99
|
+
const store = res.transaction('metaCache', 'readwrite').objectStore('metaCache')
|
|
100
|
+
const request = store.get(key)
|
|
101
|
+
request.onerror = function () {
|
|
102
|
+
console.log('读取数据失败,键:' + key)
|
|
103
|
+
}
|
|
104
|
+
request.onsuccess = function (e) {
|
|
105
|
+
const result = e.target.result
|
|
106
|
+
if (!result && url) {
|
|
107
|
+
post(url, params).then((res) => {
|
|
108
|
+
self.add(key, res)
|
|
109
|
+
callback(res)
|
|
110
|
+
})
|
|
111
|
+
} else {
|
|
112
|
+
callback(result.data)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
},
|
|
117
|
+
delete: function (key) {
|
|
118
|
+
const self = this
|
|
119
|
+
self.openDB((res) => {
|
|
120
|
+
// 删除某一条记录
|
|
121
|
+
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').delete(key)
|
|
122
|
+
|
|
123
|
+
request.onerror = function () {
|
|
124
|
+
console.error('数据删除失败')
|
|
125
|
+
}
|
|
126
|
+
request.onsuccess = function (event) {
|
|
127
|
+
console.log('已删除存储空间' + 'metaCache' + '中' + key + '记录')
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
},
|
|
131
|
+
clear: function (callback) {
|
|
132
|
+
const self = this
|
|
133
|
+
self.openDB((res) => {
|
|
134
|
+
// 删除存储空间全部记录
|
|
135
|
+
const request = res.transaction('metaCache', 'readwrite').objectStore('metaCache').clear()
|
|
136
|
+
|
|
137
|
+
request.onerror = function () {
|
|
138
|
+
console.error('数据删除失败')
|
|
139
|
+
}
|
|
140
|
+
request.onsuccess = function (event) {
|
|
141
|
+
console.log('已删除存储空间' + 'metaCache' + '中所有记录')
|
|
142
|
+
callback()
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
}
|