提交 41497f8d 编写于 作者: d-u-a's avatar d-u-a

update: <unicloud-db> lint

上级 a15b2de8
<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',
......@@ -23,9 +29,9 @@
'getcount',
'orderby',
'where'
]
]
export default {
export default {
name: 'UniClouddb',
props: {
options: {
......@@ -79,7 +85,7 @@
default: false
}
},
data() {
data () {
return {
loading: false,
dataList: this.getone ? {} : [],
......@@ -91,7 +97,7 @@
errorMessage: ''
}
},
created() {
created () {
this._isEnded = false
this.$watch(() => {
......@@ -166,7 +172,7 @@
}
},
// #ifdef H5
beforeDestroy() {
beforeDestroy () {
if (process.env.NODE_ENV === 'development' && window.unidev) {
var cd = this._debugDataList
var dl = window.unidev.clientDB.data
......@@ -180,7 +186,7 @@
},
// #endif
methods: {
loadData(args1, args2) {
loadData (args1, args2) {
let callback = null
if (typeof args1 === 'object') {
if (args1.clear) {
......@@ -199,31 +205,32 @@
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
},
add(value, {
add (value, {
toastTitle,
success,
fail,
complete
} = {}) {
uni.showLoading()
let db = uniCloud.database()
/* eslint-disable no-undef */
const db = uniCloud.database()
db.collection(this.collection).add(value).then((res) => {
success && success(res)
uni.showToast({
......@@ -240,7 +247,7 @@
complete && complete()
})
},
remove(id, {
remove (id, {
action,
success,
fail,
......@@ -263,14 +270,15 @@
}
})
},
update(id, value, {
update (id, value, {
toastTitle,
success,
fail,
complete
} = {}) {
uni.showLoading()
let db = uniCloud.database()
/* eslint-disable no-undef */
const db = uniCloud.database()
return db.collection(this.collection).doc(id).update(value).then((res) => {
success && success(res)
uni.showToast({
......@@ -287,7 +295,7 @@
complete && complete()
})
},
_execLoadData(callback) {
_execLoadData (callback) {
if (this.loading) {
return
}
......@@ -336,7 +344,7 @@
}
})
},
_getExec() {
_getExec () {
/* eslint-disable no-undef */
let db = uniCloud.database()
......@@ -366,7 +374,7 @@
return db
},
_execRemove(id, action, success, fail, complete) {
_execRemove (id, action, success, fail, complete) {
if (!this.collection || !id) {
return
}
......@@ -409,7 +417,7 @@
complete && complete()
})
},
removeData(ids) {
removeData (ids) {
const il = ids.slice(0)
const dl = this.dataList
for (let i = dl.length - 1; i >= 0; i--) {
......@@ -420,7 +428,7 @@
}
}
},
_dispatchEvent(type, data) {
_dispatchEvent (type, data) {
if (this._changeDataFunction) {
this._changeDataFunction(data, this._isEnded)
} else {
......@@ -428,5 +436,5 @@
}
}
}
}
}
</script>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册