推入代码

majiayan_branch
psnci6hgk 3 months ago
parent e40ce3bab5
commit dcedd71e90

@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

@ -0,0 +1,3 @@
{
"recommendations": ["Vue.volar"]
}

@ -0,0 +1,5 @@
# Vue 3 + Vite
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
Learn more about IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support).

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

File diff suppressed because it is too large Load Diff

@ -0,0 +1,20 @@
{
"name": "oc-community-frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"element-plus": "^2.11.2",
"vue": "^3.5.18",
"vue-router": "^4.5.1"
},
"devDependencies": {
"@vitejs/plugin-vue": "^6.0.1",
"vite": "^7.1.2"
}
}

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

@ -0,0 +1,16 @@
<template>
<div id="app">
<router-view></router-view>
</div>
</template>
<script setup>
</script>
<style>
#app {
height: 100vh;
margin: 0;
padding: 0;
}
</style>

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

After

Width:  |  Height:  |  Size: 496 B

@ -0,0 +1,165 @@
<template>
<div class="chat-window">
<div class="chat-header">
<div class="header-left">
<img v-if="activeContact" class="header-avatar" :src="activeContact.avatar" alt="avatar" />
<div>
<div class="chat-title">{{ activeContact?.name || '选择联系人' }}</div>
<div class="chat-subtitle" v-if="activeContact">{{ activeContact.status || '线' }}</div>
</div>
</div>
<div class="header-actions">
<el-button text :icon="Message" @click="$emit('open-info')"></el-button>
<el-button text :icon="Phone" @click="$emit('audio-call')"></el-button>
<el-button text :icon="VideoCamera" @click="$emit('video-call')"></el-button>
</div>
</div>
<div class="chat-messages" ref="messagesContainer">
<div
v-for="(msg, index) in messages"
:key="index"
class="message-row"
:class="{ mine: msg.senderId === selfId }"
>
<img class="avatar" :src="msg.senderId === selfId ? selfAvatar : activeContact?.avatar" alt="avatar" />
<div class="bubble">{{ msg.text }}</div>
</div>
<div v-if="messages.length === 0" class="empty"> {{ activeContact?.name || '...' }} </div>
</div>
<div class="chat-input">
<el-input
v-model="draft"
:placeholder="activeContact ? '输入消息...' : '请选择联系人后再发送'"
:disabled="!activeContact"
@keydown.enter.exact.prevent="handleSend"
clearable
/>
<el-button type="primary" :disabled="!canSend" @click="handleSend"></el-button>
</div>
</div>
</template>
<script setup>
import { onMounted, onUpdated, ref, watch, nextTick, computed } from 'vue'
import { Message, Phone, VideoCamera } from '@element-plus/icons-vue'
const props = defineProps({
activeContact: {
type: Object,
default: null
},
modelValue: {
type: Array,
default: () => []
},
selfId: {
type: String,
default: 'me'
},
selfAvatar: {
type: String,
default: 'https://avatars.githubusercontent.com/u/9919?v=4'
}
})
const emit = defineEmits(['update:modelValue', 'send'])
const messages = ref(props.modelValue)
watch(() => props.modelValue, v => (messages.value = v))
const draft = ref('')
const messagesContainer = ref(null)
const canSend = computed(() => !!props.activeContact && draft.value.trim().length > 0)
const scrollToBottom = async () => {
await nextTick()
const el = messagesContainer.value
if (el) {
el.scrollTop = el.scrollHeight
}
}
onMounted(scrollToBottom)
onUpdated(scrollToBottom)
watch(messages, scrollToBottom, { deep: true })
const handleSend = () => {
if (!canSend.value) return
const newMsg = {
senderId: props.selfId,
text: draft.value.trim(),
timestamp: Date.now()
}
const nextMessages = [...messages.value, newMsg]
messages.value = nextMessages
emit('update:modelValue', nextMessages)
emit('send', { contact: props.activeContact, message: newMsg })
draft.value = ''
}
</script>
<style scoped>
.chat-window {
display: flex;
flex-direction: column;
height: 100%;
background: #f5f7fa;
}
.chat-header {
padding: 10px 12px;
border-bottom: 1px solid #ebeef5;
background: #fff;
}
.chat-title {
font-weight: 600;
}
.chat-subtitle {
font-size: 12px;
color: #909399;
}
.chat-messages {
flex: 1;
overflow-y: auto;
padding: 12px;
}
.empty {
margin-top: 24px;
text-align: center;
color: #909399;
}
.message-row {
display: flex;
gap: 8px;
margin-bottom: 10px;
align-items: flex-end;
}
.message-row.mine {
flex-direction: row-reverse;
}
.avatar {
width: 28px;
height: 28px;
border-radius: 50%;
}
.bubble {
max-width: 70%;
padding: 8px 10px;
border-radius: 6px;
background: #fff;
border: 1px solid #ebeef5;
}
.message-row.mine .bubble {
background: #409eff;
color: #fff;
border-color: #409eff;
}
.chat-input {
display: flex;
gap: 8px;
padding: 10px;
border-top: 1px solid #ebeef5;
background: #fff;
}
</style>

