251 lines
6.3 KiB
TypeScript
251 lines
6.3 KiB
TypeScript
import request from '@/utils/request'
|
||
import { LoginData } from '@/api/types'
|
||
import { useAdminInfo } from '@/stores/adminInfo'
|
||
import { sm3Digest } from '@/assets/commjs/sm3.js'
|
||
import { sm2, encrypt } from '@/assets/commjs/sm2.js'
|
||
|
||
// 获取公钥
|
||
export function gongkey(params?: any) {
|
||
if (!params) {
|
||
const adminInfo = useAdminInfo()
|
||
params = {
|
||
loginName: encrypt(adminInfo.$state.loginName)
|
||
}
|
||
}
|
||
return request({
|
||
url: '/user-boot/user/generateSm2Key',
|
||
method: 'get',
|
||
params
|
||
})
|
||
}
|
||
|
||
export async function pwdSm3(pwd: any, loginName?: string) {
|
||
let publicKey = await gongkey(
|
||
loginName
|
||
? {
|
||
loginName: encrypt(loginName)
|
||
}
|
||
: false
|
||
)
|
||
let sm3Pwd = sm3Digest(pwd) //SM3加密
|
||
return sm2(sm3Pwd + '|' + pwd, publicKey.data, 0)
|
||
}
|
||
|
||
//登录获取token
|
||
export async function login(params: any) {
|
||
if (params.refresh_token == undefined) {
|
||
params.password = await pwdSm3(params.password, params.username)
|
||
}
|
||
params.username = encrypt(params.username)
|
||
return request({
|
||
url: '/pqs-auth/oauth/token',
|
||
method: 'post',
|
||
params
|
||
})
|
||
}
|
||
//辽宁嵌入登录获取token
|
||
export async function loginLNqr(data: any) {
|
||
return request({
|
||
url: '/pqs-auth/oauth/lnLogin',
|
||
method: 'get',
|
||
params: data
|
||
})
|
||
}
|
||
|
||
export async function lnRefreshToken(data: any) {
|
||
return request({
|
||
url: '/pqs-auth/oauth/lnRefreshToken',
|
||
method: 'get',
|
||
params: data
|
||
})
|
||
}
|
||
|
||
export async function logout() {
|
||
return request({
|
||
url: '/pqs-auth/oauth/logout',
|
||
method: 'DELETE',
|
||
})
|
||
}
|
||
|
||
|
||
//获取用户信息
|
||
export function getUserById() {
|
||
const adminInfo = useAdminInfo()
|
||
return request({
|
||
url: '/user-boot/user/getUserById?id=' + adminInfo.userIndex,
|
||
method: 'get'
|
||
})
|
||
}
|
||
|
||
// 刷新token
|
||
// 导出一个名为refreshToken的函数,该函数返回一个Promise对象
|
||
export function refreshToken(): Promise<any> {
|
||
// 调用useAdminInfo函数获取管理员信息,并将其赋值给adminInfo变量
|
||
const adminInfo = useAdminInfo()
|
||
// 调用login函数,传入一个对象作为参数,该对象包含grant_type、refresh_token和username三个属性
|
||
// grant_type设置为'refresh_token',表示使用刷新令牌的方式获取新的访问令牌
|
||
// refresh_token使用adminInfo中的refresh_token属性
|
||
// username使用adminInfo中的loginName属性
|
||
// 返回login函数的调用结果,即一个Promise对象
|
||
return login({
|
||
grant_type: 'refresh_token',
|
||
refresh_token: adminInfo.refresh_token,
|
||
username: adminInfo.loginName
|
||
})
|
||
}
|
||
|
||
|
||
export function lnRefreshTokenTo(): Promise<any> {
|
||
// 调用useAdminInfo函数获取管理员信息,并将其赋值给adminInfo变量
|
||
const adminInfo = useAdminInfo()
|
||
return lnRefreshToken({
|
||
refreshToken: adminInfo.refresh_token,
|
||
clientId: "njcn",
|
||
clientSecret:"njcnpqs"
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 获取营销用户列表
|
||
* @returns {AxiosPromise}
|
||
*/
|
||
export const getMarketList = () => {
|
||
return request({
|
||
url: '/user-boot/user/getMarketList',
|
||
method: 'post'
|
||
})
|
||
}
|
||
|
||
export function add(data: any) {
|
||
return request({
|
||
url: '/user-boot/user/add',
|
||
method: 'post',
|
||
data: data
|
||
})
|
||
}
|
||
|
||
export function edit(data: any) {
|
||
return request({
|
||
url: '/user-boot/user/update',
|
||
method: 'put',
|
||
data: data
|
||
})
|
||
}
|
||
|
||
export async function passwordConfirm(pwd: string) {
|
||
return request({
|
||
url: '/user-boot/user/passwordConfirm?password=' + (await pwdSm3(pwd)),
|
||
method: 'get'
|
||
})
|
||
}
|
||
|
||
export function deluser(data: any) {
|
||
return request({
|
||
url: '/user-boot/user/delete',
|
||
method: 'delete',
|
||
params: data
|
||
})
|
||
}
|
||
|
||
export function activateUser(data: any) {
|
||
return request({
|
||
url: '/user-boot/user/activateUser',
|
||
method: 'put',
|
||
params: data
|
||
})
|
||
}
|
||
|
||
export async function updatePassword(params: any) {
|
||
return request({
|
||
url: '/user-boot/user/updatePassword',
|
||
method: 'put',
|
||
params: {
|
||
id: params.id,
|
||
newPassword: await pwdSm3(params.newPassword)
|
||
}
|
||
})
|
||
}
|
||
|
||
export async function updateFirstPassword(params: any) {
|
||
return request({
|
||
url: '/user-boot/user/updateFirstPassword',
|
||
method: 'put',
|
||
data: {
|
||
name: encrypt(params.name),
|
||
password: await pwdSm3(params.password, params.name)
|
||
}
|
||
})
|
||
}
|
||
|
||
export function checkUser(data: any) {
|
||
return request({
|
||
url: '/user-boot/user/check',
|
||
method: 'put',
|
||
data: data
|
||
})
|
||
}
|
||
export function existMonitorDeptTree() {
|
||
return request({
|
||
url: '/user-boot/dept/existMonitorDeptTree',
|
||
method: 'post'
|
||
})
|
||
}
|
||
// 获取用户
|
||
export function getUserByRoleType(data: any) {
|
||
return request({
|
||
url: '/user-boot/user/getUserByRoleType?roleType=' + data,
|
||
method: 'GET'
|
||
})
|
||
}
|
||
|
||
// 获取部门下所有用户
|
||
export function listAllUserByDeptId(data: any) {
|
||
return request({
|
||
url: '/user-boot/user/listAllUserByDeptId?deptId=' + data,
|
||
method: 'GET'
|
||
})
|
||
}
|
||
|
||
// 根据id获取所有用户信息
|
||
export function getUserListByIds(data: any) {
|
||
return request({
|
||
url: '/user-boot/user/getUserListByIds',
|
||
method: 'POST',
|
||
data
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 查询所有用户不包括管理员
|
||
*/
|
||
export const getUserSimpleList = () => {
|
||
return request({
|
||
url: '/user-boot/user/simpleList',
|
||
method: 'GET'
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 查询所有用户包括管理员
|
||
*/
|
||
export const getAllUserSimpleList = () => {
|
||
return request({
|
||
url: '/user-boot/user/getAllUserSimpleList',
|
||
method: 'GET'
|
||
})
|
||
}
|
||
|
||
export const getSysConfig = () => {
|
||
return request({
|
||
url: '/system-boot/config/getSysConfig',
|
||
method: 'get'
|
||
})
|
||
}
|
||
// 驾驶舱组件配置
|
||
export const componentTree = () => {
|
||
return request({
|
||
url: '/user-boot/component/componentTree',
|
||
method: 'GET'
|
||
})
|
||
}
|