index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <div class="r-view pub-scroll-box">
  3. <div class="setting-top">
  4. <div class="search-input">
  5. <input type="text" @input="searchUser($event, membersArray)" placeholder="搜索群成员">
  6. <i class="el-icon-search"></i>
  7. </div>
  8. <!-- 没搜索 -->
  9. <ul v-if="!isSearch" class="user-list" :class="{'height-limit': limitHeight}">
  10. <li class="list-item" @click="$showInvite" v-if="isAdmin">
  11. <div class="avatar btn"><i class="el-icon-plus"></i></div>
  12. <span class="name">添加</span>
  13. </li>
  14. <li class="list-item" v-if="isAdmin">
  15. <div class="avatar btn"><i class="el-icon-minus"></i></div>
  16. <span class="name">删除</span>
  17. </li>
  18. <template v-for="(item, index) in membersArray">
  19. <li class="list-item" :key="index" @click="$showOtherInfo(item.user_id)">
  20. <img class="avatar" v-if="item.cover_photo" :src="item.cover_photo" alt="">
  21. <div v-else class="user-avatar avatar"
  22. :class="'avatar_bg' + item.user_id % 9"
  23. :title="item.nick_name"
  24. :data-name="item.nick_name.slice(0,2).toUpperCase()"></div>
  25. <span class="name">{{item.nick_name}}</span>
  26. </li>
  27. </template>
  28. </ul>
  29. <ul v-else class="user-list">
  30. <template v-for="(item, index) in searchList">
  31. <li class="list-item" :key="index" @click="$showOtherInfo(item.user_id)">
  32. <img class="avatar" v-if="item.cover_photo" :src="item.cover_photo" alt="">
  33. <div v-else class="user-avatar avatar"
  34. :class="'avatar_bg' + item.user_id % 9"
  35. :title="item.nick_name"
  36. :data-name="item.nick_name.slice(0,2).toUpperCase()"></div>
  37. <span class="name">{{item.nick_name}}</span>
  38. </li>
  39. </template>
  40. </ul>
  41. <div class="show-all-btn" v-if="group.userCounts > 6" @click="limitHeight = !limitHeight">
  42. {{limitHeight ? '展开全部' : '收起'}} <i :class="`el-icon-arrow-${limitHeight ? 'down' : 'up'}`"></i>
  43. </div>
  44. </div>
  45. <div class="setting-item" v-if="isAdmin">
  46. <div class="title">群名</div>
  47. <input class="edit-name-input" type="text" v-model="newGroupName" v-focus v-if="isEdit" @blur="handleTitleBlur">
  48. <p class="text" v-else @click="handleTitleFocus">点击编辑群名<i class="el-icon-edit"></i></p>
  49. </div>
  50. <div class="setting-item" v-if="isAdmin">
  51. <div class="title">设置群头像</div>
  52. <p class="text cursor" @click="$editGroupAvatar(group.coverPhoto)">
  53. <img v-if="group.coverPhoto" class="team-avatar" :src="group.coverPhoto" alt="">
  54. <span class="no-avatar" v-else>
  55. <i class="el-icon-plus"></i>
  56. </span>
  57. <i class="el-icon-arrow-right team-arrow-icon"></i>
  58. </p>
  59. </div>
  60. <div class="setting-item">
  61. <div class="title">群公告</div>
  62. <p class="text cursor" @click="handleOpenNotice" v-if="isAdmin">
  63. 点击编辑群公告
  64. <i class="el-icon-arrow-right"></i>
  65. </p>
  66. <template v-else>
  67. <p class="text notice" v-if="group.groupNotice">
  68. {{group.groupNotice}}
  69. </p>
  70. <p class="text notice" v-else>
  71. 暂无公告
  72. </p>
  73. </template>
  74. </div>
  75. <div class="setting-item">
  76. <div class="title">群邀请链接</div>
  77. <p class="text">
  78. <template v-if="!isEditLink">
  79. <a class="invite-link" href="javascript:" @click="copyLink(group.inviteUrl)">{{group.inviteUrl}}</a>
  80. <span class="link-change" v-if="isAdmin" @click="handleLinkFocus" >更改</span>
  81. </template>
  82. <input v-else class="edit-name-input" v-model="newLink" v-focus type="text" autofocus @blur="handleLinkBlur">
  83. </p>
  84. </div>
  85. <div class="setting-item">
  86. <div class="title">消息免打扰</div>
  87. <p class="text">
  88. <el-switch
  89. v-model="sessionInfo.is_mute"
  90. @change="changeMute"
  91. :active-value="'1'"
  92. :inactive-value="'0'"
  93. active-color="#2298f0"
  94. inactive-color="#cbcbcb">
  95. </el-switch>
  96. </p>
  97. </div>
  98. <div class="setting-item">
  99. <div class="title">置顶聊天</div>
  100. <p class="text">
  101. <el-switch
  102. v-model="sessionInfo.is_pin"
  103. @change="changePin"
  104. :active-value="'1'"
  105. :inactive-value="'0'"
  106. active-color="#2298f0"
  107. inactive-color="#cbcbcb">
  108. </el-switch>
  109. </p>
  110. </div>
  111. <div class="setting-bottom">
  112. <button class="delete-btn" @click="leaveGroup">退出群组</button>
  113. </div>
  114. <!-- 群公告 -->
  115. <transition name="msgbox-fade">
  116. <div class="pub-wrapper" v-if="editNotice">
  117. <div class="pub-mask"></div>
  118. <div class="pub-modal notice-modal">
  119. <div class="modal-hd">
  120. <div class="title">群公告</div>
  121. <i class="el-icon-close" @click="editNotice = false"></i>
  122. </div>
  123. <div class="modal-bd">
  124. <textarea v-focus placeholder="请输入你的群公告" v-model="newNotice"></textarea>
  125. </div>
  126. <div class="modal-fd">
  127. <el-button type="primary" @click="handleNotice">确认</el-button>
  128. </div>
  129. </div>
  130. </div>
  131. </transition>
  132. </div>
  133. </template>
  134. <script>
  135. import Vue from 'vue'
  136. import { Switch, Button } from 'element-ui'
  137. import API from '@/api'
  138. import { mapState } from 'vuex'
  139. import { confirmPopup } from '@/util/util'
  140. import { searchUserMixin } from '@/mixins'
  141. Vue.component(Button.name, Button)
  142. Vue.component(Switch.name, Switch)
  143. export default {
  144. name: 'chatSet',
  145. mixins: [searchUserMixin],
  146. computed: {
  147. ...mapState({
  148. myId: state => state.userId,
  149. group: state => state.group,
  150. curGroupId: state => state.curSession,
  151. members: state => state.group.members,
  152. sessionInfo: state => state.group.sessionInfo
  153. }),
  154. isAdmin () {
  155. return this.adminList && this.adminList.some(id => id == this.myId)
  156. },
  157. membersArray () {
  158. // members obj => array
  159. var arr = []
  160. var i = 0
  161. for (let k in this.members) {
  162. arr[i] = this.members[k]
  163. i++
  164. }
  165. return arr
  166. }
  167. },
  168. components: {
  169. },
  170. data () {
  171. return {
  172. msgPush: false, // 消失免打扰
  173. msgTop: false, // 置顶聊天
  174. limitHeight: true, // 展开全部
  175. isEdit: false, // 编辑群名
  176. newGroupName: '', // 群名
  177. newLink: '', // 新连接
  178. newNotice: '', // 新群名
  179. isEditLink: false, // 编辑链接
  180. editNotice: false
  181. }
  182. },
  183. methods: {
  184. // 群标题
  185. handleTitleBlur () {
  186. this.isEdit = false
  187. if (this.newGroupName.length) {
  188. API.group.changeTitle({
  189. group_id: this.curGroupId,
  190. title: this.newGroupName
  191. }).then(({ data }) => {
  192. this.$store.commit('updateGroup', {
  193. key: 'groupName',
  194. data: this.newGroupName
  195. })
  196. })
  197. }
  198. },
  199. handleTitleFocus () {
  200. this.isEdit = true
  201. this.newGroupName = this.group.groupName
  202. },
  203. // 群链接
  204. handleLinkBlur () {
  205. this.isEditLink = false
  206. API.group.changeName({
  207. group_id: this.curGroupId,
  208. name: this.newLink
  209. }).then(() => {
  210. this.$store.commit('updateGroup', {
  211. key: 'inviteUrl',
  212. data: this.newLink
  213. })
  214. })
  215. },
  216. handleLinkFocus () {
  217. this.isEditLink = true
  218. this.newLink = this.group.inviteUrl
  219. },
  220. // 群公告
  221. handleNotice () {
  222. API.group.changeNotice({
  223. group_id: this.curGroupId,
  224. notice: this.newNotice
  225. }).then(() => {
  226. this.$showTips('修改成功')
  227. this.$store.commit('updateGroup', {
  228. key: 'groupNotice',
  229. data: this.newNotice
  230. })
  231. })
  232. },
  233. handleOpenNotice () {
  234. this.editNotice = true
  235. this.newNotice = this.group.groupNotice
  236. },
  237. copyLink (link) {
  238. this.$copyText(link).then((e) => {
  239. this.$showTips('复制成功')
  240. })
  241. },
  242. changePin (val) {
  243. if (val === '1') {
  244. API.session.setPin({
  245. session_id: this.curGroupId
  246. }).then(() => {
  247. this.$store.commit('updatePin', val)
  248. })
  249. } else {
  250. API.session.cancelPin({
  251. session_id: this.curGroupId
  252. }).then(() => {
  253. this.$store.commit('updatePin', val)
  254. })
  255. }
  256. },
  257. changeMute (val) {
  258. if (val === '1') {
  259. API.session.setMute({
  260. session_id: this.curGroupId
  261. }).then(() => {
  262. this.$store.commit('updateMute', val)
  263. })
  264. } else {
  265. API.session.cancelMute({
  266. session_id: this.curGroupId
  267. }).then(() => {
  268. this.$store.commit('updateMute', val)
  269. })
  270. }
  271. },
  272. // 退出群组
  273. leaveGroup () {
  274. confirmPopup('确认退出该群聊?').then(() => {
  275. API.group.leaveGroup({
  276. group_id: this.curGroupId
  277. }).then(() => {
  278. this.$showTips('已退出该群聊')
  279. })
  280. })
  281. }
  282. }
  283. }
  284. </script>
  285. <style lang="scss" scoped>
  286. @import './style.scss';
  287. </style>