123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import AsyncStorage from '@react-native-community/async-storage';
- //登陆信息进行本地存储
- //参数 json 登陆信息json
- export const StorageData = async (json) => {
- try {
- const {account, usertype, userName, authorities, token} = json.data;
- await AsyncStorage.setItem('account', JSON.stringify(account));
- await AsyncStorage.setItem('userName', JSON.stringify(userName));
- await AsyncStorage.setItem('usertype', JSON.stringify(usertype));
- await AsyncStorage.setItem('token', JSON.stringify(token));
- await AsyncStorage.setItem('authority', JSON.stringify(authorities));
- } catch (e) {
- console.log(e);
- }
- };
- export const StorageState = async (json) => {
- try {
- const {initRealm} = json;
- await AsyncStorage.setItem('initRealmFlag', JSON.stringify(initRealm));
- } catch (e) {
- console.log(e);
- }
- };
- //单独数据存储
- //参数 key:字段名称
- // value: 存储值
- export const IndividualStorageData = async (key, value) => {
- try {
- await AsyncStorage.setItem(key, value);
- } catch (e) {
- console.log(e);
- }
- }
- //读取本地数据存储信息
- //参数 key:取值字段名称
- export const RetrieveData = async (key) => {
- try {
- const value = await AsyncStorage.getItem(key)
- if (value !== null) {
- return value;
- }
- } catch (e) {
- console.log(e);
- }
- };
- //清空本地存储数据
- export const ClearAll = async () => {
- try {
- await AsyncStorage.clear();
- } catch (e) {
- console.log(e);
- }
- };
|