Browse Source

use @umijs/fabric@2.5.0

pull/7994/head
chenshuai2144 5 years ago
parent
commit
3777bfa2fc
  1. 4
      package.json
  2. 4
      src/components/Authorized/CheckPermissions.tsx
  3. 27
      src/components/Authorized/Secured.tsx
  4. 3
      src/components/Authorized/renderAuthorize.ts
  5. 12
      src/layouts/BasicLayout.tsx
  6. 17
      src/pages/TableList/index.tsx
  7. 12
      src/service-worker.js
  8. 5
      src/utils/Authorized.ts
  9. 13
      src/utils/request.ts

4
package.json

@ -83,7 +83,7 @@
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-helmet": "^6.1.0",
"@umijs/fabric": "^2.3.0",
"@umijs/fabric": "^2.5.1",
"@umijs/plugin-blocks": "^2.0.5",
"@umijs/plugin-esbuild": "^1.0.1",
"@umijs/preset-ant-design-pro": "^1.2.0",
@ -102,8 +102,6 @@
"lint-staged": "^10.0.0",
"mockjs": "^1.0.1-beta3",
"prettier": "^2.0.1",
"prettier-plugin-style-order": "^0.2.2",
"pro-download": "1.0.1",
"puppeteer-core": "^5.0.0",
"stylelint": "^13.0.0",
"typescript": "^4.0.3"

4
src/components/Authorized/CheckPermissions.tsx

