t-comm
Version:
专业、稳定、纯粹的工具库
79 lines (72 loc) • 2.88 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var _regeneratorRuntime = require('@babel/runtime/regenerator');
var tslib_es6 = require('../tslib.es6-0d92ef81.js');
var pixui_gamelet = require('./gamelet.js');
var pixui_validator = require('./validator.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
/**
* 读取本地数据,IDE中不生效,在真机上才生效
* 数据以 app + roleId 为维度隔离存储,。存储的信息如15天不更新,会自动清除。
* @param key 键
* @example
* ```ts
* const token = await getLocalStorageInPixui('user-token');
* console.log(token);
* ```
*/
var getLocalStorageInPixui = function getLocalStorageInPixui(key) {
return tslib_es6.__awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
return _regeneratorRuntime__default["default"].wrap(function (_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!pixui_validator.isBrowserInPixui()) {
_context.next = 1;
break;
}
return _context.abrupt("return", localStorage.getItem(key) || '');
case 1:
_context.next = 2;
return pixui_gamelet.getGameletPixuiFrame().GameletAPI.readRoleCookie(key);
case 2:
return _context.abrupt("return", _context.sent);
case 3:
case "end":
return _context.stop();
}
}, _callee);
}));
};
/**
* 设置本地数据,IDE中不生效,在真机上才生效
* 数据以 app + roleId 为维度隔离存储,。存储的信息如15天不更新,会自动清除。
* @param key 键
* @param value 值
* @example
* ```ts
* await setLocalStorageInPixui('user-token', 'abc123');
* ```
*/
var setLocalStorageInPixui = function setLocalStorageInPixui(key, value) {
return tslib_es6.__awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2() {
return _regeneratorRuntime__default["default"].wrap(function (_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
if (!pixui_validator.isBrowserInPixui()) {
_context2.next = 1;
break;
}
return _context2.abrupt("return", localStorage.setItem(key, value));
case 1:
_context2.next = 2;
return pixui_gamelet.getGameletPixuiFrame().GameletAPI.writeRoleCookie(key, value);
case 2:
case "end":
return _context2.stop();
}
}, _callee2);
}));
};
exports.getLocalStorageInPixui = getLocalStorageInPixui;
exports.setLocalStorageInPixui = setLocalStorageInPixui;