search.vue 8.0 KB

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