@ -11,8 +11,8 @@ export type IAuthorityType =
| ((currentAuthority: string | string[]) => IAuthorityType);
/**
*
* Common check permissions method
* Common check permissions method
*
* @param { | Permission judgment } authority
* @param { | Your permission description } currentAuthority
* @param { | Passing components } target

27
src/components/Authorized/Secured.tsx

@ -1,10 +1,7 @@
import React from 'react';
import CheckPermissions from './CheckPermissions';
/**
* 访
* default is "NULL"
*/
/** 默认不能访问任何页面 default is "NULL" */
const Exception403 = () => 403;
export const isComponentClass = (component: React.ComponentClass | React.ReactNode): boolean => {
@ -30,25 +27,19 @@ const checkIsInstantiation = (target: React.ComponentClass | React.ReactNode) =>
};
/**
* 访 view
* authority string, () => boolean | Promise
* e.g. 'user' user 访
* e.g. 'user,admin' user admin 访
* e.g. ()=>boolean true能访问,false不能访问
* e.g. Promise then 访 catch不能访问
* e.g. authority support incoming string, () => boolean | Promise
* e.g. 'user' only user user can access
* e.g. 'user, admin' user and admin can access
* e.g. () => boolean true to be able to visit, return false can not be accessed
* e.g. Promise then can not access the visit to catch
* 访 view authority string, () => boolean | Promise e.g. 'user' user 访
* e.g. 'user,admin' user admin 访 e.g. ()=>boolean true能访问,false不能访问 e.g. Promise then 访
* catch不能访问 e.g. authority support incoming string, () => boolean | Promise e.g. 'user' only user
* user can access e.g. 'user, admin' user and admin can access e.g. () => boolean true to be able
* to visit, return false can not be accessed e.g. Promise then can not access the visit to catch
*
* @param {string | function | Promise} authority
* @param {ReactNode} error
*/
const authorize = (authority: string, error?: React.ReactNode) => {
/**
* conversion into a class
* staticContext造成报错
* String parameters can cause staticContext not found error
* Conversion into a class staticContext造成报错 String parameters can cause staticContext
* not found error
*/
let classError: boolean | React.FunctionComponent = false;
if (error) {

3
src/components/Authorized/renderAuthorize.ts

@ -4,7 +4,8 @@ let CURRENT: string | string[] = 'NULL';
type CurrentAuthorityType = string | string[] | (() => typeof CURRENT);
/**
* use authority or getAuthority
* Use authority or getAuthority
*
* @param {string|()=>String} currentAuthority
*/
const renderAuthorize = <T>(Authorized: T): ((currentAuthority: CurrentAuthorityType) => T) => (

12
src/layouts/BasicLayout.tsx

@ -1,7 +1,7 @@
/**
* Ant Design Pro v4 use `@ant-design/pro-layout` to handle Layout.
* You can view component api by:
* https://github.com/ant-design/ant-design-pro-layout
*
* @see You can view component api by: https://github.com/ant-design/ant-design-pro-layout
*/
import type {
MenuDataItem,
@ -43,9 +43,7 @@ export type BasicLayoutProps = {
export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & {
breadcrumbNameMap: Record<string, MenuDataItem>;
};
/**
* use Authorized check all menu item
*/
/** Use Authorized check all menu item */
const menuDataRender = (menuList: MenuDataItem[]): MenuDataItem[] =>
menuList.map((item) => {
@ -101,9 +99,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
});
}
}, []);
/**
* init variables
*/
/** Init variables */
const handleMenuCollapse = (payload: boolean): void => {
if (dispatch) {

17
src/pages/TableList/index.tsx

@ -15,6 +15,7 @@ import { queryRule, updateRule, addRule, removeRule } from './service';
/**
*
*
* @param fields
*/
const handleAdd = async (fields: TableListItem) => {
@ -33,6 +34,7 @@ const handleAdd = async (fields: TableListItem) => {
/**
*
*
* @param fields
*/
const handleUpdate = async (fields: FormValueType) => {
@ -55,7 +57,8 @@ const handleUpdate = async (fields: FormValueType) => {
};
/**
*
*
*
* @param selectedRows
*/
const handleRemove = async (selectedRows: TableListItem[]) => {
@ -76,13 +79,9 @@ const handleRemove = async (selectedRows: TableListItem[]) => {
};
const TableList: React.FC = () => {
/**
*
*/
/** 新建窗口的弹窗 */
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
/**
*
*/
/** 分布更新窗口的弹窗 */
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [showDetail, setShowDetail] = useState<boolean>(false);
@ -91,9 +90,7 @@ const TableList: React.FC = () => {
const [currentRow, setCurrentRow] = useState<TableListItem>();
const [selectedRowsState, setSelectedRows] = useState<TableListItem[]>([]);
/**
*
*/
/** 国际化配置 */
const intl = useIntl();
const columns: ProColumns<TableListItem>[] = [

12
src/service-worker.js

@ -29,14 +29,10 @@ workbox.routing.registerNavigationRoute('/index.html');
* https://developers.google.com/web/tools/workbox/reference-docs/latest/workbox.strategies
*/
/**
* Handle API requests
*/
/** Handle API requests */
workbox.routing.registerRoute(/\/api\//, workbox.strategies.networkFirst());
/**
* Handle third party requests
*/
/** Handle third party requests */
workbox.routing.registerRoute(
/^https:\/\/gw\.alipayobjects\.com\//,
workbox.strategies.networkFirst(),
@ -47,9 +43,7 @@ workbox.routing.registerRoute(
);
workbox.routing.registerRoute(/\/color.less/, workbox.strategies.networkFirst());
/**
* Response to client after skipping waiting with MessageChannel
*/
/** Response to client after skipping waiting with MessageChannel */
addEventListener('message', (event) => {
const replyPort = event.ports[0];
const message = event.data;

5
src/utils/Authorized.ts

@ -9,10 +9,7 @@ const reloadAuthorized = (): void => {
Authorized = RenderAuthorize(getAuthority());
};
/**
* hard code
* block need it
*/
/** Hard code block need it。 */
window.reloadAuthorized = reloadAuthorized;
export { reloadAuthorized };

13
src/utils/request.ts

@ -1,7 +1,4 @@
/**
* request
* api : https://github.com/umijs/umi-request
*/
/** Request 网络请求工具 更详细的 api 文档: https://github.com/umijs/umi-request */
import { extend } from 'umi-request';
import { notification } from 'antd';
@ -23,9 +20,7 @@ const codeMessage = {
504: '网关超时。',
};
/**
*
*/
/** 异常处理程序 */
const errorHandler = (error: { response: Response }): Response => {
const { response } = error;
if (response && response.status) {
@ -45,9 +40,7 @@ const errorHandler = (error: { response: Response }): Response => {
return response;
};
/**
* request请求时的默认参数
*/
/** 配置request请求时的默认参数 */
const request = extend({
errorHandler, // 默认错误处理
credentials: 'include', // 默认请求是否带上cookie

Loading…
Cancel
Save