提交 65e1d7d0 编写于 作者: Q qiang

Merge branch 'dev' into alpha

<template>
<view>
<slot
:options="options"
:data="dataList"
:pagination="paginationInternal"
:loading="loading"
:error="errorMessage"
/>
<slot :options="options" :data="dataList" :pagination="paginationInternal" :loading="loading" :error="errorMessage" />
</view>
</template>
<script>
const events = {
const events = {
load: 'load',
error: 'error'
}
const pageMode = {
}
const pageMode = {
add: 'add',
replace: 'replace'
}
}
const attrs = [
const attrs = [
'pageCurrent',
'pageSize',
'collection',
......@@ -29,9 +23,9 @@ const attrs = [
'getcount',
'orderby',
'where'
]
]
export default {
export default {
name: 'UniClouddb',
props: {
options: {
......@@ -85,7 +79,7 @@ export default {
default: false
}
},
data () {
data() {
return {
loading: false,
dataList: this.getone ? {} : [],
......@@ -97,7 +91,7 @@ export default {
errorMessage: ''
}
},
created () {
created() {
this._isEnded = false
this.$watch(() => {
......@@ -172,7 +166,7 @@ export default {
}
},
// #ifdef H5
beforeDestroy () {
beforeDestroy() {
if (process.env.NODE_ENV === 'development' && window.unidev) {
var cd = this._debugDataList
var dl = window.unidev.clientDB.data
......@@ -186,7 +180,7 @@ export default {
},
// #endif
methods: {
loadData (args1, args2) {
loadData(args1, args2) {
let callback = null
if (typeof args1 === 'object') {
if (args1.clear) {
......@@ -205,26 +199,52 @@ export default {
this._execLoadData(callback)
},
loadMore () {
loadMore() {
if (this._isEnded) {
return
}
this._execLoadData()
},
refresh () {
refresh() {
this.clear()
this._execLoadData()
},
clear () {
clear() {
this._isEnded = false
this.dataList = []
},
reset () {
reset() {
this.paginationInternal.current = 1
},
remove (id, {
add(value, {
toastTitle,
success,
fail,
complete
} = {}) {
uni.showLoading()
let db = uniCloud.database()
db.collection(this.collection).add(value).then((res) => {
success && success(res)
uni.showToast({
title: toastTitle || '新增成功'
})
}).catch((err) => {
fail && fail(err)
uni.showModal({
content: err.message,
showCancel: false
})
}).finally(() => {
uni.hideLoading()
complete && complete()
})
},
remove(id, {
action,
callback,
success,
fail,
complete,
confirmTitle,
confirmContent
} = {}) {
......@@ -239,11 +259,35 @@ export default {
if (!res.confirm) {
return
}
this._execRemove(id, action, callback)
this._execRemove(id, action, success, fail, complete)
}
})
},
_execLoadData (callback) {
update(id, value, {
toastTitle,
success,
fail,
complete
} = {}) {
uni.showLoading()
let db = uniCloud.database()
return db.collection(this.collection).doc(id).update(value).then((res) => {
success && success(res)
uni.showToast({
title: toastTitle || '修改成功'
})
}).catch((err) => {
fail && fail(err)
uni.showModal({
content: err.message,
showCancel: false
})
}).finally(() => {
uni.hideLoading()
complete && complete()
})
},
_execLoadData(callback) {
if (this.loading) {
return
}
......@@ -292,7 +336,7 @@ export default {
}
})
},
_getExec () {
_getExec() {
/* eslint-disable no-undef */
let db = uniCloud.database()
......@@ -322,7 +366,7 @@ export default {
return db
},
_execRemove (id, action, callback) {
_execRemove(id, action, success, fail, complete) {
if (!this.collection || !id) {
return
}
......@@ -348,22 +392,24 @@ export default {
exec.collection(this.collection).where({
_id: dbCmd.in(ids)
}).remove().then((res) => {
callback && callback(res.result)
success && success(res.result)
if (this.pageData === pageMode.replace) {
this.refresh()
} else {
this.removeData(ids)
}
}).catch((err) => {
fail && fail(err)
uni.showModal({
content: err.message,
showCancel: false
})
}).finally(() => {
uni.hideLoading()
complete && complete()
})
},
removeData (ids) {
removeData(ids) {
const il = ids.slice(0)
const dl = this.dataList
for (let i = dl.length - 1; i >= 0; i--) {
......@@ -374,7 +420,7 @@ export default {
}
}
},
_dispatchEvent (type, data) {
_dispatchEvent(type, data) {
if (this._changeDataFunction) {
this._changeDataFunction(data, this._isEnded)
} else {
......@@ -382,5 +428,5 @@ export default {
}
}
}
}
}
</script>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册