feat: 添加共同群组对话框组件并在用户详情中集成

This commit is contained in:
yatgei 2025-10-13 18:22:25 +08:00
parent ab76185434
commit dd7eee277e
5 changed files with 434 additions and 80 deletions

View File

@ -0,0 +1,131 @@
<template>
<Modal v-model="visibleProxy" :title="$L('共同群组') + ' (' + $L('(*)个', totalCount) + ')'" :footer-hide="true" width="500">
<div class="common-dialog-content">
<div v-if="loading > 0 && list.length === 0" class="loading-wrapper">
<Loading/>
</div>
<div v-else-if="list.length === 0" class="empty-wrapper">
<div class="empty-content">
<Icon type="ios-people-outline" size="48"/>
<p>{{$L('暂无共同群组')}}</p>
</div>
</div>
<div v-else class="dialog-list">
<div
v-for="dialog in list"
:key="dialog.id"
class="dialog-item"
@click="onEnterDialog(dialog)">
<div class="dialog-avatar">
<EAvatar v-if="dialog.avatar" :src="dialog.avatar" :size="42"></EAvatar>
<i v-else-if="dialog.group_type=='department'" class="taskfont icon-avatar department">&#xe75c;</i>
<i v-else-if="dialog.group_type=='project'" class="taskfont icon-avatar project">&#xe6f9;</i>
<i v-else-if="dialog.group_type=='task'" class="taskfont icon-avatar task">&#xe6f4;</i>
<i v-else-if="dialog.group_type=='okr'" class="taskfont icon-avatar task">&#xe6f4;</i>
<Icon v-else class="icon-avatar" type="ios-people" />
</div>
<div class="dialog-info">
<div class="dialog-name" v-html="transformEmojiToHtml(dialog.name)"></div>
<div class="dialog-meta">
<span class="member-count">{{$L('(*)人', dialog.people || 0)}}</span>
<span v-if="dialog.last_at" class="last-time">{{$A.timeFormat(dialog.last_at)}}</span>
</div>
</div>
<Icon class="enter-icon" type="ios-arrow-forward" />
</div>
<div v-if="hasMore" class="load-more-wrapper">
<Button type="primary" @click="loadList(true)" :loading="loading > 0">{{$L('加载更多')}}</Button>
</div>
</div>
</div>
</Modal>
</template>
<script>
import transformEmojiToHtml from "../../../utils/emoji";
export default {
name: 'CommonDialogModal',
props: {
value: { // v-model
type: Boolean,
default: false,
},
targetUserId: {
type: [Number, String],
required: true,
},
totalCount: {
type: [Number, String],
default: 0,
},
},
data() {
return {
list: [],
page: 1,
hasMore: false,
loading: 0,
}
},
computed: {
visibleProxy: {
get() { return this.value; },
set(v) { this.$emit('input', v); }
}
},
watch: {
visibleProxy(val) {
if (val && this.list.length === 0) {
this.loadList(false);
}
},
targetUserId() {
// reset when user changes
this.list = [];
this.page = 1;
this.hasMore = false;
}
},
methods: {
transformEmojiToHtml,
loadList(loadMore = false) {
if (!this.targetUserId) return;
this.loading++;
const page = loadMore ? this.page + 1 : 1;
this.$store.dispatch('call', {
url: 'dialog/common/list',
data: {
target_userid: this.targetUserId,
page
}
}).then(({data}) => {
const newList = loadMore ? [...this.list, ...data.data] : data.data;
this.list = Array.isArray(newList) ? newList : [];
this.page = data.current_page || page;
this.hasMore = !!data.next_page_url;
}).catch(({msg}) => {
$A.modalError(msg || this.$L('加载失败'));
}).finally(() => {
this.loading--;
});
},
onEnterDialog(dialog) {
this.$emit('open-chat', dialog);
}
}
}
</script>
<style scoped>
/* 组件自身不引入额外样式,复用全局样式类名 */
</style>

View File

