/
个人资料.js
63 lines (55 loc) · 1.2 KB
/
个人资料.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* - 同步阶段拉取个人资料
* - 多端同步个人资料更新
* - 更新个人资料
*/
import store from '../store'
nim = NIM.getInstance({
appKey: "YOUR_APPKEY",
account: "YOUR_ACCOUNT",
token: "YOUR_TOKEN",
debug: true,
onmyinfo: onmyinfo,
onupdatemyinfo: onupdatemyinfo
})
/**
* 初始化同步时获取个人资料
*/
function onmyinfo(profile) {
store.myProfile = profile
}
/**
* 多端同步获取个人资料
*/
function onupdatemyinfo(profile) {
store.myProfile = profile
}
/**
* 更新个人信息完成后,设置个人资料
*/
function updateMyInfo(partialProfile) {
nim.updateMyInfo({
...partialProfile,
done: function (err, profile) {
if (!err) {
store.myProfile = profile
}
}
})
}
/**
* 设置用户头像:先使用 previewFile 上传头像,然后将 avatar 设置为用户头像
*/
function setMyAvatar() {
nim.previewFile({
type: "image",
fileInput: "preview-file",
done: function (err, data) {
if (!err) {
updateMyInfo({
avatar: data.url
})
}
}
})
}