Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzb_79
uni-app
提交
5135c096
U
uni-app
项目概览
lzb_79
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5135c096
编写于
8月 31, 2021
作者:
d-u-a
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore(unicloud): 同步 v2 unicloud-db组件代码
上级
073d3134
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
89 addition
and
57 deletion
+89
-57
packages/uni-components/lib/unicloud-db/unicloud-db.vue
packages/uni-components/lib/unicloud-db/unicloud-db.vue
+89
-57
未找到文件。
packages/uni-components/lib/unicloud-db/unicloud-db.vue
浏览文件 @
5135c096
...
...
@@ -77,7 +77,7 @@ export default {
}
},
collection
:
{
type
:
String
,
type
:
[
String
,
Array
]
,
default
:
''
},
action
:
{
...
...
@@ -172,6 +172,21 @@ export default {
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
()
{
this
.
_isEnded
=
false
this
.
paginationInternal
=
{
...
...
@@ -319,7 +334,7 @@ export default {
db
=
db
.
action
(
action
)
}
db
.
collection
(
this
.
_getCollection
()
).
add
(
value
).
then
((
res
)
=>
{
db
.
collection
(
this
.
mainCollection
).
add
(
value
).
then
((
res
)
=>
{
success
&&
success
(
res
)
if
(
showToast
)
{
uni
.
showToast
({
...
...
@@ -393,7 +408,7 @@ export default {
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
)
if
(
showToast
)
{
uni
.
showToast
({
...
...
@@ -415,52 +430,7 @@ export default {
complete
&&
complete
()
})
},
_execLoadData
(
callback
,
clear
)
{
if
(
this
.
loading
)
{
return
}
this
.
loading
=
true
this
.
errorMessage
=
''
return
this
.
_getExec
().
then
((
res
)
=>
{
this
.
loading
=
false
const
{
data
,
count
}
=
res
.
result
this
.
_isEnded
=
count
!==
undefined
?
(
this
.
paginationInternal
.
current
*
this
.
paginationInternal
.
size
>=
count
)
:
(
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
)
}
}
}).
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
()
...
...
@@ -468,7 +438,7 @@ export default {
db
=
db
.
action
(
this
.
action
)
}
db
=
db
.
collection
(
this
.
collection
)
db
=
db
.
collection
(
...
this
.
collectionArgs
)
if
(
!
(
!
this
.
where
||
!
Object
.
keys
(
this
.
where
).
length
))
{
db
=
db
.
where
(
this
.
where
)
...
...
@@ -510,10 +480,77 @@ 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
=
''
return
this
.
_getExec
().
then
((
res
)
=>
{
this
.
loading
=
false
this
.
_execLoadDataSuccess
(
res
.
result
,
callback
,
clear
)
}).
catch
((
err
)
=>
{
this
.
loading
=
false
this
.
_execLoadDataFail
(
err
,
callback
)
})
},
_execLoadDataSuccess
(
result
,
callback
,
clear
)
{
const
{
data
,
count
}
=
result
this
.
_isEnded
=
count
!==
undefined
?
(
this
.
paginationInternal
.
current
*
this
.
paginationInternal
.
size
>=
count
)
:
(
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
...
...
@@ -540,7 +577,7 @@ export default {
exec
=
exec
.
action
(
action
)
}
exec
.
collection
(
this
.
_getCollection
()
).
where
({
exec
.
collection
(
this
.
mainCollection
).
where
({
_id
:
dbCmd
.
in
(
ids
)
}).
remove
().
then
((
res
)
=>
{
success
&&
success
(
res
.
result
)
...
...
@@ -564,11 +601,6 @@ export default {
complete
&&
complete
()
})
},
_getCollection
()
{
const
index
=
this
.
collection
.
indexOf
(
'
,
'
)
const
collection
=
index
>
0
?
this
.
collection
.
substring
(
0
,
index
)
:
this
.
collection
return
collection
},
removeData
(
ids
)
{
const
il
=
ids
.
slice
(
0
)
const
dl
=
this
.
dataList
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录