@ -5,7 +5,8 @@
:fullscreen="isFullscreen" :fullscreen="isFullscreen"
:mask-closable="false" :mask-closable="false"
:footer-hide="true" :footer-hide="true"
width="420"> width="420"
>
<div class="user-detail-body"> <div class="user-detail-body">
<div class="profile-header"> <div class="profile-header">
<div class="cover-photo"></div> <div class="cover-photo"></div>
@ -14,70 +15,113 @@
:userid="userData.userid" :userid="userData.userid"
:size="80" :size="80"
:show-state-dot="false" :show-state-dot="false"
@on-click="onOpenAvatar"/> @on-click="onOpenAvatar"
/>
</div> </div>
</div> </div>
<div class="profile-content"> <div class="profile-content">
<div class="user-info-top"> <div class="user-info-top">
<span class="username">@{{userData.nickname || 'Arnoldy'}}</span> <span class="username"
<h1 class="fullname">{{userData.nickname || 'Arnoldy Chafe'}}</h1> >@{{ userData.profession || "管理员" }}</span
>
<h1 class="fullname">
{{ userData.nickname}}
</h1>
<div class="meta"> <div class="meta">
<span>{{userData.address || 'Bandung'}}</span> <!-- <span>{{userData.address || 'Bandung'}}</span> -->
<span @click="commonDialogShow = true"
>{{ $L("共同群组") }}:
{{ $L("(*)个", commonDialog.total) }}</span
>
<span class="separator">|</span> <span class="separator">|</span>
<span>Joined {{$A.newDateString(userData.line_at, 'MMM YYYY')}}</span> <span
>{{ $L("最后在线") }}:
{{
$A.newDateString(
userData.line_at,
"YYYY-MM-DD HH:mm"
) || "-"
}}</span
>
</div> </div>
</div> </div>
<div class="profile-actions"> <div class="profile-actions">
<Button type="primary" icon="ios-person-add-outline">{{$L('Follow')}}</Button> <Button
<Button icon="ios-chatbubble-outline">{{$L('Message')}}</Button> type="primary"
<Button icon="ios-more"></Button> icon="md-chatbubbles"
@click="onOpenDialog"
>{{ $L("开始聊天") }}</Button
>
</div> </div>
<div class="profile-bio"> <div class="profile-bio">
<p>{{userData.introduction || 'CEO System D, Because your satisfaction is everything & Standing out from the rest, and that\'s what we want you to be as well.'}}</p> <p>{{ userData.introduction }}</p>
</div> </div>
<div class="profile-information"> <div class="profile-information">
<h2>{{$L('Information')}}</h2> <h2>{{ $L("个人信息") }}</h2>
<ul> <ul>
<li> <li>
<Icon type="ios-globe-outline" /> <Icon type="ios-person-outline" />
<span class="label">{{$L('Website')}}</span> <span class="label">{{ $L("部门") }}</span>
<span class="value">www.Arnoldy.com</span> <span class="value">{{
userData.department_name || "-"
}}</span>
</li> </li>
<!-- <li>
<Icon type="ios-briefcase-outline" />
<span class="label">{{$L('职位/职称')}}</span>
<span class="value">{{ userData.profession || '-' }}</span>
</li> -->
<li> <li>
<Icon type="ios-mail-outline" /> <Icon type="ios-mail-outline" />
<span class="label">{{$L('Email')}}</span> <span class="label">{{ $L("邮箱") }}</span>
<span class="value">Hello@adalahreza.com</span> <span class="value">{{
userData.email || "-"
}}</span>
</li> </li>
<li> <li>
<Icon type="ios-call-outline" /> <Icon type="ios-call-outline" />
<span class="label">{{$L('Phone')}}</span> <span class="label">{{ $L("电话") }}</span>
<span class="value">+62 517 218 92 00</span> <span class="value">{{ userData.tel || "-" }}</span>
</li> </li>
<li> <li>
<Icon type="ios-calendar-outline" /> <Icon type="ios-calendar-outline" />
<span class="label">{{$L('Joined')}}</span> <span class="label">{{ $L("生日") }}</span>
<span class="value">{{$A.newDateString(userData.line_at, 'DD MMMM, YYYY')}}</span> <span class="value">{{
userData.birthday || "-"
}}</span>
</li> </li>
</ul> </ul>
</div>
<div class="profile-tags" @click="onOpenTagsModal"> <div class="profile-tags" @click.capture="onOpenTagsModal">
<div v-if="displayTags.length" class="tags-list"> <div v-if="displayTags.length" class="tags-list">
<Tag <Button
v-for="tag in displayTags" class="manage-tags-btn icon"
:key="tag.id" @click.stop="onOpenTagsModal"
:color="tag.recognized ? 'primary' : 'default'" >
class="tag-pill">{{tag.name}}</Tag> <Icon type="ios-settings-outline" /> 管理
<Tag v-if="!displayTags.length" class="tag-pill">UI Designer</Tag> </Button>
<Tag v-if="!displayTags.length" class="tag-pill">UX Designer</Tag> <Button
<Tag v-if="!displayTags.length" class="tag-pill">Design System</Tag> v-for="tag in displayTags"
<Tag v-if="!displayTags.length" class="tag-pill">Product</Tag> :key="tag.id"
<Tag v-if="!displayTags.length" class="tag-pill">Succesfull</Tag> :type="tag.recognized ? 'primary' : 'default'"
>
{{ tag.name }}
</Button>
</div>
<div v-else class="tags-empty">
<Button
type="dashed"
size="small"
icon="md-add"
class="add-tag-btn"
@click.stop="onOpenTagsModal"
>{{ $L("添加标签") }}</Button
>
</div>
</div> </div>
<span v-else class="tags-empty">{{$L('暂无个性标签')}}</span>
</div> </div>
</div> </div>
</div> </div>
@ -85,97 +129,142 @@
v-if="userData.userid" v-if="userData.userid"
v-model="tagModalVisible" v-model="tagModalVisible"
:userid="userData.userid" :userid="userData.userid"
@updated="onTagsUpdated"/> @updated="onTagsUpdated"
/>
<CommonDialogModal
v-model="commonDialogShow"
:target-user-id="userData.userid"
:total-count="commonDialog.total || 0"
@open-chat="onOpenCommonDialogChat"
/>
</ModalAlive> </ModalAlive>
</template> </template>
<script> <script>
import emitter from "../../../store/events"; import emitter from "../../../store/events";
import {mapState} from "vuex"; import { mapState } from "vuex";
import transformEmojiToHtml from "../../../utils/emoji";
import UserTagsModal from "./UserTagsModal.vue"; import UserTagsModal from "./UserTagsModal.vue";
import CommonDialogModal from "./CommonDialogModal.vue";
export default { export default {
name: 'UserDetail', name: "UserDetail",
components: {UserTagsModal}, components: { UserTagsModal, CommonDialogModal },
data() { data() {
return { return {
userData: { userData: {
userid: 0 userid: 0,
}, },
showModal: false, showModal: false,
tagModalVisible: false, tagModalVisible: false,
} commonDialog: {
userid: null,
total: null,
list: [],
page: 1,
has_more: false,
},
commonDialogShow: false,
commonDialogLoading: 0,
};
}, },
mounted() { mounted() {
emitter.on('openUser', this.onShow); emitter.on("openUser", this.onShow);
}, },
beforeDestroy() { beforeDestroy() {
emitter.off('openUser', this.onShow); emitter.off("openUser", this.onShow);
}, },
watch: { watch: {
...mapState(['cacheUserBasic']), ...mapState(["cacheUserBasic"]),
commonDialogShow() {
if (!this.commonDialogShow || this.commonDialog.list.length > 0) {
return;
}
this.loadCommonDialogList(false);
},
}, },
computed: { computed: {
isFullscreen({windowWidth}) { isFullscreen({ windowWidth }) {
return windowWidth < 576 return windowWidth < 576;
}, },
displayTags() { displayTags() {
return Array.isArray(this.userData.personal_tags) ? this.userData.personal_tags : []; return Array.isArray(this.userData.personal_tags)
? this.userData.personal_tags
: [];
}, },
personalTagTotal() { personalTagTotal() {
if (typeof this.userData.personal_tags_total === 'number') { if (typeof this.userData.personal_tags_total === "number") {
return this.userData.personal_tags_total; return this.userData.personal_tags_total;
} }
return this.displayTags.length; return this.displayTags.length;
} },
commonDialogList() {
return this.commonDialog.list || [];
},
}, },
methods: { methods: {
transformEmojiToHtml,
onShow(userid) { onShow(userid) {
if (!/^\d+$/.test(userid)) { if (!/^\d+$/.test(userid)) {
return return;
} }
this.$store.dispatch("showSpinner", 600) this.$store.dispatch("showSpinner", 600);
this.$store.dispatch('getUserData', userid).then(user => { this.$store
this.userData = user; .dispatch("getUserData", userid)
this.ensureTagDefaults(); .then((user) => {
this.showModal = true; this.userData = user;
}).finally(_ => { this.ensureTagDefaults();
this.$store.dispatch("hiddenSpinner") this.showModal = true;
}); this.loadCommonDialogCount();
})
.finally((_) => {
this.$store.dispatch("hiddenSpinner");
});
}, },
onHide() { onHide() {
this.showModal = false; this.showModal = false;
this.tagModalVisible = false; this.tagModalVisible = false;
this.commonDialogShow = false;
}, },
onOpenAvatar() { onOpenAvatar() {
this.$store.dispatch("previewImage", this.userData.userimg) this.$store.dispatch("previewImage", this.userData.userimg);
}, },
onOpenDialog() { onOpenDialog() {
this.$store.dispatch("openDialogUserid", this.userData.userid).then(_ => { this.$store
this.onHide() .dispatch("openDialogUserid", this.userData.userid)
}).catch(({msg}) => { .then((_) => {
$A.modalError(msg) this.onHide();
}); })
.catch(({ msg }) => {
$A.modalError(msg);
});
}, },
ensureTagDefaults() { ensureTagDefaults() {
if (!Array.isArray(this.userData.personal_tags)) { if (!Array.isArray(this.userData.personal_tags)) {
this.$set(this.userData, 'personal_tags', []); this.$set(this.userData, "personal_tags", []);
} }
if (typeof this.userData.personal_tags_total !== 'number') { if (typeof this.userData.personal_tags_total !== "number") {
this.$set(this.userData, 'personal_tags_total', this.userData.personal_tags.length); this.$set(
this.userData,
"personal_tags_total",
this.userData.personal_tags.length
);
} }
}, },
@ -186,11 +275,129 @@ export default {
this.tagModalVisible = true; this.tagModalVisible = true;
}, },
onTagsUpdated({top, total}) { onTagsUpdated({ top, total }) {
this.$set(this.userData, 'personal_tags', Array.isArray(top) ? top : []); this.$set(
this.$set(this.userData, 'personal_tags_total', typeof total === 'number' ? total : this.userData.personal_tags.length); this.userData,
"personal_tags",
Array.isArray(top) ? top : []
);
this.$set(
this.userData,
"personal_tags_total",
typeof total === "number"
? total
: this.userData.personal_tags.length
);
}, },
}
loadCommonDialogCount() {
const target_userid = this.userData.userid;
const previousUserId = this.commonDialog.userid;
if (!target_userid) {
this.commonDialog = {
...this.commonDialog,
userid: target_userid || null,
total: null,
list: [],
page: 1,
has_more: false,
};
return;
}
if (previousUserId !== target_userid) {
this.commonDialog = {
...this.commonDialog,
userid: target_userid,
total: null,
list: [],
page: 1,
has_more: false,
};
}
const cacheMap = this.$store.state.dialogCommonCountCache || {};
const cached = cacheMap[String(target_userid)];
if (cached && typeof cached.total !== "undefined") {
this.commonDialog = {
...this.commonDialog,
total: cached.total,
};
}
this.$store
.dispatch("call", {
url: "dialog/common/list",
data: {
target_userid,
only_count: "yes",
},
})
.then(({ data }) => {
if (target_userid !== this.userData.userid) {
return;
}
const parsedTotal = Number(data.total);
const total = Number.isNaN(parsedTotal) ? 0 : parsedTotal;
this.commonDialog = {
...this.commonDialog,
userid: target_userid,
total,
list: [],
page: 1,
has_more: false,
};
this.$store.commit("common/dialog/count/save", {
userid: target_userid,
total,
});
});
},
loadCommonDialogList(loadMore = false) {
this.commonDialogLoading++;
const target_userid = this.userData.userid;
this.$store
.dispatch("call", {
url: "dialog/common/list",
data: {
target_userid,
page: loadMore ? this.commonDialog.page + 1 : 1,
},
})
.then(({ data }) => {
if (target_userid !== this.userData.userid) {
return;
}
this.commonDialog = {
...this.commonDialog,
list: loadMore
? [...this.commonDialog.list, ...data.data]
: data.data,
total: data.total,
page: data.current_page,
has_more: !!data.next_page_url,
};
})
.catch(({ msg }) => {
$A.modalError(msg || this.$L("加载失败"));
})
.finally(() => {
this.commonDialogLoading--;
});
},
onOpenCommonDialogChat(dialog) {
this.$store
.dispatch("openDialog", dialog.id)
.then(() => {
this.onHide();
})
.catch(({ msg }) => {
$A.modalError(msg);
});
},
},
}; };
</script> </script>