@ -0,0 +1,207 @@
<template>
<div class="community-container">
<!-- 主社区内容区域 -->
<div class="main-content">
<h2>OC社区</h2>
<p>这里是社区场景你的OC正在这里活动</p>
<!-- 社区背景和OC活动区域 -->
<div class="community-scene">
<div class="scene-background">
<img src="https://picsum.photos/800/600?random=1" alt="社区场景" class="scene-image" />
</div>
<!-- 这里将来会显示OC的位置和活动 -->
<div class="oc-characters">
<!-- OC角色会在这里显示 -->
</div>
</div>
</div>
<!-- 右侧功能按钮区域 -->
<div class="right-panel">
<div class="function-buttons">
<el-button
type="primary"
size="large"
@click="showUserCenter = true"
class="function-btn"
>
<el-icon><User /></el-icon>
<span>用户中心</span>
</el-button>
<el-button
type="success"
size="large"
@click="showOCList = true"
class="function-btn"
>
<el-icon><Avatar /></el-icon>
<span>OC列表</span>
</el-button>
<el-button
type="info"
size="large"
@click="showPhone = true"
class="function-btn"
>
<el-icon><Phone /></el-icon>
<span>手机通信</span>
</el-button>
</div>
</div>
<!-- 弹窗组件 -->
<UserCenterDialog v-model="showUserCenter" />
<OCListDialog v-model="showOCList" />
<PhoneWidget v-model="showPhone" />
</div>
</template>
<script setup>
import { ref } from 'vue'
import { User, Avatar, Phone } from '@element-plus/icons-vue'
import PhoneWidget from './PhoneWidget.vue'
import UserCenterDialog from './UserCenterDialog.vue'
import OCListDialog from './OCListDialog.vue'
// /
const showPhone = ref(false)
const showUserCenter = ref(false)
const showOCList = ref(false)
</script>
<style scoped>
.community-container {
display: flex;
height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
position: relative;
overflow: hidden;
}
.main-content {
flex: 1;
padding: 20px;
color: white;
display: flex;
flex-direction: column;
}
.main-content h2 {
margin: 0 0 10px 0;
font-size: 28px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.main-content p {
margin: 0 0 20px 0;
font-size: 16px;
opacity: 0.9;
}
.community-scene {
flex: 1;
position: relative;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.scene-background {
width: 100%;
height: 100%;
position: relative;
}
.scene-image {
width: 100%;
height: 100%;
object-fit: cover;
}
.oc-characters {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.right-panel {
width: 200px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-left: 1px solid rgba(255, 255, 255, 0.2);
display: flex;
flex-direction: column;
align-items: center;
padding: 20px 10px;
}
.function-buttons {
display: flex;
flex-direction: column;
gap: 15px;
width: 100%;
align-items: center;
}
.function-btn {
width: 100%;
height: 60px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 5px;
border-radius: 12px;
font-weight: 600;
transition: all 0.3s ease;
border: 2px solid transparent;
}
.function-btn:hover {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}
.function-btn span {
font-size: 14px;
}
.function-btn .el-icon {
font-size: 20px;
}
/* 响应式设计 */
@media (max-width: 768px) {
.community-container {
flex-direction: column;
}
.right-panel {
width: 100%;
height: auto;
flex-direction: row;
justify-content: space-around;
padding: 10px;
}
.function-buttons {
flex-direction: row;
gap: 10px;
}
.function-btn {
height: 50px;
flex: 1;
}
.function-btn span {
font-size: 12px;
}
}
</style>

@ -0,0 +1,124 @@
<template>
<div class="contacts">
<div class="contacts-header">
<el-input v-model="keyword" placeholder="搜索联系人" clearable />
</div>
<el-scrollbar class="contacts-scroll">
<div
v-for="c in filtered"
:key="c.id"
class="contact-item"
:class="{ active: c.id === modelValue }"
@click="select(c.id)"
>
<img class="avatar" :src="c.avatar" alt="avatar" />
<div class="meta">
<div class="name">{{ c.name }}</div>
<div class="last">{{ c.lastMessage || '...' }}</div>
</div>
<div class="time" v-if="c.lastTime">{{ formatTime(c.lastTime) }}</div>
<el-badge v-if="c.unread" :value="c.unread" class="unread" />
</div>
<div v-if="filtered.length === 0" class="empty"></div>
</el-scrollbar>
</div>
</template>
<script setup>
import { computed, ref } from 'vue'
const props = defineProps({
modelValue: {
type: String,
default: ''
},
contacts: {
type: Array,
default: () => []
}
})
const emit = defineEmits(['update:modelValue'])
const keyword = ref('')
const filtered = computed(() => {
const k = keyword.value.trim().toLowerCase()
if (!k) return props.contacts
return props.contacts.filter(c =>
c.name.toLowerCase().includes(k)
)
})
const select = id => emit('update:modelValue', id)
const formatTime = ts => {
try {
const d = new Date(ts)
const h = String(d.getHours()).padStart(2, '0')
const m = String(d.getMinutes()).padStart(2, '0')
return `${h}:${m}`
} catch (e) {
return ''
}
}
</script>
<style scoped>
.contacts {
display: flex;
flex-direction: column;
height: 100%;
border-right: 1px solid #ebeef5;
background: #fff;
}
.contacts-header {
padding: 10px;
border-bottom: 1px solid #ebeef5;
}
.contacts-scroll {
height: 100%;
}
.contact-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
cursor: pointer;
}
.contact-item:hover {
background: #f5f7fa;
}
.contact-item.active {
background: #ecf5ff;
}
.avatar {
width: 36px;
height: 36px;
border-radius: 8px;
}
.meta {
flex: 1;
min-width: 0;
}
.name {
font-weight: 600;
}
.last {
font-size: 12px;
color: #909399;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.time {
font-size: 12px;
color: #909399;
}
.empty {
padding: 16px;
text-align: center;
color: #909399;
}
</style>

@ -0,0 +1,37 @@
<template>
<div class="home-container">
<Navigation />
<div class="content">
<h2>首页</h2>
<el-space>
<el-button type="primary" @click="goCreate">OC</el-button>
<el-button @click="goCommunity"></el-button>
<el-button type="success" @click="goPhone"></el-button>
</el-space>
</div>
</div>
</template>
<script setup>
import { useRouter } from 'vue-router'
import Navigation from './Navigation.vue'
const router = useRouter()
const goCreate = () => router.push('/create-oc')
const goCommunity = () => router.push('/community')
const goPhone = () => router.push('/phone')
</script>
<style scoped>
.home-container {
display: flex;
flex-direction: column;
gap: 16px;
}
.content {
padding: 16px;
}
</style>

@ -0,0 +1,237 @@
<template>
<div class="login-container">
<div class="login-card">
<div class="login-header">
<h2>{{ isLoginMode ? '登录' : '注册' }}</h2>
<p>{{ isLoginMode ? '欢迎回来!' : '创建新账户' }}</p>
</div>
<el-form :model="form" label-width="80px" class="login-form">
<el-form-item label="用户名">
<el-input v-model="form.username" placeholder="请输入用户名" />
</el-form-item>
<el-form-item label="密码">
<el-input v-model="form.password" type="password" placeholder="请输入密码" />
</el-form-item>
<!-- 注册时才显示的字段 -->
<template v-if="!isLoginMode">
<el-form-item label="昵称">
<el-input v-model="form.nickname" placeholder="请输入昵称" />
</el-form-item>
<el-form-item label="生日">
<el-date-picker
v-model="form.birthday"
type="date"
placeholder="选择生日"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
/>
</el-form-item>
<el-form-item label="职业">
<el-input v-model="form.occupation" placeholder="请输入职业" />
</el-form-item>
<el-form-item label="喜好">
<el-input v-model="form.hobbies" placeholder="请输入你的喜好" />
</el-form-item>
<el-form-item label="个人简介">
<el-input
v-model="form.bio"
type="textarea"
:rows="3"
placeholder="介绍一下自己吧"
/>
</el-form-item>
</template>
<el-form-item>
<el-button
type="primary"
@click="isLoginMode ? handleLogin() : handleRegister()"
:loading="loading"
class="submit-btn"
>
{{ isLoginMode ? '登录' : '注册' }}
</el-button>
</el-form-item>
<el-form-item>
<el-button type="text" @click="toggleMode" class="toggle-btn">
{{ isLoginMode ? '还没有账户?点击注册' : '已有账户?点击登录' }}
</el-button>
</el-form-item>
</el-form>
</div>
</div>
</template>
<script setup>
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElLoading } from 'element-plus'
import { login, register } from '../stores/userStore.js'
const router = useRouter()
const form = reactive({
username: '',
password: '',
nickname: '',
birthday: '',
occupation: '',
hobbies: '',
bio: ''
})
const isLoginMode = ref(true)
const loading = ref(false)
const handleLogin = async () => {
if (!form.username || !form.password) {
ElMessage.warning('请输入用户名和密码')
return
}
loading.value = true
try {
const result = await login({
username: form.username,
password: form.password
})
if (result.success) {
ElMessage.success('登录成功')
router.push('/community')
}
} catch (error) {
ElMessage.error(error.message || '登录失败')
} finally {
loading.value = false
}
}
const handleRegister = async () => {
if (!form.username || !form.password) {
ElMessage.warning('请输入用户名和密码')
return
}
loading.value = true
try {
const result = await register({
username: form.username,
password: form.password,
nickname: form.nickname,
birthday: form.birthday,
occupation: form.occupation,
hobbies: form.hobbies,
bio: form.bio
})
if (result.success) {
ElMessage.success('注册成功,已自动登录')
//
router.push('/community')
}
} catch (error) {
ElMessage.error(error.message || '注册失败')
} finally {
loading.value = false
}
}
const toggleMode = () => {
isLoginMode.value = !isLoginMode.value
//
Object.keys(form).forEach(key => {
form[key] = ''
})
}
</script>
<style scoped>
.login-container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 20px;
}
.login-card {
background: white;
border-radius: 16px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
padding: 40px;
width: 100%;
max-width: 500px;
animation: slideUp 0.6s ease-out;
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.login-header {
text-align: center;
margin-bottom: 30px;
}
.login-header h2 {
margin: 0 0 10px 0;
color: #303133;
font-size: 28px;
font-weight: 600;
}
.login-header p {
margin: 0;
color: #909399;
font-size: 16px;
}
.login-form {
margin-top: 20px;
}
.submit-btn {
width: 100%;
height: 45px;
font-size: 16px;
font-weight: 600;
border-radius: 8px;
}
.toggle-btn {
width: 100%;
color: #409eff;
font-size: 14px;
}
.toggle-btn:hover {
color: #66b1ff;
}
/* 响应式设计 */
@media (max-width: 768px) {
.login-card {
padding: 30px 20px;
margin: 10px;
}
.login-header h2 {
font-size: 24px;
}
.login-header p {
font-size: 14px;
}
}
</style>

@ -0,0 +1,13 @@
<template>
<div class="navigation">
<el-menu mode="horizontal" :router="true">
<el-menu-item index="/login">登录</el-menu-item>
<el-menu-item index="/create-oc">创建OC</el-menu-item>
<el-menu-item index="/community">社区</el-menu-item>
</el-menu>
</div>
</template>
<script setup>
// 使 :router="true"
</script>

@ -0,0 +1,247 @@
<template>
<div class="creation-container">
<div class="creation-card">
<div class="creation-header">
<h2>创建你的OC</h2>
<p>设计一个独特的角色让它在社区中生活</p>
</div>
<el-form :model="ocForm" label-width="120px" class="creation-form">
<el-form-item label="OC名称" required>
<el-input v-model="ocForm.name" placeholder="请输入OC名称" />
</el-form-item>
<el-form-item label="性格描述">
<el-input
v-model="ocForm.personality"
type="textarea"
:rows="3"
placeholder="描述一下这个角色的性格特点"
/>
</el-form-item>
<el-form-item label="职业">
<el-input v-model="ocForm.occupation" placeholder="请输入职业" />
</el-form-item>
<el-form-item label="生日">
<el-date-picker
v-model="ocForm.birthday"
type="date"
placeholder="选择生日"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
/>
</el-form-item>
<el-form-item label="爱好">
<el-input
v-model="ocForm.hobbies"
placeholder="请输入爱好,用逗号分隔"
/>
</el-form-item>
<el-form-item label="个人简介">
<el-input
v-model="ocForm.bio"
type="textarea"
:rows="3"
placeholder="介绍一下这个角色"
/>
</el-form-item>
<el-form-item label="头像">
<el-input v-model="ocForm.avatar" placeholder="头像URL可选" />
</el-form-item>
<el-form-item>
<el-button
type="primary"
@click="handleAIGenerate"
class="action-btn"
>
AI随机生成
</el-button>
<el-button
type="success"
@click="handleSubmit"
:loading="loading"
class="action-btn"
>
确认创建
</el-button>
<el-button
type="info"
@click="handleCancel"
class="action-btn"
>
取消创建
</el-button>
</el-form-item>
</el-form>
</div>
</div>
</template>
<script setup>
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { addOC } from '../stores/ocStore.js'
import { currentUser } from '../stores/userStore.js'
const router = useRouter()
const loading = ref(false)
const ocForm = reactive({
name: '',
personality: '',
occupation: '',
birthday: '',
hobbies: '',
bio: '',
avatar: ''
})
const handleAIGenerate = () => {
console.log('AI生成OC')
// AI
ocForm.name = '小' + Math.random().toString(36).substr(2, 4)
ocForm.personality = '活泼开朗,喜欢交朋友'
ocForm.occupation = '学生'
ocForm.birthday = '2000-01-01'
ocForm.hobbies = '音乐、绘画、运动'
ocForm.bio = '这是一个由AI生成的OC角色'
ocForm.avatar = `https://i.pravatar.cc/100?img=${Math.floor(Math.random() * 50) + 1}`
ElMessage.success('AI生成完成')
}
const handleSubmit = async () => {
if (!ocForm.name.trim()) {
ElMessage.warning('请输入OC名称')
return
}
loading.value = true
try {
//
const hobbies = ocForm.hobbies ? ocForm.hobbies.split(/[,]/).map(h => h.trim()).filter(h => h) : []
// OC
const ocData = {
name: ocForm.name,
personality: ocForm.personality,
occupation: ocForm.occupation || '学生',
birthday: ocForm.birthday || '2000-01-01',
hobbies: hobbies,
bio: ocForm.bio || '这是一个新创建的OC角色',
avatar: ocForm.avatar || 'https://i.pravatar.cc/100?img=1'
}
// OC使
addOC(ocData, currentUser.value.username)
ElMessage.success('OC创建成功')
//
router.push('/community')
} catch (error) {
ElMessage.error('创建失败:' + error.message)
} finally {
loading.value = false
}
}
const handleCancel = () => {
//
Object.keys(ocForm).forEach(key => {
ocForm[key] = ''
})
//
router.push('/community')
}
</script>
<style scoped>
.creation-container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 20px;
}
.creation-card {
background: white;
border-radius: 16px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
padding: 40px;
width: 100%;
max-width: 600px;
animation: slideUp 0.6s ease-out;
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.creation-header {
text-align: center;
margin-bottom: 30px;
}
.creation-header h2 {
margin: 0 0 10px 0;
color: #303133;
font-size: 28px;
font-weight: 600;
}
.creation-header p {
margin: 0;
color: #909399;
font-size: 16px;
}
.creation-form {
margin-top: 20px;
}
.action-btn {
width: 120px;
height: 40px;
font-weight: 600;
border-radius: 8px;
margin-right: 10px;
}
/* 响应式设计 */
@media (max-width: 768px) {
.creation-card {
padding: 30px 20px;
margin: 10px;
}
.creation-header h2 {
font-size: 24px;
}
.creation-header p {
font-size: 14px;
}
.action-btn {
width: 100%;
margin: 5px 0;
}
}
</style>

@ -0,0 +1,242 @@
<template>
<el-dialog
v-model="visible"
title="OC列表"
width="800px"
:before-close="handleClose"
append-to-body
>
<div class="oc-list">
<!-- 创建OC按钮 -->
<div class="create-section">
<el-button
type="primary"
size="large"
@click="createNewOC"
icon="Plus"
class="create-btn"
>
创建新OC
</el-button>
</div>
<!-- OC列表 -->
<div class="oc-grid" v-if="ocList.length > 0">
<div
v-for="oc in ocList"
:key="oc.id"
class="oc-card"
@click="viewOCDetail(oc)"
>
<div class="oc-avatar">
<el-avatar :size="60" :src="oc.avatar" />
</div>
<div class="oc-info">
<h4>{{ oc.name }}</h4>
<p class="oc-occupation">{{ oc.occupation }}</p>
<p class="oc-birthday">生日{{ oc.birthday }}</p>
<div class="oc-tags">
<el-tag
v-for="hobby in oc.hobbies.slice(0, 2)"
:key="hobby"
size="small"
class="hobby-tag"
>
{{ hobby }}
</el-tag>
</div>
</div>
<div class="oc-actions">
<el-button
type="text"
size="small"
@click.stop="editOC(oc)"
>
编辑
</el-button>
<el-button
type="text"
size="small"
@click.stop="handleDeleteOC(oc.id)"
class="delete-btn"
>
删除
</el-button>
</div>
</div>
</div>
<!-- 空状态 -->
<div v-else class="empty-state">
<el-empty description="还没有创建任何OC">
<el-button type="primary" @click="createNewOC">
创建第一个OC
</el-button>
</el-empty>
</div>
</div>
<template #footer>
<el-button @click="handleClose"></el-button>
</template>
</el-dialog>
</template>
<script setup>
import { ref, computed, watch } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ocList, deleteOC, loadOCFromStorage } from '../stores/ocStore.js'
import { currentUser } from '../stores/userStore.js'
const props = defineProps({
modelValue: {
type: Boolean,
default: false
}
})
const emit = defineEmits(['update:modelValue'])
const router = useRouter()
const visible = computed({
get: () => props.modelValue,
set: value => emit('update:modelValue', value)
})
// OC
watch(visible, (newVal) => {
if (newVal && currentUser.value.username) {
loadOCFromStorage(currentUser.value.username)
}
})
const handleClose = () => {
visible.value = false
}
const createNewOC = () => {
// OC
router.push('/create-oc')
visible.value = false
}
const viewOCDetail = (oc) => {
ElMessage.info(`查看OC详情${oc.name}`)
// OC
}
const editOC = (oc) => {
ElMessage.info(`编辑OC${oc.name}`)
// OC
}
const handleDeleteOC = (id) => {
ElMessageBox.confirm('确定要删除这个OC吗', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if (deleteOC(id, currentUser.value.username)) {
ElMessage.success('删除成功')
} else {
ElMessage.error('删除失败')
}
}).catch(() => {
//
})
}
</script>
<style scoped>
.oc-list {
padding: 20px 0;
}
.create-section {
text-align: center;
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 1px solid #ebeef5;
}
.create-btn {
width: 200px;
}
.oc-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 20px;
}
.oc-card {
display: flex;
align-items: center;
padding: 15px;
border: 1px solid #ebeef5;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s;
background: #fff;
}
.oc-card:hover {
border-color: #409eff;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
transform: translateY(-2px);
}
.oc-avatar {
margin-right: 15px;
}
.oc-info {
flex: 1;
}
.oc-info h4 {
margin: 0 0 5px 0;
color: #303133;
font-size: 16px;
}
.oc-occupation {
margin: 0 0 5px 0;
color: #606266;
font-size: 14px;
}
.oc-birthday {
margin: 0 0 10px 0;
color: #909399;
font-size: 12px;
}
.oc-tags {
display: flex;
gap: 5px;
flex-wrap: wrap;
}
.hobby-tag {
font-size: 11px;
}
.oc-actions {
display: flex;
flex-direction: column;
gap: 5px;
align-items: flex-end;
justify-content: center;
}
.delete-btn {
color: #f56c6c;
}
.empty-state {
text-align: center;
padding: 40px 0;
}
</style>

