修改群信息

This commit is contained in:
2022-02-14 12:13:50 +08:00
parent db94c6b962
commit de7f0453bb
2 changed files with 83 additions and 10 deletions

View File

@@ -27,9 +27,9 @@
</u-cell-group>
<u-cell-group class="cells" v-if="group.is_admin">
<u-cell isLink title="修改群聊名称" :value="group.name" @click="onGroupName"></u-cell>
<u-cell isLink title="修改群聊名称" :value="groupName" @click="onGroupName"></u-cell>
<u-cell isLink title="修改群头像">
<u-avatar slot="value" size="24" shape="square" :src="group.cover"></u-avatar>
<u-avatar slot="value" size="24" shape="square" @click="onGroupAvatar" :src="group.cover"></u-avatar>
</u-cell>
</u-cell-group>
@@ -39,13 +39,22 @@
<view class="action u-border-bottom" v-else @click="onQuite">删除并退出</view>
</view>
<u-modal :show="modalShow" title="修改群名称" showCancelButton @cancel="onHideModal" @confirm="onChangeGroupName">
<view class="slot-content">
<u--input placeholder="群名称" border="surround" v-model="groupName"></u--input>
</view>
</u-modal>
</view>
</template>
<script>
import {
getGroupInfo
getGroupInfo,
updateGroup
} from '@/apis/interfaces/im.js'
import {
uploads
} from '@/apis/interfaces/uploading'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
export default {
@@ -58,7 +67,9 @@
members: [],
status: false,
isTop: false,
loaded: false
loaded: false,
modalShow: false,
groupName: ''
}
},
onLoad(e) {
@@ -75,7 +86,7 @@
if (code == 0) {
this.isTop = conversation.isTop
}
})
})
this.initData()
uni.$on('groupAnnouncementCreated', this.initData)
},
@@ -86,6 +97,7 @@
initData() {
getGroupInfo(this.targetId).then(res => {
this.group = res.group
this.groupName = res.group.name
this.announcement = res.announcement
this.members = res.members
this.loaded = true
@@ -127,7 +139,22 @@
})
},
onGroupName() {
this.modalShow = true
},
onChangeGroupName() {
updateGroup(this.targetId, {
name: this.groupName
}).then(res => {
this.modalShow = false
uni.showToast({
icon: 'none',
title: '群名称修改成功'
})
})
},
onHideModal() {
this.modalShow = false
this.groupName = this.group.name
},
onClean() {
uni.showModal({
@@ -157,6 +184,46 @@
icon: 'none',
title: '开发中'
})
},
// 修改群头像
onGroupAvatar() {
uni.chooseImage({
count: 1,
sizeType: ['original'],
sourceType: ['album'],
crop: {
quality: 100,
width: 128,
height: 128,
resize: true
},
success: res => {
console.log(res);
let path = res.tempFiles.map((val, index) => {
return {
name: 'uploads' + index,
uri: val.path
}
})
uploads(path).then(path => {
updateGroup(this.targetId, {
cover: path.path[0]
}).then(res => {
uni.showToast({
icon: 'none',
title: '群头像修改成功'
})
this.modalShow = false
this.group.cover = path.url[0]
})
}).catch(err => {
uni.showToast({
title: err.message,
icon: 'none'
})
})
}
})
}
}
}

View File

@@ -12,7 +12,6 @@ export default {
contactInfo: (state) => (targetId) => {
if (state.contacts[targetId]) {
const info = state.contacts[targetId]
return {
name: info.name,
hash: info.hash,
@@ -79,7 +78,10 @@ export default {
portraitUrl: contactInfo.portraitUrl,
localAvatar: savedFilePath
}
model.update('targetId=' + contactInfo.targetId, info, (err, res) => {})
model.update('targetId="' + contactInfo.targetId + '"', info, (err,
res) => {
console.log('UPDATE AVATAR, ERR', err);
})
commit('updateContactInfo', info)
})
} else {
@@ -90,9 +92,13 @@ export default {
portraitUrl: contactInfo.portraitUrl,
localAvatar: result[0].localAvatar
}
model.update('targetId="' + contactInfo.targetId + '"', info, (err, res) => {})
model.update('targetId="' + contactInfo.targetId + '"', info, (err, res) => {
console.log('UPDATE NAME, ERR', err);
})
}
} else {}
} else {
console.log('updateContact, 无操作');
}
})
},
// 初始化好友信息