@dcloudio/uni-components 0.0.1-nvue3.3030820220125001

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.
Files changed (43) hide show
  1. package/LICENSE +202 -0
  2. package/index.js +0 -0
  3. package/lib/custom-tab-bar/custom-tab-bar.vue +126 -0
  4. package/lib/navigation-bar/navigation-bar.vue +159 -0
  5. package/lib/page-meta/page-meta.vue +205 -0
  6. package/lib/page-meta-head/page-meta-head.vue +10 -0
  7. package/lib/uni-match-media/uni-match-media.vue +73 -0
  8. package/lib/unicloud-db/i18n/en.json +6 -0
  9. package/lib/unicloud-db/i18n/es.json +6 -0
  10. package/lib/unicloud-db/i18n/fr.json +6 -0
  11. package/lib/unicloud-db/i18n/index.js +12 -0
  12. package/lib/unicloud-db/i18n/zh-Hans.json +6 -0
  13. package/lib/unicloud-db/i18n/zh-Hant.json +6 -0
  14. package/lib/unicloud-db/unicloud-db.vue +626 -0
  15. package/package.json +24 -0
  16. package/style/button.css +264 -0
  17. package/style/canvas.css +14 -0
  18. package/style/checkbox-group.css +7 -0
  19. package/style/checkbox.css +56 -0
  20. package/style/editor.css +393 -0
  21. package/style/form.css +0 -0
  22. package/style/icon.css +9 -0
  23. package/style/image.css +33 -0
  24. package/style/input.css +87 -0
  25. package/style/label.css +3 -0
  26. package/style/movable-area.css +10 -0
  27. package/style/movable-view.css +13 -0
  28. package/style/navigator.css +45 -0
  29. package/style/picker-view-column.css +99 -0
  30. package/style/picker-view.css +14 -0
  31. package/style/progress.css +25 -0
  32. package/style/radio-group.css +6 -0
  33. package/style/radio.css +53 -0
  34. package/style/resize-sensor.css +33 -0
  35. package/style/rich-text.css +0 -0
  36. package/style/scroll-view.css +90 -0
  37. package/style/slider.css +89 -0
  38. package/style/swiper-item.css +13 -0
  39. package/style/swiper.css +85 -0
  40. package/style/switch.css +111 -0
  41. package/style/text.css +8 -0
  42. package/style/textarea.css +79 -0
  43. package/style/view.css +6 -0
