feat(avatar): enhance SpaceAvatar component with emoji support

- Updated SpaceAvatar component to allow emoji-based avatars, enabling users to select emojis as their space avatar.
- Added new props and computed properties to handle emoji logic and display.
- Enhanced UI to include an emoji picker and clear option for avatars.
- Updated localization strings in English and Chinese for new avatar features.
- Adjusted styles for emoji display and interaction.

This update improves user personalization options for avatars, enhancing the overall user experience in the application.
This commit is contained in:
wizardchen
2026-02-02 00:30:27 +08:00
committed by lyingbug
parent 72173432c9
commit 342e56735f
15 changed files with 767 additions and 352 deletions
+2 -16
View File
@@ -1,17 +1,3 @@
<svg width="20" height="20" viewBox="0 0 56 40" fill="none" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<defs>
<radialGradient id="orbGreen" cx="0.35" cy="0.35" r="0.7" gradientUnits="objectBoundingBox">
<stop offset="0%" stop-color="#6ee7a0"/>
<stop offset="45%" stop-color="#07C05F"/>
<stop offset="100%" stop-color="#047857"/>
</radialGradient>
</defs>
<!-- 连接线:粗实线 -->
<path d="M14 13 L24 10 M32 10 L42 13" stroke="#07C05F" stroke-width="2.2" stroke-linecap="round" opacity="0.95"/>
<path d="M28 14 L28 22 M20 18 L26 24 M36 18 L30 24" stroke="#07C05F" stroke-width="1.8" stroke-linecap="round" opacity="0.9"/>
<!-- 节点:立体球体 -->
<circle cx="10" cy="12" r="5" fill="url(#orbGreen)" stroke="#059669" stroke-width="0.8"/>
<circle cx="28" cy="8" r="6" fill="url(#orbGreen)" stroke="#059669" stroke-width="0.9"/>
<circle cx="46" cy="14" r="5" fill="url(#orbGreen)" stroke="#059669" stroke-width="0.8"/>
<circle cx="28" cy="28" r="7" fill="url(#orbGreen)" stroke="#059669" stroke-width="0.9"/>
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10 10C8.8 7.5 7.8 3.8 4.8 3.8C2.2 3.8 0.8 6.8 0.8 10C0.8 13.2 2.2 16.2 4.8 16.2C7.8 16.2 8.8 12.5 10 10C11.2 7.5 12.5 5.5 14.5 5.5C16.5 5.5 18 7.5 18 10C18 12.5 16.5 14.5 14.5 14.5C12.5 14.5 11.2 12.5 10 10Z" stroke="#07C05F" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 421 B

+2 -20
View File
@@ -1,21 +1,3 @@
<svg width="20" height="20" viewBox="0 0 56 40" fill="none" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<defs>
<radialGradient id="orbGray" cx="0.35" cy="0.35" r="0.7" gradientUnits="objectBoundingBox">
<stop offset="0%" stop-color="#b5b5b5"/>
<stop offset="45%" stop-color="#6b6b6b"/>
<stop offset="100%" stop-color="#3d3d3d"/>
</radialGradient>
<linearGradient id="lineGray" x1="0%" y1="0%" x2="100%" y2="0%" gradientUnits="objectBoundingBox">
<stop offset="0%" stop-color="#5c5c5c"/>
<stop offset="100%" stop-color="#4a4a4a"/>
</linearGradient>
</defs>
<!-- 连接线:粗实线增强空间感 -->
<path d="M14 13 L24 10 M32 10 L42 13" stroke="#5c5c5c" stroke-width="2.2" stroke-linecap="round" opacity="0.9"/>
<path d="M28 14 L28 22 M20 18 L26 24 M36 18 L30 24" stroke="#5c5c5c" stroke-width="1.8" stroke-linecap="round" opacity="0.85"/>
<!-- 节点:立体球体 -->
<circle cx="10" cy="12" r="5" fill="url(#orbGray)" stroke="#4a4a4a" stroke-width="0.8"/>
<circle cx="28" cy="8" r="6" fill="url(#orbGray)" stroke="#4a4a4a" stroke-width="0.9"/>
<circle cx="46" cy="14" r="5" fill="url(#orbGray)" stroke="#4a4a4a" stroke-width="0.8"/>
<circle cx="28" cy="28" r="7" fill="url(#orbGray)" stroke="#4a4a4a" stroke-width="0.9"/>
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10 10C8.8 7.5 7.8 3.8 4.8 3.8C2.2 3.8 0.8 6.8 0.8 10C0.8 13.2 2.2 16.2 4.8 16.2C7.8 16.2 8.8 12.5 10 10C11.2 7.5 12.5 5.5 14.5 5.5C16.5 5.5 18 7.5 18 10C18 12.5 16.5 14.5 14.5 14.5C12.5 14.5 11.2 12.5 10 10Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 426 B

