You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 登录接口示例 - 启用加密版本
*
* 这个文件展示了如何在现有接口中启用加密功能
* 仅需在请求配置中添加 encrypt: true 即可
*/
import request from '@/utils/request'
// 登录方法 - 启用加密
export function login(username, password, code, uuid) {
const data = {
username,
password,
code,
uuid
}
return request({
url: '/auth/login',
headers: {
isToken: false
},
method: 'post',
data: data,
encrypt: true // ⭐ 启用加密:添加这一行即可
})
}
// 注册方法 - 启用加密
export function register(data) {
return request({
url: '/register',
headers: {
isToken: false
},
method: 'post',
data: data,
encrypt: true // ⭐ 启用加密:注册信息需要加密
})
}
// 获取用户详细信息 - 不需要加密GET 请求)
export function getInfo() {
return request({
url: '/getInfo',
method: 'get'
// GET 请求不支持加密,无需设置 encrypt
})
}
// 退出方法 - 不需要加密
export function logout() {
return request({
url: '/logout',
method: 'post'
// 退出登录通常不需要加密
})
}
// 获取验证码 - 不需要加密
export function getCodeImg() {
return request({
url: '/auth/code',
headers: {
isToken: false
},
method: 'get',
timeout: 20000
// 验证码获取不需要加密
})
}
/**
* 使用说明:
*
* 1. 确保已安装依赖:
* npm install crypto-js jsencrypt
*
* 2. 配置 config.js
* enableEncrypt: true // 开启全局加密开关
* rsaPublicKey: '...' // 配置 RSA 公钥
*
* 3. 在需要加密的接口中添加 encrypt: true
*
* 4. 只有 POST/PUT 请求支持加密
*
* 5. 后端需要配置相同的加密规则
*/