search.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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"></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;"
  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. handleTouchMove: function(e) {
  63. console.log("滑动")
  64. if (Math.abs(e.touches[e.touches.length - 1].clientY - this.startPoint.clientY) > 35) {
  65. this.is_clock = false
  66. } else {
  67. this.is_clock = true
  68. }
  69. },
  70. longpressBtn(e) {
  71. this.longPress = '2';
  72. this.is_clock = true,
  73. console.log(e);
  74. this.startPoint = e.touches[0],
  75. recorderManager.onStop((res) => {
  76. console.log("录音结束")
  77. this.tempFilePath = res.tempFilePath;
  78. })
  79. const options = {
  80. duration: this.duration, // 指定录音的时长,单位 ms
  81. sampleRate: 16000, // 采样率
  82. numberOfChannels: 1, // 录音通道数
  83. encodeBitRate: 96000, // 编码码率
  84. // format: 'mp3', // 音频格式,有效值 aac/mp3
  85. frameSize: 10, // 指定帧大小,单位 KB
  86. }
  87. recorderManager.start(options);
  88. // 监听音频开始事件
  89. recorderManager.onStart((res) => {
  90. console.log(res)
  91. })
  92. },
  93. touchendBtn() {
  94. console.log("录音结束")
  95. let that = this
  96. this.longPress = '1';
  97. recorderManager.onStop((res) => {
  98. this.tempFilePath = res.tempFilePath
  99. let _file = ''
  100. if (that.is_clock) {
  101. _file = uni.getFileSystemManager().readFileSync(res.tempFilePath, "base64")
  102. console.log(_file)
  103. that.$request.baseRequest('admin.unimall.certificateManagementInfo', 'speechRecognition', {
  104. voiceMessage: _file,
  105. }, failres => {
  106. console.log('res+++++', failres.errmsg)
  107. this.$refs.uToast.show({
  108. type: 'error',
  109. message: failres.errmsg,
  110. })
  111. }).then(res => {
  112. uni.hideLoading()
  113. console.log(res)
  114. uni.setStorageSync('search_val', res.data);
  115. uni.switchTab({
  116. url: "/pages/cardHolder/cardHolder"
  117. })
  118. })
  119. }
  120. recorderManager.stop()
  121. })
  122. },
  123. onClickDelAll() {},
  124. onSearchName(e) {
  125. uni.setStorageSync('search_val', e);
  126. uni.switchTab({
  127. url: "/pages/cardHolder/cardHolder"
  128. })
  129. }
  130. }
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. .shqx {
  135. position: absolute;
  136. top: -100rpx;
  137. left: 0;
  138. right: 0;
  139. margin: auto;
  140. text-align: center;
  141. color: rgba(221, 221, 221, 1);
  142. }
  143. .record-box {
  144. width: 100%;
  145. position: relative;
  146. top: 80rpx;
  147. }
  148. .record-btn-layer {
  149. width: 100%;
  150. display: flex;
  151. justify-content: center;
  152. }
  153. .record-btn-layer button::after {
  154. border: none;
  155. }
  156. .record-btn-layer button {
  157. font-size: 14px;
  158. line-height: 38px;
  159. width: 100%;
  160. height: 38px;
  161. border-radius: 8px;
  162. text-align: center;
  163. background: rgba(56, 86, 156, 1);
  164. }
  165. .record-btn-layer button image {
  166. width: 16px;
  167. height: 16px;
  168. margin-right: 4px;
  169. vertical-align: middle;
  170. }
  171. .record-btn-layer .record-btn-2 {
  172. background: rgba(56, 86, 156, 1);
  173. }
  174. .prompt-layer {
  175. border-radius: 8px;
  176. background: rgba(56, 86, 156, 1);
  177. padding: 8px 16px;
  178. box-sizing: border-box;
  179. position: absolute;
  180. left: 50%;
  181. transform: translateX(-50%);
  182. }
  183. .prompt-layer::after {
  184. content: '';
  185. display: block;
  186. border: 6px solid rgba(0, 0, 0, 0);
  187. border-top-color: rgba(56, 86, 156, 1);
  188. position: absolute;
  189. bottom: -10px;
  190. left: 50%;
  191. transform: translateX(-50%);
  192. }
  193. .prompt-layer-1 {
  194. font-size: 12px;
  195. width: 128px;
  196. text-align: center;
  197. display: flex;
  198. flex-direction: column;
  199. align-items: center;
  200. justify-content: center;
  201. top: -240px;
  202. }
  203. .del {
  204. position: absolute;
  205. top: -200rpx;
  206. .img {
  207. width: 100rpx;
  208. }
  209. }
  210. .prompt-layer-1 .p {
  211. color: #000000;
  212. }
  213. .prompt-layer-1 .span {
  214. color: #fff;
  215. }
  216. .prompt-loader .em {}
  217. .prompt-loader {
  218. width: 96px;
  219. height: 20px;
  220. display: flex;
  221. align-items: center;
  222. justify-content: space-between;
  223. margin-bottom: 6px;
  224. }
  225. .prompt-loader .em {
  226. display: block;
  227. background: #fff;
  228. width: 1px;
  229. height: 10%;
  230. margin-right: 2.5px;
  231. float: left;
  232. }
  233. .prompt-loader .em:last-child {
  234. margin-right: 0px;
  235. }
  236. .prompt-loader .em:nth-child(1) {
  237. animation: load 2.5s 1.4s infinite linear;
  238. }
  239. .prompt-loader .em:nth-child(2) {
  240. animation: load 2.5s 1.2s infinite linear;
  241. }
  242. .prompt-loader .em:nth-child(3) {
  243. animation: load 2.5s 1s infinite linear;
  244. }
  245. .prompt-loader .em:nth-child(4) {
  246. animation: load 2.5s 0.8s infinite linear;
  247. }
  248. .prompt-loader .em:nth-child(5) {
  249. animation: load 2.5s 0.6s infinite linear;
  250. }
  251. .prompt-loader .em:nth-child(6) {
  252. animation: load 2.5s 0.4s infinite linear;
  253. }
  254. .prompt-loader .em:nth-child(7) {
  255. animation: load 2.5s 0.2s infinite linear;
  256. }
  257. .prompt-loader .em:nth-child(8) {
  258. animation: load 2.5s 0s infinite linear;
  259. }
  260. .prompt-loader .em:nth-child(9) {
  261. animation: load 2.5s 0.2s infinite linear;
  262. }
  263. .prompt-loader .em:nth-child(10) {
  264. animation: load 2.5s 0.4s infinite linear;
  265. }
  266. .prompt-loader .em:nth-child(11) {
  267. animation: load 2.5s 0.6s infinite linear;
  268. }
  269. .prompt-loader .em:nth-child(12) {
  270. animation: load 2.5s 0.8s infinite linear;
  271. }
  272. .prompt-loader .em:nth-child(13) {
  273. animation: load 2.5s 1s infinite linear;
  274. }
  275. .prompt-loader .em:nth-child(14) {
  276. animation: load 2.5s 1.2s infinite linear;
  277. }
  278. .prompt-loader .em:nth-child(15) {
  279. animation: load 2.5s 1.4s infinite linear;
  280. }
  281. @keyframes load {
  282. 0% {
  283. height: 10%;
  284. }
  285. 50% {
  286. height: 100%;
  287. }
  288. 100% {
  289. height: 10%;
  290. }
  291. }
  292. .prompt-layer-2 {
  293. // top: -540px;
  294. }
  295. .prompt-layer-2 .text {
  296. color: rgba(0, 0, 0, 1);
  297. font-size: 12px;
  298. }
  299. .record-btn {
  300. display: flex;
  301. flex-direction: column;
  302. justify-content: center;
  303. align-items: center;
  304. .text {
  305. margin-top: 20rpx;
  306. }
  307. }
  308. /deep/.u-popup__content {
  309. padding-bottom: 100rpx;
  310. background: linear-gradient(180deg, rgba(204, 204, 204, 0.95) 0%, rgba(203, 203, 203, 0.01) 100%) !important;
  311. border-radius: 50% 50% 0 0;
  312. }
  313. .record-layerP {
  314. position: relative;
  315. top: 50px;
  316. }
  317. </style>