userset.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <view class="page">
  3. <ul class="profile" style="height: 40px;line-height: 40px;">
  4. <li>群名片:</li>
  5. <li>
  6. <button class="btn" @tap="sub_rename()">修改</button>
  7. <input type="text" class="input1" id="nickname" style="width: 100px;text-align:left;float: right;" v-model="group_user.nickname" maxlength="10" />
  8. </li>
  9. </ul>
  10. <block v-if="this.thistype=='owner'">
  11. <ul class="profile" style="height: 40px;line-height: 40px;">
  12. <li>禁言:</li>
  13. <li>
  14. <switch :checked="group_user.is_deny" @change="user_setmenu('deny')" style="vertical-align: middle;" />
  15. </li>
  16. </ul>
  17. <ul class="profile" style="height: 40px;line-height: 40px;">
  18. <li>设为管理:</li>
  19. <li>
  20. <switch :checked="group_user.type=='manager'" @change="user_setmenu('manager')" style="vertical-align: middle;" />
  21. </li>
  22. </ul>
  23. <ul class="profile" @tap="user_setmenu('delete')" style="height: 40px;line-height: 40px;text-align: center;color: #007AFF;">
  24. 踢出该群
  25. </ul>
  26. </block>
  27. <block v-if="this.thistype=='manager' && group_user.type=='user'">
  28. <ul class="profile" style="height: 40px;line-height: 40px;">
  29. <li>禁言:</li>
  30. <li>
  31. <switch :checked="group_user.is_deny" @change="user_setmenu('deny')" style="vertical-align: middle;" />
  32. </li>
  33. </ul>
  34. <ul class="profile" @tap="user_setmenu('delete')" style="height: 40px;line-height: 40px;text-align: center;color: #007AFF;">
  35. 踢出该群
  36. </ul>
  37. </block>
  38. <logoutwords v-if="showlogout" :item="logoutinfo" @sub="logout_sub" @cancle="showlogout=false;" ></logoutwords>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. mapState
  44. } from 'vuex';
  45. import logoutwords from '../../components/logout_words.vue'
  46. import api from '../../library/index.js'
  47. import http from '../../library/http.js'
  48. export default {
  49. components:{
  50. logoutwords
  51. },
  52. data() {
  53. return {
  54. system:uni.getStorageSync('system'),
  55. userinfo:[],
  56. group_id:0,
  57. userid:0,
  58. myid:uni.getStorageSync('access_token'),
  59. group_users:[],
  60. group_user:[],
  61. thistype:'',
  62. usertype:'',
  63. showlogout:false,
  64. logoutinfo:{},
  65. }
  66. },
  67. computed: {
  68. },
  69. methods: {
  70. user_setmenu(type){
  71. var user=this.group_user;
  72. var isin=0;
  73. var nickname=user.nickname;
  74. for(var i=0;i<this.group_users.length;i++){
  75. if(this.group_users[i].id==this.userid){
  76. isin=1;
  77. break;
  78. }
  79. }
  80. var that=this;
  81. if(isin==1){
  82. //设为管理
  83. if(type=='manager'){
  84. if(user.type=='manager') {
  85. var tips="是否要取消["+nickname+"]的管理权限?";
  86. var sendtype=false;
  87. this.group_user.type='user';
  88. }
  89. else {
  90. var tips="是否要将["+nickname+"]设为管理?";
  91. var sendtype=true;
  92. this.group_user.type='manager';
  93. }
  94. uni.showModal({
  95. title: '提示',
  96. content: tips,
  97. success: function (res) {
  98. if (res.confirm) {
  99. var data={type:'groupset1',mode:'manage',settype:sendtype,group_id:that.group_id,userid:that.userid,from_uid:that.myid};
  100. that.$socket.send(data);
  101. } else if (res.cancel) {
  102. if(that.group_user.type=='user')
  103. that.group_user.type='manager';
  104. else that.group_user.type='user'
  105. }
  106. }
  107. });
  108. }
  109. //禁言
  110. if(type=='deny'){
  111. if(user.is_deny==1) {
  112. var settype=0;
  113. var tips="是否要解除["+nickname+"]禁言?";
  114. this.group_user.is_deny=0;
  115. }
  116. else {
  117. var settype=1;
  118. var tips="是否要将["+nickname+"]禁言?";
  119. this.group_user.is_deny=1;
  120. }
  121. uni.showModal({
  122. title: '禁言提示',
  123. content: tips,
  124. success: function (res) {
  125. if (res.confirm) {
  126. var data={type:'groupset1',mode:'deny',settype:settype,group_id:that.group_id,userid:that.userid,from_uid:that.myid};
  127. that.$socket.send(data);
  128. }
  129. else{
  130. if(that.group_user.is_deny==0)
  131. that.group_user.is_deny=1;
  132. else that.group_user.is_deny=0
  133. }
  134. }
  135. });
  136. }
  137. //踢人
  138. if(type=='delete'){
  139. // var tips="是否要将["+nickname+"]移除本群?";
  140. // uni.showModal({
  141. // title: '踢人提示',
  142. // content: tips,
  143. // success: function (res) {
  144. // if (res.confirm) {
  145. // var data={type:'deleteGroup',group_id:that.group_id,userid:that.menu_id,fromid:that.userid};
  146. // that.$socket.send(data);
  147. // uni.showToast({
  148. // icon:'none',
  149. // title:nickname+'已被移除本群'
  150. // })
  151. // setTimeout(function(){
  152. // uni.navigateBack({
  153. // delta:2
  154. // })
  155. // },500)
  156. // }
  157. // }
  158. // });
  159. this.showlogout=true;
  160. this.logoutinfo={group_id:that.group_id,userid:this.userid,nickname:nickname};
  161. }
  162. //设置备注
  163. if(type=='update'){
  164. this.user_rename(this.menu_id);
  165. }
  166. if(type=='view'){
  167. this.lookMember(user);
  168. }
  169. }
  170. else{
  171. uni.showToast({
  172. title:"该用户已被移除群组",
  173. icon:'none'
  174. })
  175. this.getGroupUsers();
  176. }
  177. },
  178. logout_sub(e){
  179. uni.showToast({
  180. icon:'none',
  181. title:'操作成功'
  182. })
  183. setTimeout(function(){
  184. uni.navigateBack({
  185. delta:2
  186. })
  187. },500)
  188. },
  189. sub_rename(){
  190. var postdata={group_id:this.group_id,content:this.group_user.nickname,userid:this.userid};
  191. var that=this;
  192. http.setWait(false).post('group.php?act=setGroupNickname',postdata).then(res=>{
  193. if(res.code==200){
  194. uni.showToast({
  195. title:"操作成功",
  196. icon:'none'
  197. })
  198. this.getGroupuser(this.userid,this.group_id);
  199. }
  200. else{
  201. uni.showToast({
  202. title:res.message,
  203. icon:'none'
  204. })
  205. this.getGroupuser(this.userid,this.group_id);
  206. }
  207. })
  208. },
  209. users_set(data){
  210. if(data.length>0){
  211. for(var i=0;i<data.length;i++){
  212. if(this.userid==data[i].id){
  213. this.group_user=data[i];
  214. }
  215. if(this.myid==data[i].id){
  216. this.thistype=data[i].type;
  217. }
  218. }
  219. uni.setStorageSync(this.group_id+'_group_members',data);
  220. }
  221. this.group_users=data;
  222. },
  223. getGroupuser(userid,group_id){
  224. api.getGroupUsers({
  225. group_id: group_id,
  226. userid: userid,
  227. }).then(res => {
  228. this.users_set(res.data);
  229. })
  230. },
  231. },
  232. onShow() {
  233. },
  234. onLoad(opts) {
  235. this.userid=opts.id;
  236. this.group_id=opts.group_id;
  237. this.thistype=opts.thistype;
  238. this.usertype=opts.usertype;
  239. var group_users=uni.getStorageSync(this.group_id+'_group_members');
  240. if(group_users.length>0){
  241. this.users_set(group_users);
  242. }
  243. this.getGroupuser(this.userid,this.group_id);
  244. this.$socket.on('group_update', (res) => {
  245. this.getGroupuser(this.userid,this.group_id);
  246. })
  247. }
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. @import "@/static/css/user.css";
  252. .page{
  253. background-color: #fafafa;
  254. }
  255. .profile{
  256. background-color: #fff;
  257. margin: 10px auto;
  258. width: 100%;
  259. }
  260. .profile li{
  261. vertical-align: middle;
  262. }
  263. .profile li:first-child{
  264. padding-left: 10px;
  265. width: 150px;
  266. text-align: left;
  267. }
  268. .profile li:last-child{
  269. padding-right: 10px;
  270. text-align: right;
  271. width: calc(100% - 180px);
  272. vertical-align: middle;
  273. }
  274. .btn{
  275. height: 30px;
  276. line-height: 30px;
  277. background-color: #3388ff;
  278. float: right;
  279. color: #fff;
  280. padding: 0px 15px;
  281. margin-left: 5px;
  282. cursor: pointer;
  283. vertical-align: middle;
  284. }
  285. </style>