search.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <view style='background:#fff;height:100vh;'>
  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/mic.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.tourism.productManagement', '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/find/find"
  148. })
  149. }
  150. }
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. /deep/.dSLComVue .dSLComVueTop {
  155. width:100%;
  156. margin-left:20rpx;
  157. height:80rpx;
  158. }
  159. /deep/.dSLComVue1 .dSLComVueLog{
  160. width:95%;
  161. }
  162. .shqx {
  163. position: absolute;
  164. top: -100rpx;
  165. left: 0;
  166. right: 0;
  167. margin: auto;
  168. text-align: center;
  169. color: rgba(221, 221, 221, 1);
  170. }
  171. .record-box {
  172. width: 100%;
  173. position: relative;
  174. top: 80rpx;
  175. }
  176. .record-btn-layer {
  177. width: 100%;
  178. display: flex;
  179. justify-content: center;
  180. }
  181. .record-btn-layer button::after {
  182. border: none;
  183. }
  184. .record-btn-layer button {
  185. font-size: 14px;
  186. line-height: 38px;
  187. width: 100%;
  188. height: 38px;
  189. border-radius: 8px;
  190. text-align: center;
  191. background: rgba(56, 86, 156, 1);
  192. }
  193. .record-btn-layer button image {
  194. width: 16px;
  195. height: 16px;
  196. margin-right: 4px;
  197. vertical-align: middle;
  198. }
  199. .record-btn-layer .record-btn-2 {
  200. background: rgba(56, 86, 156, 1);
  201. }
  202. .prompt-layer {
  203. border-radius: 8px;
  204. background: rgba(56, 86, 156, 1);
  205. padding: 8px 16px;
  206. box-sizing: border-box;
  207. position: absolute;
  208. left: 50%;
  209. transform: translateX(-50%);
  210. }
  211. .prompt-layer::after {
  212. content: '';
  213. display: block;
  214. border: 6px solid rgba(0, 0, 0, 0);
  215. border-top-color: rgba(56, 86, 156, 1);
  216. position: absolute;
  217. bottom: -10px;
  218. left: 50%;
  219. transform: translateX(-50%);
  220. }
  221. .prompt-layer-1 {
  222. font-size: 12px;
  223. width: 128px;
  224. text-align: center;
  225. display: flex;
  226. flex-direction: column;
  227. align-items: center;
  228. justify-content: center;
  229. top: -240px;
  230. }
  231. .del {
  232. position: absolute;
  233. top: -200rpx;
  234. .img {
  235. width: 100rpx;
  236. }
  237. }
  238. .prompt-layer-1 .p {
  239. color: #000000;
  240. }
  241. .prompt-layer-1 .span {
  242. color: #fff;
  243. }
  244. .prompt-loader .em {}
  245. .prompt-loader {
  246. width: 96px;
  247. height: 20px;
  248. display: flex;
  249. align-items: center;
  250. justify-content: space-between;
  251. margin-bottom: 6px;
  252. }
  253. .prompt-loader .em {
  254. display: block;
  255. background: #fff;
  256. width: 1px;
  257. height: 10%;
  258. margin-right: 2.5px;
  259. float: left;
  260. }
  261. .prompt-loader .em:last-child {
  262. margin-right: 0px;
  263. }
  264. .prompt-loader .em:nth-child(1) {
  265. animation: load 2.5s 1.4s infinite linear;
  266. }
  267. .prompt-loader .em:nth-child(2) {
  268. animation: load 2.5s 1.2s infinite linear;
  269. }
  270. .prompt-loader .em:nth-child(3) {
  271. animation: load 2.5s 1s infinite linear;
  272. }
  273. .prompt-loader .em:nth-child(4) {
  274. animation: load 2.5s 0.8s infinite linear;
  275. }
  276. .prompt-loader .em:nth-child(5) {
  277. animation: load 2.5s 0.6s infinite linear;
  278. }
  279. .prompt-loader .em:nth-child(6) {
  280. animation: load 2.5s 0.4s infinite linear;
  281. }
  282. .prompt-loader .em:nth-child(7) {
  283. animation: load 2.5s 0.2s infinite linear;
  284. }
  285. .prompt-loader .em:nth-child(8) {
  286. animation: load 2.5s 0s infinite linear;
  287. }
  288. .prompt-loader .em:nth-child(9) {
  289. animation: load 2.5s 0.2s infinite linear;
  290. }
  291. .prompt-loader .em:nth-child(10) {
  292. animation: load 2.5s 0.4s infinite linear;
  293. }
  294. .prompt-loader .em:nth-child(11) {
  295. animation: load 2.5s 0.6s infinite linear;
  296. }
  297. .prompt-loader .em:nth-child(12) {
  298. animation: load 2.5s 0.8s infinite linear;
  299. }
  300. .prompt-loader .em:nth-child(13) {
  301. animation: load 2.5s 1s infinite linear;
  302. }
  303. .prompt-loader .em:nth-child(14) {
  304. animation: load 2.5s 1.2s infinite linear;
  305. }
  306. .prompt-loader .em:nth-child(15) {
  307. animation: load 2.5s 1.4s infinite linear;
  308. }
  309. @keyframes load {
  310. 0% {
  311. height: 10%;
  312. }
  313. 50% {
  314. height: 100%;
  315. }
  316. 100% {
  317. height: 10%;
  318. }
  319. }
  320. .prompt-layer-2 {
  321. // top: -540px;
  322. }
  323. .prompt-layer-2 .text {
  324. color: rgba(0, 0, 0, 1);
  325. font-size: 12px;
  326. }
  327. .record-btn {
  328. display: flex;
  329. flex-direction: column;
  330. justify-content: center;
  331. align-items: center;
  332. .text {
  333. margin-top: 20rpx;
  334. }
  335. }
  336. /deep/.u-popup__content {
  337. padding-bottom: 100rpx;
  338. // background: linear-gradient(180deg, rgba(204, 204, 204, 0.95) 0%, rgba(203, 203, 203, 0.01) 100%) !important;
  339. border-radius: 50% 50% 0 0;
  340. }
  341. .record-layerP {
  342. position: relative;
  343. top: 50px;
  344. }
  345. </style>