Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
foreign
/
im-demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
dd301453
authored
Feb 25, 2022
by
杨铁龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add create add chat api
parent
6547881d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
89 additions
and
13 deletions
.env.test1
.env.test2
package-lock.json
package.json
src/config/index.ts
src/service/chat.ts
src/service/user.ts
src/views/home.vue
.env.test1
View file @
dd301453
VUE_APP_TEST_ACCOUNT="15132146321"
VUE_APP_TEST_PASSWORD="erhao521"
\ No newline at end of file
VUE_APP_EID="10"
\ No newline at end of file
.env.test2
View file @
dd301453
VUE_APP_TEST_ACCOUNT="18040417207"
VUE_APP_TEST_PASSWORD="y1234567"
\ No newline at end of file
VUE_APP_EID="11"
\ No newline at end of file
package-lock.json
View file @
dd301453
...
...
@@ -36,6 +36,7 @@
"@vue/eslint-config-standard"
:
"^6.1.0"
,
"@vue/eslint-config-typescript"
:
"^9.1.0"
,
"compression-webpack-plugin"
:
"^9.2.0"
,
"cross-env"
:
"^7.0.3"
,
"eslint"
:
"^7.32.0"
,
"eslint-plugin-import"
:
"^2.25.3"
,
"eslint-plugin-node"
:
"^11.1.0"
,
...
...
@@ -4825,6 +4826,25 @@
"node"
:
">=8"
}
},
"node_modules/cross-env"
:
{
"version"
:
"7.0.3"
,
"resolved"
:
"http://npm.job.qinqinxiaobao.com/cross-env/-/cross-env-7.0.3.tgz"
,
"integrity"
:
"sha1-hlJkspZ33AFbqEGJGJZd0jL8VM8="
,
"dev"
:
true
,
"license"
:
"MIT"
,
"dependencies"
:
{
"cross-spawn"
:
"^7.0.1"
},
"bin"
:
{
"cross-env"
:
"src/bin/cross-env.js"
,
"cross-env-shell"
:
"src/bin/cross-env-shell.js"
},
"engines"
:
{
"node"
:
">=10.14"
,
"npm"
:
">=6"
,
"yarn"
:
">=1"
}
},
"node_modules/cross-spawn"
:
{
"version"
:
"7.0.3"
,
"resolved"
:
"https://registry.npmmirror.com/cross-spawn/-/cross-spawn-7.0.3.tgz"
,
...
...
@@ -16637,6 +16657,15 @@
"yaml"
:
"^1.7.2"
}
},
"cross-env"
:
{
"version"
:
"7.0.3"
,
"resolved"
:
"http://npm.job.qinqinxiaobao.com/cross-env/-/cross-env-7.0.3.tgz"
,
"integrity"
:
"sha1-hlJkspZ33AFbqEGJGJZd0jL8VM8="
,
"dev"
:
true
,
"requires"
:
{
"cross-spawn"
:
"^7.0.1"
}
},
"cross-spawn"
:
{
"version"
:
"7.0.3"
,
"resolved"
:
"https://registry.npmmirror.com/cross-spawn/-/cross-spawn-7.0.3.tgz"
,
...
...
package.json
View file @
dd301453
...
...
@@ -97,4 +97,4 @@
"last 2 versions"
,
"not dead"
]
}
}
\ No newline at end of file
src/config/index.ts
View file @
dd301453
export
const
config
=
{
chatApi
:
'http://xchat-ds.jinsehuaqin.com:8020/chat/api'
,
appId
:
'tecsun'
,
password
:
'ds123456'
,
eid
:
process
.
env
.
VUE_APP_EID
,
chatApi
:
'http://xchat-ds.jinsehuaqin.com:8020/'
,
SocketUrl
:
'ws://xchat-ds.jinsehuaqin.com:8010/ws'
,
testAccount
:
process
.
env
.
VUE_APP_TEST_ACCOUNT
,
testPassword
:
process
.
env
.
VUE_APP_TEST_PASSWORD
,
...
...
src/service/chat.ts
View file @
dd301453
...
...
@@ -6,7 +6,6 @@ import Chat from '@/customer-service/xim'
import
store
from
'@/store'
import
{
throttle
}
from
'lodash'
import
{
cache
}
from
'./user'
// import { sdk } from './sdk'
export
function
initChat
()
{
console
.
log
(
'初始化chat'
)
...
...
src/service/user.ts
View file @
dd301453
import
{
config
}
from
'@/config'
import
{
randomString
}
from
'@/utils'
import
axios
from
'axios'
export
const
cache
=
{
chatApiOrgId
:
'chatApiOrgId'
,
chatApiToken
:
'chatApiToken'
,
...
...
@@ -9,7 +10,6 @@ export const cache = {
export
function
buildHeaders
()
{
return
{
headers
:
{
'content-type'
:
'application/x-www-form-urlencoded'
,
Authorization
:
'Bearer '
+
localStorage
.
getItem
(
cache
.
chatApiToken
),
},
}
...
...
@@ -18,11 +18,15 @@ export function buildHeaders() {
export
interface
CreateChat
{
// 成员uid
members
:
string
[]
// 会话标题
title
:
string
}
function
createChat
(
data
:
CreateChat
)
{
/** 创建会话 biz_id暂时随机生成,唯一字段 */
export
function
createChat
(
data
:
CreateChat
)
{
const
d
=
{
members
:
data
.
members
.
map
((
i
)
=>
{
// 都传成员uid
return
{
uid
:
i
,
eid
:
i
,
...
...
@@ -35,6 +39,45 @@ function createChat(data: CreateChat) {
biz_id
:
randomString
(
32
),
}
return
axios
.
post
(
`
${
config
.
chatApi
}
/add_xchat`
,
d
,
buildHeaders
())
.
post
(
`
${
config
.
chatApi
}
/
chat/api/
add_xchat`
,
d
,
buildHeaders
())
.
then
((
r
)
=>
r
.
data
.
access_token
)
}
/**
* 添加成员到会话中
* @param members 用户id
* @param chatId 会话id
* @returns
*/
export
function
addToChat
(
members
:
string
[],
chatId
:
number
)
{
const
d
=
{
members
:
members
.
map
((
i
)
=>
{
// 都传成员uid
return
{
uid
:
i
,
eid
:
i
,
oid
:
i
,
}
}),
chat_id
:
chatId
,
}
return
axios
.
post
(
`
${
config
.
chatApi
}
/chat/api/join_xchat`
,
d
,
buildHeaders
())
.
then
((
r
)
=>
r
.
data
.
access_token
)
}
/** 生成token */
export
function
generateToken
()
{
return
axios
.
post
(
`
${
config
.
chatApi
}
/inside/api/get_auth_token`
,
{
app_id
:
config
.
appId
,
password
:
config
.
password
,
eid
:
config
.
eid
,
})
.
then
((
r
)
=>
{
const
token
=
r
.
data
.
data
.
token
const
orgId
=
r
.
data
.
data
.
org_id
localStorage
.
setItem
(
cache
.
chatApiToken
,
token
)
localStorage
.
setItem
(
cache
.
chatApiOrgId
,
orgId
)
})
}
src/views/home.vue
View file @
dd301453
...
...
@@ -29,6 +29,7 @@
import
{
ChatStore
,
chatStore
}
from
"@/customer-service/store/model"
import
ChatRoom
from
"@/customer-service/components/chat-room.vue"
import
{
getUid
}
from
"@/utils"
import
{
generateToken
}
from
"@/service/user"
@
Component
({
components
:
{
ChatRoom
},
})
...
...
@@ -51,7 +52,9 @@
}
private
init
()
{
return
initChat
()
return
generateToken
().
then
(()
=>
{
return
initChat
()
})
}
}
</
script
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment