Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/components/GlobalHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => (
<svg
Expand Down Expand Up @@ -159,23 +160,23 @@ class GlobalHeader extends PureComponent {

handleNamespacesValueChange = (value) => {
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 = () => {
Expand Down
81 changes: 42 additions & 39 deletions src/components/_utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
];
12 changes: 6 additions & 6 deletions src/models/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getUserPermissionByToken,
} from "../services/api";
import { getIntlContent } from "../utils/IntlUtils";
import { defaultNamespaceId } from "../components/_utils/utils";

export default {
namespace: "global",
Expand All @@ -37,7 +38,7 @@ export default {
permissions: {},
language: "",
namespaces: [],
currentNamespaceId: "649330b6-c2d7-4edc-be8e-8a54df9eb385",
currentNamespaceId: defaultNamespaceId,
},

effects: {
Expand All @@ -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 }) {
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/routes/System/Namespace/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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" });
Expand Down Expand Up @@ -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 ? (
""
) : (
<div className="optionParts">
Expand Down Expand Up @@ -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) => {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/System/User/DataPermModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,7 +58,7 @@ export default class DataPermModal extends Component {
pageSize: 12,
ruleListMap: {},
searchValue: "",
currentNamespaceId: "649330b6-c2d7-4edc-be8e-8a54df9eb385",
currentNamespaceId: defaultNamespaceId,
selectorExpandedRowKeys: [],
};
}
Expand Down
10 changes: 0 additions & 10 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`, {
Expand Down
Loading