修改util.js

This commit is contained in:
shiziyuan9527 2020-05-11 15:33:40 +08:00
parent 867225673b
commit dff0c8a008
8 changed files with 22 additions and 29 deletions

View File

@ -51,7 +51,7 @@
TokenKey, TokenKey,
WORKSPACE_ID WORKSPACE_ID
} from '../../../../common/js/constants'; } from '../../../../common/js/constants';
import {hasRoles, saveLocalStorage} from "../../../../common/js/utils"; import {getCurrentUser, hasRoles, saveLocalStorage} from "../../../../common/js/utils";
export default { export default {
name: "MsUser", name: "MsUser",
@ -68,7 +68,7 @@
{index: '2-1', name: '无工作空间'}, {index: '2-1', name: '无工作空间'},
], ],
currentUserInfo: {}, currentUserInfo: {},
currentUserId: JSON.parse(localStorage.getItem(TokenKey)).id, currentUserId: getCurrentUser().id,
workspaceIds: [], workspaceIds: [],
currentOrganizationName: '选择组织', currentOrganizationName: '选择组织',
currentWorkspaceName: '选择工作空间' currentWorkspaceName: '选择工作空间'
@ -76,9 +76,7 @@
}, },
computed: { computed: {
currentUser: () => { currentUser: () => {
let user = localStorage.getItem(TokenKey); return getCurrentUser();
// window.console.log(user);
return JSON.parse(user);
} }
}, },
methods: { methods: {

View File

@ -44,11 +44,11 @@
<script> <script>
import MsCreateBox from "../settings/CreateBox"; import MsCreateBox from "../settings/CreateBox";
import {Message} from "element-ui"; import {Message} from "element-ui";
import {TokenKey} from "../../../common/js/constants";
import MsTablePagination from "../common/pagination/TablePagination"; import MsTablePagination from "../common/pagination/TablePagination";
import MsTableHeader from "../common/components/MsTableHeader"; import MsTableHeader from "../common/components/MsTableHeader";
import MsTableOperator from "../common/components/MsTableOperator"; import MsTableOperator from "../common/components/MsTableOperator";
import MsDialogFooter from "../common/components/MsDialogFooter"; import MsDialogFooter from "../common/components/MsDialogFooter";
import {getCurrentUser} from "../../../common/js/utils";
export default { export default {
name: "MsProject", name: "MsProject",
@ -97,8 +97,7 @@
}, },
computed: { computed: {
currentUser: () => { currentUser: () => {
let user = localStorage.getItem(TokenKey); return getCurrentUser();
return JSON.parse(user);
} }
}, },
destroyed() { destroyed() {

View File

@ -6,7 +6,7 @@
</template> </template>
<script> <script>
import {TokenKey} from "../../../common/js/constants"; import {getCurrentUser} from "../../../common/js/utils";
export default { export default {
name: "MsCurrentUser", name: "MsCurrentUser",
@ -30,8 +30,7 @@
}, },
computed: { computed: {
currentUser: () => { currentUser: () => {
let user = localStorage.getItem(TokenKey); return getCurrentUser();
return JSON.parse(user);
} }
} }
} }

View File

@ -95,12 +95,12 @@
<script> <script>
import MsCreateBox from "../CreateBox"; import MsCreateBox from "../CreateBox";
import {TokenKey} from "../../../../common/js/constants";
import MsTablePagination from "../../common/pagination/TablePagination"; import MsTablePagination from "../../common/pagination/TablePagination";
import MsTableHeader from "../../common/components/MsTableHeader"; import MsTableHeader from "../../common/components/MsTableHeader";
import MsRolesTag from "../../common/components/MsRolesTag"; import MsRolesTag from "../../common/components/MsRolesTag";
import MsTableOperator from "../../common/components/MsTableOperator"; import MsTableOperator from "../../common/components/MsTableOperator";
import MsDialogFooter from "../../common/components/MsDialogFooter"; import MsDialogFooter from "../../common/components/MsDialogFooter";
import {getCurrentUser} from "../../../../common/js/utils";
export default { export default {
name: "MsOrganizationMember", name: "MsOrganizationMember",
@ -134,8 +134,7 @@
}, },
methods: { methods: {
currentUser: () => { currentUser: () => {
let user = localStorage.getItem(TokenKey); return getCurrentUser();
return JSON.parse(user);
}, },
initTableData() { initTableData() {
let param = { let param = {

View File

@ -145,13 +145,13 @@
<script> <script>
import MsCreateBox from "../CreateBox"; import MsCreateBox from "../CreateBox";
import {Message} from "element-ui"; import {Message} from "element-ui";
import {DEFAULT, TokenKey} from "../../../../common/js/constants"; import {DEFAULT} from "../../../../common/js/constants";
import MsTablePagination from "../../common/pagination/TablePagination"; import MsTablePagination from "../../common/pagination/TablePagination";
import MsTableHeader from "../../common/components/MsTableHeader"; import MsTableHeader from "../../common/components/MsTableHeader";
import MsRolesTag from "../../common/components/MsRolesTag"; import MsRolesTag from "../../common/components/MsRolesTag";
import MsTableOperator from "../../common/components/MsTableOperator"; import MsTableOperator from "../../common/components/MsTableOperator";
import MsDialogFooter from "../../common/components/MsDialogFooter"; import MsDialogFooter from "../../common/components/MsDialogFooter";
import {getCurrentWorkspaceId, refreshSessionAndCookies} from "../../../../common/js/utils"; import {getCurrentUser, getCurrentWorkspaceId, refreshSessionAndCookies} from "../../../../common/js/utils";
export default { export default {
name: "MsOrganizationWorkspace", name: "MsOrganizationWorkspace",
@ -161,8 +161,7 @@
}, },
computed: { computed: {
currentUser: () => { currentUser: () => {
let user = localStorage.getItem(TokenKey); return getCurrentUser();
return JSON.parse(user);
} }
}, },
methods: { methods: {

View File

@ -82,6 +82,7 @@
<script> <script>
import {TokenKey} from "../../../../common/js/constants"; import {TokenKey} from "../../../../common/js/constants";
import MsDialogFooter from "../../common/components/MsDialogFooter"; import MsDialogFooter from "../../common/components/MsDialogFooter";
import {getCurrentUser} from "../../../../common/js/utils";
export default { export default {
data() { data() {
@ -152,8 +153,7 @@
}, },
methods: { methods: {
currentUser: () => { currentUser: () => {
let user = localStorage.getItem(TokenKey); return getCurrentUser();
return JSON.parse(user);
}, },
edit(row) { edit(row) {
this.updateVisible = true; this.updateVisible = true;

View File

@ -97,12 +97,12 @@
<script> <script>
import MsCreateBox from "../CreateBox"; import MsCreateBox from "../CreateBox";
import {TokenKey} from "../../../../common/js/constants";
import MsTablePagination from "../../common/pagination/TablePagination"; import MsTablePagination from "../../common/pagination/TablePagination";
import MsTableHeader from "../../common/components/MsTableHeader"; import MsTableHeader from "../../common/components/MsTableHeader";
import MsRolesTag from "../../common/components/MsRolesTag"; import MsRolesTag from "../../common/components/MsRolesTag";
import MsTableOperator from "../../common/components/MsTableOperator"; import MsTableOperator from "../../common/components/MsTableOperator";
import MsDialogFooter from "../../common/components/MsDialogFooter"; import MsDialogFooter from "../../common/components/MsDialogFooter";
import {getCurrentUser} from "../../../../common/js/utils";
export default { export default {
name: "MsMember", name: "MsMember",
@ -136,8 +136,7 @@
}, },
methods: { methods: {
currentUser: () => { currentUser: () => {
let user = localStorage.getItem(TokenKey); return getCurrentUser();
return JSON.parse(user);
}, },
initTableData() { initTableData() {
if (this.currentUser().lastWorkspaceId === null) { if (this.currentUser().lastWorkspaceId === null) {

View File

@ -9,13 +9,13 @@ import {
import axios from "axios"; import axios from "axios";
export function hasRole(role) { export function hasRole(role) {
let user = JSON.parse(localStorage.getItem(TokenKey)); let user = getCurrentUser();
let roles = user.roles.map(r => r.id); let roles = user.roles.map(r => r.id);
return roles.indexOf(role) > -1; return roles.indexOf(role) > -1;
} }
export function hasRoles(...roles) { export function hasRoles(...roles) {
let user = JSON.parse(localStorage.getItem(TokenKey)); let user = getCurrentUser();
let rs = user.roles.map(r => r.id); let rs = user.roles.map(r => r.id);
for (let item of roles) { for (let item of roles) {
if (rs.indexOf(item) > -1) { if (rs.indexOf(item) > -1) {
@ -26,24 +26,24 @@ export function hasRoles(...roles) {
} }
export function checkoutCurrentOrganization() { export function checkoutCurrentOrganization() {
let user = JSON.parse(localStorage.getItem(TokenKey)); let user = getCurrentUser();
// 查看当前用户是否是 lastOrganizationId 的组织管理员 // 查看当前用户是否是 lastOrganizationId 的组织管理员
return user.userRoles.filter(ur => hasRole(ROLE_ORG_ADMIN) && user.lastOrganizationId === ur.sourceId).length > 0; return user.userRoles.filter(ur => hasRole(ROLE_ORG_ADMIN) && user.lastOrganizationId === ur.sourceId).length > 0;
} }
export function checkoutCurrentWorkspace() { export function checkoutCurrentWorkspace() {
let user = JSON.parse(localStorage.getItem(TokenKey)); let user = getCurrentUser();
// 查看当前用户是否是 lastWorkspaceId 的工作空间用户 // 查看当前用户是否是 lastWorkspaceId 的工作空间用户
return user.userRoles.filter(ur => hasRoles(ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER) && user.lastWorkspaceId === ur.sourceId).length > 0; return user.userRoles.filter(ur => hasRoles(ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER) && user.lastWorkspaceId === ur.sourceId).length > 0;
} }
export function getCurrentOrganizationId() { export function getCurrentOrganizationId() {
let user = JSON.parse(localStorage.getItem(TokenKey)); let user = getCurrentUser();
return user.lastOrganizationId; return user.lastOrganizationId;
} }
export function getCurrentWorkspaceId() { export function getCurrentWorkspaceId() {
let user = JSON.parse(localStorage.getItem(TokenKey)); let user = getCurrentUser();
return user.lastWorkspaceId; return user.lastWorkspaceId;
} }