hookehuyr

refactor(api): 更新API路径和参数以支持手机号登录

统一将用户相关接口的路径和参数从邮箱改为手机号,并更新相关文档和前端登录页面
1 /* 1 /*
2 * @Date: 2022-06-17 14:54:29 2 * @Date: 2022-06-17 14:54:29
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-12-01 16:26:27 4 + * @LastEditTime: 2025-03-26 00:42:59
5 - * @FilePath: /data-table/src/api/common.js 5 + * @FilePath: /mlaj/src/api/common.js
6 * @Description: 通用接口 6 * @Description: 通用接口
7 */ 7 */
8 import { fn, fetch, uploadFn } from '@/api/fn'; 8 import { fn, fetch, uploadFn } from '@/api/fn';
9 9
10 const Api = { 10 const Api = {
11 - SMS: '/srv/?a=sms', 11 + SMS: '/srv/?a=sms_code',
12 TOKEN: '/srv/?a=upload', 12 TOKEN: '/srv/?a=upload',
13 SAVE_FILE: '/srv/?a=upload&t=save_file', 13 SAVE_FILE: '/srv/?a=upload&t=save_file',
14 } 14 }
15 15
16 /** 16 /**
17 * @description: 发送验证码 17 * @description: 发送验证码
18 - * @param {*} phone 手机号码 18 + * @param {*} mobile 手机号码
19 * @returns 19 * @returns
20 */ 20 */
21 export const smsAPI = (params) => fn(fetch.post(Api.SMS, params)); 21 export const smsAPI = (params) => fn(fetch.post(Api.SMS, params));
......
1 /* 1 /*
2 * @Date: 2025-03-23 23:45:53 2 * @Date: 2025-03-23 23:45:53
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-03-23 23:45:54 4 + * @LastEditTime: 2025-03-26 00:41:11
5 * @FilePath: /mlaj/src/api/users.js 5 * @FilePath: /mlaj/src/api/users.js
6 * @Description: 用户相关接口 6 * @Description: 用户相关接口
7 */ 7 */
8 import { fn, fetch } from './fn'; 8 import { fn, fetch } from './fn';
9 9
10 const Api = { 10 const Api = {
11 - USER_LOGIN: '/users/login', 11 + USER_LOGIN: '/srv/?a=user_login',
12 - USER_REGISTER: '/users/register', 12 + USER_REGISTER: '/srv/?a=user_register',
13 - USER_INFO: '/users/info', 13 + USER_INFO: '/srv/?a=user_info',
14 - USER_UPDATE: '/users/update', 14 + USER_UPDATE: '/srv/?a=user_edit',
15 - USER_AVATAR: '/users/avatar', 15 + USER_PASSWORD: '/srv/?a=user_reset_password',
16 - USER_PASSWORD: '/users/password',
17 } 16 }
18 17
19 /** 18 /**
20 * @description: 用户登录 19 * @description: 用户登录
21 - * @param: email 用户邮箱 20 + * @param: mobile 手机号
22 * @param: password 用户密码 21 * @param: password 用户密码
23 */ 22 */
24 export const loginAPI = (params) => fn(fetch.post(Api.USER_LOGIN, params)); 23 export const loginAPI = (params) => fn(fetch.post(Api.USER_LOGIN, params));
...@@ -26,31 +25,30 @@ export const loginAPI = (params) => fn(fetch.post(Api.USER_LOGIN, params)); ...@@ -26,31 +25,30 @@ export const loginAPI = (params) => fn(fetch.post(Api.USER_LOGIN, params));
26 /** 25 /**
27 * @description: 用户注册 26 * @description: 用户注册
28 * @param: name 用户名称 27 * @param: name 用户名称
29 - * @param: email 用户邮箱 28 + * @param: mobile 手机号
29 + * @param: sms_code 短信验证码
30 * @param: password 用户密码 30 * @param: password 用户密码
31 + * @param: avatar 头像
31 */ 32 */
32 export const registerAPI = (params) => fn(fetch.post(Api.USER_REGISTER, params)); 33 export const registerAPI = (params) => fn(fetch.post(Api.USER_REGISTER, params));
33 34
34 /** 35 /**
35 * @description: 获取用户信息 36 * @description: 获取用户信息
37 + * @return: data: { user: { id, name, mobile, avatar } }
36 */ 38 */
37 export const getUserInfoAPI = () => fn(fetch.get(Api.USER_INFO)); 39 export const getUserInfoAPI = () => fn(fetch.get(Api.USER_INFO));
38 40
39 /** 41 /**
40 * @description: 更新用户信息 42 * @description: 更新用户信息
41 * @param: name 用户名称 43 * @param: name 用户名称
44 + * @param: avatar 头像
42 */ 45 */
43 export const updateUserInfoAPI = (params) => fn(fetch.put(Api.USER_UPDATE, params)); 46 export const updateUserInfoAPI = (params) => fn(fetch.put(Api.USER_UPDATE, params));
44 47
45 /** 48 /**
46 - * @description: 上传用户头像 49 + * @description: 忘记密码
47 - * @param: avatar 头像文件 50 + * @param: mobile 手机号
51 + * @param: sms_code 短信验证码
52 + * @param: password 密码
48 */ 53 */
49 -export const uploadAvatarAPI = (formData) => fn(fetch.post(Api.USER_AVATAR, formData)); 54 +export const resetPasswordAPI = (params) => fn(fetch.put(Api.USER_PASSWORD, params));
50 -
51 -/**
52 - * @description: 修改用户密码
53 - * @param: oldPassword 原密码
54 - * @param: newPassword 新密码
55 - */
56 -export const updatePasswordAPI = (params) => fn(fetch.put(Api.USER_PASSWORD, params));
......
...@@ -13,15 +13,15 @@ ...@@ -13,15 +13,15 @@
13 13
14 <form class="space-y-6" @submit.prevent="handleSubmit"> 14 <form class="space-y-6" @submit.prevent="handleSubmit">
15 <div> 15 <div>
16 - <label for="email" class="block text-sm font-medium text-gray-700"> 16 + <label for="mobile" class="block text-sm font-medium text-gray-700">
17 - 邮箱 / 手机号 17 + 手机号
18 </label> 18 </label>
19 <input 19 <input
20 - id="email" 20 + id="mobile"
21 - v-model="email" 21 + v-model="mobile"
22 - name="email" 22 + name="mobile"
23 type="text" 23 type="text"
24 - autocomplete="email" 24 + autocomplete="mobile"
25 required 25 required
26 class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-green-500 focus:border-green-500" 26 class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-green-500 focus:border-green-500"
27 /> 27 />
...@@ -114,22 +114,23 @@ import { ref } from 'vue' ...@@ -114,22 +114,23 @@ import { ref } from 'vue'
114 import { useRoute, useRouter } from 'vue-router' 114 import { useRoute, useRouter } from 'vue-router'
115 import FrostedGlass from '@/components/ui/FrostedGlass.vue' 115 import FrostedGlass from '@/components/ui/FrostedGlass.vue'
116 import { useAuth } from '@/contexts/auth' 116 import { useAuth } from '@/contexts/auth'
117 -import { useTitle } from '@vueuse/core'
118 import { loginAPI } from '@/api/users' 117 import { loginAPI } from '@/api/users'
118 +
119 +import { useTitle } from '@vueuse/core'
119 const $route = useRoute(); 120 const $route = useRoute();
120 -const $router = useRouter();
121 useTitle($route.meta.title); 121 useTitle($route.meta.title);
122 +
122 const router = useRouter() 123 const router = useRouter()
123 const { login } = useAuth() 124 const { login } = useAuth()
124 125
125 -const email = ref('user1@example.com') 126 +const mobile = ref('13761653761')
126 const password = ref('password123') 127 const password = ref('password123')
127 const error = ref('') 128 const error = ref('')
128 const loading = ref(false) 129 const loading = ref(false)
129 130
130 // 原登录逻辑 131 // 原登录逻辑
131 // const handleSubmit = async () => { 132 // const handleSubmit = async () => {
132 -// if (!email.value || !password.value) { 133 +// if (!mobile.value || !password.value) {
133 // error.value = '请填写所有字段' 134 // error.value = '请填写所有字段'
134 // return 135 // return
135 // } 136 // }
...@@ -140,7 +141,7 @@ const loading = ref(false) ...@@ -140,7 +141,7 @@ const loading = ref(false)
140 141
141 // // 调用登录接口 142 // // 调用登录接口
142 // const response = await loginAPI({ 143 // const response = await loginAPI({
143 -// email: email.value, 144 +// mobile: mobile.value,
144 // password: password.value 145 // password: password.value
145 // }) 146 // })
146 147
...@@ -162,7 +163,7 @@ const loading = ref(false) ...@@ -162,7 +163,7 @@ const loading = ref(false)
162 163
163 // 临时登录逻辑 - 支持任意输入 164 // 临时登录逻辑 - 支持任意输入
164 const handleSubmit = async () => { 165 const handleSubmit = async () => {
165 - if (!email.value || !password.value) { 166 + if (!mobile.value || !password.value) {
166 error.value = '请填写所有字段' 167 error.value = '请填写所有字段'
167 return 168 return
168 } 169 }
......