View File

@ -43,7 +43,7 @@
:class="{'is-editing': editId === tag.id}"> :class="{'is-editing': editId === tag.id}">
<div class="tag-item-main"> <div class="tag-item-main">
<div class="tag-name" v-if="editId !== tag.id"> <div class="tag-name" v-if="editId !== tag.id">
<Tag :color="tag.recognized ? 'primary' : 'default'" class="tag-pill">{{tag.name}}</Tag> <Tag :color="tag.recognized ? '#84C56A' : 'default'" class="tag-pill">{{tag.name}}</Tag>
</div> </div>
<div class="tag-name edit" v-else> <div class="tag-name edit" v-else>
<Input <Input

View File

@ -50,7 +50,7 @@
<Tag <Tag
v-for="tag in displayTags" v-for="tag in displayTags"
:key="tag.id" :key="tag.id"
:color="tag.recognized ? 'primary' : 'default'" :color="tag.recognized ? '#84C56A' : 'default'"
class="tag-pill">{{tag.name}}</Tag> class="tag-pill">{{tag.name}}</Tag>
</template> </template>
<span v-else class="tags-empty">{{$L('暂无个性标签')}}</span> <span v-else class="tags-empty">{{$L('暂无个性标签')}}</span>

View File

@ -1,6 +1,7 @@
.common-user-detail-modal { .common-user-detail-modal {
.ivu-modal-content { .ivu-modal-content {
border-radius: 16px; border-radius: 16px !important;
margin-top: calc(var(--status-bar-height) + 46px) !important;
} }
.ivu-modal-body { .ivu-modal-body {
padding: 0 !important; padding: 0 !important;
@ -8,10 +9,10 @@
.user-detail-body { .user-detail-body {
.profile-header { .profile-header {
position: relative; position: relative;
height: 120px; height: 140px;
.cover-photo { .cover-photo {
background: #1a2c47; background: #84C56A;
height: 80px; height: 100px;
border-top-left-radius: 16px; border-top-left-radius: 16px;
border-top-right-radius: 16px; border-top-right-radius: 16px;
} }
@ -64,6 +65,8 @@
color: #515a6e; color: #515a6e;
line-height: 1.5; line-height: 1.5;
margin: 16px 0; margin: 16px 0;
padding: 0 50px;
font-size: 12px;
} }
.profile-information { .profile-information {
@ -84,7 +87,7 @@
li { li {
display: flex; display: flex;
align-items: center; align-items: flex-start; // 避免多行内容导致垂直居中不齐
padding: 8px 0; padding: 8px 0;
font-size: 14px; font-size: 14px;
@ -95,26 +98,39 @@
} }
.label { .label {
color: #515a6e; color: #808695;
flex: 0 0 64px;
flex-shrink: 0;
line-height: 22px;
margin-right: 8px;
} }
.value { .value {
margin-left: auto;
color: #17233d; color: #17233d;
font-weight: 500; font-weight: 500;
flex: 1 1 auto;
min-width: 0;
margin-left: 0;
text-align: right;
white-space: normal;
word-break: break-word;
overflow-wrap: break-word;
} }
} }
} }
} }
.profile-tags { .profile-tags {
margin-top: 24px; margin-top: 12px;
padding-top: 12px;
border-top: 1px solid #80869550;
cursor: pointer; cursor: pointer;
.tags-list { .tags-list {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: 8px; gap: 8px;
justify-content: center; justify-content: center;
position: relative;
} }
.ivu-tag { .ivu-tag {
margin: 0; margin: 0;