@ -0,0 +1,31 @@
<template>
<div class="phone-page">
<h2>手机</h2>
<el-alert title="这是独立的手机页面(也可在社区中以弹窗形式使用)" type="info" show-icon />
<div class="widget">
<PhoneWidget v-model="open" />
<el-button type="primary" @click="open = true">打开手机</el-button>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import PhoneWidget from './PhoneWidget.vue'
const open = ref(true)
</script>
<style scoped>
.phone-page {
display: flex;
flex-direction: column;
gap: 12px;
padding: 16px;
}
.widget {
margin-top: 8px;
}
</style>

@ -0,0 +1,265 @@
<template>
<el-dialog
v-model="modelValueLocal"
title="聊天"
width="900px"
destroy-on-close
append-to-body
>
<div class="chat-layout">
<div class="left">
<div class="left-header">
<img class="me-avatar" :src="selfAvatar" alt="me" />
<div class="me-meta">
<div class="me-name"></div>
<div class="me-sub">在线</div>
</div>
</div>
<el-tabs v-model="leftTab" class="left-tabs">
<el-tab-pane label="聊天" name="chat" />
<el-tab-pane label="联系人" name="contacts" />
</el-tabs>
<ContactsList v-model="activeContactId" :contacts="contacts" v-show="leftTab === 'contacts'" />
<div v-show="leftTab === 'chat'" class="chat-list">
<div
v-for="c in contacts"
:key="c.id"
class="contact-item"
:class="{ active: c.id === activeContactId }"
@click="selectContact(c.id)"
>
<img class="avatar" :src="c.avatar" alt="avatar" />
<div class="meta">
<div class="name">{{ c.name }}</div>
<div class="last">{{ c.lastMessage || '...' }}</div>
</div>
<div class="time" v-if="c.lastTime">{{ formatTime(c.lastTime) }}</div>
<el-badge v-if="c.unread" :value="c.unread" class="unread" />
</div>
</div>
</div>
<div class="right">
<ChatWindow
:active-contact="activeContact"
v-model="activeMessages"
:self-id="selfId"
:self-avatar="selfAvatar"
@send="handleSend"
/>
</div>
</div>
<template #footer>
<el-button @click="close"></el-button>
</template>
</el-dialog>
</template>
<script setup>
import { computed, ref, watch } from 'vue'
import ContactsList from './ContactsList.vue'
import ChatWindow from './ChatWindow.vue'
const props = defineProps({
modelValue: {
type: Boolean,
default: false
}
})
const emit = defineEmits(['update:modelValue'])
const modelValueLocal = computed({
get: () => props.modelValue,
set: value => emit('update:modelValue', value)
})
// mock user and contacts
const selfId = 'me'
const selfAvatar = 'https://avatars.githubusercontent.com/u/9919?v=4'
const contacts = ref([
{ id: 'u_alice', name: 'Alice', avatar: 'https://i.pravatar.cc/100?img=5', status: '在线', lastMessage: '好的', lastTime: Date.now() - 600000, unread: 0 },
{ id: 'u_bob', name: 'Bob', avatar: 'https://i.pravatar.cc/100?img=12', status: '离线', lastMessage: '明天见', lastTime: Date.now() - 3600000, unread: 2 },
{ id: 'u_carla', name: 'Carla', avatar: 'https://i.pravatar.cc/100?img=32', status: '在线', lastMessage: '在吗?', lastTime: Date.now() - 120000, unread: 1 }
])
const messagesByContact = ref({
u_alice: [
{ senderId: 'u_alice', text: '你好~', timestamp: Date.now() - 7200000 },
{ senderId: selfId, text: '嗨!', timestamp: Date.now() - 7100000 }
],
u_bob: [
{ senderId: 'u_bob', text: '有空吗', timestamp: Date.now() - 5000000 }
],
u_carla: []
})
const activeContactId = ref('u_alice')
const activeContact = computed(() => contacts.value.find(c => c.id === activeContactId.value) || null)
const leftTab = ref('chat')
const activeMessages = computed({
get: () => messagesByContact.value[activeContactId.value] || [],
set: val => {
messagesByContact.value[activeContactId.value] = val
}
})
const close = () => {
modelValueLocal.value = false
}
const selectContact = (contactId) => {
activeContactId.value = contactId
}
const formatTime = (ts) => {
try {
const d = new Date(ts)
const h = String(d.getHours()).padStart(2, '0')
const m = String(d.getMinutes()).padStart(2, '0')
return `${h}:${m}`
} catch (e) {
return ''
}
}
const handleSend = ({ contact, message }) => {
const idx = contacts.value.findIndex(c => c.id === contact.id)
if (idx !== -1) {
contacts.value[idx] = {
...contacts.value[idx],
lastMessage: message.text,
lastTime: message.timestamp
}
}
// mock auto-reply
setTimeout(() => {
const reply = {
senderId: contact.id,
text: '收到:' + message.text,
timestamp: Date.now()
}
const list = messagesByContact.value[contact.id] || []
messagesByContact.value[contact.id] = [...list, reply]
const cIndex = contacts.value.findIndex(c => c.id === contact.id)
if (cIndex !== -1) {
const isActive = activeContactId.value === contact.id
const nextUnread = isActive ? 0 : (contacts.value[cIndex].unread || 0) + 1
contacts.value[cIndex] = {
...contacts.value[cIndex],
lastMessage: reply.text,
lastTime: reply.timestamp,
unread: nextUnread
}
}
}, 800)
}
// clear unread when switching to a contact
watch(activeContactId, id => {
const i = contacts.value.findIndex(c => c.id === id)
if (i !== -1) {
contacts.value[i] = { ...contacts.value[i], unread: 0 }
}
})
</script>
<style scoped>
.chat-layout {
display: flex;
height: 600px;
background: #f5f7fa;
}
.left {
width: 280px;
height: 100%;
}
.left-header {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
background: #fff;
border-bottom: 1px solid #ebeef5;
}
.me-avatar {
width: 32px;
height: 32px;
border-radius: 50%;
}
.me-name {
font-weight: 600;
}
.me-sub {
font-size: 12px;
color: #909399;
}
.left-tabs {
background: #fff;
border-bottom: 1px solid #ebeef5;
}
.right {
flex: 1;
height: 100%;
}
.chat-list {
height: 100%;
overflow-y: auto;
background: #fff;
}
.contact-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
cursor: pointer;
border-bottom: 1px solid #f0f0f0;
}
.contact-item:hover {
background: #f5f7fa;
}
.contact-item.active {
background: #ecf5ff;
}
.avatar {
width: 36px;
height: 36px;
border-radius: 8px;
}
.meta {
flex: 1;
min-width: 0;
}
.name {
font-weight: 600;
font-size: 14px;
}
.last {
font-size: 12px;
color: #909399;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.time {
font-size: 12px;
color: #909399;
}
</style>

