12-23-上传master

This commit is contained in:
xingsy
2020-12-23 11:14:35 +08:00
parent 9769f83bc8
commit b42e0c1ddd
553 changed files with 56506 additions and 0 deletions

19
src/utils/Authorized.ts Normal file
View File

@ -0,0 +1,19 @@
import RenderAuthorize from '@/components/Authorized';
import { getAuthority } from './authority';
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable import/no-mutable-exports */
let Authorized = RenderAuthorize(getAuthority());
// Reload the rights component
const reloadAuthorized = (): void => {
Authorized = RenderAuthorize(getAuthority());
};
/**
* hard code
* block need it。
*/
window.reloadAuthorized = reloadAuthorized;
export { reloadAuthorized };
export default Authorized;

48
src/utils/CommonUtils.ts Normal file
View File

@ -0,0 +1,48 @@
/*
* @Author: liqiang
* @Date: 2020-11-24 15:26:54
* @LastEditTime: 2020-12-09 14:13:30
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \ebtp-cloud-frontend\src\utils\CommonUtils.ts
*/
/**
* 判断是否等于空
* @param value
*/
export function isEmpty(value: any) {
return value === null || value === void 0 || value === '';
}
/**
* 判断不等于空
* @param value
*/
export function isNotEmpty(value: any) {
return value !== null && value !== void 0 && value !== '';
}
/**
* proTable下拉选格式转换
* @param data 字典数据
*/
export function proTableValueEnum(data: any) {
let json = {};
if(isEmpty(data)){
return json;
}
for (const item of data) {
json[item.code] = { text: item.dicName };
}
return json;
}
/**
* 获取url路径信息
* @param name
*/
export function getURLInformation(name: string) {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
let r = window.location.search.substr(1).match(reg);
return r !== null ? unescape(r[2]) : null;
}

45
src/utils/DateUtils.ts Normal file
View File

@ -0,0 +1,45 @@
/*
* @Author: liqiang
* @Date: 2020-12-02 14:25:23
* @LastEditTime: 2020-12-07 14:59:14
* @LastEditors: Please set LastEditors
* @Description: 日期工具类
* @FilePath: \ebtp-cloud-frontend\src\utils\DateUtils.ts
*/
import moment from "moment";
import { isEmpty } from "./CommonUtils";
/**
* 日期时间格式
*/
export const dateTimeFormatter = 'yyyy-MM-DD HH:mm:ss';
/**
* 用于保存 日期格式化
* @param date
*/
export function saveDateTimeFormatter(date: any) {
if (isEmpty(date)) {
return date;
}
return date.format(dateTimeFormatter);
}
/**
* 用于回显 日期格式化
* @param date
*/
export function echoDateTimeFormatter(date: any) {
if (isEmpty(date)) {
return date;
}
return moment(date, dateTimeFormatter);
}
/**
* 判断当前时间是否超过指定时间
*/
export function nowExceedSpecifiedTime(specifiedTime: string) {
let now = new Date(),
specified = new Date(specifiedTime);
return now.getTime() > specified.getTime();
}

View File

@ -0,0 +1,11 @@
/*
* @Author: liqiang
* @Date: 2020-12-14 10:13:59
* @LastEditTime: 2020-12-16 11:36:38
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \ebtp-cloud-frontend\src\utils\DownloadUtils.ts
*/
export const downloadAttachmentPath = 'http://192.168.1.103:8760/ebtp-mall-attachment/v1/download/';

31
src/utils/InquiryBox.tsx Normal file
View File

@ -0,0 +1,31 @@
import { Modal } from 'antd';
import React from 'react';
interface InquiryBoxItem {
visible: boolean,
message: string,
data: any,
setVisible: (value: boolean) => void,
onOk: (data: any) => void
}
/**
* 询问框
* @param props
*/
const InquiryBox: React.FC<InquiryBoxItem> = (props) => {
const { visible, message, data, setVisible, onOk } = props;
return (
<>
<Modal
width={300}
centered
visible={visible}
onCancel={() => setVisible(false)}
onOk={() => onOk(data)}
>
{message}
</Modal>
</>
)
}
export default InquiryBox;

