search.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. <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. };
  54. },
  55. onLoad(options) {
  56. if (options.mic == 1) {
  57. this.isRecorderManager = true
  58. }
  59. },
  60. methods: {
  61. onSearchvoice(e){
  62. this.isRecorderManager = true
  63. },
  64. handleTouchMove: function(e) {
  65. console.log("滑动")
  66. if (Math.abs(e.touches[e.touches.length - 1].clientY - this.startPoint.clientY) > 35) {
  67. this.is_clock = false
  68. } else {
  69. this.is_clock = true
  70. }
  71. },
  72. longpressBtn(e) {
  73. this.longPress = '2';
  74. this.is_clock = true,
  75. console.log(e);
  76. this.startPoint = e.touches[0],
  77. recorderManager.onStop((res) => {
  78. console.log("录音结束")
  79. this.tempFilePath = res.tempFilePath;
  80. })
  81. const options = {
  82. duration: this.duration, // 指定录音的时长,单位 ms
  83. sampleRate: 16000, // 采样率
  84. numberOfChannels: 1, // 录音通道数
  85. encodeBitRate: 96000, // 编码码率
  86. // format: 'mp3', // 音频格式,有效值 aac/mp3
  87. frameSize: 10, // 指定帧大小,单位 KB
  88. }
  89. recorderManager.start(options);
  90. // 监听音频开始事件
  91. recorderManager.onStart((res) => {
  92. console.log(res)
  93. })
  94. },
  95. touchendBtn() {
  96. console.log("录音结束")
  97. let that = this
  98. this.longPress = '1';
  99. recorderManager.onStop((res) => {
  100. this.tempFilePath = res.tempFilePath
  101. let _file = ''
  102. if (that.is_clock) {
  103. _file = uni.getFileSystemManager().readFileSync(res.tempFilePath, "base64")
  104. console.log(_file)
  105. that.$request.baseRequest('admin.unimall.certificateManagementInfo', 'speechRecognition', {
  106. voiceMessage: _file,
  107. }, failres => {
  108. console.log('res+++++', failres.errmsg)
  109. uni.showToast({
  110. icon:"none",
  111. title: failres.errmsg,
  112. duration: 3000
  113. });
  114. }).then(res => {
  115. uni.hideLoading()
  116. console.log(res)
  117. if(res.data.text.length>10){
  118. var text = res.data.text.substring(0, 10)
  119. }else{
  120. var text = res.data.text
  121. }
  122. uni.setStorageSync('search_val', text);
  123. uni.switchTab({
  124. url: "/pages/cardHolder/cardHolder"
  125. })
  126. })
  127. }
  128. recorderManager.stop()
  129. })
  130. },
  131. onClickDelAll() {},
  132. onSearchName(e) {
  133. if(e.length>10){
  134. var text = e.substring(0, 10)
  135. }else{
  136. var text = e
  137. }
  138. uni.setStorageSync('search_val', text);
  139. uni.switchTab({
  140. url: "/pages/cardHolder/cardHolder"
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .shqx {
  148. position: absolute;
  149. top: -100rpx;
  150. left: 0;
  151. right: 0;
  152. margin: auto;
  153. text-align: center;
  154. color: rgba(221, 221, 221, 1);
  155. }
  156. .record-box {
  157. width: 100%;
  158. position: relative;
  159. top: 80rpx;
  160. }
  161. .record-btn-layer {
  162. width: 100%;
  163. display: flex;
  164. justify-content: center;
  165. }
  166. .record-btn-layer button::after {
  167. border: none;
  168. }
  169. .record-btn-layer button {
  170. font-size: 14px;
  171. line-height: 38px;
  172. width: 100%;
  173. height: 38px;
  174. border-radius: 8px;
  175. text-align: center;
  176. background: rgba(56, 86, 156, 1);
  177. }
  178. .record-btn-layer button image {
  179. width: 16px;
  180. height: 16px;
  181. margin-right: 4px;
  182. vertical-align: middle;
  183. }
  184. .record-btn-layer .record-btn-2 {
  185. background: rgba(56, 86, 156, 1);
  186. }
  187. .prompt-layer {
  188. border-radius: 8px;
  189. background: rgba(56, 86, 156, 1);
  190. padding: 8px 16px;
  191. box-sizing: border-box;
  192. position: absolute;
  193. left: 50%;
  194. transform: translateX(-50%);
  195. }
  196. .prompt-layer::after {
  197. content: '';
  198. display: block;
  199. border: 6px solid rgba(0, 0, 0, 0);
  200. border-top-color: rgba(56, 86, 156, 1);
  201. position: absolute;
  202. bottom: -10px;
  203. left: 50%;
  204. transform: translateX(-50%);
  205. }
  206. .prompt-layer-1 {
  207. font-size: 12px;
  208. width: 128px;
  209. text-align: center;
  210. display: flex;
  211. flex-direction: column;
  212. align-items: center;
  213. justify-content: center;
  214. top: -240px;
  215. }
  216. .del {
  217. position: absolute;
  218. top: -200rpx;
  219. .img {
  220. width: 100rpx;
  221. }
  222. }
  223. .prompt-layer-1 .p {
  224. color: #000000;
  225. }
  226. .prompt-layer-1 .span {
  227. color: #fff;
  228. }
  229. .prompt-loader .em {}
  230. .prompt-loader {
  231. width: 96px;
  232. height: 20px;
  233. display: flex;
  234. align-items: center;
  235. justify-content: space-between;
  236. margin-bottom: 6px;
  237. }
  238. .prompt-loader .em {
  239. display: block;
  240. background: #fff;
  241. width: 1px;
  242. height: 10%;
  243. margin-right: 2.5px;
  244. float: left;
  245. }
  246. .prompt-loader .em:last-child {
  247. margin-right: 0px;
  248. }
  249. .prompt-loader .em:nth-child(1) {
  250. animation: load 2.5s 1.4s infinite linear;
  251. }
  252. .prompt-loader .em:nth-child(2) {
  253. animation: load 2.5s 1.2s infinite linear;
  254. }
  255. .prompt-loader .em:nth-child(3) {
  256. animation: load 2.5s 1s infinite linear;
  257. }
  258. .prompt-loader .em:nth-child(4) {
  259. animation: load 2.5s 0.8s infinite linear;
  260. }
  261. .prompt-loader .em:nth-child(5) {
  262. animation: load 2.5s 0.6s infinite linear;
  263. }
  264. .prompt-loader .em:nth-child(6) {
  265. animation: load 2.5s 0.4s infinite linear;
  266. }
  267. .prompt-loader .em:nth-child(7) {
  268. animation: load 2.5s 0.2s infinite linear;
  269. }
  270. .prompt-loader .em:nth-child(8) {
  271. animation: load 2.5s 0s infinite linear;
  272. }
  273. .prompt-loader .em:nth-child(9) {
  274. animation: load 2.5s 0.2s infinite linear;
  275. }
  276. .prompt-loader .em:nth-child(10) {
  277. animation: load 2.5s 0.4s infinite linear;
  278. }
  279. .prompt-loader .em:nth-child(11) {
  280. animation: load 2.5s 0.6s infinite linear;
  281. }
  282. .prompt-loader .em:nth-child(12) {
  283. animation: load 2.5s 0.8s infinite linear;
  284. }
  285. .prompt-loader .em:nth-child(13) {
  286. animation: load 2.5s 1s infinite linear;
  287. }
  288. .prompt-loader .em:nth-child(14) {
  289. animation: load 2.5s 1.2s infinite linear;
  290. }
  291. .prompt-loader .em:nth-child(15) {
  292. animation: load 2.5s 1.4s infinite linear;
  293. }
  294. @keyframes load {
  295. 0% {
  296. height: 10%;
  297. }
  298. 50% {
  299. height: 100%;
  300. }
  301. 100% {
  302. height: 10%;
  303. }
  304. }
  305. .prompt-layer-2 {
  306. // top: -540px;
  307. }
  308. .prompt-layer-2 .text {
  309. color: rgba(0, 0, 0, 1);
  310. font-size: 12px;
  311. }
  312. .record-btn {
  313. display: flex;
  314. flex-direction: column;
  315. justify-content: center;
  316. align-items: center;
  317. .text {
  318. margin-top: 20rpx;
  319. }
  320. }
  321. /deep/.u-popup__content {
  322. padding-bottom: 100rpx;
  323. // background: linear-gradient(180deg, rgba(204, 204, 204, 0.95) 0%, rgba(203, 203, 203, 0.01) 100%) !important;
  324. border-radius: 50% 50% 0 0;
  325. }
  326. .record-layerP {
  327. position: relative;
  328. top: 50px;
  329. }
  330. </style>