chore(模块): 对脚手架做了些更改
This commit is contained in:
parent
beb008c078
commit
6ed190d92e
102
config/config.ts
102
config/config.ts
@ -1,5 +1,5 @@
|
|||||||
// import { defineConfig } from "umi";
|
// import { defineConfig } from "umi";
|
||||||
// import proxy from './proxy';
|
import proxy from './proxy';
|
||||||
|
|
||||||
//不使用defineConfig则能在其他地方获取这些配置
|
//不使用defineConfig则能在其他地方获取这些配置
|
||||||
export default {
|
export default {
|
||||||
@ -11,5 +11,105 @@ export default {
|
|||||||
title: 'UMI4 Admin',
|
title: 'UMI4 Admin',
|
||||||
favicons: [
|
favicons: [
|
||||||
'/favicon.svg'
|
'/favicon.svg'
|
||||||
|
],
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
key: '1',
|
||||||
|
path: '/',
|
||||||
|
redirect: '',
|
||||||
|
name: '首页'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
key: '2',
|
||||||
|
name: '关于',
|
||||||
|
path: '/about',
|
||||||
|
redirect: '/about/m',
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
id: 21,
|
||||||
|
key: '2-1',
|
||||||
|
name: '关于你',
|
||||||
|
path: '/about/u',
|
||||||
|
redirect: '/about/u/1',
|
||||||
|
pid: 2,
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
id: 211,
|
||||||
|
key: '2-1-1',
|
||||||
|
name: '关于你1',
|
||||||
|
path: '/about/u/index',
|
||||||
|
redirect: '',
|
||||||
|
pid: 21
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 212,
|
||||||
|
key: '2-1-2',
|
||||||
|
name: '关于你2',
|
||||||
|
path: '/about/u/2',
|
||||||
|
redirect: '',
|
||||||
|
pid: 21
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 22,
|
||||||
|
key: '2-2',
|
||||||
|
path: '/about/m',
|
||||||
|
redirect: '',
|
||||||
|
name: '(页面元素权限)关于我',
|
||||||
|
pid: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 23,
|
||||||
|
key: '2-3',
|
||||||
|
path: '/about/um',
|
||||||
|
redirect: '',
|
||||||
|
name: '关于你和我',
|
||||||
|
pid: 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
key: '3',
|
||||||
|
name: '教师',
|
||||||
|
path: '/teacher',
|
||||||
|
redirect: '/teacher/u',
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
id: 31,
|
||||||
|
key: '3-1',
|
||||||
|
path: '/teacher/u',
|
||||||
|
redirect: '',
|
||||||
|
name: '(403)关于你教师',
|
||||||
|
pid: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 32,
|
||||||
|
key: '3-2',
|
||||||
|
path: '/teacher/m',
|
||||||
|
redirect: '',
|
||||||
|
name: '关于我教师',
|
||||||
|
pid: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 33,
|
||||||
|
key: '3-3',
|
||||||
|
path: '/teacher/um',
|
||||||
|
redirect: '',
|
||||||
|
name: '关于你和我教师',
|
||||||
|
pid: 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
key: '4',
|
||||||
|
name: '(404)学生',
|
||||||
|
path: '/student',
|
||||||
|
redirect: '',
|
||||||
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
const proxy = {
|
const proxy = {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'https://preview.pro.ant.design',
|
target: 'http://10.104.1.38:3000',
|
||||||
changeOrigin: true
|
changeOrigin: true,
|
||||||
|
pathRewrite: { '^/api': '' },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,12 +20,12 @@ const handleCommonRes = (data: Record<string, unknown> | Record<string, unknown>
|
|||||||
const userApi = {
|
const userApi = {
|
||||||
//登录
|
//登录
|
||||||
'POST /api/user/login': async (req: Request, res: Response) => {
|
'POST /api/user/login': async (req: Request, res: Response) => {
|
||||||
const { UserPassWord, UserPassport, mobile, captcha } = req.body;
|
const { password, username, mobile, captcha } = req.body;
|
||||||
await waitTime(2000);
|
await waitTime(2000);
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case UserPassport === 'admin' && UserPassWord === 'ant.design':
|
case username === 'admin' && password === 'ant.design':
|
||||||
case UserPassport === 'user' && UserPassWord === 'ant.design':
|
case username === 'user' && password === 'ant.design':
|
||||||
case /^1\d{10}$/.test(mobile) && Boolean(captcha):
|
case /^1\d{10}$/.test(mobile) && Boolean(captcha):
|
||||||
res.send(
|
res.send(
|
||||||
handleCommonRes({
|
handleCommonRes({
|
||||||
@ -159,7 +159,7 @@ const userApi = {
|
|||||||
id: 211,
|
id: 211,
|
||||||
key: '2-1-1',
|
key: '2-1-1',
|
||||||
name: '关于你1',
|
name: '关于你1',
|
||||||
path: '/about/u/1',
|
path: '/about/u/index',
|
||||||
redirect: '',
|
redirect: '',
|
||||||
pid: 21
|
pid: 21
|
||||||
},
|
},
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
"@ant-design/pro-components": "^2.8.6",
|
"@ant-design/pro-components": "^2.8.6",
|
||||||
"antd": "^5.21.2",
|
"antd": "^5.21.2",
|
||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
|
"crypto-js": "^4.2.0",
|
||||||
"dva": "^3.0.0-alpha.1",
|
"dva": "^3.0.0-alpha.1",
|
||||||
"umi": "^4.3.24"
|
"umi": "^4.3.24"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -49,6 +49,8 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
|
|||||||
const [collapsed, setCollapsed] = useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
const [openKeys, setOpenKeys] = useState(['']);
|
const [openKeys, setOpenKeys] = useState(['']);
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
dispatch,
|
dispatch,
|
||||||
user: {
|
user: {
|
||||||
@ -139,6 +141,8 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
|
|||||||
// ];
|
// ];
|
||||||
console.log('consumableMenu', consumableMenu);
|
console.log('consumableMenu', consumableMenu);
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
console.log('location', location);
|
||||||
|
|
||||||
|
|
||||||
// 改变panes
|
// 改变panes
|
||||||
const handleTabsPanes = (payload: any): void => {
|
const handleTabsPanes = (payload: any): void => {
|
||||||
@ -183,7 +187,7 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
|
|||||||
guid: "2",
|
guid: "2",
|
||||||
hideInMenu: false,
|
hideInMenu: false,
|
||||||
name: "关于你1",
|
name: "关于你1",
|
||||||
path: "/about/u/1",
|
path: "/about/u/index",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
SYSTEMMODULE_DESC: "",
|
SYSTEMMODULE_DESC: "",
|
||||||
|
|||||||
@ -108,6 +108,7 @@ const UserModel: UserModelType = {
|
|||||||
effects: {
|
effects: {
|
||||||
//登录
|
//登录
|
||||||
*login({ payload }, { call, put }) {
|
*login({ payload }, { call, put }) {
|
||||||
|
console.log('payload', payload);
|
||||||
|
|
||||||
yield put({
|
yield put({
|
||||||
type: 'save',
|
type: 'save',
|
||||||
@ -117,6 +118,7 @@ const UserModel: UserModelType = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const res: API.LoginResponse = yield call(userLogin, payload);
|
const res: API.LoginResponse = yield call(userLogin, payload);
|
||||||
|
console.log('res', res);
|
||||||
|
|
||||||
//登录成功之后设置token并获取用户信息等数据
|
//登录成功之后设置token并获取用户信息等数据
|
||||||
if (!res.code) {
|
if (!res.code) {
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
const authority: PageAuthority = {
|
const authority: PageAuthority = {
|
||||||
'/': [
|
'/': [
|
||||||
'/',
|
'/',
|
||||||
],
|
],
|
||||||
'/about/u/1': [
|
'/about/u/index': [
|
||||||
'/about/u/1',
|
'/about/u/index',
|
||||||
],
|
],
|
||||||
'/about/u/2': [
|
'/about/u/2': [
|
||||||
'/about/u/2',
|
'/about/u/2',
|
||||||
|
|||||||
@ -88,8 +88,7 @@ const Index: FC<UserConnectedProps> = (props) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ProFormText
|
<ProFormText
|
||||||
name="UserPassport"
|
name="username"
|
||||||
|
|
||||||
fieldProps={{
|
fieldProps={{
|
||||||
size: 'large',
|
size: 'large',
|
||||||
prefix: <UserOutlined className={styles.prefixIcon} />,
|
prefix: <UserOutlined className={styles.prefixIcon} />,
|
||||||
@ -103,7 +102,7 @@ const Index: FC<UserConnectedProps> = (props) => {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<ProFormText.Password
|
<ProFormText.Password
|
||||||
name="UserPassWord"
|
name="password"
|
||||||
fieldProps={{
|
fieldProps={{
|
||||||
size: 'large',
|
size: 'large',
|
||||||
prefix: <LockFilled className={styles.prefixIcon} />,
|
prefix: <LockFilled className={styles.prefixIcon} />,
|
||||||
|
|||||||
@ -1,9 +1,21 @@
|
|||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
|
|
||||||
//登录
|
//登录
|
||||||
export const userLogin = (params: Record<string, unknown>): Promise<API.LoginResponse> => (
|
// export const userLogin = (params: Record<string, unknown>): Promise<API.LoginResponse> => (
|
||||||
request.post('/api/user/login', params)
|
// request.post('/api/user/login', params)
|
||||||
);
|
// );
|
||||||
|
|
||||||
|
// 登录
|
||||||
|
export async function userLogin(params: any) {
|
||||||
|
console.log('paramsuserLogin', params);
|
||||||
|
|
||||||
|
const data = await request.post('/api/user/login', params)
|
||||||
|
// const data = await request.post('/auth/login', params)
|
||||||
|
console.log('data', data);
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
export const retrieveUserInfo = (): Promise<API.UserInfoResponse> => (
|
export const retrieveUserInfo = (): Promise<API.UserInfoResponse> => (
|
||||||
|
|||||||
@ -2,15 +2,23 @@ import axios from 'axios';
|
|||||||
import { getDvaApp } from 'umi';
|
import { getDvaApp } from 'umi';
|
||||||
import { notification } from 'antd';
|
import { notification } from 'antd';
|
||||||
import type { AxiosRequestHeaders } from 'axios/index';
|
import type { AxiosRequestHeaders } from 'axios/index';
|
||||||
|
import CryptoJS from "crypto-js";
|
||||||
|
|
||||||
const { UMI_APP_BASEURL } = process.env;
|
const { UMI_APP_BASEURL } = process.env;
|
||||||
|
|
||||||
const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
||||||
// const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
|
// const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
|
||||||
|
// const instance = axios.create({ baseURL: '/api' });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
instance.interceptors.request.use(
|
instance.interceptors.request.use(
|
||||||
(config) => {
|
(config) => {
|
||||||
|
// 对data数据进行加密
|
||||||
|
// if (config.data) {
|
||||||
|
// config.data = preprocessData(JSON.stringify(config.data)); // 调用预处理函数
|
||||||
|
// }
|
||||||
|
|
||||||
config.headers = {
|
config.headers = {
|
||||||
...config.headers,
|
...config.headers,
|
||||||
Authorization: localStorage.getItem('Authorization') || '',
|
Authorization: localStorage.getItem('Authorization') || '',
|
||||||
@ -27,13 +35,19 @@ instance.interceptors.response.use(
|
|||||||
const { data } = response;
|
const { data } = response;
|
||||||
const { code } = data;
|
const { code } = data;
|
||||||
|
|
||||||
if (code) {
|
if (code !== 200) {
|
||||||
notification.error({
|
notification.error({
|
||||||
message: data.message,
|
message: data.message,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
const timestamp = getFormattedDate()
|
||||||
|
|
||||||
|
// let res = JSON.parse(decryptAESECB(data.data, timestamp))
|
||||||
|
// return res;
|
||||||
|
// console.log('resdsa', data);
|
||||||
|
|
||||||
|
return data
|
||||||
},
|
},
|
||||||
//状态码不为2xx的时候执行
|
//状态码不为2xx的时候执行
|
||||||
(error) => {
|
(error) => {
|
||||||
@ -72,4 +86,80 @@ instance.interceptors.response.use(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// 加密
|
||||||
|
const encryptAESECB = (data: string, key: string) => {
|
||||||
|
// const cipher = CryptoJS.createCipheriv('aes-128-ecb', key, null); // ECB 模式不需要 IV
|
||||||
|
const newKey = CryptoJS.enc.Utf8.parse(key); // 密钥必须是 16 字节
|
||||||
|
const cipher = CryptoJS.AES.encrypt(data, newKey, {
|
||||||
|
mode: CryptoJS.mode.ECB,
|
||||||
|
padding: CryptoJS.pad.Pkcs7
|
||||||
|
});
|
||||||
|
let encrypted = cipher.ciphertext.toString(CryptoJS.enc.Hex);
|
||||||
|
// let encrypted = cipher.update(data, 'utf8', 'hex');
|
||||||
|
// encrypted += cipher.final('hex');
|
||||||
|
return encrypted;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解密
|
||||||
|
const decryptAESECB = (data: string, key: string) => {
|
||||||
|
// const decipher = CryptoJS.createDecipheriv('aes-128-ecb', key, null);
|
||||||
|
// let decrypted = decipher.update(data, 'hex', 'utf8');
|
||||||
|
// decrypted += decipher.final('utf8');
|
||||||
|
const newKey = CryptoJS.enc.Utf8.parse(key);
|
||||||
|
|
||||||
|
const encryptedData = CryptoJS.enc.Hex.parse(data);
|
||||||
|
|
||||||
|
// 解密操作
|
||||||
|
const decrypted = CryptoJS.AES.decrypt({ ciphertext: encryptedData }, newKey, {
|
||||||
|
mode: CryptoJS.mode.ECB, // ECB 模式
|
||||||
|
padding: CryptoJS.pad.Pkcs7 // PKCS7 填充方式
|
||||||
|
});
|
||||||
|
// 将解密后的结果转为 UTF-8 字符串
|
||||||
|
const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
|
||||||
|
return decryptedText;
|
||||||
|
}
|
||||||
|
|
||||||
|
// md5 签名
|
||||||
|
const md5 = (key: string, data: string, timestamp: string) => {
|
||||||
|
const text = "s" + key + data + timestamp;
|
||||||
|
return CryptoJS.MD5(text).toString(CryptoJS.enc.Hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成签名戳
|
||||||
|
const getFormattedDate = () => {
|
||||||
|
const date = new Date();
|
||||||
|
const year = date.getFullYear(); // 获取年份 (yyyy)
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份 (MM)
|
||||||
|
const day = String(date.getDate()).padStart(2, '0'); // 获取日期 (dd)
|
||||||
|
const hours = String(date.getHours()).padStart(2, '0'); // 获取小时 (HH)
|
||||||
|
return `es0${year}${month}${day}${hours}0es`; // 拼接成 yyyyMMddHH 格式
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加密方法
|
||||||
|
const preprocessData = (data: string) => {
|
||||||
|
console.log('data', data);
|
||||||
|
// YYYYMMDD
|
||||||
|
let timestamp = getFormattedDate()
|
||||||
|
console.log('timestamp', timestamp);
|
||||||
|
// 秒为单位的时间戳
|
||||||
|
let timeSecond = parseInt((new Date().getTime() / 1000).toString())
|
||||||
|
console.log('timeSecond', timeSecond);
|
||||||
|
// 数据的加密
|
||||||
|
let encryptionData = encryptAESECB(data, timestamp)
|
||||||
|
console.log('encryptionData', encryptionData);
|
||||||
|
// md5签名方法
|
||||||
|
let md5Data = md5(timestamp, encryptionData, timestamp)
|
||||||
|
console.log('md5Data', md5Data);
|
||||||
|
|
||||||
|
let res = {
|
||||||
|
data: encryptionData,
|
||||||
|
timestamp: timeSecond,
|
||||||
|
sign: md5Data
|
||||||
|
}
|
||||||
|
console.log('res', res);
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
export default instance;
|
export default instance;
|
||||||
|
|||||||
@ -4630,6 +4630,11 @@ crypto-browserify@^3.11.0:
|
|||||||
randombytes "^2.1.0"
|
randombytes "^2.1.0"
|
||||||
randomfill "^1.0.4"
|
randomfill "^1.0.4"
|
||||||
|
|
||||||
|
crypto-js@^4.2.0:
|
||||||
|
version "4.2.0"
|
||||||
|
resolved "https://registry.npmmirror.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631"
|
||||||
|
integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==
|
||||||
|
|
||||||
css-blank-pseudo@^3.0.3:
|
css-blank-pseudo@^3.0.3:
|
||||||
version "3.0.3"
|
version "3.0.3"
|
||||||
resolved "https://registry.npmmirror.com/css-blank-pseudo/-/css-blank-pseudo-3.0.3.tgz#36523b01c12a25d812df343a32c322d2a2324561"
|
resolved "https://registry.npmmirror.com/css-blank-pseudo/-/css-blank-pseudo-3.0.3.tgz#36523b01c12a25d812df343a32c322d2a2324561"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user