Skip to content

Commit afab230

Browse files
committed
feat: 修改登录表单字段为账户,添加获取当前用户信息的API,重构字典和用户相关接口
1 parent 8b2052e commit afab230

File tree

11 files changed

+67
-66
lines changed

11 files changed

+67
-66
lines changed

src/api/auth/index.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const AuthAPI = {
66
/** 登录接口*/
77
login(data: LoginFormData) {
88
const formData = new FormData();
9-
formData.append("account", data.username);
9+
formData.append("account", data.account);
1010
formData.append("password", data.password);
1111
formData.append("captchaKey", data.captchaKey);
1212
formData.append("captchaCode", data.captchaCode);
@@ -48,6 +48,18 @@ const AuthAPI = {
4848
});
4949
},
5050

51+
/**
52+
* 获取当前登录用户信息
53+
*
54+
* @returns 登录用户昵称、头像信息,包括角色和权限
55+
*/
56+
getInfo() {
57+
return request<any, UserInfo>({
58+
url: `${AUTH_BASE_URL}/userinfo`,
59+
method: "get",
60+
});
61+
},
62+
5163
/** 获取个人中心用户信息 */
5264
getProfile() {
5365
return request<any, UserProfileVO>({
@@ -116,7 +128,7 @@ export default AuthAPI;
116128
/** 登录表单数据 */
117129
export interface LoginFormData {
118130
/** 用户名 */
119-
username: string;
131+
account: string;
120132
/** 密码 */
121133
password: string;
122134
/** 验证码缓存key */
@@ -145,6 +157,27 @@ export interface CaptchaInfo {
145157
captchaBase64: string;
146158
}
147159

160+
/** 登录用户信息 */
161+
export interface UserInfo {
162+
/** 用户ID */
163+
id?: number;
164+
165+
/** 用户名 */
166+
account?: string;
167+
168+
/** 昵称 */
169+
name?: string;
170+
171+
/** 头像URL */
172+
avatar?: string;
173+
174+
/** 角色 */
175+
roles: string[];
176+
177+
/** 权限 */
178+
perms: string[];
179+
}
180+
148181
/** 个人中心用户信息 */
149182
export interface UserProfileVO {
150183
/** 用户ID */

src/api/system/config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ export interface ConfigForm {
8080
/** 主键 */
8181
id?: number;
8282
/** 配置名称 */
83-
Name?: string;
83+
name?: string;
8484
/** 配置键 */
85-
Key?: string;
85+
key?: string;
8686
/** 配置值 */
87-
Value?: string;
87+
value?: string;
8888
/** 描述、备注 */
8989
remark?: string;
9090
}
@@ -94,11 +94,11 @@ export interface ConfigPageVO {
9494
/** 主键 */
9595
id?: number;
9696
/** 配置名称 */
97-
Name?: string;
97+
name?: string;
9898
/** 配置键 */
99-
Key?: string;
99+
key?: string;
100100
/** 配置值 */
101-
Value?: string;
101+
value?: string;
102102
/** 描述、备注 */
103103
remark?: string;
104104
}

src/api/system/dict.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ const DictAPI = {
7070
},
7171

7272
/**
73-
* 获取字典列表
73+
* 获取字典的数据项
7474
*
75-
* @returns 字典列表
75+
* @param dictCode 字典编码
76+
* @returns 字典数据项
7677
*/
77-
getList() {
78+
getOptions() {
7879
return request<any, DictVO[]>({
79-
url: `${DICT_BASE_URL}/page`,
80+
url: `${DICT_BASE_URL}/options`,
8081
method: "get",
8182
});
8283
},

src/api/system/notice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const NoticeAPI = {
113113
/** 获取我的通知分页列表 */
114114
getMyNoticePage(queryParams?: NoticePageQuery) {
115115
return request<any, PageResult<NoticePageVO[]>>({
116-
url: `${NOTICE_BASE_URL}/my-page`,
116+
url: `${NOTICE_BASE_URL}/mine`,
117117
method: "get",
118118
params: queryParams,
119119
});

src/api/system/user.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@ import request from "@/utils/request";
33
const USER_BASE_URL = "/admin/users";
44

55
const UserAPI = {
6-
/**
7-
* 获取当前登录用户信息
8-
*
9-
* @returns 登录用户昵称、头像信息,包括角色和权限
10-
*/
11-
getInfo() {
12-
return request<any, UserInfo>({
13-
url: `${USER_BASE_URL}/userinfo`,
14-
method: "get",
15-
});
16-
},
17-
186
/**
197
* 重置密码
208
*
@@ -150,27 +138,6 @@ const UserAPI = {
150138

151139
export default UserAPI;
152140

153-
/** 登录用户信息 */
154-
export interface UserInfo {
155-
/** 用户ID */
156-
id?: number;
157-
158-
/** 用户名 */
159-
account?: string;
160-
161-
/** 昵称 */
162-
name?: string;
163-
164-
/** 头像URL */
165-
avatar?: string;
166-
167-
/** 角色 */
168-
roles: string[];
169-
170-
/** 权限 */
171-
perms: string[];
172-
}
173-
174141
/**
175142
* 用户分页查询对象
176143
*/

src/lang/package/en.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ export default {
66
},
77
// 登录页面国际化
88
login: {
9-
username: "Username",
9+
account: "Username",
1010
password: "Password",
1111
login: "Login",
1212
captchaCode: "Verify Code",
1313
capsLock: "Caps Lock is On",
1414
rememberMe: "Remember Me",
1515
forgetPassword: "Forget Password",
1616
message: {
17-
username: {
18-
required: "Please enter Username",
17+
account: {
18+
required: "Please enter account",
1919
},
2020
password: {
2121
required: "Please enter Password",

src/lang/package/zh-cn.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ export default {
66
},
77
// 登录页面国际化
88
login: {
9-
username: "用户名",
9+
account: "用户名",
1010
password: "密码",
1111
login: "登 录",
1212
captchaCode: "验证码",
1313
capsLock: "大写锁定已打开",
1414
rememberMe: "记住我",
1515
forgetPassword: "忘记密码",
1616
message: {
17-
username: {
17+
account: {
1818
required: "请输入用户名",
1919
},
2020
password: {

src/store/modules/dict.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ export const useDictStore = defineStore("dict", () => {
55
const dictionary = useStorage<Record<string, DictData[]>>("dictionary", {});
66

77
const setDictionary = (dict: DictVO) => {
8-
dictionary.value[dict.dictCode] = dict.dictDataList;
8+
dictionary.value[dict.code] = dict.dictDataList;
99
};
1010

1111
const loadDictionaries = async () => {
12-
const dictList = await DictionaryAPI.getList();
12+
const dictList = await DictionaryAPI.getOptions();
1313
dictList.forEach(setDictionary);
1414
};
1515

src/store/modules/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const useUserStore = defineStore("user", () => {
3838
*/
3939
function getUserInfo() {
4040
return new Promise<UserInfo>((resolve, reject) => {
41-
UserAPI.getInfo()
41+
AuthAPI.getInfo()
4242
.then((data) => {
4343
if (!data) {
4444
reject("Verification failed, please Login again.");

src/views/login/index.vue

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@
4646
--></div>
4747

4848
<!-- 用户名 -->
49-
<el-form-item prop="username">
49+
<el-form-item prop="account">
5050
<div class="input-wrapper">
5151
<el-icon class="mx-2">
5252
<User />
5353
</el-icon>
5454
<el-input
55-
ref="username"
56-
v-model="loginFormData.username"
57-
:placeholder="$t('login.username')"
58-
name="username"
55+
ref="account"
56+
v-model="loginFormData.account"
57+
:placeholder="$t('login.account')"
58+
name="account"
5959
size="large"
6060
class="h-[48px]"
6161
/>
@@ -171,19 +171,19 @@ const isCapslock = ref(false); // 是否大写锁定
171171
const captchaBase64 = ref(); // 验证码图片Base64字符串
172172
173173
const loginFormData = ref<LoginFormData>({
174-
username: "alpha2008",
174+
account: "alpha2008",
175175
password: "alpha2008",
176176
captchaKey: "",
177177
captchaCode: "",
178178
});
179179
180180
const loginRules = computed(() => {
181181
return {
182-
username: [
182+
account: [
183183
{
184184
required: true,
185185
trigger: "blur",
186-
message: t("login.message.username.required"),
186+
message: t("login.message.account.required"),
187187
},
188188
],
189189
password: [
@@ -226,7 +226,7 @@ async function handleLoginSubmit() {
226226
.then(async () => {
227227
await userStore.getUserInfo();
228228
// 需要在路由跳转前加载字典数据,否则会出现字典数据未加载完成导致页面渲染异常
229-
// await dictStore.loadDictionaries();
229+
await dictStore.loadDictionaries();
230230
// 跳转到登录前的页面
231231
const { path, queryParams } = parseRedirect();
232232
router.push({ path: path, query: queryParams });
@@ -279,8 +279,8 @@ function checkCapslock(event: KeyboardEvent) {
279279
}
280280
281281
// 设置登录凭证
282-
const setLoginCredentials = (username: string, password: string) => {
283-
loginFormData.value.username = username;
282+
const setLoginCredentials = (account: string, password: string) => {
283+
loginFormData.value.account = account;
284284
loginFormData.value.password = password;
285285
};
286286

src/views/system/menu/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331

332332
<script setup lang="ts">
333333
defineOptions({
334-
name: "SysMenu",
334+
name: "Menu",
335335
inheritAttrs: false,
336336
});
337337

0 commit comments

Comments
 (0)