u
This commit is contained in:
1 parent
572011017a
commit
ff3ee944d5
4 files changed
+209
-92
No files matched your search
@@ -1,29 +1,34 @@
|
||||
import { useRouter } from 'expo-router'
|
||||
import { Text, View } from 'react-native'
|
||||
import { ScrollView } from 'react-native-gesture-handler'
|
||||
import { AButton, ACell, ACellGroup } from '@/components/common/ao'
|
||||
import EmptyState from '@/components/common/EmptyStatus'
|
||||
import { Grid, GridItem } from '@/components/ui/grid'
|
||||
import { useMoneyCategoryStore } from '@/store/moneyCategory'
|
||||
import { useSpaceStore } from '@/store/space'
|
||||
|
||||
export default function Demo() {
|
||||
const moneyCategoryStore = useMoneyCategoryStore()
|
||||
const router = useRouter()
|
||||
const spaceStore = useSpaceStore()
|
||||
|
||||
function getCategories() {
|
||||
console.log(moneyCategoryStore.categories)
|
||||
function NoSpaceTip() {
|
||||
return (
|
||||
<EmptyState
|
||||
description="还没有加入空间,选择一个加入或自己创建一个,开始聊天!"
|
||||
footer={
|
||||
<AButton size="sm">创建 / 加入 空间</AButton>
|
||||
}
|
||||
|
||||
async function resetCategory() {
|
||||
moneyCategoryStore.setCategories([])
|
||||
await moneyCategoryStore.init()
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollView>
|
||||
<Grid className="gap-4 p-4" _extra={{ className: 'grid-cols-12' }}>
|
||||
<GridItem className="bg-background-50 p-6 rounded-md" _extra={{ className: 'col-span-3' }} />
|
||||
<GridItem className="bg-background-50 p-6 rounded-md" _extra={{ className: 'col-span-3' }} />
|
||||
<GridItem className="bg-background-50 p-6 rounded-md" _extra={{ className: 'col-span-3' }} />
|
||||
<GridItem className="bg-background-50 p-6 rounded-md" _extra={{ className: 'col-span-3' }} />
|
||||
</Grid>
|
||||
</ScrollView>
|
||||
<View className="flex-1">
|
||||
{
|
||||
spaceStore.inSpace()
|
||||
? (<View></View>)
|
||||
: <NoSpaceTip />
|
||||
}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -28,8 +28,8 @@ function isWhiteListed(url: string) {
|
||||
}
|
||||
|
||||
const alovaInstance = createAlova({
|
||||
baseURL: 'http://192.168.5.6:8086/app',
|
||||
// baseURL: 'http://192.168.1.137:8086/app',
|
||||
// baseURL: 'http://192.168.5.6:8086/app',
|
||||
baseURL: 'http://192.168.1.137:8086/app',
|
||||
requestAdapter: axiosRequestAdapter(),
|
||||
timeout: 5000,
|
||||
cacheFor: null,
|
||||
|
||||
@@ -4,6 +4,7 @@ interface SpaceState {
|
||||
userSpace: UserSpace | null
|
||||
setUserSpace: (space: UserSpace | null) => void
|
||||
clear: () => void
|
||||
inSpace: () => boolean
|
||||
}
|
||||
|
||||
export const useSpaceStore = create<SpaceState>((set, get) => ({
|
||||
@@ -14,4 +15,8 @@ export const useSpaceStore = create<SpaceState>((set, get) => ({
|
||||
userSpace: null,
|
||||
})
|
||||
},
|
||||
inSpace: () => {
|
||||
const userSpace = get().userSpace
|
||||
return userSpace !== null && userSpace.id !== 0
|
||||
},
|
||||
}))
|
||||
+182
-75
@@ -1,94 +1,201 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="zh">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>WebSocket Test</title>
|
||||
<title>IM 列表</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<style>
|
||||
body {
|
||||
/* 全局设置 */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 20px;
|
||||
}
|
||||
#output {
|
||||
background-color: #f7f7f7;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
/* 顶部栏 */
|
||||
header {
|
||||
background-color: #fff;
|
||||
padding: 15px 20px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
color: #4a90e2;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
padding: 8px 12px;
|
||||
width: 200px;
|
||||
border-radius: 20px;
|
||||
border: 1px solid #ddd;
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* 联系人列表 */
|
||||
.contact-list {
|
||||
margin-top: 20px;
|
||||
padding: 10px;
|
||||
border: 1px solid #ccc;
|
||||
min-height: 150px;
|
||||
}
|
||||
#sendMessage {
|
||||
margin-top: 20px;
|
||||
padding: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.contact-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background-color: #fff;
|
||||
margin: 10px 20px;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.contact-item:hover {
|
||||
background-color: #f1f1f1;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* 头像 */
|
||||
.avatar img {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
/* 联系人信息 */
|
||||
.contact-info {
|
||||
flex: 1;
|
||||
margin-left: 12px;
|
||||
}
|
||||
|
||||
.contact-name {
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.last-message {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
/* 时间和未读消息数 */
|
||||
.meta-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.message-time {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.unread-count {
|
||||
background-color: #f03e3e;
|
||||
color: #fff;
|
||||
padding: 4px 8px;
|
||||
border-radius: 12px;
|
||||
font-size: 12px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
/* 底部创建聊天按钮 */
|
||||
.create-chat {
|
||||
position: fixed;
|
||||
right: 20px;
|
||||
bottom: 20px;
|
||||
}
|
||||
|
||||
.create-chat button {
|
||||
background-color: #4a90e2;
|
||||
color: #fff;
|
||||
padding: 15px 25px;
|
||||
border-radius: 50%;
|
||||
font-size: 18px;
|
||||
border: none;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.create-chat button:hover {
|
||||
background-color: #357ab7;
|
||||
}
|
||||
|
||||
.create-chat button:active {
|
||||
background-color: #2f6790;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- 顶部栏 -->
|
||||
<header>
|
||||
<div class="header-content">
|
||||
<h1>IM 列表</h1>
|
||||
<input type="text" placeholder="搜索联系人或群组" class="search-bar">
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<h2>WebSocket Test</h2>
|
||||
<div>
|
||||
<label for="messageInput">Enter Message:</label>
|
||||
<input type="text" id="messageInput" placeholder="Type your message here">
|
||||
<button id="sendBtn">Send Message</button>
|
||||
<!-- 联系人列表 -->
|
||||
<div class="contact-list">
|
||||
<div class="contact-item">
|
||||
<div class="avatar">
|
||||
<img src="https://via.placeholder.com/40" alt="头像">
|
||||
</div>
|
||||
<div class="contact-info">
|
||||
<p class="contact-name">张三</p>
|
||||
<p class="last-message">你好,最近怎么样?</p>
|
||||
</div>
|
||||
<div class="meta-info">
|
||||
<p class="message-time">2分钟前</p>
|
||||
<div class="unread-count">3</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="output">
|
||||
<h3>Messages:</h3>
|
||||
<div id="messages"></div>
|
||||
<div class="contact-item">
|
||||
<div class="avatar">
|
||||
<img src="https://via.placeholder.com/40" alt="头像">
|
||||
</div>
|
||||
<div class="contact-info">
|
||||
<p class="contact-name">李四</p>
|
||||
<p class="last-message">好的,明天见!</p>
|
||||
</div>
|
||||
<div class="meta-info">
|
||||
<p class="message-time">昨天</p>
|
||||
<div class="unread-count">0</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Create a new WebSocket connection
|
||||
const socket = new WebSocket('ws://192.168.1.137:8086/app/ws');
|
||||
<!-- 更多联系人项可以在此复制 -->
|
||||
</div>
|
||||
|
||||
// Get HTML elements
|
||||
const sendButton = document.getElementById('sendBtn');
|
||||
const messageInput = document.getElementById('messageInput');
|
||||
const messagesDiv = document.getElementById('messages');
|
||||
<!-- 底部按钮 -->
|
||||
<div class="create-chat">
|
||||
<button>新建对话</button>
|
||||
</div>
|
||||
|
||||
// WebSocket onopen event: Fired when WebSocket connection is established
|
||||
socket.onopen = function(event) {
|
||||
console.log("Connected to WebSocket server!");
|
||||
displayMessage("Connected to WebSocket server!");
|
||||
};
|
||||
|
||||
// WebSocket onmessage event: Fired when a message is received from the server
|
||||
socket.onmessage = function(event) {
|
||||
console.log("Received message from server: " + event.data);
|
||||
displayMessage("Server: " + event.data);
|
||||
};
|
||||
|
||||
// WebSocket onerror event: Fired when there's an error with the WebSocket
|
||||
socket.onerror = function(error) {
|
||||
console.log(error)
|
||||
console.error("WebSocket Error: " + error);
|
||||
displayMessage("WebSocket Error: " + error);
|
||||
};
|
||||
|
||||
// WebSocket onclose event: Fired when the connection is closed
|
||||
socket.onclose = function(event) {
|
||||
console.log("WebSocket connection closed");
|
||||
displayMessage("WebSocket connection closed");
|
||||
};
|
||||
|
||||
// Function to display messages on the page
|
||||
function displayMessage(message) {
|
||||
const messageElement = document.createElement('div');
|
||||
messageElement.textContent = message;
|
||||
messagesDiv.appendChild(messageElement);
|
||||
}
|
||||
|
||||
// Button to send the message
|
||||
sendButton.onclick = function() {
|
||||
const message = messageInput.value;
|
||||
if (message) {
|
||||
console.log("Sending message: " + message);
|
||||
socket.send(message);
|
||||
displayMessage("You: " + message);
|
||||
messageInput.value = ''; // Clear the input field
|
||||
} else {
|
||||
alert("Please enter a message!");
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in new issue
Block a user