Skip to content

Let's use AI to Earn!

扫码登录

DESKTOP-ZTS2NQJNA48b2c8dbf853
diff --git a/electron/db/models/user.ts b/electron/db/models/user.ts
index bf80c3ab..71a1c458 100644
--- a/electron/db/models/user.ts
+++ b/electron/db/models/user.ts
@@ -19,6 +19,9 @@ export class UserModel extends TempModel {
@Column({ type: 'varchar', nullable: false, comment: '用户手机号' })
phone!: string;
+ @Column({ type: 'varchar', nullable: false, comment: '用户微信openid' })
+ wxOpenId!: string;
+
@Column({ type: 'datetime', nullable: false, comment: '登录时间' })
loginTime!: Date;
}
diff --git a/electron/main/user/controller.ts b/electron/main/user/controller.ts
index 6ddb810d..096eb29e 100644
--- a/electron/main/user/controller.ts
+++ b/electron/main/user/controller.ts
@@ -24,6 +24,7 @@ export class UserController {
): Promise<UserModel> {
const currUser = {
...user,
+ phone: user.phone || user.wxOpenId,
loginTime: new Date(),
};
await this.userService.addUser(currUser);
diff --git a/src/api/types/user-t.ts b/src/api/types/user-t.ts
index 9c4db67a..fd950dba 100644
--- a/src/api/types/user-t.ts
+++ b/src/api/types/user-t.ts
@@ -9,10 +9,11 @@ export interface IUserInfo {
_id: string;
id: string;
name: string;
- phone: string;
- gender: number;
- avatar: string;
- desc: string;
+ phone?: string;
+ gender?: number;
+ avatar?: string;
+ desc?: string;
+ wxOpenId?: string;
}
export interface IRefreshToken {
diff --git a/src/views/login/components/qrcodeLogin.tsx b/src/views/login/components/qrcodeLogin.tsx
index 9f2eb2c7..bfb7bc48 100644
--- a/src/views/login/components/qrcodeLogin.tsx
+++ b/src/views/login/components/qrcodeLogin.tsx
@@ -10,6 +10,10 @@ import { userApi } from '@/api/user';
import { Button } from 'antd';
import { ReloadOutlined } from '@ant-design/icons';
import styles from '../login.module.scss';
+import { useUserStore } from '@/store/user';
+import { IRefreshToken, PhoneLoginParams } from '@/api/types/user-t';
+import { message } from 'antd';
+import { useNavigate } from 'react-router-dom';
export interface PubItemRef {
init: (pubRecord: any) => Promise<void>;
@@ -21,18 +25,41 @@ export default forwardRef<PubItemRef>((props, ref) => {
key: '',
});
const [showMask, setShowMask] = useState(false);
+ const userStore = useUserStore();
+ const navigate = useNavigate();
useEffect(() => {
getQrcode();
- const timer = setTimeout(() => {
+ const qrcodeTimer = setTimeout(() => {
setShowMask(true);
}, 30000); // 30秒后显示遮罩
return () => {
- clearTimeout(timer);
+ clearTimeout(qrcodeTimer);
};
}, []);
+ // 添加轮询登录检查
+ useEffect(() => {
+ let loginTimer: NodeJS.Timeout;
+
+ if (ticketInfo.ticket) {
+ loginTimer = setInterval(async () => {
+ const res = await userApi.wxGzhQrcodelogin(ticketInfo);
+ if (res.token !== '' && res.userInfo) {
+ LoginSuccess(res);
+ clearInterval(loginTimer);
+ }
+ }, 2000); // 每2秒检查一次
+ }
+
+ return () => {
+ if (loginTimer) {
+ clearInterval(loginTimer);
+ }
+ };
+ }, [ticketInfo]);
+
async function getQrcode() {
const res = await userApi.getWxLoginQrcode({});
if (res) {
@@ -44,12 +71,24 @@ export default forwardRef<PubItemRef>((props, ref) => {
}
}
+ const LoginSuccess = (res: any) => {
+ if (!res) return;
+ window.ipcRenderer.invoke('ICP_USER_ADD', res.userInfo);
+ userStore.setToken(res);
+ userStore.getUserInfo(res.userInfo);
+ message.success('登录成功!');
+ navigate('/');
+ };
+
/**
* 登录
*/
async function wxGzhQrcodelogin() {
const res = await userApi.wxGzhQrcodelogin(ticketInfo);
console.log('---- res', res);
+ if (res.token !== '' && res.userInfo) {
+ LoginSuccess(res);
+ }
}
useImperativeHandle(ref, () => ({
@@ -86,13 +125,10 @@ export default forwardRef<PubItemRef>((props, ref) => {
)}
</div>
- <div className={styles['loginForm-buttonWrapper']}>
- <Button
- onClick={wxGzhQrcodelogin}
- className={`${styles.submitBtn} ${ticketInfo.ticket ? styles.active : ''}`}
- >
- 登录
- </Button>
+ <div className={styles.agreement}>
+ 登录即表示已接受爱团团
+ <a href="#" onClick={(e) => { e.preventDefault(); /* 打开注册协议 */ }}>《注册协议》</a>
+ <a href="#" onClick={(e) => { e.preventDefault(); /* 打开隐私政策 */ }}>《隐私权政策》</a>
</div>
</div>
);
diff --git a/src/views/login/login.module.scss b/src/views/login/login.module.scss
index e4393f48..5e1f6814 100644
--- a/src/views/login/login.module.scss
+++ b/src/views/login/login.module.scss
@@ -173,6 +173,23 @@
margin-top: 0;
padding: 0 40px;
}
+
+ .agreement {
+ margin-top: 20px;
+ text-align: center;
+ font-size: 12px;
+ color: #666;
+
+ a {
+ color: #C367EF;
+ text-decoration: none;
+ margin: 0 2px;
+
+ &:hover {
+ color: #64C9ED;
+ }
+ }
+ }
}
}