123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- function set(key, data, sync = true) {
- try {
- if (sync) {
- return uni.setStorageSync(key, data);
- } else {
- uni.setStorage({
- key,
- data,
- success: function(res) {
- }
- });
- }
- } catch (e) {
- return false;
- }
- }
- function get(key, sync = true) {
- try {
- if (sync) {
- return uni.getStorageSync(key);
- } else {
- let val = '';
- uni.getStorage({
- key,
- success: function(res) {
- val = res.data;
- }
- });
- return val;
- }
- } catch (e) {
- return false;
- }
- }
- function info(sync = false) {
- try {
- if (sync) {
- return uni.getStorageInfoSync();
- } else {
- let val = '';
- uni.getStorageInfo({
- success: function(res) {
- val = res;
- }
- });
- return val
- }
- } catch (e) {
- return false;
- }
- }
- function remove(key, sync = true) {
- try {
- if (sync) {
- return uni.removeStorageSync(key);
- } else {
- uni.removeStorage({
- key: key
- });
- }
- } catch (e) {
- return false;
- }
- }
- function clear(sync = true) {
- try {
- if (sync) {
- return uni.clearStorageSync();
- } else {
- uni.clearStorage();
- }
- } catch (e) {
- return false;
- }
- }
- function has(key, sync = true) {
- try {
- if (sync) {
- return uni.getStorageSync(key) !== null;
- } else {
- let val = false;
- uni.getStorage({
- key: key,
- success: function(res) {
- val = res.data !== null;
- }
- });
- return val;
- }
- } catch (e) {
- return false;
- }
- }
- const storage = {
- get,
- set,
- info,
- remove,
- clear,
- has
- }
- export default storage;
|