Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx
/
dj-scrm-wx-work-attachment-psd
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 210cadac
authored
Jul 26, 2023
by
李伟康
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
提交
1 parent
7c4d2007
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
21 deletions
src/api/chatgptApi.js
src/components/ChatGPT.vue
src/config/env.development.js
src/api/chatgptApi.js
View file @
210cada
const
url
=
'/router'
const
url
=
'/ro
p-scrm-marketing/ro
uter'
import
{
utils
}
from
'glsx-common'
export
default
{
...
...
@@ -8,6 +8,27 @@ export default {
return
httpRequest
(
method
,
data
)
},
/**
* 获取AI id
*/
getAiId
(
data
)
{
data
.
method
=
'marketing.api.scriptlibrary.ai.id'
return
window
.
$HTTP
({
url
,
data
,
returnAll
:
true
})
},
/**
* 新增聊天记录
*/
updatedAiRecord
(
data
)
{
data
.
method
=
'marketing.api.scriptlibrary.ai.record.add'
return
window
.
$HTTP
({
url
,
data
})
},
}
const
httpRequest
=
(
method
,
data
)
=>
{
const
{
secret
,
sign
,
request
}
=
window
.
$fetchConfig
...
...
@@ -16,7 +37,7 @@ const httpRequest = (method, data) => {
...
sign
})
return
new
Promise
((
resolve
,
reject
)
=>
{
window
.
fetch
(
`
${
request
.
base
URL
}
/router/
${
method
}
/1.0.0`
,
{
window
.
fetch
(
`
${
request
.
chatGpt
URL
}
/router/
${
method
}
/1.0.0`
,
{
method
:
'POST'
,
headers
:
{
'Content-Type'
:
'application/json;charset=UTF-8'
},
body
:
JSON
.
stringify
(
utils
.
createSign
(
data
,
secret
))
...
...
src/components/ChatGPT.vue
View file @
210cada
...
...
@@ -4,9 +4,15 @@
:class=
"['view',
{'show-tips':showTips
&&
issuesList.length}]"
ref="contentView"
>
<div
class=
"content-item left"
>
<div
class=
"sprite-icon icon-ai icon"
></div>
<div
class=
"content"
>
您可以向我提问公司的业务产品或销售等相关问题,我将给您组织语言并提供建议,您可以复制段落稍作润色并答复给您的客户。
</div>
</div>
<template
v-for=
"(i,index) in contentList"
>
<div
:key=
"index"
>
<template
v-if=
"i.
speaker == 'AI'
"
>
<template
v-if=
"i.
contentType == 1
"
>
<div
class=
"content-item left"
>
<div
class=
"sprite-icon icon-ai icon"
></div>
<div
class=
"content"
>
...
...
@@ -70,24 +76,40 @@
<
script
type=
'text/ecmascript-6'
>
import
{
chatgptApi
}
from
'@/api'
import
*
as
dayjs
from
'dayjs'
export
default
{
name
:
'ChatGpt'
,
data
()
{
return
{
contentList
:
[{
content
:
'您可以向我提问公司的业务产品或销售等相关问题,我将给您组织语言并提供建议,您可以复制段落稍作润色并答复给您的客户。'
,
speaker
:
'AI'
}],
contentList
:
[],
issuesList
:
window
.
$fetchConfig
.
issuesList
||
[],
showTips
:
true
,
issue
:
''
issue
:
''
,
scriptLibraryAIId
:
''
}
},
mounted
()
{
this
.
getAiId
()
},
methods
:
{
async
getAiId
()
{
this
.
showLoading
()
const
{
merchantId
,
uuid
,
merchantName
,
userName
}
=
this
.
getLocalStorage
(
'dj_scrm_userInfo'
)
try
{
const
{
code
,
data
,
message
}
=
await
chatgptApi
.
getAiId
({
merchantId
,
merchantName
,
staffUuid
:
uuid
,
staffName
:
userName
})
if
(
code
==
0
&&
data
)
this
.
scriptLibraryAIId
=
data
else
throw
message
this
.
hideLoading
()
}
catch
(
error
)
{
console
.
log
(
error
)
this
.
showToast
(
error
)
}
},
onkeydown
(
e
)
{
if
(
e
.
keyCode
==
13
)
{
this
.
send
()
...
...
@@ -97,16 +119,20 @@ export default {
const
{
issue
}
=
this
,
content
=
val
||
issue
if
(
!
content
)
return
const
chatTime
=
Date
.
now
()
this
.
contentList
.
push
({
speaker
:
'ME'
,
content
contentType
:
0
,
content
,
chatTime
:
dayjs
(
chatTime
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
})
if
(
!
val
)
{
this
.
issue
=
''
this
.
$refs
.
input
.
blur
()
}
this
.
toBottom
()
this
.
toQuestionChatGPT
(
content
)
this
.
$nextTick
(()
=>
{
this
.
toQuestionChatGPT
(
content
)
})
},
toBottom
()
{
this
.
$nextTick
(()
=>
{
...
...
@@ -116,14 +142,17 @@ export default {
async
toQuestionChatGPT
(
question
)
{
const
id
=
Date
.
now
()
this
.
contentList
.
push
({
speaker
:
'AI'
,
id
,
content
:
''
contentType
:
1
,
content
:
''
,
id
})
const
{
response
}
=
await
chatgptApi
.
issueChatGpt
({
question
,
history
:
''
})
let
questionEffectiveCount
=
0
if
(
response
.
indexOf
(
'很抱歉'
)
==
-
1
)
questionEffectiveCount
=
1
this
.
contentList
.
find
(
i
=>
i
.
id
==
id
).
chatTime
=
dayjs
().
format
(
'YYYY-MM-DD HH:mm:ss'
)
let
index
=
0
,
speed
=
10
const
typeWriter
=
()
=>
{
if
(
index
<
response
.
length
)
{
...
...
@@ -131,10 +160,28 @@ export default {
index
++
setTimeout
(
typeWriter
,
speed
)
this
.
toBottom
()
}
}
else
this
.
addRecord
(
id
,
questionEffectiveCount
)
}
typeWriter
()
},
addRecord
(
id
,
questionEffectiveCount
)
{
const
{
contentList
,
scriptLibraryAIId
}
=
this
,
index
=
this
.
contentList
.
findIndex
(
i
=>
i
.
id
==
id
),
questionItem
=
contentList
[
index
-
1
],
answerItem
=
contentList
[
index
],
lastQuestionTime
=
dayjs
(
questionItem
.
chatTime
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
delete
answerItem
.
id
// aiRecordList[index - 1] = questionItem
// aiRecordList[index] = answerItem
chatgptApi
.
updatedAiRecord
({
scriptLibraryAIId
,
lastQuestionTime
,
aiRecordList
:
[
questionItem
,
answerItem
],
questionCount
:
1
,
questionEffectiveCount
})
}
}
}
</
script
>
...
...
src/config/env.development.js
View file @
210cada
...
...
@@ -11,8 +11,8 @@ module.exports = {
title
:
'嘻嘻'
,
envVersion
:
'trial'
,
request
:
{
baseURL
:
'//192.168.1.124
:7860'
,
// 本地测试项目地址,
// baseURL: '//scrm.test
.glsx.com.cn', // 本地测试项目地址,
// baseURL: '//192.168.3.191
:7860', // 本地测试项目地址,
baseURL
:
'//scrm.dev
.glsx.com.cn'
,
// 本地测试项目地址,
// 设置超时时间
timeout
:
180000
,
...
...
@@ -20,7 +20,11 @@ module.exports = {
withCredentials
:
true
,
// 返回数据类型
responseType
:
'json'
,
chatGptURL
:
'//chatgpt.dev.glsx.com.cn'
,
/**
* 开发//chatgpt.dev.glsx.com.cn
* 测试//chatgpt.dev.glsx.com.cn
*/
ropMerchantURL
:
'http://rop-merchant.dev.glsx.com.cn'
/**
* 开发:http://rop-merchant.dev.glsx.com.cn
...
...
@@ -47,7 +51,7 @@ module.exports = {
source
:
"scrm-main"
,
v
:
"1.0.0"
,
},
vconsole
:
fals
e
,
vconsole
:
tru
e
,
issuesList
:
[
'你这个保险有点贵啊,好像别人那里都没有那么高的价格。'
,
'我这个保险在外面朋友买没那么便宜。'
,
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment