footer-input.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <view>
  3. <!-- 底部输入栏 -->
  4. <view :style='{bottom:bottomHeight+"px;"}' class="input-box" :class="popupLayerClass" @touchmove.stop.prevent="discard">
  5. <!-- H5下不能录音,输入栏布局改动一下 -->
  6. <!-- #ifndef H5 -->
  7. <view class="voice">
  8. <view class="cuIcon-notification" :class="isVoice?'cuIcon-community':'cuIcon-notification'" @tap="switchVoice"></view>
  9. </view>
  10. <!-- #endif -->
  11. <!-- #ifdef H5 -->
  12. <view class="more" @tap="showMore">
  13. <view class="cuIcon-roundadd"></view>
  14. </view>
  15. <!-- #endif -->
  16. <!-- 录音 -->
  17. <view class="textbox" >
  18. <view class="voice-mode" :class="[isVoice?'':'hidden',recording?'recording':'']" @touchstart="voiceBegin"
  19. @touchmove.stop.prevent="voiceIng" @touchend="voiceEnd" @touchcancel="voiceCancel">{{voiceTis}}</view>
  20. <view class="text-mode" :class="isVoice?'hidden':''">
  21. <view class="box">
  22. <textarea id='textarea' :confirm-type="'send'" :confirm-hold="false" :show-confirm-bar="false" @confirm="sendMsg(0, textMsg)"
  23. auto-height="true" :adjust-position='false' :disabled="disabledSay===1" :hold-keyboard='true'
  24. v-model="textMsg" @focus="textareaFocus" @blur='textareaBlur' />
  25. </view>
  26. <view class="em" @tap.stop="chooseEmoji(e)">
  27. <view class="cuIcon-emoji"></view>
  28. </view>
  29. </view>
  30. </view>
  31. <view v-if='!show' class="more" @tap="showMore">
  32. <view class="cuIcon-roundadd"></view>
  33. </view>
  34. <button v-else @tap="btnSend(0, textMsg)" class="cu-btn bg-green shadow textmsg">发送</button>
  35. <!-- <view class='textmsg' v-show='show'>
  36. <view @tap="">发送</view>
  37. </view> -->
  38. <!-- #ifdef H5 -->
  39. <view class="send" @tap="sendMsg(0, textMsg)" :class="isVoice?'hidden':''">
  40. <view class="iconfont icontuiguang-weixuan"></view>
  41. </view>
  42. <!-- #endif -->
  43. </view>
  44. <!-- 录音UI效果 -->
  45. <view class="record" :class="recording?'':'hidden'">
  46. <view class="ing" :class="willStop?'hidden':''">
  47. <view class="voice_an">
  48. <view class="voice_an_icon">
  49. <view id="one" class="wave"></view>
  50. <view id="two" class="wave"></view>
  51. <view id="three" class="wave"></view>
  52. <view id="four" class="wave"></view>
  53. <view id="five" class="wave"></view>
  54. <view id="six" class="wave"></view>
  55. <view id="seven" class="wave"></view>
  56. </view>
  57. </view>
  58. </view>
  59. <view class="cancel" :class="willStop?'':'hidden'"><view class="icon chehui" ></view></view>
  60. <view class="tis" :class="willStop?'change':''">{{recordTis}}</view>
  61. </view>
  62. <!-- <v-keyboard ref="keyboard" :disorderly="false" @typing="typing" @enter="enter"></v-keyboard> -->
  63. </view>
  64. </template>
  65. <script>
  66. export default {
  67. name:'footer-input',
  68. components: { } ,
  69. props: {
  70. inputOffsetBottom: {
  71. type: Number,
  72. default: 0
  73. },
  74. isVoice: {
  75. type: Boolean,
  76. default: false
  77. },
  78. focus: {
  79. type: Boolean,
  80. default: false
  81. },
  82. disabledSay: {
  83. type: Number,
  84. default: 0
  85. },
  86. popupLayerClass: {
  87. type: String,
  88. default: ''
  89. },
  90. textMsg2:{
  91. type:String,
  92. default:''
  93. }
  94. },
  95. data() {
  96. return {
  97. placeholder: '',
  98. initPoint:{identifier:0,Y:0},
  99. //录音相关参数
  100. // #ifndef H5
  101. //H5不能录音
  102. RECORDER:uni.getRecorderManager(),
  103. // #endif
  104. recordTis:"手指上滑 取消发送",
  105. voiceTis:'按住 说话',
  106. recording:false,
  107. willStop:false,
  108. recordTimer:null,
  109. recordLength:0,
  110. textMsg:'',
  111. bottomHeight:0,
  112. show:false
  113. };
  114. },
  115. watch:{
  116. textMsg:function(v){
  117. console.log(v)
  118. if(v.length>0){
  119. this.show=true
  120. }else{
  121. this.show=false
  122. }
  123. this.$emit('textMsgFunc',v)
  124. if(this.textMsg.indexOf('@')!=-1){
  125. if (this.chatObj.chatType==1){
  126. this.$u.route({
  127. url:'pageC/chat/remind',
  128. params:{ msg :this.textMsg }
  129. });
  130. }
  131. }
  132. },
  133. textMsg2:function(v){
  134. this.textMsg = v
  135. }
  136. },
  137. mounted() {
  138. // #ifndef H5
  139. this.RECORDER.onStart((e)=>{
  140. this.recordBegin(e);
  141. })
  142. //录音结束事件
  143. this.RECORDER.onStop((e)=>{
  144. this.recordEnd(e);
  145. })
  146. // #endif
  147. },
  148. methods:{
  149. discard(){
  150. return;
  151. },
  152. btnSend(index, msg){
  153. uni.hideKeyboard()
  154. console.log('this.focus',this.focus)
  155. this.focus=false
  156. this.sendMsg(index, msg)
  157. },
  158. // sendmsg(){
  159. // console.log(uni.createSelectorQuery().select("#iamnode"))
  160. // },
  161. sendMsg(index, msg){
  162. this.bottomHeight=0
  163. this.show=false
  164. this.$emit('sendMsg', index,msg);
  165. this.textMsg = ''
  166. },
  167. textareaBlur(e){
  168. console.log('textareaBlur',e)
  169. this.bottomHeight=0
  170. },
  171. textareaFocus(e){
  172. this.$refs.keyboard.activate()
  173. console.log('textareaFocus',this.focus)
  174. this.bottomHeight=e.detail.height
  175. this.$emit('textareaFocus', true);
  176. },
  177. // 选择表情
  178. chooseEmoji(e){
  179. e.preventDefault();
  180. this.bottomHeight=0
  181. uni.hideKeyboard()
  182. this.$emit('chooseEmoji', true);
  183. },
  184. // 切换语音/文字输入
  185. switchVoice(){
  186. this.$emit('switchVoice', true);
  187. },
  188. // 录音开始
  189. voiceBegin(e){
  190. if(e.touches.length>1){
  191. return ;
  192. }
  193. this.recording = true;
  194. this.initPoint.Y = e.touches[0].clientY;
  195. this.initPoint.identifier = e.touches[0].identifier;
  196. this.RECORDER.start({format:"mp3"});//录音开始,
  197. },
  198. //录音开始UI效果
  199. recordBegin(e){
  200. this.recording = true;
  201. this.voiceTis='松开 结束';
  202. this.recordLength = 0;
  203. this.recordTimer = setInterval(()=>{
  204. this.recordLength++;
  205. },1000)
  206. },
  207. // 录音被打断
  208. voiceCancel(){
  209. this.recording = false;
  210. this.voiceTis='按住 说话';
  211. this.recordTis = '手指上滑 取消发送'
  212. this.willStop = true;//不发送录音
  213. this.RECORDER.stop();//录音结束
  214. },
  215. // 录音中(判断是否触发上滑取消发送)
  216. voiceIng(e){
  217. if(!this.recording){
  218. return;
  219. }
  220. let touche = e.touches[0];
  221. //上滑一个导航栏的高度触发上滑取消发送
  222. if(this.initPoint.Y - touche.clientY>=uni.upx2px(100)){
  223. this.willStop = true;
  224. this.recordTis = '松开手指 取消发送'
  225. }else{
  226. this.willStop = false;
  227. this.recordTis = '手指上滑 取消发送'
  228. }
  229. },
  230. // 结束录音
  231. voiceEnd(e){
  232. if(!this.recording){
  233. return;
  234. }
  235. this.recording = false;
  236. this.voiceTis='按住 说话';
  237. this.recordTis = '手指上滑 取消发送'
  238. this.RECORDER.stop();//录音结束
  239. },
  240. //录音结束(回调文件)
  241. recordEnd(e){
  242. console.log('--------到此一游------1-')
  243. clearInterval(this.recordTimer);
  244. if(this.recordLength == 0){
  245. this.$api.msg("录音时长过短")
  246. return
  247. }
  248. if(!this.willStop){
  249. let tempFilePaths =e.tempFilePath;
  250. let that=this;
  251. uni.uploadFile({
  252. url: this.$uploadUrl, //仅为示例,非真实的接口地址
  253. filePath: tempFilePaths,
  254. header: {
  255. 'merchcode':'md5'
  256. },
  257. name: 'file',
  258. formData: {
  259. 'user': 'test'
  260. },
  261. success: (res) => {
  262. let data =JSON.parse(res.data)
  263. let msg = {
  264. length:0,
  265. url:data.data
  266. }
  267. let min = parseInt(this.recordLength/60);
  268. let sec = this.recordLength%60;
  269. min = min<10?'0'+min:min;
  270. sec = sec<10?'0'+sec:sec;
  271. msg.length = min+':'+sec;
  272. console.log('--------到此一游------2-')
  273. this.$emit('sendMsg', 3,JSON.stringify(msg));
  274. }
  275. });
  276. }else{
  277. // console.log('取消发送录音');
  278. }
  279. this.willStop = false;
  280. console.log('--------到此一游------3-')
  281. },
  282. //更多功能(点击+弹出)
  283. showMore(){
  284. this.$emit('showMore', true);
  285. },
  286. // 打开抽屉
  287. openDrawer(){
  288. this.$emit('openDrawer', true);
  289. },
  290. // 隐藏抽屉
  291. hideDrawer(){
  292. this.$emit('hideDrawer', true);
  293. },
  294. }
  295. }
  296. </script>
  297. <style lang="scss" scoped>
  298. @import "@/pageC/chat/style.scss";
  299. [class^='cuIcon']{
  300. font-size:50rpx;
  301. }
  302. .input-box{
  303. position:fixed;
  304. }
  305. .textmsg{
  306. width: 160upx;
  307. padding: 5upx;
  308. margin-top: 10upx
  309. }
  310. .textmsg view{
  311. border: 1px solid;
  312. background: #39b54a;
  313. color: #fff;
  314. padding: 10px;
  315. }
  316. .voice_an_icon{
  317. position: relative;
  318. }
  319. .voice_an_icon .wave:nth-child(1){
  320. left: 0px;
  321. animation: musicWave 0.5s infinite linear both alternate;
  322. }
  323. .voice_an_icon .wave:nth-child(2){
  324. left: 10px;
  325. animation: musicWave 0.2s infinite linear both alternate;
  326. }
  327. .voice_an_icon .wave:nth-child(3){
  328. left: 20px;
  329. animation: musicWave 0.6s infinite linear both alternate;
  330. }
  331. .voice_an_icon .wave:nth-child(4){
  332. left: 40px;
  333. animation: musicWave 0.3s infinite linear both alternate;
  334. }
  335. .voice_an_icon .wave:nth-child(5){
  336. left: 50px;
  337. animation: musicWave 0.4s infinite linear both alternate;
  338. }
  339. .voice_an_icon .wave:nth-child(6){
  340. left: 50px;
  341. animation: musicWave 0.7s infinite linear both alternate;
  342. }
  343. .voice_an_icon .wave:nth-child(7){
  344. left: 50px;
  345. animation: musicWave 0.1s infinite linear both alternate;
  346. }
  347. @keyframes musicWave{
  348. 0%{
  349. height: 10px;
  350. }
  351. 100%{
  352. height: 30px;
  353. }
  354. }
  355. </style>