@ -0,0 +1,230 @@
<template>
<el-dialog
v-model="visible"
title="用户中心"
width="500px"
:before-close="handleClose"
append-to-body
>
<div class="user-center">
<!-- 用户头像和基本信息 -->
<div class="user-info">
<div class="avatar-section">
<el-avatar :size="80" :src="userInfo.avatar" />
<el-button
type="text"
size="small"
@click="changeAvatar"
class="change-avatar-btn"
>
更换头像
</el-button>
</div>
<div class="user-details">
<h3>{{ userInfo.nickname }}</h3>
<p class="username">@{{ userInfo.username }}</p>
</div>
</div>
<!-- 个人信息 -->
<div class="personal-info">
<h4>个人信息</h4>
<el-form :model="userInfo" label-width="80px" size="small">
<el-form-item label="生日">
<el-date-picker
v-model="userInfo.birthday"
type="date"
placeholder="选择生日"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
/>
</el-form-item>
<el-form-item label="职业">
<el-input v-model="userInfo.occupation" placeholder="请输入职业" />
</el-form-item>
<el-form-item label="喜好">
<el-input
v-model="userInfo.hobbies"
type="textarea"
:rows="2"
placeholder="请输入你的喜好"
/>
</el-form-item>
<el-form-item label="个人简介">
<el-input
v-model="userInfo.bio"
type="textarea"
:rows="3"
placeholder="介绍一下自己吧"
/>
</el-form-item>
</el-form>
</div>
<!-- 操作按钮 -->
<div class="actions">
<el-button type="primary" @click="saveProfile"></el-button>
<el-button @click="handleClose"></el-button>
</div>
<!-- 退出登录按钮 -->
<div class="logout-section">
<el-button
type="danger"
plain
@click="handleLogout"
class="logout-btn"
>
退出登录
</el-button>
</div>
</div>
</el-dialog>
</template>
<script setup>
import { ref, computed, watch } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { currentUser, updateUserInfo, logout } from '../stores/userStore.js'
const props = defineProps({
modelValue: {
type: Boolean,
default: false
}
})
const emit = defineEmits(['update:modelValue'])
const router = useRouter()
const visible = computed({
get: () => props.modelValue,
set: value => emit('update:modelValue', value)
})
//
const userInfo = ref({ ...currentUser.value })
//
const originalUserInfo = ref({})
//
watch(visible, (newVal) => {
if (newVal) {
// OC
const currentUserData = currentUser.value
userInfo.value = {
username: currentUserData.username || '',
nickname: currentUserData.nickname || currentUserData.username || '',
avatar: currentUserData.avatar || 'https://avatars.githubusercontent.com/u/9919?v=4',
birthday: currentUserData.birthday || '2000-01-01',
occupation: currentUserData.occupation || '学生',
hobbies: currentUserData.hobbies || '编程、游戏、音乐',
bio: currentUserData.bio || '这是一个热爱编程的用户',
isLoggedIn: currentUserData.isLoggedIn || false
}
originalUserInfo.value = JSON.parse(JSON.stringify(userInfo.value))
}
})
const handleClose = () => {
//
userInfo.value = JSON.parse(JSON.stringify(originalUserInfo.value))
visible.value = false
}
const changeAvatar = () => {
ElMessage.info('头像更换功能待实现')
}
const saveProfile = () => {
//
updateUserInfo(userInfo.value)
ElMessage.success('资料保存成功')
visible.value = false
}
const handleLogout = () => {
ElMessageBox.confirm('确定要退出登录吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// 退
logout()
ElMessage.success('已退出登录')
visible.value = false
//
router.push('/login')
}).catch(() => {
//
})
}
</script>
<style scoped>
.user-center {
padding: 20px 0;
}
.user-info {
display: flex;
align-items: center;
gap: 20px;
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 1px solid #ebeef5;
}
.avatar-section {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
}
.change-avatar-btn {
font-size: 12px;
}
.user-details h3 {
margin: 0 0 5px 0;
color: #303133;
}
.username {
margin: 0;
color: #909399;
font-size: 14px;
}
.personal-info {
margin-bottom: 30px;
}
.personal-info h4 {
margin: 0 0 15px 0;
color: #303133;
font-size: 16px;
}
.actions {
display: flex;
justify-content: center;
gap: 10px;
margin-bottom: 20px;
}
.logout-section {
text-align: center;
padding-top: 20px;
border-top: 1px solid #ebeef5;
}
.logout-btn {
width: 200px;
}
</style>

