@dcloudio/uni-cli-shared 2.0.2-4020420240722002 → 2.0.2-4020420240722004

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.
@@ -1,674 +1,668 @@
1
1
  <template>
2
2
  <view>
3
- <slot
4
- :options="options"
5
- :data="dataList"
6
- :pagination="paginationInternal"
7
- :loading="loading"
8
- :hasMore="hasMore"
9
- :error="errorMessage"
10
- />
3
+ <slot :options="options" :data="dataList" :pagination="paginationInternal" :loading="loading" :hasMore="hasMore"
4
+ :error="errorMessage" />
11
5
  </view>
12
6
  </template>
13
7
 
14
8
  <script>
15
- import {
16
- initVueI18n
17
- } from '@dcloudio/uni-i18n'
18
- import messages from './i18n/index'
19
-
20
- const {
21
- t
22
- } = initVueI18n(messages)
23
-
24
- const events = {
25
- load: 'load',
26
- error: 'error'
27
- }
28
- const pageMode = {
29
- add: 'add',
30
- replace: 'replace'
31
- }
32
- const loadMode = {
33
- auto: 'auto',
34
- onready: 'onready',
35
- manual: 'manual'
36
- }
37
-
38
- const attrs = [
39
- 'pageCurrent',
40
- 'pageSize',
41
- 'spaceInfo',
42
- 'collection',
43
- 'action',
44
- 'field',
45
- 'getcount',
46
- 'orderby',
47
- 'where',
48
- 'groupby',
49
- 'groupField',
50
- 'distinct'
51
- ]
52
-
53
- export default {
54
- name: 'UniClouddb',
55
- props: {
56
- options: {
57
- type: [Object, Array],
58
- default () {
59
- return {}
9
+ import {
10
+ initVueI18n
11
+ } from '@dcloudio/uni-i18n'
12
+ import messages from './i18n/index'
13
+
14
+ const {
15
+ t
16
+ } = initVueI18n(messages)
17
+
18
+ const events = {
19
+ load: 'load',
20
+ error: 'error'
21
+ }
22
+ const pageMode = {
23
+ add: 'add',
24
+ replace: 'replace'
25
+ }
26
+ const loadMode = {
27
+ auto: 'auto',
28
+ onready: 'onready',
29
+ manual: 'manual'
30
+ }
31
+
32
+ const attrs = [
33
+ 'pageCurrent',
34
+ 'pageSize',
35
+ 'spaceInfo',
36
+ 'collection',
37
+ 'action',
38
+ 'field',
39
+ 'getcount',
40
+ 'orderby',
41
+ 'where',
42
+ 'groupby',
43
+ 'groupField',
44
+ 'distinct'
45
+ ]
46
+
47
+ export default {
48
+ name: 'UniClouddb',
49
+ props: {
50
+ options: {
51
+ type: [Object, Array],
52
+ default () {
53
+ return {}
54
+ }
55
+ },
56
+ spaceInfo: {
57
+ type: Object,
58
+ default () {
59
+ return {}
60
+ }
61
+ },
62
+ collection: {
63
+ type: [String, Array],
64
+ default: ''
65
+ },
66
+ action: {
67
+ type: String,
68
+ default: ''
69
+ },
70
+ field: {
71
+ type: String,
72
+ default: ''
73
+ },
74
+ orderby: {
75
+ type: String,
76
+ default: ''
77
+ },
78
+ where: {
79
+ type: [String, Object],
80
+ default: ''
81
+ },
82
+ pageData: {
83
+ type: String,
84
+ default: 'add'
85
+ },
86
+ pageCurrent: {
87
+ type: Number,
88
+ default: 1
89
+ },
90
+ pageSize: {
91
+ type: Number,
92
+ default: 20
93
+ },
94
+ getcount: {
95
+ type: [Boolean, String],
96
+ default: false
97
+ },
98
+ getone: {
99
+ type: [Boolean, String],
100
+ default: false
101
+ },
102
+ gettree: {
103
+ type: [Boolean, String, Object],
104
+ default: false
105
+ },
106
+ gettreepath: {
107
+ type: [Boolean, String],
108
+ default: false
109
+ },
110
+ startwith: {
111
+ type: String,
112
+ default: ''
113
+ },
114
+ limitlevel: {
115
+ type: Number,
116
+ default: 10
117
+ },
118
+ groupby: {
119
+ type: String,
120
+ default: ''
121
+ },
122
+ groupField: {
123
+ type: String,
124
+ default: ''
125
+ },
126
+ distinct: {
127
+ type: [Boolean, String],
128
+ default: false
129
+ },
130
+ pageIndistinct: {
131
+ type: [Boolean, String],
132
+ default: false
133
+ },
134
+ foreignKey: {
135
+ type: String,
136
+ default: ''
137
+ },
138
+ loadtime: {
139
+ type: String,
140
+ default: 'auto'
141
+ },
142
+ manual: {
143
+ type: Boolean,
144
+ default: false
145
+ }
146
+ },
147
+ data() {
148
+ return {
149
+ loading: false,
150
+ hasMore: false,
151
+ dataList: this.getone ? undefined : [],
152
+ paginationInternal: {},
153
+ errorMessage: ''
154
+ }
155
+ },
156
+ computed: {
157
+ collectionArgs() {
158
+ return Array.isArray(this.collection) ? this.collection : [this.collection]
159
+ },
160
+ isLookup() {
161
+ return (Array.isArray(this.collection) && this.collection.length > 1) || (typeof this.collection === 'string' &&
162
+ this.collection.indexOf(',') > -1)
60
163
  }
61
164
  },
62
- spaceInfo: {
63
- type: Object,
64
- default () {
65
- return {}
165
+ created() {
166
+ this._isEnded = false
167
+ this.paginationInternal = {
168
+ current: this.pageCurrent,
169
+ size: this.pageSize,
170
+ count: 0
66
171
  }
67
- },
68
- collection: {
69
- type: [String, Array],
70
- default: ''
71
- },
72
- action: {
73
- type: String,
74
- default: ''
75
- },
76
- field: {
77
- type: String,
78
- default: ''
79
- },
80
- orderby: {
81
- type: String,
82
- default: ''
83
- },
84
- where: {
85
- type: [String, Object],
86
- default: ''
87
- },
88
- pageData: {
89
- type: String,
90
- default: 'add'
91
- },
92
- pageCurrent: {
93
- type: Number,
94
- default: 1
95
- },
96
- pageSize: {
97
- type: Number,
98
- default: 20
99
- },
100
- getcount: {
101
- type: [Boolean, String],
102
- default: false
103
- },
104
- getone: {
105
- type: [Boolean, String],
106
- default: false
107
- },
108
- gettree: {
109
- type: [Boolean, String, Object],
110
- default: false
111
- },
112
- gettreepath: {
113
- type: [Boolean, String],
114
- default: false
115
- },
116
- startwith: {
117
- type: String,
118
- default: ''
119
- },
120
- limitlevel: {
121
- type: Number,
122
- default: 10
123
- },
124
- groupby: {
125
- type: String,
126
- default: ''
127
- },
128
- groupField: {
129
- type: String,
130
- default: ''
131
- },
132
- distinct: {
133
- type: [Boolean, String],
134
- default: false
135
- },
136
- pageIndistinct: {
137
- type: [Boolean, String],
138
- default: false
139
- },
140
- foreignKey: {
141
- type: String,
142
- default: ''
143
- },
144
- loadtime: {
145
- type: String,
146
- default: 'auto'
147
- },
148
- manual: {
149
- type: Boolean,
150
- default: false
151
- }
152
- },
153
- data () {
154
- return {
155
- loading: false,
156
- hasMore: false,
157
- dataList: this.getone ? undefined : [],
158
- paginationInternal: {},
159
- errorMessage: ''
160
- }
161
- },
162
- computed: {
163
- collectionArgs () {
164
- return Array.isArray(this.collection) ? this.collection : [this.collection]
165
- },
166
- isLookup () {
167
- return (Array.isArray(this.collection) && this.collection.length > 1) || (typeof this.collection === 'string' &&
168
- this.collection.indexOf(',') > -1)
169
- }
170
- },
171
- created () {
172
- this._isEnded = false
173
- this.paginationInternal = {
174
- current: this.pageCurrent,
175
- size: this.pageSize,
176
- count: 0
177
- }
178
172
 
179
- this.$watch(() => {
180
- var al = []
181
- attrs.forEach(key => {
182
- al.push(this[key])
183
- })
184
- return al
185
- }, (newValue, oldValue) => {
186
- this.paginationInternal.size = this.pageSize
187
- if (newValue[0] !== oldValue[0]) {
188
- this.paginationInternal.current = this.pageCurrent
189
- }
190
- if (this.loadtime === loadMode.manual) {
191
- return
192
- }
173
+ this.$watch(() => {
174
+ var al = []
175
+ attrs.forEach(key => {
176
+ al.push(this[key])
177
+ })
178
+ return al
179
+ }, (newValue, oldValue) => {
180
+ this.paginationInternal.size = this.pageSize
181
+ if (newValue[0] !== oldValue[0]) {
182
+ this.paginationInternal.current = this.pageCurrent
183
+ }
184
+ if (this.loadtime === loadMode.manual) {
185
+ return
186
+ }
193
187
 
194
- let needReset = false
195
- for (let i = 2; i < newValue.length; i++) {
196
- if (newValue[i] !== oldValue[i]) {
197
- needReset = true
198
- break
188
+ let needReset = false
189
+ for (let i = 2; i < newValue.length; i++) {
190
+ if (newValue[i] !== oldValue[i]) {
191
+ needReset = true
192
+ break
193
+ }
194
+ }
195
+ if (needReset) {
196
+ this.clear()
197
+ this.reset()
199
198
  }
200
- }
201
- if (needReset) {
202
- this.clear()
203
- this.reset()
204
- }
205
199
 
206
- this._execLoadData()
207
- })
200
+ this._execLoadData()
201
+ })
208
202
 
209
- // #ifdef H5
210
- if (process.env.NODE_ENV === 'development') {
211
- this._debugDataList = []
212
- if (!window.unidev) {
213
- window.unidev = {
214
- clientDB: {
215
- data: []
203
+ // #ifdef H5
204
+ if (process.env.NODE_ENV === 'development') {
205
+ this._debugDataList = []
206
+ if (!window.unidev) {
207
+ window.unidev = {
208
+ clientDB: {
209
+ data: []
210
+ }
216
211
  }
217
212
  }
213
+ window.unidev.clientDB.data.push(this._debugDataList)
218
214
  }
219
- window.unidev.clientDB.data.push(this._debugDataList)
220
- }
221
- // #endif
215
+ // #endif
222
216
 
223
- // #ifdef MP-TOUTIAO
224
- let changeName
225
- const events = this.$scope.dataset.eventOpts || []
226
- for (var i = 0; i < events.length; i++) {
227
- const event = events[i]
228
- if (event[0].includes('^load')) {
229
- changeName = event[1][0][0]
230
- }
231
- }
232
- if (changeName) {
233
- let parent = this.$parent
234
- let maxDepth = 16
235
- this._changeDataFunction = null
236
- while (parent && maxDepth > 0) {
237
- const fun = parent[changeName]
238
- if (fun && typeof fun === 'function') {
239
- this._changeDataFunction = fun
240
- maxDepth = 0
241
- break
242
- }
243
- parent = parent.$parent
244
- maxDepth--
245
- }
246
- }
247
- // #endif
248
-
249
- if (!this.manual && this.loadtime === loadMode.auto) {
250
- this.loadData()
251
- }
252
- },
253
- // #ifdef H5
254
- beforeDestroy () {
255
- if (process.env.NODE_ENV === 'development' && window.unidev) {
256
- var cd = this._debugDataList
257
- var dl = window.unidev.clientDB.data
258
- for (var i = dl.length - 1; i >= 0; i--) {
259
- if (dl[i] === cd) {
260
- dl.splice(i, 1)
261
- break
217
+ // #ifdef MP-TOUTIAO
218
+ let changeName
219
+ const events = this.$scope.dataset.eventOpts || []
220
+ for (var i = 0; i < events.length; i++) {
221
+ const event = events[i]
222
+ if (event[0].includes('^load')) {
223
+ changeName = event[1][0][0]
262
224
  }
263
225
  }
264
- }
265
- },
266
- // #endif
267
- methods: {
268
- loadData (args1, args2) {
269
- let callback = null
270
- let clear = false
271
- if (typeof args1 === 'object') {
272
- if (args1.clear) {
273
- if (this.pageData === pageMode.replace) {
274
- this.clear()
275
- } else {
276
- clear = args1.clear
226
+ if (changeName) {
227
+ let parent = this.$parent
228
+ let maxDepth = 16
229
+ this._changeDataFunction = null
230
+ while (parent && maxDepth > 0) {
231
+ const fun = parent[changeName]
232
+ if (fun && typeof fun === 'function') {
233
+ this._changeDataFunction = fun
234
+ maxDepth = 0
235
+ break
277
236
  }
278
- this.reset()
237
+ parent = parent.$parent
238
+ maxDepth--
279
239
  }
280
- if (args1.current !== undefined) {
281
- this.paginationInternal.current = args1.current
282
- }
283
- if (typeof args2 === 'function') {
284
- callback = args2
285
- }
286
- } else if (typeof args1 === 'function') {
287
- callback = args1
288
240
  }
241
+ // #endif
289
242
 
290
- this._execLoadData(callback, clear)
291
- },
292
- loadMore () {
293
- if (this._isEnded || this.loading) {
294
- return
243
+ if (!this.manual && this.loadtime === loadMode.auto) {
244
+ this.loadData()
295
245
  }
296
-
297
- if (this.pageData === pageMode.add) {
298
- this.paginationInternal.current++
299
- }
300
-
301
- this._execLoadData()
302
- },
303
- refresh () {
304
- this.clear()
305
- this._execLoadData()
306
246
  },
307
- clear () {
308
- this._isEnded = false
309
- this.dataList = []
310
- },
311
- reset () {
312
- this.paginationInternal.current = 1
313
- },
314
- add (value, {
315
- action,
316
- showToast = true,
317
- toastTitle,
318
- success,
319
- fail,
320
- complete,
321
- needConfirm = true,
322
- needLoading = true,
323
- loadingTitle = ''
324
- } = {}) {
325
- if (needLoading) {
326
- uni.showLoading({
327
- title: loadingTitle
328
- })
329
- }
330
- /* eslint-disable no-undef */
331
- let db = uniCloud.database(this.spaceInfo)
332
- if (action) {
333
- db = db.action(action)
247
+ // #ifdef H5
248
+ beforeDestroy() {
249
+ if (process.env.NODE_ENV === 'development' && window.unidev) {
250
+ var cd = this._debugDataList
251
+ var dl = window.unidev.clientDB.data
252
+ for (var i = dl.length - 1; i >= 0; i--) {
253
+ if (dl[i] === cd) {
254
+ dl.splice(i, 1)
255
+ break
256
+ }
257
+ }
334
258
  }
259
+ },
260
+ // #endif
261
+ methods: {
262
+ loadData(args1, args2) {
263
+ let callback = null
264
+ let clear = false
265
+ if (typeof args1 === 'object') {
266
+ if (args1.clear) {
267
+ if (this.pageData === pageMode.replace) {
268
+ this.clear()
269
+ } else {
270
+ clear = args1.clear
271
+ }
272
+ this.reset()
273
+ }
274
+ if (args1.current !== undefined) {
275
+ this.paginationInternal.current = args1.current
276
+ }
277
+ if (typeof args2 === 'function') {
278
+ callback = args2
279
+ }
280
+ } else if (typeof args1 === 'function') {
281
+ callback = args1
282
+ }
335
283
 
336
- db.collection(this.getMainCollection()).add(value).then((res) => {
337
- success && success(res)
338
- if (showToast) {
339
- uni.showToast({
340
- title: toastTitle || t('uniCloud.component.add.success')
341
- })
284
+ this._execLoadData(callback, clear)
285
+ },
286
+ loadMore() {
287
+ if (this._isEnded || this.loading) {
288
+ return
342
289
  }
343
- }).catch((err) => {
344
- fail && fail(err)
345
- if (needConfirm) {
346
- uni.showModal({
347
- content: err.message,
348
- showCancel: false
349
- })
290
+
291
+ if (this.pageData === pageMode.add) {
292
+ this.paginationInternal.current++
350
293
  }
351
- }).finally(() => {
294
+
295
+ this._execLoadData()
296
+ },
297
+ refresh() {
298
+ this.clear()
299
+ this._execLoadData()
300
+ },
301
+ clear() {
302
+ this._isEnded = false
303
+ this.dataList = []
304
+ },
305
+ reset() {
306
+ this.paginationInternal.current = 1
307
+ },
308
+ add(value, {
309
+ action,
310
+ showToast = true,
311
+ toastTitle,
312
+ success,
313
+ fail,
314
+ complete,
315
+ needConfirm = true,
316
+ needLoading = true,
317
+ loadingTitle = ''
318
+ } = {}) {
352
319
  if (needLoading) {
353
- uni.hideLoading()
320
+ uni.showLoading({
321
+ title: loadingTitle
322
+ })
354
323
  }
355
- complete && complete()
356
- })
357
- },
358
- remove (id, {
359
- action,
360
- success,
361
- fail,
362
- complete,
363
- confirmTitle,
364
- confirmContent,
365
- needConfirm = true,
366
- needLoading = true,
367
- loadingTitle = ''
368
- } = {}) {
369
- if (!id || !id.length) {
370
- return
371
- }
372
- if (!needConfirm) {
373
- this._execRemove(id, action, success, fail, complete, needConfirm, needLoading, loadingTitle)
374
- return
375
- }
376
- uni.showModal({
377
- title: confirmTitle || t('uniCloud.component.remove.showModal.title'),
378
- content: confirmContent || t('uniCloud.component.remove.showModal.content'),
379
- showCancel: true,
380
- success: (res) => {
381
- if (!res.confirm) {
382
- return
324
+ /* eslint-disable no-undef */
325
+ let db = uniCloud.database(this.spaceInfo)
326
+ if (action) {
327
+ db = db.action(action)
328
+ }
329
+
330
+ db.collection(this.getMainCollection()).add(value).then((res) => {
331
+ success && success(res)
332
+ if (showToast) {
333
+ uni.showToast({
334
+ title: toastTitle || t('uniCloud.component.add.success')
335
+ })
336
+ }
337
+ }).catch((err) => {
338
+ fail && fail(err)
339
+ if (needConfirm) {
340
+ uni.showModal({
341
+ content: err.message,
342
+ showCancel: false
343
+ })
344
+ }
345
+ }).finally(() => {
346
+ if (needLoading) {
347
+ uni.hideLoading()
383
348
  }
349
+ complete && complete()
350
+ })
351
+ },
352
+ remove(id, {
353
+ action,
354
+ success,
355
+ fail,
356
+ complete,
357
+ confirmTitle,
358
+ confirmContent,
359
+ needConfirm = true,
360
+ needLoading = true,
361
+ loadingTitle = ''
362
+ } = {}) {
363
+ if (!id || !id.length) {
364
+ return
365
+ }
366
+ if (!needConfirm) {
384
367
  this._execRemove(id, action, success, fail, complete, needConfirm, needLoading, loadingTitle)
368
+ return
385
369
  }
386
- })
387
- },
388
- update (id, value, options = {}) {
389
- const fixOptions = Object.assign({
390
- action: null,
391
- showToast: true,
392
- toastTitle: null,
393
- success: null,
394
- fail: null,
395
- complete: null,
396
- confirmTitle: null,
397
- confirmContent: null,
398
- needConfirm: true,
399
- needLoading: true,
400
- loadingTitle: ''
401
- }, options)
402
- if (!options.needConfirm) {
403
370
  uni.showModal({
404
- title: options.confirmTitle || t('uniCloud.component.update.showModal.title'),
405
- content: options.confirmContent || t('uniCloud.component.update.showModal.content'),
371
+ title: confirmTitle || t('uniCloud.component.remove.showModal.title'),
372
+ content: confirmContent || t('uniCloud.component.remove.showModal.content'),
406
373
  showCancel: true,
407
374
  success: (res) => {
408
- if (res.confirm) {
409
- this._doUpdate(id, value, fixOptions)
375
+ if (!res.confirm) {
376
+ return
410
377
  }
378
+ this._execRemove(id, action, success, fail, complete, needConfirm, needLoading, loadingTitle)
411
379
  }
412
380
  })
413
- } else {
414
- this._doUpdate(id, value, fixOptions)
415
- }
416
- },
417
- _doUpdate (id, value, options) {
418
- const {
419
- action,
420
- success,
421
- fail,
422
- complete,
423
- showToast,
424
- toastTitle,
425
- needConfirm,
426
- needLoading,
427
- loadingTitle
428
- } = options
429
-
430
- if (needLoading) {
431
- uni.showLoading({
432
- title: loadingTitle
433
- })
434
- }
435
- /* eslint-disable no-undef */
436
- let db = uniCloud.database(this.spaceInfo)
437
- if (action) {
438
- db = db.action(action)
439
- }
440
-
441
- db.collection(this.getMainCollection()).doc(id).update(value).then((res) => {
442
- success && success(res)
443
- if (showToast) {
444
- uni.showToast({
445
- title: toastTitle || t('uniCloud.component.update.success')
446
- })
447
- }
448
- }).catch((err) => {
449
- fail && fail(err)
450
- if (needConfirm) {
381
+ },
382
+ update(id, value, options = {}) {
383
+ const fixOptions = Object.assign({
384
+ action: null,
385
+ showToast: true,
386
+ toastTitle: null,
387
+ success: null,
388
+ fail: null,
389
+ complete: null,
390
+ confirmTitle: null,
391
+ confirmContent: null,
392
+ needConfirm: true,
393
+ needLoading: true,
394
+ loadingTitle: ''
395
+ }, options);
396
+ if (!options.needConfirm) {
451
397
  uni.showModal({
452
- content: err.message,
453
- showCancel: false
398
+ title: options.confirmTitle || t('uniCloud.component.update.showModal.title'),
399
+ content: options.confirmContent || t('uniCloud.component.update.showModal.content'),
400
+ showCancel: true,
401
+ success: (res) => {
402
+ if (res.confirm) {
403
+ this._doUpdate(id, value, fixOptions)
404
+ }
405
+ }
454
406
  })
407
+ } else {
408
+ this._doUpdate(id, value, fixOptions)
455
409
  }
456
- }).finally(() => {
410
+ },
411
+ _doUpdate(id, value, options) {
412
+ const {
413
+ action,
414
+ success,
415
+ fail,
416
+ complete,
417
+ showToast,
418
+ toastTitle,
419
+ needConfirm,
420
+ needLoading,
421
+ loadingTitle
422
+ } = options
423
+
457
424
  if (needLoading) {
458
- uni.hideLoading()
425
+ uni.showLoading({
426
+ title: loadingTitle
427
+ })
428
+ }
429
+ /* eslint-disable no-undef */
430
+ let db = uniCloud.database(this.spaceInfo)
431
+ if (action) {
432
+ db = db.action(action)
459
433
  }
460
- complete && complete()
461
- })
462
- },
463
- getMainCollection () {
464
- if (typeof this.collection === 'string') {
465
- return this.collection.split(',')[0]
466
- }
467
- const mainQuery = JSON.parse(JSON.stringify(this.collection[0]))
468
- return mainQuery.$db[0].$param[0]
469
- },
470
- getTemp (isTemp = true) {
471
- /* eslint-disable no-undef */
472
- let db = uniCloud.database(this.spaceInfo)
473
-
474
- if (this.action) {
475
- db = db.action(this.action)
476
- }
477
-
478
- db = db.collection(...this.collectionArgs)
479
434
 
480
- if (this.foreignKey) {
481
- db = db.foreignKey(this.foreignKey)
482
- }
483
- if (!(!this.where || !Object.keys(this.where).length)) {
484
- db = db.where(this.where)
485
- }
486
- if (this.field) {
487
- db = db.field(this.field)
488
- }
489
- if (this.groupby) {
490
- db = db.groupBy(this.groupby)
491
- }
492
- if (this.groupField) {
493
- db = db.groupField(this.groupField)
494
- }
495
- if (this.distinct === true) {
496
- db = db.distinct()
497
- }
498
- if (this.orderby) {
499
- db = db.orderBy(this.orderby)
500
- }
435
+ db.collection(this.getMainCollection()).doc(id).update(value).then((res) => {
436
+ success && success(res)
437
+ if (showToast) {
438
+ uni.showToast({
439
+ title: toastTitle || t('uniCloud.component.update.success')
440
+ })
441
+ }
442
+ }).catch((err) => {
443
+ fail && fail(err)
444
+ if (needConfirm) {
445
+ uni.showModal({
446
+ content: err.message,
447
+ showCancel: false
448
+ })
449
+ }
450
+ }).finally(() => {
451
+ if (needLoading) {
452
+ uni.hideLoading()
453
+ }
454
+ complete && complete()
455
+ })
456
+ },
457
+ getMainCollection() {
458
+ if (typeof this.collection === 'string') {
459
+ return this.collection.split(',')[0]
460
+ }
461
+ const mainQuery = JSON.parse(JSON.stringify(this.collection[0]))
462
+ return mainQuery.$db[0].$param[0]
463
+ },
464
+ getTemp(isTemp = true) {
465
+ /* eslint-disable no-undef */
466
+ let db = uniCloud.database(this.spaceInfo)
467
+
468
+ if (this.action) {
469
+ db = db.action(this.action)
470
+ }
501
471
 
502
- const {
503
- current,
504
- size
505
- } = this.paginationInternal
506
- const getOptions = {}
507
- if (this.getcount) {
508
- getOptions.getCount = this.getcount
509
- }
510
- const treeOptions = {
511
- limitLevel: this.limitlevel,
512
- startWith: this.startwith
513
- }
514
- if (this.gettree) {
515
- getOptions.getTree = treeOptions
516
- }
517
- if (this.gettreepath) {
518
- getOptions.getTreePath = treeOptions
519
- }
520
- db = db.skip(size * (current - 1)).limit(size)
472
+ db = db.collection(...this.collectionArgs)
521
473
 
522
- if (isTemp) {
523
- db = db.getTemp(getOptions)
524
- db.udb = this
525
- } else {
526
- db = db.get(getOptions)
527
- }
474
+ if (this.foreignKey) {
475
+ db = db.foreignKey(this.foreignKey)
476
+ }
477
+ if (!(!this.where || !Object.keys(this.where).length)) {
478
+ db = db.where(this.where)
479
+ }
480
+ if (this.field) {
481
+ db = db.field(this.field)
482
+ }
483
+ if (this.groupby) {
484
+ db = db.groupBy(this.groupby)
485
+ }
486
+ if (this.groupField) {
487
+ db = db.groupField(this.groupField)
488
+ }
489
+ if (this.distinct === true) {
490
+ db = db.distinct()
491
+ }
492
+ if (this.orderby) {
493
+ db = db.orderBy(this.orderby)
494
+ }
528
495
 
529
- return db
530
- },
531
- setResult (result) {
532
- if (result.code === 0) {
533
- this._execLoadDataSuccess(result)
534
- } else {
535
- this._execLoadDataFail(new Error(result.message))
536
- }
537
- },
538
- _execLoadData (callback, clear) {
539
- if (this.loading) {
540
- return
541
- }
542
- this.loading = true
543
- this.errorMessage = ''
496
+ const {
497
+ current,
498
+ size
499
+ } = this.paginationInternal
500
+ const getOptions = {}
501
+ if (this.getcount) {
502
+ getOptions.getCount = this.getcount
503
+ }
504
+ const treeOptions = {
505
+ limitLevel: this.limitlevel,
506
+ startWith: this.startwith
507
+ }
508
+ if (this.gettree) {
509
+ getOptions.getTree = treeOptions
510
+ }
511
+ if (this.gettreepath) {
512
+ getOptions.getTreePath = treeOptions
513
+ }
514
+ db = db.skip(size * (current - 1)).limit(size)
544
515
 
545
- this._getExec().then((res) => {
546
- this.loading = false
547
- this._execLoadDataSuccess(res.result, callback, clear)
516
+ if (isTemp) {
517
+ db = db.getTemp(getOptions)
518
+ db.udb = this
519
+ } else {
520
+ db = db.get(getOptions)
521
+ }
548
522
 
549
- // #ifdef H5
550
- if (process.env.NODE_ENV === 'development') {
551
- this._debugDataList.length = 0
552
- const formatData = JSON.parse(JSON.stringify(this.dataList))
553
- if (Array.isArray(this.dataList)) {
554
- this._debugDataList.push(...formatData)
555
- } else {
556
- this._debugDataList.push(formatData)
557
- }
523
+ return db
524
+ },
525
+ setResult(result) {
526
+ if (result.code === 0) {
527
+ this._execLoadDataSuccess(result)
528
+ } else {
529
+ this._execLoadDataFail(new Error(result.message))
558
530
  }
559
- // #endif
560
- }).catch((err) => {
561
- this.loading = false
562
- this._execLoadDataFail(err, callback)
563
- })
564
- },
565
- _execLoadDataSuccess (result, callback, clear) {
566
- const {
567
- data,
568
- count
569
- } = result
570
- this._isEnded = count !== undefined ? (this.paginationInternal.current * this.paginationInternal.size >=
531
+ },
532
+ _execLoadData(callback, clear) {
533
+ if (this.loading) {
534
+ return
535
+ }
536
+ this.loading = true
537
+ this.errorMessage = ''
538
+
539
+ this._getExec().then((res) => {
540
+ this.loading = false
541
+ this._execLoadDataSuccess(res.result, callback, clear)
542
+
543
+ // #ifdef H5
544
+ if (process.env.NODE_ENV === 'development') {
545
+ this._debugDataList.length = 0
546
+ const formatData = JSON.parse(JSON.stringify(this.dataList))
547
+ if (Array.isArray(this.dataList)) {
548
+ this._debugDataList.push(...formatData)
549
+ } else {
550
+ this._debugDataList.push(formatData)
551
+ }
552
+ }
553
+ // #endif
554
+ }).catch((err) => {
555
+ this.loading = false
556
+ this._execLoadDataFail(err, callback)
557
+ })
558
+ },
559
+ _execLoadDataSuccess(result, callback, clear) {
560
+ const {
561
+ data,
562
+ count
563
+ } = result
564
+ this._isEnded = count !== undefined ? (this.paginationInternal.current * this.paginationInternal.size >=
571
565
  count) : (data.length < this.pageSize)
572
- this.hasMore = !this._isEnded
566
+ this.hasMore = !this._isEnded
573
567
 
574
- const data2 = this.getone ? (data.length ? data[0] : undefined) : data
568
+ const data2 = this.getone ? (data.length ? data[0] : undefined) : data
575
569
 
576
- if (this.getcount) {
577
- this.paginationInternal.count = count
578
- }
570
+ if (this.getcount) {
571
+ this.paginationInternal.count = count
572
+ }
579
573
 
580
- callback && callback(data2, this._isEnded, this.paginationInternal)
581
- this._dispatchEvent(events.load, data2)
574
+ callback && callback(data2, this._isEnded, this.paginationInternal)
575
+ this._dispatchEvent(events.load, data2)
582
576
 
583
- if (this.getone || this.pageData === pageMode.replace) {
584
- this.dataList = data2
585
- } else {
586
- if (clear) {
577
+ if (this.getone || this.pageData === pageMode.replace) {
587
578
  this.dataList = data2
588
579
  } else {
589
- this.dataList.push(...data2)
580
+ if (clear) {
581
+ this.dataList = data2
582
+ } else {
583
+ this.dataList.push(...data2)
584
+ }
585
+ }
586
+ },
587
+ _execLoadDataFail(err, callback) {
588
+ this.errorMessage = err
589
+ callback && callback()
590
+ this.$emit(events.error, err)
591
+ if (process.env.NODE_ENV === 'development') {
592
+ console.error(err)
593
+ }
594
+ },
595
+ _getExec() {
596
+ return this.getTemp(false)
597
+ },
598
+ _execRemove(id, action, success, fail, complete, needConfirm, needLoading, loadingTitle) {
599
+ if (!this.collection || !id) {
600
+ return
590
601
  }
591
- }
592
- },
593
- _execLoadDataFail (err, callback) {
594
- this.errorMessage = err
595
- callback && callback()
596
- this.$emit(events.error, err)
597
- if (process.env.NODE_ENV === 'development') {
598
- console.error(err)
599
- }
600
- },
601
- _getExec () {
602
- return this.getTemp(false)
603
- },
604
- _execRemove (id, action, success, fail, complete, needConfirm, needLoading, loadingTitle) {
605
- if (!this.collection || !id) {
606
- return
607
- }
608
-
609
- const ids = Array.isArray(id) ? id : [id]
610
- if (!ids.length) {
611
- return
612
- }
613
602
 
614
- if (needLoading) {
615
- uni.showLoading({
616
- mask: true,
617
- title: loadingTitle
618
- })
619
- }
603
+ const ids = Array.isArray(id) ? id : [id]
604
+ if (!ids.length) {
605
+ return
606
+ }
620
607
 
621
- /* eslint-disable no-undef */
622
- const db = uniCloud.database(this.spaceInfo)
623
- const dbCmd = db.command
608
+ if (needLoading) {
609
+ uni.showLoading({
610
+ mask: true,
611
+ title: loadingTitle
612
+ })
613
+ }
624
614
 
625
- let exec = db
626
- if (action) {
627
- exec = exec.action(action)
628
- }
615
+ /* eslint-disable no-undef */
616
+ const db = uniCloud.database(this.spaceInfo)
617
+ const dbCmd = db.command
629
618
 
630
- exec.collection(this.getMainCollection()).where({
631
- _id: dbCmd.in(ids)
632
- }).remove().then((res) => {
633
- success && success(res.result)
634
- if (this.pageData === pageMode.replace) {
635
- this.refresh()
636
- } else {
637
- this.removeData(ids)
638
- }
639
- }).catch((err) => {
640
- fail && fail(err)
641
- if (needConfirm) {
642
- uni.showModal({
643
- content: err.message,
644
- showCancel: false
645
- })
619
+ let exec = db
620
+ if (action) {
621
+ exec = exec.action(action)
646
622
  }
647
- }).finally(() => {
648
- if (needLoading) {
649
- uni.hideLoading()
623
+
624
+ exec.collection(this.getMainCollection()).where({
625
+ _id: dbCmd.in(ids)
626
+ }).remove().then((res) => {
627
+ success && success(res.result)
628
+ if (this.pageData === pageMode.replace) {
629
+ this.refresh()
630
+ } else {
631
+ this.removeData(ids)
632
+ }
633
+ }).catch((err) => {
634
+ fail && fail(err)
635
+ if (needConfirm) {
636
+ uni.showModal({
637
+ content: err.message,
638
+ showCancel: false
639
+ })
640
+ }
641
+ }).finally(() => {
642
+ if (needLoading) {
643
+ uni.hideLoading()
644
+ }
645
+ complete && complete()
646
+ })
647
+ },
648
+ removeData(ids) {
649
+ const il = ids.slice(0)
650
+ const dl = this.dataList
651
+ for (let i = dl.length - 1; i >= 0; i--) {
652
+ const index = il.indexOf(dl[i]._id)
653
+ if (index >= 0) {
654
+ dl.splice(i, 1)
655
+ il.splice(index, 1)
656
+ }
650
657
  }
651
- complete && complete()
652
- })
653
- },
654
- removeData (ids) {
655
- const il = ids.slice(0)
656
- const dl = this.dataList
657
- for (let i = dl.length - 1; i >= 0; i--) {
658
- const index = il.indexOf(dl[i]._id)
659
- if (index >= 0) {
660
- dl.splice(i, 1)
661
- il.splice(index, 1)
658
+ },
659
+ _dispatchEvent(type, data) {
660
+ if (this._changeDataFunction) {
661
+ this._changeDataFunction(data, this._isEnded, this.paginationInternal)
662
+ } else {
663
+ this.$emit(type, data, this._isEnded, this.paginationInternal)
662
664
  }
663
665
  }
664
- },
665
- _dispatchEvent (type, data) {
666
- if (this._changeDataFunction) {
667
- this._changeDataFunction(data, this._isEnded, this.paginationInternal)
668
- } else {
669
- this.$emit(type, data, this._isEnded, this.paginationInternal)
670
- }
671
666
  }
672
667
  }
673
- }
674
668
  </script>
package/lib/platform.js CHANGED
@@ -1,5 +1,8 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
+ const {
4
+ getManifestJson
5
+ } = require('./manifest')
3
6
 
4
7
  const {
5
8
  isInHBuilderX,
@@ -17,10 +20,12 @@ function getShadowCss () {
17
20
  if (process.env.UNI_PLATFORM === 'h5') {
18
21
  tagName = 'body'
19
22
  }
20
- const cdn = getShadowCdn()
21
- return `${tagName}::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(${cdn}/img/shadow-grey.png)}100%{background-image:url(${cdn}/img/shadow-grey.png)}}@keyframes shadow-preload{0%{background-image:url(${cdn}/img/shadow-grey.png)}100%{background-image:url(${cdn}/img/shadow-grey.png)}}`
23
+ const url = createShadowImageUrl(getShadowCdn(), 'grey')
24
+ return `${tagName}::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(${url})}100%{background-image:url(${url})}}@keyframes shadow-preload{0%{background-image:url(${url})}100%{background-image:url(${url})}}`
22
25
  }
23
26
  const cdns = {
27
+ h5: '',
28
+ web: '',
24
29
  'mp-weixin': 1,
25
30
  'mp-alipay': 2,
26
31
  'mp-baidu': 3,
@@ -37,8 +42,31 @@ const cdns = {
37
42
  }
38
43
 
39
44
  function getShadowCdn () {
40
- const index = cdns[process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM] || ''
41
- return `https://cdn${index}.dcloud.net.cn`
45
+ return cdns[process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM] || ''
46
+ }
47
+
48
+ let appid
49
+
50
+ function createIdent () {
51
+ if (process.env.UNI_INPUT_DIR) {
52
+ if (typeof appid === 'undefined') {
53
+ appid = getManifestJson().appid || ''
54
+ }
55
+ const id = appid.replace('__UNI__', '')
56
+ if (id) {
57
+ return Buffer.from(Buffer.from(id).toString('base64')).toString('hex')
58
+ }
59
+ }
60
+ return ''
61
+ }
62
+
63
+ function createShadowImageUrl (cdn, type = 'grey') {
64
+ let identStr = ''
65
+ if (process.env.UNI_PLATFORM !== 'h5' && process.env.UNI_PLATFORM !== 'web') {
66
+ const ident = createIdent()
67
+ identStr = ident ? `${ident}/` : ''
68
+ }
69
+ return `https://cdn${cdn || ''}.dcloud.net.cn/${identStr}img/shadow-${type}.png`
42
70
  }
43
71
 
44
72
  // 解决 vue-cli-service lint 时 UNI_PLATFORM 不存在
@@ -145,6 +173,7 @@ module.exports = {
145
173
  discardDuplicates: false // 条件编译会导致重复
146
174
  }
147
175
  },
176
+ createShadowImageUrl,
148
177
  getShadowCss,
149
178
  getShadowTemplate (colorType = 'grey') {
150
179
  let tagName = 'cover-image'
@@ -152,7 +181,7 @@ module.exports = {
152
181
  .UNI_PLATFORM === 'mp-xhs') {
153
182
  tagName = 'image'
154
183
  }
155
- return `<${tagName} src="${getShadowCdn()}/img/shadow-${colorType}.png" style="z-index:998;position:fixed;left:0;top:0;width:100%;height:3px;"/>`
184
+ return `<${tagName} src="${createShadowImageUrl(getShadowCdn(), colorType)}" style="z-index:998;position:fixed;left:0;top:0;width:100%;height:3px;"/>`
156
185
  },
157
186
  getPlatformScss () {
158
187
  return SCSS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.2-4020420240722002",
3
+ "version": "2.0.2-4020420240722004",
4
4
  "description": "uni-cli-shared",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -26,5 +26,5 @@
26
26
  "postcss-urlrewrite": "^0.2.2",
27
27
  "strip-json-comments": "^2.0.1"
28
28
  },
29
- "gitHead": "cbb0057bc5a5b43e783409da539add44dd703d16"
29
+ "gitHead": "2d3e029c00dc153d1f9b01b3cf4e697470e01087"
30
30
  }