123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575 |
- import API from '@/api'
- import { mapState, mapActions, mapMutations } from 'vuex'
- import { confirmPopup, getMeechatType, getAvatarBgColor } from '@/util/util'
- import { Message, MessageBox } from 'element-ui'
- import { searchGroupUserMixin } from '@/mixins'
- import _ from 'lodash'
- export const groupSetMixins = {
- mixins: [searchGroupUserMixin],
- computed: {
- ...mapState({
- myId: state => state.userId,
- group: state => state.group,
- curGroupId: state => state.curSession,
- members: state => state.group.members,
- sessionInfo: state => state.group.sessionInfo,
- shareName: state => state.group.shareName,
- adminList: state => state.group.adminList,
- membersArray: state => state.group.membersArray
- }),
- isAdmin () {
- return this.members && this.members[this.myId] && this.members[this.myId].is_admin == 1
- },
- isCreator () {
- return this.group.creator == this.myId
- },
- isPrivate () {
- return this.$store.getters.isPrivate
- }
- },
- mounted () {
- let groupId = this.$route.params.id
- this.changeSessionId(groupId)
- if (!this.isPrivate && !this.group.groupId) {
- this.initGroup({
- userId: this.myId,
- groupId: groupId,
- useCache: false
- })
- this.getGroupInfo()
- }
- document.addEventListener('click', () => {
- if (!this.$refs.chatSet) return
- let classNames = this.$refs.chatSet.getAttribute('class')
- if (classNames.indexOf('move-left') > -1) {
- this.$emit('showCharSet', 0)
- }
- })
- },
- data () {
- return {
- msgPush: false,
- msgTop: false,
- limitHeight: true,
- isEdit: false,
- newGroupName: '',
- newLink: '',
- newNotice: '',
- isEditLink: false,
- editNotice: false,
- editShareName: '',
- sharePath: `${location.origin}/s/`,
- isSearch: false,
- searchList: [],
- searchTxt: '',
- meechatType: getMeechatType()
- }
- },
- methods: {
- ...mapMutations(['initGroup', 'changeSessionId', 'changeHotGroupStatus', 'removeSessionListById']),
- ...mapActions([
- 'updateSessionItem',
- 'getGroupInfo'
- ]),
-
- handleTitleBlur () {
- this.isEdit = false
- if (this.newGroupName.length) {
- API.group.changeTitle({
- group_id: this.curGroupId,
- title: this.newGroupName
- }).then(({ data }) => {
-
- this.updateSessionItem({
- sessionId: this.curGroupId,
- data: {
- name: this.newGroupName
- }
- })
-
- this.$store.commit('updateGroup', {
- key: 'groupName',
- data: this.newGroupName
- })
- })
- }
- },
- handleTitleFocus () {
- this.isEdit = true
- this.newGroupName = this.group.groupName
- },
- handleShowAll () {
- if (!this.limitHeight) {
- this.$refs.scrollWrap.scrollTop = 0
- }
- this.limitHeight = !this.limitHeight
- },
-
- async handleLinkBlur () {
- this.isEditLink = false
- if (this.editShareName.match(/^\d{1,}$/)) {
- this.$showTips('分享链接不能是纯数字')
- return
- }
- if (!this.editShareName.match(/^(\w|.){1,}$/)) {
- this.$showTips('分享链接只能是英文字母,数字和 . 的组合')
- return
- }
- await confirmPopup(`分享链接只能被修改一次,确认修改为:${this.sharePath + this.editShareName}`, '提示')
- .catch(e => {})
- API.group.changeName({
- group_id: this.curGroupId,
- name: this.editShareName
- }).then(() => {
- this.$store.commit('updateGroup', {
- key: 'shareName',
- data: this.editShareName
- })
- })
- },
- handleLinkFocus () {
- this.isEditLink = true
- this.editShareName = this.shareName
-
- },
-
- handleNotice () {
- API.group.changeNotice({
- group_id: this.curGroupId,
- notice: this.newNotice
- }).then(() => {
- this.$showTips('修改成功')
- this.editNotice = false
- this.$store.commit('updateGroup', {
- key: 'groupNotice',
- data: this.newNotice
- })
- })
- },
-
- handleGroudMgr () {
- this.$emit('handleShowGroudMgr', 1)
- },
- handleOpenNotice () {
- this.editNotice = true
- this.newNotice = this.group.groupNotice
- },
- copyLink (link) {
- let url = document.location.protocol + link
- this.$copyText(url).then((e) => {
- this.$showTips('复制成功')
- })
- },
-
- async changePin (val) {
- let opt = val == 1 ? 'setPin' : 'cancelPin'
- let optRes = val == 1 ? 'updateSessionListByPin' : 'cancelSessionListByPin'
- let res = await API.session[opt]({
- session_id: this.curGroupId
- })
- let data = res.data.data
- this.$store.commit('updatePin', val)
-
- this.$store.commit(optRes, {
- session_id: this.curGroupId,
- is_pin: data.is_pin,
- pin_time_int: data.pin_time_int
- })
- },
-
- async changeMute (val) {
- let opt = val == 1 ? 'setMute' : 'cancelMute'
- let optRes = val == 1 ? 'updateSessionListByMute' : 'cancelSessionListByMute'
- await API.session[opt]({
- session_id: this.curGroupId
- })
- this.$store.commit('updateMute', val)
-
- this.$store.commit(optRes, this.curGroupId)
- },
-
- leaveGroup () {
- confirmPopup(this.$t('group.leaveComfirm')).then(() => {
- this.$emit('showLoadingRoom', true)
- API.group.leaveGroup({
- group_id: this.curGroupId
- }).then(() => {
- this.changeHotGroupStatus({
- groupId: this.curGroupId,
- isJoin: 0
- })
- this.removeSessionListById(this.curGroupId)
- this.$showTips(this.$t('group.leaveTip'))
- this.$emit('showLoadingRoom', false)
- this.$store.commit('updateJoin', false)
- if (this.meechatType == 'h5') this.$router.go(-2)
- }).catch(() => {
- this.$emit('showLoadingRoom', false)
- })
- })
- }
- }
- }
- export const groupInviteMixins = {
- mixins: [searchGroupUserMixin],
- data () {
- return {
- curItemIndex: 0,
- checkList: [],
- groupName: '',
- isLoading: false,
- meechatType: getMeechatType()
- }
- },
- computed: {
- checkedNum () {
- return (this.checkList.filter(v => {
- return v.isChecked
- })).length
- },
- ...mapState({
- userId: state => state.userId,
- friendList: state => state.chat.friendList,
- groupId: state => state.group.groupId,
- group: state => state.group,
- members: state => state.group.members,
- membersArray: state => state.group.membersArray,
- membersNum: state => state.group.membersNum,
- adminList: state => state.group.adminList
- }),
- inviteList () {
- return this.checkList.filter(v => {
- return v.isChecked
- }).map(v => v.user_id).join(',')
- },
- resultList () {
- return (this.checkList && this.checkList.filter(v => {
- return v.isChecked
- })) || []
- }
- },
- methods: {
- ...mapActions(['getGroupInfo']),
- ...mapMutations([
- 'initGroup',
- 'changeSessionId'
- ]),
- getItemByUid (uid) {
- return this.checkList.filter((item, index) => {
- if (item.user_id == uid) this.curItemIndex = index
- return item.user_id == uid
- })[0]
- },
- changeState (uid, flag = true) {
- let item = this.getItemByUid(uid)
- if (item.isChoosed) return
-
- if (
- this.inviteType == 4 &&
- flag &&
- this.adminList.length + this.checkedNum > 5
- ) {
- this.$showTips(this.$t('group.groupMgrMostTips'))
- return
- }
-
- if (this.inviteType == 5) {
- this.checkList.forEach(item => {
- item.isChecked = false
- })
- }
- item['isChecked'] = flag
- this.$set(this.checkList, this.curItemIndex, item)
- },
- changeStateForH5 (uid) {
- let item = this.getItemByUid(uid)
- let flag = !item.isChecked
-
- if (this.inviteType == 4 && flag && this.adminList.length + this.checkedNum > 5) {
- this.$showTips(this.$t('group.groupMgrMostTips'))
- return
- }
-
- if (this.inviteType == 5) {
- this.checkList.forEach(item => {
- item.isChecked = false
- })
- }
- item['isChecked'] = flag
- this.$set(this.checkList, this.curItemIndex, item)
- },
- async initList () {
- switch (this.inviteType) {
-
- case 1:
- case 2:
- await this.$store.dispatch('getFriendList')
- this.checkList = this.friendList
- break
-
- case 3:
- case 4:
- case 5:
- this.checkList = this.membersArray
- break
- }
- this.checkList = _.filter(this.checkList, item => {
- item.isChecked = false
- item.isChoosed = false
- item.isShow = true
-
- if (this.inviteType == 2) {
-
- let isInGroup = this.membersArray.some((n) => {
- return n.user_id == item.user_id
- })
- return !isInGroup
- }
-
- if (this.inviteType == 4 && item.is_admin == 1) {
- item.isChoosed = true
- }
- return item.user_id != this.userId
- })
- this.showNum = this.checkList.length
- },
- optSubmit () {
- switch (this.inviteType) {
-
- case 1:
- this.createGroup()
- break
-
- case 2:
- this.invitesMember()
- break
-
- case 3:
- this.removesMember()
- break
-
- case 4:
- this.addAdmin()
- break
-
- case 5:
- this.changeCreator()
- break
-
- case 6:
- this.createGroup()
- break
- }
- },
-
- createGroup () {
- if (this.groupName.length > 16) {
- this.$showTips(this.$t('group.groupNameLengthTips'))
- return
- }
- if (this.groupName) {
- this.isLoading = true
- API.group
- .createGroup({
- group_title: this.groupName,
- user_id_list: this.inviteList
- })
- .then(({ data }) => {
- let groupId = data.data.session_id
- this.$showTips(this.$t('group.createSuccess'))
- if (this.ext && this.ext.tgGroupId) {
-
- this.doSyncTelegram(groupId)
- } else {
- this.$router.push(`/group/${groupId}`)
- }
- if (this.meechatType != 'h5') this.hidePopup()
- })
- } else {
- Message({
- message: this.$t('group.groupNameTips'),
- type: 'warning'
- })
- }
- },
-
- doSyncTelegram (groupId) {
- API.tg.doSync({
- group_id: groupId,
- tg_group_id: this.ext.tgGroupId
- }).then(() => {
- this.$router.replace(`/group/${groupId}`)
- }).catch(error => {
- console.log(error)
- if (this.meechatType == 'h5') this.$router.replace('/')
- })
- },
-
- async invitesMember () {
- this.isLoading = true
- await API.group.invites({
- user_ids: this.inviteList,
- group_id: this.groupId
- })
- await this.getGroupInfo()
- if (this.meechatType == 'h5') this.$router.go(-1)
- else this.hidePopup()
- },
-
- async removesMember () {
- this.isLoading = true
- await API.group.removes({
- user_ids: this.inviteList,
- group_id: this.groupId
- })
- await this.getGroupInfo()
- if (this.meechatType == 'h5') this.$router.go(-1)
- else this.hidePopup()
- },
-
- addAdmin () {
- this.isLoading = true
- API.group
- .addAdmin({
- user_ids: this.inviteList,
- group_id: this.groupId
- })
- .then(({ data }) => {
- this.getGroupInfo()
- if (this.meechatType == 'h5') this.$router.go(-1)
- else this.hidePopup()
- })
- },
- changeCreator () {
- if (this.checkedNum <= 0) return
- let curMember = this.checkList[this.curItemIndex]
- let username = curMember.nick_name || curMember.user_name
- MessageBox.confirm(`${this.$t('group.groupMgrComfime')} ${username}`)
- .then(() => {
- this.isLoading = true
- API.group
- .changeCreator({
- new_creator: this.inviteList,
- group_id: this.groupId
- })
- .then(({ data }) => {
- if (this.meechatType == 'h5') this.$router.go(-1)
- else this.hidePopup()
- this.$store.dispatch('getGroupInfo')
- Message({
- message: `${this.$t('group.groupMgrResult')} ${username}`,
- type: 'warning'
- })
- })
- })
- .catch(e => {
- console.log(e)
- })
- }
- },
- mounted () {
- this.initList()
- }
- }
- export const groupHotMixins = {
- props: {
- searchTxt: String
- },
- data () {
- return {
- }
- },
- components: {},
- computed: {
- ...mapState(['hotList']),
- showHotList () {
- let val = this.searchTxt && this.searchTxt.trim()
- if (!val) return this.hotList
- let arr = this.hotList.filter((item) => {
- let title = (item.group_title && item.group_title.toLocaleLowerCase()) || ''
- return title.match(val)
- })
- return arr
- }
- },
- methods: {
- ...mapMutations(['changeHotGroupStatus']),
- bgColorNum (str) {
- return getAvatarBgColor(str, this.userId)
- },
-
- joinGroup (groupId, type) {
- if (type == 1) {
- this.$router.push(`/group/${groupId}`)
- } else {
- API.group.joinGroup({
- group_id: groupId
- }).then(() => {
- this.changeHotGroupStatus({
- groupId: groupId,
- isJoin: 1
- })
- this.$router.push(`/group/${groupId}`)
- })
- }
- }
- },
- mounted () {
- this.$store.commit('changeSessionId', '0')
- this.$store.dispatch('getHotList')
- }
- }
|