会话存储sessionStorage之token、用户 & 设置-sessionStorage.setItem(‘num’, ‘张三’)、获取sessionStorage.getItem(‘num’)
设置值
sessionStorage.setItem(‘manInplementIndex’, ‘4’)
获取值
sessionStorage.getItem(‘manInplementIndex’)
效果
//设置 sessionStorage.setItem('manInplementIndex', '2') //获取 const manInplementIndex = ref('1') if (sessionStorage.getItem('manInplementIndex')) {
manInplementIndex.value = sessionStorage.getItem('manInplementIndex') }
1、获取本地token
示例
{
token:'8ef751b46f2a19e5f5da3452ddaa3ab55a57f7a5439d5ca11c95011a78de5b55add4a5ad01fd3b04f1d2d2f0320fd287b3b8460afbb5245c6c497f0e762a8bfe94076c789de71e06a41a613def1ade172a87358a4b4ddd32d5653c239c233d9007b11d3deec3dece984b85bf40a3'}
页面
import {
getToken } from '@src/utils/token' const obj = ref({
token: getToken(), })
方法
src\utils\token.ts
import {
storage, tokenTableName } from '@/config' import cookie from 'js-cookie' / * @description 获取token * @returns {string|ActiveX.IXMLDOMNode|Promise<any>|any|IDBRequest<any>|MediaKeyStatus|FormDataEntryValue|Function|Promise<Credential | null>} */ export function getToken() {
const token = sessionStorage.getItem('token') return token } / * @description 存储token * @param token * @returns {void|*} */ export function setToken(token: string) {
if (storage) {
if ('localStorage' === storage) {
return localStorage.setItem(tokenTableName, token) } else if ('sessionStorage' === storage) {
return sessionStorage.setItem(tokenTableName, token) } else if ('cookie' === storage) {
return cookie.set(tokenTableName, token) } else {
return localStorage.setItem(tokenTableName, token) } } else {
return localStorage.setItem(tokenTableName, token) } } / * @description 移除token * @returns {void|Promise<void>} */ export function removeToken() {
if (storage) {
if ('localStorage' === storage) {
return localStorage.removeItem(tokenTableName) } else if ('sessionStorage' === storage) {
return sessionStorage.clear() } else if ('cookie' === storage) {
return cookie.remove(tokenTableName) } else {
return localStorage.removeItem(tokenTableName) } } else {
return localStorage.removeItem(tokenTableName) } }
2、获取本地用户信息
示例
loginUserInfo:{
"userId":null,"userTel":"","userEmail":"ls2@isc.com","dispOrder":0,"validBegTime":"2023-03-13","validEndTime":"2023-06-13","userTitle":"","fax":"","custTel":"","userName":"kjcx_kj01","userCode":null,"userStat":1,"userStatName":"正常","loginName":"kjcx_kj01","systemUserId":"9b4483c86db54cc59788f","timeOut":1800,"photo":"","remark":null,"birthDay":"","birthPlace":"","gender":"","genderName":"","employNo":null,"duty":null,"sapHrUserId":null,"homePostalCode":"","homePostalAddress":"","homePhone":"","postalCode":"","postalAddress":"","identityNo":"","nationCode":null,"nationCodeName":"","nativePlace":"","resExt":null,"userSource":null,"orgId":null,"orgNo":"1001","orgName":"国家电网公司","deptId":null,"deptNo":null,"deptName":null,"orgLevel":"01","systemOrgId":"9b4483c870d976dc705ed","relaUserId":null,"mgtOrgType":"corp","mgtOrgPathDTO":{
"mgtOrgDTOList":[{
"mgtOrgId":null,"mgtOrgCode":"1001","mgtOrgName":"国家电网公司","distLv":"01","prntMgtOrgId":null,"prntMgtOrgCode":null,"prntMgtOrgName":null,"mgtOrgChar":"sg01","validDate":"2023-03-23 08:00:00.0","invalidDate":"2028-03-31 08:00:00.0","validFlag":"Y","mgtOrgChnAbbr1":"国网公司","mgtOrgChnAbbr2":null,"mgtOrgType":"corp","srvKind":"01","srvKindName":null,"comment":null,"relaMgtOrgId":null,"sysMgtOrgId":"9b4483c870d976dc705ed","prntSysMgtOrgId":null,"isLeaf":null,"majAttr":null,"children":null,"supCorrSysMgtOrgId":null,"supCorrMgtOrgCode":null,"supCorrMgtOrgName":null,"sysCode":"","resExt":{
}}]},"supCorrSysMgtOrgId":null,"supCorrMgtOrgCode":null,"supCorrMgtOrgName":null,"sysCode":"","orgRoles":[{
"orgRoleId":"9b4483c8831eb7ff139c9","orgRoleName":"国家电网公司_总部菜单角色","orgRoleCode":"zbcd01","roleId":"9b4483c8831c","roleName":null,"roleCode":null,"orgNo":null,"orgName":null,"deptNo":null,"deptName":null,"systemOrgId":"9b4483c870d976dc705ed"},{
"orgRoleId":"9b4483c8852c7d0905c5e","orgRoleName":"国家电网_规划计划填报人","orgRoleCode":"ghjhtbr","roleId":"9b4483c8831f21a7839e9","roleName":null,"roleCode":null,"orgNo":null,"orgName":null,"deptNo":null,"deptName":null,"systemOrgId":"9b4483c870d976dc705ed"},{
"orgRoleId":"9b4483c8823a6cc891ea6","orgRoleName":"国家电网_kj国家级项目立项审批人","orgRoleCode":"kjxm_0301","roleId":"9b4483c88239e7b111ea0","roleName":null,"roleCode":null,"orgNo":null,"orgName":null,"deptNo":null,"deptName":null,"systemOrgId":"9b4483c870d976dc705ed"},{
"orgRoleId":"9b4483c88237fc45d1e0c","orgRoleName":"国家电网公司_公司总部项目归档审批人","orgRoleCode":"tprj_03901","roleId":"9b4483ce081df9","roleName":null,"roleCode":null,"orgNo":null,"orgName":null,"deptNo":null,"deptName":null,"systemOrgId":"9b4483c870d976dc705ed"},{
"orgRoleId":"9b4483c88237e3be81e0b","orgRoleName":"国家电网公司_公司总部项目验收审批人","orgRoleCode":"tprj_03701","roleId":"9b4483caba51df7","roleName":null,"roleCode":null,"orgNo":null,"orgName":null,"deptNo":null,"deptName":null,"systemOrgId":"9b4483c870d976dc705ed"},{
"orgRoleId":"9b4483c88237db2a61e0a","orgRoleName":"国家电网公司_公司总部项目执行审批人","orgRoleCode":"tprj_02701","roleId":"9b4483cfa81df5","roleName":null,"roleCode":null,"orgNo":null,"orgName":null,"deptNo":null,"deptName":null,"systemOrgId":"9b4483c870d976dc705ed"},{
"orgRoleId":"9b4483c88237d4f0d1e09","orgRoleName":"国家电网公司_公司总部项目立项审批人","orgRoleCode":"tprj_03101","roleId":"9b4483ce31df2","roleName":null,"roleCode":null,"orgNo":null,"orgName":null,"deptNo":null,"deptName":null,"systemOrgId":"9b4483c870d976dc705ed"},{
"orgRoleId":"9b4483c8823a7ee6d1ea8","orgRoleName":"国家电网公司_科技管理部门执行审核人","orgRoleCode":"kjxm_0601","roleId":"9b4483c88239f84dd1ea3","roleName":null,"roleCode":null,"orgNo":null,"orgName":null,"deptNo":null,"deptName":null,"systemOrgId":"9b4483c870d976dc705ed"},{
"orgRoleId":"9b4483c8823a76cc51ea7","orgRoleName":"国家电网公司_国家级项目执行审批人","orgRoleCode":"kjxm_0501","roleId":"9b4483c88239f3a641ea2","roleName":null,"roleCode":null,"orgNo":null,"orgName":null,"deptNo":null,"deptName":null,"systemOrgId":"9b4483c870d976dc705ed"},{
"orgRoleId":"9b4483c886bb1a66469e2","orgRoleName":"国家电网公司_各单位填报人审批人","orgRoleCode":"gw_techprj_037","roleId":"9b4483c886bab26e369a7","roleName":null,"roleCode":null,"orgNo":null,"orgName":null,"deptNo":null,"deptName":null,"systemOrgId":"9b4483c870d976dc705ed"}],"currentDuty":null,"dutyDtoList":null,"baseImg":"iVBORw0KGgoAAAANSUhEUgAAAVoAAAFaCAYAAABfUZV2AAAKyElEQVR42u3dYY4jpxqG0d7/amcHifKvFfW4KSj4XuAcKbpSRnfs2K7HVBmory8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgE38+fPnn//+8UoATAzt9/8FYEF0ARBbALEFQGwB3g/n0xkG338oE16AB6PTJ+EUWYCBSwC/BVRkAQZDOxpiABpjKagAhaNaAIxqAdYG9W/BNKoFKAyxyAK8PLL9/uemcAFMiK2RLMDC2AIgtgAZMRVbgIlhbZ0nK7YAYguQG9sn2x565QA6Yvt9fuxP/wgtwIuXEVw6ACiKrcgCLBrZAhAYW5cdABYFXGwBNh41A0THbHX8xBa4KrRV10/FFrgitNU/UoktcHRoZ0T2p9Vkrc/VzATguNjOiGxvyEUW2CKqv+1TUBV1+90Cx49oV4R3ZPQsskD8KDYhYPZKAI4drSaFzV1zAaGdPJI2qgWE1qgWoG3k2PJnlc9vZMQLsMWodvWPYJ9iazECcNzItup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jFFsQ2Nvqz/xtGIm9UCwfH9oZNu0d+LFq1gc6TH7lEFjaK7Q2bdn//e5/+/SnbU34PrhkGsFFsb9i0u/dxZsZs5P0QWNgotjds2p0arE+XCNyVFg6J7S2bdu80Oly93SKwYVzSNu3eKbb2LACGYrXDDlOzf2Tq/XuFFmiOwQ7BmBnZ3scQWuDrlGisiOzT10FkgbjYpi1IGLmcIrJAd6jSFiNUvSZCCnSNHKsWI+y46bXQAt1RS7jdy8xLDEILLI9D5V6uvVGfPYWrZxaG67JA7KbdKaPFkbvmiiwQv2l39eOO7OsgssCW82R32JHMxjFAXGyfRGl1wFyTBZbGNmUJ66377AKHxzZpCavbgwPHxTZpCevs5zQyrcwnCOgK4Op5slWhdSNFoCS2N0/hciNF4LjYVT32yMhaYIFjIl9xx1ohBbYP6Q5LWIUWOGrU+tOfVV//FFrg+BFv2naHfvgCjgtt0qhbZAHhnPCcTOECtolsS9wqYta6ibjIAltEtjW2SaNqkQW2DO3soLaMqr0zwDGRTVgMYG8C4OigVoe2515oIgy4fPBCZI12geNHtgmRFVbgyNiuPDUXW8DINii2QguI7cTYiiwgtoOP9enxRBY4OrYzRqxPYiuywFGxXfl3t+5z650BGAi429MALBglCyrAxMiKLYDYApwTW6EFaIxlzwYwIgvwcET6JLYiC9B52t/y70QWoDOyLbEVWYDByPZcRgCgM5bCCiC2APvHVmgBJsZWZAEmxlZkASbGVmQBJsZWZAEWjmwBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABL8C0mUh3yy1PEXAAAAAElFTkSuQmCC","orgShortName":"国网公司","upperOrg":"1001","upperDept":null,"defaultTimeout":1800,"dutyFlag":false,"mgtOrgDTOS":null,"orgRoleFlag":false,"currentLoginUserIp":"27.196.104.110","needIpVerify":false,"registerIp":false,"authBio":null}
页面
// 用法一 const loginUserInfo = JSON.parse(sessionStorage.getItem('loginUserInfo')) // 用法二 import {
getSystemUserId } from '@src/utils/limits'
src\utils\limits.js
//获取当前登录人 export const getSystemUserId = (createUser) => {
const loginUserInfo = JSON.parse(sessionStorage.getItem('loginUserInfo')) if ( loginUserInfo === null || loginUserInfo === '' || !loginUserInfo.systemUserId || loginUserInfo.systemUserId === null ) return false return loginUserInfo.systemUserId === createUser }
到此这篇会话存储sessionStorage之token、用户 & 设置-sessionStorage.setItem(‘num‘, ‘张三‘)、获取sessionStorage.getItem(‘num‘)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!
版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/rfx/10754.html