search.vue 8.0 KB

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