use localStorage

This commit is contained in:
Captain.B 2020-02-28 17:50:05 +08:00
parent 85e3556a86
commit 2e8055f7f3
9 changed files with 15 additions and 23 deletions

View File

@ -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",

View File

@ -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);
//

View File

@ -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();
})
}

View File

@ -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);
}
}

View File

@ -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() {

View File

@ -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() {

View File

@ -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);
}

View File

@ -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();

View File

@ -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') {