search.vue 8.0 KB

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