@ -0,0 +1,12 @@
import { createApp } from 'vue'
import App from './App.vue'
// 添加这两行来引入 Element Plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import router from './router'
const app = createApp(App)
app.use(ElementPlus) // 使用 Element Plus
app.use(router)
app.mount('#app')

@ -0,0 +1,69 @@
import { createRouter, createWebHistory } from 'vue-router'
import { isLoggedIn } from '../stores/userStore.js'
// 1. 导入页面组件
import LoginPage from '../components/LoginPage.vue'
import OCCreationPage from '../components/OCCreationPage.vue'
import HomePage from '../components/HomePage.vue'
import PhonePage from '../components/PhonePage.vue'
import CommunityPage from '../components/CommunityPage.vue'
// 2. 定义路由规则
const routes = [
{
path: '/', // 访问路径
redirect: '/login' // 重定向到登录页
},
{
path: '/login', // 访问路径http://localhost:5173/login
name: 'Login', // 路由名称
component: LoginPage // 对应的组件
},
{
path: '/home', // 首页
name: 'Home',
component: HomePage
},
{
path: '/create-oc', // 访问路径http://localhost:5173/create-oc
name: 'CreateOC',
component: OCCreationPage
},
{
path: '/community', // 访问路径http://localhost:5173/community
name: 'Community',
component: CommunityPage
},
{
path: '/phone',
name: 'Phone',
component: PhonePage
}
]
// 3. 创建路由实例
const router = createRouter({
history: createWebHistory(),
routes
})
// 4. 添加路由守卫
router.beforeEach((to, from, next) => {
// 如果访问登录页,直接通过
if (to.path === '/login') {
next()
return
}
// 检查是否已登录
if (!isLoggedIn.value) {
// 未登录,重定向到登录页
next('/login')
} else {
// 已登录,正常访问
next()
}
})
// 5. 导出路由
export default router

