search.vue 7.8 KB

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