51
src/utils/MessageUtils.ts Normal file
View File

@ -0,0 +1,51 @@
import { message } from "antd";
import { isNotEmpty } from "./CommonUtils";
/*
* @Author: liqiang
* @Date: 2020-11-30 10:57:11
* @LastEditTime: 2020-12-14 14:50:42
* @LastEditors: Please set LastEditors
* @Description: 消息提示
* @FilePath: \ebtp-cloud-frontend\src\utils\MessageUtils.ts
*/
/**
* 保存修改提示
* @param res
*/
export function saveMessage(res: any) {
if (isNotEmpty(res) && res.data) {
message.success('操作成功!');
return true;
} else {
message.error('操作失败!');
return false;
}
}
/**
* 删除提示
* @param res
*/
export function deleteMessage(res: any) {
if (isNotEmpty(res) && res.data) {
message.success('删除成功!');
return true;
} else {
message.error('操作失败!');
return false;
}
}
/**
* 通用消息
* @param res
*/
export function commonMessage(res:any){
if (isNotEmpty(res) && res.data) {
message.success('操作成功!');
return true;
} else {
message.error('操作失败!');
return false;
}
}

37
src/utils/NumberUtils.ts Normal file
View File

@ -0,0 +1,37 @@
/*
* @Author: liqiang
* @Date: 2020-11-27 16:12:36
* @LastEditTime: 2020-11-27 16:21:29
* @LastEditors: Please set LastEditors
* @Description: 数字工具类
* @FilePath: \ebtp-cloud-frontend\src\utils\NumberUtils.ts
*/
/**
* 金额正则
*/
const amountReplace = /(\d)(?=(\d{3})+(?!\d))/g;
function getZero(num: number) {
let number = '';
for (let i = 0; i < num; i++) {
number += '0';
}
return number;
}
/**
* 数字转换金额格式
* @param money 数字
* @param retain 小数点后保留几位
*/
export function digitalConversionAmount(money: string, retain: number) {
let zero = getZero(retain);
if (money.indexOf('.') === -1) {
money = money.replace(amountReplace, '$1,') + '.' + zero;
} else {
let division = money.split('.');
money = division[0].replace(amountReplace, '$1,');
money = money + '.' + (division[1] + zero).substr(0, retain);
}
return money;
};

54
src/utils/PageUtils.ts Normal file
View File

@ -0,0 +1,54 @@
/*
* @Author: liqiang
* @Date: 2020-11-21 12:29:53
* @LastEditTime: 2020-12-14 17:13:46
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \ebtp-cloud-frontend\src\utils\PageUtils.ts
*/
import request from '@/utils/request';
import { RequestData } from '@ant-design/pro-table';
function requestData(data:any, success:boolean, total:number) {
return {
data: data,
success: success,
total: total,
}
}
function setBasePageRequest(params:any) {
return {
...params,
basePageRequest: {
"pageNo": params.current,
"pageSize": params.pageSize
}
};
}
/**
* 用于ProTable
* @param api 后台api路径 (/api/...)
* @param method 请求方法(get, post...)
* @param params 对象数据 ({})
*/
export function queryingPagingData(api: string, method: string, params: any) {
return new Promise<RequestData<any>>((resolve, reject) => {
let parameters = setBasePageRequest(params);
get(api, method, parameters).then(res => {
if (res.code === 200) {
resolve(requestData(res.data.records, res.success, res.data.total));
}else{
reject(requestData([], false, 0))
}
})
});
}
export async function get(api: string, method: string, params?: any) {
return request(api, {
method: method,
data: params,
});
}

32
src/utils/authority.ts Normal file
View File

