search.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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" :input_text="input_text"
  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. <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. <u-toast ref="uToast"></u-toast>
  28. </view>
  29. </template>
  30. <script>
  31. import dSearchLog from '@/uni_modules/d-search-log/components/d-search-log/d-search-log.vue'
  32. const recorderManager = uni.getRecorderManager();
  33. const innerAudioContext = uni.createInnerAudioContext();
  34. var init // 录制时长计时器
  35. var timer // 播放 录制倒计时
  36. export default {
  37. components: {
  38. "dSearchLog": dSearchLog
  39. },
  40. data() {
  41. return {
  42. duration: 2000, //录音最大值ms 60000/1分钟
  43. tempFilePath: '', //音频路径
  44. playStatus: 0, //录音播放状态 0:未播放 1:正在播放
  45. longPress: '1',
  46. tempFilePath: '',
  47. color_border: "#00aaff",
  48. search_list_hot: [],
  49. store_key: 'search_list',
  50. isRecorderManager: false,
  51. is_clock: true,
  52. startPoint: "",
  53. input_text:""
  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. that.isRecorderManager = false
  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. uni.showLoading({
  108. title:"正在识别"
  109. })
  110. that.$request.baseRequest('admin.unimall.certificateManagementInfo', 'speechRecognition', {
  111. voiceMessage: _file,
  112. }, failres => {
  113. console.log('res+++++', failres.errmsg)
  114. uni.hideLoading()
  115. uni.showToast({
  116. icon:"none",
  117. title: failres.errmsg,
  118. duration: 3000
  119. });
  120. }).then(res => {
  121. uni.hideLoading()
  122. console.log(res)
  123. if(res.data.text.length>10){
  124. var text = res.data.text.substring(0, 10)
  125. }else{
  126. var text = res.data.text
  127. }
  128. that.input_text = text
  129. // uni.setStorageSync('search_val', text);
  130. // uni.switchTab({
  131. // url: "/pages/cardHolder/search"
  132. // })
  133. })
  134. }
  135. recorderManager.stop()
  136. })
  137. },
  138. onClickDelAll() {},
  139. onSearchName(e) {
  140. if(e.length>10){
  141. var text = e.substring(0, 10)
  142. }else{
  143. var text = e
  144. }
  145. uni.setStorageSync('search_val', text);
  146. uni.switchTab({
  147. url: "/pages/cardHolder/cardHolder"
  148. })
  149. }
  150. }
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. .shqx {
  155. position: absolute;
  156. top: -100rpx;
  157. left: 0;
  158. right: 0;
  159. margin: auto;
  160. text-align: center;
  161. color: rgba(221, 221, 221, 1);
  162. }
  163. .record-box {
  164. width: 100%;
  165. position: relative;
  166. top: 80rpx;
  167. }
  168. .record-btn-layer {
  169. width: 100%;
  170. display: flex;
  171. justify-content: center;
  172. }
  173. .record-btn-layer button::after {
  174. border: none;
  175. }
  176. .record-btn-layer button {
  177. font-size: 14px;
  178. line-height: 38px;
  179. width: 100%;
  180. height: 38px;
  181. border-radius: 8px;
  182. text-align: center;
  183. background: rgba(56, 86, 156, 1);
  184. }
  185. .record-btn-layer button image {
  186. width: 16px;
  187. height: 16px;
  188. margin-right: 4px;
  189. vertical-align: middle;
  190. }
  191. .record-btn-layer .record-btn-2 {
  192. background: rgba(56, 86, 156, 1);
  193. }
  194. .prompt-layer {
  195. border-radius: 8px;
  196. background: rgba(56, 86, 156, 1);
  197. padding: 8px 16px;
  198. box-sizing: border-box;
  199. position: absolute;
  200. left: 50%;
  201. transform: translateX(-50%);
  202. }
  203. .prompt-layer::after {
  204. content: '';
  205. display: block;
  206. border: 6px solid rgba(0, 0, 0, 0);
  207. border-top-color: rgba(56, 86, 156, 1);
  208. position: absolute;
  209. bottom: -10px;
  210. left: 50%;
  211. transform: translateX(-50%);
  212. }
  213. .prompt-layer-1 {
  214. font-size: 12px;
  215. width: 128px;
  216. text-align: center;
  217. display: flex;
  218. flex-direction: column;
  219. align-items: center;
  220. justify-content: center;
  221. top: -240px;
  222. }
  223. .del {
  224. position: absolute;
  225. top: -200rpx;
  226. .img {
  227. width: 100rpx;
  228. }
  229. }
  230. .prompt-layer-1 .p {
  231. color: #000000;
  232. }
  233. .prompt-layer-1 .span {
  234. color: #fff;
  235. }
  236. .prompt-loader .em {}
  237. .prompt-loader {
  238. width: 96px;
  239. height: 20px;
  240. display: flex;
  241. align-items: center;
  242. justify-content: space-between;
  243. margin-bottom: 6px;
  244. }
  245. .prompt-loader .em {
  246. display: block;
  247. background: #fff;
  248. width: 1px;
  249. height: 10%;
  250. margin-right: 2.5px;
  251. float: left;
  252. }
  253. .prompt-loader .em:last-child {
  254. margin-right: 0px;
  255. }
  256. .prompt-loader .em:nth-child(1) {
  257. animation: load 2.5s 1.4s infinite linear;
  258. }
  259. .prompt-loader .em:nth-child(2) {
  260. animation: load 2.5s 1.2s infinite linear;
  261. }
  262. .prompt-loader .em:nth-child(3) {
  263. animation: load 2.5s 1s infinite linear;
  264. }
  265. .prompt-loader .em:nth-child(4) {
  266. animation: load 2.5s 0.8s infinite linear;
  267. }
  268. .prompt-loader .em:nth-child(5) {
  269. animation: load 2.5s 0.6s infinite linear;
  270. }
  271. .prompt-loader .em:nth-child(6) {
  272. animation: load 2.5s 0.4s infinite linear;
  273. }
  274. .prompt-loader .em:nth-child(7) {
  275. animation: load 2.5s 0.2s infinite linear;
  276. }
  277. .prompt-loader .em:nth-child(8) {
  278. animation: load 2.5s 0s infinite linear;
  279. }
  280. .prompt-loader .em:nth-child(9) {
  281. animation: load 2.5s 0.2s infinite linear;
  282. }
  283. .prompt-loader .em:nth-child(10) {
  284. animation: load 2.5s 0.4s infinite linear;
  285. }
  286. .prompt-loader .em:nth-child(11) {
  287. animation: load 2.5s 0.6s infinite linear;
  288. }
  289. .prompt-loader .em:nth-child(12) {
  290. animation: load 2.5s 0.8s infinite linear;
  291. }
  292. .prompt-loader .em:nth-child(13) {
  293. animation: load 2.5s 1s infinite linear;
  294. }
  295. .prompt-loader .em:nth-child(14) {
  296. animation: load 2.5s 1.2s infinite linear;
  297. }
  298. .prompt-loader .em:nth-child(15) {
  299. animation: load 2.5s 1.4s infinite linear;
  300. }
  301. @keyframes load {
  302. 0% {
  303. height: 10%;
  304. }
  305. 50% {
  306. height: 100%;
  307. }
  308. 100% {
  309. height: 10%;
  310. }
  311. }
  312. .prompt-layer-2 {
  313. // top: -540px;
  314. }
  315. .prompt-layer-2 .text {
  316. color: rgba(0, 0, 0, 1);
  317. font-size: 12px;
  318. }
  319. .record-btn {
  320. display: flex;
  321. flex-direction: column;
  322. justify-content: center;
  323. align-items: center;
  324. .text {
  325. margin-top: 20rpx;
  326. }
  327. }
  328. /deep/.u-popup__content {
  329. padding-bottom: 100rpx;
  330. // background: linear-gradient(180deg, rgba(204, 204, 204, 0.95) 0%, rgba(203, 203, 203, 0.01) 100%) !important;
  331. border-radius: 50% 50% 0 0;
  332. }
  333. .record-layerP {
  334. position: relative;
  335. top: 50px;
  336. }
  337. </style>