mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 03:58:33 +08:00
use localStorage
This commit is contained in:
parent
85e3556a86
commit
2e8055f7f3
@ -18,8 +18,7 @@
|
||||
"vue": "^2.6.10",
|
||||
"vue-i18n": "^8.15.3",
|
||||
"vue-router": "^3.1.3",
|
||||
"vuex": "^3.1.2",
|
||||
"js-cookie": "^2.2.0"
|
||||
"vuex": "^3.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "^4.1.0",
|
||||
|
@ -43,7 +43,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Cookies from 'js-cookie';
|
||||
import {TokenKey} from '../common/constants';
|
||||
|
||||
|
||||
@ -109,7 +108,7 @@
|
||||
if (valid) {
|
||||
this.$post("signin", this.form, (response) => {
|
||||
// 登录信息保存 cookie
|
||||
Cookies.set(TokenKey, response.data);
|
||||
localStorage.setItem(TokenKey, JSON.stringify(response.data));
|
||||
let rolesArray = response.data.roles;
|
||||
let roles = rolesArray.map(r => r.id);
|
||||
// 保存角色
|
||||
|
@ -42,7 +42,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Cookies from 'js-cookie';
|
||||
import {ROLE_ORG_ADMIN, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER, TokenKey} from '../../common/constants';
|
||||
|
||||
export default {
|
||||
@ -60,7 +59,7 @@
|
||||
{index: '2-1', name: '无工作空间'},
|
||||
],
|
||||
currentUserInfo: {},
|
||||
currentUserId: JSON.parse(Cookies.get(TokenKey)).id,
|
||||
currentUserId: JSON.parse(localStorage.getItem(TokenKey)).id,
|
||||
workspaceIds: [],
|
||||
currentOrganizationName: '选择组织',
|
||||
currentWorkspaceName: '选择工作空间'
|
||||
@ -68,7 +67,7 @@
|
||||
},
|
||||
computed: {
|
||||
currentUser: () => {
|
||||
let user = Cookies.get(TokenKey);
|
||||
let user = localStorage.getItem(TokenKey);
|
||||
// window.console.log(user);
|
||||
return JSON.parse(user);
|
||||
}
|
||||
@ -81,7 +80,7 @@
|
||||
break;
|
||||
case "logout":
|
||||
this.$get("/signout", function () {
|
||||
Cookies.remove(TokenKey);
|
||||
localStorage.removeItem(TokenKey);
|
||||
window.location.href = "/login";
|
||||
});
|
||||
break;
|
||||
@ -129,7 +128,7 @@
|
||||
let orgId = data.id;
|
||||
let sign = "organization";
|
||||
this.$post("/user/switch/source/" + sign + "/" + orgId, {}, response => {
|
||||
Cookies.set(TokenKey, response.data);
|
||||
localStorage.setItem(TokenKey, JSON.stringify(response.data));
|
||||
window.location.reload();
|
||||
})
|
||||
},
|
||||
@ -141,7 +140,7 @@
|
||||
return false;
|
||||
}
|
||||
this.$post("/user/switch/source/" + sign + "/" + workspaceId, {}, response => {
|
||||
Cookies.set(TokenKey, response.data);
|
||||
localStorage.setItem(TokenKey, JSON.stringify(response.data));
|
||||
window.location.reload();
|
||||
})
|
||||
}
|
||||
|
@ -21,7 +21,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Cookies from 'js-cookie';
|
||||
import {TokenKey} from "../../../common/constants";
|
||||
|
||||
export default {
|
||||
@ -46,7 +45,7 @@
|
||||
},
|
||||
computed: {
|
||||
currentUser: () => {
|
||||
let user = Cookies.get(TokenKey);
|
||||
let user = localStorage.getItem(TokenKey);
|
||||
return JSON.parse(user);
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,6 @@
|
||||
|
||||
<script>
|
||||
import MsCreateBox from "./CreateBox";
|
||||
import Cookies from 'js-cookie';
|
||||
import {TokenKey} from "../../../common/constants";
|
||||
|
||||
export default {
|
||||
@ -149,7 +148,7 @@
|
||||
},
|
||||
methods: {
|
||||
currentUser: () => {
|
||||
let user = Cookies.get(TokenKey);
|
||||
let user = localStorage.getItem(TokenKey);
|
||||
return JSON.parse(user);
|
||||
},
|
||||
initTableData() {
|
||||
|
@ -113,8 +113,8 @@
|
||||
|
||||
<script>
|
||||
import MsCreateBox from "./CreateBox";
|
||||
import Cookies from 'js-cookie';
|
||||
import {TokenKey} from "../../../common/constants";
|
||||
|
||||
export default {
|
||||
name: "MsOrganizationMember",
|
||||
components: {MsCreateBox},
|
||||
@ -147,7 +147,7 @@
|
||||
},
|
||||
methods: {
|
||||
currentUser: () => {
|
||||
let user = Cookies.get(TokenKey);
|
||||
let user = localStorage.getItem(TokenKey);
|
||||
return JSON.parse(user);
|
||||
},
|
||||
initTableData() {
|
||||
|
@ -60,7 +60,6 @@
|
||||
|
||||
<script>
|
||||
import MsCreateBox from "./CreateBox";
|
||||
import Cookies from 'js-cookie';
|
||||
import {Message} from "element-ui";
|
||||
import {TokenKey} from "../../../common/constants";
|
||||
|
||||
@ -72,7 +71,7 @@
|
||||
},
|
||||
computed: {
|
||||
currentUser: () => {
|
||||
let user = Cookies.get(TokenKey);
|
||||
let user = localStorage.getItem(TokenKey);
|
||||
window.console.log(user);
|
||||
return JSON.parse(user);
|
||||
}
|
||||
|
@ -50,7 +50,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Cookies from 'js-cookie';
|
||||
import {TokenKey} from "../../../common/constants";
|
||||
|
||||
export default {
|
||||
@ -98,7 +97,7 @@
|
||||
},
|
||||
methods: {
|
||||
currentUser: () => {
|
||||
let user = Cookies.get(TokenKey);
|
||||
let user = localStorage.getItem(TokenKey);
|
||||
return JSON.parse(user);
|
||||
},
|
||||
edit(row) {
|
||||
@ -113,7 +112,7 @@
|
||||
type: 'success',
|
||||
message: '修改成功!'
|
||||
});
|
||||
Cookies.set(TokenKey, response.data);
|
||||
localStorage.setItem(TokenKey, JSON.stringify(response.data));
|
||||
this.updateVisible = false;
|
||||
this.initTableData();
|
||||
window.location.reload();
|
||||
|
@ -1,5 +1,4 @@
|
||||
import router from './components/router/router'
|
||||
import Cookies from 'js-cookie' // get token from cookie
|
||||
import {TokenKey} from '../common/constants';
|
||||
|
||||
const whiteList = ['/login']; // no redirect whitelist
|
||||
@ -26,7 +25,7 @@ export const permission = {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
|
||||
// determine whether the user has logged in
|
||||
const user = JSON.parse(Cookies.get(TokenKey));
|
||||
const user = JSON.parse(localStorage.getItem(TokenKey));
|
||||
|
||||
if (user) {
|
||||
if (to.path === '/login') {
|
||||
|
Loading…
Reference in New Issue
Block a user