@aochuang/client-sdk 1.0.382 → 1.0.401
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/components/chat-editor/chat-editor-suggestions/chat-editor-suggestions.vue +4 -40
- package/components/chat-editor/chat-editor.vue +5 -75
- package/components/index.js +6 -1
- package/components/session-select/session-select-item.vue +8 -9
- package/components/wechat-chat-control/location/location.vue +3 -3
- package/components/wework-chat-control/channel-card/channel-card.vue +144 -0
- package/components/wework-chat-control/channel-live/channel-live.vue +7 -2
- package/components/wework-chat-control/company-card/company-card.vue +1 -1
- package/components/wework-chat-control/custom-expression/custom-expression.vue +2 -1
- package/components/wework-chat-control/file-url/file-url.vue +34 -16
- package/components/wework-chat-control/image/image.vue +137 -2
- package/components/wework-chat-control/index.js +15 -7
- package/components/wework-chat-control/location/location.vue +3 -3
- package/components/wework-chat-control/merge-message/merge-message-panel.vue +63 -0
- package/components/wework-chat-control/merge-message/merge-message.vue +84 -0
- package/components/wework-chat-control/merge-message/util.js +59 -0
- package/components/wework-chat-control/metting/enterprise-wechat.png +0 -0
- package/components/wework-chat-control/metting/meeting-video.svg +4 -0
- package/components/wework-chat-control/metting/metting.vue +181 -0
- package/components/wework-chat-control/red-envelopes/red-envelopes.vue +3 -2
- package/components/wework-chat-control/text/text-default.vue +99 -0
- package/components/wework-chat-control/text/text-quote.vue +138 -0
- package/components/wework-chat-control/text/text.vue +27 -143
- package/components/wework-chat-control/url/url-channel-live.vue +53 -0
- package/components/wework-chat-control/url/url-miniprogram.vue +6 -7
- package/components/wework-chat-control/url/url.vue +26 -2
- package/components/wework-chat-control/util.js +30 -17
- package/components/wework-chat-control/video/video.vue +11 -3
- package/components/wework-chat-control/voice/voice.vue +14 -3
- package/components/wework-chat-control/wework-chat-control-config-item.vue +24 -0
- package/components/wework-chat-control/wework-chat-control-config-msg.vue +25 -0
- package/{uni-components/chat-control/chat-control-config.vue → components/wework-chat-control/wework-chat-control-config.vue} +16 -13
- package/components/wework-chat-panel/chat-panel-chat-status/chat-panel-chat-status.vue +120 -0
- package/components/wework-chat-panel/chat-panel-item.vue +70 -39
- package/components/wework-chat-panel/chat-panel.vue +96 -13
- package/package.json +10 -3
- package/services/client-chat/client-chat-wechat/client-chat-account.js +37 -7
- package/services/client-chat/client-chat-wechat/client-chat-message.js +175 -18
- package/services/client-chat/client-chat-wechat/client-chat-session.js +83 -10
- package/services/client-chat/client-chat-wechat/client-chat-socket.js +80 -22
- package/services/client-chat/client-chat-wechat/client-chat.js +59 -11
- package/services/client-chat/client-chat-wework/client-chat-account.js +93 -1
- package/services/client-chat/client-chat-wework/client-chat-concats.js +104 -18
- package/services/client-chat/client-chat-wework/client-chat-message.js +268 -11
- package/services/client-chat/client-chat-wework/client-chat-session.js +271 -191
- package/services/client-chat/client-chat-wework/client-chat-socket.js +18 -2
- package/services/client-chat/client-chat-wework/client-chat.js +470 -85
- package/services/client-chat/client-chat-wework/docs/README.md +308 -0
- package/services/client-chat/client-chat-wework/utils.js +5 -5
- package/services/socket/socket.js +56 -7
- package/utils/log/constants.js +13 -0
- package/utils/log/export.js +88 -0
- package/utils/log/findings.md +141 -0
- package/utils/log/index.js +331 -0
- package/utils/log/indexed-db.js +228 -0
- package/utils/log/progress.md +267 -0
- package/utils/log/serialize.js +146 -0
- package/utils/log/task_plan.md +149 -0
- package/utils/log//345/210/206/346/236/220/344/270/216/344/274/230/345/214/226/346/226/271/346/241/210.md +303 -0
- package/utils/log//346/212/200/346/234/257/346/226/271/346/241/210/346/226/207/346/241/243.md +201 -0
- package/utils/log//346/236/266/346/236/204/346/226/207/346/241/243.md +169 -0
- package/utils/log//351/234/200/346/261/202/346/226/207/346/241/243.md +124 -0
- package/utils/log.js +2 -626
- package/components/wework-chat-panel/chat-panel-controls/company-card/company-card.vue +0 -35
- package/components/wework-chat-panel/chat-panel-controls/expression/expression.vue +0 -36
- package/components/wework-chat-panel/chat-panel-controls/file-url/file-url.vue +0 -35
- package/components/wework-chat-panel/chat-panel-controls/image/image.vue +0 -36
- package/components/wework-chat-panel/chat-panel-controls/index.js +0 -35
- package/components/wework-chat-panel/chat-panel-controls/jx-sys-text/jx-sys-text.vue +0 -28
- package/components/wework-chat-panel/chat-panel-controls/link/link.vue +0 -35
- package/components/wework-chat-panel/chat-panel-controls/location/location.vue +0 -35
- package/components/wework-chat-panel/chat-panel-controls/text/text.vue +0 -43
- package/components/wework-chat-panel/chat-panel-controls/unkonw/unkonw.vue +0 -39
- package/components/wework-chat-panel/chat-panel-controls/video/video.vue +0 -37
- package/components/wework-chat-panel/chat-panel-controls/voice/voice.vue +0 -35
- package/uni-common/account-portray/account-portray.vue +0 -51
- package/uni-common/account-select/account-select-item.vue +0 -172
- package/uni-common/account-select/account-select.vue +0 -252
- package/uni-common/all-friend-avatar/all-friend-avatar.vue +0 -49
- package/uni-common/friend-avatar/default.svg +0 -1
- package/uni-common/friend-avatar/friend-avatar.vue +0 -27
- package/uni-common/friend-avatar/index.js +0 -3
- package/uni-common/friend-loader/friend-loader.vue +0 -53
- package/uni-common/friend-portray/friend-portray.vue +0 -56
- package/uni-common/group-avatar/default.svg +0 -1
- package/uni-common/group-avatar/group-avatar.vue +0 -18
- package/uni-common/group-avatar/index.js +0 -3
- package/uni-common/room-avatar/default.svg +0 -6
- package/uni-common/room-avatar/index.js +0 -3
- package/uni-common/room-avatar/room-avatar.vue +0 -27
- package/uni-common/room-loader/room-loader.vue +0 -53
- package/uni-common/room-portray/room-portray.vue +0 -56
- package/uni-components/chat-control/calling/calling.vue +0 -91
- package/uni-components/chat-control/calling/phone-fill.svg +0 -1
- package/uni-components/chat-control/calling/vidicon-fill.svg +0 -1
- package/uni-components/chat-control/channel-video/channel-video.vue +0 -89
- package/uni-components/chat-control/channel-video-card/channel-video-card.vue +0 -105
- package/uni-components/chat-control/channel-video-live/channel-video-live.vue +0 -92
- package/uni-components/chat-control/chat-control-config-item/chat-control-config-item.vue +0 -20
- package/uni-components/chat-control/chat-control-config-item/index.js +0 -3
- package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-app.vue +0 -25
- package/uni-components/chat-control/chat-control-config-msg/chat-control-config-msg-h5.vue +0 -21
- package/uni-components/chat-control/chat-control.vue +0 -218
- package/uni-components/chat-control/company-card/company-card.vue +0 -123
- package/uni-components/chat-control/const.js +0 -28
- package/uni-components/chat-control/expression/expression.vue +0 -41
- package/uni-components/chat-control/image/image.vue +0 -68
- package/uni-components/chat-control/index.js +0 -89
- package/uni-components/chat-control/location/location.vue +0 -110
- package/uni-components/chat-control/member-change/member-change.vue +0 -32
- package/uni-components/chat-control/quote-message/quote-message.vue +0 -216
- package/uni-components/chat-control/real-time-position/real-time-position.vue +0 -62
- package/uni-components/chat-control/redpacket/red-envelope.svg +0 -1
- package/uni-components/chat-control/redpacket/redpacket.vue +0 -75
- package/uni-components/chat-control/share-card/share-card.vue +0 -101
- package/uni-components/chat-control/system/system.vue +0 -69
- package/uni-components/chat-control/system-batch-message/system-batch-message.vue +0 -30
- package/uni-components/chat-control/system-text/system-text.vue +0 -32
- package/uni-components/chat-control/text/text.vue +0 -67
- package/uni-components/chat-control/text-with-at/text-with-at.vue +0 -51
- package/uni-components/chat-control/transfer/red-transfer.svg +0 -1
- package/uni-components/chat-control/transfer/transfer.vue +0 -80
- package/uni-components/chat-control/unkonw/unkonw.vue +0 -37
- package/uni-components/chat-control/url/icons/file-excel-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-info-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-music-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-pdf-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-ppt-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-settings-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-text-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-unknow-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-word-line.svg +0 -1
- package/uni-components/chat-control/url/icons/file-zip-line.svg +0 -1
- package/uni-components/chat-control/url/icons/index.js +0 -24
- package/uni-components/chat-control/url/miniprogram.svg +0 -1
- package/uni-components/chat-control/url/url-miniprogram.vue +0 -116
- package/uni-components/chat-control/url/url.vue +0 -306
- package/uni-components/chat-control/url-new/icons/file-excel-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-info-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-music-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-pdf-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-ppt-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-settings-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-text-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-unknow-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-word-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/file-zip-line.svg +0 -1
- package/uni-components/chat-control/url-new/icons/index.js +0 -24
- package/uni-components/chat-control/url-new/url-new.vue +0 -110
- package/uni-components/chat-control/utils.js +0 -12
- package/uni-components/chat-control/video/video.vue +0 -156
- package/uni-components/chat-control/voice/voice.vue +0 -166
- package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-collect.vue +0 -84
- package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet-system.vue +0 -28
- package/uni-components/chat-editor/chat-editor-chartlet/chat-editor-chartlet.vue +0 -85
- package/uni-components/chat-editor/chat-editor-func/chat-editor-func.vue +0 -157
- package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at-panel.vue +0 -158
- package/uni-components/chat-editor/chat-editor-func-at/chat-editor-func-at.vue +0 -61
- package/uni-components/chat-editor/chat-editor-func-button/chat-editor-func-button.vue +0 -58
- package/uni-components/chat-editor/chat-editor-func-file/chat-editor-func-file.vue +0 -54
- package/uni-components/chat-editor/chat-editor-func-image/chat-editor-func-image.vue +0 -42
- package/uni-components/chat-editor/chat-editor-func-video/chat-editor-func-video.vue +0 -42
- package/uni-components/chat-editor/chat-editor-func-voice/chat-editor-func-voice.vue +0 -25
- package/uni-components/chat-editor/chat-editor-message-send/chat-editor-message-send.vue +0 -158
- package/uni-components/chat-editor/chat-editor-quote/chat-editor-quote.vue +0 -75
- package/uni-components/chat-editor/chat-editor.vue +0 -257
- package/uni-components/chat-editor/index.js +0 -10
- package/uni-components/chat-editor/util.js +0 -65
- package/uni-components/chat-panel/chat-panel-chats-box.vue +0 -238
- package/uni-components/chat-panel/chat-panel-chats-forward/chat-panel-chats-forward.vue +0 -273
- package/uni-components/chat-panel/chat-panel-chats-item.vue +0 -578
- package/uni-components/chat-panel/chat-panel-chats-status/chat-panel-chats-status.vue +0 -71
- package/uni-components/chat-panel/chat-panel-chats.vue +0 -368
- package/uni-components/chat-panel/chat-panel.vue +0 -227
- package/uni-components/contacts-group-select/contacts-group-select-item.vue +0 -85
- package/uni-components/contacts-group-select/contacts-group-select-panel.vue +0 -119
- package/uni-components/contacts-group-select/contacts-group-select.vue +0 -150
package/utils/log.js
CHANGED
|
@@ -1,626 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
let uniqueId = Date.now()
|
|
4
|
-
|
|
5
|
-
function unique () {
|
|
6
|
-
uniqueId++
|
|
7
|
-
return uniqueId
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function parse (value) {
|
|
11
|
-
try {
|
|
12
|
-
return typeof value === 'string' ? JSON.parse(value) : value
|
|
13
|
-
} catch (e) {
|
|
14
|
-
return value
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const INDEXED_DB_VERSION = 2
|
|
19
|
-
const INDEXED_DB_STORE_NAME = 'logs'
|
|
20
|
-
const INDEXED_DB_META_STORE_NAME = 'meta'
|
|
21
|
-
const INDEXED_DB_ORDER_INDEX_NAME = 'order'
|
|
22
|
-
const INDEXED_DB_MAX_SIZE = 50 * 1024 * 1024
|
|
23
|
-
const INDEXED_DB_STATS_KEY = 'stats'
|
|
24
|
-
const AUTO_PUBLISH_DELAY = 1000
|
|
25
|
-
|
|
26
|
-
function isUniRuntime () {
|
|
27
|
-
try {
|
|
28
|
-
return !!uni
|
|
29
|
-
} catch (e) {
|
|
30
|
-
return false
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function isIndexedDbSupported () {
|
|
35
|
-
return typeof window !== 'undefined' && !isUniRuntime() && !!window.indexedDB
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function getLogSize (item) {
|
|
39
|
-
return item && item.size ? item.size : JSON.stringify(item || {}).length
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function getLogByteSize (item) {
|
|
43
|
-
const value = JSON.stringify(item || {})
|
|
44
|
-
if (typeof Blob !== 'undefined') {
|
|
45
|
-
return new Blob([value]).size
|
|
46
|
-
}
|
|
47
|
-
return unescape(encodeURIComponent(value)).length
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function normalizeLogStore (store) {
|
|
51
|
-
let nextStore = store
|
|
52
|
-
if (!nextStore) {
|
|
53
|
-
nextStore = {
|
|
54
|
-
size: 0,
|
|
55
|
-
data: []
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (Array.isArray(nextStore)) {
|
|
59
|
-
let totalSize = 0
|
|
60
|
-
nextStore = {
|
|
61
|
-
data: nextStore.map(item => {
|
|
62
|
-
if (item && !item.size) {
|
|
63
|
-
item.size = JSON.stringify(item).length
|
|
64
|
-
}
|
|
65
|
-
totalSize += getLogSize(item)
|
|
66
|
-
return item
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
nextStore.size = totalSize
|
|
70
|
-
}
|
|
71
|
-
if (!Array.isArray(nextStore.data)) {
|
|
72
|
-
nextStore.data = []
|
|
73
|
-
}
|
|
74
|
-
if (!nextStore.size) {
|
|
75
|
-
nextStore.size = nextStore.data.reduce((totalSize, item) => {
|
|
76
|
-
return totalSize + getLogSize(item)
|
|
77
|
-
}, 0)
|
|
78
|
-
}
|
|
79
|
-
return nextStore
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function parseLogStoreValue (value) {
|
|
83
|
-
if (!value) {
|
|
84
|
-
return null
|
|
85
|
-
}
|
|
86
|
-
if (typeof value === 'string') {
|
|
87
|
-
value = parse(value)
|
|
88
|
-
}
|
|
89
|
-
return normalizeLogStore(value)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function readLegacyStorage (storageKey) {
|
|
93
|
-
if (isUniRuntime()) {
|
|
94
|
-
return uni.getStorageSync(storageKey)
|
|
95
|
-
}
|
|
96
|
-
if (typeof window !== 'undefined' && window.localStorage) {
|
|
97
|
-
return window.localStorage.getItem(storageKey)
|
|
98
|
-
}
|
|
99
|
-
return null
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function writeLegacyStorage (storageKey, value) {
|
|
103
|
-
if (isUniRuntime()) {
|
|
104
|
-
uni.setStorageSync(storageKey, value)
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
if (typeof window !== 'undefined' && window.localStorage) {
|
|
108
|
-
window.localStorage.setItem(storageKey, typeof value === 'string' ? value : JSON.stringify(value))
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function removeLegacyStorage (storageKey) {
|
|
113
|
-
if (isUniRuntime()) {
|
|
114
|
-
uni.removeStorageSync(storageKey)
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
if (typeof window !== 'undefined' && window.localStorage) {
|
|
118
|
-
window.localStorage.removeItem(storageKey)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function hashString (value) {
|
|
123
|
-
let hash = 2166136261
|
|
124
|
-
for (let index = 0; index < value.length; index++) {
|
|
125
|
-
hash ^= value.charCodeAt(index)
|
|
126
|
-
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24)
|
|
127
|
-
}
|
|
128
|
-
return (hash >>> 0).toString(16)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function getLogRecordId (log) {
|
|
132
|
-
if (log && log.id !== undefined && log.id !== null) {
|
|
133
|
-
return `id:${log.id}`
|
|
134
|
-
}
|
|
135
|
-
const value = JSON.stringify(log || {})
|
|
136
|
-
return `legacy:${hashString(value)}:${value.length}`
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function createIndexedDbStores (db) {
|
|
140
|
-
const logStore = db.createObjectStore(INDEXED_DB_STORE_NAME, { keyPath: 'recordId' })
|
|
141
|
-
logStore.createIndex(INDEXED_DB_ORDER_INDEX_NAME, 'order', { unique: false })
|
|
142
|
-
if (!db.objectStoreNames.contains(INDEXED_DB_META_STORE_NAME)) {
|
|
143
|
-
db.createObjectStore(INDEXED_DB_META_STORE_NAME, { keyPath: 'key' })
|
|
144
|
-
}
|
|
145
|
-
return logStore
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function createIndexedDbRecord (log, order) {
|
|
149
|
-
return {
|
|
150
|
-
recordId: getLogRecordId(log),
|
|
151
|
-
order,
|
|
152
|
-
byteSize: getLogByteSize(log),
|
|
153
|
-
log
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function uniqueLogs (logs) {
|
|
158
|
-
const recordIds = Object.create(null)
|
|
159
|
-
return logs.filter(log => {
|
|
160
|
-
const recordId = getLogRecordId(log)
|
|
161
|
-
if (recordIds[recordId]) {
|
|
162
|
-
return false
|
|
163
|
-
}
|
|
164
|
-
recordIds[recordId] = true
|
|
165
|
-
return true
|
|
166
|
-
})
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function trimRecordsToIndexedDbLimit (records) {
|
|
170
|
-
let totalBytes = 0
|
|
171
|
-
const retainedRecords = []
|
|
172
|
-
records.some(record => {
|
|
173
|
-
if (record.byteSize + totalBytes > INDEXED_DB_MAX_SIZE) {
|
|
174
|
-
return true
|
|
175
|
-
}
|
|
176
|
-
retainedRecords.push(record)
|
|
177
|
-
totalBytes += record.byteSize
|
|
178
|
-
return false
|
|
179
|
-
})
|
|
180
|
-
return {
|
|
181
|
-
records: retainedRecords,
|
|
182
|
-
totalBytes,
|
|
183
|
-
removedCount: records.length - retainedRecords.length
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export default class Log {
|
|
188
|
-
|
|
189
|
-
static checkAndSync (storageKeys) {
|
|
190
|
-
const keys = [].concat(storageKeys || []).filter((storageKey, index, list) => {
|
|
191
|
-
return typeof storageKey === 'string' && storageKey && list.indexOf(storageKey) === index
|
|
192
|
-
})
|
|
193
|
-
return Promise.all(keys.map(storageKey => {
|
|
194
|
-
const log = new Log({ name: storageKey })
|
|
195
|
-
log._customStorageKey = storageKey
|
|
196
|
-
return log.checkAndSync().then(result => {
|
|
197
|
-
return log._closeIndexedDb().then(() => {
|
|
198
|
-
return Object.assign({ storageKey }, result)
|
|
199
|
-
})
|
|
200
|
-
})
|
|
201
|
-
}))
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
constructor (options) {
|
|
205
|
-
this.prefix = 'log'
|
|
206
|
-
this.name = null
|
|
207
|
-
this.tempStore = []
|
|
208
|
-
this.beforeAddCallback = null
|
|
209
|
-
this._writePromise = Promise.resolve()
|
|
210
|
-
this._indexedDbPromise = null
|
|
211
|
-
this._syncPromise = null
|
|
212
|
-
this._syncCompleted = false
|
|
213
|
-
this._customStorageKey = null
|
|
214
|
-
this._publishTimer = null
|
|
215
|
-
options = Object.assign({
|
|
216
|
-
name: null,
|
|
217
|
-
console: false, // 是否控制台打印
|
|
218
|
-
maxSize: 1024 * 1024 * 3 // 非网页版本默认最多存3M日志数据
|
|
219
|
-
}, options)
|
|
220
|
-
if (!options.name) {
|
|
221
|
-
throw new Error('必须指定日志的name名称')
|
|
222
|
-
}
|
|
223
|
-
this.options = options
|
|
224
|
-
this.maxSize = options.maxSize
|
|
225
|
-
this.name = options.name
|
|
226
|
-
this.validTime = options.validTime
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
get storageKey () {
|
|
230
|
-
return this._customStorageKey || this.prefix + '_' + this.name
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
get useIndexedDb () {
|
|
234
|
-
return isIndexedDbSupported()
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
get indexedDbName () {
|
|
238
|
-
return this.storageKey
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
onBeforeAdd (callback) {
|
|
242
|
-
this.beforeAddCallback = callback
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
_enqueueWrite (callback) {
|
|
246
|
-
const task = this._writePromise.then(callback, callback)
|
|
247
|
-
this._writePromise = task.catch(() => {})
|
|
248
|
-
return task
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
_clearPublishTimer () {
|
|
252
|
-
if (!this._publishTimer) {
|
|
253
|
-
return
|
|
254
|
-
}
|
|
255
|
-
clearTimeout(this._publishTimer)
|
|
256
|
-
this._publishTimer = null
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
_schedulePublish () {
|
|
260
|
-
this._clearPublishTimer()
|
|
261
|
-
this._publishTimer = setTimeout(() => {
|
|
262
|
-
this._publishTimer = null
|
|
263
|
-
this.publishLogData().catch(() => {})
|
|
264
|
-
}, AUTO_PUBLISH_DELAY)
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
_closeIndexedDb () {
|
|
268
|
-
const indexedDbPromise = this._indexedDbPromise
|
|
269
|
-
this._indexedDbPromise = null
|
|
270
|
-
if (!indexedDbPromise) {
|
|
271
|
-
return Promise.resolve()
|
|
272
|
-
}
|
|
273
|
-
return indexedDbPromise.then(db => {
|
|
274
|
-
db.close()
|
|
275
|
-
}, () => {})
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
_upgradeIndexedDb (request) {
|
|
279
|
-
const db = request.result
|
|
280
|
-
const transaction = request.transaction
|
|
281
|
-
if (!db.objectStoreNames.contains(INDEXED_DB_STORE_NAME)) {
|
|
282
|
-
createIndexedDbStores(db)
|
|
283
|
-
transaction.objectStore(INDEXED_DB_META_STORE_NAME).put({
|
|
284
|
-
key: INDEXED_DB_STATS_KEY,
|
|
285
|
-
totalBytes: 0,
|
|
286
|
-
nextOrder: 0
|
|
287
|
-
})
|
|
288
|
-
return
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const legacyStore = transaction.objectStore(INDEXED_DB_STORE_NAME)
|
|
292
|
-
const legacyRequest = legacyStore.get(this.storageKey)
|
|
293
|
-
legacyRequest.onerror = () => {
|
|
294
|
-
transaction.abort()
|
|
295
|
-
}
|
|
296
|
-
legacyRequest.onsuccess = () => {
|
|
297
|
-
let legacyLogStore = null
|
|
298
|
-
try {
|
|
299
|
-
const result = legacyRequest.result
|
|
300
|
-
legacyLogStore = result && result.value ? parseLogStoreValue(result.value) : null
|
|
301
|
-
} catch (e) {
|
|
302
|
-
legacyLogStore = null
|
|
303
|
-
}
|
|
304
|
-
db.deleteObjectStore(INDEXED_DB_STORE_NAME)
|
|
305
|
-
if (db.objectStoreNames.contains(INDEXED_DB_META_STORE_NAME)) {
|
|
306
|
-
db.deleteObjectStore(INDEXED_DB_META_STORE_NAME)
|
|
307
|
-
}
|
|
308
|
-
const logStore = createIndexedDbStores(db)
|
|
309
|
-
const logs = uniqueLogs(legacyLogStore ? legacyLogStore.data : [])
|
|
310
|
-
const records = logs.map((log, index) => createIndexedDbRecord(log, logs.length - index))
|
|
311
|
-
const result = trimRecordsToIndexedDbLimit(records)
|
|
312
|
-
result.records.forEach(record => logStore.put(record))
|
|
313
|
-
transaction.objectStore(INDEXED_DB_META_STORE_NAME).put({
|
|
314
|
-
key: INDEXED_DB_STATS_KEY,
|
|
315
|
-
totalBytes: result.totalBytes,
|
|
316
|
-
nextOrder: logs.length
|
|
317
|
-
})
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
openIndexedDb () {
|
|
322
|
-
if (!this.useIndexedDb) {
|
|
323
|
-
return Promise.reject(new Error('indexedDB不可用'))
|
|
324
|
-
}
|
|
325
|
-
if (this._indexedDbPromise) {
|
|
326
|
-
return this._indexedDbPromise
|
|
327
|
-
}
|
|
328
|
-
this._indexedDbPromise = new Promise((resolve, reject) => {
|
|
329
|
-
const request = window.indexedDB.open(this.indexedDbName, INDEXED_DB_VERSION)
|
|
330
|
-
request.onerror = () => {
|
|
331
|
-
this._indexedDbPromise = null
|
|
332
|
-
reject(request.error || new Error('打开日志数据库失败'))
|
|
333
|
-
}
|
|
334
|
-
request.onupgradeneeded = () => {
|
|
335
|
-
this._upgradeIndexedDb(request)
|
|
336
|
-
}
|
|
337
|
-
request.onsuccess = () => {
|
|
338
|
-
const db = request.result
|
|
339
|
-
db.onversionchange = () => {
|
|
340
|
-
db.close()
|
|
341
|
-
this._indexedDbPromise = null
|
|
342
|
-
}
|
|
343
|
-
resolve(db)
|
|
344
|
-
}
|
|
345
|
-
})
|
|
346
|
-
return this._indexedDbPromise
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
_readIndexedDbLogData () {
|
|
350
|
-
return this.openIndexedDb().then(db => {
|
|
351
|
-
return new Promise((resolve, reject) => {
|
|
352
|
-
const transaction = db.transaction([INDEXED_DB_STORE_NAME], 'readonly')
|
|
353
|
-
const store = transaction.objectStore(INDEXED_DB_STORE_NAME)
|
|
354
|
-
const request = store.index(INDEXED_DB_ORDER_INDEX_NAME).openCursor(null, 'prev')
|
|
355
|
-
const data = []
|
|
356
|
-
let size = 0
|
|
357
|
-
request.onerror = () => {
|
|
358
|
-
reject(request.error || new Error('读取日志失败'))
|
|
359
|
-
}
|
|
360
|
-
request.onsuccess = event => {
|
|
361
|
-
const cursor = event.target.result
|
|
362
|
-
if (!cursor) {
|
|
363
|
-
resolve({ size, data })
|
|
364
|
-
return
|
|
365
|
-
}
|
|
366
|
-
data.push(cursor.value.log)
|
|
367
|
-
size += getLogSize(cursor.value.log)
|
|
368
|
-
cursor.continue()
|
|
369
|
-
}
|
|
370
|
-
})
|
|
371
|
-
})
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
_writeIndexedDbLogs (logs) {
|
|
375
|
-
if (!logs.length) {
|
|
376
|
-
return Promise.resolve({ migratedCount: 0, duplicateCount: 0, removedCount: 0 })
|
|
377
|
-
}
|
|
378
|
-
const uniqueLogList = uniqueLogs(logs)
|
|
379
|
-
const repeatedInputCount = logs.length - uniqueLogList.length
|
|
380
|
-
return this.openIndexedDb().then(db => {
|
|
381
|
-
return new Promise((resolve, reject) => {
|
|
382
|
-
const transaction = db.transaction(
|
|
383
|
-
[INDEXED_DB_STORE_NAME, INDEXED_DB_META_STORE_NAME],
|
|
384
|
-
'readwrite'
|
|
385
|
-
)
|
|
386
|
-
const store = transaction.objectStore(INDEXED_DB_STORE_NAME)
|
|
387
|
-
const metaStore = transaction.objectStore(INDEXED_DB_META_STORE_NAME)
|
|
388
|
-
const metaRequest = metaStore.get(INDEXED_DB_STATS_KEY)
|
|
389
|
-
let result = null
|
|
390
|
-
transaction.oncomplete = () => {
|
|
391
|
-
resolve(result || { migratedCount: 0, duplicateCount: 0, removedCount: 0 })
|
|
392
|
-
}
|
|
393
|
-
transaction.onerror = () => {
|
|
394
|
-
reject(transaction.error || new Error('写入日志失败'))
|
|
395
|
-
}
|
|
396
|
-
transaction.onabort = () => {
|
|
397
|
-
reject(transaction.error || new Error('写入日志失败'))
|
|
398
|
-
}
|
|
399
|
-
metaRequest.onsuccess = () => {
|
|
400
|
-
const stats = metaRequest.result || {
|
|
401
|
-
key: INDEXED_DB_STATS_KEY,
|
|
402
|
-
totalBytes: 0,
|
|
403
|
-
nextOrder: 0
|
|
404
|
-
}
|
|
405
|
-
const records = uniqueLogList.map((log, index) => {
|
|
406
|
-
return createIndexedDbRecord(log, stats.nextOrder + uniqueLogList.length - index)
|
|
407
|
-
})
|
|
408
|
-
let pendingCount = records.length
|
|
409
|
-
let duplicateCount = repeatedInputCount
|
|
410
|
-
records.forEach(record => {
|
|
411
|
-
const getRequest = store.get(record.recordId)
|
|
412
|
-
getRequest.onsuccess = () => {
|
|
413
|
-
if (getRequest.result) {
|
|
414
|
-
stats.totalBytes -= getRequest.result.byteSize || 0
|
|
415
|
-
duplicateCount++
|
|
416
|
-
}
|
|
417
|
-
stats.totalBytes += record.byteSize
|
|
418
|
-
store.put(record)
|
|
419
|
-
pendingCount--
|
|
420
|
-
if (!pendingCount) {
|
|
421
|
-
stats.nextOrder += uniqueLogList.length
|
|
422
|
-
trimOldestLogs(stats, duplicateCount)
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
})
|
|
426
|
-
|
|
427
|
-
function trimOldestLogs (nextStats, nextDuplicateCount) {
|
|
428
|
-
let removedCount = 0
|
|
429
|
-
const cursorRequest = store.index(INDEXED_DB_ORDER_INDEX_NAME).openCursor(null, 'next')
|
|
430
|
-
cursorRequest.onsuccess = event => {
|
|
431
|
-
const cursor = event.target.result
|
|
432
|
-
if (nextStats.totalBytes <= INDEXED_DB_MAX_SIZE || !cursor) {
|
|
433
|
-
metaStore.put(nextStats)
|
|
434
|
-
result = {
|
|
435
|
-
migratedCount: logs.length - nextDuplicateCount,
|
|
436
|
-
duplicateCount: nextDuplicateCount,
|
|
437
|
-
removedCount
|
|
438
|
-
}
|
|
439
|
-
return
|
|
440
|
-
}
|
|
441
|
-
nextStats.totalBytes -= cursor.value.byteSize || 0
|
|
442
|
-
cursor.delete()
|
|
443
|
-
removedCount++
|
|
444
|
-
cursor.continue()
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
})
|
|
449
|
-
})
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
_writeLegacyLogs (logs) {
|
|
453
|
-
const localLogStore = parseLogStoreValue(readLegacyStorage(this.storageKey)) || {
|
|
454
|
-
size: 0,
|
|
455
|
-
data: []
|
|
456
|
-
}
|
|
457
|
-
const allData = [].concat(logs, localLogStore.data)
|
|
458
|
-
const nextLocalStore = {
|
|
459
|
-
size: 0,
|
|
460
|
-
data: []
|
|
461
|
-
}
|
|
462
|
-
allData.some(item => {
|
|
463
|
-
const itemSize = getLogSize(item)
|
|
464
|
-
if (itemSize + nextLocalStore.size >= this.maxSize) {
|
|
465
|
-
return true
|
|
466
|
-
}
|
|
467
|
-
nextLocalStore.data.push(item)
|
|
468
|
-
nextLocalStore.size += itemSize
|
|
469
|
-
return false
|
|
470
|
-
})
|
|
471
|
-
writeLegacyStorage(this.storageKey, nextLocalStore)
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
checkAndSync () {
|
|
475
|
-
if (!this.useIndexedDb || this._syncCompleted) {
|
|
476
|
-
return Promise.resolve({
|
|
477
|
-
synced: false,
|
|
478
|
-
migratedCount: 0,
|
|
479
|
-
duplicateCount: 0,
|
|
480
|
-
removedCount: 0
|
|
481
|
-
})
|
|
482
|
-
}
|
|
483
|
-
if (this._syncPromise) {
|
|
484
|
-
return this._syncPromise
|
|
485
|
-
}
|
|
486
|
-
const task = this._enqueueWrite(() => {
|
|
487
|
-
const legacyLogStore = parseLogStoreValue(readLegacyStorage(this.storageKey))
|
|
488
|
-
if (!legacyLogStore || !legacyLogStore.data.length) {
|
|
489
|
-
return {
|
|
490
|
-
synced: false,
|
|
491
|
-
migratedCount: 0,
|
|
492
|
-
duplicateCount: 0,
|
|
493
|
-
removedCount: 0
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
return this._writeIndexedDbLogs(legacyLogStore.data).then(result => {
|
|
497
|
-
removeLegacyStorage(this.storageKey)
|
|
498
|
-
return Object.assign({ synced: true }, result)
|
|
499
|
-
})
|
|
500
|
-
})
|
|
501
|
-
this._syncPromise = task.then(result => {
|
|
502
|
-
this._syncPromise = null
|
|
503
|
-
this._syncCompleted = true
|
|
504
|
-
return result
|
|
505
|
-
}, () => {
|
|
506
|
-
this._syncPromise = null
|
|
507
|
-
this._syncCompleted = true
|
|
508
|
-
return {
|
|
509
|
-
synced: false,
|
|
510
|
-
migratedCount: 0,
|
|
511
|
-
duplicateCount: 0,
|
|
512
|
-
removedCount: 0
|
|
513
|
-
}
|
|
514
|
-
})
|
|
515
|
-
return this._syncPromise
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
* 新增日志到内存
|
|
520
|
-
*/
|
|
521
|
-
addLog (data) {
|
|
522
|
-
data = Object.assign({
|
|
523
|
-
group: this.defautGroup,
|
|
524
|
-
refererId: undefined, // 可以关联一个日志
|
|
525
|
-
content: null
|
|
526
|
-
}, data, {
|
|
527
|
-
createTime: formatDate(new Date())
|
|
528
|
-
})
|
|
529
|
-
data.id = unique(data.group)
|
|
530
|
-
if (this.beforeAddCallback && this.beforeAddCallback({ data }) === false) {
|
|
531
|
-
return
|
|
532
|
-
}
|
|
533
|
-
data.size = JSON.stringify(data).length
|
|
534
|
-
this.tempStore.push(data)
|
|
535
|
-
this.checkAndSync().catch(() => {})
|
|
536
|
-
this._schedulePublish()
|
|
537
|
-
if (this.tempStore.length > 5) {
|
|
538
|
-
this.publishLogData().then(null, err => {
|
|
539
|
-
console.log(err)
|
|
540
|
-
})
|
|
541
|
-
}
|
|
542
|
-
if (this.options.console) {
|
|
543
|
-
console.log(`【${this.name || 'operateLog'}】${JSON.stringify(data) || '--'}`)
|
|
544
|
-
}
|
|
545
|
-
return data
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
* 清空本地日志
|
|
550
|
-
*/
|
|
551
|
-
clearLogData () {
|
|
552
|
-
this._clearPublishTimer()
|
|
553
|
-
this.tempStore = []
|
|
554
|
-
const task = this._enqueueWrite(() => {
|
|
555
|
-
if (!this.useIndexedDb) {
|
|
556
|
-
removeLegacyStorage(this.storageKey)
|
|
557
|
-
return
|
|
558
|
-
}
|
|
559
|
-
return this.openIndexedDb().then(db => {
|
|
560
|
-
return new Promise((resolve, reject) => {
|
|
561
|
-
const transaction = db.transaction(
|
|
562
|
-
[INDEXED_DB_STORE_NAME, INDEXED_DB_META_STORE_NAME],
|
|
563
|
-
'readwrite'
|
|
564
|
-
)
|
|
565
|
-
transaction.objectStore(INDEXED_DB_STORE_NAME).clear()
|
|
566
|
-
transaction.objectStore(INDEXED_DB_META_STORE_NAME).put({
|
|
567
|
-
key: INDEXED_DB_STATS_KEY,
|
|
568
|
-
totalBytes: 0,
|
|
569
|
-
nextOrder: 0
|
|
570
|
-
})
|
|
571
|
-
transaction.oncomplete = resolve
|
|
572
|
-
transaction.onerror = () => reject(transaction.error || new Error('清理日志失败'))
|
|
573
|
-
transaction.onabort = () => reject(transaction.error || new Error('清理日志失败'))
|
|
574
|
-
})
|
|
575
|
-
}).then(() => {
|
|
576
|
-
removeLegacyStorage(this.storageKey)
|
|
577
|
-
})
|
|
578
|
-
})
|
|
579
|
-
return task.catch(() => {
|
|
580
|
-
removeLegacyStorage(this.storageKey)
|
|
581
|
-
})
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
loadLogData () {
|
|
585
|
-
return this.checkAndSync().then(() => this._writePromise).then(() => {
|
|
586
|
-
if (this.useIndexedDb) {
|
|
587
|
-
return this._readIndexedDbLogData().catch(() => ({ size: 0, data: [] }))
|
|
588
|
-
}
|
|
589
|
-
return parseLogStoreValue(readLegacyStorage(this.storageKey)) || {
|
|
590
|
-
size: 0,
|
|
591
|
-
data: []
|
|
592
|
-
}
|
|
593
|
-
})
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
publishLogData () {
|
|
597
|
-
this._clearPublishTimer()
|
|
598
|
-
return this.checkAndSync().then(() => {
|
|
599
|
-
return this._enqueueWrite(() => {
|
|
600
|
-
if (!this.tempStore.length) {
|
|
601
|
-
return
|
|
602
|
-
}
|
|
603
|
-
const flushingTempStore = this.tempStore.slice()
|
|
604
|
-
this.tempStore = []
|
|
605
|
-
let writeTask
|
|
606
|
-
if (this.useIndexedDb) {
|
|
607
|
-
writeTask = this._writeIndexedDbLogs(flushingTempStore).catch(() => {})
|
|
608
|
-
} else {
|
|
609
|
-
writeTask = Promise.resolve().then(() => this._writeLegacyLogs(flushingTempStore))
|
|
610
|
-
}
|
|
611
|
-
return writeTask.catch(error => {
|
|
612
|
-
this.tempStore = flushingTempStore.concat(this.tempStore)
|
|
613
|
-
throw error
|
|
614
|
-
})
|
|
615
|
-
})
|
|
616
|
-
})
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
exportLogData () {
|
|
620
|
-
return this.checkAndSync().then(() => {
|
|
621
|
-
return this.publishLogData()
|
|
622
|
-
}).then(() => {
|
|
623
|
-
return this.loadLogData()
|
|
624
|
-
})
|
|
625
|
-
}
|
|
626
|
-
}
|
|
1
|
+
export { default } from './log/index'
|
|
2
|
+
export * from './log/index'
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import SdkChatPanelBox from '../../../chat-panel/chat-panel-box'
|
|
3
|
-
import { companyCard } from '../../../wework-chat-control'
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
name: 'SdkWeworkChatPanelControlsCompanyCard',
|
|
7
|
-
functional: true,
|
|
8
|
-
props: {
|
|
9
|
-
dir: {
|
|
10
|
-
type: String
|
|
11
|
-
},
|
|
12
|
-
data: {
|
|
13
|
-
type: Object,
|
|
14
|
-
required: true
|
|
15
|
-
},
|
|
16
|
-
fetchUserMethod: {
|
|
17
|
-
type: Function
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
render (h, c) {
|
|
21
|
-
const { props } = c
|
|
22
|
-
return h(SdkChatPanelBox, {
|
|
23
|
-
props: {
|
|
24
|
-
dir: props.dir,
|
|
25
|
-
data: props.data,
|
|
26
|
-
fetchUserMethod: props.fetchUserMethod
|
|
27
|
-
}
|
|
28
|
-
}, [h(companyCard, {
|
|
29
|
-
props: {
|
|
30
|
-
data: props.data
|
|
31
|
-
}
|
|
32
|
-
})])
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
</script>
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { expression } from '../../../wework-chat-control'
|
|
3
|
-
import SdkChatPanelBox from '../../../chat-panel/chat-panel-box'
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
name: 'SdkWeworkChatPanelControlsExpression',
|
|
7
|
-
functional: true,
|
|
8
|
-
props: {
|
|
9
|
-
dir: {
|
|
10
|
-
type: String
|
|
11
|
-
},
|
|
12
|
-
data: {
|
|
13
|
-
type: Object,
|
|
14
|
-
default: () => ({})
|
|
15
|
-
},
|
|
16
|
-
fetchUserMethod: {
|
|
17
|
-
type: Function
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
render (h, c) {
|
|
21
|
-
const { props } = c
|
|
22
|
-
return h(SdkChatPanelBox, {
|
|
23
|
-
props: {
|
|
24
|
-
dir: props.dir,
|
|
25
|
-
data: props.data,
|
|
26
|
-
fetchUserMethod: props.fetchUserMethod
|
|
27
|
-
}
|
|
28
|
-
}, [h(expression, {
|
|
29
|
-
props: {
|
|
30
|
-
data: props.data
|
|
31
|
-
},
|
|
32
|
-
key: c.data.key
|
|
33
|
-
})])
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
</script>
|