@ -0,0 +1,115 @@
import { ref } from 'vue'
// OC状态管理
const ocList = ref([
// 示例数据
{
id: 1,
name: '小艾',
avatar: 'https://i.pravatar.cc/100?img=1',
occupation: '程序员',
birthday: '1998-05-15',
hobbies: ['编程', '阅读', '音乐'],
bio: '热爱编程的AI助手',
schedule: [],
achievements: [],
socialCircle: []
},
{
id: 2,
name: '小智',
avatar: 'https://i.pravatar.cc/100?img=2',
occupation: '设计师',
birthday: '1999-08-22',
hobbies: ['绘画', '摄影', '旅行'],
bio: '充满创意的设计师',
schedule: [],
achievements: [],
socialCircle: []
}
])
// 从本地存储加载OC列表
const loadOCFromStorage = (username = null) => {
let storageKey = 'ocList'
if (username) {
storageKey = `ocList_${username}`
}
const storedOC = localStorage.getItem(storageKey)
if (storedOC) {
try {
ocList.value = JSON.parse(storedOC)
} catch (error) {
console.error('Failed to parse OC list from storage:', error)
}
} else {
// 如果没有找到用户特定的OC列表使用默认的
if (username) {
ocList.value = []
}
}
}
// 保存OC列表到本地存储
const saveOCToStorage = (username = null) => {
let storageKey = 'ocList'
if (username) {
storageKey = `ocList_${username}`
}
localStorage.setItem(storageKey, JSON.stringify(ocList.value))
}
// 添加新OC
const addOC = (ocData, username = null) => {
const newOC = {
id: Date.now(), // 简单的ID生成
...ocData,
schedule: [],
achievements: [],
socialCircle: []
}
ocList.value.push(newOC)
saveOCToStorage(username)
return newOC
}
// 更新OC信息
const updateOC = (id, updatedData, username = null) => {
const index = ocList.value.findIndex(oc => oc.id === id)
if (index !== -1) {
ocList.value[index] = { ...ocList.value[index], ...updatedData }
saveOCToStorage(username)
return ocList.value[index]
}
return null
}
// 删除OC
const deleteOC = (id, username = null) => {
const index = ocList.value.findIndex(oc => oc.id === id)
if (index !== -1) {
ocList.value.splice(index, 1)
saveOCToStorage(username)
return true
}
return false
}
// 根据ID获取OC
const getOCById = (id) => {
return ocList.value.find(oc => oc.id === id)
}
// 初始化时加载数据
loadOCFromStorage()
export {
ocList,
addOC,
updateOC,
deleteOC,
getOCById,
loadOCFromStorage
}

