search.vue 7.8 KB

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