123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { Injectable, Inject } from '@angular/core';
- import { DOCUMENT } from '@angular/common';
- import { ConfigService, RequsetData } from "./config.service";
- import { from, Observable } from "rxjs";
- @Injectable({ providedIn: 'root' })
- export class UserService {
- win: any;
- lStorage: any;
- userInfo: any;
- userExt: any;
- openIDName = "userOpenID";
- constructor(@Inject(DOCUMENT) private document: any) {
- this.win = this.document.defaultView;
- this.lStorage = this.win.localStorage;
- }
- SetUser(user: any): void {
- this.userInfo = user;
- //this.document.cookie=`username=${user.username};path=/`;
- this.lStorage['userinfo'] = JSON.stringify(this.userInfo);
- }
- GetUser(): any {
- if (this.lStorage['userinfo']) {
- this.userInfo = JSON.parse(this.lStorage['userinfo']);
- }
- return this.userInfo;
- }
- SetFunctionCode(functionCode: string): void {
- this.lStorage['functionCodes'] = functionCode;
- }
- GetFunctionCode(): string {
- return this.lStorage['functionCodes'];
- }
- SetExt(ext: any) {
- this.lStorage['userExt'] = JSON.stringify(ext);
- }
- GetExt() {
- return JSON.parse(this.lStorage['userExt']);
- }
- SetToken(token: string) {
- this.lStorage['token'] = token;
- }
- GetToken() {
- return this.lStorage['token'];
- }
- Remember(loginId: string, pwd: string) {
- this.lStorage['loginId'] = loginId;
- this.lStorage['pwd'] = pwd;
- }
- GetRemember() {
- if (this.lStorage['loginId'] && this.lStorage['pwd']) {
- return {
- loginId: this.lStorage['loginId'],
- pwd: this.lStorage['pwd']
- }
- } else {
- return null;
- }
- }
- ClearRemember() {
- this.lStorage.removeItem('loginId');
- this.lStorage.removeItem('pwd');
- }
- ClearUser(): void {
- this.lStorage.removeItem('userinfo');
- this.lStorage.removeItem('token');
- this.lStorage.removeItem(this.openIDName);
- this.ClearRemember();
- }
- setOpenID(openID: string) {
- this.lStorage[this.openIDName] = openID;
- }
- getOpenID() {
- return this.lStorage[this.openIDName] || "";
- }
- }
|