diff --git a/docs/en/develop/3-1-BaseList-introduction.md b/docs/en/develop/3-1-BaseList-introduction.md index d3379977..f8fca269 100644 --- a/docs/en/develop/3-1-BaseList-introduction.md +++ b/docs/en/develop/3-1-BaseList-introduction.md @@ -175,7 +175,7 @@ English | [Chinese](../../zh/develop/3-1-BaseList-introduction.md) { title: t('ID/Name'), dataIndex: 'name', - linkPrefix: `/compute/${this.getUrl('image')}/detail`, + routeName: this.getRouteName('imageDetail'), }, { title: t('Project ID/Name'), @@ -526,7 +526,7 @@ English | [Chinese](../../zh/develop/3-1-BaseList-introduction.md) - Is the current page a "management platform" page - `hasAdminRole` - Whether the logged-in user role has an administrator role -- `getUrl` +- `getRoutePath` - Function to generate page URL - For example, it is necessary to provide a jump function to the associated resources of the list page. Using this function, you can jump to the corresponding address of the console in the console, and jump to the corresponding address of the management platform in the management platform. - `params` diff --git a/docs/en/develop/3-2-BaseTabList-introduction.md b/docs/en/develop/3-2-BaseTabList-introduction.md index 39f87b18..ed51347c 100644 --- a/docs/en/develop/3-2-BaseTabList-introduction.md +++ b/docs/en/develop/3-2-BaseTabList-introduction.md @@ -114,7 +114,7 @@ English | [Chinese](../../zh/develop/3-2-BaseTabList-introduction.md) - Is the current page a "management platform" page - `hasAdminRole` - Whether the logged-in user role has an administrator role -- `getUrl` +- `getRoutePath` - Function to generate page URL - For example, it is necessary to provide a jump function for the associated resources of the list page. Using this function, you can jump to the corresponding address of the console in the console, and jump to the corresponding address of the management platform in the management platform. diff --git a/docs/en/develop/3-3-BaseDetail-introduction.md b/docs/en/develop/3-3-BaseDetail-introduction.md index cb640fb4..bad891ba 100644 --- a/docs/en/develop/3-3-BaseDetail-introduction.md +++ b/docs/en/develop/3-3-BaseDetail-introduction.md @@ -72,7 +72,7 @@ English | [Chinese](../../zh/develop/3-3-BaseDetail-introduction.md) ```javascript get listUrl() { - return this.getUrl('/storage/volume'); + return this.getRoutePath('volume'); } ``` @@ -241,7 +241,7 @@ English | [Chinese](../../zh/develop/3-3-BaseDetail-introduction.md) - `id` in routing information - `isAdminPage` - Is the current page a "management platform" page -- `getUrl` +- `getRoutePath` - Function to generate page URL - For example, it is necessary to provide a jump function to the associated resource. Using this function, you can jump to the corresponding address of the console in the console, and jump to the corresponding address of the management platform in the management platform. - `routing` diff --git a/docs/en/develop/3-4-BaseDetailInfo-introduction.md b/docs/en/develop/3-4-BaseDetailInfo-introduction.md index db0cd1bf..642e75b4 100644 --- a/docs/en/develop/3-4-BaseDetailInfo-introduction.md +++ b/docs/en/develop/3-4-BaseDetailInfo-introduction.md @@ -131,7 +131,7 @@ English | [Chinese](../../zh/develop/3-4-BaseDetailInfo-introduction.md) - `id` in routing information - `isAdminPage` - Is the current page a "management platform" page -- `getUrl` +- `getRoutePath` - Function to generate page URL - For example, it is necessary to provide a jump function to the associated resource. Using this function, you can jump to the corresponding address of the console in the console, and jump to the corresponding address of the management platform in the management platform. - `routing` diff --git a/docs/en/develop/3-6-FormAction-introduction.md b/docs/en/develop/3-6-FormAction-introduction.md index 8e8e63d5..54c283d0 100644 --- a/docs/en/develop/3-6-FormAction-introduction.md +++ b/docs/en/develop/3-6-FormAction-introduction.md @@ -147,7 +147,7 @@ English | [Chinese](../../zh/develop/3-6-FormAction-introduction.md) ```javascript get listUrl() { - return this.getUrl('/storage/volume'); + return this.getRoutePath('volume'); } ``` @@ -381,7 +381,7 @@ English | [Chinese](../../zh/develop/3-6-FormAction-introduction.md) - After the form is successfully validated, the updated form value - `isAdminPage` - Is the current page a "management platform" page -- `getUrl` +- `getRoutePath` - Function to generate page URL - For example, it is necessary to provide a jump function to the associated resource. Using this function, you can jump to the corresponding address of the console in the console, and jump to the corresponding address of the management platform in the management platform. diff --git a/docs/en/develop/3-9-StepAction-introduction.md b/docs/en/develop/3-9-StepAction-introduction.md index e0d18538..11954094 100644 --- a/docs/en/develop/3-9-StepAction-introduction.md +++ b/docs/en/develop/3-9-StepAction-introduction.md @@ -286,7 +286,7 @@ English | [简体中文](../../zh/develop/3-9-StepAction-introduction.md) - `isAdminPage` - Whether current page is a "management platform" page -- `getUrl` +- `getRoutePath` - Generate function of page URL - Such as: need to provide a ability of jump to the associated resource, use this function, you can jump to the corresponding address of the `console platform` in the `console platform`, and jump to the corresponding address of the `management platform` in the `management platform`. diff --git a/docs/zh/develop/3-1-BaseList-introduction.md b/docs/zh/develop/3-1-BaseList-introduction.md index 369cb3cc..d9525caf 100644 --- a/docs/zh/develop/3-1-BaseList-introduction.md +++ b/docs/zh/develop/3-1-BaseList-introduction.md @@ -175,7 +175,7 @@ { title: t('ID/Name'), dataIndex: 'name', - linkPrefix: `/compute/${this.getUrl('image')}/detail`, + routeName: this.getRouteName('imageDetail'), }, { title: t('Project ID/Name'), @@ -526,7 +526,7 @@ - 当前页面是否是“管理平台”的页面 - `hasAdminRole` - 登录的用户角色是否具有管理员角色 -- `getUrl` +- `getRoutePath` - 生成页面 Url 的函数 - 如:需要给列表页的关联资源提供跳转功能,使用该函数,可以在控制台跳转到控制台的相应地址,在管理平台跳转到管理平台的相应地址 - `params` diff --git a/docs/zh/develop/3-2-BaseTabList-introduction.md b/docs/zh/develop/3-2-BaseTabList-introduction.md index fa3a2924..14b28d7a 100644 --- a/docs/zh/develop/3-2-BaseTabList-introduction.md +++ b/docs/zh/develop/3-2-BaseTabList-introduction.md @@ -114,7 +114,7 @@ - 当前页面是否是“管理平台”的页面 - `hasAdminRole` - 登录的用户角色是否具有管理员角色 -- `getUrl` +- `getRoutePath` - 生成页面 Url 的函数 - 如:需要给列表页的关联资源提供跳转功能,使用该函数,可以在控制台跳转到控制台的相应地址,在管理平台跳转到管理平台的相应地址 diff --git a/docs/zh/develop/3-3-BaseDetail-introduction.md b/docs/zh/develop/3-3-BaseDetail-introduction.md index 04f7b7ea..15078bb8 100644 --- a/docs/zh/develop/3-3-BaseDetail-introduction.md +++ b/docs/zh/develop/3-3-BaseDetail-introduction.md @@ -72,7 +72,7 @@ ```javascript get listUrl() { - return this.getUrl('/storage/volume'); + return this.getRoutePath('volume'); } ``` @@ -241,7 +241,7 @@ - 路由信息中的`id` - `isAdminPage` - 当前页面是否是“管理平台”的页面 -- `getUrl` +- `getRoutePath` - 生成页面 Url 的函数 - 如:需要给关联资源提供跳转功能,使用该函数,可以在控制台跳转到控制台的相应地址,在管理平台跳转到管理平台的相应地址 - `routing` diff --git a/docs/zh/develop/3-4-BaseDetailInfo-introduction.md b/docs/zh/develop/3-4-BaseDetailInfo-introduction.md index 0f65e40f..d8454b37 100644 --- a/docs/zh/develop/3-4-BaseDetailInfo-introduction.md +++ b/docs/zh/develop/3-4-BaseDetailInfo-introduction.md @@ -131,7 +131,7 @@ - 路由信息中的`id` - `isAdminPage` - 当前页面是否是“管理平台”的页面 -- `getUrl` +- `getRoutePath` - 生成页面 Url 的函数 - 如:需要给关联资源提供跳转功能,使用该函数,可以在控制台跳转到控制台的相应地址,在管理平台跳转到管理平台的相应地址 - `routing` diff --git a/docs/zh/develop/3-6-FormAction-introduction.md b/docs/zh/develop/3-6-FormAction-introduction.md index 9f3aec80..594f221f 100644 --- a/docs/zh/develop/3-6-FormAction-introduction.md +++ b/docs/zh/develop/3-6-FormAction-introduction.md @@ -147,7 +147,7 @@ ```javascript get listUrl() { - return this.getUrl('/storage/volume'); + return this.getRoutePath('volume'); } ``` @@ -381,7 +381,7 @@ - 表单验证成功后,更新的表单值 - `isAdminPage` - 当前页面是否是“管理平台”的页面 -- `getUrl` +- `getRoutePath` - 生成页面 Url 的函数 - 如:需要给关联资源提供跳转功能,使用该函数,可以在控制台跳转到控制台的相应地址,在管理平台跳转到管理平台的相应地址 diff --git a/docs/zh/develop/3-9-StepAction-introduction.md b/docs/zh/develop/3-9-StepAction-introduction.md index 0925c59e..3292a1e0 100644 --- a/docs/zh/develop/3-9-StepAction-introduction.md +++ b/docs/zh/develop/3-9-StepAction-introduction.md @@ -282,7 +282,7 @@ - 表单验证成功后,更新的表单值 - `isAdminPage` - 当前页面是否是“管理平台”的页面 -- `getUrl` +- `getRoutePath` - 生成页面 Url 的函数 - 如:需要给关联资源提供跳转功能,使用该函数,可以在控制台跳转到控制台的相应地址,在管理平台跳转到管理平台的相应地址 diff --git a/src/components/Form/index.jsx b/src/components/Form/index.jsx index 1af0f841..c321c8d3 100644 --- a/src/components/Form/index.jsx +++ b/src/components/Form/index.jsx @@ -22,6 +22,7 @@ import { isAdminPage, firstUpperCase, unescapeHtml } from 'utils/index'; import { parse } from 'qs'; import FormItem from 'components/FormItem'; import { CancelToken } from 'axios'; +import { getPath, getLinkRender } from 'utils/route-map'; import styles from './index.less'; export default class BaseForm extends React.Component { @@ -137,6 +138,20 @@ export default class BaseForm extends React.Component { return this.isAdminPage ? `${path}${adminStr || '-admin'}` : path; } + getRouteName(routeName) { + return this.isAdminPage ? `${routeName}Admin` : routeName; + } + + getRoutePath(routeName, params = {}, query = {}) { + const realName = this.getRouteName(routeName); + return getPath({ key: realName, params, query }); + } + + getLinkRender(routeName, value, params = {}, query = {}) { + const realName = this.getRouteName(routeName); + return getLinkRender({ key: realName, params, query, value }); + } + get isStep() { return false; } diff --git a/src/components/FormItem/MemberAllocator/index.jsx b/src/components/FormItem/MemberAllocator/index.jsx index 0c2d3dfc..ccfa5c91 100644 --- a/src/components/FormItem/MemberAllocator/index.jsx +++ b/src/components/FormItem/MemberAllocator/index.jsx @@ -18,8 +18,8 @@ import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; import SelectTable from 'components/FormItem/SelectTable'; import { ipValidate } from 'utils/validate'; import { isAdminPage } from 'utils/index'; -import { Link } from 'react-router-dom'; import { Address4, Address6 } from 'ip-address'; +import { getLinkRender } from 'utils/route-map'; import Item from './Item'; const { isIPv4, isIpv6 } = ipValidate; @@ -34,9 +34,11 @@ const MemberAllocator = ({ componentProps, formItemProps }) => { onChange && onChange(data); }; - function getUrl(path, adminStr) { + function getLink(routerName, item) { const { pathname } = window.location; - return isAdminPage(pathname) ? `${path}${adminStr || '-admin'}` : path; + const key = isAdminPage(pathname) ? `${routerName}Admin` : routerName; + const { id } = item; + return getLinkRender({ key, params: { id }, value: id }); } let addOuter = () => {}; @@ -60,16 +62,7 @@ const MemberAllocator = ({ componentProps, formItemProps }) => { dataIndex: 'name', render: (n, record) => (