user.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <!-- 个人中心:支持装修 -->
  2. <template>
  3. <s-layout
  4. title=""
  5. navbar="inner"
  6. tabbar="/pages/index/user"
  7. :bgStyle="state.page"
  8. :navbarStyle="state.navigationBar"
  9. showLogoutButton
  10. >
  11. <view class="user_page">
  12. <view class="ai_box">
  13. <view class="ai_name">我的外呼智能体</view>
  14. <view class="ai_cont">
  15. <!-- <view class="ai_audio">
  16. <image v-if="state.play" class="play_icon" src="/static/play_icon.png"></image>
  17. <image v-else class="pause_icon" src="/static/pause_icon.png"></image>
  18. <image class="play_img" src="/static/play_img.png"></image>
  19. </view> -->
  20. <view class="progress-box">
  21. <progress :percent="20" stroke-width="20rpx" />
  22. <view class="progress_bottom">
  23. <view class="label">训练中…</view>
  24. <view class="percent">20%</view>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="training_btn" @tap="openTrainingAuthModal">训练</view>
  29. </view>
  30. <!-- <view class="ai_no">
  31. <image class="ai_no_img" src="/static/ai_no_img.png"></image>
  32. <view class="dsc">外呼智能体尚未学习您的声音</view>
  33. <image class="training_img" src="/static/training_img.png"></image>
  34. </view> -->
  35. </view>
  36. <su-popup :show="state.showTraining" round="20" :showClose="true" @close="closeTrainingAuthModal">
  37. <view class="training_wrap">
  38. <view class="training_cont">
  39. <view class="label">请朗读(1/3)</view>
  40. <view class="cont">您好,我是您的五萎汽车官方服务顾问,恭喜您成功注册五菱汽车App,您可参与新用户专属 现金抽奖活动,最高获得10元现金红包,100%中奖,提交【五菱天选座驾】表单即可参与!更有请问您有华为手机香薰机等好礼!您提交一下,领个现金红包呗?</view>
  41. </view>
  42. <view
  43. class="record_btn"
  44. :class="{'recording_btn':state.isRecording,'touched_btn':state.isTouched}"
  45. @touchstart="startRecording"
  46. @touchmove="moveRecording"
  47. @touchend="stopRecording"
  48. @touchcancel="stopRecording"
  49. >
  50. <view v-show="state.isRecording" class="optimize_tip">
  51. <span class="recording_text" :style="{'color': state.isTouched ? '#FF4E4E' : '#666666'}">{{state.isTouched ? '松开取消' : '松开发送,上滑取消'}}</span>
  52. </view>
  53. {{state.audioLoading ? '录音校验中,请稍等…' : state.isRecording?'':'按住录制'}}
  54. <view v-if="state.isRecording" class="recording_loading">
  55. <view class="dot1"></view>
  56. <view class="dot2"></view>
  57. <view class="dot3"></view>
  58. </view>
  59. </view>
  60. </view>
  61. </su-popup>
  62. <su-popup :show="state.showClone" round="20" type="center" :isMaskClick="false" :showClose="false" @close="state.showClone=false">
  63. <view class="tips_wrap">
  64. <view class="tips_cont">
  65. <view class="label">声音克隆中</view>
  66. <view class="cont">预计需要30分钟,克隆完成后会通知您</view>
  67. </view>
  68. <view class="group_btn">
  69. <!-- <view class="item_btn cancel_btn">取消</view> -->
  70. <view class="item_btn confirm_btn" @tap="state.showClone=false">确认</view>
  71. </view>
  72. </view>
  73. </su-popup>
  74. </s-layout>
  75. </template>
  76. <script setup>
  77. import { onShow } from '@dcloudio/uni-app';
  78. import AuthUtil from '@/common/api/member/auth';
  79. import { reactive } from 'vue';
  80. import sheep from '@/common';
  81. const state = reactive({
  82. navigationBar: {},
  83. page: {
  84. backgroundColor: '#FAFAFA',
  85. backgroundImage: '/static/homeTopBg.png'
  86. },
  87. play:false,
  88. showTraining: false,
  89. isRecording: false,
  90. isTouched: false,
  91. startY: 0,
  92. audioLoading: false,
  93. recorderManager: null,
  94. showClone: true
  95. })
  96. // 隐藏原生tabBar
  97. uni.hideTabBar({
  98. fail: () => {},
  99. })
  100. onShow(() => {
  101. })
  102. function openTrainingAuthModal(){
  103. state.showTraining = true
  104. initH5Record()
  105. }
  106. function closeTrainingAuthModal(){
  107. state.showTraining = false
  108. }
  109. async function initH5Record(){
  110. if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
  111. //sheep.$helper.toast('您的浏览器不支持录音功能')
  112. return
  113. }
  114. navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
  115. state.recorderManager = new MediaRecorder(stream)
  116. const audioChunks = []
  117. state.recorderManager.ondataavailable = e => {
  118. audioChunks.push(e.data)
  119. }
  120. state.recorderManager.onstop = () => {
  121. let audioBlob = new Blob(audioChunks)
  122. let audioSrc = URL.createObjectURL(audioBlob)
  123. stream.getTracks().forEach(track => track.stop())
  124. state.isRecording = false
  125. if (!state.isTouched) {
  126. console.log(audioBlob,audioSrc)
  127. } else {
  128. sheep.$helper.toast("取消录音")
  129. console.log("取消录音")
  130. }
  131. }
  132. }).catch(err => {
  133. console.error('录音权限获取失败:', err)
  134. sheep.$helper.toast('请允许麦克风权限')
  135. })
  136. }
  137. function initRecord(){
  138. // 初始化录音管理器
  139. state.recorderManager = uni.getRecorderManager()
  140. // 监听录音结束事件
  141. state.recorderManager.onStop((res) => {
  142. console.log('录音结束', res)
  143. state.isRecording = false
  144. if (!state.isTouched) {
  145. console.log(res.tempFilePath)
  146. } else {
  147. sheep.$helper.toast("取消录音")
  148. console.log("取消录音")
  149. }
  150. })
  151. }
  152. function startRecord() {
  153. sheep.$helper.toast(state.recorderManager)
  154. if (!state.isRecording) {
  155. state.isRecording = true
  156. state.recorderManager.start()
  157. }
  158. }
  159. function pauseRecord() {
  160. if (state.isRecording) {
  161. state.recorderManager.pause()
  162. }
  163. }
  164. function stopRecord() {
  165. if (state.isRecording) {
  166. state.recorderManager.stop()
  167. }
  168. }
  169. // 按住按钮
  170. function startRecording(event) {
  171. console.log('startRecording')
  172. if (state.audioLoading) {
  173. sheep.$helper.toast("录音校验中…")
  174. return
  175. }
  176. startRecord()
  177. // 获取触摸开始的坐标
  178. state.startY = event.touches[0].clientY;
  179. state.isTouched = false;
  180. }
  181. // 移动手指
  182. function moveRecording(event) {
  183. console.log('moveRecording')
  184. const currentY = event.touches[0].clientY;
  185. const deltaY = state.startY - currentY;
  186. // 判断垂直滑动,并且滑动距离是否足够
  187. if (deltaY > 10) {
  188. // 按到了取消按钮
  189. state.isTouched = true;
  190. } else {
  191. state.isTouched = false
  192. }
  193. }
  194. // 松开按钮
  195. function stopRecording() {
  196. stopRecord()
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .user_page{
  201. .ai_box{
  202. display: flex;
  203. flex-direction: column;
  204. align-items: center;
  205. padding: 232rpx 40rpx 0;
  206. .ai_name{
  207. font-weight: bold;
  208. font-size: 40rpx;
  209. color: #222222;
  210. line-height: 80rpx;
  211. margin-bottom: 29rpx;
  212. }
  213. .ai_cont{
  214. width: 670rpx;
  215. height: 260rpx;
  216. background: url('/static/aiBg.png') no-repeat center/100% 100%;
  217. position: relative;
  218. .ai_audio{
  219. width: 300rpx;
  220. height: 100rpx;
  221. background: #E2F5ED;
  222. box-shadow: inset 0rpx 4rpx 6rpx 2rpx rgba(0,0,0,0.05);
  223. border-radius: 60rpx;
  224. border: 1rpx solid #FFFFFF;
  225. position: absolute;
  226. bottom: 40rpx;
  227. right: 60rpx;
  228. display: flex;
  229. align-items: center;
  230. justify-content: center;
  231. .pause_icon,
  232. .play_icon{
  233. width: 60rpx;
  234. height: 60rpx;
  235. margin-right: 16rpx;
  236. }
  237. .play_img{
  238. width: 148rpx;
  239. height: 40rpx;
  240. }
  241. }
  242. .progress-box{
  243. width: 320rpx;
  244. position: absolute;
  245. bottom: 40rpx;
  246. right: 40rpx;
  247. :deep(.uni-progress){
  248. .uni-progress-bar{
  249. border-radius: 10rpx;
  250. box-shadow: inset 0rpx 4rpx 6rpx 2rpx rgba(0,0,0,0.05);
  251. background: #CAF2E0 !important;
  252. border: 1rpx solid #FFFFFF;
  253. .uni-progress-inner-bar{
  254. border-radius: 10rpx;
  255. background: linear-gradient( 90deg, #35E89A 0%, #00EBB0 100%) !important;
  256. }
  257. }
  258. }
  259. .progress_bottom{
  260. display: flex;
  261. justify-content: space-between;
  262. font-weight: 400;
  263. font-size: 24rpx;
  264. color: #222222;
  265. line-height: 34rpx;
  266. padding-top: 12rpx;
  267. }
  268. }
  269. }
  270. .training_btn{
  271. width: 630rpx;
  272. height: 104rpx;
  273. background: #222222;
  274. border-radius: 40rpx;
  275. font-weight: bold;
  276. font-size: 32rpx;
  277. color: #FFFFFF;
  278. line-height: 104rpx;
  279. text-align: center;
  280. margin: 80rpx auto 126rpx;
  281. }
  282. }
  283. .ai_no{
  284. padding: 360rpx 40rpx 0;
  285. display: flex;
  286. flex-direction: column;
  287. align-items: center;
  288. .ai_no_img{
  289. width: 290rpx;
  290. height: 260rpx;
  291. margin-bottom: 40rpx;
  292. }
  293. .dsc{
  294. font-weight: 400;
  295. font-size: 28rpx;
  296. color: #999999;
  297. line-height: 40rpx;
  298. margin-bottom: 80rpx;
  299. }
  300. .training_img{
  301. width: 250rpx;
  302. height: 82rpx;
  303. }
  304. }
  305. }
  306. .training_wrap{
  307. padding: 118rpx 40rpx 40rpx;
  308. height: 1132rpx;
  309. box-sizing: border-box;
  310. display: flex;
  311. flex-direction: column;
  312. justify-content: space-between;
  313. .training_cont{
  314. .label{
  315. font-weight: bold;
  316. font-size: 40rpx;
  317. color: #222222;
  318. line-height: 58rpx;
  319. text-align: center;
  320. margin-bottom: 120rpx;
  321. }
  322. .cont{
  323. font-weight: 500;
  324. font-size: 32rpx;
  325. color: #222222;
  326. line-height: 56rpx;
  327. }
  328. }
  329. .record_btn{
  330. width: 630rpx;
  331. height: 104rpx;
  332. background: #35E89A;
  333. border-radius: 40rpx;
  334. display: flex;
  335. align-items: center;
  336. justify-content: center;
  337. margin: 0 auto;
  338. position: relative;
  339. .optimize_tip{
  340. position: absolute;
  341. top: -60rpx;
  342. left: 0;
  343. width: 100%;
  344. display: flex;
  345. align-items: center;
  346. .recording_text {
  347. width: 100%;
  348. font-weight: 400;
  349. font-size: 24rpx;
  350. text-align: center;
  351. }
  352. }
  353. .recording_loading {
  354. display: flex;
  355. align-items: center;
  356. justify-content: space-around;
  357. width: 76rpx;
  358. height: 100rpx;
  359. .dot1, .dot2, .dot3 {
  360. width: 8rpx;
  361. height: 8rpx;
  362. background-color: #333;
  363. border-radius: 50%;
  364. animation: scaleAnimation 3s infinite;
  365. }
  366. .dot1 {
  367. animation: jump 1.6s -0.32s linear infinite;
  368. background: #FFFFFF;
  369. }
  370. .dot2 {
  371. animation: jump 1.6s -0.16s linear infinite;
  372. background: #FFFFFF;
  373. }
  374. .dot3 {
  375. animation: jump 1.6s linear infinite;
  376. background: #FFFFFF;
  377. }
  378. @keyframes jump {
  379. 0%, 80%, 100% {
  380. -webkit-transform: scale(0);
  381. transform: scale(0);
  382. }
  383. 40% {
  384. -webkit-transform: scale(2.0);
  385. transform: scale(2.0);
  386. }
  387. }
  388. }
  389. }
  390. .recording_btn{
  391. width: 630rpx;
  392. background: #CCCCCC;
  393. }
  394. .recording_btn.touched_btn{
  395. background: #FF4E4E;
  396. }
  397. }
  398. </style>