提交 5260b0bf 编写于 作者: 雪洛's avatar 雪洛

feat: unicloud-db add get temp lookup support

上级 8ba66e31
...@@ -55,7 +55,7 @@ export default { ...@@ -55,7 +55,7 @@ export default {
} }
}, },
collection: { collection: {
type: String, type: [String, Array],
default: '' default: ''
}, },
action: { action: {
...@@ -148,6 +148,21 @@ export default { ...@@ -148,6 +148,21 @@ export default {
errorMessage: '' 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 () { created () {
this._isEnded = false this._isEnded = false
this.paginationInternal = { this.paginationInternal = {
...@@ -314,7 +329,7 @@ export default { ...@@ -314,7 +329,7 @@ export default {
db = db.action(action) db = db.action(action)
} }
db.collection(this._getCollection()).add(value).then((res) => { db.collection(this.mainCollection).add(value).then((res) => {
success && success(res) success && success(res)
if (showToast) { if (showToast) {
uni.showToast({ uni.showToast({
...@@ -388,7 +403,7 @@ export default { ...@@ -388,7 +403,7 @@ export default {
db = db.action(action) 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) success && success(res)
if (showToast) { if (showToast) {
uni.showToast({ uni.showToast({
...@@ -418,7 +433,7 @@ export default { ...@@ -418,7 +433,7 @@ export default {
db = db.action(this.action) db = db.action(this.action)
} }
db = db.collection(this.collection) db = db.collection(...this.collectionArgs)
if (!(!this.where || !Object.keys(this.where).length)) { if (!(!this.where || !Object.keys(this.where).length)) {
db = db.where(this.where) db = db.where(this.where)
...@@ -569,7 +584,7 @@ export default { ...@@ -569,7 +584,7 @@ export default {
exec = exec.action(action) exec = exec.action(action)
} }
exec.collection(this._getCollection()).where({ exec.collection(this.mainCollection).where({
_id: dbCmd.in(ids) _id: dbCmd.in(ids)
}).remove().then((res) => { }).remove().then((res) => {
success && success(res.result) success && success(res.result)
...@@ -593,11 +608,6 @@ export default { ...@@ -593,11 +608,6 @@ export default {
complete && complete() complete && complete()
}) })
}, },
_getCollection () {
const index = this.collection.indexOf(',')
const collection = index > 0 ? this.collection.substring(0, index) : this.collection
return collection
},
removeData (ids) { removeData (ids) {
const il = ids.slice(0) const il = ids.slice(0)
const dl = this.dataList const dl = this.dataList
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册