import upload from '@/utils/upload'
import request from '@/utils/request'

/** 接口 */
const Api = {
	edit: '/api/sys/user/edit',
	editPassword: '/api/sys/user/password/edit',
	resetPassword: '/api/sys/user/password/reset',
	menu: '/api/sys/user/menu',
	menuWithClientType: '/api/sys/user/menuWithClientType',
	power: '/api/sys/user/power',
	powerWithClientType: '/api/sys/user/powerWithClientType',
	role: '/api/sys/user/role',
	login: '/api/login',
	logout: '/api/logout',
	profile: '/api/sys/user/profile',
	uploadAvatar:'/api/sys/oss/upload',
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
	const data = {
		oldPassword,
		newPassword
	}
	return request({
		url: '/system/user/profile/updatePwd',
		method: 'put',
		params: data
	})
}

// 修改用户个人信息
export function updateUserProfile(data) {
	return request({
		url: '/system/user/profile',
		method: 'put',
		data: data
	})
}

// 用户头像上传
export function uploadAvatar(data) {
	return upload({
		url: Api.uploadAvatar,
		name: data.name,
		filePath: data.filePath
	})
}
/** 登录 */
export const login = data => {
	return request({
		url: Api.login,
		params: data,
		method: 'POST'
	})
}
/** 注销 */
export const logout = data => {
	return request({
		url: Api.logout,
		data: data,
		method: 'GET'
	})
}

/** 修改密码 */
export const editPassword = data => {
	return request({
		url: Api.editPassword,
		data: data,
		method: 'PUT'
	})
}

/** 重置密码 */
export const resetPassword = data => {
	return request({
		url: Api.resetPassword,
		params: data,
		method: 'PUT'
	})
}
/** 个人信息 */
export const profile = data => {
	return request({
		url: Api.profile,
		data: data,
		method: 'GET'
	})
}

/** 用户菜单 */
export const menu = data => {
	return request({
		url: Api.menuWithClientType,
		params: data,
		method: 'GET'
	})
}

/** 用户角色 */
export const role = data => {
	return request({
		url: Api.role,
		params: data,
		method: 'GET'
	})
}

/** 用户权限 */
export const power = data => {
	return request({
		url: Api.powerWithClientType,
		params: data,
		method: 'GET'
	})
}