index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view @touchstart="drag_start"
  3. @touchmove.stop.prevent="moveStop"
  4. @touchmove="drag_hmove" v-if="show">
  5. <view class="ball" :class="typeClass"
  6. :style="'left:'+setX+'px;top :'+setY+'px;'" @tap="toModel">
  7. </view>
  8. <uni-popup ref="popup" type="alert">
  9. <view class="alert" v-if="onLine">
  10. <view class="alert-list">
  11. <view class="alert-item" v-if="voiceModel == 0" @tap="voiceModelTap(1)">
  12. <view class="alert-item-model">扬声器播放</view>
  13. </view>
  14. <view class="alert-item" v-else @tap="voiceModelTap(0)">
  15. <view class="alert-item-model">听筒播放</view>
  16. </view>
  17. <view class="hr"></view>
  18. <view class="alert-item" @tap="xiaMai(list_id,0)">
  19. <view class="alert-item-model"> 下麦并关闭收听</view>
  20. </view>
  21. <view class="hr"></view>
  22. <view class="alert-item" @tap="xiaMai(list_id)">
  23. <view class="alert-item-model">下麦</view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="alert" v-else>
  28. <view class="alert-list">
  29. <view class="alert-item" v-if="voiceModel == 1" @tap="voiceModelTap(0)">
  30. <view class="alert-item-model">扬声器播放</view>
  31. </view>
  32. <view class="alert-item" v-else @tap="voiceModelTap(1)">
  33. <view class="alert-item-model">听筒播放</view>
  34. </view>
  35. <view class="hr"></view>
  36. <view class="alert-item" @tap="closeVoice">
  37. <view class="alert-item-model">关闭收听</view>
  38. </view>
  39. </view>
  40. </view>
  41. <!--<uni-popup-alert title="温馨提示" :content="popuMsg" @confirm = "confirm"> </uni-popup-alert>-->
  42. </uni-popup>
  43. </view>
  44. </template>
  45. <script>
  46. import _data from '../../common/_data';
  47. import _get from '../../common/_get';
  48. import SDK from '../../common/tendenceImSdk';
  49. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  50. export default {
  51. props: {
  52. show: {
  53. type: Boolean,
  54. defualt: false
  55. },
  56. state:{
  57. type: Number,
  58. defualt: 3
  59. },
  60. list_id:{
  61. type: String,
  62. defualt: ""
  63. }
  64. },
  65. data() {
  66. return {
  67. start: [0, 0],
  68. voiceModel:0,
  69. onLine:0
  70. }
  71. },
  72. components:{
  73. uniPopup,
  74. },
  75. computed:{
  76. typeClass(){
  77. switch (true) {
  78. case this.state == 1:
  79. return 'shangmai bgred';
  80. case this.state == 2:
  81. return 'shangmai-ing bgblue';
  82. case this.state == 3:
  83. return 'shouting bgblue';
  84. case this.state == 4:
  85. return 'jingyin bgblue';
  86. default:
  87. return 'shangmai bgred';
  88. }
  89. },
  90. setX(){
  91. return this.X;
  92. },
  93. setY(){
  94. return this.Y;
  95. },
  96. setState(){
  97. return this.state;
  98. }
  99. },
  100. created() {
  101. this.setInfo();
  102. let _this = this;
  103. },
  104. methods: {
  105. closeVoice(){
  106. //关闭收听
  107. let _this = this;
  108. SDK.IMSDK.muteLocalAudio(0,function () {
  109. _this.setModel(4);
  110. _this.closeModel();
  111. });
  112. },
  113. closeModel(){
  114. if(this.$refs.popup){
  115. this.$refs.popup.close();
  116. }
  117. },
  118. voiceModelTap(val){
  119. let _this = this;
  120. console.log("使用扬声器")
  121. SDK.IMSDK.muteLocalAudio(1,function () { //开启声音
  122. SDK.IMSDK.setAudioRoute(val,function () { //设置扬声器模式
  123. if(val == 0){
  124. uni.showToast({
  125. title:'使用扬声器播放',
  126. icon:'none'
  127. })
  128. }else {
  129. uni.showToast({
  130. title:'使用听筒播放',
  131. icon:'none'
  132. })
  133. }
  134. _this.closeModel();
  135. _this.voiceModel = val;
  136. })
  137. });
  138. },
  139. xiaMai(list_id,mode = 1){
  140. let _this = this;
  141. console.log("下麦..........")
  142. _get.setVoiceRoomMsg({list_id:list_id,type:0},function (num) {
  143. //判断有几个人在麦上,如果有且只有一个人则同时下麦,如果大于1人则设置为听筒模式]
  144. console.log(num)
  145. if(num == 0){
  146. _this.closeVoiceRoom()
  147. }else {
  148. if(mode == 1){
  149. //禁言 收听
  150. _this.jingyanShouTing() //禁言 关闭收听
  151. }else {
  152. _this.jinyanJingyin();
  153. }
  154. }
  155. _this.closeModel()
  156. });
  157. },
  158. toModel(){
  159. switch (true) {
  160. case this.state == 1:
  161. //如果是在上麦模式打开则打开弹窗提示操作
  162. this.onLine = 1;
  163. this.$refs.popup.open();
  164. return 'shangmai';
  165. case this.state == 2:
  166. //如果是正在上麦则切换图片
  167. return 'shangmai-ing';
  168. case this.state == 3:
  169. //切换到收听图片
  170. this.onLine = 0;
  171. this.$refs.popup.open();
  172. return 'shouting';
  173. case this.state == 4:
  174. //切换到禁音图片
  175. this.setModel(3);
  176. //设置扬声器模式
  177. this.voiceModelTap(0)
  178. return 'jingyin';
  179. default:
  180. return 'shangmai';
  181. }
  182. },
  183. joinOnline(list_id,cb){
  184. //开启语音聊天
  185. let _this = this;
  186. SDK.IMSDK.muteRemoteAudio(_data.localData('voice_room_userid'),1,function () {
  187. _this.setModel(1);//加入
  188. _this.onLine = 1; //在线上
  189. _data.localData('voice_room_type',1); //是否在麦
  190. _this.voiceModelTap(1)
  191. _get.setVoiceRoomMsg({list_id:list_id,type:1},function (ret) {
  192. if(cb)cb()
  193. });
  194. });
  195. },
  196. setModel(state){
  197. //设置模式
  198. this.$emit('setState',{state:state})
  199. },
  200. joinRoom(list_id,cb){
  201. let _this = this;
  202. // _get.joinVoiceRoom({list_id:list_id},function (ret) {
  203. // SDK.IMSDK.joinRoom(ret,function (sdk_ret) {
  204. // })
  205. // _this.setModel(1);
  206. // _data.localData('voice_room_userid',ret.userid);
  207. // _data.localData('voice_room_type',1); //是否在麦]
  208. // _this.voiceModelTap(1)
  209. // _get.setVoiceRoomMsg({list_id:list_id,type:1},function () {
  210. // if(cb)cb();
  211. // });
  212. // })
  213. },
  214. closeVoiceRoom(){
  215. //静默退出聊天室
  216. this.setModel(-1)
  217. this.$emit('closeServing',{});
  218. _data.localData('voice_room_userid',null);
  219. SDK.IMSDK.exitRoom(function () {
  220. })
  221. },
  222. memberJoin(user_id,list_id,cb){
  223. let _this = this;
  224. _get.memberjoinVoiceRoom({list_id:list_id},function (ret) {
  225. SDK.IMSDK.joinRoom(ret,function (sdk_ret) {
  226. })
  227. _this.jinyanJingyin(cb)
  228. _data.localData('voice_room_userid',ret.userid);
  229. _data.localData('voice_room_type',0); //是否在麦
  230. _this.voiceModelTap(1)
  231. })
  232. },
  233. jinyanJingyin(cb){ //禁言禁音
  234. let _this = this;
  235. SDK.IMSDK.muteRemoteAudio(_data.localData('voice_room_userid'),0,function () {
  236. _this.setModel(4);//加入之后直接禁言
  237. SDK.IMSDK.muteLocalAudio(0); //禁音
  238. if(cb)cb();
  239. });
  240. },
  241. jingyanShouTing(cb){ //禁言收听
  242. let _this = this;
  243. SDK.IMSDK.muteRemoteAudio(_data.localData('voice_room_userid'),0,function () {
  244. _this.setModel(3);//加入之后直接禁言
  245. SDK.IMSDK.muteLocalAudio(1); //s收听
  246. if(cb)cb();
  247. });
  248. },
  249. setInfo(){
  250. let dragInfo = getApp().globalData['dragInfo']
  251. this.X = dragInfo.moveX;
  252. this.Y = dragInfo.moveY;
  253. },
  254. moveStop() {
  255. },
  256. drag_start(event) {
  257. this.start[0] = event.touches[0].clientX - event.target.offsetLeft;
  258. this.start[1] = event.touches[0].clientY - event.target.offsetTop;
  259. },
  260. setGlobleX(x){
  261. this.X = x;
  262. let dragInfo = getApp().globalData['dragInfo'];
  263. dragInfo.moveX = x;
  264. getApp().globalData['dragInfo'] = dragInfo;
  265. },
  266. setGlobleY(y){
  267. this.Y = y;
  268. let dragInfo = getApp().globalData['dragInfo'];
  269. dragInfo.moveY = y;
  270. getApp().globalData['dragInfo'] = dragInfo;
  271. },
  272. drag_hmove(event) {
  273. let sysInfo = uni.getSystemInfoSync();
  274. const maxWidth = sysInfo.windowWidth - 50;//屏幕宽度减去悬浮框宽高
  275. const maxHeight = sysInfo.windowHeight;
  276. let tag = event.touches;
  277. if (tag[0].clientX <= 50) { //屏幕x限制
  278. this.setGlobleX(0);
  279. } else if (tag[0].clientX > maxWidth) {
  280. this.setGlobleX(maxWidth);
  281. } else {
  282. let x = tag[0].clientX - this.start[0];
  283. this.setGlobleX(x);
  284. }
  285. if (tag[0].clientY <= 25) { //屏幕y限制
  286. this.setGlobleY(0);
  287. } else if (tag[0].clientY > maxHeight) {
  288. this.setGlobleY(maxHeight);
  289. } else {
  290. let y = tag[0].clientY - this.start[1];
  291. this.setGlobleY(y);
  292. }
  293. }
  294. }
  295. }
  296. </script>
  297. <style lang="less">
  298. .ball {
  299. width: 50px;
  300. height: 50px;
  301. border-radius: 50%;
  302. z-index: 10000;
  303. top: 140px;
  304. position: fixed;
  305. }
  306. .bgred{
  307. background: red;
  308. }
  309. .bgblue{
  310. background: #00b1f7;
  311. }
  312. .shangmai{
  313. background-image: url("/static/theme/default/shangmai.png");
  314. background-size:40px 40px;
  315. background-repeat:no-repeat;
  316. background-position:center;
  317. }
  318. .shouting{
  319. background-image: url("/static/theme/default/laba.png");
  320. background-size:30px 30px;
  321. background-repeat:no-repeat;
  322. background-position:center;
  323. }
  324. .jingyin{
  325. background-image: url("/static/theme/default/jingyin.png");
  326. background-size:20px 20px;
  327. background-repeat:no-repeat;
  328. background-position:center;
  329. }
  330. .alert{
  331. width: 300px;
  332. background-color: #fff;
  333. }
  334. .alert-list{
  335. display: flex;
  336. flex-direction: column;
  337. }
  338. .alert-item{
  339. height: 50px;
  340. display: flex;
  341. justify-content: space-between;
  342. align-items: center;
  343. padding-left: 20px;
  344. }
  345. .alert-item-model{
  346. }
  347. .hr{
  348. height: 1upx;
  349. width:95%;
  350. margin: 0 auto;
  351. background-color: #e1e1e1;
  352. }
  353. </style>