From 7a790bc2c4e84db2dd58450263747004a8205163 Mon Sep 17 00:00:00 2001 From: handongxun Date: Tue, 6 Jul 2021 21:11:26 +0800 Subject: [PATCH] =?UTF-8?q?update:=20unicloud-db=20=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=B4=E6=9D=A1=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=9F=90=E4=BA=9B=E6=83=85=E5=86=B5=E4=B8=8B=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20getTemp=E6=96=B9=E6=B3=95=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=A4=9A=E4=B8=AA=E7=BB=84=E4=BB=B6=E6=97=B6?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E7=BD=91=E7=BB=9C=E8=AF=B7=E6=B1=82=E5=87=8F?= =?UTF-8?q?=E5=B0=91=E7=BD=91=E7=BB=9C=E8=AF=B7=E6=B1=82=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uni-cli-shared/components/unicloud-db.vue | 141 ++++++++++-------- 1 file changed, 82 insertions(+), 59 deletions(-) diff --git a/packages/uni-cli-shared/components/unicloud-db.vue b/packages/uni-cli-shared/components/unicloud-db.vue index 1e2a07609..c5e2c246b 100644 --- a/packages/uni-cli-shared/components/unicloud-db.vue +++ b/packages/uni-cli-shared/components/unicloud-db.vue @@ -203,7 +203,7 @@ export default { // #ifdef MP-TOUTIAO let changeName - const events = this.$scope.dataset.eventOpts + const events = this.$scope.dataset.eventOpts || [] for (var i = 0; i < events.length; i++) { const event = events[i] if (event[0].includes('^load')) { @@ -410,63 +410,7 @@ export default { complete && complete() }) }, - _execLoadData (callback, clear) { - if (this.loading) { - return - } - this.loading = true - this.errorMessage = '' - - this._getExec().then((res) => { - this.loading = false - const { - data, - count - } = res.result - this._isEnded = data.length < this.pageSize - this.hasMore = !this._isEnded - - const data2 = this.getone ? (data.length ? data[0] : undefined) : data - - if (this.getcount) { - this.paginationInternal.count = count - } - - callback && callback(data2, this._isEnded, this.paginationInternal) - this._dispatchEvent(events.load, data2) - - if (this.getone || this.pageData === pageMode.replace) { - this.dataList = data2 - } else { - if (clear) { - this.dataList = data2 - } else { - this.dataList.push(...data2) - } - } - - // #ifdef H5 - if (process.env.NODE_ENV === 'development') { - this._debugDataList.length = 0 - const formatData = JSON.parse(JSON.stringify(this.dataList)) - if (Array.isArray(this.dataList)) { - this._debugDataList.push(...formatData) - } else { - this._debugDataList.push(formatData) - } - } - // #endif - }).catch((err) => { - this.loading = false - this.errorMessage = err - callback && callback() - this.$emit(events.error, err) - if (process.env.NODE_ENV === 'development') { - console.error(err) - } - }) - }, - _getExec () { + getTemp(isTemp = true) { /* eslint-disable no-undef */ let db = uniCloud.database() @@ -516,10 +460,89 @@ export default { if (this.gettreepath) { getOptions.getTreePath = treeOptions } - db = db.skip(size * (current - 1)).limit(size).get(getOptions) + db = db.skip(size * (current - 1)).limit(size) + + if (isTemp) { + db = db.getTemp(getOptions) + db.udb = this + } else { + db = db.get(getOptions) + } return db }, + setResult(result) { + if (result.code === 0) { + this._execLoadDataSuccess(result) + } else { + this._execLoadDataFail(new Error(result.message)) + } + }, + _execLoadData (callback, clear) { + if (this.loading) { + return + } + this.loading = true + this.errorMessage = '' + + this._getExec().then((res) => { + this.loading = false + this._execLoadDataSuccess(res.result, callback, clear) + + // #ifdef H5 + if (process.env.NODE_ENV === 'development') { + this._debugDataList.length = 0 + const formatData = JSON.parse(JSON.stringify(this.dataList)) + if (Array.isArray(this.dataList)) { + this._debugDataList.push(...formatData) + } else { + this._debugDataList.push(formatData) + } + } + // #endif + }).catch((err) => { + this.loading = false + this._execLoadDataFail(err, callback) + }) + }, + _execLoadDataSuccess(result, callback, clear) { + const { + data, + count + } = result + this._isEnded = data.length < this.pageSize + this.hasMore = !this._isEnded + + const data2 = this.getone ? (data.length ? data[0] : undefined) : data + + if (this.getcount) { + this.paginationInternal.count = count + } + + callback && callback(data2, this._isEnded, this.paginationInternal) + this._dispatchEvent(events.load, data2) + + if (this.getone || this.pageData === pageMode.replace) { + this.dataList = data2 + } else { + if (clear) { + this.dataList = data2 + } else { + this.dataList.push(...data2) + } + } + }, + _execLoadDataFail(err, callback) { + this.errorMessage = err + callback && callback() + this.$emit(events.error, err) + if (process.env.NODE_ENV === 'development') { + console.error(err) + } + }, + _getExec () { + return this.getTemp(false) + }, _execRemove (id, action, success, fail, complete, needConfirm, needLoading, loadingTitle) { if (!this.collection || !id) { return -- GitLab