fix: 添加登录模块
This commit is contained in:
parent
c28ed3b747
commit
c821b7e428
2
.npmrc
2
.npmrc
@ -1,2 +1,2 @@
|
||||
registry=https://registry.npmmirror.com/
|
||||
|
||||
@zhst:registry="http://10.0.0.77:4874"
|
||||
|
@ -3,13 +3,13 @@
|
||||
"private": true,
|
||||
"author": "dev <710328466@qq.com>",
|
||||
"scripts": {
|
||||
"dev": "max dev",
|
||||
"build:master": "max build",
|
||||
"comp": "cross-env max g component",
|
||||
"dev": "max dev",
|
||||
"format": "prettier --cache --write .",
|
||||
"prepare": "husky install",
|
||||
"postinstall": "max setup",
|
||||
"page": "cross-env max g page",
|
||||
"comp": "cross-env max g component",
|
||||
"prepare": "husky install",
|
||||
"setup": "max setup",
|
||||
"start": "npm run dev"
|
||||
},
|
||||
@ -17,6 +17,7 @@
|
||||
"@ant-design/icons": "^5.3.0",
|
||||
"@ant-design/pro-components": "^2.6.49",
|
||||
"@umijs/max": "^4.1.1",
|
||||
"@zhst/communal-cabinet": "^0.3.0",
|
||||
"antd": "^5.14.1",
|
||||
"cross-env": "^7.0.3"
|
||||
},
|
||||
|
2756
pnpm-lock.yaml
2756
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
11
src/app.ts
11
src/app.ts
@ -1,3 +1,4 @@
|
||||
import doRequest from '@/utils/request';
|
||||
import { useState } from 'react';
|
||||
|
||||
// 运行时配置
|
||||
@ -35,6 +36,8 @@ export const qiankun = {
|
||||
? `//${hostname}:30068/intelligent-file-cabinet/`
|
||||
: '//localhost:30068/',
|
||||
props: {},
|
||||
singular: false,
|
||||
credentials: true,
|
||||
},
|
||||
{
|
||||
name: 'smart-video-analysis', // AI 智能分析仓
|
||||
@ -42,6 +45,8 @@ export const qiankun = {
|
||||
APP_ENV === 'production'
|
||||
? `//${hostname}:30088/smart-video-analysis/`
|
||||
: '//localhost:30088/',
|
||||
singular: false,
|
||||
credentials: true,
|
||||
},
|
||||
{
|
||||
name: 'algorithm-warehouse', // AI 算法分析
|
||||
@ -49,6 +54,8 @@ export const qiankun = {
|
||||
APP_ENV === 'production'
|
||||
? `//${hostname}:30078/algorithm-warehouse/`
|
||||
: '//localhost:30078/',
|
||||
singular: false,
|
||||
credentials: true,
|
||||
},
|
||||
{
|
||||
name: 'communal-facilities-pages', // 物料库
|
||||
@ -56,6 +63,8 @@ export const qiankun = {
|
||||
APP_ENV === 'production'
|
||||
? `//${hostname}:30098/communal-facilities-pages/`
|
||||
: '//localhost:30098/',
|
||||
singular: false,
|
||||
credentials: true,
|
||||
},
|
||||
],
|
||||
lifeCycles: {
|
||||
@ -65,3 +74,5 @@ export const qiankun = {
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const request = doRequest;
|
||||
|
BIN
src/assets/ai-video.png
Normal file
BIN
src/assets/ai-video.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 921 KiB |
4
src/global.less
Normal file
4
src/global.less
Normal file
@ -0,0 +1,4 @@
|
||||
* {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
@ -1,18 +1,10 @@
|
||||
import { SettingOutlined, ShopOutlined } from '@ant-design/icons';
|
||||
import { Outlet, useAppData, useModel } from '@umijs/max';
|
||||
import { Outlet } from '@umijs/max';
|
||||
import { FloatButton } from 'antd';
|
||||
import React from 'react';
|
||||
import styles from './index.less';
|
||||
|
||||
const Layout = () => {
|
||||
const p = useAppData();
|
||||
const model = useModel('@@qiankunStateForSlave');
|
||||
const model2 = useModel('@@initialState');
|
||||
|
||||
console.log('useAppData', p);
|
||||
console.log('qiankunStateForSlave', model);
|
||||
console.log('initialState', model2);
|
||||
|
||||
return (
|
||||
<div className={styles.layout}>
|
||||
<FloatButton.Group
|
||||
|
@ -2,15 +2,38 @@
|
||||
* Created by dev on 2024/03/18
|
||||
*/
|
||||
|
||||
import React, { FC } from 'react';
|
||||
import bg from '@/assets/ai-video.png';
|
||||
import loginController from '@/services/login';
|
||||
import { getValueByUrlParams } from '@/utils/format';
|
||||
import { history, useModel, useRequest } from '@umijs/max';
|
||||
import { Login } from '@zhst/communal-cabinet';
|
||||
import { Spin } from 'antd';
|
||||
import React from 'react';
|
||||
|
||||
interface LoginProps {
|
||||
demo: string;
|
||||
}
|
||||
const LoginPage = () => {
|
||||
const { setGlobalState } = useModel('@@qiankunStateForSlave');
|
||||
const urlJson = getValueByUrlParams(history.location.search);
|
||||
|
||||
const Login: FC<LoginProps> = (props) => {
|
||||
console.log('props', props);
|
||||
return <div>登录</div>;
|
||||
const { run, loading } = useRequest((params) => {
|
||||
return loginController.login(params);
|
||||
});
|
||||
|
||||
const handleFinish = (values: { account: string; password: string }) => {
|
||||
run({ username: values.account, password: values.password }).then(
|
||||
(res: any) => {
|
||||
if (res.token) {
|
||||
history.push(`${urlJson?.get('to')}?token=${res.token}` || '/', res);
|
||||
setGlobalState(res);
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Spin spinning={loading}>
|
||||
<Login title="" imageUrl={bg} onFinish={handleFinish} />
|
||||
</Spin>
|
||||
);
|
||||
};
|
||||
|
||||
export default Login;
|
||||
export default LoginPage;
|
||||
|
@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Created by dev on 2024/03/18
|
||||
*/
|
||||
|
||||
import React, { FC } from 'react';
|
||||
|
||||
export interface PasswordProps {
|
||||
demo: string;
|
||||
}
|
||||
|
||||
const Password: FC<PasswordProps> = (props) => {
|
||||
console.log('props', props);
|
||||
return <div>修改密码</div>;
|
||||
};
|
||||
|
||||
export default Password;
|
@ -1,96 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// 该文件由 OneAPI 自动生成,请勿手动修改!
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
/** 此处后端没有提供注释 GET /api/v1/queryUserList */
|
||||
export async function queryUserList(
|
||||
params: {
|
||||
// query
|
||||
/** keyword */
|
||||
keyword?: string;
|
||||
/** current */
|
||||
current?: number;
|
||||
/** pageSize */
|
||||
pageSize?: number;
|
||||
},
|
||||
options?: { [key: string]: any },
|
||||
) {
|
||||
return request<API.Result_PageInfo_UserInfo__>('/api/v1/queryUserList', {
|
||||
method: 'GET',
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** 此处后端没有提供注释 POST /api/v1/user */
|
||||
export async function addUser(
|
||||
body?: API.UserInfoVO,
|
||||
options?: { [key: string]: any },
|
||||
) {
|
||||
return request<API.Result_UserInfo_>('/api/v1/user', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** 此处后端没有提供注释 GET /api/v1/user/${param0} */
|
||||
export async function getUserDetail(
|
||||
params: {
|
||||
// path
|
||||
/** userId */
|
||||
userId?: string;
|
||||
},
|
||||
options?: { [key: string]: any },
|
||||
) {
|
||||
const { userId: param0 } = params;
|
||||
return request<API.Result_UserInfo_>(`/api/v1/user/${param0}`, {
|
||||
method: 'GET',
|
||||
params: { ...params },
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** 此处后端没有提供注释 PUT /api/v1/user/${param0} */
|
||||
export async function modifyUser(
|
||||
params: {
|
||||
// path
|
||||
/** userId */
|
||||
userId?: string;
|
||||
},
|
||||
body?: API.UserInfoVO,
|
||||
options?: { [key: string]: any },
|
||||
) {
|
||||
const { userId: param0 } = params;
|
||||
return request<API.Result_UserInfo_>(`/api/v1/user/${param0}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
params: { ...params },
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** 此处后端没有提供注释 DELETE /api/v1/user/${param0} */
|
||||
export async function deleteUser(
|
||||
params: {
|
||||
// path
|
||||
/** userId */
|
||||
userId?: string;
|
||||
},
|
||||
options?: { [key: string]: any },
|
||||
) {
|
||||
const { userId: param0 } = params;
|
||||
return request<API.Result_string_>(`/api/v1/user/${param0}`, {
|
||||
method: 'DELETE',
|
||||
params: { ...params },
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// 该文件由 OneAPI 自动生成,请勿手动修改!
|
||||
|
||||
import * as UserController from './UserController';
|
||||
export default {
|
||||
UserController,
|
||||
};
|
68
src/services/demo/typings.d.ts
vendored
68
src/services/demo/typings.d.ts
vendored
@ -1,68 +0,0 @@
|
||||
/* eslint-disable */
|
||||
// 该文件由 OneAPI 自动生成,请勿手动修改!
|
||||
|
||||
declare namespace API {
|
||||
interface PageInfo {
|
||||
/**
|
||||
1 */
|
||||
current?: number;
|
||||
pageSize?: number;
|
||||
total?: number;
|
||||
list?: Array<Record<string, any>>;
|
||||
}
|
||||
|
||||
interface PageInfo_UserInfo_ {
|
||||
/**
|
||||
1 */
|
||||
current?: number;
|
||||
pageSize?: number;
|
||||
total?: number;
|
||||
list?: Array<UserInfo>;
|
||||
}
|
||||
|
||||
interface Result {
|
||||
success?: boolean;
|
||||
errorMessage?: string;
|
||||
data?: Record<string, any>;
|
||||
}
|
||||
|
||||
interface Result_PageInfo_UserInfo__ {
|
||||
success?: boolean;
|
||||
errorMessage?: string;
|
||||
data?: PageInfo_UserInfo_;
|
||||
}
|
||||
|
||||
interface Result_UserInfo_ {
|
||||
success?: boolean;
|
||||
errorMessage?: string;
|
||||
data?: UserInfo;
|
||||
}
|
||||
|
||||
interface Result_string_ {
|
||||
success?: boolean;
|
||||
errorMessage?: string;
|
||||
data?: string;
|
||||
}
|
||||
|
||||
type UserGenderEnum = 'MALE' | 'FEMALE';
|
||||
|
||||
interface UserInfo {
|
||||
id?: string;
|
||||
name?: string;
|
||||
/** nick */
|
||||
nickName?: string;
|
||||
/** email */
|
||||
email?: string;
|
||||
gender?: UserGenderEnum;
|
||||
}
|
||||
|
||||
interface UserInfoVO {
|
||||
name?: string;
|
||||
/** nick */
|
||||
nickName?: string;
|
||||
/** email */
|
||||
email?: string;
|
||||
}
|
||||
|
||||
type definitions_0 = null;
|
||||
}
|
12
src/services/login/LoginController.ts
Normal file
12
src/services/login/LoginController.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
export async function login(
|
||||
body?: Login_API.IUserInfo,
|
||||
options?: { [key: string]: any },
|
||||
) {
|
||||
return request<Login_API.IUserInfo>('/v1/ma/BusinessApi/Login', {
|
||||
method: 'POST',
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
5
src/services/login/index.ts
Normal file
5
src/services/login/index.ts
Normal file
@ -0,0 +1,5 @@
|
||||
/* eslint-disable */
|
||||
|
||||
import * as LoginController from './LoginController';
|
||||
|
||||
export default LoginController;
|
6
src/services/login/typing.d.ts
vendored
Normal file
6
src/services/login/typing.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
declare namespace Login_API {
|
||||
interface IUserInfo {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
}
|
4
src/utils/constants.ts
Normal file
4
src/utils/constants.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export const API_URL =
|
||||
APP_ENV === 'production'
|
||||
? 'http://10.0.0.222:31300'
|
||||
: 'http://10.0.0.222:31300';
|
@ -1,4 +1,12 @@
|
||||
// 示例方法,没有实际意义
|
||||
export function trim(str: string) {
|
||||
return str.trim();
|
||||
}
|
||||
/**
|
||||
* 通过 url 获取想要的参数
|
||||
* @param key
|
||||
* @param url
|
||||
*/
|
||||
export const getValueByUrlParams = (url: string) => {
|
||||
if (url.indexOf('?') < 0) return;
|
||||
|
||||
const _params = new URLSearchParams(url.split('?')[1]);
|
||||
|
||||
return _params;
|
||||
};
|
||||
|
90
src/utils/request.ts
Normal file
90
src/utils/request.ts
Normal file
@ -0,0 +1,90 @@
|
||||
import type { RequestConfig } from '@umijs/max';
|
||||
import { API_URL } from './constants';
|
||||
|
||||
const doRequest: RequestConfig = {
|
||||
timeout: 1000,
|
||||
baseURL: API_URL,
|
||||
// other axios options you want
|
||||
errorConfig: {
|
||||
// @ts-ignore
|
||||
errorHandler(error: any, opts: any) {
|
||||
console.log('first', error, opts);
|
||||
// if (opts?.skipErrorHandler) throw error
|
||||
// try {
|
||||
// const { res } = ctx;
|
||||
// const d = await res.text();
|
||||
|
||||
// if (res.status === 401 && store.user.isLogin) {
|
||||
// store.user.resetLoginState();
|
||||
// message.warning('登录过期,请重新登录!');
|
||||
// return;
|
||||
// }
|
||||
// const isEmptyRes = d === '' || d.replace(/\s/g,"")=== 'tokenisinvalid'; //有些后端接口成功会返回空 做下兼容
|
||||
// const body = !isEmptyRes ? JSON.parse(d || '{}') : d;
|
||||
// const sessionCode = sessionStorage.getItem('zhst_errcode') || '{}'
|
||||
// const ERROR_CODE = JSON.parse(sessionCode);
|
||||
|
||||
// if (Number(res.status) === 200) {
|
||||
// ctx.res = body;
|
||||
// } else {
|
||||
// // 先判断Grpc-Metadata-Errorx-Message
|
||||
// let errMsg = ERROR_CODE[body.code]?.value || body.message || '您的网络发生异常,无法连接服务器'
|
||||
// toast && message.error(errMsg || body);
|
||||
// ctx.res = {
|
||||
// code: body.code,
|
||||
// message: errMsg
|
||||
// };
|
||||
// }
|
||||
|
||||
// } catch (error) {
|
||||
// if (get(error, 'type') !== 'CustomError') {
|
||||
// toast && message.error('您的网络发生异常,无法连接服务器');
|
||||
// }
|
||||
// throw error;
|
||||
// }
|
||||
},
|
||||
// @ts-ignore
|
||||
errorThrower(res) {
|
||||
console.log('res', res);
|
||||
},
|
||||
},
|
||||
// 请求
|
||||
requestInterceptors: [
|
||||
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
||||
[
|
||||
(url, options) => {
|
||||
// console.log('options', options);
|
||||
return {
|
||||
url,
|
||||
options: {
|
||||
...options,
|
||||
headers: {
|
||||
authorization: 'test',
|
||||
// ...(refererSuffix ? { zhst_referer: `${baseUrl}${refererSuffix}` } : {}),
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error);
|
||||
},
|
||||
],
|
||||
],
|
||||
// 返回
|
||||
responseInterceptors: [
|
||||
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
||||
[
|
||||
(response) => {
|
||||
if (response.status !== 200) {
|
||||
throw Error(JSON.stringify(response.data));
|
||||
}
|
||||
return response;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error);
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
|
||||
export default doRequest;
|
Loading…
Reference in New Issue
Block a user