bixi
Version:
企业级中后台前端解决方案
30 lines (25 loc) • 742 B
text/typescript
import { ITokenModel } from '../token/interface';
import { IStore } from './interface';
// tslint:disable-next-line:no-any
declare var Cookies: any;
/**
* `cookie` storage, muse be install
* [js-cookie](https://github.com/js-cookie/js-cookie) library
* and import `"node_modules/js-cookie/src/js.cookie.js"` in `angular.json`
*
* ```ts
* { provide: BIXI_STORE_TOKEN, useClass: CookieStorageStore }
* ```
*/
export class CookieStorageStore implements IStore {
get(key: string): ITokenModel {
return JSON.parse(Cookies.get(key) || '{}') || {};
}
set(key: string, value: ITokenModel | null): boolean {
Cookies.set(key, JSON.stringify(value));
return true;
}
remove(key: string) {
Cookies.remove(key);
}
}