diff --git a/src/components/GlobalHeader/index.js b/src/components/GlobalHeader/index.js index d00469794..57c5b6cb9 100644 --- a/src/components/GlobalHeader/index.js +++ b/src/components/GlobalHeader/index.js @@ -35,6 +35,7 @@ import { getCurrentLocale, getIntlContent } from "../../utils/IntlUtils"; import { checkUserPassword } from "../../services/api"; import { emit } from "../../utils/emit"; import { resetAuthMenuCache } from "../../utils/AuthRoute"; +import { defaultNamespaceId } from "../_utils/utils"; const TranslationOutlinedSvg = () => ( { const { dispatch } = this.props; - const namespaceId = value?.key || "649330b6-c2d7-4edc-be8e-8a54df9eb385"; - window.sessionStorage.setItem("currentNamespaceId", namespaceId); + const namespaceId = value?.key || defaultNamespaceId; + dispatch({ + type: "global/saveCurrentNamespaceId", + payload: namespaceId, + }); + if (namespaceId !== defaultNamespaceId) { + message.warn(getIntlContent("SHENYU.NAMESPACE.ALERTNAMESPACEID.CHANGED")); + } dispatch({ type: "global/fetchPermission", payload: { + namespaceId, callback: () => { resetAuthMenuCache(); }, }, }); - dispatch({ - type: "global/saveCurrentNamespaceId", - payload: value.key, - }); - if (value.key !== "649330b6-c2d7-4edc-be8e-8a54df9eb385") { - message.warn(getIntlContent("SHENYU.NAMESPACE.ALERTNAMESPACEID.CHANGED")); - } }; importConfigClick = () => { diff --git a/src/components/_utils/utils.ts b/src/components/_utils/utils.ts index a8ac69d31..65cd4cffc 100644 --- a/src/components/_utils/utils.ts +++ b/src/components/_utils/utils.ts @@ -15,52 +15,55 @@ * limitations under the License. */ +// 默认 namespaceId +export const defaultNamespaceId = "649330b6-c2d7-4edc-be8e-8a54df9eb385"; + // 随机数字 export function randomNum(m: number, n: number) { - return Math.floor(Math.random() * (n - m + 1) + m); + return Math.floor(Math.random() * (n - m + 1) + m); } // 随机颜色 export function randomColor() { - return `rgb(${randomNum(0, 255)}, ${randomNum(0, 255)}, ${randomNum( - 0, - 255 - )})`; + return `rgb(${randomNum(0, 255)}, ${randomNum(0, 255)}, ${randomNum( + 0, + 255, + )})`; } export const originalCharacter = [ - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "a", - "b", - "c", - "d", - "e", - "f", - "g", - "h", - "i", - "j", - "k", - "l", - "m", - "n", - "p", - "q", - "r", - "s", - "t", - "u", - "v", - "w", - "x", - "y", - "z" + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "a", + "b", + "c", + "d", + "e", + "f", + "g", + "h", + "i", + "j", + "k", + "l", + "m", + "n", + "p", + "q", + "r", + "s", + "t", + "u", + "v", + "w", + "x", + "y", + "z", ]; diff --git a/src/models/global.js b/src/models/global.js index 64874d560..7ea50eb4e 100644 --- a/src/models/global.js +++ b/src/models/global.js @@ -25,6 +25,7 @@ import { getUserPermissionByToken, } from "../services/api"; import { getIntlContent } from "../utils/IntlUtils"; +import { defaultNamespaceId } from "../components/_utils/utils"; export default { namespace: "global", @@ -37,7 +38,7 @@ export default { permissions: {}, language: "", namespaces: [], - currentNamespaceId: "649330b6-c2d7-4edc-be8e-8a54df9eb385", + currentNamespaceId: defaultNamespaceId, }, effects: { @@ -57,9 +58,6 @@ export default { type: "saveNamespaces", payload: json.data, }); - const namespaceId = - json.data[0]?.namespaceId || "649330b6-c2d7-4edc-be8e-8a54df9eb385"; - window.sessionStorage.setItem("currentNamespaceId", namespaceId); } }, *fetchPlugins({ payload }, { call, put }) { @@ -92,11 +90,13 @@ export default { message.warn(json.message); } }, - *fetchPermission({ payload }, { call, put }) { + *fetchPermission({ payload }, { call, put, select }) { const { callback } = payload; let permissions = { menu: [], button: [] }; const token = window.sessionStorage.getItem("token"); - const namespaceId = window.sessionStorage.getItem("currentNamespaceId"); + const namespaceId = yield select( + ({ global }) => global.currentNamespaceId, + ); if (namespaceId) { const params = { token, namespaceId }; const json = yield call(getUserPermissionByToken, params); diff --git a/src/routes/System/Namespace/index.js b/src/routes/System/Namespace/index.js index 90973bf82..3ffc8af82 100644 --- a/src/routes/System/Namespace/index.js +++ b/src/routes/System/Namespace/index.js @@ -23,6 +23,7 @@ import AddModal from "./AddModal"; import { getCurrentLocale, getIntlContent } from "../../../utils/IntlUtils"; import AuthButton from "../../../utils/AuthButton"; import { refreshAuthMenus } from "../../../utils/AuthRoute"; +import { defaultNamespaceId } from "../../../components/_utils/utils"; @connect(({ namespace, resource, loading, global }) => ({ namespace, @@ -201,7 +202,7 @@ export default class Namespace extends Component { if (deletedCurrentNamespace) { dispatch({ type: "global/saveCurrentNamespaceId", - payload: "649330b6-c2d7-4edc-be8e-8a54df9eb385", + payload: defaultNamespaceId, }); } dispatch({ type: "global/fetchNamespaces" }); @@ -294,8 +295,7 @@ export default class Namespace extends Component { width: 160, fixed: "right", render: (text, record) => { - return record.namespaceId === - "649330b6-c2d7-4edc-be8e-8a54df9eb385" ? ( + return record.namespaceId === defaultNamespaceId ? ( "" ) : (
@@ -357,7 +357,7 @@ export default class Namespace extends Component { selectedRowKeys, onChange: this.onSelectChange, getCheckboxProps: (record) => ({ - disabled: record.namespaceId === "649330b6-c2d7-4edc-be8e-8a54df9eb385", + disabled: record.namespaceId === defaultNamespaceId, }), }; const flatList = (map, list) => { diff --git a/src/routes/System/User/DataPermModal.js b/src/routes/System/User/DataPermModal.js index b03b6fbbc..827da4689 100644 --- a/src/routes/System/User/DataPermModal.js +++ b/src/routes/System/User/DataPermModal.js @@ -33,6 +33,7 @@ import { import { connect } from "dva"; import { getIntlContent } from "../../../utils/IntlUtils"; import { titleCase } from "../../../utils/utils"; +import { defaultNamespaceId } from "../../../components/_utils/utils"; const { TreeNode } = Tree; const { Search } = Input; @@ -57,7 +58,7 @@ export default class DataPermModal extends Component { pageSize: 12, ruleListMap: {}, searchValue: "", - currentNamespaceId: "649330b6-c2d7-4edc-be8e-8a54df9eb385", + currentNamespaceId: defaultNamespaceId, selectorExpandedRowKeys: [], }; } diff --git a/src/services/api.js b/src/services/api.js index b3723708f..bc01a06d3 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -814,16 +814,6 @@ export async function getUserPermissionByToken(params) { ); } -// get userPermission -export async function getUserPermission(params) { - return request( - `${baseUrl}/permission/getUserPermissionByToken?namespaceId=${params.namespaceId}`, - { - method: `GET`, - }, - ); -} - /* get dataPermision's selectors by page */ export async function getDataPermisionSelectors(params) { return request(`${baseUrl}/data-permission/selector?${stringify(params)}`, {