Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tangtanglove committed Jul 12, 2023
1 parent bf64e9a commit 1654a55
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface InitialStateProps {
// 更多信息见文档:https://next.umijs.org/docs/api/runtime-config#getinitialstate
export async function getInitialState(): Promise<InitialStateProps> {
const getAccountInfo = () => {
const token = sessionStorage.getItem('token');
const token = localStorage.getItem('token');
if (token) {
// 返回解析的用户信息
return JSON.parse(Base64.decode(token.split('.')[1]));
Expand All @@ -26,7 +26,7 @@ export async function getInitialState(): Promise<InitialStateProps> {
return undefined;
};

const token = sessionStorage.getItem('token');
const token = localStorage.getItem('token');
if (token) {
const accountInfo = getAccountInfo();
return { accountInfo: accountInfo, getAccountInfo };
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form/Field/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ const EditorPage: React.FC<any> = ({ value, onChange, height, width }) => {
xhr.open('POST', upurl);
xhr.setRequestHeader(
'authorization',
'Bearer ' + sessionStorage['token'],
'Bearer ' + localStorage['token'],
);
xhr.onload = function () {
if (xhr.status !== 200) {
Expand Down Expand Up @@ -435,7 +435,7 @@ const EditorPage: React.FC<any> = ({ value, onChange, height, width }) => {
multiple={true}
action={'/api/admin/upload/image/handle'}
headers={{
authorization: 'Bearer ' + sessionStorage['token'],
authorization: 'Bearer ' + localStorage['token'],
}}
onChange={(info: any) => {
getPictures();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/Field/FileUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const FileUploader: React.FC<FileUploaderProps> = ({
multiple={true}
action={action}
headers={{
authorization: 'Bearer ' + sessionStorage['token'],
authorization: 'Bearer ' + localStorage['token'],
}}
beforeUpload={(file: any) => {
return checkUpload(file);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form/Field/ImageUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const ImageUploader: React.FC<ImageUploaderProps> = ({
showUploadList={false}
action={action}
headers={{
authorization: 'Bearer ' + sessionStorage['token'],
authorization: 'Bearer ' + localStorage['token'],
}}
beforeUpload={(file: any) => {
return checkUpload(file);
Expand Down Expand Up @@ -210,7 +210,7 @@ const ImageUploader: React.FC<ImageUploaderProps> = ({
listType="picture-card"
action={action}
headers={{
authorization: 'Bearer ' + sessionStorage['token'],
authorization: 'Bearer ' + localStorage['token'],
}}
beforeUpload={(file: any) => {
return checkUpload(file);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const Form: React.FC<ProFormProps & FormExtendProps> = (props) => {
if (apiType === 'GET') {
if (targetBlank) {
let url = tplEngine(api, data);
values['token'] = sessionStorage.getItem('token');
values['token'] = localStorage.getItem('token');
if (api?.indexOf('http') === -1) {
url = `${url}`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const Layout: React.FC<ProLayoutProps & LayoutProps> = (props) => {
url: '/api/admin/logout/index/handle',
});
if (result['status'] === 'success') {
sessionStorage.removeItem('token');
localStorage.removeItem('token');
}
history.push('/');
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const Login: React.FC<LoginProps> = (props) => {

if (result.status === 'success') {
// 记录登录凭据
sessionStorage.setItem('token', result.data.token);
localStorage.setItem('token', result.data.token);

// 清空layout
sessionStorage.removeItem('layout');
Expand Down
2 changes: 1 addition & 1 deletion src/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const Table: React.FC<ProTableProps<any, any, any> & TableExtendProps> = (
let getQuery: any = { ...query };
let url = search.exportApi;
getQuery['search'] = JSON.stringify(formRef.current?.getFieldsFormatValue?.());
getQuery['token'] = sessionStorage.getItem('token');
getQuery['token'] = localStorage.getItem('token');

window.open(`${url}?${qs.stringify(getQuery)}`);
}}
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const Layout: React.FC<any> = (props) => {
url: '/api/admin/logout/index/handle',
});
if (result['status'] === 'success') {
sessionStorage.removeItem('token');
localStorage.removeItem('token');
}
history.push('/');
};
Expand Down
2 changes: 1 addition & 1 deletion src/requestConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const requestConfig: RequestConfig = {
(config: RequestOptions) => {
config.headers = {
Accept: 'application/json',
Authorization: `Bearer ${sessionStorage.getItem('token') ?? ''}`,
Authorization: `Bearer ${localStorage.getItem('token') ?? ''}`,
};
const url = config?.url;
return { ...config, url };
Expand Down

0 comments on commit 1654a55

Please sign in to comment.