Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivWeb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivWeb
Commits
a32c8fae
Commit
a32c8fae
authored
Mar 07, 2024
by
xuchaozou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 完成懒加载模式
parent
1a947679
Pipeline
#85735
passed with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
99 deletions
+135
-99
PandaUi.js
src/components/SoundAi/PandaUi.js
+126
-0
index.js
src/components/SoundAi/index.js
+9
-99
No files found.
src/components/SoundAi/PandaUi.js
0 → 100644
View file @
a32c8fae
import
{
request
,
event
}
from
'@wisdom-utils/utils'
import
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
'react'
import
{
PandaRecordWebSocket
}
from
'./core'
import
{
message
}
from
'antd'
import
PandaTip
from
'./Ui/PandaTip'
import
{
init
,
cut
,
extract
,
ready
}
from
"@congcongcai/jieba.js"
;
const
PandaUi
=
props
=>
{
const
pandaRecordWebSocketRef
=
useRef
(
null
)
const
[
isStartRecorder
,
setIsStartRecorder
]
=
useState
(
false
)
const
{
keyRef
}
=
props
useEffect
(
async
()
=>
{
try
{
await
initJieBa
()
event
.
emit
(
"record:changeVisible"
,
{
visible
:
true
})
event
.
on
(
"record:changedStaus"
,
changeSwitch
)
}
catch
(
error
)
{
console
.
warn
(
error
)
}
return
()
=>
{
event
.
off
(
"record:changedStaus"
,
changeSwitch
)
}
},
[])
const
changeSwitch
=
useCallback
(
async
({
recordData
,
e
:
checked
})
=>
{
if
(
checked
)
{
emitSwitch
({
loading
:
true
})
createPandaRecordWebSocket
()
const
data
=
await
pandaRecordWebSocketRef
.
current
.
start
()
emitSwitch
({
loading
:
false
})
if
(
!
data
.
isSuccess
)
{
return
message
.
info
(
data
.
msg
)
}
emitSwitch
({
checked
:
true
})
setIsStartRecorder
(
true
)
}
else
{
emitSwitch
({
loading
:
true
})
await
destroyPandaRecorderWebSocket
()
emitSwitch
({
loading
:
false
,
checked
:
false
})
setIsStartRecorder
(
false
)
}
},
[])
const
createPandaRecordWebSocket
=
async
()
=>
{
destroyPandaRecorderWebSocket
()
pandaRecordWebSocketRef
.
current
=
new
PandaRecordWebSocket
({
config
:
keyRef
.
current
.
shortSound
,
events
:
{
frame
(
data
)
{
event
.
emit
(
"aiSound:frame"
,
data
)
},
finish
(
data
)
{
event
.
emit
(
"aiSound:finish"
,
data
)
}
}
})
// await testText("我需要打开浩源孪生平台菜单")
// await testText("我需要返回首页")
// await testText("我需要打开礼泉孪生平台菜单")
// await testText("我需要打开浩源孪生平台菜单")
// await testText("我需要关闭平台菜单")
// await testText("我需要打开孪生平台菜单")
// await testText("我需要打开第二个菜单")
// await testText("我需要打开浩源孪生平台菜单")
}
const
testText
=
text
=>
new
Promise
((
resolve
,
reject
)
=>
{
setTimeout
(()
=>
{
event
.
emit
(
"aiSound:frame"
,
{
resultTextTemp
:
text
})
setTimeout
(()
=>
{
event
.
emit
(
"aiSound:finish"
,
{
resultText
:
text
})
setTimeout
(()
=>
{
resolve
()
},
500
)
},
500
)
},
500
)
})
const
destroyPandaRecorderWebSocket
=
async
()
=>
{
if
(
pandaRecordWebSocketRef
.
current
)
{
await
pandaRecordWebSocketRef
.
current
.
destroy
()
pandaRecordWebSocketRef
.
current
=
null
}
}
const
emitSwitch
=
data
=>
{
event
.
emit
(
"record:changeSwicth"
,
data
)
}
const
initJieBa
=
()
=>
new
Promise
((
resolve
,
reject
)
=>
{
ready
().
then
(()
=>
{
init
()
resolve
()
}).
catch
(()
=>
{
reject
()
})
})
return
(
<>
{
isStartRecorder
?
<
PandaTip
pandaRecordWebSocketRef
=
{
pandaRecordWebSocketRef
}
/> : nul
l
}
<
/>
)
}
export
default
PandaUi
\ No newline at end of file
src/components/SoundAi/index.js
View file @
a32c8fae
import
{
request
,
event
}
from
'@wisdom-utils/utils'
import
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
'react'
import
{
PandaRecordWebSocket
}
from
'./core'
import
{
message
}
from
'antd'
import
PandaTip
from
'./Ui/PandaTip'
import
{
init
,
cut
,
extract
,
ready
}
from
"@congcongcai/jieba.js"
;
import
{
Suspense
,
lazy
,
useCallback
,
useEffect
,
useRef
,
useState
}
from
'react'
const
SoundAi
=
props
=>
{
const
PandaUi
=
lazy
(()
=>
import
(
"./PandaUi"
))
const
pandaRecordWebSocketRef
=
useRef
(
null
)
const
SoundAi
=
props
=>
{
const
keyRef
=
useRef
(
null
)
const
[
isStartRecorder
,
setIsStartRecorder
]
=
useState
(
false
)
const
[
visible
,
setVisible
]
=
useState
(
false
)
useEffect
(
async
()
=>
{
try
{
await
getIsOpenConfig
()
await
getKey
()
await
initJieBa
()
event
.
emit
(
"record:changeVisible"
,
{
visible
:
true
})
event
.
on
(
"record:changedStaus"
,
changeSwitch
)
setVisible
(
true
)
}
catch
(
error
)
{
console
.
warn
(
error
)
}
return
()
=>
{
event
.
off
(
"record:changedStaus"
,
changeSwitch
)
}
},
[])
const
changeSwitch
=
useCallback
(
async
({
recordData
,
e
:
checked
})
=>
{
if
(
checked
)
{
emitSwitch
({
loading
:
true
})
createPandaRecordWebSocket
()
const
data
=
await
pandaRecordWebSocketRef
.
current
.
start
()
emitSwitch
({
loading
:
false
})
if
(
!
data
.
isSuccess
)
{
return
message
.
info
(
data
.
msg
)
}
emitSwitch
({
checked
:
true
})
setIsStartRecorder
(
true
)
}
else
{
emitSwitch
({
loading
:
true
})
await
destroyPandaRecorderWebSocket
()
emitSwitch
({
loading
:
false
,
checked
:
false
})
setIsStartRecorder
(
false
)
}
},
[])
const
createPandaRecordWebSocket
=
async
()
=>
{
destroyPandaRecorderWebSocket
()
pandaRecordWebSocketRef
.
current
=
new
PandaRecordWebSocket
({
config
:
keyRef
.
current
.
shortSound
,
events
:
{
frame
(
data
)
{
event
.
emit
(
"aiSound:frame"
,
data
)
},
finish
(
data
)
{
event
.
emit
(
"aiSound:finish"
,
data
)
}
}
})
// await testText("我需要打开浩源孪生平台菜单")
// await testText("我需要返回首页")
// await testText("我需要打开礼泉孪生平台菜单")
// await testText("我需要打开浩源孪生平台菜单")
// await testText("我需要关闭平台菜单")
// await testText("我需要打开孪生平台菜单")
// await testText("我需要打开第二个菜单")
// await testText("我需要打开浩源孪生平台菜单")
}
const
testText
=
text
=>
new
Promise
((
resolve
,
reject
)
=>
{
setTimeout
(()
=>
{
event
.
emit
(
"aiSound:frame"
,
{
resultTextTemp
:
text
})
setTimeout
(()
=>
{
event
.
emit
(
"aiSound:finish"
,
{
resultText
:
text
})
setTimeout
(()
=>
{
resolve
()
},
500
)
},
500
)
},
500
)
})
const
destroyPandaRecorderWebSocket
=
async
()
=>
{
if
(
pandaRecordWebSocketRef
.
current
)
{
await
pandaRecordWebSocketRef
.
current
.
destroy
()
pandaRecordWebSocketRef
.
current
=
null
}
}
const
emitSwitch
=
data
=>
{
event
.
emit
(
"record:changeSwicth"
,
data
)
}
const
getIsOpenConfig
=
()
=>
new
Promise
((
resolve
,
reject
)
=>
{
request
(
"/PandaOMS/OMS/DataManger/GetDicConfigs"
,
{
...
...
@@ -148,17 +63,12 @@ const SoundAi = props => {
})
})
const
initJieBa
=
()
=>
new
Promise
((
resolve
,
reject
)
=>
{
ready
().
then
(()
=>
{
init
()
resolve
()
}).
catch
(()
=>
{
reject
()
})
})
return
(
<>
{
isStartRecorder
?
<
PandaTip
pandaRecordWebSocketRef
=
{
pandaRecordWebSocketRef
}
/> : nul
l
visible
?
<
Suspense
fallback
=
{
<><
/>}
>
<
PandaUi
keyRef
=
{
keyRef
}
/
>
<
/Suspense> : nul
l
}
<
/>
)
}
...
...
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