diff --git a/packages/uni-cli-shared/components/unicloud-db.vue b/packages/uni-cli-shared/components/unicloud-db.vue index 8bb95c8394b91363a3a596da5a8355b0009e579e..24c3250a7a7717ad5ef41d2f1d492e4694b78c08 100644 --- a/packages/uni-cli-shared/components/unicloud-db.vue +++ b/packages/uni-cli-shared/components/unicloud-db.vue @@ -88,6 +88,10 @@ export default { type: [Boolean, String], default: false }, + gettreepath: { + type: [Boolean, String], + default: false + }, startwith: { type: String, default: '' @@ -96,10 +100,6 @@ export default { type: Number, default: 10 }, - manual: { - type: Boolean, - default: false - }, groupby: { type: String, default: '' @@ -111,6 +111,10 @@ export default { distinct: { type: [Boolean, String], default: false + }, + manual: { + type: Boolean, + default: false } }, data () { @@ -118,16 +122,17 @@ export default { loading: false, hasMore: false, dataList: this.getone ? undefined : [], - paginationInternal: { - current: this.pageCurrent, - size: this.pageSize, - count: 0 - }, + paginationInternal: {}, errorMessage: '' } }, created () { this._isEnded = false + this.paginationInternal = { + current: this.pageCurrent, + size: this.pageSize, + count: 0 + } this.$watch(() => { var al = [] @@ -217,9 +222,14 @@ export default { methods: { loadData (args1, args2) { let callback = null + let clear = false if (typeof args1 === 'object') { if (args1.clear) { - this.clear() + if (this.pageData === pageMode.replace) { + this.clear() + } else { + clear = args1.clear + } this.reset() } if (args1.current !== undefined) { @@ -232,7 +242,7 @@ export default { callback = args1 } - this._execLoadData(callback) + this._execLoadData(callback, clear) }, loadMore () { if (this._isEnded) { @@ -252,6 +262,8 @@ export default { this.paginationInternal.current = 1 }, add (value, { + action, + showToast = true, toastTitle, success, fail, @@ -259,12 +271,18 @@ export default { } = {}) { uni.showLoading() /* eslint-disable no-undef */ - const db = uniCloud.database() + let db = uniCloud.database() + if (action) { + db = db.action(action) + } + db.collection(this.collection).add(value).then((res) => { success && success(res) - uni.showToast({ - title: toastTitle || '新增成功' - }) + if (showToast) { + uni.showToast({ + title: toastTitle || '新增成功' + }) + } }).catch((err) => { fail && fail(err) uni.showModal({ @@ -300,6 +318,8 @@ export default { }) }, update (id, value, { + action, + showToast = true, toastTitle, success, fail, @@ -307,12 +327,18 @@ export default { } = {}) { uni.showLoading() /* eslint-disable no-undef */ - const db = uniCloud.database() + let db = uniCloud.database() + if (action) { + db = db.action(action) + } + return db.collection(this.collection).doc(id).update(value).then((res) => { success && success(res) - uni.showToast({ - title: toastTitle || '修改成功' - }) + if (showToast) { + uni.showToast({ + title: toastTitle || '修改成功' + }) + } }).catch((err) => { fail && fail(err) uni.showModal({ @@ -324,7 +350,7 @@ export default { complete && complete() }) }, - _execLoadData (callback) { + _execLoadData (callback, clear) { if (this.loading) { return } @@ -348,7 +374,11 @@ export default { if (this.getone || this.pageData === pageMode.replace) { this.dataList = data2 } else { - this.dataList.push(...data2) + if (clear) { + this.dataList = data2 + } else { + this.dataList.push(...data2) + } if (this.dataList.length) { this.paginationInternal.current++ } @@ -396,7 +426,7 @@ export default { db = db.field(this.field) } if (this.groupby) { - db = db.groupby(this.groupby) + db = db.groupBy(this.groupby) } if (this.groupField) { db = db.groupField(this.groupField) @@ -416,11 +446,15 @@ export default { if (this.getcount) { getOptions.getCount = this.getcount } + const treeOptions = { + limitLevel: this.limitlevel, + startWith: this.startwith + } if (this.gettree) { - getOptions.getTree = { - limitLevel: this.limitlevel, - startWith: this.startwith - } + getOptions.getTree = treeOptions + } + if (this.gettreepath) { + getOptions.getTreePath = treeOptions } db = db.skip(size * (current - 1)).limit(size).get(getOptions)