index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <div class="r-view pub-scroll-box">
  3. <div class="setting-top">
  4. <div class="search-input">
  5. <input type="text" v-model="searchTxt" placeholder="搜索群成员">
  6. <i class="el-icon-search"></i>
  7. </div>
  8. <!-- 没搜索 -->
  9. <ul v-if="!isSearch" class="user-list pub-scroll-box" ref="scrollWrap" :class="{'height-limit': limitHeight}">
  10. <li class="list-item" @click="$showInvite(2)" v-if="isAdmin || isCreator">
  11. <div class="avatar btn"><i class="el-icon-plus"></i></div>
  12. <span class="name">添加</span>
  13. </li>
  14. <li class="list-item" @click="$showInvite(3)" v-if="isAdmin || isCreator">
  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. <div class="avatar-box">
  21. <img class="avatar" v-if="item.cover_photo" :src="item.cover_photo" alt="">
  22. <div v-else class="user-avatar avatar"
  23. :class="'avatar_bg' + item.user_id % 9"
  24. :title="item.nick_name"
  25. :data-name="item && item.nick_name && item.nick_name.slice(0,2).toUpperCase()">
  26. </div>
  27. <i v-if="group.creator == item.user_id" class="creator-icon"></i>
  28. <i v-else-if="adminList.includes(Number(item.user_id))" class="admin-icon el-icon-star-on"></i>
  29. </div>
  30. <span class="name">{{item.nick_name}}</span>
  31. </li>
  32. </template>
  33. </ul>
  34. <ul v-else class="user-list pub-scroll-box">
  35. <template v-for="(item, index) in searchList">
  36. <li class="list-item" :key="index" @click="$showOtherInfo(item.user_id)">
  37. <img class="avatar" v-if="item.cover_photo" :src="item.cover_photo" alt="">
  38. <div v-else class="user-avatar avatar"
  39. :class="'avatar_bg' + item.user_id % 9"
  40. :title="item.nick_name"
  41. :data-name="item && item.nick_name && item.nick_name.slice(0,2).toUpperCase()"></div>
  42. <span class="name">{{item.nick_name}}</span>
  43. </li>
  44. </template>
  45. </ul>
  46. <div class="show-all-btn" v-if="group.userCounts > 6" @click="handleShowAll">
  47. {{limitHeight ? '展开全部' : '收起'}} <i :class="`el-icon-arrow-${limitHeight ? 'down' : 'up'}`"></i>
  48. </div>
  49. </div>
  50. <div class="setting-item" v-if="isAdmin || isCreator">
  51. <div class="title">群名</div>
  52. <input class="edit-full-input" type="text" v-model="newGroupName" v-focus v-if="isEdit" @blur="handleTitleBlur">
  53. <p class="text" v-else @click="handleTitleFocus">{{group.groupName}}<i class="el-icon-edit"></i></p>
  54. </div>
  55. <div class="setting-item" v-if="isAdmin || isCreator">
  56. <div class="title">设置群头像</div>
  57. <p class="text cursor" @click="$editGroupAvatar(group.coverPhoto)">
  58. <img v-if="group.coverPhoto" class="team-avatar" :src="group.coverPhoto" alt="">
  59. <span class="no-avatar" v-else>
  60. <i class="el-icon-plus"></i>
  61. </span>
  62. <i class="el-icon-arrow-right team-arrow-icon"></i>
  63. </p>
  64. </div>
  65. <div class="setting-item">
  66. <div class="title">群公告</div>
  67. <p class="text cursor" @click="handleOpenNotice" v-if="isAdmin || isCreator">{{group.groupNotice}}<i class="el-icon-edit"></i></p>
  68. <template v-else>
  69. <p class="text notice" v-if="group.groupNotice">
  70. {{group.groupNotice}}
  71. </p>
  72. <p class="text notice" v-else>
  73. 暂无公告
  74. </p>
  75. </template>
  76. </div>
  77. <div class="setting-item">
  78. <div class="title">群邀请链接</div>
  79. <p class="text">
  80. <template v-if="!isEditLink">
  81. <a class="invite-link" href="javascript:" @click="copyLink(group.inviteUrl)">{{sharePath + shareName}}</a>
  82. <span class="invite-editBtn" v-if="isAdmin || isCreator" @click="handleLinkFocus">
  83. <i class="el-icon-edit"></i>
  84. </span>
  85. <!-- <span class="link-change" v-if="isAdmin || isCreator" @click="handleLinkFocus" >更改</span> -->
  86. </template>
  87. <template v-else>
  88. <em class="edit-name-path">{{sharePath}}</em>
  89. <input class="edit-name-input" v-model="editShareName" v-focus type="text" autofocus @blur="handleLinkBlur">
  90. </template>
  91. </p>
  92. </div>
  93. <div class="setting-item">
  94. <div class="title">消息免打扰</div>
  95. <p class="text">
  96. <el-switch
  97. v-model="sessionInfo.is_mute"
  98. @change="changeMute"
  99. :active-value="1"
  100. :inactive-value="0"
  101. active-color="#2298f0"
  102. inactive-color="#cbcbcb">
  103. </el-switch>
  104. </p>
  105. </div>
  106. <div class="setting-item">
  107. <div class="title">置顶聊天</div>
  108. <p class="text">
  109. <el-switch
  110. v-model="sessionInfo.is_pin"
  111. @change="changePin"
  112. :active-value="1"
  113. :inactive-value="0"
  114. active-color="#2298f0"
  115. inactive-color="#cbcbcb">
  116. </el-switch>
  117. </p>
  118. </div>
  119. <div class="setting-item ext-group-admin" v-if="isCreator" @click="handleGroudMgr">
  120. <div class="title">群管理<i class="el-icon-arrow-right team-arrow-icon"></i></div>
  121. </div>
  122. <div class="setting-bottom">
  123. <button class="delete-btn" @click="leaveGroup">退出群组</button>
  124. </div>
  125. <!-- 群公告 -->
  126. <transition name="msgbox-fade">
  127. <div class="pub-wrapper" v-if="editNotice">
  128. <div class="pub-mask"></div>
  129. <div class="pub-modal notice-modal">
  130. <div class="modal-hd">
  131. <div class="title">群公告</div>
  132. <i class="el-icon-close" @click="editNotice = false"></i>
  133. </div>
  134. <div class="modal-bd">
  135. <textarea v-focus placeholder="请输入你的群公告" v-model="newNotice"></textarea>
  136. </div>
  137. <div class="modal-fd">
  138. <el-button type="primary" @click="handleNotice">确认</el-button>
  139. </div>
  140. </div>
  141. </div>
  142. </transition>
  143. </div>
  144. </template>
  145. <script>
  146. import Vue from 'vue'
  147. import { Switch, Button } from 'element-ui'
  148. import API from '@/api'
  149. import { mapState, mapActions } from 'vuex'
  150. import { confirmPopup } from '@/util/util'
  151. Vue.component(Button.name, Button)
  152. Vue.component(Switch.name, Switch)
  153. export default {
  154. name: 'chatSet',
  155. watch: {
  156. searchTxt (newVal, val) {
  157. if (newVal == '') {
  158. this.isSearch = false
  159. } else {
  160. this.isSearch = true
  161. this.searchUser()
  162. }
  163. }
  164. },
  165. computed: {
  166. ...mapState({
  167. myId: state => state.userId,
  168. group: state => state.group,
  169. curGroupId: state => state.curSession,
  170. members: state => state.group.members,
  171. sessionInfo: state => state.group.sessionInfo,
  172. shareName: state => state.group.shareName,
  173. adminList: state => state.group.adminList,
  174. membersArray: state => state.group.membersArray
  175. }),
  176. isAdmin () {
  177. return this.members && this.members[this.myId] && this.members[this.myId].is_admin == 1
  178. },
  179. isCreator () {
  180. return this.group.creator == this.myId
  181. }
  182. },
  183. data () {
  184. return {
  185. msgPush: false, // 消失免打扰
  186. msgTop: false, // 置顶聊天
  187. limitHeight: true, // 展开全部
  188. isEdit: false, // 编辑群名
  189. newGroupName: '', // 群名
  190. newLink: '', // 新连接
  191. newNotice: '', // 新群名
  192. isEditLink: false, // 编辑链接
  193. editNotice: false,
  194. editShareName: '',
  195. sharePath: `${location.origin}/s/`,
  196. isSearch: false,
  197. searchList: [], // 搜索结果列表
  198. searchTxt: ''// 搜索内容
  199. }
  200. },
  201. methods: {
  202. ...mapActions([
  203. 'updateSessionItem'
  204. ]),
  205. // 群标题
  206. handleTitleBlur () {
  207. this.isEdit = false
  208. if (this.newGroupName.length) {
  209. API.group.changeTitle({
  210. group_id: this.curGroupId,
  211. title: this.newGroupName
  212. }).then(({ data }) => {
  213. // 更新侧边栏
  214. this.updateSessionItem({
  215. sessionId: this.curGroupId,
  216. data: {
  217. name: this.newGroupName
  218. }
  219. })
  220. // 更新群组数据
  221. this.$store.commit('updateGroup', {
  222. key: 'groupName',
  223. data: this.newGroupName
  224. })
  225. })
  226. }
  227. },
  228. handleTitleFocus () {
  229. this.isEdit = true
  230. this.newGroupName = this.group.groupName
  231. },
  232. handleShowAll () {
  233. if (!this.limitHeight) {
  234. this.$refs.scrollWrap.scrollTop = 0
  235. }
  236. this.limitHeight = !this.limitHeight
  237. },
  238. // 群链接
  239. async handleLinkBlur () {
  240. this.isEditLink = false
  241. if (this.editShareName.match(/^\d{1,}$/)) {
  242. this.$showTips('分享链接不能是纯数字')
  243. return
  244. }
  245. if (!this.editShareName.match(/^(\w|.){1,}$/)) {
  246. this.$showTips('分享链接只能是英文字母,数字和 . 的组合')
  247. return
  248. }
  249. await confirmPopup(`分享链接只能被修改一次,确认修改为:${this.sharePath + this.editShareName}`, '提示')
  250. .catch(e => {})
  251. API.group.changeName({
  252. group_id: this.curGroupId,
  253. name: this.editShareName
  254. }).then(() => {
  255. this.$store.commit('updateGroup', {
  256. key: 'shareName',
  257. data: this.editShareName
  258. })
  259. })
  260. },
  261. handleLinkFocus () {
  262. this.isEditLink = true
  263. this.editShareName = this.shareName
  264. // this.newLink = this.group.inviteUrl
  265. },
  266. // 群公告
  267. handleNotice () {
  268. API.group.changeNotice({
  269. group_id: this.curGroupId,
  270. notice: this.newNotice
  271. }).then(() => {
  272. this.$showTips('修改成功')
  273. this.editNotice = false
  274. this.$store.commit('updateGroup', {
  275. key: 'groupNotice',
  276. data: this.newNotice
  277. })
  278. })
  279. },
  280. // 群管理
  281. handleGroudMgr () {
  282. this.$emit('handleShowGroudMgr', 1)
  283. },
  284. handleOpenNotice () {
  285. this.editNotice = true
  286. this.newNotice = this.group.groupNotice
  287. },
  288. copyLink (link) {
  289. let url = document.location.protocol + link
  290. this.$copyText(url).then((e) => {
  291. this.$showTips('复制成功')
  292. })
  293. },
  294. /**
  295. * @des 置顶聊天相关操作
  296. * @param {String} val 置顶操作Flag开关{1: 置顶, 0: 取消置顶}
  297. */
  298. changePin (val) {
  299. if (val == 1) {
  300. API.session.setPin({
  301. session_id: this.curGroupId
  302. }).then(() => {
  303. this.$store.commit('updatePin', val)
  304. // 更新侧边栏的顺序
  305. this.$store.commit('updateSessionListByPin', this.curGroupId)
  306. })
  307. } else {
  308. API.session.cancelPin({
  309. session_id: this.curGroupId
  310. }).then(() => {
  311. this.$store.commit('updatePin', val)
  312. // 更新侧边栏的顺序
  313. this.$store.commit('cancelSessionListByPin', this.curGroupId)
  314. })
  315. }
  316. },
  317. /**
  318. * @des 消息免打扰
  319. * @param {String} val 消息免打扰Flag开关{1: 免打扰, 0: 取消免打扰}
  320. */
  321. changeMute (val) {
  322. if (val == 1) {
  323. API.session.setMute({
  324. session_id: this.curGroupId
  325. }).then(() => {
  326. this.$store.commit('updateMute', val)
  327. })
  328. } else {
  329. API.session.cancelMute({
  330. session_id: this.curGroupId
  331. }).then(() => {
  332. this.$store.commit('updateMute', val)
  333. })
  334. }
  335. },
  336. // 退出群组
  337. leaveGroup () {
  338. confirmPopup('确认退出该群聊?').then(() => {
  339. API.group.leaveGroup({
  340. group_id: this.curGroupId
  341. }).then(() => {
  342. this.$store.commit('removeSessionListById', this.curGroupId)
  343. this.$store.dispatch('getGroupInfo')
  344. this.$showTips('已退出该群聊')
  345. })
  346. })
  347. },
  348. searchUser () {
  349. if (this.membersArray.length < this.group.membersNum) {
  350. API.group.searchMember({
  351. group_id: this.group.groupId,
  352. keyword: this.searchTxt
  353. }).then(({ data }) => {
  354. this.searchList = data.data
  355. })
  356. } else {
  357. let val = this.searchTxt
  358. this.searchList = this.membersArray.filter(item => {
  359. let inName, inNick
  360. inName = item.user_name ? item.user_name.indexOf(val) > -1 : false
  361. inNick = item.nick_name ? item.nick_name.indexOf(val) > -1 : false
  362. return inName || inNick
  363. })
  364. }
  365. }
  366. }
  367. }
  368. </script>
  369. <style lang="scss" scoped>
  370. @import './style.scss';
  371. </style>