提交 7a790bc2 编写于 作者: d-u-a's avatar d-u-a

update: unicloud-db 组件修改头条小程序某些情况下报错的问题,新增支持 getTemp方法解决页面多个组件时合并网络请求减少网络请求次数

上级 50576019
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册