@ -0,0 +1,282 @@
import { ref, computed } from 'vue'
// 用户状态管理
const userInfo = ref({
username: '',
nickname: '',
avatar: '',
birthday: '',
occupation: '',
hobbies: '',
bio: '',
isLoggedIn: false
})
// 从本地存储加载用户信息
const loadUserFromStorage = (username = null, clearOnError = true) => {
if (username) {
const userInfoKey = `userInfo_${username}`
const storedUser = localStorage.getItem(userInfoKey)
const storedToken = localStorage.getItem('userToken')
if (storedUser && storedToken) {
try {
const user = JSON.parse(storedUser)
userInfo.value = {
...user,
isLoggedIn: true
}
} catch (error) {
console.error('Failed to parse user info from storage:', error)
if (clearOnError) {
clearUserData()
}
}
}
} else {
// 兼容旧版本,从通用存储加载
const storedUser = localStorage.getItem('userInfo')
const storedToken = localStorage.getItem('userToken')
if (storedUser && storedToken) {
try {
const user = JSON.parse(storedUser)
userInfo.value = {
...user,
isLoggedIn: true
}
} catch (error) {
console.error('Failed to parse user info from storage:', error)
if (clearOnError) {
clearUserData()
}
}
}
}
}
// 保存用户信息到本地存储
const saveUserToStorage = (userData) => {
// 为每个用户创建独立的用户信息存储
if (userData.username) {
const userInfoKey = `userInfo_${userData.username}`
localStorage.setItem(userInfoKey, JSON.stringify(userData))
// 只在登录时更新token更新用户信息时不更新token
if (userData.isLoggedIn && !localStorage.getItem('userToken')) {
localStorage.setItem('userToken', 'mock-token-' + Date.now())
}
// 为每个用户创建独立的OC存储键
const userOCKey = `ocList_${userData.username}`
if (!localStorage.getItem(userOCKey)) {
localStorage.setItem(userOCKey, JSON.stringify([]))
}
}
}
// 清除用户数据
const clearUserData = () => {
// 清除当前用户的独立存储
if (userInfo.value.username) {
const userInfoKey = `userInfo_${userInfo.value.username}`
localStorage.removeItem(userInfoKey)
}
// 清除通用存储(兼容旧版本)
localStorage.removeItem('userInfo')
localStorage.removeItem('userToken')
userInfo.value = {
username: '',
nickname: '',
avatar: '',
birthday: '',
occupation: '',
hobbies: '',
bio: '',
isLoggedIn: false
}
}
// 登录
const login = (loginData) => {
return new Promise((resolve, reject) => {
// 模拟登录API调用
setTimeout(() => {
if (loginData.username && loginData.password) {
// 首先检查用户是否已注册
const userRegistryKey = `userRegistry_${loginData.username}`
const existingRegistry = localStorage.getItem(userRegistryKey)
if (!existingRegistry) {
reject({ success: false, message: '用户不存在,请先注册' })
return
}
// 优先从用户特定的存储中加载用户数据
const userInfoKey = `userInfo_${loginData.username}`
let storedUser = localStorage.getItem(userInfoKey)
let userData
console.log('登录调试 - 用户信息键:', userInfoKey)
console.log('登录调试 - 用户信息数据:', storedUser)
console.log('登录调试 - 所有用户信息键:', Object.keys(localStorage).filter(key => key.startsWith('userInfo_')))
if (storedUser) {
try {
const existingUser = JSON.parse(storedUser)
userData = {
...existingUser,
isLoggedIn: true
}
} catch (error) {
// 如果解析失败,尝试从通用存储加载
storedUser = localStorage.getItem('userInfo')
if (storedUser) {
try {
const existingUser = JSON.parse(storedUser)
if (existingUser.username === loginData.username) {
userData = {
...existingUser,
isLoggedIn: true
}
} else {
reject({ success: false, message: '用户数据不匹配,请重新注册' })
return
}
} catch (error2) {
reject({ success: false, message: '用户数据损坏,请重新注册' })
return
}
} else {
reject({ success: false, message: '用户数据不存在,请重新注册' })
return
}
}
} else {
// 没有用户特定数据,尝试从通用存储加载
storedUser = localStorage.getItem('userInfo')
if (storedUser) {
try {
const existingUser = JSON.parse(storedUser)
if (existingUser.username === loginData.username) {
userData = {
...existingUser,
isLoggedIn: true
}
} else {
reject({ success: false, message: '用户数据不匹配,请重新注册' })
return
}
} catch (error) {
reject({ success: false, message: '用户数据损坏,请重新注册' })
return
}
} else {
reject({ success: false, message: '用户数据不存在,请重新注册' })
return
}
}
userInfo.value = userData
saveUserToStorage(userData)
// 同时更新通用存储以保持兼容性
localStorage.setItem('userInfo', JSON.stringify(userData))
resolve({ success: true, user: userData })
} else {
reject({ success: false, message: '用户名和密码不能为空' })
}
}, 1000)
})
}
// 注册
const register = (registerData) => {
return new Promise((resolve, reject) => {
// 模拟注册API调用
setTimeout(() => {
if (registerData.username && registerData.password) {
// 检查用户名是否已存在 - 使用独立的用户注册记录
const userRegistryKey = `userRegistry_${registerData.username}`
const existingRegistry = localStorage.getItem(userRegistryKey)
if (existingRegistry) {
reject({ success: false, message: '用户名已存在,请选择其他用户名' })
return
}
const userData = {
username: registerData.username,
nickname: registerData.nickname || registerData.username,
avatar: registerData.avatar || 'https://avatars.githubusercontent.com/u/9919?v=4',
birthday: registerData.birthday || '2000-01-01',
occupation: registerData.occupation || '未知',
hobbies: registerData.hobbies || 'ta一点也没透露',
bio: registerData.bio || '这是一个新用户',
isLoggedIn: true
}
// 保存用户注册记录
localStorage.setItem(userRegistryKey, JSON.stringify({
username: registerData.username,
registeredAt: Date.now()
}))
userInfo.value = userData
saveUserToStorage(userData)
// 同时更新通用存储以保持兼容性
localStorage.setItem('userInfo', JSON.stringify(userData))
console.log('注册调试 - 保存的用户信息键:', `userInfo_${userData.username}`)
console.log('注册调试 - 保存的用户信息:', localStorage.getItem(`userInfo_${userData.username}`))
console.log('注册调试 - 所有用户信息键:', Object.keys(localStorage).filter(key => key.startsWith('userInfo_')))
resolve({ success: true, user: userData })
} else {
reject({ success: false, message: '用户名和密码不能为空' })
}
}, 1000)
})
}
// 更新用户信息
const updateUserInfo = (newUserInfo) => {
const updatedUser = {
...userInfo.value,
...newUserInfo
}
userInfo.value = updatedUser
saveUserToStorage(updatedUser)
// 同时更新通用存储以保持兼容性
localStorage.setItem('userInfo', JSON.stringify(updatedUser))
}
// 退出登录
const logout = () => {
clearUserData()
}
// 计算属性
const isLoggedIn = computed(() => userInfo.value.isLoggedIn)
const currentUser = computed(() => userInfo.value)
// 初始化时加载用户数据 - 从通用存储加载以保持兼容性,不清除数据
loadUserFromStorage(null, false)
export {
userInfo,
isLoggedIn,
currentUser,
login,
register,
updateUserInfo,
logout,
loadUserFromStorage
}

@ -0,0 +1,79 @@
:root {
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
.card {
padding: 2em;
}
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}

@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vite.dev/config/
export default defineConfig({
plugins: [vue()],
})

