Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface UserPackageType {
package_name: string;
created_at: string;
type: number;
expired_day: number;
}

export interface UserInfoType {
Expand Down Expand Up @@ -50,7 +51,7 @@ export default {
getUserPackages(): Promise<UserPackageType[]> {
return request('user/package/record');
},
register(data: { nickname: string; mobile: string; password: string; shareOpenId: string }): Promise<{
register(data: { nickname: string; mobile: string; password: string; share_openid: string }): Promise<{
user: UserInfoType;
access_token: string;
}> {
Expand All @@ -75,7 +76,7 @@ export default {
mobile: string;
code: string;
oauth_id: string;
shareOpenId: string;
share_openid: string;
}): Promise<{ user: UserInfoType; access_token: string }> {
return request('sms/login', {
method: 'post',
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use-task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import taskService, { TaskTypeEnums } from '@/api/task';
import { useUserStore } from '@/store';

const useTask = () => {
const [isLogin] = useUserStore((state) => [state.isLogin]);
const [isLogin] = useUserStore((state) => [state.isLogin()]);

// 分享成功
async function shareCallback() {
Expand Down
58 changes: 30 additions & 28 deletions src/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,34 +99,36 @@ const UserDropDown = () => {
};

return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="p-0 px-2">
<Avatar className="h-8 w-8">
<AvatarImage src={avatar || appConfig.user_logo} alt={nickname} />
<AvatarFallback>{nickname.slice(0, 1)}</AvatarFallback>
</Avatar>
<p className="ml-2">{nickname}</p>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align={'end'}>
<DropdownMenuItem
className="flex items-center gap-2"
onClick={() => {
if (!isLogin) {
navigate('/login');
} else {
navigate('/user');
}
}}
>
{!isLogin ? '请先登录' : '个人中心'}
</DropdownMenuItem>
<DropdownMenuItem className="flex items-center gap-2" onClick={() => handleSignOut()}>
退出登录
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<>
{isLogin ? (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="p-0 px-2">
<Avatar className="h-8 w-8">
<AvatarImage src={avatar || appConfig.user_logo} alt={nickname} />
<AvatarFallback>{nickname.slice(0, 1)}</AvatarFallback>
</Avatar>
<p className="ml-2">{nickname}</p>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align={'end'}>
<DropdownMenuItem
className="flex items-center gap-2"
onClick={() => {
navigate('/user');
}}
>
个人中心
</DropdownMenuItem>
<DropdownMenuItem className="flex items-center gap-2" onClick={() => handleSignOut()}>
退出登录
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
) : (
<Button onClick={() => navigate('/login')}>去登陆</Button>
)}
</>
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/pages/billing/BillingRecords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function BillingRecordsDialog({ children }: { children: React.ReactNode }
{userPackages.map((item, index) => (
<TableRow key={index}>
<TableCell className="font-medium">{item.package_name}</TableCell>
<TableCell>+{item.num}次</TableCell>
<TableCell> {item.num === -1 ? `+${item.expired_day}天` : `${item.num}次`}</TableCell>
<TableCell className="text-right">{item.created_at}</TableCell>
</TableRow>
))}
Expand Down
5 changes: 3 additions & 2 deletions src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Footer = ({
state.setStream,
],
);
const [{ openid }, isLogin] = useUserStore((state) => [state.userInfo, state.isLogin]);
const [{ openid }, isLogin] = useUserStore((state) => [state.userInfo, state.isLogin()]);
const [currentConversation, editConversation] = useChatStore((state) => [
state.currentConversation,
state.editConversation,
Expand All @@ -61,7 +61,8 @@ const Footer = ({
const handleSendUserMessage = async () => {
if (!isLogin) {
toast.error('请登录');
return navigator('/login');
navigator('/login');
return;
}
if (!currentChatData.length) {
editConversation(currentConversation.uuid, { title: userInput });
Expand Down
4 changes: 2 additions & 2 deletions src/pages/login/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function PhoneLoginForm({ oauthId = '', protocolChecked = false }) {
const { user, access_token } = await userService.phoneLogin({
...values,
oauth_id: oauthId,
shareOpenId: localStorage.getItem(StoreKey.ShareOpenId) || '',
share_openid: localStorage.getItem(StoreKey.ShareOpenId) || '',
});
setUserInfo(user);
setAccessToken(access_token);
Expand Down Expand Up @@ -232,7 +232,7 @@ export function RegisterDialog({ children }: { children: React.ReactNode }) {
try {
const { user, access_token } = await userService.register({
...omit(values, ['repassword']),
shareOpenId: localStorage.getItem(StoreKey.ShareOpenId) || '',
share_openid: localStorage.getItem(StoreKey.ShareOpenId) || '',
});
setUserInfo(user);
setAccessToken(access_token);
Expand Down