search.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. this.$refs.uToast.show({
  107. type: 'error',
  108. message: failres.errmsg,
  109. })
  110. }).then(res => {
  111. uni.hideLoading()
  112. console.log(res)
  113. uni.setStorageSync('cirlce_search_val', res.data);
  114. uni.switchTab({
  115. url: "/pages/circle/circle"
  116. })
  117. })
  118. }
  119. recorderManager.stop()
  120. })
  121. },
  122. onSearchName(e) {
  123. uni.setStorageSync('cirlce_search_val', e);
  124. uni.switchTab({
  125. url:`/pages/circle/circle`
  126. })
  127. // uni.switchTab({
  128. // url:"/pages/circle/circle?val="+e
  129. // })
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. .shqx {
  136. position: absolute;
  137. top: -100rpx;
  138. left: 0;
  139. right: 0;
  140. margin: auto;
  141. text-align: center;
  142. color: rgba(221, 221, 221, 1);
  143. }
  144. .record-box {
  145. width: 100%;
  146. position: relative;
  147. top: 80rpx;
  148. }
  149. .record-btn-layer {
  150. width: 100%;
  151. display: flex;
  152. justify-content: center;
  153. }
  154. .record-btn-layer button::after {
  155. border: none;
  156. }
  157. .record-btn-layer button {
  158. font-size: 14px;
  159. line-height: 38px;
  160. width: 100%;
  161. height: 38px;
  162. border-radius: 8px;
  163. text-align: center;
  164. background: rgba(56, 86, 156, 1);
  165. }
  166. .record-btn-layer button image {
  167. width: 16px;
  168. height: 16px;
  169. margin-right: 4px;
  170. vertical-align: middle;
  171. }
  172. .record-btn-layer .record-btn-2 {
  173. background: rgba(56, 86, 156, 1);
  174. }
  175. .prompt-layer {
  176. border-radius: 8px;
  177. background: rgba(56, 86, 156, 1);
  178. padding: 8px 16px;
  179. box-sizing: border-box;
  180. position: absolute;
  181. left: 50%;
  182. transform: translateX(-50%);
  183. }
  184. .prompt-layer::after {
  185. content: '';
  186. display: block;
  187. border: 6px solid rgba(0, 0, 0, 0);
  188. border-top-color: rgba(56, 86, 156, 1);
  189. position: absolute;
  190. bottom: -10px;
  191. left: 50%;
  192. transform: translateX(-50%);
  193. }
  194. .prompt-layer-1 {
  195. font-size: 12px;
  196. width: 128px;
  197. text-align: center;
  198. display: flex;
  199. flex-direction: column;
  200. align-items: center;
  201. justify-content: center;
  202. top: -240px;
  203. }
  204. .del {
  205. position: absolute;
  206. top: -200rpx;
  207. .img {
  208. width: 100rpx;
  209. }
  210. }
  211. .prompt-layer-1 .p {
  212. color: #000000;
  213. }
  214. .prompt-layer-1 .span {
  215. color: #fff;
  216. }
  217. .prompt-loader .em {}
  218. .prompt-loader {
  219. width: 96px;
  220. height: 20px;
  221. display: flex;
  222. align-items: center;
  223. justify-content: space-between;
  224. margin-bottom: 6px;
  225. }
  226. .prompt-loader .em {
  227. display: block;
  228. background: #fff;
  229. width: 1px;
  230. height: 10%;
  231. margin-right: 2.5px;
  232. float: left;
  233. }
  234. .prompt-loader .em:last-child {
  235. margin-right: 0px;
  236. }
  237. .prompt-loader .em:nth-child(1) {
  238. animation: load 2.5s 1.4s infinite linear;
  239. }
  240. .prompt-loader .em:nth-child(2) {
  241. animation: load 2.5s 1.2s infinite linear;
  242. }
  243. .prompt-loader .em:nth-child(3) {
  244. animation: load 2.5s 1s infinite linear;
  245. }
  246. .prompt-loader .em:nth-child(4) {
  247. animation: load 2.5s 0.8s infinite linear;
  248. }
  249. .prompt-loader .em:nth-child(5) {
  250. animation: load 2.5s 0.6s infinite linear;
  251. }
  252. .prompt-loader .em:nth-child(6) {
  253. animation: load 2.5s 0.4s infinite linear;
  254. }
  255. .prompt-loader .em:nth-child(7) {
  256. animation: load 2.5s 0.2s infinite linear;
  257. }
  258. .prompt-loader .em:nth-child(8) {
  259. animation: load 2.5s 0s infinite linear;
  260. }
  261. .prompt-loader .em:nth-child(9) {
  262. animation: load 2.5s 0.2s infinite linear;
  263. }
  264. .prompt-loader .em:nth-child(10) {
  265. animation: load 2.5s 0.4s infinite linear;
  266. }
  267. .prompt-loader .em:nth-child(11) {
  268. animation: load 2.5s 0.6s infinite linear;
  269. }
  270. .prompt-loader .em:nth-child(12) {
  271. animation: load 2.5s 0.8s infinite linear;
  272. }
  273. .prompt-loader .em:nth-child(13) {
  274. animation: load 2.5s 1s infinite linear;
  275. }
  276. .prompt-loader .em:nth-child(14) {
  277. animation: load 2.5s 1.2s infinite linear;
  278. }
  279. .prompt-loader .em:nth-child(15) {
  280. animation: load 2.5s 1.4s infinite linear;
  281. }
  282. @keyframes load {
  283. 0% {
  284. height: 10%;
  285. }
  286. 50% {
  287. height: 100%;
  288. }
  289. 100% {
  290. height: 10%;
  291. }
  292. }
  293. .prompt-layer-2 {
  294. // top: -540px;
  295. }
  296. .prompt-layer-2 .text {
  297. color: rgba(0, 0, 0, 1);
  298. font-size: 12px;
  299. }
  300. .record-btn {
  301. display: flex;
  302. flex-direction: column;
  303. justify-content: center;
  304. align-items: center;
  305. .text {
  306. margin-top: 20rpx;
  307. }
  308. }
  309. /deep/.u-popup__content {
  310. padding-bottom: 100rpx;
  311. background: linear-gradient(180deg, rgba(204, 204, 204, 0.95) 0%, rgba(203, 203, 203, 0.01) 100%) !important;
  312. border-radius: 50% 50% 0 0;
  313. }
  314. .record-layerP {
  315. position: relative;
  316. top: 50px;
  317. }
  318. </style>