From cb5c9968b763362d399e1c7fce1129ec7434aba8 Mon Sep 17 00:00:00 2001 From: kongdeqiang <123456> Date: 星期三, 26 四月 2023 14:07:31 +0800 Subject: [PATCH] session保存token --- src/views/activiti/model-manage/modelManage.vue | 6 +- src/views/xboot-vue-generator/tableGenerator.vue | 3 src/views/login1.vue | 25 ++++--- src/views/my-components/xboot/quill.vue | 2 src/views/my-components/xboot/editor.vue | 4 src/views/main-components/user.vue | 13 ++-- src/views/activiti/historic-detail/historicDetail.vue | 4 src/views/main-components/search.vue | 3 src/views/access/access.vue | 2 src/libs/hasRole.js | 2 src/libs/util.js | 2 src/views/authorize.vue | 2 src/views/auto-chat/setting/setting.vue | 4 src/views/sys/oss-manage/ossManage.vue | 4 src/views/my-components/xboot/file-upload.vue | 2 src/views/relate.vue | 10 +- src/views/my-components/xboot/upload-pic-input.vue | 2 src/views/own-space/own-space.vue | 1 src/views/activiti/process-manage/processManage.vue | 8 +- src/views/my-components/xboot/upload-pic-thumb.vue | 2 src/views/Main.vue | 1 src/views/xboot-vue-generator/treeGenerator.vue | 3 src/views/xboot-vue-template/excel/excel.vue | 3 src/libs/storage.js | 18 ++++++ src/views/sys/user-manage/userManage.vue | 3 src/views/login.vue | 23 ++++--- src/main.js | 5 + src/libs/axios.js | 18 +++--- src/views/own-space/message.vue | 2 src/views/your/carInfo-manage/carInfoManage.vue | 1 30 files changed, 109 insertions(+), 69 deletions(-) diff --git a/src/libs/axios.js b/src/libs/axios.js index 287ed6f..b1a108f 100644 --- a/src/libs/axios.js +++ b/src/libs/axios.js @@ -1,5 +1,5 @@ import axios from 'axios'; -import { getStore, setStore } from './storage'; +import { getStore, setStore,getSessionStore,setSessionStore} from './storage'; import { router } from '../router/index'; import { Message } from 'view-design'; import Cookies from 'js-cookie'; @@ -25,7 +25,7 @@ case 401: // 鏈櫥褰� 娓呴櫎宸茬櫥褰曠姸鎬� Cookies.set('userInfo', ''); - setStore('accessToken', ''); + setSessionStore('accessToken', ''); if (router.history.current.name != "login") { if (data.message !== null) { Message.error(data.message); @@ -63,7 +63,7 @@ }); export const getRequest = (url, params, responseType = null) => { - let accessToken = getStore('accessToken'); + let accessToken = getSessionStore('accessToken'); return axios({ method: 'get', url: `${baseApi}${url}`, @@ -75,7 +75,7 @@ }); }; export const getmethod = (url, params) => { - let accessToken = getStore('accessToken'); + let accessToken = getSessionStore('accessToken'); return axios({ method: 'get', url: `${baseApi}${url}`, @@ -88,7 +88,7 @@ }; export const postRequest = (url, params) => { - let accessToken = getStore("accessToken"); + let accessToken = getSessionStore("accessToken"); return axios({ method: 'post', url: `${baseApi}${url}`, @@ -109,7 +109,7 @@ }; export const putRequest = (url, params) => { - let accessToken = getStore("accessToken"); + let accessToken = getSessionStore("accessToken"); return axios({ method: 'put', url: `${baseApi}${url}`, @@ -130,7 +130,7 @@ }; export const postBodyRequest = (url, params) => { - let accessToken = getStore('accessToken'); + let accessToken = getSessionStore('accessToken'); return axios({ method: 'post', url: `${baseApi}${url}`, @@ -143,8 +143,8 @@ /** * 鏃犻渶token楠岃瘉鐨凣ET璇锋眰 閬垮厤鏃oken杩囨湡瀵艰嚧璇锋眰澶辫触 - * @param {*} url - * @param {*} params + * @param {*} url + * @param {*} params */ export const getNoAuthRequest = (url, params) => { return axios({ diff --git a/src/libs/hasRole.js b/src/libs/hasRole.js index 4fadf55..7ee50ac 100644 --- a/src/libs/hasRole.js +++ b/src/libs/hasRole.js @@ -1,4 +1,4 @@ -import { getStore } from './storage'; +import { getStore,getSessionStore } from './storage'; const hasRole = { install (Vue, options) { diff --git a/src/libs/storage.js b/src/libs/storage.js index 4602cab..ec51907 100644 --- a/src/libs/storage.js +++ b/src/libs/storage.js @@ -8,6 +8,14 @@ } window.localStorage.setItem(name, content); } +export const setSessionStore = (name, content) => { + if (!name) return; + if (typeof content !== 'string') { + content = JSON.stringify(content); + } + window.sessionStorage.setItem(name, content); +} + /** * 鑾峰彇localStorage @@ -21,6 +29,16 @@ return v; } +export const getSessionStore = name => { + if (!name) return; + let v = window.sessionStorage.getItem(name); + if (v == null) { + return ""; + } + return v; +} + + /** * 鍒犻櫎localStorage */ diff --git a/src/libs/util.js b/src/libs/util.js index 37045d3..d13ced2 100644 --- a/src/libs/util.js +++ b/src/libs/util.js @@ -328,7 +328,7 @@ if (!vm.$store.state.app.added) { vm.$Loading.start(); // 绗竴娆″姞杞� 璇诲彇鏁版嵁 - let accessToken = window.localStorage.getItem('accessToken'); + let accessToken = window.sessionStorage.getItem('accessToken'); // 鍔犺浇鑿滃崟 axios.get(getMenuList, { headers: { 'accessToken': accessToken } }).then(res => { vm.$Loading.finish(); diff --git a/src/main.js b/src/main.js index 272ad5d..7e1deb0 100644 --- a/src/main.js +++ b/src/main.js @@ -8,7 +8,7 @@ import store from './store' import i18n from '@/locale' import { getRequest, postRequest, putRequest, postBodyRequest, getNoAuthRequest, postNoAuthRequest } from '@/libs/axios' -import { setStore, getStore, removeStore } from '@/libs/storage' +import { setStore, getStore, removeStore,setSessionStore,getSessionStore } from '@/libs/storage' import { format } from "date-fns" import util from '@/libs/util' import hasPermission from '@/libs/hasPermission' @@ -45,6 +45,9 @@ Vue.prototype.postNoAuthRequest = postNoAuthRequest; Vue.prototype.setStore = setStore; Vue.prototype.getStore = getStore; +Vue.prototype.setSessionStore = setSessionStore; +Vue.prototype.getSessionStore = getSessionStore; + Vue.prototype.removeStore = removeStore; Vue.prototype.format = format; diff --git a/src/views/Main.vue b/src/views/Main.vue index 883d514..607d243 100644 --- a/src/views/Main.vue +++ b/src/views/Main.vue @@ -166,6 +166,7 @@ import circleLoading from "@/views/my-components/xboot/circle-loading.vue"; import util from "@/libs/util.js"; +import {getSessionStore} from "../libs/storage"; export default { components: { diff --git a/src/views/access/access.vue b/src/views/access/access.vue index 95c24ed..5e4cc74 100644 --- a/src/views/access/access.vue +++ b/src/views/access/access.vue @@ -99,6 +99,8 @@ </template> <script> +import {getSessionStore} from "../../libs/storage"; + export default { name: "access_index", data() { diff --git a/src/views/activiti/historic-detail/historicDetail.vue b/src/views/activiti/historic-detail/historicDetail.vue index ee20d05..e871f29 100644 --- a/src/views/activiti/historic-detail/historicDetail.vue +++ b/src/views/activiti/historic-detail/historicDetail.vue @@ -215,7 +215,7 @@ getHighlightImg + this.id + "?accessToken=" + - this.getStore("accessToken") + + this.getSessionStore("accessToken") + "&time=" + new Date(); this.getDataList(); @@ -262,4 +262,4 @@ }, }, }; -</script> \ No newline at end of file +</script> diff --git a/src/views/activiti/model-manage/modelManage.vue b/src/views/activiti/model-manage/modelManage.vue index f3e6074..2b86520 100644 --- a/src/views/activiti/model-manage/modelManage.vue +++ b/src/views/activiti/model-manage/modelManage.vue @@ -424,7 +424,7 @@ } this.modelerUrl = `${this.domain}/modeler/modeler.html?modelId=${ v.id - }&accessToken=${this.getStore("accessToken")}&time=${new Date()}`; + }&accessToken=${this.getSessionStore("accessToken")}&time=${new Date()}`; this.showModeler = true; this.modelerLoading = true; let that = this; @@ -491,7 +491,7 @@ }, export(v) { window.open( - exportModel + v.id + "?accessToken=" + this.getStore("accessToken") + exportModel + v.id + "?accessToken=" + this.getSessionStore("accessToken") ); }, remove(v) { @@ -556,4 +556,4 @@ }, }, }; -</script> \ No newline at end of file +</script> diff --git a/src/views/activiti/process-manage/processManage.vue b/src/views/activiti/process-manage/processManage.vue index 13d127a..ce305fb 100644 --- a/src/views/activiti/process-manage/processManage.vue +++ b/src/views/activiti/process-manage/processManage.vue @@ -458,7 +458,7 @@ methods: { init() { this.accessToken = { - accessToken: this.getStore("accessToken"), + accessToken: this.getSessionStore("accessToken"), }; this.deployByFileUrl = deployByFile; this.getDataList(); @@ -636,13 +636,13 @@ window.open( `${exportResource}?id=${ v.id - }&type=${type}&accessToken=${this.getStore("accessToken")}` + }&type=${type}&accessToken=${this.getSessionStore("accessToken")}` ); } else if (type == 1) { this.viewTitle = "娴佺▼鍥剧墖棰勮(" + v.diagramName + ")"; this.diagramUrl = `${exportResource}?id=${ v.id - }&type=${type}&accessToken=${this.getStore("accessToken")}`; + }&type=${type}&accessToken=${this.getSessionStore("accessToken")}`; this.viewImage = true; } }, @@ -708,4 +708,4 @@ }, }, }; -</script> \ No newline at end of file +</script> diff --git a/src/views/authorize.vue b/src/views/authorize.vue index 7fd7a94..19acd56 100644 --- a/src/views/authorize.vue +++ b/src/views/authorize.vue @@ -353,7 +353,7 @@ authorize(this.form).then((res) => { if (res.success) { // 瀛樺偍accessToken - this.setStore("accessToken", res.result.accessToken); + this.setSessionStore("accessToken", res.result.accessToken); let redictInfo = res.result; // 鑾峰彇鐢ㄦ埛淇℃伅 userInfo().then((res) => { diff --git a/src/views/auto-chat/setting/setting.vue b/src/views/auto-chat/setting/setting.vue index cd946c8..e895cff 100644 --- a/src/views/auto-chat/setting/setting.vue +++ b/src/views/auto-chat/setting/setting.vue @@ -374,7 +374,7 @@ }); return; } - this.demoUrl = `${this.domain}/chat/chat.html?accessToken=${this.getStore( + this.demoUrl = `${this.domain}/chat/chat.html?accessToken=${this.getSessionStore( "accessToken" )}&time=${new Date()}`; if (previewPC) { @@ -510,4 +510,4 @@ background: #fafafa; } } -</style> \ No newline at end of file +</style> diff --git a/src/views/login.vue b/src/views/login.vue index 1041cd8..42d2136 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -194,6 +194,7 @@ ] } ], + sessionStorage: null, showMore: false, code:"", captchaId: "", @@ -246,14 +247,15 @@ }, afterLogin(res) { let accessToken = res.result; - this.setStore("accessToken", accessToken); + console.log("login_afterLogin()",accessToken) + this.setSessionStore("accessToken", accessToken); getOtherSet().then((res) => { if (res.result) { let domain = res.result.ssoDomain; - Cookies.set("accessToken", accessToken, { - domain: domain, - expires: 7, - }); + // Cookies.set("accessToken", accessToken, { + // domain: domain, + // expires: 7, + // }); } }); // 鑾峰彇鐢ㄦ埛淇℃伅 @@ -406,14 +408,14 @@ if (res.success) { this.socialLogining = true; let accessToken = res.result; - this.setStore("accessToken", accessToken); + this.setSessionStore("accessToken", accessToken); getOtherSet().then((res) => { if (res.result) { let domain = res.result.ssoDomain; - Cookies.set("accessToken", accessToken, { - domain: domain, - expires: 7, - }); + // Cookies.set("accessToken", accessToken, { + // domain: domain, + // expires: 7, + // }); } }); // 鑾峰彇鐢ㄦ埛淇℃伅 @@ -500,6 +502,7 @@ //this.showNotice(); this.relatedLogin(); this.getCaptchaImg(); + }, }; </script> diff --git a/src/views/login1.vue b/src/views/login1.vue index d656ed0..b9c6a9d 100644 --- a/src/views/login1.vue +++ b/src/views/login1.vue @@ -303,6 +303,7 @@ ] } ], + sessionStorage: null, showMore: false, captchaId: "", captchaImg: "", @@ -387,14 +388,15 @@ }, afterLogin(res) { let accessToken = res.result; - this.setStore("accessToken", accessToken); + this.setSessionStore("accessToken", accessToken); getOtherSet().then((res) => { if (res.result) { let domain = res.result.ssoDomain; - Cookies.set("accessToken", accessToken, { - domain: domain, - expires: 7, - }); + // Cookies.set("accessToken", accessToken, { + // domain: domain, + // expires: 7, + // }); + } }); // 鑾峰彇鐢ㄦ埛淇℃伅 @@ -410,7 +412,7 @@ this.setStore("roles", roles); this.setStore("saveLogin", this.saveLogin); if (this.saveLogin) { - // 淇濆瓨7澶� + 淇濆瓨7澶� Cookies.set("userInfo", JSON.stringify(res.result), { expires: 7, }); @@ -546,14 +548,14 @@ if (res.success) { this.socialLogining = true; let accessToken = res.result; - this.setStore("accessToken", accessToken); + this.setSessionStore("accessToken", accessToken); getOtherSet().then((res) => { if (res.result) { let domain = res.result.ssoDomain; - Cookies.set("accessToken", accessToken, { - domain: domain, - expires: 7, - }); + // Cookies.set("accessToken", accessToken, { + // domain: domain, + // expires: 7, + // }); } }); // 鑾峰彇鐢ㄦ埛淇℃伅 @@ -640,6 +642,7 @@ this.showNotice(); this.relatedLogin(); this.getCaptchaImg(); + this.sessionStorage = window.sessionStorage; }, }; </script> diff --git a/src/views/main-components/search.vue b/src/views/main-components/search.vue index 447333c..f642b6f 100644 --- a/src/views/main-components/search.vue +++ b/src/views/main-components/search.vue @@ -59,6 +59,7 @@ <script> import axios from "axios"; import { getMenuList } from "@/api/index"; +import {getSessionStore} from "../../libs/storage"; export default { name: "search", props: { @@ -83,7 +84,7 @@ let menuData = this.getStore("menuData"); if (!menuData) { // 绗竴娆″姞杞� 璇诲彇鏁版嵁 - let accessToken = this.getStore("accessToken"); + let accessToken = this.getSessionStore("accessToken"); // 鍔犺浇鑿滃崟 axios .get(getMenuList, { headers: { accessToken: accessToken } }) diff --git a/src/views/main-components/user.vue b/src/views/main-components/user.vue index 2565a19..a37dc1d 100644 --- a/src/views/main-components/user.vue +++ b/src/views/main-components/user.vue @@ -36,6 +36,7 @@ import { getOtherSet } from "@/api/index"; import util from "@/libs/util.js"; import changePass from "@/views/change-pass/change-pass"; +import {getSessionStore} from "../../libs/storage"; export default { name: "user", components: { @@ -106,13 +107,13 @@ this.$store.commit("setLoading", false); if (res.result) { let domain = res.result.ssoDomain; - Cookies.set("accessToken", "", { - domain: domain, - expires: 7, - }); + // Cookies.set("accessToken", "", { + // domain: domain, + // expires: 7, + // }); } this.$store.commit("logout", this); - this.setStore("accessToken", ""); + this.setSessionStore("accessToken", "") // 寮哄埗鍒锋柊椤甸潰 閲嶆柊鍔犺浇router location.reload(); }); @@ -126,4 +127,4 @@ </script> <style lang="less" scoped> -</style> \ No newline at end of file +</style> diff --git a/src/views/my-components/xboot/editor.vue b/src/views/my-components/xboot/editor.vue index 14aaf0f..6e2ba92 100644 --- a/src/views/my-components/xboot/editor.vue +++ b/src/views/my-components/xboot/editor.vue @@ -228,7 +228,7 @@ this.editor.config.uploadImgServer = uploadFile; // xboot濡傝header涓紶鍏oken閴存潈 this.editor.config.uploadImgHeaders = { - accessToken: that.getStore("accessToken"), + accessToken: that.getSessionStore("accessToken"), }; this.editor.config.uploadFileName = "file"; this.editor.config.uploadImgHooks = { @@ -267,7 +267,7 @@ if (this.uploadVideo) { this.editor.config.uploadVideoServer = uploadFile; this.editor.config.uploadVideoHeaders = { - accessToken: that.getStore("accessToken"), + accessToken: that.getSessionStore("accessToken"), }; this.editor.config.uploadVideoName = "file"; this.editor.config.uploadVideoHooks = { diff --git a/src/views/my-components/xboot/file-upload.vue b/src/views/my-components/xboot/file-upload.vue index 1b3c866..a86d2ae 100644 --- a/src/views/my-components/xboot/file-upload.vue +++ b/src/views/my-components/xboot/file-upload.vue @@ -112,7 +112,7 @@ methods: { init() { this.accessToken = { - accessToken: this.getStore("accessToken"), + accessToken: this.getSessionStore("accessToken"), }; this.setCurrentValue(this.value); }, diff --git a/src/views/my-components/xboot/quill.vue b/src/views/my-components/xboot/quill.vue index 8beabe4..02b1159 100644 --- a/src/views/my-components/xboot/quill.vue +++ b/src/views/my-components/xboot/quill.vue @@ -157,7 +157,7 @@ methods: { initEditor() { this.accessToken = { - accessToken: this.getStore("accessToken") + accessToken: this.getSessionStore("accessToken") }; this.editor = new Quill(`#${this.id}`, this.options); let that = this; diff --git a/src/views/my-components/xboot/upload-pic-input.vue b/src/views/my-components/xboot/upload-pic-input.vue index 66d7cc4..80c7ffd 100644 --- a/src/views/my-components/xboot/upload-pic-input.vue +++ b/src/views/my-components/xboot/upload-pic-input.vue @@ -150,7 +150,7 @@ methods: { init() { this.accessToken = { - accessToken: this.getStore("accessToken"), + accessToken: this.getSessionStore("accessToken"), }; }, viewImage() { diff --git a/src/views/my-components/xboot/upload-pic-thumb.vue b/src/views/my-components/xboot/upload-pic-thumb.vue index b2010c0..f63c17e 100644 --- a/src/views/my-components/xboot/upload-pic-thumb.vue +++ b/src/views/my-components/xboot/upload-pic-thumb.vue @@ -144,7 +144,7 @@ init() { this.setData(this.value); this.accessToken = { - accessToken: this.getStore("accessToken"), + accessToken: this.getSessionStore("accessToken"), }; }, handleView(v, i) { diff --git a/src/views/own-space/message.vue b/src/views/own-space/message.vue index d4d4c9d..a2f2619 100644 --- a/src/views/own-space/message.vue +++ b/src/views/own-space/message.vue @@ -21,6 +21,8 @@ </template> <script> +import {getSessionStore} from "../../libs/storage"; + export default { components: {}, name: "message", diff --git a/src/views/own-space/own-space.vue b/src/views/own-space/own-space.vue index 632043a..43a9c60 100644 --- a/src/views/own-space/own-space.vue +++ b/src/views/own-space/own-space.vue @@ -40,6 +40,7 @@ import security from "./security"; import social from "./social"; import message from "./message"; +import {getSessionStore} from "../../libs/storage"; export default { components: { user, diff --git a/src/views/relate.vue b/src/views/relate.vue index b764dce..e022f61 100644 --- a/src/views/relate.vue +++ b/src/views/relate.vue @@ -147,14 +147,14 @@ if (res.success) { this.$Message.success("缁戝畾鎴愬姛"); let accessToken = res.result; - this.setStore("accessToken", accessToken); + this.setSessionStore("accessToken", accessToken); getOtherSet().then((res) => { if (res.result) { let domain = res.result.ssoDomain; - Cookies.set("accessToken", accessToken, { - domain: domain, - expires: 7, - }); + // Cookies.set("accessToken", accessToken, { + // domain: domain, + // expires: 7, + // }); } }); // 鑾峰彇鐢ㄦ埛淇℃伅 diff --git a/src/views/sys/oss-manage/ossManage.vue b/src/views/sys/oss-manage/ossManage.vue index dcf8910..c09a69b 100644 --- a/src/views/sys/oss-manage/ossManage.vue +++ b/src/views/sys/oss-manage/ossManage.vue @@ -794,7 +794,7 @@ }, init() { this.accessToken = { - accessToken: this.getStore("accessToken"), + accessToken: this.getSessionStore("accessToken"), }; checkOssSet().then((res) => { if (!res.success) { @@ -1133,4 +1133,4 @@ this.init(); }, }; -</script> \ No newline at end of file +</script> diff --git a/src/views/sys/user-manage/userManage.vue b/src/views/sys/user-manage/userManage.vue index 9558e46..d04ccc2 100644 --- a/src/views/sys/user-manage/userManage.vue +++ b/src/views/sys/user-manage/userManage.vue @@ -255,6 +255,7 @@ import excel from "@/libs/excel"; import addEdit from "./addEdit.vue"; import dict from "@/views/my-components/xboot/dict"; +import {getSessionStore} from "../../../libs/storage"; export default { name: "user-manage", components: { @@ -939,4 +940,4 @@ this.init(); }, }; -</script> \ No newline at end of file +</script> diff --git a/src/views/xboot-vue-generator/tableGenerator.vue b/src/views/xboot-vue-generator/tableGenerator.vue index 913953f..d915fc1 100644 --- a/src/views/xboot-vue-generator/tableGenerator.vue +++ b/src/views/xboot-vue-generator/tableGenerator.vue @@ -503,6 +503,7 @@ import { generateTable, getEntityData } from "@/api/index"; import customList from "@/views/my-components/xboot/custom-list"; import FileSaver from "file-saver"; +import {getSessionStore} from "../../libs/storage"; export default { name: "table-generator", components: { @@ -979,4 +980,4 @@ this.init(); }, }; -</script> \ No newline at end of file +</script> diff --git a/src/views/xboot-vue-generator/treeGenerator.vue b/src/views/xboot-vue-generator/treeGenerator.vue index 9bfacb2..d8b17bc 100644 --- a/src/views/xboot-vue-generator/treeGenerator.vue +++ b/src/views/xboot-vue-generator/treeGenerator.vue @@ -342,6 +342,7 @@ import { generateTree, getEntityData } from "@/api/index"; import customList from "@/views/my-components/xboot/custom-list"; import FileSaver from "file-saver"; +import {getSessionStore} from "../../libs/storage"; export default { name: "tree-generator", components: { @@ -727,4 +728,4 @@ this.init(); }, }; -</script> \ No newline at end of file +</script> diff --git a/src/views/xboot-vue-template/excel/excel.vue b/src/views/xboot-vue-template/excel/excel.vue index e00525e..e1fb1be 100644 --- a/src/views/xboot-vue-template/excel/excel.vue +++ b/src/views/xboot-vue-template/excel/excel.vue @@ -135,6 +135,7 @@ import { userColumns, userData } from "@/views/sys/user-manage/importTemplate"; // excel杞崲宸ュ叿绫� import excel from "@/libs/excel"; +import {getSessionStore} from "../../../libs/storage"; export default { name: "excel", data() { @@ -518,4 +519,4 @@ this.init(); }, }; -</script> \ No newline at end of file +</script> diff --git a/src/views/your/carInfo-manage/carInfoManage.vue b/src/views/your/carInfo-manage/carInfoManage.vue index c6ddb9f..17ca841 100644 --- a/src/views/your/carInfo-manage/carInfoManage.vue +++ b/src/views/your/carInfo-manage/carInfoManage.vue @@ -191,6 +191,7 @@ import util from "@/libs/util.js"; import excel from "@/libs/excel.js"; import {exportColumn} from "./exportColumn"; + import {getSessionStore} from "../../../libs/storage"; export default { name: "car-manage", data() { -- Gitblit v1.9.1