footer-input.vue 9.0 KB

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