@ -0,0 +1,32 @@
import { reloadAuthorized } from './Authorized';
// use localStorage to store the authority info, which might be sent from server in actual project.
export function getAuthority(str?: string): string | string[] {
const authorityString =
typeof str === 'undefined' && localStorage ? localStorage.getItem('antd-pro-authority') : str;
// authorityString could be admin, "admin", ["admin"]
let authority;
try {
if (authorityString) {
authority = JSON.parse(authorityString);
}
} catch (e) {
authority = authorityString;
}
if (typeof authority === 'string') {
return [authority];
}
// preview.pro.ant.design only do not use in your production.
// preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
if (!authority && ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
return ['admin'];
}
return authority;
}
export function setAuthority(authority: string | string[]): void {
const proAuthority = typeof authority === 'string' ? [authority] : authority;
localStorage.setItem('antd-pro-authority', JSON.stringify(proAuthority));
// auto reload
reloadAuthorized();
}

7
src/utils/checkEmpty.ts Normal file
View File

@ -0,0 +1,7 @@
export default function checkUn (val: any) {
if (val == undefined || val == null || val == "" || val == [] || JSON.stringify(val) == "{}" || val == "null") {
return false;
} else {
return true;
}
}

121
src/utils/lq.style.less Normal file
View File

@ -0,0 +1,121 @@
/*
* @Author: liqiang
* @Date: 2020-11-09 18:02:11
* @LastEditTime: 2020-12-07 16:19:49
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \ebtp-cloud-frontend\src\utils\lq.style.less
*/
@import '~antd/es/style/themes/default.less';
@themeColors:#cb0000;
.background{
background-color: #fff;
}
.p10{
padding: 10px;
background-color: #fff;
}
.name {
color: #333;
padding: 0 15px 10px 0;
margin: 0;
font-weight: 700;
font-size: 16px;
}
.file{
color: @themeColors;
border-left: 5px solid @themeColors;
line-height: 18px;
padding-left: 7px;
margin: 3px 0;
}
.message{
margin-top: 12px;
border-top: 1px solid #ccc;
border-bottom: 1px solid @themeColors;
margin-bottom: 0;
.text{
background-color:@themeColors;
padding: 3px 8px;
color: #fff;
display: inline-block;
margin-top: 8px;
}
}
.table-mess{
p{
width: 33.33%;
display: inline-block;
}
}
.tr{
text-align: right;
}
.red{
color:@themeColors;
}
.f12{
font-size: 13px;
}
.b-red{
background-color: @themeColors !important;
border-color: @themeColors !important;
margin-left: 20px;
color: #fff;
}
.titBlock{
position: relative;
margin: 5px 10px;
height: 40px;
line-height: 40px;
border-bottom: 1px solid #ddd;
}
.titBlockI{
float: left;
margin: 10px 0 0 5px;
width: 4px;
height: 18px;
background: @themeColors;
}
.titBlockH4{
padding-left: 20px;
font-size: 16px;
color: @themeColors;
}
.spaceBetween{
margin: 0px 8px;
}
.ml20{
margin-left: 15px;
}
.t_left{
text-align:left;
}
.t_right{
text-align:right;
}
.f_left{
float:left;
}
.f_right{
float:right;
}
.textAlignCenter{
text-align:center;
}
.tit_block_i{
position: relative;
margin: 8px 0px;
height: 40px;
line-height: 40px;
border-bottom: 1px solid #ddd;
}
.tit_block_h4{
font-size: 16px;
color: @themeColors;
}
.input-border{
border: 1px solid #d9d9d9;
}

56
src/utils/request.ts Normal file
View File