@@ -0,0 +1,626 @@
1
+ <template>
2
+ <view>
3
+ <slot
4
+ :options="options"
5
+ :data="dataList"
6
+ :pagination="paginationInternal"
7
+ :loading="loading"
8
+ :hasMore="hasMore"
9
+ :error="errorMessage"
10
+ />
11
+ </view>
12
+ </template>
13
+
14
+ <script>
15
+ import { onMounted, getCurrentInstance } from 'vue'
16
+ import { ssrRef, shallowSsrRef } from '@dcloudio/uni-app'
17
+ import { initVueI18n } from '@dcloudio/uni-i18n'
18
+ import messages from './i18n/index'
19
+
20
+ const { t } = initVueI18n(messages)
21
+
22
+ const events = {
23
+ load: 'load',
24
+ error: 'error'
25
+ }
26
+ const pageMode = {
27
+ add: 'add',
28
+ replace: 'replace'
29
+ }
30
+ const loadMode = {
31
+ auto: 'auto',
32
+ onready: 'onready',
33
+ manual: 'manual'
34
+ }
35
+
36
+ const attrs = [
37
+ 'pageCurrent',
38
+ 'pageSize',
39
+ 'collection',
40
+ 'action',
41
+ 'field',
42
+ 'getcount',
43
+ 'orderby',
44
+ 'where',
45
+ 'groupby',
46
+ 'groupField',
47
+ 'distinct'
48
+ ]
49
+
50
+ export default {
51
+ name: 'UniClouddb',
52
+ // #ifdef VUE3
53
+ setup(props) {
54
+ // 单条记录时,使用shallowRef(仅支持赋值修改),列表时,采用ref(支持push等修改)
55
+ const dataListRef = props.getone ? shallowSsrRef(undefined) : ssrRef([])
56
+ const instance = getCurrentInstance()
57
+ onMounted(() => {
58
+ // client端判断是否需要再次请求数据(正常情况下,SSR返回的html中已包含此数据状态,无需再次额外请求)
59
+ if ((!dataListRef.value || dataListRef.value.length === 0) && !props.manual && props.loadtime === loadMode.auto) {
60
+ instance.proxy.loadData()
61
+ }
62
+ })
63
+ return { dataList: dataListRef }
64
+ },
65
+ // 服务端serverPrefetch生命周期,用于服务端加载数据,等将来全端支持Suspense时,可以采用 Suspense + async setup 来实现一版
66
+ async serverPrefetch() {
67
+ if (!this.manual && this.loadtime === loadMode.auto) {
68
+ return this.loadData()
69
+ }
70
+ },
71
+ // #endif
72
+ props: {
73
+ options: {
74
+ type: [Object, Array],
75
+ default() {
76
+ return {}
77
+ }
78
+ },
79
+ spaceInfo: {
80
+ type: Object,
81
+ default() {
82
+ return {}
83
+ }
84
+ },
85
+ collection: {
86
+ type: [String, Array],
87
+ default: ''
88
+ },
89
+ action: {
90
+ type: String,
91
+ default: ''
92
+ },
93
+ field: {
94
+ type: String,
95
+ default: ''
96
+ },
97
+ orderby: {
98
+ type: String,
99
+ default: ''
100
+ },
101
+ where: {
102
+ type: [String, Object],
103
+ default: ''
104
+ },
105
+ pageData: {
106
+ type: String,
107
+ default: 'add'
108
+ },
109
+ pageCurrent: {
110
+ type: Number,
111
+ default: 1
112
+ },
113
+ pageSize: {
114
+ type: Number,
115
+ default: 20
116
+ },
117
+ getcount: {
118
+ type: [Boolean, String],
119
+ default: false
120
+ },
121
+ getone: {
122
+ type: [Boolean, String],
123
+ default: false
124
+ },
125
+ gettree: {
126
+ type: [Boolean, String, Object],
127
+ default: false
128
+ },
129
+ gettreepath: {
130
+ type: [Boolean, String],
131
+ default: false
132
+ },
133
+ startwith: {
134
+ type: String,
135
+ default: ''
136
+ },
137
+ limitlevel: {
138
+ type: Number,
139
+ default: 10
140
+ },
141
+ groupby: {
142
+ type: String,
143
+ default: ''
144
+ },
145
+ groupField: {
146
+ type: String,
147
+ default: ''
148
+ },
149
+ distinct: {
150
+ type: [Boolean, String],
151
+ default: false
152
+ },
153
+ pageIndistinct: {
154
+ type: [Boolean, String],
155
+ default: false
156
+ },
157
+ foreignKey: {
158
+ type: String,
159
+ default: ''
160
+ },
161
+ loadtime: {
162
+ type: String,
163
+ default: 'auto'
164
+ },
165
+ manual: {
166
+ type: Boolean,
167
+ default: false
168
+ }
169
+ },
170
+ data() {
171
+ return {
172
+ loading: false,
173
+ hasMore: false,
174
+ // #ifndef VUE3
175
+ dataList: [],
176
+ // #endif
177
+ paginationInternal: {},
178
+ errorMessage: ''
179
+ }
180
+ },
181
+ computed: {
182
+ collectionArgs () {
183
+ return Array.isArray(this.collection) ? this.collection : [this.collection]
184
+ },
185
+ isLookup () {
186
+ return (Array.isArray(this.collection) && this.collection.length > 1) || (typeof this.collection === 'string' && this.collection.indexOf(',') > -1)
187
+ },
188
+ mainCollection () {
189
+ if (typeof this.collection === 'string') {
190
+ return this.collection.split(',')[0]
191
+ }
192
+ const mainQuery = JSON.parse(JSON.stringify(this.collection[0]))
193
+ return mainQuery.$db[0].$param[0]
194
+ }
195
+ },
196
+ created() {
197
+ this._isEnded = false
198
+ this.paginationInternal = {
199
+ current: this.pageCurrent,
200
+ size: this.pageSize,
201
+ count: 0
202
+ }
203
+ // #ifndef VUE3
204
+ if (this.getone) {
205
+ this.dataList = undefined
206
+ }
207
+ // #endif
208
+
209
+ this.$watch(() => {
210
+ var al = []
211
+ attrs.forEach(key => {
212
+ al.push(this[key])
213
+ })
214
+ return al
215
+ }, (newValue, oldValue) => {
216
+ this.paginationInternal.size = this.pageSize
217
+ if (newValue[0] !== oldValue[0]) {
218
+ this.paginationInternal.current = this.pageCurrent
219
+ }
220
+ if (this.loadtime === loadMode.manual) {
221
+ return
222
+ }
223
+
224
+ let needReset = false
225
+ for (let i = 2; i < newValue.length; i++) {
226
+ if (newValue[i] !== oldValue[i]) {
227
+ needReset = true
228
+ break
229
+ }
230
+ }
231
+ if (needReset) {
232
+ this.clear()
233
+ this.reset()
234
+ }
235
+
236
+ this._execLoadData()
237
+ })
238
+
239
+ // #ifdef MP-TOUTIAO
240
+ let changeName
241
+ const events = this.$scope.dataset.eventOpts || []
242
+ for (var i = 0; i < events.length; i++) {
243
+ const event = events[i]
244
+ if (event[0].includes('^load')) {
245
+ changeName = event[1][0][0]
246
+ }
247
+ }
248
+ if (changeName) {
249
+ let parent = this.$parent
250
+ let maxDepth = 16
251
+ this._changeDataFunction = null
252
+ while (parent && maxDepth > 0) {
253
+ const fun = parent[changeName]
254
+ if (fun && typeof fun === 'function') {
255
+ this._changeDataFunction = fun
256
+ maxDepth = 0
257
+ break
258
+ }
259
+ parent = parent.$parent
260
+ maxDepth--
261
+ }
262
+ }
263
+ // #endif
264
+
265
+ },
266
+ // #ifndef VUE3
267
+ mounted() {
268
+ if (!this.manual && this.loadtime === loadMode.auto) {
269
+ this.loadData()
270
+ }
271
+ },
272
+ // #endif
273
+ methods: {
274
+ loadData(args1, args2) {
275
+ let callback = null
276
+ let clear = false
277
+ if (typeof args1 === 'object') {
278
+ if (args1.clear) {
279
+ if (this.pageData === pageMode.replace) {
280
+ this.clear()
281
+ } else {
282
+ clear = args1.clear
283
+ }
284
+ this.reset()
285
+ }
286
+ if (args1.current !== undefined) {
287
+ this.paginationInternal.current = args1.current
288
+ }
289
+ if (typeof args2 === 'function') {
290
+ callback = args2
291
+ }
292
+ } else if (typeof args1 === 'function') {
293
+ callback = args1
294
+ }
295
+
296
+ return this._execLoadData(callback, clear)
297
+ },
298
+ loadMore() {
299
+ if (this._isEnded || this.loading) {
300
+ return
301
+ }
302
+
303
+ if (this.pageData === pageMode.add) {
304
+ this.paginationInternal.current++
305
+ }
306
+
307
+ this._execLoadData()
308
+ },
309
+ refresh() {
310
+ this.clear()
311
+ this._execLoadData()
312
+ },
313
+ clear() {
314
+ this._isEnded = false
315
+ this.dataList = []
316
+ },
317
+ reset() {
318
+ this.paginationInternal.current = 1
319
+ },
320
+ add(value, {
321
+ action,
322
+ showToast = true,
323
+ toastTitle,
324
+ success,
325
+ fail,
326
+ complete,
327
+ needConfirm = true,
328
+ needLoading = true,
329
+ loadingTitle = ''
330
+ } = {}) {
331
+ if (needLoading) {
332
+ uni.showLoading({
333
+ title: loadingTitle
334
+ })
335
+ }
336
+ /* eslint-disable no-undef */
337
+ let db = uniCloud.database(this.spaceInfo)
338
+ if (action) {
339
+ db = db.action(action)
340
+ }
341
+
342
+ db.collection(this.mainCollection).add(value).then((res) => {
343
+ success && success(res)
344
+ if (showToast) {
345
+ uni.showToast({
346
+ title: toastTitle || t('uniCloud.component.add.success')
347
+ })
348
+ }
349
+ }).catch((err) => {
350
+ fail && fail(err)
351
+ if (needConfirm) {
352
+ uni.showModal({
353
+ content: err.message,
354
+ showCancel: false
355
+ })
356
+ }
357
+ }).finally(() => {
358
+ if (needLoading) {
359
+ uni.hideLoading()
360
+ }
361
+ complete && complete()
362
+ })
363
+ },
364
+ remove(id, {
365
+ action,
366
+ success,
367
+ fail,
368
+ complete,
369
+ confirmTitle,
370
+ confirmContent,
371
+ needConfirm = true,
372
+ needLoading = true,
373
+ loadingTitle = ''
374
+ } = {}) {
375
+ if (!id || !id.length) {
376
+ return
377
+ }
378
+ if (!needConfirm) {
379
+ this._execRemove(id, action, success, fail, complete, needConfirm, needLoading, loadingTitle)
380
+ return
381
+ }
382
+ uni.showModal({
383
+ title: confirmTitle || t('uniCloud.component.remove.showModal.title'),
384
+ content: confirmContent || t('uniCloud.component.remove.showModal.content'),
385
+ showCancel: true,
386
+ success: (res) => {
387
+ if (!res.confirm) {
388
+ return
389
+ }
390
+ this._execRemove(id, action, success, fail, complete, needConfirm, needLoading, loadingTitle)
391
+ }
392
+ })
393
+ },
394
+ update(id, value, {
395
+ action,
396
+ showToast = true,
397
+ toastTitle,
398
+ success,
399
+ fail,
400
+ complete,
401
+ needConfirm = true,
402
+ needLoading = true,
403
+ loadingTitle = ''
404
+ } = {}) {
405
+ if (needLoading) {
406
+ uni.showLoading({
407
+ title: loadingTitle
408
+ })
409
+ }
410
+ let db = uniCloud.database(this.spaceInfo)
411
+ if (action) {
412
+ db = db.action(action)
413
+ }
414
+
415
+ return db.collection(this.mainCollection).doc(id).update(value).then((res) => {
416
+ success && success(res)
417
+ if (showToast) {
418
+ uni.showToast({
419
+ title: toastTitle || t('uniCloud.component.update.success')
420
+ })
421
+ }
422
+ }).catch((err) => {
423
+ fail && fail(err)
424
+ if (needConfirm) {
425
+ uni.showModal({
426
+ content: err.message,
427
+ showCancel: false
428
+ })
429
+ }
430
+ }).finally(() => {
431
+ if (needLoading) {
432
+ uni.hideLoading()
433
+ }
434
+ complete && complete()
435
+ })
436
+ },
437
+ getTemp(isTemp = true) {
438
+ let db = uniCloud.database(this.spaceInfo)
439
+
440
+ if (this.action) {
441
+ db = db.action(this.action)
442
+ }
443
+
444
+ db = db.collection(...this.collectionArgs)
445
+
446
+ if (!(!this.where || !Object.keys(this.where).length)) {
447
+ db = db.where(this.where)
448
+ }
449
+ if (this.field) {
450
+ db = db.field(this.field)
451
+ }
452
+ if (this.foreignKey) {
453
+ db = db.foreignKey(this.foreignKey)
454
+ }
455
+ if (this.groupby) {
456
+ db = db.groupBy(this.groupby)
457
+ }
458
+ if (this.groupField) {
459
+ db = db.groupField(this.groupField)
460
+ }
461
+ if (this.distinct === true) {
462
+ db = db.distinct()
463
+ }
464
+ if (this.orderby) {
465
+ db = db.orderBy(this.orderby)
466
+ }
467
+
468
+ const {
469
+ current,
470
+ size
471
+ } = this.paginationInternal
472
+ const getOptions = {}
473
+ if (this.getcount) {
474
+ getOptions.getCount = this.getcount
475
+ }
476
+ const treeOptions = {
477
+ limitLevel: this.limitlevel,
478
+ startWith: this.startwith
479
+ }
480
+ if (this.gettree) {
481
+ getOptions.getTree = treeOptions
482
+ }
483
+ if (this.gettreepath) {
484
+ getOptions.getTreePath = treeOptions
485
+ }
486
+ db = db.skip(size * (current - 1)).limit(size)
487
+
488
+ if (isTemp) {
489
+ db = db.getTemp(getOptions)
490
+ db.udb = this
491
+ } else {
492
+ db = db.get(getOptions)
493
+ }
494
+
495
+ return db
496
+ },
497
+ setResult(result) {
498
+ if (result.code === 0) {
499
+ this._execLoadDataSuccess(result)
500
+ } else {
501
+ this._execLoadDataFail(new Error(result.message))
502
+ }
503
+ },
504
+ _execLoadData(callback, clear) {
505
+ if (this.loading) {
506
+ return
507
+ }
508
+ this.loading = true
509
+ this.errorMessage = ''
510
+
511
+ return this._getExec().then((res) => {
512
+ this.loading = false
513
+ this._execLoadDataSuccess(res.result, callback, clear)
514
+ }).catch((err) => {
515
+ this.loading = false
516
+ this._execLoadDataFail(err, callback)
517
+ })
518
+ },
519
+ _execLoadDataSuccess(result, callback, clear) {
520
+ const {
521
+ data,
522
+ count
523
+ } = result
524
+ this._isEnded = count !== undefined ? (this.paginationInternal.current * this.paginationInternal.size >= count) : (data.length < this.pageSize)
525
+ this.hasMore = !this._isEnded
526
+
527
+ const data2 = this.getone ? (data.length ? data[0] : undefined) : data
528
+
529
+ if (this.getcount) {
530
+ this.paginationInternal.count = count
531
+ }
532
+
533
+ callback && callback(data2, this._isEnded, this.paginationInternal)
534
+ this._dispatchEvent(events.load, data2)
535
+
536
+ if (this.getone || this.pageData === pageMode.replace) {
537
+ this.dataList = data2
538
+ } else {
539
+ if (clear) {
540
+ this.dataList = data2
541
+ } else {
542
+ this.dataList.push(...data2)
543
+ }
544
+ }
545
+ },
546
+ _execLoadDataFail(err, callback) {
547
+ this.errorMessage = err
548
+ callback && callback()
549
+ this.$emit(events.error, err)
550
+ if (process.env.NODE_ENV === 'development') {
551
+ console.error(err)
552
+ }
553
+ },
554
+ _getExec() {
555
+ return this.getTemp(false)
556
+ },
557
+ _execRemove(id, action, success, fail, complete, needConfirm, needLoading, loadingTitle) {
558
+ if (!this.collection || !id) {
559
+ return
560
+ }
561
+
562
+ const ids = Array.isArray(id) ? id : [id]
563
+ if (!ids.length) {
564
+ return
565
+ }
566
+
567
+ if (needLoading) {
568
+ uni.showLoading({
569
+ mask: true,
570
+ title: loadingTitle
571
+ })
572
+ }
573
+
574
+ const db = uniCloud.database(this.spaceInfo)
575
+ const dbCmd = db.command
576
+
577
+ let exec = db
578
+ if (action) {
579
+ exec = exec.action(action)
580
+ }
581
+
582
+ exec.collection(this.mainCollection).where({
583
+ _id: dbCmd.in(ids)
584
+ }).remove().then((res) => {
585
+ success && success(res.result)
586
+ if (this.pageData === pageMode.replace) {
587
+ this.refresh()
588
+ } else {
589
+ this.removeData(ids)
590
+ }
591
+ }).catch((err) => {
592
+ fail && fail(err)
593
+ if (needConfirm) {
594
+ uni.showModal({
595
+ content: err.message,
596
+ showCancel: false
597
+ })
598
+ }
599
+ }).finally(() => {
600
+ if (needLoading) {
601
+ uni.hideLoading()
602
+ }
603
+ complete && complete()
604
+ })
605
+ },
606
+ removeData(ids) {
607
+ const il = ids.slice(0)
608
+ const dl = this.dataList
609
+ for (let i = dl.length - 1; i >= 0; i--) {
610
+ const index = il.indexOf(dl[i]._id)
611
+ if (index >= 0) {
612
+ dl.splice(i, 1)
613
+ il.splice(index, 1)
614
+ }
615
+ }
616
+ },
617
+ _dispatchEvent(type, data) {
618
+ if (this._changeDataFunction) {
619
+ this._changeDataFunction(data, this._isEnded, this.paginationInternal)
620
+ } else {
621
+ this.$emit(type, data, this._isEnded, this.paginationInternal)
622
+ }
623
+ }
624
+ }
625
+ }
626
+ </script>
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@dcloudio/uni-components",
3
+ "version": "0.0.1-nvue3.3030820220125001",
4
+ "description": "@dcloudio/uni-components",
5
+ "main": "index.js",
6
+ "files": [
7
+ "style",
8
+ "lib"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/dcloudio/uni-app.git",
13
+ "directory": "packages/uni-components"
14
+ },
15
+ "license": "Apache-2.0",
16
+ "bugs": {
17
+ "url": "https://github.com/dcloudio/uni-app/issues"
18
+ },
19
+ "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
20
+ "devDependencies": {
21
+ "@dcloudio/uni-shared": "0.0.1-nvue3.3030820220125001",
22
+ "@types/quill": "^1.3.7"
23
+ }
24
+ }