Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Update Mobile Login and update Pwd API #17

Merged
merged 2 commits into from
Sep 22, 2023
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
4 changes: 2 additions & 2 deletions apps/test-server/service/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Result } from '../utils';

const fakeUserInfo = {
userId: '1',
username: 'vben',
realName: 'Vben Admin',
username: 'admin',
name: 'test Admin',
desc: 'manager',
password: '123456',
token: 'fakeToken1',
Expand Down
20 changes: 20 additions & 0 deletions src/api/sys/model/userModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ export interface LoginReq {
captchaId: string;
}

export interface mobileLoginReq {
phoneNumber: string;
sms: string;
type: number;
}

export interface registerReq {
username: string;
password: string;
phoneNumber: string;
sms: number;
}

export interface updatePasswordReq {
username: string;
password: string;
phoneNumber: string;
sms: number;
}

export interface RoleInfo {
roleName: string;
value: string;
Expand Down
125 changes: 90 additions & 35 deletions src/api/sys/user.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,115 @@
import { defHttp } from '/@/utils/http/axios';
import {GetUserInfoModel, LoginReq, LoginResp} from './model/userModel';
import {defHttp} from '/@/utils/http/axios';
import {GetUserInfoModel, LoginReq, LoginResp, mobileLoginReq, registerReq, updatePasswordReq} from './model/userModel';

import { ErrorMessageMode } from '/#/axios';
import {BaseDataResp} from "@/api/model/baseModel";
import {ErrorMessageMode} from '/#/axios';
import {BaseDataResp, BaseResp} from "@/api/model/baseModel";

enum Api {
Login = '/user/login',
Logout = '/user/logout',
GetUserInfo = '/user/info',
GetPermCode = '/getPermCode',
TestRetry = '/testRetry',
Login = '/user/login',
MobileLogin = '/user/mobileLogin',
Logout = '/user/logout',
Register = '/user/register',
SMS = '/v2/common/sms',
UpdatePassword = '/user/updatePassword',
GetUserInfo = '/user/info',
GetPermCode = '/getPermCode',
TestRetry = '/testRetry',
}

/**
* @description: user login api
*/
export function login(params: LoginReq, mode: ErrorMessageMode = 'notice') {
return defHttp.post<BaseDataResp<LoginResp>>(
{
url: Api.Login,
params,
},
{
errorMessageMode: mode,
successMessageMode: mode,
},
);
return defHttp.post<BaseDataResp<LoginResp>>(
{
url: Api.Login,
params,
},
{
errorMessageMode: mode,
successMessageMode: mode,
},
);
}

export function mobileLogin(params: mobileLoginReq, mode: ErrorMessageMode = 'notice') {
return defHttp.post<BaseDataResp<LoginResp>>(
{
url: Api.MobileLogin,
params,
},
{
errorMessageMode: mode,
successMessageMode: mode,
},
);
}

export function register(params: registerReq, mode: ErrorMessageMode = 'notice') {
return defHttp.post<BaseResp>(
{
url: Api.Register,
params,
},
{
errorMessageMode: mode,
successMessageMode: mode,
}
)
}

export function sendSmsRegister(type: number, phoneNumber: string, mode: ErrorMessageMode = 'notice') {
return defHttp.get<BaseResp>(
{
url: `${Api.SMS}/${type}/${phoneNumber}`
},
{
errorMessageMode: mode,
successMessageMode: mode,
}
)
}

export function updatePassword(params: updatePasswordReq, mode: ErrorMessageMode = 'notice') {
return defHttp.post<BaseResp>(
{
url: Api.UpdatePassword,
params,
},
{
errorMessageMode: mode,
successMessageMode: mode,
}
)
}

/**
* @description: getUserInfo
*/
export function getUserInfo() {
return defHttp.get<BaseDataResp<GetUserInfoModel>>(
{ url: Api.GetUserInfo },
{ errorMessageMode: 'none' },
);
return defHttp.get<BaseDataResp<GetUserInfoModel>>(
{url: Api.GetUserInfo},
{errorMessageMode: 'none'},
);
}

export function getPermCode() {
return defHttp.get<string[]>({ url: Api.GetPermCode });
return defHttp.get<string[]>({url: Api.GetPermCode});
}

export function doLogout() {
return defHttp.get({ url: Api.Logout });
return defHttp.get({url: Api.Logout});
}

export function testRetry() {
return defHttp.get(
{ url: Api.TestRetry },
{
retryRequest: {
isOpenRetry: true,
count: 5,
waitTime: 1000,
},
},
);
return defHttp.get(
{url: Api.TestRetry},
{
retryRequest: {
isOpenRetry: true,
count: 5,
waitTime: 1000,
},
},
);
}
2 changes: 1 addition & 1 deletion src/hooks/web/useTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function useTabs(_router?: Router) {
if (!show) {
throw new Error('The multi-tab page is currently not open, please open it in the settings!');
}
return !!show;
return show;
}

const tabStore = useMultipleTabStore();
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/default/header/components/lock/LockModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
const userStore = useUserStore();
const lockStore = useLockStore();

const getRealName = computed(() => userStore.getUserInfo?.realName);
const getRealName = computed(() => userStore.getUserInfo?.name);
const [register, { closeModal }] = useModalInner();

const [registerForm, { validateFields, resetFields }] = useForm({
Expand Down
6 changes: 3 additions & 3 deletions src/layouts/default/header/components/user-dropdown/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<img :class="`${prefixCls}__header`" :src="getUserInfo.avatar" />
<span :class="`${prefixCls}__info hidden md:block`">
<span :class="`${prefixCls}__name`" class="truncate">
{{ getUserInfo.realName }}
{{ getUserInfo.name }}
</span>
</span>
</span>
Expand Down Expand Up @@ -76,8 +76,8 @@
const userStore = useUserStore();

const getUserInfo = computed(() => {
const { realName = '', avatar, desc } = userStore.getUserInfo || {};
return { realName, avatar: avatar || headerImg, desc };
const { name = '', avatar, desc } = userStore.getUserInfo || {};
return { name, avatar: avatar || headerImg, desc };
});

const [register, { openModal }] = useModal();
Expand Down
3 changes: 3 additions & 0 deletions src/locales/lang/en/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default {
// placeholder
accountPlaceholder: 'Please input username',
passwordPlaceholder: 'Please input password',
captchaPlaceholder: 'Please input verification code',
smsPlaceholder: 'Please input sms code',
mobilePlaceholder: 'Please input mobile',
policyPlaceholder: 'Register after checking',
Expand All @@ -100,6 +101,8 @@ export default {
userName: 'Username',
password: 'Password',
confirmPassword: 'Confirm Password',
newPassword: 'New Password',
updatePassword: 'Change Password',
email: 'Email',
smsCode: 'SMS code',
mobile: 'Mobile',
Expand Down
3 changes: 3 additions & 0 deletions src/locales/lang/zh-CN/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default {
// placeholder
accountPlaceholder: '请输入账号',
passwordPlaceholder: '请输入密码',
captchaPlaceholder: '请输入验证码',
smsPlaceholder: '请输入验证码',
mobilePlaceholder: '请输入手机号码',
policyPlaceholder: '勾选后才能注册',
Expand All @@ -94,6 +95,8 @@ export default {
userName: '账号',
password: '密码',
confirmPassword: '确认密码',
newPassword: '新密码',
updatePassword: '修改密码',
email: '邮箱',
smsCode: '短信验证码',
mobile: '手机号码',
Expand Down
29 changes: 27 additions & 2 deletions src/store/modules/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { ROLES_KEY, ROLES_NAME_KEY, TOKEN_KEY, USER_INFO_KEY } from '/@/enums/ca
import { getAuthCache, setAuthCache } from '/@/utils/auth';
import {
GetUserInfoModel,
LoginReq,
LoginReq, mobileLoginReq, updatePasswordReq,
} from '/@/api/sys/model/userModel';
import { doLogout, getUserInfo, login} from '/@/api/sys/user';
import {doLogout, getUserInfo, login, mobileLogin} from '/@/api/sys/user';
import { useI18n } from '/@/hooks/web/useI18n';
import { useMessage } from '/@/hooks/web/useMessage';
import { router } from '/@/router';
Expand Down Expand Up @@ -117,6 +117,31 @@ export const useUserStore = defineStore({
}
},

/**
* @description: mobileLogin
*/
async mobileLogin(
params: mobileLoginReq & {
goHome?: boolean;
mode?: ErrorMessageMode;
},
): Promise<GetUserInfoModel | null> {
try {
const { goHome = true, mode, ...mobileLoginReq } = params;
const data = await mobileLogin(mobileLoginReq, mode);
if (data.code !== '00000') {
return Promise.reject(null);
}
const { token } = data.data;

// save token
this.setToken(token);
return this.afterLoginAction(goHome);
} catch (error) {
return Promise.reject(error);
}
},

async afterLoginAction(goHome?: boolean): Promise<GetUserInfoModel | null> {
if (!this.getToken) return null;
// get user info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="lg:flex">
<Avatar :src="userinfo.avatar || headerImg" :size="72" class="!mx-auto !block" />
<div class="md:ml-6 flex flex-col justify-center md:mt-0 mt-2">
<h1 class="md:text-lg text-md">早安, {{ userinfo.realName }}, 开始您一天的工作吧!</h1>
<h1 class="md:text-lg text-md">早安, {{ userinfo.name }}, 开始您一天的工作吧!</h1>
<span class="text-secondary"> 今日晴,20℃ - 32℃! </span>
</div>
<div class="flex flex-1 justify-end md:mt-0 mt-4">
Expand Down
Loading