@ -0,0 +1,56 @@
/**
* request 网络请求工具
* 更详细的 api 文档: https://github.com/umijs/umi-request
*/
import { extend } from 'umi-request';
import { notification } from 'antd';
const codeMessage = {
200: '服务器成功返回请求的数据。',
201: '新建或修改数据成功。',
202: '一个请求已经进入后台排队(异步任务)。',
204: '删除数据成功。',
400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
401: '用户没有权限(令牌、用户名、密码错误)。',
403: '用户得到授权,但是访问是被禁止的。',
404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
406: '请求的格式不可得。',
410: '请求的资源被永久删除,且不会再得到的。',
422: '当创建一个对象时,发生一个验证错误。',
500: '服务器发生错误,请检查服务器。',
502: '网关错误。',
503: '服务不可用,服务器暂时过载或维护。',
504: '网关超时。',
};
/**
* 异常处理程序
*/
const errorHandler = (error: { response: Response }): Response => {
const { response } = error;
if (response && response.status) {
const errorText = codeMessage[response.status] || response.statusText;
const { status, url } = response;
notification.error({
message: `请求错误 ${status}: ${url}`,
description: errorText,
});
} else if (!response) {
notification.error({
description: '您的网络发生异常,无法连接服务器',
message: '网络异常',
});
}
return response;
};
/**
* 配置request请求时的默认参数
*/
const request = extend({
errorHandler, // 默认错误处理
credentials: 'include', // 默认请求是否带上cookie
});
export default request;

16
src/utils/utils.less Normal file
View File

@ -0,0 +1,16 @@
// mixins for clearfix
// ------------------------
.clearfix() {
zoom: 1;
&::before,
&::after {
display: table;
content: ' ';
}
&::after {
clear: both;
height: 0;
font-size: 0;
visibility: hidden;
}
}

37
src/utils/utils.test.ts Normal file
View File

@ -0,0 +1,37 @@
import { isUrl } from './utils';
describe('isUrl tests', (): void => {
it('should return false for invalid and corner case inputs', (): void => {
expect(isUrl([] as any)).toBeFalsy();
expect(isUrl({} as any)).toBeFalsy();
expect(isUrl(false as any)).toBeFalsy();
expect(isUrl(true as any)).toBeFalsy();
expect(isUrl(NaN as any)).toBeFalsy();
expect(isUrl(null as any)).toBeFalsy();
expect(isUrl(undefined as any)).toBeFalsy();
expect(isUrl('')).toBeFalsy();
});
it('should return false for invalid URLs', (): void => {
expect(isUrl('foo')).toBeFalsy();
expect(isUrl('bar')).toBeFalsy();
expect(isUrl('bar/test')).toBeFalsy();
expect(isUrl('http:/example.com/')).toBeFalsy();
expect(isUrl('ttp://example.com/')).toBeFalsy();
});
it('should return true for valid URLs', (): void => {
expect(isUrl('http://example.com/')).toBeTruthy();
expect(isUrl('https://example.com/')).toBeTruthy();
expect(isUrl('http://example.com/test/123')).toBeTruthy();
expect(isUrl('https://example.com/test/123')).toBeTruthy();
expect(isUrl('http://example.com/test/123?foo=bar')).toBeTruthy();
expect(isUrl('https://example.com/test/123?foo=bar')).toBeTruthy();
expect(isUrl('http://www.example.com/')).toBeTruthy();
expect(isUrl('https://www.example.com/')).toBeTruthy();
expect(isUrl('http://www.example.com/test/123')).toBeTruthy();
expect(isUrl('https://www.example.com/test/123')).toBeTruthy();
expect(isUrl('http://www.example.com/test/123?foo=bar')).toBeTruthy();
expect(isUrl('https://www.example.com/test/123?foo=bar')).toBeTruthy();
});
});

24
src/utils/utils.ts Normal file
View File

@ -0,0 +1,24 @@
import { parse } from 'querystring';
/* eslint no-useless-escape:0 import/prefer-default-export:0 */
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
export const isUrl = (path: string): boolean => reg.test(path);
export const isAntDesignPro = (): boolean => {
if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
return true;
}
return window.location.hostname === 'preview.pro.ant.design';
};
// 给官方演示站点用,用于关闭真实开发环境不需要使用的特性
export const isAntDesignProOrDev = (): boolean => {
const { NODE_ENV } = process.env;
if (NODE_ENV === 'development') {
return true;
}
return isAntDesignPro();
};
export const getPageQuery = () => parse(window.location.href.split('?')[1]);