@ -0,0 +1,240 @@
大学生软工课设 自定义ai伙伴-oc社区 上帝视角
用户登录
用户可以自主设定一个“我”角色 自定义外观 日程表 生日 喜好 职业等等
创建oc 填写oc问卷或交给ai随机生成oc上传oc图片或通过填写问卷ai生成图片作为当前oc的头像。
确定oc头像后进入社区界面用户可以自定义oc的日程表或者让ai根据填写的问卷生成日程表游戏内时间需要与用户所处实际时间相同oc会根据自己的日程表安排自己的活动。小屋中包含卧室客厅厨房健身房餐厅超市花店体育馆酒店等等可拓展性活动场所所有oc都在社区里生活工作甚至学习上课社区里也有一些aiNPC和用户的oc一起生活。
进入手机界面用户可以给oc或已结识的NPC发消息进行交流ai会根据oc自身日程表当前的活动方式决策是实时回复还是延时回复比如oc当前正在休闲放松可以实时回复若进行体育运动如游泳就要延时回复NPC同理。
我希望打开网站后首先出现登录注册页面,完成登录后直接显示社区界面,在当前界面右侧一排从上到下有三个按钮 依次是用户中心 oc列表 手机通信,
点击用户中心会出现用户中心弹窗,弹窗中包含用户头像,用户昵称和一些自我角色的个人信息,下拉最下方有退出登录按钮,点击后会回到登录注册页面。
点击oc列表出现oc列表界面弹窗初始列表为空白有一个“创建oc”按钮点击按钮后出现oc问卷用户完成问卷填写后点击提交oc信息会交给ai进行模拟出现oc头像选择窗口用户可以选择上传本地图片或者使用ai根据表单提交的信息生成。头像选择完毕后点击确定。
回到用户列表此时列表中会显示出刚创建的o头像及名称集成卡片点击卡片会出现oc的信息界面包含oc头像oc名称oc生日oc喜好oc职业oc日程表oc的社交圈oc的成就等等用户可以点击日程表进行修改点击社交圈可以添加好友点击成就可以查看自己或好友的成就。
功能详细介绍:
登录注册 保存用户数据
社区界面 公寓
拓展构想:
多个世界,多个社区,自定义社区场景和社区活动,自定义自然环境和社会背景(与实时性相悖?)
与时俱进 增加每日大事件和新闻功能
联机功能 邀请朋友加入自己的世界或加入朋友的世界
oc问卷内容
版本问题
1.0
按钮没有对其
oc创建后没有显示在列表中
用户注册完成后应当回到登录界面进行登录,而不是直接进入社区界面
已注册的用户再次登录时,个人信息出现错误
1.1
按钮仍没有对齐 用户中心按钮稍微考前了一点
用户登陆后的信息仍旧没有储存 每个用户创建的oc信息应当不是共享的 而是独立的
登录另一个用户后前一个用户的注册信息竟然变成了oc信息 没有注册的用户应当不可以登录
1.2
创建oc填写oc信息界面需要增加取消创建按钮 按下后可以返回oc列表界面
手机界面中点击导航栏的“联系人按钮”后应当跳转到一个类似微信的联系人列表,在列表中选择联系人后,右侧出现和所选联系人的聊天界面
已注册过的账号退出登录后再注册出现问题 显示用户不存在
1.3
用户的个人信息应当与注册信息一致,只有在修改并保存后变化,再次登录后个人信息也应当和原来保持一致
要求用户注册后的信息可以正常登录并保存在用户中心中,可以随时修改或查看
联系人列表只要有联系人头像名称就好,不显示最近一次聊天内容和时间
cursor重置方案
方案一:机器码全量重置,并禁用更新(推荐)
📌 实现原理
Terminal window
## Windows系统操作PowerShell需管理员权限
irm https://raw.githubusercontent.com/yuaotian/go-cursor-help/refs/heads/master/scripts/run/cursor_win_id_modifier.ps1 | iex
### **第一步:搭建你的开发环境 (第1天)**
1. **安装 Node.js:**
* **是什么:** Node.js是JavaScript的运行环境前端很多工具都依赖它。
* **怎么做:** 访问 [Node.js 官网](https://nodejs.org/),下载并安装 **LTS长期支持版**。
* **验证:** 安装完成后打开命令行Windows: CMD 或 PowerShell; Mac: Terminal输入以下命令能显示版本号即成功。
```bash
node -v
npm -v
```
2. **安装代码编辑器 - Visual Studio Code (VS Code):**
* **是什么:** 目前最强大的免费前端开发编辑器。
* **怎么做:** 访问 [VS Code 官网](https://code.visualstudio.com/),下载安装。
* **安装必备插件:** 打开VS Code在左侧扩展商店中搜索并安装
* `Volar` (Vue 3官方推荐支持插件**必装**)
* `Auto Rename Tag` (自动重命名配对的HTML标签)
* `ESLint` (代码格式检查)
* `Live Server` (右键一键启动本地服务器预览HTML页面)
* `Chinese (Simplified) Language Pack` (如果需要中文界面)
3. **安装 Git:**
* **是什么:** 代码版本管理工具,团队协作核心。
* **怎么做:** 访问 [Git 官网](https://git-scm.com/) 下载安装。
* **配置:** 安装后,在命令行中设置你的用户名和邮箱(用于标识你的提交):
```bash
git config --global user.name "你的名字"
git config --global user.email "你的邮箱@example.com"
```
---
### **第二步创建你的第一个Vue项目 (第1-2天)**
我们使用Vue官方推荐的脚手架工具 `Vite` 来创建项目,它非常快!
1. **在命令行中创建项目:**
找一个你喜欢的文件夹,在地址栏输入 `cmd` 打开命令行,执行以下命令:
```bash
# 使用 npm 创建项目,项目名为 `oc-community-frontend`
npm create vite@latest oc-community-frontend -- --template vue
# 接下来按照提示操作
cd oc-community-frontend # 进入项目目录
npm install # 安装项目依赖(所有需要的代码库)
npm run dev # 启动开发服务器
```
2. **查看效果:**
执行 `npm run dev` 后,命令行会给出一个本地地址(通常是 `http://localhost:5173`。用浏览器打开它你会看到Vue的欢迎页面恭喜你项目成功运行了
3. **了解项目结构:**
用VS Code打开你刚创建的 `oc-community-frontend` 文件夹,你会看到类似下面的结构:
```
oc-community-frontend
├── node_modules/ # 所有安装的依赖包(不用动它)
├── src/ # 源代码目录(主要在这里工作!)
│ ├── assets/ # 静态资源,如图片、字体
│ ├── components/ # Vue组件目录可复用的小模块
│ ├── App.vue # 根组件(应用的主组件)
│ └── main.js # 项目的入口文件
├── index.html # 主HTML页面
├── package.json # 项目配置文件(记录了项目信息和依赖)
└── vite.config.js # Vite的配置文件
```
---
### **第三步:学习核心概念并开始修改 (第2-4周)**
你的目标是实现页面,而不是从零造轮子。所以我们要**现学现用**。
1. **学习最低限度的Vue语法**
* **单文件组件 (.vue文件)**`<template>` (HTML), `<script>` (JavaScript), `<style>` (CSS) 三部分。
* **响应式数据**:使用 `ref` 或 `reactive` 声明数据,数据变,页面自动变。
* **事件处理**`@click` 等指令,用于处理用户点击等操作。
* **条件渲染**`v-if` 和 `v-show`,控制组件显示隐藏。
* **循环渲染**`v-for`,用于渲染列表(如消息列表)。
* **组件通信**`props` (父传子)`$emit` (子传父)。
**如何学?** 只看文档的必要部分:
* **Vue 官方中文教程****[https://cn.vuejs.org/guide/essentials/application.html](https://cn.vuejs.org/guide/essentials/application.html)** 精读 **“基础”** 和 **“深入组件”** 章节。
2. **安装和使用UI组件库 (事半功倍!)**
* 在项目目录下运行命令安装 `Element Plus`:
```bash
npm install element-plus --save
```
* 在 `main.js` 文件中全局引入:
```javascript
import { createApp } from 'vue'
import App from './App.vue'
// 引入 Element Plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
const app = createApp(App)
app.use(ElementPlus)
app.mount('#app')
```
* **现在你就可以在项目的任何地方使用Element Plus的组件了** 去它的官网 **[https://element-plus.gitee.io/zh-CN/](https://element-plus.gitee.io/zh-CN/)**,复制你需要的组件代码到你的 `.vue` 文件里,然后修改一下就行。
* **例如:** 你需要一个按钮就在官网找到Button组件复制代码贴到你的`<template>`里,改一下文字和`@click`事件函数名。
3. **划分页面与组件:**
根据你的项目,前端至少需要这些页面和组件:
* `LoginPage.vue` - 登录/注册页
* `OCCreationPage.vue` - 创建OC的页面表单+AI生成按钮
* `CommunityPage.vue` - 主社区页面显示背景图、OC位置
* `PhoneWidget.vue` - **可复用的手机组件**(里面包含聊天界面)
* `ChatWindow.vue` - **手机组件内部的聊天窗口组件**
在 `src/components` 下创建这些文件,然后在 `src/App.vue` 中通过路由切换它们,或者先用 `v-if` 简单切换。
---
### **第四步:与后端联调 (第5周起)**
当前端页面大概样子出来后,就要开始请求后端的数据了。
1. **安装Axios (用于发送HTTP请求)**
```bash
npm install axios
```
2. **学习如何使用:**
* 在你的组件脚本中 `import axios from 'axios'`。
* 在生命周期函数(如 `onMounted`或事件如按钮点击中调用API。
* **示例:登录请求**
```javascript
import { ref } from 'vue';
import axios from 'axios';
const username = ref('');
const password = ref('');
const handleLogin = async () => {
try {
// 假设后端地址是 http://localhost:8000
const response = await axios.post('http://localhost:8000/api/login', {
username: username.value,
password: password.value
});
// 登录成功保存token并跳转页面
console.log('登录成功', response.data);
} catch (error) {
// 登录失败,提示用户
console.error('登录失败', error);
}
};
```
3. **和后端同学约定API格式**
* 一起讨论每个接口的**URL、请求方法GET/POST、请求参数、返回数据格式**。
* 使用 **Apifox** 或 **Postman** 这类工具来模拟请求测试后端API是否正常工作然后再写到代码里。
### **给你的行动清单**
1. **[ ] 今天内**完成环境搭建和第一个Vue项目运行。
2. **[ ] 本周末**通读Vue核心概念文档跑通一个Element Plus的组件例子。
3. **[ ] 下周**画出前端页面的简单线框图并开始尝试实现登录页和OC创建页的静态样式只画样子不管功能
4. **[ ] 之后**和后端同学开会定好API接口开始尝试用Axios连接登录功能。
不要怕遇到问题随时搜索CSDN、掘金、StackOverflow、官方文档90%的问题都能找到答案。祝你顺利!
Loading…
Cancel
Save