+55 -12
View File
@@ -2,18 +2,22 @@
<div
class="space-avatar"
:style="avatarStyle"
:class="{ 'space-avatar-small': size === 'small', 'space-avatar-large': size === 'large' }"
:class="{ 'space-avatar-small': size === 'small', 'space-avatar-large': size === 'large', 'space-avatar-emoji': isEmoji }"
>
<!-- 协作网络图案:右下角点缀,可调大小/变形 -->
<svg class="space-avatar-decoration" viewBox="0 0 56 40" preserveAspectRatio="xMaxYMax meet" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<circle cx="10" cy="12" r="4" stroke="currentColor" stroke-width="1.5" fill="none" opacity="0.5"/>
<circle cx="28" cy="8" r="5" stroke="currentColor" stroke-width="1.8" fill="none" opacity="0.7"/>
<circle cx="46" cy="14" r="4" stroke="currentColor" stroke-width="1.5" fill="none" opacity="0.5"/>
<path d="M14 13 L24 10 M32 10 L42 13" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" opacity="0.4"/>
<circle cx="28" cy="28" r="6" stroke="currentColor" stroke-width="1.2" fill="none" opacity="0.35"/>
<path d="M28 14 L28 22 M20 18 L26 24 M36 18 L30 24" stroke="currentColor" stroke-width="1" stroke-linecap="round" opacity="0.3"/>
</svg>
<span class="space-avatar-letter" :style="letterStyle">{{ letter }}</span>
<template v-if="isEmoji">
<span class="space-avatar-emoji-char">{{ emojiChar }}</span>
</template>
<template v-else>
<svg class="space-avatar-decoration" viewBox="0 0 56 40" preserveAspectRatio="xMaxYMax meet" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<circle cx="10" cy="12" r="4" stroke="currentColor" stroke-width="1.5" fill="none" opacity="0.5"/>
<circle cx="28" cy="8" r="5" stroke="currentColor" stroke-width="1.8" fill="none" opacity="0.7"/>
<circle cx="46" cy="14" r="4" stroke="currentColor" stroke-width="1.5" fill="none" opacity="0.5"/>
<path d="M14 13 L24 10 M32 10 L42 13" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" opacity="0.4"/>
<circle cx="28" cy="28" r="6" stroke="currentColor" stroke-width="1.2" fill="none" opacity="0.35"/>
<path d="M28 14 L28 22 M20 18 L26 24 M36 18 L30 24" stroke="currentColor" stroke-width="1" stroke-linecap="round" opacity="0.3"/>
</svg>
<span class="space-avatar-letter" :style="letterStyle">{{ letter }}</span>
</template>
</div>
</template>
@@ -22,9 +26,23 @@ import { computed } from 'vue';
const props = withDefaults(defineProps<{
name: string;
/** Optional: "emoji:🚀" for emoji avatar; otherwise name-based */
avatar?: string;
size?: 'small' | 'medium' | 'large';
}>(), {
size: 'medium'
size: 'medium',
avatar: ''
});
const isEmoji = computed(() => {
const v = (props.avatar || '').trim();
return v.startsWith('emoji:') && v.length > 6;
});
const emojiChar = computed(() => {
const v = (props.avatar || '').trim();
if (!v.startsWith('emoji:')) return '';
return v.slice(6).trim() || '';
});
// 预定义渐变色(与项目绿色主色协调,偏空间/协作感)
@@ -67,6 +85,9 @@ const gradient = computed(() => {
});
const avatarStyle = computed(() => {
if (isEmoji.value) {
return { background: 'linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%)' };
}
const g = gradient.value;
return {
background: `linear-gradient(135deg, ${g.from} 0%, ${g.to} 100%)`
@@ -117,6 +138,28 @@ const letterStyle = computed(() => {
.space-avatar-letter {
font-size: 20px;
}
.space-avatar-emoji-char {
font-size: 28px;
}
}
&.space-avatar-emoji {
.space-avatar-emoji-char {
position: relative;
z-index: 1;
line-height: 1;
user-select: none;
}
}
}
.space-avatar-emoji-char {
font-size: 18px;
line-height: 1;
.space-avatar-small & {
font-size: 14px;
}
}
+5
View File
@@ -2343,6 +2343,8 @@ export default {
namePlaceholder: 'Enter space name',
nameRequired: 'Please enter space name',
avatar: 'Space Avatar',
avatarClear: 'Clear',
avatarPickerHint: 'Choose an emoji as space avatar',
description: 'Description',
descriptionPlaceholder: 'Enter space description (optional)',
noDescription: 'No description',
@@ -2379,6 +2381,7 @@ export default {
noSearchableSpaces: 'No discoverable spaces yet, or try a search',
membersWithLimit: '{current}/{limit} members',
memberLimitReached: 'Full',
backToSearch: 'Back to search',
},
invite: {
loading: 'Loading...',
@@ -2436,6 +2439,8 @@ export default {
all: 'All',
createdByMe: 'Created by me',
joinedByMe: 'Joined',
createdTag: 'Created',
joinedTag: 'Joined',
joinedLabel: 'Joined',
emptyCreated: 'You have not created any space yet',
emptyCreatedDesc: 'Click "Create Space" to create one',
+5
View File
@@ -2348,6 +2348,8 @@ export default {
namePlaceholder: "请输入空间名称",
nameRequired: "请输入空间名称",
avatar: "空间头像",
avatarClear: "清除",
avatarPickerHint: "选择 Emoji 作为空间头像",
description: "空间描述",
descriptionPlaceholder: "请输入空间描述(选填)",
noDescription: "暂无描述",
@@ -2384,6 +2386,7 @@ export default {
noSearchableSpaces: "暂无开放可被搜索的空间,或输入关键词搜索",
membersWithLimit: "{current}/{limit} 成员",
memberLimitReached: "成员已满",
backToSearch: "返回搜索",
},
invite: {
loading: "加载中...",
@@ -2441,6 +2444,8 @@ export default {
all: "全部",
createdByMe: "我创建的",
joinedByMe: "我加入的",
createdTag: "创建",
joinedTag: "加入",
joinedLabel: "已加入",
emptyCreated: "您还没有创建任何共享空间",
emptyCreatedDesc: "点击「创建空间」创建一个新空间",
File diff suppressed because it is too large Load Diff
@@ -41,7 +41,7 @@
</div>
<div class="settings-group">
<!-- 空间名称(头像由名称生成,与智能体一致) -->
<!-- 空间名称与头像:一行展示,头像点击弹出 Emoji 选择 -->
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('organization.name') }} <span class="required">*</span></label>
@@ -49,7 +49,44 @@
</div>
<div class="setting-control">
<div class="name-input-wrapper">
<SpaceAvatar :name="formData.name || '?'" size="large" />
<t-popup
v-model="avatarPopoverVisible"
trigger="click"
placement="bottom-left"
:disabled="!isAdmin"
overlay-class-name="avatar-emoji-popover"
>
<div class="avatar-trigger-wrap">
<SpaceAvatar :name="formData.name || '?'" :avatar="formData.avatar" size="large" />
<span v-if="isAdmin" class="avatar-change-hint">{{ $t('organization.avatar') }}</span>
</div>
<template #content>
<div class="avatar-popover-content" @click.stop>
<p class="avatar-popover-title">{{ $t('organization.avatarPickerHint') }}</p>
<div class="avatar-emoji-grid">
<button
v-for="emoji in avatarEmojiOptions"
:key="emoji"
type="button"
class="avatar-emoji-btn"
:class="{ 'is-selected': formData.avatar === 'emoji:' + emoji }"
@click="selectAvatarEmoji(emoji)"
>
{{ emoji }}
</button>
</div>
<t-button
v-if="formData.avatar"
variant="text"
size="small"
class="avatar-clear-btn"
@click="clearAvatarEmoji"
>
{{ $t('organization.avatarClear') }}
</t-button>
</div>
</template>
</t-popup>
<t-input
v-model="formData.name"
:placeholder="$t('organization.namePlaceholder')"
@@ -693,12 +730,30 @@ const addMemberRole = ref<'admin' | 'editor' | 'viewer'>('viewer')
const formData = ref({
name: '',
description: '',
avatar: '' as string,
require_approval: false,
searchable: false,
invite_code_validity_days: 7 as number,
member_limit: 50 as number // 0 = unlimited
})
// 空间头像可选 Emoji(方案三:Emoji 作为头像)
const avatarEmojiOptions = [
'🚀', '📁', '👥', '🏢', '💡', '📚', '🌟', '🔧', '📌', '🎯',
'📂', '🔒', '🌐', '⚡', '🎨', '📊', '🤝', '💼', '📧', '🏠',
'🔑', '📈', '✨', '📋', '🌍', '💬', '🔔', '📦', '🎉', '🌈'
]
const avatarPopoverVisible = ref(false)
function selectAvatarEmoji(emoji: string) {
formData.value.avatar = 'emoji:' + emoji
avatarPopoverVisible.value = false
}
function clearAvatarEmoji() {
formData.value.avatar = ''
avatarPopoverVisible.value = false
}
// Computed
const isCreateMode = computed(() => props.mode === 'create')
const isEditMode = computed(() => props.mode === 'edit' || props.mode === 'create')
@@ -821,6 +876,7 @@ const fetchOrgDetail = async () => {
formData.value = {
name: res.data.name,
description: res.data.description || '',
avatar: res.data.avatar || '',
require_approval: res.data.require_approval || false,
searchable: res.data.searchable || false,
invite_code_validity_days: typeof validity === 'number' ? validity : 7,
@@ -972,6 +1028,7 @@ const handleSave = async () => {
const res = await updateOrganization(props.orgId, {
name: formData.value.name.trim(),
description: formData.value.description.trim(),
avatar: formData.value.avatar || undefined,
require_approval: formData.value.require_approval,
searchable: formData.value.searchable,
invite_code_validity_days: formData.value.invite_code_validity_days,
@@ -1259,7 +1316,7 @@ watch(() => props.visible, (newVal) => {
joinRequests.value = []
if (props.mode === 'create') {
// 创建模式:重置表单
formData.value = { name: '', description: '', require_approval: false, searchable: false, invite_code_validity_days: 7, member_limit: 50 }
formData.value = { name: '', description: '', avatar: '', require_approval: false, searchable: false, invite_code_validity_days: 7, member_limit: 50 }
orgInfo.value = null
members.value = []
sharedKnowledgeBases.value = []
@@ -1560,6 +1617,26 @@ watch(currentSection, (section) => {
}
}
.avatar-trigger-wrap {
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
cursor: pointer;
flex-shrink: 0;
padding: 4px;
border-radius: 12px;
transition: background 0.2s ease;
}
.avatar-trigger-wrap:hover {
background: rgba(0, 0, 0, 0.04);
}
.avatar-change-hint {
font-size: 11px;
color: #94a3b8;
line-height: 1.2;
}
.name-input-wrapper {
display: flex;
align-items: center;
@@ -1570,6 +1647,54 @@ watch(currentSection, (section) => {
min-width: 0;
}
/* 头像 Emoji 弹层内容 */
.avatar-popover-content {
padding: 12px;
min-width: 260px;
}
.avatar-popover-title {
margin: 0 0 10px 0;
font-size: 12px;
color: #64748b;
line-height: 1.4;
}
.avatar-popover-content .avatar-emoji-grid {
display: flex;
flex-wrap: wrap;
gap: 6px;
max-width: 280px;
}
.avatar-popover-content .avatar-emoji-btn {
display: flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
padding: 0;
border: 1px solid #e2e8f0;
border-radius: 8px;
background: #fff;
font-size: 18px;
cursor: pointer;
transition: border-color 0.2s ease, background 0.2s ease;
}
.avatar-popover-content .avatar-emoji-btn:hover {
border-color: #07c05f;
background: rgba(7, 192, 95, 0.06);
}
.avatar-popover-content .avatar-emoji-btn.is-selected {
border-color: #07c05f;
background: rgba(7, 192, 95, 0.12);
}
.avatar-popover-content .avatar-clear-btn {
margin-top: 10px;
color: #64748b;
font-size: 12px;
}
.avatar-popover-content .avatar-clear-btn:hover {
color: #059669;
}
// 邀请卡片样式
.invite-card {
background: #f5f5f5;
@@ -99,7 +99,7 @@ func (r *organizationRepository) ListSearchable(ctx context.Context, query strin
// Update updates an organization (Select ensures zero values like invite_code_validity_days=0 are persisted)
func (r *organizationRepository) Update(ctx context.Context, org *types.Organization) error {
return r.db.WithContext(ctx).Model(&types.Organization{}).Where("id = ?", org.ID).
Select("name", "description", "require_approval", "searchable", "invite_code_validity_days", "member_limit", "updated_at").
Select("name", "description", "avatar", "require_approval", "searchable", "invite_code_validity_days", "member_limit", "updated_at").
Updates(org).Error
}
@@ -1,5 +1,6 @@
-- Migration: Create "未分类" tag for each knowledge base that has untagged entries
-- and update chunks, knowledges, and embeddings to reference the new tag
ALTER EXTENSION pg_search UPDATE;
DO $$
DECLARE
@@ -1,9 +1,9 @@
-- Migration: 000011_organizations (down, merged 000011–000017, 000012)
DO $$ BEGIN RAISE NOTICE '[Migration 000011] Rolling back organization tables...'; END $$;
-- Migration: 000012_organizations (down, merged 000011–000017, 000012, 000013)
DO $$ BEGIN RAISE NOTICE '[Migration 000012] Rolling back organization tables...'; END $$;
DROP TABLE IF EXISTS organization_join_requests;
DROP TABLE IF EXISTS kb_shares;
DROP TABLE IF EXISTS organization_members;
DROP TABLE IF EXISTS organizations;
DO $$ BEGIN RAISE NOTICE '[Migration 000011] Rollback completed successfully!'; END $$;
DO $$ BEGIN RAISE NOTICE '[Migration 000012] Rollback completed successfully!'; END $$;
@@ -1,6 +1,6 @@
-- Migration: 000011_organizations (merged 000011–000017, 000012)
-- Description: Organization tables, approval, invite expiry, join requests, avatar, searchable
DO $$ BEGIN RAISE NOTICE '[Migration 000011] Starting organization tables setup...'; END $$;
-- Migration: 000012_organizations (merged 000011–000017, 000012, 000013)
-- Description: Organization tables, approval, invite expiry, join requests, avatar, searchable, member_limit
DO $$ BEGIN RAISE NOTICE '[Migration 000012] Starting organization tables setup...'; END $$;
-- Create organizations table
CREATE TABLE IF NOT EXISTS organizations (
@@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS organizations (
invite_code_validity_days SMALLINT NOT NULL DEFAULT 7,
avatar VARCHAR(512) DEFAULT '',
searchable BOOLEAN NOT NULL DEFAULT FALSE,
member_limit INTEGER NOT NULL DEFAULT 50,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE
@@ -30,6 +31,7 @@ COMMENT ON COLUMN organizations.require_approval IS 'Whether joining this organi
COMMENT ON COLUMN organizations.invite_code_expires_at IS 'When the current invite code expires; NULL means no expiry (legacy)';
COMMENT ON COLUMN organizations.invite_code_validity_days IS 'Invite link validity in days: 0=never expire, 1/7/30 days';
COMMENT ON COLUMN organizations.searchable IS 'When true, space appears in search and can be joined by org ID';
COMMENT ON COLUMN organizations.member_limit IS 'Max members allowed; 0 means no limit';
-- Create organization_members table
CREATE TABLE IF NOT EXISTS organization_members (
@@ -106,4 +108,4 @@ COMMENT ON COLUMN organization_join_requests.message IS 'Optional message from t
COMMENT ON COLUMN organization_join_requests.reviewed_by IS 'User ID of the admin who reviewed the request';
COMMENT ON COLUMN organization_join_requests.review_message IS 'Optional message from the reviewer';
DO $$ BEGIN RAISE NOTICE '[Migration 000011] Organization tables setup completed successfully!'; END $$;
DO $$ BEGIN RAISE NOTICE '[Migration 000012] Organization tables setup completed successfully!'; END $$;
@@ -1,2 +0,0 @@
-- Rollback: 000012_organizations_searchable
ALTER TABLE organizations DROP COLUMN IF EXISTS searchable;
@@ -1,8 +0,0 @@
-- Migration: 000012_organizations_searchable
-- Description: Add searchable flag to organizations (open for discovery)
DO $$ BEGIN RAISE NOTICE '[Migration 000012] Adding searchable to organizations...'; END $$;
ALTER TABLE organizations ADD COLUMN IF NOT EXISTS searchable BOOLEAN NOT NULL DEFAULT FALSE;
COMMENT ON COLUMN organizations.searchable IS 'When true, space appears in search and can be joined by org ID';
DO $$ BEGIN RAISE NOTICE '[Migration 000012] Organizations searchable column added.'; END $$;
@@ -1,3 +0,0 @@
-- Migration: 000013_organization_member_limit (down)
ALTER TABLE organizations
DROP COLUMN IF EXISTS member_limit;
@@ -1,6 +0,0 @@
-- Migration: 000013_organization_member_limit
-- Description: Add member_limit to organizations (0 = unlimited)
ALTER TABLE organizations
ADD COLUMN IF NOT EXISTS member_limit INTEGER NOT NULL DEFAULT 50;
COMMENT ON COLUMN organizations.member_limit IS 'Max members allowed; 0 means no limit';