mirror of
https://gitee.com/log4j/pig-ui.git
synced 2024-12-23 05:40:20 +08:00
ref: 细节优化,头像上传增加 api prefix
This commit is contained in:
parent
1fcb7c129b
commit
fc39d84942
@ -3,6 +3,12 @@ import { Session } from '/@/utils/storage';
|
|||||||
import { validateNull } from '/@/utils/validate';
|
import { validateNull } from '/@/utils/validate';
|
||||||
import { useUserInfo } from '/@/stores/userInfo';
|
import { useUserInfo } from '/@/stores/userInfo';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://www.ietf.org/rfc/rfc6749.txt
|
||||||
|
* OAuth 协议 4.3.1 要求格式为 form 而不是 JSON 注意!
|
||||||
|
*/
|
||||||
|
const FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
* @param data
|
* @param data
|
||||||
@ -18,9 +24,8 @@ export const login = (data: any) => {
|
|||||||
data: { password: password },
|
data: { password: password },
|
||||||
headers: {
|
headers: {
|
||||||
skipToken: true,
|
skipToken: true,
|
||||||
'TENANT-ID': '1',
|
|
||||||
Authorization: basicAuth,
|
Authorization: basicAuth,
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': FORM_CONTENT_TYPE,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -35,9 +40,8 @@ export const loginByMobile = (mobile: any, code: any) => {
|
|||||||
url: '/auth/oauth2/token',
|
url: '/auth/oauth2/token',
|
||||||
headers: {
|
headers: {
|
||||||
skipToken: true,
|
skipToken: true,
|
||||||
'TENANT-ID': '1',
|
|
||||||
Authorization: basicAuth,
|
Authorization: basicAuth,
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': FORM_CONTENT_TYPE,
|
||||||
},
|
},
|
||||||
method: 'post',
|
method: 'post',
|
||||||
params: { mobile: 'SMS@' + mobile, code: code, grant_type, scope },
|
params: { mobile: 'SMS@' + mobile, code: code, grant_type, scope },
|
||||||
@ -54,9 +58,8 @@ export const loginBySocial = (state: string, code: string) => {
|
|||||||
url: '/auth/oauth2/token',
|
url: '/auth/oauth2/token',
|
||||||
headers: {
|
headers: {
|
||||||
skipToken: true,
|
skipToken: true,
|
||||||
'TENANT-ID': '1',
|
|
||||||
Authorization: basicAuth,
|
Authorization: basicAuth,
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': FORM_CONTENT_TYPE,
|
||||||
},
|
},
|
||||||
method: 'post',
|
method: 'post',
|
||||||
params: { mobile: state + '@' + code, code: code, grant_type, scope },
|
params: { mobile: state + '@' + code, code: code, grant_type, scope },
|
||||||
@ -80,9 +83,8 @@ export const refreshTokenApi = (refresh_token: string) => {
|
|||||||
url: '/auth/oauth2/token',
|
url: '/auth/oauth2/token',
|
||||||
headers: {
|
headers: {
|
||||||
skipToken: true,
|
skipToken: true,
|
||||||
'TENANT-ID': '1',
|
|
||||||
Authorization: basicAuth,
|
Authorization: basicAuth,
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': FORM_CONTENT_TYPE,
|
||||||
},
|
},
|
||||||
method: 'post',
|
method: 'post',
|
||||||
params: { refresh_token, grant_type, scope },
|
params: { refresh_token, grant_type, scope },
|
||||||
@ -100,7 +102,7 @@ export const checkToken = (refreshTime: number, refreshLock: boolean) => {
|
|||||||
headers: {
|
headers: {
|
||||||
skipToken: true,
|
skipToken: true,
|
||||||
Authorization: basicAuth,
|
Authorization: basicAuth,
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': FORM_CONTENT_TYPE,
|
||||||
},
|
},
|
||||||
method: 'get',
|
method: 'get',
|
||||||
params: { token: Session.getToken() },
|
params: { token: Session.getToken() },
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
:accept="fileType.join(',')"
|
:accept="fileType.join(',')"
|
||||||
>
|
>
|
||||||
<template v-if="imageUrl">
|
<template v-if="imageUrl">
|
||||||
<img :src="imageUrl.indexOf('http') > 0 ? baseURL + imageUrl : imageUrl" class="upload-image" />
|
<!-- 如果返回的是OSS 地址则不需要增加 baseURL -->
|
||||||
|
<img :src="imageUrl.includes('http') ? imageUrl : baseURL + imageUrl" class="upload-image" />
|
||||||
<div class="upload-handle" @click.stop>
|
<div class="upload-handle" @click.stop>
|
||||||
<div class="handle-icon" @click="editImg" v-if="!self_disabled">
|
<div class="handle-icon" @click="editImg" v-if="!self_disabled">
|
||||||
<el-icon><Edit /></el-icon>
|
<el-icon><Edit /></el-icon>
|
||||||
|
@ -29,15 +29,15 @@ service.interceptors.request.use(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 统一增加Authorization请求头
|
// 统一增加Authorization请求头, skipToken 跳过增加token
|
||||||
const token = Session.getToken();
|
const token = Session.getToken();
|
||||||
if (token && !config.headers?.isToken) {
|
if (token && !config.headers?.skipToken) {
|
||||||
config.headers!['Authorization'] = `Bearer ${token}`;
|
config.headers!['Authorization'] = `Bearer ${token}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 统一增加TENANT-ID请求头
|
// 统一增加TENANT-ID请求头
|
||||||
const tenantId = Session.getTenant()
|
const tenantId = Session.getTenant();
|
||||||
if (tenantId && !config.headers?.skipTenant) {
|
if (tenantId) {
|
||||||
config.headers!['TENANT-ID'] = tenantId;
|
config.headers!['TENANT-ID'] = tenantId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<el-card style="height: 100%">
|
<el-card style="height: 100%">
|
||||||
<div style="display: flex; justify-content: space-between">
|
<div style="display: flex; justify-content: space-between">
|
||||||
<div style="display: flex">
|
<div style="display: flex">
|
||||||
<el-avatar style="width: 60px; height: 60px" shape="circle" :size="100" fit="cover" :src="baseURL + userData.avatar" />
|
<el-avatar style="width: 60px; height: 60px" shape="circle" :size="100" fit="cover" :src="userData.avatar" />
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<span style="font-weight: 600; margin: 2px; font-size: 18px">{{ userData.name }}</span>
|
<span style="font-weight: 600; margin: 2px; font-size: 18px">{{ userData.name }}</span>
|
||||||
<span style="color: #6d737b; margin: 2px">{{ userData.deptName }} | {{ userData.postName }}</span>
|
<span style="color: #6d737b; margin: 2px">{{ userData.deptName }} | {{ userData.postName }}</span>
|
||||||
@ -19,6 +19,7 @@
|
|||||||
import { useUserInfo } from '/@/stores/userInfo';
|
import { useUserInfo } from '/@/stores/userInfo';
|
||||||
import { getObj } from '/@/api/admin/user';
|
import { getObj } from '/@/api/admin/user';
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance();
|
||||||
const date = ref(new Date());
|
const date = ref(new Date());
|
||||||
|
|
||||||
const userData = ref({
|
const userData = ref({
|
||||||
@ -52,6 +53,8 @@ const initUserInfo = async (userId: any): Promise<void> => {
|
|||||||
const res = await getObj(userId); // 执行查询操作
|
const res = await getObj(userId); // 执行查询操作
|
||||||
userData.value = res.data; // 将查询到的数据保存到 userData 变量中
|
userData.value = res.data; // 将查询到的数据保存到 userData 变量中
|
||||||
userData.value.postName = res.data?.postList?.map((item: any) => item.postName).join(',') || ''; // 将 postList 中的 postName 合并成字符串并保存到 userData 变量中
|
userData.value.postName = res.data?.postList?.map((item: any) => item.postName).join(',') || ''; // 将 postList 中的 postName 合并成字符串并保存到 userData 变量中
|
||||||
|
// 文件上传增加后端前缀
|
||||||
|
userData.value.avatar = proxy.baseURL + res.data.avatar;
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false; // 结束加载状态
|
loading.value = false; // 结束加载状态
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user