Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
dd274ccf
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dd274ccf
编写于
1月 21, 2022
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(App): addPhoneContact
https://gitee.com/dcloud/uni-app/issues/I4NY6C
上级
a8fb01b3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
170 addition
and
244 deletion
+170
-244
packages/uni-api/src/protocols/device/addPhoneContact.ts
packages/uni-api/src/protocols/device/addPhoneContact.ts
+13
-1
packages/uni-app-plus/src/service/api/device/addPhoneContact.ts
...es/uni-app-plus/src/service/api/device/addPhoneContact.ts
+157
-243
未找到文件。
packages/uni-api/src/protocols/device/addPhoneContact.ts
浏览文件 @
dd274ccf
export
const
API_ADD_PHONE_CONTACT
=
'
addPhoneContact
'
export
type
API_TYPE_ADD_PHONE_CONTACT
=
typeof
uni
.
addPhoneContact
export
const
AddPhoneContactOptions
:
ApiOptions
<
API_TYPE_ADD_PHONE_CONTACT
>
=
{
formatArgs
:
{
firstName
(
firstName
)
{
if
(
!
firstName
)
return
'
addPhoneContact:fail parameter error: parameter.firstName should not be empty;
'
},
},
}
export
const
AddPhoneContactProtocol
:
ApiProtocol
<
API_TYPE_ADD_PHONE_CONTACT
>
=
{
firstName
:
{
type
:
String
,
required
:
true
,
},
photoFilePath
:
String
,
nickName
:
String
,
lastName
:
String
,
middleName
:
String
,
firstName
:
String
,
remark
:
String
,
mobilePhoneNumber
:
String
,
weChatNumber
:
String
,
...
...
packages/uni-app-plus/src/service/api/device/addPhoneContact.ts
浏览文件 @
dd274ccf
...
...
@@ -2,260 +2,174 @@ import {
API_ADD_PHONE_CONTACT
,
API_TYPE_ADD_PHONE_CONTACT
,
defineAsyncApi
,
MakePhoneCallProtocol
,
AddPhoneContactProtocol
,
AddPhoneContactOptions
,
}
from
'
@dcloudio/uni-api
'
export
const
addPhoneContact
=
defineAsyncApi
<
API_TYPE_ADD_PHONE_CONTACT
>
(
API_ADD_PHONE_CONTACT
,
(
type
Schema
=
Record
<
Exclude
<
keyof
PlusContactsContact
,
|
'
id
'
|
'
displayName
'
|
'
birthday
'
|
'
categories
'
|
'
clone
'
|
'
remove
'
|
'
save
'
>
,
any
>
const
schema
:
Schema
=
{
name
:
{
givenName
:
'
firstName
'
,
middleName
:
'
middleName
'
,
familyName
:
'
lastName
'
,
},
nickname
:
'
nickName
'
,
photos
:
{
type
:
'
url
'
,
value
:
'
photoFilePath
'
,
},
note
:
'
remark
'
,
phoneNumbers
:
[
{
type
:
'
mobile
'
,
value
:
'
mobilePhoneNumber
'
,
},
{
type
:
'
work
'
,
value
:
'
workPhoneNumber
'
,
},
{
photoFilePath
=
''
,
nickName
,
lastName
,
middleName
,
firstName
,
remark
,
mobilePhoneNumber
,
weChatNumber
,
addressCountry
,
addressState
,
addressCity
,
addressStreet
,
addressPostalCode
,
organization
,
title
,
workFaxNumber
,
workPhoneNumber
,
hostNumber
,
email
,
url
,
workAddressCountry
,
workAddressState
,
workAddressCity
,
workAddressStreet
,
workAddressPostalCode
,
homeFaxNumber
,
homePhoneNumber
,
homeAddressCountry
,
homeAddressState
,
homeAddressCity
,
homeAddressStreet
,
homeAddressPostalCode
,
type
:
'
company
'
,
value
:
'
hostNumber
'
,
},
{
resolve
,
reject
}
)
=>
{
{
type
:
'
home fax
'
,
value
:
'
homeFaxNumber
'
,
},
{
type
:
'
work fax
'
,
value
:
'
workFaxNumber
'
,
},
],
emails
:
[
{
type
:
'
home
'
,
value
:
'
email
'
,
},
],
urls
:
[
{
type
:
'
other
'
,
value
:
'
url
'
,
},
],
organizations
:
[
{
type
:
'
company
'
,
name
:
'
organization
'
,
title
:
'
title
'
,
},
],
ims
:
[
{
type
:
'
other
'
,
value
:
'
weChatNumber
'
,
},
],
addresses
:
[
{
type
:
'
other
'
,
preferred
:
true
,
country
:
'
addressCountry
'
,
region
:
'
addressState
'
,
locality
:
'
addressCity
'
,
streetAddress
:
'
addressStreet
'
,
postalCode
:
'
addressPostalCode
'
,
},
{
type
:
'
home
'
,
country
:
'
homeAddressCountry
'
,
region
:
'
homeAddressState
'
,
locality
:
'
homeAddressCity
'
,
streetAddress
:
'
homeAddressStreet
'
,
postalCode
:
'
homeAddressPostalCode
'
,
},
{
type
:
'
company
'
,
country
:
'
workAddressCountry
'
,
region
:
'
workAddressState
'
,
locality
:
'
workAddressCity
'
,
streetAddress
:
'
workAddressStreet
'
,
postalCode
:
'
workAddressPostalCode
'
,
},
],
}
const
keepFields
=
[
'
type
'
,
'
preferred
'
]
function
buildContact
(
contact
:
any
,
data
:
any
,
schema
:
any
)
{
let
hasValue
=
0
Object
.
keys
(
schema
).
forEach
((
contactKey
)
=>
{
const
dataKey
=
schema
[
contactKey
]
const
typed
=
typeof
dataKey
if
(
typed
!==
'
object
'
)
{
if
(
keepFields
.
indexOf
(
contactKey
)
!==
-
1
)
{
contact
[
contactKey
]
=
schema
[
contactKey
]
}
else
{
if
(
typeof
data
[
dataKey
]
!==
'
undefined
'
)
{
hasValue
++
contact
[
contactKey
]
=
data
[
dataKey
]
}
else
{
delete
contact
[
contactKey
]
}
}
}
else
{
if
(
dataKey
instanceof
Array
)
{
contact
[
contactKey
]
=
[]
dataKey
.
forEach
((
item
)
=>
{
const
obj
=
{}
if
(
buildContact
(
obj
,
data
,
item
))
{
contact
[
contactKey
].
push
(
obj
)
}
})
if
(
!
contact
[
contactKey
].
length
)
{
delete
contact
[
contactKey
]
}
else
{
hasValue
++
}
}
else
{
contact
[
contactKey
]
=
{}
if
(
buildContact
(
contact
[
contactKey
],
data
,
dataKey
))
{
hasValue
++
}
else
{
delete
contact
[
contactKey
]
}
}
}
})
return
hasValue
}
export
const
addPhoneContact
=
defineAsyncApi
<
API_TYPE_ADD_PHONE_CONTACT
>
(
API_ADD_PHONE_CONTACT
,
(
data
,
{
resolve
,
reject
})
=>
{
!
data
.
photoFilePath
&&
(
data
.
photoFilePath
=
''
)
plus
.
contacts
.
getAddressBook
(
plus
.
contacts
.
ADDRESSBOOK_PHONE
,
(
addressbook
)
=>
{
const
contact
=
addressbook
.
create
()
const
name
:
any
=
{}
if
(
lastName
)
{
name
.
familyName
=
lastName
}
if
(
firstName
)
{
name
.
givenName
=
firstName
}
if
(
middleName
)
{
name
.
middleName
=
middleName
}
contact
.
name
=
name
if
(
nickName
)
{
contact
.
nickname
=
nickName
}
if
(
photoFilePath
)
{
;(
contact
as
any
).
photos
=
[
{
type
:
'
url
'
,
value
:
photoFilePath
,
},
]
}
if
(
remark
)
{
contact
.
note
=
remark
}
const
mobilePhone
:
any
=
{
type
:
'
mobile
'
,
}
const
workPhone
:
any
=
{
type
:
'
work
'
,
}
const
companyPhone
:
any
=
{
type
:
'
company
'
,
}
const
homeFax
:
any
=
{
type
:
'
home fax
'
,
}
const
workFax
:
any
=
{
type
:
'
work fax
'
,
}
if
(
mobilePhoneNumber
)
{
mobilePhone
.
value
=
mobilePhoneNumber
}
if
(
workPhoneNumber
)
{
workPhone
.
value
=
workPhoneNumber
}
if
(
hostNumber
)
{
companyPhone
.
value
=
hostNumber
}
if
(
homeFaxNumber
)
{
homeFax
.
value
=
homeFaxNumber
}
if
(
workFaxNumber
)
{
workFax
.
value
=
workFaxNumber
}
;(
contact
as
any
).
phoneNumbers
=
[
mobilePhone
,
workPhone
,
companyPhone
,
homeFax
,
workFax
,
]
if
(
email
)
{
;(
contact
as
any
).
emails
=
[
{
type
:
'
home
'
,
value
:
email
,
},
]
}
if
(
url
)
{
;(
contact
as
any
).
urls
=
[
{
type
:
'
other
'
,
value
:
url
,
},
]
}
const
org
:
any
=
{
type
:
'
company
'
,
}
if
(
organization
)
{
org
.
name
=
organization
}
if
(
title
)
{
org
.
title
=
title
}
if
(
weChatNumber
)
{
;(
contact
as
any
).
ims
=
[
{
type
:
'
other
'
,
value
:
weChatNumber
,
},
]
}
const
defaultAddress
:
any
=
{
type
:
'
other
'
,
preferred
:
true
,
}
const
homeAddress
:
any
=
{
type
:
'
home
'
,
}
const
companyAddress
:
any
=
{
type
:
'
company
'
,
}
if
(
addressCountry
)
{
defaultAddress
.
country
=
addressCountry
}
if
(
addressState
)
{
defaultAddress
.
region
=
addressState
}
if
(
addressCity
)
{
defaultAddress
.
locality
=
addressCity
}
if
(
addressStreet
)
{
defaultAddress
.
streetAddress
=
addressStreet
}
if
(
addressPostalCode
)
{
defaultAddress
.
postalCode
=
addressPostalCode
}
if
(
homeAddressCountry
)
{
homeAddress
.
country
=
homeAddressCountry
}
if
(
homeAddressState
)
{
homeAddress
.
region
=
homeAddressState
}
if
(
homeAddressCity
)
{
homeAddress
.
locality
=
homeAddressCity
}
if
(
homeAddressStreet
)
{
homeAddress
.
streetAddress
=
homeAddressStreet
}
if
(
homeAddressPostalCode
)
{
homeAddress
.
postalCode
=
homeAddressPostalCode
}
if
(
workAddressCountry
)
{
companyAddress
.
country
=
workAddressCountry
}
if
(
workAddressState
)
{
companyAddress
.
region
=
workAddressState
}
if
(
workAddressCity
)
{
companyAddress
.
locality
=
workAddressCity
}
if
(
workAddressStreet
)
{
companyAddress
.
streetAddress
=
workAddressStreet
}
if
(
workAddressPostalCode
)
{
companyAddress
.
postalCode
=
workAddressPostalCode
}
;(
contact
as
any
).
addresses
=
[
defaultAddress
,
homeAddress
,
companyAddress
,
]
buildContact
(
contact
,
data
,
schema
)
contact
.
save
(
()
=>
{
resolve
({
errMsg
:
'
addPhoneContact:ok
'
,
})
},
(
e
)
=>
{
reject
(
'
addPhoneContact:fail
'
)
}
()
=>
resolve
(),
(
e
)
=>
reject
()
)
},
(
e
)
=>
{
reject
(
'
addPhoneContact:fail
'
)
}
(
e
)
=>
reject
()
)
},
MakePhoneCallProtocol
AddPhoneContactProtocol
,
AddPhoneContactOptions
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录