search.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <view>
  3. <d-search-log :color_border="color_border" :color_text="color_border" :search_list_old_man_num='15' :search_list_hot="cirlce_search_list_hot"
  4. :store_key="store_key" @onClickDelAllApi="onClickDelAll" @onSearchNameApi="onSearchName" @onSearchvoiceApi='onSearchvoice'></d-search-log>
  5. <u-popup :show="isRecorderManager" mode="bottom">
  6. <view class="shqx" v-if="longPress == '2'">
  7. 上划取消
  8. </view>
  9. <view class="record-layer">
  10. <view class="record-box">
  11. <view class="record-btn-layer" v-if="tempFilePath == ''">
  12. <view class="record-btn">
  13. <image src="../../static/mic1.png" mode="widthFix" style="width:120rpx;"
  14. @longpress="longpressBtn" @touchend="touchendBtn" @touchmove="handleTouchMove"></image>
  15. <text class="text">{{longPress == '1' ? '按住说出姓名' : '松开自动识别'}}</text>
  16. </view>
  17. </view>
  18. <!-- 语音音阶动画 -->
  19. <view class="prompt-layer prompt-layer-1" v-if="longPress == '2'">
  20. <view class="prompt-loader">
  21. <view class="em" v-for="(item,index) in 15" :key="index"></view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </u-popup>
  27. </view>
  28. </template>
  29. <script>
  30. import dSearchLog from '@/uni_modules/d-search-log/components/d-search-log/d-search-log.vue';
  31. const recorderManager = uni.getRecorderManager();
  32. const innerAudioContext = uni.createInnerAudioContext();
  33. var init // 录制时长计时器
  34. var timer // 播放 录制倒计时
  35. export default {
  36. components: {
  37. "dSearchLog": dSearchLog
  38. },
  39. data() {
  40. return {
  41. color_border: "#00aaff",
  42. cirlce_search_list_hot: [],
  43. store_key: 'circle_search_list',
  44. duration: 60000, //录音最大值ms 60000/1分钟
  45. tempFilePath: '', //音频路径
  46. playStatus: 0, //录音播放状态 0:未播放 1:正在播放
  47. longPress: '1',
  48. tempFilePath: '',
  49. isRecorderManager: false,
  50. is_clock: true,
  51. startPoint: ""
  52. };
  53. },
  54. methods: {
  55. onClickDelAll(val) {
  56. console.log(val)
  57. },
  58. onSearchvoice(e){
  59. this.isRecorderManager = true
  60. },
  61. handleTouchMove: function(e) {
  62. console.log("滑动")
  63. if (Math.abs(e.touches[e.touches.length - 1].clientY - this.startPoint.clientY) > 35) {
  64. this.is_clock = false
  65. } else {
  66. this.is_clock = true
  67. }
  68. },
  69. longpressBtn(e) {
  70. this.longPress = '2';
  71. this.is_clock = true,
  72. console.log(e);
  73. this.startPoint = e.touches[0],
  74. recorderManager.onStop((res) => {
  75. console.log("录音结束")
  76. this.tempFilePath = res.tempFilePath;
  77. })
  78. const options = {
  79. duration: this.duration, // 指定录音的时长,单位 ms
  80. sampleRate: 16000, // 采样率
  81. numberOfChannels: 1, // 录音通道数
  82. encodeBitRate: 96000, // 编码码率
  83. // format: 'mp3', // 音频格式,有效值 aac/mp3
  84. frameSize: 10, // 指定帧大小,单位 KB
  85. }
  86. recorderManager.start(options);
  87. // 监听音频开始事件
  88. recorderManager.onStart((res) => {
  89. console.log(res)
  90. })
  91. },
  92. touchendBtn() {
  93. console.log("录音结束")
  94. let that = this
  95. this.longPress = '1';
  96. recorderManager.onStop((res) => {
  97. this.tempFilePath = res.tempFilePath
  98. let _file = ''
  99. if (that.is_clock) {
  100. _file = uni.getFileSystemManager().readFileSync(res.tempFilePath, "base64")
  101. console.log(_file)
  102. that.$request.baseRequest('admin.unimall.certificateManagementInfo', 'speechRecognition', {
  103. voiceMessage: _file,
  104. }, failres => {
  105. console.log('res+++++', failres.errmsg)
  106. uni.showToast({
  107. icon:"none",
  108. title: failres.errmsg,
  109. duration: 3000
  110. });
  111. }).then(res => {
  112. uni.hideLoading()
  113. console.log(res)
  114. uni.setStorageSync('cirlce_search_val', res.data);
  115. uni.switchTab({
  116. url: "/pages/circle/circle"
  117. })
  118. })
  119. }
  120. recorderManager.stop()
  121. })
  122. },
  123. onSearchName(e) {
  124. uni.setStorageSync('cirlce_search_val', e);
  125. uni.switchTab({
  126. url:`/pages/circle/circle`
  127. })
  128. // uni.switchTab({
  129. // url:"/pages/circle/circle?val="+e
  130. // })
  131. }
  132. }
  133. }
  134. </script>
  135. <style lang="scss" scoped>
  136. .shqx {
  137. position: absolute;
  138. top: -100rpx;
  139. left: 0;
  140. right: 0;
  141. margin: auto;
  142. text-align: center;
  143. color: rgba(221, 221, 221, 1);
  144. }
  145. .record-box {
  146. width: 100%;
  147. position: relative;
  148. top: 80rpx;
  149. }
  150. .record-btn-layer {
  151. width: 100%;
  152. display: flex;
  153. justify-content: center;
  154. }
  155. .record-btn-layer button::after {
  156. border: none;
  157. }
  158. .record-btn-layer button {
  159. font-size: 14px;
  160. line-height: 38px;
  161. width: 100%;
  162. height: 38px;
  163. border-radius: 8px;
  164. text-align: center;
  165. background: rgba(56, 86, 156, 1);
  166. }
  167. .record-btn-layer button image {
  168. width: 16px;
  169. height: 16px;
  170. margin-right: 4px;
  171. vertical-align: middle;
  172. }
  173. .record-btn-layer .record-btn-2 {
  174. background: rgba(56, 86, 156, 1);
  175. }
  176. .prompt-layer {
  177. border-radius: 8px;
  178. background: rgba(56, 86, 156, 1);
  179. padding: 8px 16px;
  180. box-sizing: border-box;
  181. position: absolute;
  182. left: 50%;
  183. transform: translateX(-50%);
  184. }
  185. .prompt-layer::after {
  186. content: '';
  187. display: block;
  188. border: 6px solid rgba(0, 0, 0, 0);
  189. border-top-color: rgba(56, 86, 156, 1);
  190. position: absolute;
  191. bottom: -10px;
  192. left: 50%;
  193. transform: translateX(-50%);
  194. }
  195. .prompt-layer-1 {
  196. font-size: 12px;
  197. width: 128px;
  198. text-align: center;
  199. display: flex;
  200. flex-direction: column;
  201. align-items: center;
  202. justify-content: center;
  203. top: -240px;
  204. }
  205. .del {
  206. position: absolute;
  207. top: -200rpx;
  208. .img {
  209. width: 100rpx;
  210. }
  211. }
  212. .prompt-layer-1 .p {
  213. color: #000000;
  214. }
  215. .prompt-layer-1 .span {
  216. color: #fff;
  217. }
  218. .prompt-loader .em {}
  219. .prompt-loader {
  220. width: 96px;
  221. height: 20px;
  222. display: flex;
  223. align-items: center;
  224. justify-content: space-between;
  225. margin-bottom: 6px;
  226. }
  227. .prompt-loader .em {
  228. display: block;
  229. background: #fff;
  230. width: 1px;
  231. height: 10%;
  232. margin-right: 2.5px;
  233. float: left;
  234. }
  235. .prompt-loader .em:last-child {
  236. margin-right: 0px;
  237. }
  238. .prompt-loader .em:nth-child(1) {
  239. animation: load 2.5s 1.4s infinite linear;
  240. }
  241. .prompt-loader .em:nth-child(2) {
  242. animation: load 2.5s 1.2s infinite linear;
  243. }
  244. .prompt-loader .em:nth-child(3) {
  245. animation: load 2.5s 1s infinite linear;
  246. }
  247. .prompt-loader .em:nth-child(4) {
  248. animation: load 2.5s 0.8s infinite linear;
  249. }
  250. .prompt-loader .em:nth-child(5) {
  251. animation: load 2.5s 0.6s infinite linear;
  252. }
  253. .prompt-loader .em:nth-child(6) {
  254. animation: load 2.5s 0.4s infinite linear;
  255. }
  256. .prompt-loader .em:nth-child(7) {
  257. animation: load 2.5s 0.2s infinite linear;
  258. }
  259. .prompt-loader .em:nth-child(8) {
  260. animation: load 2.5s 0s infinite linear;
  261. }
  262. .prompt-loader .em:nth-child(9) {
  263. animation: load 2.5s 0.2s infinite linear;
  264. }
  265. .prompt-loader .em:nth-child(10) {
  266. animation: load 2.5s 0.4s infinite linear;
  267. }
  268. .prompt-loader .em:nth-child(11) {
  269. animation: load 2.5s 0.6s infinite linear;
  270. }
  271. .prompt-loader .em:nth-child(12) {
  272. animation: load 2.5s 0.8s infinite linear;
  273. }
  274. .prompt-loader .em:nth-child(13) {
  275. animation: load 2.5s 1s infinite linear;
  276. }
  277. .prompt-loader .em:nth-child(14) {
  278. animation: load 2.5s 1.2s infinite linear;
  279. }
  280. .prompt-loader .em:nth-child(15) {
  281. animation: load 2.5s 1.4s infinite linear;
  282. }
  283. @keyframes load {
  284. 0% {
  285. height: 10%;
  286. }
  287. 50% {
  288. height: 100%;
  289. }
  290. 100% {
  291. height: 10%;
  292. }
  293. }
  294. .prompt-layer-2 {
  295. // top: -540px;
  296. }
  297. .prompt-layer-2 .text {
  298. color: rgba(0, 0, 0, 1);
  299. font-size: 12px;
  300. }
  301. .record-btn {
  302. display: flex;
  303. flex-direction: column;
  304. justify-content: center;
  305. align-items: center;
  306. .text {
  307. margin-top: 20rpx;
  308. }
  309. }
  310. /deep/.u-popup__content {
  311. padding-bottom: 100rpx;
  312. background: linear-gradient(180deg, rgba(204, 204, 204, 0.95) 0%, rgba(203, 203, 203, 0.01) 100%) !important;
  313. border-radius: 50% 50% 0 0;
  314. }
  315. .record-layerP {
  316. position: relative;
  317. top: 50px;
  318. }
  319. </style>