ref: 细节优化,头像上传增加 api prefix

This commit is contained in:
lbw 2023-04-07 16:56:37 +08:00
parent 1fcb7c129b
commit fc39d84942
4 changed files with 21 additions and 15 deletions

View File

@ -3,6 +3,12 @@ import { Session } from '/@/utils/storage';
import { validateNull } from '/@/utils/validate';
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
@ -18,9 +24,8 @@ export const login = (data: any) => {
data: { password: password },
headers: {
skipToken: true,
'TENANT-ID': '1',
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',
headers: {
skipToken: true,
'TENANT-ID': '1',
Authorization: basicAuth,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Type': FORM_CONTENT_TYPE,
},
method: 'post',
params: { mobile: 'SMS@' + mobile, code: code, grant_type, scope },
@ -54,9 +58,8 @@ export const loginBySocial = (state: string, code: string) => {
url: '/auth/oauth2/token',
headers: {
skipToken: true,
'TENANT-ID': '1',
Authorization: basicAuth,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Type': FORM_CONTENT_TYPE,
},
method: 'post',
params: { mobile: state + '@' + code, code: code, grant_type, scope },
@ -80,9 +83,8 @@ export const refreshTokenApi = (refresh_token: string) => {
url: '/auth/oauth2/token',
headers: {
skipToken: true,
'TENANT-ID': '1',
Authorization: basicAuth,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Type': FORM_CONTENT_TYPE,
},
method: 'post',
params: { refresh_token, grant_type, scope },
@ -100,7 +102,7 @@ export const checkToken = (refreshTime: number, refreshLock: boolean) => {
headers: {
skipToken: true,
Authorization: basicAuth,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Type': FORM_CONTENT_TYPE,
},
method: 'get',
params: { token: Session.getToken() },

View File

@ -15,7 +15,8 @@
:accept="fileType.join(',')"
>
<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="handle-icon" @click="editImg" v-if="!self_disabled">
<el-icon><Edit /></el-icon>

View File

@ -29,15 +29,15 @@ service.interceptors.request.use(
};
}
// 统一增加Authorization请求头
// 统一增加Authorization请求头, skipToken 跳过增加token
const token = Session.getToken();
if (token && !config.headers?.isToken) {
if (token && !config.headers?.skipToken) {
config.headers!['Authorization'] = `Bearer ${token}`;
}
// 统一增加TENANT-ID请求头
const tenantId = Session.getTenant()
if (tenantId && !config.headers?.skipTenant) {
const tenantId = Session.getTenant();
if (tenantId) {
config.headers!['TENANT-ID'] = tenantId;
}

View File

@ -2,7 +2,7 @@
<el-card style="height: 100%">
<div style="display: flex; justify-content: space-between">
<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">
<span style="font-weight: 600; margin: 2px; font-size: 18px">{{ userData.name }}</span>
<span style="color: #6d737b; margin: 2px">{{ userData.deptName }} | {{ userData.postName }}</span>
@ -19,6 +19,7 @@
import { useUserInfo } from '/@/stores/userInfo';
import { getObj } from '/@/api/admin/user';
const { proxy } = getCurrentInstance();
const date = ref(new Date());
const userData = ref({
@ -52,6 +53,8 @@ const initUserInfo = async (userId: any): Promise<void> => {
const res = await getObj(userId); //
userData.value = res.data; // 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 {
loading.value = false; //
}