diff --git a/packages/uni-cli-shared/components/unicloud-db.vue b/packages/uni-cli-shared/components/unicloud-db.vue index 1058d22722504a8eaa3b5d9f42dadec620e403d2..c65d802ea50777b2ccf24a10a4ad18fe3df5f4d9 100644 --- a/packages/uni-cli-shared/components/unicloud-db.vue +++ b/packages/uni-cli-shared/components/unicloud-db.vue @@ -55,7 +55,7 @@ export default { } }, collection: { - type: String, + type: [String, Array], default: '' }, action: { @@ -148,6 +148,21 @@ export default { errorMessage: '' } }, + computed: { + collectionArgs () { + return Array.isArray(this.collection) ? this.collection : [this.collection] + }, + isLookup () { + return (Array.isArray(this.collection) && this.collection.length > 1) || (typeof this.collection === 'string' && this.collection.indexOf(',') > -1) + }, + mainCollection () { + if (typeof this.collection === 'string') { + return this.collection.split(',')[0] + } + const mainQuery = JSON.parse(JSON.stringify(this.collection[0])) + return mainQuery.$db[0].$param[0] + } + }, created () { this._isEnded = false this.paginationInternal = { @@ -314,7 +329,7 @@ export default { db = db.action(action) } - db.collection(this._getCollection()).add(value).then((res) => { + db.collection(this.mainCollection).add(value).then((res) => { success && success(res) if (showToast) { uni.showToast({ @@ -388,7 +403,7 @@ export default { db = db.action(action) } - return db.collection(this._getCollection()).doc(id).update(value).then((res) => { + return db.collection(this.mainCollection).doc(id).update(value).then((res) => { success && success(res) if (showToast) { uni.showToast({ @@ -418,7 +433,7 @@ export default { db = db.action(this.action) } - db = db.collection(this.collection) + db = db.collection(...this.collectionArgs) if (!(!this.where || !Object.keys(this.where).length)) { db = db.where(this.where) @@ -569,7 +584,7 @@ export default { exec = exec.action(action) } - exec.collection(this._getCollection()).where({ + exec.collection(this.mainCollection).where({ _id: dbCmd.in(ids) }).remove().then((res) => { success && success(res.result) @@ -593,11 +608,6 @@ export default { complete && complete() }) }, - _getCollection () { - const index = this.collection.indexOf(',') - const collection = index > 0 ? this.collection.substring(0, index) : this.collection - return collection - }, removeData (ids) { const il = ids.slice(0) const dl = this.dataList