session.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**本地缓存 */
  2. var SessionOperation = {
  3. type:'session',
  4. setType:function(){
  5. if(this.type == 'session'){
  6. return window.sessionStorage;
  7. }
  8. if(this.type == 'local'){
  9. return window.localStorage;
  10. }
  11. console.log('类型错误!');
  12. },
  13. set:function($key,$value){
  14. this.setType().setItem($key,$value);
  15. },
  16. get:function($key){
  17. return this.setType().getItem($key)
  18. },
  19. clearAll:function(){
  20. if(this.type == 'session'){
  21. window.sessionStorage.clear();
  22. }
  23. if(this.type == 'local'){
  24. window.localStorage.clear();
  25. }
  26. console.log('类型错误!');
  27. },
  28. setToken:function(token){
  29. this.set("TOKEN", token);
  30. },
  31. getToken:function(){
  32. return this.get("TOKEN");
  33. },
  34. setUserId:function(userId){
  35. this.set("userId", userId);
  36. },
  37. getUserId:function(){
  38. return this.get("userId");
  39. },
  40. setPersonnelId:function(personnelId){
  41. this.set("personnelId", personnelId);
  42. },
  43. getPersonnelId:function(){
  44. return this.get("personnelId");
  45. },
  46. setUserDeps:function(userDeps){
  47. this.set("UserDeps", userDeps);
  48. },
  49. getUserDeps:function(){
  50. return this.get("UserDeps");
  51. },
  52. setRealName:function(realname){
  53. this.set("RealName", realname);
  54. },
  55. getRealName:function(){
  56. return this.get("RealName");
  57. },
  58. setUserName:function(username){
  59. this.set("UserName", username);
  60. },
  61. getUserName:function(){
  62. return this.get("UserName");
  63. },
  64. setOrgnizeId(id){
  65. this.set("OrgnizeId", id);
  66. },
  67. getOrgnizeId(){
  68. return this.get("OrgnizeId");
  69. },
  70. setOrgnizeName(name){
  71. this.set("OrgnizeName", name);
  72. },
  73. getOrgnizeName(){
  74. return this.get("OrgnizeName");
  75. }
  76. };
  77. function getQueryVariable(variable){
  78. var query = window.location.search.substring(1);
  79. var vars = query.split("&");
  80. for (var i=0;i<vars.length;i++) {
  81. var pair = vars[i].split("=");
  82. if(pair[0] == variable){
  83. return pair[1];
  84. }
  85. }
  86. return(false);
  87. }