@smart100/spu-web-plugin 1.0.25-beta.4 → 1.0.25-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var version = "1.0.25-beta.4";
1
+ var version = "1.0.25-beta.6";
2
2
 
3
3
  /** Detect free variable `global` from Node.js. */
4
4
  var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
@@ -7618,7 +7618,7 @@ function _requestEnvdata() {
7618
7618
  hostsRoot = document.location.protocol === 'https:' ? 'https://mconfig.xuantongkeji.com' : 'http://mconfig.xuantongkeji.com:8015';
7619
7619
  _context3.prev = 3;
7620
7620
  _context3.next = 6;
7621
- return normalAxios$1.get("".concat(hostsRoot, "/multiplatconfig/env/").concat(envName), {
7621
+ return apaasAxios.get("".concat(hostsRoot, "/multiplatconfig/env/").concat(envName), {
7622
7622
  isShowLoading: false,
7623
7623
  isSendToken: false
7624
7624
  });
@@ -7829,7 +7829,7 @@ var Core = /*#__PURE__*/function () {
7829
7829
  }
7830
7830
  _context3.prev = 5;
7831
7831
  _context3.next = 8;
7832
- return normalAxios$1.post("".concat(smartcenter, "/api/smartcenter/biz/getTenantWebAndApiDefined"), {
7832
+ return apaasAxios.post("".concat(smartcenter, "/api/smartcenter/biz/getTenantWebAndApiDefined"), {
7833
7833
  envid: envId,
7834
7834
  tenantcode: tenantCode
7835
7835
  }, {
@@ -15896,72 +15896,83 @@ var normalizeEncryData = function normalizeEncryData(response) {
15896
15896
  }
15897
15897
  return response;
15898
15898
  };
15899
+ // 检查接口错误返回信息是否登录
15900
+ var checkErrorResponseIsLogin = function checkErrorResponseIsLogin() {
15901
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'spu';
15902
+ var err = arguments.length > 1 ? arguments[1] : undefined;
15903
+ if (type === 'spu') {
15904
+ if (err.message === '未授权' && get$1(err, 'response.data.code') === 401) {
15905
+ return false;
15906
+ } else {
15907
+ return true;
15908
+ }
15909
+ } else if (type === 'apaas') {
15910
+ if (err.message.indexOf('token is invalid(decode).') !== -1 || err.message.indexOf('token is invalid(null).') !== -1 || err.message === 'token无效,请重新登录' || err.message === 'jwt token无效') {
15911
+ return false;
15912
+ } else {
15913
+ return true;
15914
+ }
15915
+ }
15916
+ };
15899
15917
  var createAxiosInstance$1 = function createAxiosInstance() {
15900
15918
  var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'spu';
15901
- var options = arguments.length > 1 ? arguments[1] : undefined;
15902
- var axiosInstance = axios$3.create({
15903
- baseURL: type === 'spu' ? "/api/".concat(options.modulekey, "/").concat(options.moduleversion) : ''
15904
- // baseURL: '',
15905
- // timeout: 36000000
15906
- // withCredentials: true, // 不能开启 影响ali oss
15907
- // headers: {
15908
- // // 'Content-Type': 'application/json;charset=UTF-8',
15909
- // // 'app_id': '100'
15910
- // }
15911
- });
15912
-
15919
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
15920
+ var axiosInstance = axios$3.create(Object.assign(config, {
15921
+ baseURL: type === 'spu' ? "/api/".concat(globalOptions.modulekey, "/").concat(globalOptions.moduleversion) : ''
15922
+ }));
15913
15923
  axiosInstance.interceptors.request.use( /*#__PURE__*/function () {
15914
15924
  var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(config) {
15915
- var isShowLoading, isSendToken, loginState, token, moduleData, isSendTecode, tecode;
15925
+ var isShowLoading, moduleData, isSendToken, loginState, token, isSendTecode, tecode;
15916
15926
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
15917
15927
  while (1) switch (_context.prev = _context.next) {
15918
15928
  case 0:
15919
- // const isShowLoading = typeof config?.isShowLoading !== 'undefined' ? config.isShowLoading : true
15920
- // console.error(444444)
15921
- // console.log(config)
15922
15929
  isShowLoading = get$1(config, 'isShowLoading', true);
15923
15930
  isShowLoading && loadding$1.open();
15931
+ if (!(type === 'spu' && config.modulekey)) {
15932
+ _context.next = 7;
15933
+ break;
15934
+ }
15935
+ _context.next = 5;
15936
+ return core$1.getModuleData(config.modulekey);
15937
+ case 5:
15938
+ moduleData = _context.sent;
15939
+ if (moduleData.data) {
15940
+ config.baseURL = "/api/".concat(config.modulekey, "/").concat(moduleData.data.moduleversion);
15941
+ } else {
15942
+ console.error(moduleData.errorMsg);
15943
+ config.baseURL = "/api/".concat(config.modulekey, "/v?.?");
15944
+ }
15945
+ case 7:
15946
+ // if (config.url === 'http://120.46.182.226/api/smartcenter/biz/getTenantWebAndApiDefined') {
15947
+ // console.log(config)
15948
+ // debugger
15949
+ // }
15924
15950
  isSendToken = get$1(config, 'isSendToken', true);
15925
15951
  if (!isSendToken) {
15926
- _context.next = 16;
15952
+ _context.next = 21;
15927
15953
  break;
15928
15954
  }
15929
15955
  // 请求接口前校验是否过期 如果过期先刷新token
15930
15956
  loginState = getLoginState();
15931
15957
  if (!(config.url !== '/api/auth/refreshtoken' && !loginState.islogin && loginState.type === 2 && loginState.role !== 'center')) {
15932
- _context.next = 14;
15958
+ _context.next = 19;
15933
15959
  break;
15934
15960
  }
15935
- _context.prev = 6;
15936
- _context.next = 9;
15937
- return updateToken();
15938
- case 9:
15961
+ _context.prev = 11;
15939
15962
  _context.next = 14;
15963
+ return updateToken();
15964
+ case 14:
15965
+ _context.next = 19;
15940
15966
  break;
15941
- case 11:
15942
- _context.prev = 11;
15943
- _context.t0 = _context["catch"](6);
15967
+ case 16:
15968
+ _context.prev = 16;
15969
+ _context.t0 = _context["catch"](11);
15944
15970
  console.error(_context.t0);
15945
- case 14:
15971
+ case 19:
15946
15972
  token = getToken();
15947
15973
  if (config !== null && config !== void 0 && config.headers && token) {
15948
15974
  config.headers.token = token;
15949
15975
  }
15950
- case 16:
15951
- if (!(type === 'spu' && config.modulekey)) {
15952
- _context.next = 21;
15953
- break;
15954
- }
15955
- _context.next = 19;
15956
- return core$1.getModuleData(config.modulekey);
15957
- case 19:
15958
- moduleData = _context.sent;
15959
- if (moduleData.data) {
15960
- config.baseURL = "/api/".concat(config.modulekey, "/").concat(moduleData.data.moduleversion);
15961
- } else {
15962
- console.error(moduleData.errorMsg);
15963
- config.baseURL = "/api/".concat(config.modulekey, "/v?.?");
15964
- }
15965
15976
  case 21:
15966
15977
  // 平台的业务接口开了开发者模式后,header带上debug方便查看接口的ide日志
15967
15978
  if (type !== 'spu' && urlquery.isdebugger && config.url.indexOf('api/teapi/dy-biz/') > -1) {
@@ -15983,86 +15994,129 @@ var createAxiosInstance$1 = function createAxiosInstance() {
15983
15994
  case "end":
15984
15995
  return _context.stop();
15985
15996
  }
15986
- }, _callee, null, [[6, 11]]);
15997
+ }, _callee, null, [[11, 16]]);
15987
15998
  }));
15988
15999
  return function (_x) {
15989
16000
  return _ref.apply(this, arguments);
15990
16001
  };
15991
16002
  }(), function (error) {
16003
+ // console.error(error)
16004
+ // debugger
15992
16005
  return Promise.reject(error);
15993
16006
  });
15994
- axiosInstance.interceptors.response.use(function (res) {
15995
- // debugger
15996
- var isShowLoading = get$1(res, 'config.isShowLoading', true);
15997
- isShowLoading && loadding$1.close();
15998
- normalizeEncryData(res);
15999
- var realRes = {
16000
- code: 404,
16001
- data: '',
16002
- msg: '',
16003
- message: ''
16007
+ axiosInstance.interceptors.response.use( /*#__PURE__*/function () {
16008
+ var _ref2 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2(res) {
16009
+ var isShowLoading, realRes, _res$data, _res$data2, _res$data3;
16010
+ return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
16011
+ while (1) switch (_context2.prev = _context2.next) {
16012
+ case 0:
16013
+ isShowLoading = get$1(res, 'config.isShowLoading', true);
16014
+ isShowLoading && loadding$1.close();
16015
+ // if (res.config.url === '/api/auth/refreshtoken') {
16016
+ // console.log(res)
16017
+ // debugger
16018
+ // }
16019
+ normalizeEncryData(res);
16020
+ if (!(type !== 'normal')) {
16021
+ _context2.next = 20;
16022
+ break;
16023
+ }
16024
+ realRes = {
16025
+ code: 404,
16026
+ data: '',
16027
+ msg: '',
16028
+ message: ''
16029
+ };
16030
+ if (!(type === 'spu')) {
16031
+ _context2.next = 15;
16032
+ break;
16033
+ }
16034
+ if (!(res.data.code === 200)) {
16035
+ _context2.next = 11;
16036
+ break;
16037
+ }
16038
+ // return res.data
16039
+ realRes = {
16040
+ code: res.data.code,
16041
+ data: res.data.data,
16042
+ msg: res.data.msg,
16043
+ message: res.data.msg
16044
+ };
16045
+ return _context2.abrupt("return", realRes);
16046
+ case 11:
16047
+ realRes = {
16048
+ code: res.data.code,
16049
+ data: res.data.data,
16050
+ msg: res.data.msg || '网络异常,请稍后重试。',
16051
+ message: res.data.msg || '网络异常,请稍后重试。'
16052
+ };
16053
+ return _context2.abrupt("return", Promise.reject(realRes));
16054
+ case 13:
16055
+ _context2.next = 18;
16056
+ break;
16057
+ case 15:
16058
+ if (!(type === 'apaas')) {
16059
+ _context2.next = 18;
16060
+ break;
16061
+ }
16062
+ realRes = {
16063
+ code: res.status || 200,
16064
+ data: ((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.resp_data) || res.data,
16065
+ msg: ((_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : _res$data2.error_code) || '',
16066
+ message: ((_res$data3 = res.data) === null || _res$data3 === void 0 ? void 0 : _res$data3.error_code) || ''
16067
+ };
16068
+ return _context2.abrupt("return", realRes);
16069
+ case 18:
16070
+ _context2.next = 21;
16071
+ break;
16072
+ case 20:
16073
+ return _context2.abrupt("return", res);
16074
+ case 21:
16075
+ case "end":
16076
+ return _context2.stop();
16077
+ }
16078
+ }, _callee2);
16079
+ }));
16080
+ return function (_x2) {
16081
+ return _ref2.apply(this, arguments);
16004
16082
  };
16005
- if (type === 'spu') {
16006
- if (res.data.code === 200) {
16007
- // return res.data
16008
- realRes = {
16009
- code: res.data.code,
16010
- data: res.data.data,
16011
- msg: res.data.msg,
16012
- message: res.data.msg
16013
- };
16014
- return realRes;
16015
- } else {
16016
- realRes = {
16017
- code: res.data.code,
16018
- data: res.data.data,
16019
- msg: res.data.msg || '网络异常,请稍后重试。',
16020
- message: res.data.msg || '网络异常,请稍后重试。'
16021
- };
16022
- // const isShowErrorMessage = get(res, 'config.isShowErrorMessage', true)
16023
- // isShowErrorMessage && Message.error(realRes.msg)
16024
- return Promise.reject(realRes);
16025
- }
16026
- } else if (type === 'normal') {
16027
- var _res$data, _res$data2, _res$data3;
16028
- realRes = {
16029
- code: res.status || 200,
16030
- data: ((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.resp_data) || res.data,
16031
- msg: ((_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : _res$data2.error_code) || '',
16032
- message: ((_res$data3 = res.data) === null || _res$data3 === void 0 ? void 0 : _res$data3.error_code) || ''
16033
- };
16034
- return realRes;
16035
- }
16036
- }, function (err) {
16037
- // err: AxiosError
16038
- // console.log(err)
16039
- // debugger
16083
+ }(), function (err) {
16040
16084
  var isShowLoading = get$1(err, 'config.isShowLoading', true);
16041
16085
  isShowLoading && loadding$1.close();
16086
+ // err: AxiosError
16042
16087
  // console.log(err)
16043
16088
  // debugger
16044
- var msg = '';
16045
- if (type === 'spu') {
16046
- msg = get$1(err, 'response.data.msg', '');
16047
- } else {
16048
- msg = get$1(err, 'response.data.error_code', '');
16049
- }
16050
- if (msg) {
16051
- err.message = msg;
16052
- } else {
16053
- var _err$response;
16054
- err.message = ((_err$response = err.response) === null || _err$response === void 0 ? void 0 : _err$response.statusText) || err.message || '网络异常,请稍后重试。';
16089
+ if (type !== 'normal') {
16090
+ var msg = '';
16091
+ if (type === 'spu') {
16092
+ msg = get$1(err, 'response.data.msg', '');
16093
+ } else if (type === 'apaas') {
16094
+ msg = get$1(err, 'response.data.error_code', '');
16095
+ } else ;
16096
+ if (msg) {
16097
+ err.message = msg;
16098
+ } else {
16099
+ var _err$response;
16100
+ err.message = ((_err$response = err.response) === null || _err$response === void 0 ? void 0 : _err$response.statusText) || err.message || '网络异常,请稍后重试。';
16101
+ }
16102
+ err.msg = err.message;
16103
+ // 对接口报错进行处理
16104
+ if (!checkErrorResponseIsLogin(type, err)) ;
16055
16105
  }
16056
- err.msg = err.message;
16057
16106
  return Promise.reject(err);
16058
16107
  });
16059
16108
  return axiosInstance;
16060
16109
  };
16110
+ // spuAxios: 针对spu接口的返回形式,调用接口加前缀 `/api/${config.modulekey}/${moduleData.data.moduleversion}` 状态码一直返回200,调用成功/错误基于返回的 data.code【200是成功】判断,返回数据放 data.data,错误信息放 data.msg,对返回数据进行包装,保证一致性
16111
+ // apaasAxios: 针对平台接口的返回形式,返回数据放 data.resp_data,错误信息放 data.error_code,对返回数据进行包装,保证一致性
16112
+ // normalAxios: 普通接口调用,除了必要的拦截器前置后置处理外,接口返回什么就是什么,不做包装
16061
16113
  var spuAxios = null;
16114
+ var apaasAxios = null;
16062
16115
  var normalAxios$1 = null;
16063
16116
  function installAxios(options) {
16064
- spuAxios = createAxiosInstance$1('spu', options);
16065
- normalAxios$1 = createAxiosInstance$1('normal', options);
16117
+ spuAxios = createAxiosInstance$1('spu');
16118
+ apaasAxios = createAxiosInstance$1('apaas');
16119
+ normalAxios$1 = createAxiosInstance$1('normal');
16066
16120
  }
16067
16121
 
16068
16122
  var CloudServ = /*#__PURE__*/function () {
@@ -16138,7 +16192,7 @@ var TenantSetting = /*#__PURE__*/function () {
16138
16192
  case 0:
16139
16193
  _context.prev = 0;
16140
16194
  _context.next = 3;
16141
- return normalAxios$1.post('/api/auth/tenantsettings', {
16195
+ return apaasAxios.post('/api/auth/tenantsettings', {
16142
16196
  tenantcode: tenantcode || ''
16143
16197
  }, {
16144
16198
  isSendToken: false,
@@ -16438,7 +16492,7 @@ function _getAndSetUserInfo() {
16438
16492
  case 0:
16439
16493
  _context6.prev = 0;
16440
16494
  _context6.next = 3;
16441
- return normalAxios$1.post('/api/teapi/rolepermission/account/getaccountinfo', {
16495
+ return apaasAxios.post('/api/teapi/rolepermission/account/getaccountinfo', {
16442
16496
  positionid: getUser('positioncode') || '',
16443
16497
  deviceinfo: '',
16444
16498
  sysversion: '',
@@ -16506,7 +16560,7 @@ function _getAndSetTenant() {
16506
16560
  case 0:
16507
16561
  _context7.prev = 0;
16508
16562
  _context7.next = 3;
16509
- return normalAxios$1.get('/api/auth/tenantlist', {}).then(function (res) {
16563
+ return apaasAxios.get('/api/auth/tenantlist', {}).then(function (res) {
16510
16564
  var _res$data;
16511
16565
  return res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.tenants;
16512
16566
  });
@@ -16560,7 +16614,7 @@ function updateToken() {
16560
16614
  var token = getToken();
16561
16615
  var refreshtoken = getRefreshToken();
16562
16616
  var sendToken = checkLoginByToken(token) ? token : refreshtoken;
16563
- return normalAxios$1.get('/api/auth/refreshtoken', {
16617
+ return apaasAxios.get('/api/auth/refreshtoken', {
16564
16618
  params: {
16565
16619
  refreshtoken: sendToken
16566
16620
  },
@@ -16839,7 +16893,7 @@ function singleLogin(_x3) {
16839
16893
  }
16840
16894
  function _singleLogin() {
16841
16895
  _singleLogin = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee8(query) {
16842
- var flag, token, refreshtoken, tokenexpires, envname, context, setBaseInfo, isneedlogin, loginRole, refreshTokenUser, tokenUser, nowEnvname, envData;
16896
+ var flag, token, refreshtoken, tokenexpires, envname, context, setBaseInfo, isneedlogin, loginRole, curUser, cacheUser, refreshTokenUser, tokenUser, nowEnvname, envData;
16843
16897
  return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
16844
16898
  while (1) switch (_context8.prev = _context8.next) {
16845
16899
  case 0:
@@ -16858,7 +16912,9 @@ function _singleLogin() {
16858
16912
  }
16859
16913
  };
16860
16914
  query = cloneDeep$1(query);
16861
- if (!globalOptions.isfixapptokenexpired) {
16915
+ // App SPUWebview 内用 Native-Api 获取token 而不是从 url 上取
16916
+ // 暂时只在 门户引擎 中启用 等门户引擎验证通过之后 再改成所有 SPU 默认
16917
+ if (!(globalOptions.isfixapptokenexpired && globalOptions.modulekey === 'portalEngine')) {
16862
16918
  _context8.next = 6;
16863
16919
  break;
16864
16920
  }
@@ -16874,141 +16930,153 @@ function _singleLogin() {
16874
16930
  envname = query.envname;
16875
16931
  context = query.context;
16876
16932
  if (!checkLoginByToken(token)) {
16877
- _context8.next = 65;
16933
+ _context8.next = 67;
16878
16934
  break;
16879
16935
  }
16880
16936
  isneedlogin = true; // 是否需要走单点登录流程
16881
16937
  loginRole = getRoleByToken(token);
16882
- if (loginRole === 'center') {
16883
- // 如果本地已经登录 query 登录参数与本地一致 说明是刚登录没多久【token也没刷新过】 视为已经登录 不需再走单点登录流程
16884
- // 之所以不强制校验 refreshtoken tokenexpires 是因为安装卸载配置页面有可能放在产品运营中心 没有这两字段
16885
- if (checkLogin() && token === getToken()) {
16886
- isneedlogin = false;
16887
- }
16888
- } else {
16889
- // 如果本地已经登录 且 query 登录参数与本地一致 说明是刚登录没多久【token也没刷新过】 视为已经登录 不需再走单点登录流程
16890
- if (checkLogin() && token === getToken() && refreshtoken === getRefreshToken() && tokenexpires === getTokenExpires()) {
16891
- isneedlogin = false;
16938
+ curUser = getUserByToken(token);
16939
+ cacheUser = getUserByToken(getToken()); // 如果本地已经登录
16940
+ if (checkLogin()) {
16941
+ // 产品运营中心单点登录只有 token
16942
+ if (loginRole === 'center') {
16943
+ if ((curUser === null || curUser === void 0 ? void 0 : curUser.userCode) === (cacheUser === null || cacheUser === void 0 ? void 0 : cacheUser.userCode) && (curUser === null || curUser === void 0 ? void 0 : curUser.appId) === (cacheUser === null || cacheUser === void 0 ? void 0 : cacheUser.appId)) {
16944
+ isneedlogin = false;
16945
+ }
16946
+ } else {
16947
+ // 不重复走单点登录的逻辑
16948
+ // 旧:判断当前单点登录的 token/refreshtoken/tokenexpires 是否与本地缓存的一致
16949
+ // 新:解析当前单点登录 token 中的 mbcode、tenantcode,如果与缓存的一致,说明本次登录与上次登录是同个人同个租户
16950
+ // 新逻辑暂时只用于超表
16951
+ if (globalOptions.modulekey === 'litheformspu' && globalOptions.isoptimizesingleloginlogic) {
16952
+ if ((curUser === null || curUser === void 0 ? void 0 : curUser.memberCode) === (cacheUser === null || cacheUser === void 0 ? void 0 : cacheUser.memberCode) && (curUser === null || curUser === void 0 ? void 0 : curUser.tenantCode) === (cacheUser === null || cacheUser === void 0 ? void 0 : cacheUser.tenantCode)) {
16953
+ isneedlogin = false;
16954
+ }
16955
+ } else {
16956
+ if (token === getToken() && refreshtoken === getRefreshToken() && tokenexpires === getTokenExpires()) {
16957
+ isneedlogin = false;
16958
+ }
16959
+ }
16892
16960
  }
16893
16961
  }
16894
16962
  // isneedlogin = true
16895
16963
  // debugger
16896
16964
  if (!isneedlogin) {
16897
- _context8.next = 62;
16965
+ _context8.next = 64;
16898
16966
  break;
16899
16967
  }
16900
16968
  setBaseInfo();
16901
16969
  // 单点登录写入 token 之后
16902
- _context8.prev = 18;
16970
+ _context8.prev = 20;
16903
16971
  if (!checkLogin()) {
16904
- _context8.next = 25;
16972
+ _context8.next = 27;
16905
16973
  break;
16906
16974
  }
16907
16975
  refreshTokenUser = getUserByToken(getRefreshToken());
16908
16976
  tokenUser = getUserByToken(getToken()); // 如果 refreshtoken 不完整【由于web端登录时 如果有选择租户或选择职位的情况 得到的 refreshtoken 是不完整】 则通过完整的 token 换取完整的 refreshtoken 如果不换的话 通过刷新 token 接口得到的 token 也变成不完整的了
16909
16977
  if (!(!(refreshTokenUser !== null && refreshTokenUser !== void 0 && refreshTokenUser.tokenId) && tokenUser !== null && tokenUser !== void 0 && tokenUser.tokenId)) {
16910
- _context8.next = 25;
16978
+ _context8.next = 27;
16911
16979
  break;
16912
16980
  }
16913
- _context8.next = 25;
16981
+ _context8.next = 27;
16914
16982
  return updateToken();
16915
- case 25:
16916
- _context8.next = 30;
16917
- break;
16918
16983
  case 27:
16919
- _context8.prev = 27;
16920
- _context8.t0 = _context8["catch"](18);
16921
- console.error(_context8.t0);
16922
- case 30:
16923
16984
  _context8.next = 32;
16924
- return getEnvname();
16985
+ break;
16986
+ case 29:
16987
+ _context8.prev = 29;
16988
+ _context8.t0 = _context8["catch"](20);
16989
+ console.error(_context8.t0);
16925
16990
  case 32:
16991
+ _context8.next = 34;
16992
+ return getEnvname();
16993
+ case 34:
16926
16994
  nowEnvname = _context8.sent;
16927
16995
  if (!nowEnvname) {
16928
- _context8.next = 53;
16996
+ _context8.next = 55;
16929
16997
  break;
16930
16998
  }
16931
- _context8.next = 36;
16999
+ _context8.next = 38;
16932
17000
  return requestEnvdata(nowEnvname);
16933
- case 36:
17001
+ case 38:
16934
17002
  envData = _context8.sent;
16935
17003
  if (!envData) {
16936
- _context8.next = 49;
17004
+ _context8.next = 51;
16937
17005
  break;
16938
17006
  }
16939
17007
  saveEnvdata(envData);
16940
17008
  if (!envData.tenantcode) {
16941
- _context8.next = 45;
17009
+ _context8.next = 47;
16942
17010
  break;
16943
17011
  }
16944
17012
  setTecode(envData.tenantcode);
16945
17013
  // 租户配置
16946
- _context8.next = 43;
17014
+ _context8.next = 45;
16947
17015
  return tenantSetting.requestAndSetTenantSetting(envData.tenantcode);
16948
- case 43:
16949
- _context8.next = 47;
16950
- break;
16951
17016
  case 45:
17017
+ _context8.next = 49;
17018
+ break;
17019
+ case 47:
16952
17020
  tenantSetting.removeTenantSetting();
16953
17021
  removeTecode();
16954
- case 47:
16955
- _context8.next = 51;
16956
- break;
16957
17022
  case 49:
17023
+ _context8.next = 53;
17024
+ break;
17025
+ case 51:
16958
17026
  removeEnvdata();
16959
17027
  removeTecode();
16960
- case 51:
16961
- _context8.next = 55;
16962
- break;
16963
17028
  case 53:
17029
+ _context8.next = 57;
17030
+ break;
17031
+ case 55:
16964
17032
  removeEnvdata();
16965
17033
  removeTecode();
16966
- case 55:
16967
- _context8.next = 57;
16968
- return getAndSetTenant();
16969
17034
  case 57:
16970
17035
  _context8.next = 59;
16971
- return getAndSetUserInfo();
17036
+ return getAndSetTenant();
16972
17037
  case 59:
17038
+ _context8.next = 61;
17039
+ return getAndSetUserInfo();
17040
+ case 61:
16973
17041
  flag = true;
16974
- _context8.next = 63;
17042
+ _context8.next = 65;
16975
17043
  break;
16976
- case 62:
17044
+ case 64:
16977
17045
  flag = true;
16978
- case 63:
16979
- _context8.next = 68;
16980
- break;
16981
17046
  case 65:
17047
+ _context8.next = 70;
17048
+ break;
17049
+ case 67:
16982
17050
  flag = false;
16983
17051
  setBaseInfo(); // 传递的token过期依然写入 如果不写入的话 有可能之前的token本来没过期 页面依然可用
16984
17052
  console.error('单点登录失败,请检查链接所传 token/refreshtoken/tokenexpires 是否非法或过期。');
16985
- case 68:
17053
+ case 70:
16986
17054
  if (!flag) {
16987
- _context8.next = 77;
17055
+ _context8.next = 79;
16988
17056
  break;
16989
17057
  }
16990
17058
  // 启动刷新token机制
16991
17059
  startRefreshtoken();
16992
17060
  // 获取spu 信息
16993
- _context8.next = 72;
17061
+ _context8.next = 74;
16994
17062
  return core$1.initGetData();
16995
- case 72:
17063
+ case 74:
16996
17064
  // 删除 query 中相关参数
16997
17065
  token && delete query.token;
16998
17066
  refreshtoken && delete query.refreshtoken;
16999
17067
  tokenexpires && delete query.tokenexpires;
17000
17068
  envname && delete query.envname;
17001
17069
  context && delete query.context;
17002
- case 77:
17070
+ case 79:
17003
17071
  return _context8.abrupt("return", {
17004
17072
  flag: flag,
17005
17073
  query: query
17006
17074
  });
17007
- case 78:
17075
+ case 80:
17008
17076
  case "end":
17009
17077
  return _context8.stop();
17010
17078
  }
17011
- }, _callee8, null, [[18, 27]]);
17079
+ }, _callee8, null, [[20, 29]]);
17012
17080
  }));
17013
17081
  return _singleLogin.apply(this, arguments);
17014
17082
  }
@@ -17193,7 +17261,7 @@ var getServerTime = function getServerTime() {
17193
17261
  }
17194
17262
  });
17195
17263
  } else {
17196
- normalAxios$1.get('/api/teapi/offline/servertime', {}, {
17264
+ apaasAxios.get('/api/teapi/offline/servertime', {}, {
17197
17265
  isShowLoading: false
17198
17266
  }).then(function (res) {
17199
17267
  if (res.data) {
@@ -17207,6 +17275,49 @@ var getServerTime = function getServerTime() {
17207
17275
  }
17208
17276
  });
17209
17277
  };
17278
+ // 精准判断是否能访问业务服务器(结合 navigator.onLine + 接口请求)
17279
+ var isOnline = /*#__PURE__*/function () {
17280
+ var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
17281
+ var pingUrl,
17282
+ response,
17283
+ _args = arguments;
17284
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
17285
+ while (1) switch (_context.prev = _context.next) {
17286
+ case 0:
17287
+ pingUrl = _args.length > 0 && _args[0] !== undefined ? _args[0] : './';
17288
+ if (navigator.onLine) {
17289
+ _context.next = 3;
17290
+ break;
17291
+ }
17292
+ return _context.abrupt("return", false);
17293
+ case 3:
17294
+ _context.prev = 3;
17295
+ _context.next = 6;
17296
+ return fetch(pingUrl, {
17297
+ method: 'GET',
17298
+ credentials: 'omit',
17299
+ mode: 'cors',
17300
+ cache: 'no-store' // 禁用缓存,保证实时性
17301
+ // cache: 'default'
17302
+ // signal: AbortSignal.timeout(3000) // 超时取消
17303
+ });
17304
+ case 6:
17305
+ response = _context.sent;
17306
+ return _context.abrupt("return", response.ok);
17307
+ case 10:
17308
+ _context.prev = 10;
17309
+ _context.t0 = _context["catch"](3);
17310
+ return _context.abrupt("return", false);
17311
+ case 13:
17312
+ case "end":
17313
+ return _context.stop();
17314
+ }
17315
+ }, _callee, null, [[3, 10]]);
17316
+ }));
17317
+ return function isOnline() {
17318
+ return _ref.apply(this, arguments);
17319
+ };
17320
+ }();
17210
17321
 
17211
17322
  var Urlquery = /*#__PURE__*/function () {
17212
17323
  function Urlquery() {
@@ -18773,6 +18884,3246 @@ var getDistance = /*#__PURE__*/function () {
18773
18884
  };
18774
18885
  }();
18775
18886
 
18887
+ var localforage$1 = {exports: {}};
18888
+
18889
+ /*!
18890
+ localForage -- Offline Storage, Improved
18891
+ Version 1.10.0
18892
+ https://localforage.github.io/localForage
18893
+ (c) 2013-2017 Mozilla, Apache License 2.0
18894
+ */
18895
+
18896
+ (function (module, exports) {
18897
+ (function(f){{module.exports=f();}})(function(){return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof commonjsRequire=="function"&&commonjsRequire;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw (f.code="MODULE_NOT_FOUND", f)}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r);}return n[o].exports}var i=typeof commonjsRequire=="function"&&commonjsRequire;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
18898
+ (function (global){
18899
+ var Mutation = global.MutationObserver || global.WebKitMutationObserver;
18900
+
18901
+ var scheduleDrain;
18902
+
18903
+ {
18904
+ if (Mutation) {
18905
+ var called = 0;
18906
+ var observer = new Mutation(nextTick);
18907
+ var element = global.document.createTextNode('');
18908
+ observer.observe(element, {
18909
+ characterData: true
18910
+ });
18911
+ scheduleDrain = function () {
18912
+ element.data = (called = ++called % 2);
18913
+ };
18914
+ } else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
18915
+ var channel = new global.MessageChannel();
18916
+ channel.port1.onmessage = nextTick;
18917
+ scheduleDrain = function () {
18918
+ channel.port2.postMessage(0);
18919
+ };
18920
+ } else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
18921
+ scheduleDrain = function () {
18922
+
18923
+ // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
18924
+ // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
18925
+ var scriptEl = global.document.createElement('script');
18926
+ scriptEl.onreadystatechange = function () {
18927
+ nextTick();
18928
+
18929
+ scriptEl.onreadystatechange = null;
18930
+ scriptEl.parentNode.removeChild(scriptEl);
18931
+ scriptEl = null;
18932
+ };
18933
+ global.document.documentElement.appendChild(scriptEl);
18934
+ };
18935
+ } else {
18936
+ scheduleDrain = function () {
18937
+ setTimeout(nextTick, 0);
18938
+ };
18939
+ }
18940
+ }
18941
+
18942
+ var draining;
18943
+ var queue = [];
18944
+ //named nextTick for less confusing stack traces
18945
+ function nextTick() {
18946
+ draining = true;
18947
+ var i, oldQueue;
18948
+ var len = queue.length;
18949
+ while (len) {
18950
+ oldQueue = queue;
18951
+ queue = [];
18952
+ i = -1;
18953
+ while (++i < len) {
18954
+ oldQueue[i]();
18955
+ }
18956
+ len = queue.length;
18957
+ }
18958
+ draining = false;
18959
+ }
18960
+
18961
+ module.exports = immediate;
18962
+ function immediate(task) {
18963
+ if (queue.push(task) === 1 && !draining) {
18964
+ scheduleDrain();
18965
+ }
18966
+ }
18967
+
18968
+ }).call(this,typeof commonjsGlobal !== "undefined" ? commonjsGlobal : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
18969
+ },{}],2:[function(_dereq_,module,exports){
18970
+ var immediate = _dereq_(1);
18971
+
18972
+ /* istanbul ignore next */
18973
+ function INTERNAL() {}
18974
+
18975
+ var handlers = {};
18976
+
18977
+ var REJECTED = ['REJECTED'];
18978
+ var FULFILLED = ['FULFILLED'];
18979
+ var PENDING = ['PENDING'];
18980
+
18981
+ module.exports = Promise;
18982
+
18983
+ function Promise(resolver) {
18984
+ if (typeof resolver !== 'function') {
18985
+ throw new TypeError('resolver must be a function');
18986
+ }
18987
+ this.state = PENDING;
18988
+ this.queue = [];
18989
+ this.outcome = void 0;
18990
+ if (resolver !== INTERNAL) {
18991
+ safelyResolveThenable(this, resolver);
18992
+ }
18993
+ }
18994
+
18995
+ Promise.prototype["catch"] = function (onRejected) {
18996
+ return this.then(null, onRejected);
18997
+ };
18998
+ Promise.prototype.then = function (onFulfilled, onRejected) {
18999
+ if (typeof onFulfilled !== 'function' && this.state === FULFILLED ||
19000
+ typeof onRejected !== 'function' && this.state === REJECTED) {
19001
+ return this;
19002
+ }
19003
+ var promise = new this.constructor(INTERNAL);
19004
+ if (this.state !== PENDING) {
19005
+ var resolver = this.state === FULFILLED ? onFulfilled : onRejected;
19006
+ unwrap(promise, resolver, this.outcome);
19007
+ } else {
19008
+ this.queue.push(new QueueItem(promise, onFulfilled, onRejected));
19009
+ }
19010
+
19011
+ return promise;
19012
+ };
19013
+ function QueueItem(promise, onFulfilled, onRejected) {
19014
+ this.promise = promise;
19015
+ if (typeof onFulfilled === 'function') {
19016
+ this.onFulfilled = onFulfilled;
19017
+ this.callFulfilled = this.otherCallFulfilled;
19018
+ }
19019
+ if (typeof onRejected === 'function') {
19020
+ this.onRejected = onRejected;
19021
+ this.callRejected = this.otherCallRejected;
19022
+ }
19023
+ }
19024
+ QueueItem.prototype.callFulfilled = function (value) {
19025
+ handlers.resolve(this.promise, value);
19026
+ };
19027
+ QueueItem.prototype.otherCallFulfilled = function (value) {
19028
+ unwrap(this.promise, this.onFulfilled, value);
19029
+ };
19030
+ QueueItem.prototype.callRejected = function (value) {
19031
+ handlers.reject(this.promise, value);
19032
+ };
19033
+ QueueItem.prototype.otherCallRejected = function (value) {
19034
+ unwrap(this.promise, this.onRejected, value);
19035
+ };
19036
+
19037
+ function unwrap(promise, func, value) {
19038
+ immediate(function () {
19039
+ var returnValue;
19040
+ try {
19041
+ returnValue = func(value);
19042
+ } catch (e) {
19043
+ return handlers.reject(promise, e);
19044
+ }
19045
+ if (returnValue === promise) {
19046
+ handlers.reject(promise, new TypeError('Cannot resolve promise with itself'));
19047
+ } else {
19048
+ handlers.resolve(promise, returnValue);
19049
+ }
19050
+ });
19051
+ }
19052
+
19053
+ handlers.resolve = function (self, value) {
19054
+ var result = tryCatch(getThen, value);
19055
+ if (result.status === 'error') {
19056
+ return handlers.reject(self, result.value);
19057
+ }
19058
+ var thenable = result.value;
19059
+
19060
+ if (thenable) {
19061
+ safelyResolveThenable(self, thenable);
19062
+ } else {
19063
+ self.state = FULFILLED;
19064
+ self.outcome = value;
19065
+ var i = -1;
19066
+ var len = self.queue.length;
19067
+ while (++i < len) {
19068
+ self.queue[i].callFulfilled(value);
19069
+ }
19070
+ }
19071
+ return self;
19072
+ };
19073
+ handlers.reject = function (self, error) {
19074
+ self.state = REJECTED;
19075
+ self.outcome = error;
19076
+ var i = -1;
19077
+ var len = self.queue.length;
19078
+ while (++i < len) {
19079
+ self.queue[i].callRejected(error);
19080
+ }
19081
+ return self;
19082
+ };
19083
+
19084
+ function getThen(obj) {
19085
+ // Make sure we only access the accessor once as required by the spec
19086
+ var then = obj && obj.then;
19087
+ if (obj && (typeof obj === 'object' || typeof obj === 'function') && typeof then === 'function') {
19088
+ return function appyThen() {
19089
+ then.apply(obj, arguments);
19090
+ };
19091
+ }
19092
+ }
19093
+
19094
+ function safelyResolveThenable(self, thenable) {
19095
+ // Either fulfill, reject or reject with error
19096
+ var called = false;
19097
+ function onError(value) {
19098
+ if (called) {
19099
+ return;
19100
+ }
19101
+ called = true;
19102
+ handlers.reject(self, value);
19103
+ }
19104
+
19105
+ function onSuccess(value) {
19106
+ if (called) {
19107
+ return;
19108
+ }
19109
+ called = true;
19110
+ handlers.resolve(self, value);
19111
+ }
19112
+
19113
+ function tryToUnwrap() {
19114
+ thenable(onSuccess, onError);
19115
+ }
19116
+
19117
+ var result = tryCatch(tryToUnwrap);
19118
+ if (result.status === 'error') {
19119
+ onError(result.value);
19120
+ }
19121
+ }
19122
+
19123
+ function tryCatch(func, value) {
19124
+ var out = {};
19125
+ try {
19126
+ out.value = func(value);
19127
+ out.status = 'success';
19128
+ } catch (e) {
19129
+ out.status = 'error';
19130
+ out.value = e;
19131
+ }
19132
+ return out;
19133
+ }
19134
+
19135
+ Promise.resolve = resolve;
19136
+ function resolve(value) {
19137
+ if (value instanceof this) {
19138
+ return value;
19139
+ }
19140
+ return handlers.resolve(new this(INTERNAL), value);
19141
+ }
19142
+
19143
+ Promise.reject = reject;
19144
+ function reject(reason) {
19145
+ var promise = new this(INTERNAL);
19146
+ return handlers.reject(promise, reason);
19147
+ }
19148
+
19149
+ Promise.all = all;
19150
+ function all(iterable) {
19151
+ var self = this;
19152
+ if (Object.prototype.toString.call(iterable) !== '[object Array]') {
19153
+ return this.reject(new TypeError('must be an array'));
19154
+ }
19155
+
19156
+ var len = iterable.length;
19157
+ var called = false;
19158
+ if (!len) {
19159
+ return this.resolve([]);
19160
+ }
19161
+
19162
+ var values = new Array(len);
19163
+ var resolved = 0;
19164
+ var i = -1;
19165
+ var promise = new this(INTERNAL);
19166
+
19167
+ while (++i < len) {
19168
+ allResolver(iterable[i], i);
19169
+ }
19170
+ return promise;
19171
+ function allResolver(value, i) {
19172
+ self.resolve(value).then(resolveFromAll, function (error) {
19173
+ if (!called) {
19174
+ called = true;
19175
+ handlers.reject(promise, error);
19176
+ }
19177
+ });
19178
+ function resolveFromAll(outValue) {
19179
+ values[i] = outValue;
19180
+ if (++resolved === len && !called) {
19181
+ called = true;
19182
+ handlers.resolve(promise, values);
19183
+ }
19184
+ }
19185
+ }
19186
+ }
19187
+
19188
+ Promise.race = race;
19189
+ function race(iterable) {
19190
+ var self = this;
19191
+ if (Object.prototype.toString.call(iterable) !== '[object Array]') {
19192
+ return this.reject(new TypeError('must be an array'));
19193
+ }
19194
+
19195
+ var len = iterable.length;
19196
+ var called = false;
19197
+ if (!len) {
19198
+ return this.resolve([]);
19199
+ }
19200
+
19201
+ var i = -1;
19202
+ var promise = new this(INTERNAL);
19203
+
19204
+ while (++i < len) {
19205
+ resolver(iterable[i]);
19206
+ }
19207
+ return promise;
19208
+ function resolver(value) {
19209
+ self.resolve(value).then(function (response) {
19210
+ if (!called) {
19211
+ called = true;
19212
+ handlers.resolve(promise, response);
19213
+ }
19214
+ }, function (error) {
19215
+ if (!called) {
19216
+ called = true;
19217
+ handlers.reject(promise, error);
19218
+ }
19219
+ });
19220
+ }
19221
+ }
19222
+
19223
+ },{"1":1}],3:[function(_dereq_,module,exports){
19224
+ (function (global){
19225
+ if (typeof global.Promise !== 'function') {
19226
+ global.Promise = _dereq_(2);
19227
+ }
19228
+
19229
+ }).call(this,typeof commonjsGlobal !== "undefined" ? commonjsGlobal : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
19230
+ },{"2":2}],4:[function(_dereq_,module,exports){
19231
+
19232
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
19233
+
19234
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19235
+
19236
+ function getIDB() {
19237
+ /* global indexedDB,webkitIndexedDB,mozIndexedDB,OIndexedDB,msIndexedDB */
19238
+ try {
19239
+ if (typeof indexedDB !== 'undefined') {
19240
+ return indexedDB;
19241
+ }
19242
+ if (typeof webkitIndexedDB !== 'undefined') {
19243
+ return webkitIndexedDB;
19244
+ }
19245
+ if (typeof mozIndexedDB !== 'undefined') {
19246
+ return mozIndexedDB;
19247
+ }
19248
+ if (typeof OIndexedDB !== 'undefined') {
19249
+ return OIndexedDB;
19250
+ }
19251
+ if (typeof msIndexedDB !== 'undefined') {
19252
+ return msIndexedDB;
19253
+ }
19254
+ } catch (e) {
19255
+ return;
19256
+ }
19257
+ }
19258
+
19259
+ var idb = getIDB();
19260
+
19261
+ function isIndexedDBValid() {
19262
+ try {
19263
+ // Initialize IndexedDB; fall back to vendor-prefixed versions
19264
+ // if needed.
19265
+ if (!idb || !idb.open) {
19266
+ return false;
19267
+ }
19268
+ // We mimic PouchDB here;
19269
+ //
19270
+ // We test for openDatabase because IE Mobile identifies itself
19271
+ // as Safari. Oh the lulz...
19272
+ var isSafari = typeof openDatabase !== 'undefined' && /(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent) && !/BlackBerry/.test(navigator.platform);
19273
+
19274
+ var hasFetch = typeof fetch === 'function' && fetch.toString().indexOf('[native code') !== -1;
19275
+
19276
+ // Safari <10.1 does not meet our requirements for IDB support
19277
+ // (see: https://github.com/pouchdb/pouchdb/issues/5572).
19278
+ // Safari 10.1 shipped with fetch, we can use that to detect it.
19279
+ // Note: this creates issues with `window.fetch` polyfills and
19280
+ // overrides; see:
19281
+ // https://github.com/localForage/localForage/issues/856
19282
+ return (!isSafari || hasFetch) && typeof indexedDB !== 'undefined' &&
19283
+ // some outdated implementations of IDB that appear on Samsung
19284
+ // and HTC Android devices <4.4 are missing IDBKeyRange
19285
+ // See: https://github.com/mozilla/localForage/issues/128
19286
+ // See: https://github.com/mozilla/localForage/issues/272
19287
+ typeof IDBKeyRange !== 'undefined';
19288
+ } catch (e) {
19289
+ return false;
19290
+ }
19291
+ }
19292
+
19293
+ // Abstracts constructing a Blob object, so it also works in older
19294
+ // browsers that don't support the native Blob constructor. (i.e.
19295
+ // old QtWebKit versions, at least).
19296
+ // Abstracts constructing a Blob object, so it also works in older
19297
+ // browsers that don't support the native Blob constructor. (i.e.
19298
+ // old QtWebKit versions, at least).
19299
+ function createBlob(parts, properties) {
19300
+ /* global BlobBuilder,MSBlobBuilder,MozBlobBuilder,WebKitBlobBuilder */
19301
+ parts = parts || [];
19302
+ properties = properties || {};
19303
+ try {
19304
+ return new Blob(parts, properties);
19305
+ } catch (e) {
19306
+ if (e.name !== 'TypeError') {
19307
+ throw e;
19308
+ }
19309
+ var Builder = typeof BlobBuilder !== 'undefined' ? BlobBuilder : typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder : typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder : WebKitBlobBuilder;
19310
+ var builder = new Builder();
19311
+ for (var i = 0; i < parts.length; i += 1) {
19312
+ builder.append(parts[i]);
19313
+ }
19314
+ return builder.getBlob(properties.type);
19315
+ }
19316
+ }
19317
+
19318
+ // This is CommonJS because lie is an external dependency, so Rollup
19319
+ // can just ignore it.
19320
+ if (typeof Promise === 'undefined') {
19321
+ // In the "nopromises" build this will just throw if you don't have
19322
+ // a global promise object, but it would throw anyway later.
19323
+ _dereq_(3);
19324
+ }
19325
+ var Promise$1 = Promise;
19326
+
19327
+ function executeCallback(promise, callback) {
19328
+ if (callback) {
19329
+ promise.then(function (result) {
19330
+ callback(null, result);
19331
+ }, function (error) {
19332
+ callback(error);
19333
+ });
19334
+ }
19335
+ }
19336
+
19337
+ function executeTwoCallbacks(promise, callback, errorCallback) {
19338
+ if (typeof callback === 'function') {
19339
+ promise.then(callback);
19340
+ }
19341
+
19342
+ if (typeof errorCallback === 'function') {
19343
+ promise["catch"](errorCallback);
19344
+ }
19345
+ }
19346
+
19347
+ function normalizeKey(key) {
19348
+ // Cast the key to a string, as that's all we can set as a key.
19349
+ if (typeof key !== 'string') {
19350
+ console.warn(key + ' used as a key, but it is not a string.');
19351
+ key = String(key);
19352
+ }
19353
+
19354
+ return key;
19355
+ }
19356
+
19357
+ function getCallback() {
19358
+ if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
19359
+ return arguments[arguments.length - 1];
19360
+ }
19361
+ }
19362
+
19363
+ // Some code originally from async_storage.js in
19364
+ // [Gaia](https://github.com/mozilla-b2g/gaia).
19365
+
19366
+ var DETECT_BLOB_SUPPORT_STORE = 'local-forage-detect-blob-support';
19367
+ var supportsBlobs = void 0;
19368
+ var dbContexts = {};
19369
+ var toString = Object.prototype.toString;
19370
+
19371
+ // Transaction Modes
19372
+ var READ_ONLY = 'readonly';
19373
+ var READ_WRITE = 'readwrite';
19374
+
19375
+ // Transform a binary string to an array buffer, because otherwise
19376
+ // weird stuff happens when you try to work with the binary string directly.
19377
+ // It is known.
19378
+ // From http://stackoverflow.com/questions/14967647/ (continues on next line)
19379
+ // encode-decode-image-with-base64-breaks-image (2013-04-21)
19380
+ function _binStringToArrayBuffer(bin) {
19381
+ var length = bin.length;
19382
+ var buf = new ArrayBuffer(length);
19383
+ var arr = new Uint8Array(buf);
19384
+ for (var i = 0; i < length; i++) {
19385
+ arr[i] = bin.charCodeAt(i);
19386
+ }
19387
+ return buf;
19388
+ }
19389
+
19390
+ //
19391
+ // Blobs are not supported in all versions of IndexedDB, notably
19392
+ // Chrome <37 and Android <5. In those versions, storing a blob will throw.
19393
+ //
19394
+ // Various other blob bugs exist in Chrome v37-42 (inclusive).
19395
+ // Detecting them is expensive and confusing to users, and Chrome 37-42
19396
+ // is at very low usage worldwide, so we do a hacky userAgent check instead.
19397
+ //
19398
+ // content-type bug: https://code.google.com/p/chromium/issues/detail?id=408120
19399
+ // 404 bug: https://code.google.com/p/chromium/issues/detail?id=447916
19400
+ // FileReader bug: https://code.google.com/p/chromium/issues/detail?id=447836
19401
+ //
19402
+ // Code borrowed from PouchDB. See:
19403
+ // https://github.com/pouchdb/pouchdb/blob/master/packages/node_modules/pouchdb-adapter-idb/src/blobSupport.js
19404
+ //
19405
+ function _checkBlobSupportWithoutCaching(idb) {
19406
+ return new Promise$1(function (resolve) {
19407
+ var txn = idb.transaction(DETECT_BLOB_SUPPORT_STORE, READ_WRITE);
19408
+ var blob = createBlob(['']);
19409
+ txn.objectStore(DETECT_BLOB_SUPPORT_STORE).put(blob, 'key');
19410
+
19411
+ txn.onabort = function (e) {
19412
+ // If the transaction aborts now its due to not being able to
19413
+ // write to the database, likely due to the disk being full
19414
+ e.preventDefault();
19415
+ e.stopPropagation();
19416
+ resolve(false);
19417
+ };
19418
+
19419
+ txn.oncomplete = function () {
19420
+ var matchedChrome = navigator.userAgent.match(/Chrome\/(\d+)/);
19421
+ var matchedEdge = navigator.userAgent.match(/Edge\//);
19422
+ // MS Edge pretends to be Chrome 42:
19423
+ // https://msdn.microsoft.com/en-us/library/hh869301%28v=vs.85%29.aspx
19424
+ resolve(matchedEdge || !matchedChrome || parseInt(matchedChrome[1], 10) >= 43);
19425
+ };
19426
+ })["catch"](function () {
19427
+ return false; // error, so assume unsupported
19428
+ });
19429
+ }
19430
+
19431
+ function _checkBlobSupport(idb) {
19432
+ if (typeof supportsBlobs === 'boolean') {
19433
+ return Promise$1.resolve(supportsBlobs);
19434
+ }
19435
+ return _checkBlobSupportWithoutCaching(idb).then(function (value) {
19436
+ supportsBlobs = value;
19437
+ return supportsBlobs;
19438
+ });
19439
+ }
19440
+
19441
+ function _deferReadiness(dbInfo) {
19442
+ var dbContext = dbContexts[dbInfo.name];
19443
+
19444
+ // Create a deferred object representing the current database operation.
19445
+ var deferredOperation = {};
19446
+
19447
+ deferredOperation.promise = new Promise$1(function (resolve, reject) {
19448
+ deferredOperation.resolve = resolve;
19449
+ deferredOperation.reject = reject;
19450
+ });
19451
+
19452
+ // Enqueue the deferred operation.
19453
+ dbContext.deferredOperations.push(deferredOperation);
19454
+
19455
+ // Chain its promise to the database readiness.
19456
+ if (!dbContext.dbReady) {
19457
+ dbContext.dbReady = deferredOperation.promise;
19458
+ } else {
19459
+ dbContext.dbReady = dbContext.dbReady.then(function () {
19460
+ return deferredOperation.promise;
19461
+ });
19462
+ }
19463
+ }
19464
+
19465
+ function _advanceReadiness(dbInfo) {
19466
+ var dbContext = dbContexts[dbInfo.name];
19467
+
19468
+ // Dequeue a deferred operation.
19469
+ var deferredOperation = dbContext.deferredOperations.pop();
19470
+
19471
+ // Resolve its promise (which is part of the database readiness
19472
+ // chain of promises).
19473
+ if (deferredOperation) {
19474
+ deferredOperation.resolve();
19475
+ return deferredOperation.promise;
19476
+ }
19477
+ }
19478
+
19479
+ function _rejectReadiness(dbInfo, err) {
19480
+ var dbContext = dbContexts[dbInfo.name];
19481
+
19482
+ // Dequeue a deferred operation.
19483
+ var deferredOperation = dbContext.deferredOperations.pop();
19484
+
19485
+ // Reject its promise (which is part of the database readiness
19486
+ // chain of promises).
19487
+ if (deferredOperation) {
19488
+ deferredOperation.reject(err);
19489
+ return deferredOperation.promise;
19490
+ }
19491
+ }
19492
+
19493
+ function _getConnection(dbInfo, upgradeNeeded) {
19494
+ return new Promise$1(function (resolve, reject) {
19495
+ dbContexts[dbInfo.name] = dbContexts[dbInfo.name] || createDbContext();
19496
+
19497
+ if (dbInfo.db) {
19498
+ if (upgradeNeeded) {
19499
+ _deferReadiness(dbInfo);
19500
+ dbInfo.db.close();
19501
+ } else {
19502
+ return resolve(dbInfo.db);
19503
+ }
19504
+ }
19505
+
19506
+ var dbArgs = [dbInfo.name];
19507
+
19508
+ if (upgradeNeeded) {
19509
+ dbArgs.push(dbInfo.version);
19510
+ }
19511
+
19512
+ var openreq = idb.open.apply(idb, dbArgs);
19513
+
19514
+ if (upgradeNeeded) {
19515
+ openreq.onupgradeneeded = function (e) {
19516
+ var db = openreq.result;
19517
+ try {
19518
+ db.createObjectStore(dbInfo.storeName);
19519
+ if (e.oldVersion <= 1) {
19520
+ // Added when support for blob shims was added
19521
+ db.createObjectStore(DETECT_BLOB_SUPPORT_STORE);
19522
+ }
19523
+ } catch (ex) {
19524
+ if (ex.name === 'ConstraintError') {
19525
+ console.warn('The database "' + dbInfo.name + '"' + ' has been upgraded from version ' + e.oldVersion + ' to version ' + e.newVersion + ', but the storage "' + dbInfo.storeName + '" already exists.');
19526
+ } else {
19527
+ throw ex;
19528
+ }
19529
+ }
19530
+ };
19531
+ }
19532
+
19533
+ openreq.onerror = function (e) {
19534
+ e.preventDefault();
19535
+ reject(openreq.error);
19536
+ };
19537
+
19538
+ openreq.onsuccess = function () {
19539
+ var db = openreq.result;
19540
+ db.onversionchange = function (e) {
19541
+ // Triggered when the database is modified (e.g. adding an objectStore) or
19542
+ // deleted (even when initiated by other sessions in different tabs).
19543
+ // Closing the connection here prevents those operations from being blocked.
19544
+ // If the database is accessed again later by this instance, the connection
19545
+ // will be reopened or the database recreated as needed.
19546
+ e.target.close();
19547
+ };
19548
+ resolve(db);
19549
+ _advanceReadiness(dbInfo);
19550
+ };
19551
+ });
19552
+ }
19553
+
19554
+ function _getOriginalConnection(dbInfo) {
19555
+ return _getConnection(dbInfo, false);
19556
+ }
19557
+
19558
+ function _getUpgradedConnection(dbInfo) {
19559
+ return _getConnection(dbInfo, true);
19560
+ }
19561
+
19562
+ function _isUpgradeNeeded(dbInfo, defaultVersion) {
19563
+ if (!dbInfo.db) {
19564
+ return true;
19565
+ }
19566
+
19567
+ var isNewStore = !dbInfo.db.objectStoreNames.contains(dbInfo.storeName);
19568
+ var isDowngrade = dbInfo.version < dbInfo.db.version;
19569
+ var isUpgrade = dbInfo.version > dbInfo.db.version;
19570
+
19571
+ if (isDowngrade) {
19572
+ // If the version is not the default one
19573
+ // then warn for impossible downgrade.
19574
+ if (dbInfo.version !== defaultVersion) {
19575
+ console.warn('The database "' + dbInfo.name + '"' + " can't be downgraded from version " + dbInfo.db.version + ' to version ' + dbInfo.version + '.');
19576
+ }
19577
+ // Align the versions to prevent errors.
19578
+ dbInfo.version = dbInfo.db.version;
19579
+ }
19580
+
19581
+ if (isUpgrade || isNewStore) {
19582
+ // If the store is new then increment the version (if needed).
19583
+ // This will trigger an "upgradeneeded" event which is required
19584
+ // for creating a store.
19585
+ if (isNewStore) {
19586
+ var incVersion = dbInfo.db.version + 1;
19587
+ if (incVersion > dbInfo.version) {
19588
+ dbInfo.version = incVersion;
19589
+ }
19590
+ }
19591
+
19592
+ return true;
19593
+ }
19594
+
19595
+ return false;
19596
+ }
19597
+
19598
+ // encode a blob for indexeddb engines that don't support blobs
19599
+ function _encodeBlob(blob) {
19600
+ return new Promise$1(function (resolve, reject) {
19601
+ var reader = new FileReader();
19602
+ reader.onerror = reject;
19603
+ reader.onloadend = function (e) {
19604
+ var base64 = btoa(e.target.result || '');
19605
+ resolve({
19606
+ __local_forage_encoded_blob: true,
19607
+ data: base64,
19608
+ type: blob.type
19609
+ });
19610
+ };
19611
+ reader.readAsBinaryString(blob);
19612
+ });
19613
+ }
19614
+
19615
+ // decode an encoded blob
19616
+ function _decodeBlob(encodedBlob) {
19617
+ var arrayBuff = _binStringToArrayBuffer(atob(encodedBlob.data));
19618
+ return createBlob([arrayBuff], { type: encodedBlob.type });
19619
+ }
19620
+
19621
+ // is this one of our fancy encoded blobs?
19622
+ function _isEncodedBlob(value) {
19623
+ return value && value.__local_forage_encoded_blob;
19624
+ }
19625
+
19626
+ // Specialize the default `ready()` function by making it dependent
19627
+ // on the current database operations. Thus, the driver will be actually
19628
+ // ready when it's been initialized (default) *and* there are no pending
19629
+ // operations on the database (initiated by some other instances).
19630
+ function _fullyReady(callback) {
19631
+ var self = this;
19632
+
19633
+ var promise = self._initReady().then(function () {
19634
+ var dbContext = dbContexts[self._dbInfo.name];
19635
+
19636
+ if (dbContext && dbContext.dbReady) {
19637
+ return dbContext.dbReady;
19638
+ }
19639
+ });
19640
+
19641
+ executeTwoCallbacks(promise, callback, callback);
19642
+ return promise;
19643
+ }
19644
+
19645
+ // Try to establish a new db connection to replace the
19646
+ // current one which is broken (i.e. experiencing
19647
+ // InvalidStateError while creating a transaction).
19648
+ function _tryReconnect(dbInfo) {
19649
+ _deferReadiness(dbInfo);
19650
+
19651
+ var dbContext = dbContexts[dbInfo.name];
19652
+ var forages = dbContext.forages;
19653
+
19654
+ for (var i = 0; i < forages.length; i++) {
19655
+ var forage = forages[i];
19656
+ if (forage._dbInfo.db) {
19657
+ forage._dbInfo.db.close();
19658
+ forage._dbInfo.db = null;
19659
+ }
19660
+ }
19661
+ dbInfo.db = null;
19662
+
19663
+ return _getOriginalConnection(dbInfo).then(function (db) {
19664
+ dbInfo.db = db;
19665
+ if (_isUpgradeNeeded(dbInfo)) {
19666
+ // Reopen the database for upgrading.
19667
+ return _getUpgradedConnection(dbInfo);
19668
+ }
19669
+ return db;
19670
+ }).then(function (db) {
19671
+ // store the latest db reference
19672
+ // in case the db was upgraded
19673
+ dbInfo.db = dbContext.db = db;
19674
+ for (var i = 0; i < forages.length; i++) {
19675
+ forages[i]._dbInfo.db = db;
19676
+ }
19677
+ })["catch"](function (err) {
19678
+ _rejectReadiness(dbInfo, err);
19679
+ throw err;
19680
+ });
19681
+ }
19682
+
19683
+ // FF doesn't like Promises (micro-tasks) and IDDB store operations,
19684
+ // so we have to do it with callbacks
19685
+ function createTransaction(dbInfo, mode, callback, retries) {
19686
+ if (retries === undefined) {
19687
+ retries = 1;
19688
+ }
19689
+
19690
+ try {
19691
+ var tx = dbInfo.db.transaction(dbInfo.storeName, mode);
19692
+ callback(null, tx);
19693
+ } catch (err) {
19694
+ if (retries > 0 && (!dbInfo.db || err.name === 'InvalidStateError' || err.name === 'NotFoundError')) {
19695
+ return Promise$1.resolve().then(function () {
19696
+ if (!dbInfo.db || err.name === 'NotFoundError' && !dbInfo.db.objectStoreNames.contains(dbInfo.storeName) && dbInfo.version <= dbInfo.db.version) {
19697
+ // increase the db version, to create the new ObjectStore
19698
+ if (dbInfo.db) {
19699
+ dbInfo.version = dbInfo.db.version + 1;
19700
+ }
19701
+ // Reopen the database for upgrading.
19702
+ return _getUpgradedConnection(dbInfo);
19703
+ }
19704
+ }).then(function () {
19705
+ return _tryReconnect(dbInfo).then(function () {
19706
+ createTransaction(dbInfo, mode, callback, retries - 1);
19707
+ });
19708
+ })["catch"](callback);
19709
+ }
19710
+
19711
+ callback(err);
19712
+ }
19713
+ }
19714
+
19715
+ function createDbContext() {
19716
+ return {
19717
+ // Running localForages sharing a database.
19718
+ forages: [],
19719
+ // Shared database.
19720
+ db: null,
19721
+ // Database readiness (promise).
19722
+ dbReady: null,
19723
+ // Deferred operations on the database.
19724
+ deferredOperations: []
19725
+ };
19726
+ }
19727
+
19728
+ // Open the IndexedDB database (automatically creates one if one didn't
19729
+ // previously exist), using any options set in the config.
19730
+ function _initStorage(options) {
19731
+ var self = this;
19732
+ var dbInfo = {
19733
+ db: null
19734
+ };
19735
+
19736
+ if (options) {
19737
+ for (var i in options) {
19738
+ dbInfo[i] = options[i];
19739
+ }
19740
+ }
19741
+
19742
+ // Get the current context of the database;
19743
+ var dbContext = dbContexts[dbInfo.name];
19744
+
19745
+ // ...or create a new context.
19746
+ if (!dbContext) {
19747
+ dbContext = createDbContext();
19748
+ // Register the new context in the global container.
19749
+ dbContexts[dbInfo.name] = dbContext;
19750
+ }
19751
+
19752
+ // Register itself as a running localForage in the current context.
19753
+ dbContext.forages.push(self);
19754
+
19755
+ // Replace the default `ready()` function with the specialized one.
19756
+ if (!self._initReady) {
19757
+ self._initReady = self.ready;
19758
+ self.ready = _fullyReady;
19759
+ }
19760
+
19761
+ // Create an array of initialization states of the related localForages.
19762
+ var initPromises = [];
19763
+
19764
+ function ignoreErrors() {
19765
+ // Don't handle errors here,
19766
+ // just makes sure related localForages aren't pending.
19767
+ return Promise$1.resolve();
19768
+ }
19769
+
19770
+ for (var j = 0; j < dbContext.forages.length; j++) {
19771
+ var forage = dbContext.forages[j];
19772
+ if (forage !== self) {
19773
+ // Don't wait for itself...
19774
+ initPromises.push(forage._initReady()["catch"](ignoreErrors));
19775
+ }
19776
+ }
19777
+
19778
+ // Take a snapshot of the related localForages.
19779
+ var forages = dbContext.forages.slice(0);
19780
+
19781
+ // Initialize the connection process only when
19782
+ // all the related localForages aren't pending.
19783
+ return Promise$1.all(initPromises).then(function () {
19784
+ dbInfo.db = dbContext.db;
19785
+ // Get the connection or open a new one without upgrade.
19786
+ return _getOriginalConnection(dbInfo);
19787
+ }).then(function (db) {
19788
+ dbInfo.db = db;
19789
+ if (_isUpgradeNeeded(dbInfo, self._defaultConfig.version)) {
19790
+ // Reopen the database for upgrading.
19791
+ return _getUpgradedConnection(dbInfo);
19792
+ }
19793
+ return db;
19794
+ }).then(function (db) {
19795
+ dbInfo.db = dbContext.db = db;
19796
+ self._dbInfo = dbInfo;
19797
+ // Share the final connection amongst related localForages.
19798
+ for (var k = 0; k < forages.length; k++) {
19799
+ var forage = forages[k];
19800
+ if (forage !== self) {
19801
+ // Self is already up-to-date.
19802
+ forage._dbInfo.db = dbInfo.db;
19803
+ forage._dbInfo.version = dbInfo.version;
19804
+ }
19805
+ }
19806
+ });
19807
+ }
19808
+
19809
+ function getItem(key, callback) {
19810
+ var self = this;
19811
+
19812
+ key = normalizeKey(key);
19813
+
19814
+ var promise = new Promise$1(function (resolve, reject) {
19815
+ self.ready().then(function () {
19816
+ createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {
19817
+ if (err) {
19818
+ return reject(err);
19819
+ }
19820
+
19821
+ try {
19822
+ var store = transaction.objectStore(self._dbInfo.storeName);
19823
+ var req = store.get(key);
19824
+
19825
+ req.onsuccess = function () {
19826
+ var value = req.result;
19827
+ if (value === undefined) {
19828
+ value = null;
19829
+ }
19830
+ if (_isEncodedBlob(value)) {
19831
+ value = _decodeBlob(value);
19832
+ }
19833
+ resolve(value);
19834
+ };
19835
+
19836
+ req.onerror = function () {
19837
+ reject(req.error);
19838
+ };
19839
+ } catch (e) {
19840
+ reject(e);
19841
+ }
19842
+ });
19843
+ })["catch"](reject);
19844
+ });
19845
+
19846
+ executeCallback(promise, callback);
19847
+ return promise;
19848
+ }
19849
+
19850
+ // Iterate over all items stored in database.
19851
+ function iterate(iterator, callback) {
19852
+ var self = this;
19853
+
19854
+ var promise = new Promise$1(function (resolve, reject) {
19855
+ self.ready().then(function () {
19856
+ createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {
19857
+ if (err) {
19858
+ return reject(err);
19859
+ }
19860
+
19861
+ try {
19862
+ var store = transaction.objectStore(self._dbInfo.storeName);
19863
+ var req = store.openCursor();
19864
+ var iterationNumber = 1;
19865
+
19866
+ req.onsuccess = function () {
19867
+ var cursor = req.result;
19868
+
19869
+ if (cursor) {
19870
+ var value = cursor.value;
19871
+ if (_isEncodedBlob(value)) {
19872
+ value = _decodeBlob(value);
19873
+ }
19874
+ var result = iterator(value, cursor.key, iterationNumber++);
19875
+
19876
+ // when the iterator callback returns any
19877
+ // (non-`undefined`) value, then we stop
19878
+ // the iteration immediately
19879
+ if (result !== void 0) {
19880
+ resolve(result);
19881
+ } else {
19882
+ cursor["continue"]();
19883
+ }
19884
+ } else {
19885
+ resolve();
19886
+ }
19887
+ };
19888
+
19889
+ req.onerror = function () {
19890
+ reject(req.error);
19891
+ };
19892
+ } catch (e) {
19893
+ reject(e);
19894
+ }
19895
+ });
19896
+ })["catch"](reject);
19897
+ });
19898
+
19899
+ executeCallback(promise, callback);
19900
+
19901
+ return promise;
19902
+ }
19903
+
19904
+ function setItem(key, value, callback) {
19905
+ var self = this;
19906
+
19907
+ key = normalizeKey(key);
19908
+
19909
+ var promise = new Promise$1(function (resolve, reject) {
19910
+ var dbInfo;
19911
+ self.ready().then(function () {
19912
+ dbInfo = self._dbInfo;
19913
+ if (toString.call(value) === '[object Blob]') {
19914
+ return _checkBlobSupport(dbInfo.db).then(function (blobSupport) {
19915
+ if (blobSupport) {
19916
+ return value;
19917
+ }
19918
+ return _encodeBlob(value);
19919
+ });
19920
+ }
19921
+ return value;
19922
+ }).then(function (value) {
19923
+ createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) {
19924
+ if (err) {
19925
+ return reject(err);
19926
+ }
19927
+
19928
+ try {
19929
+ var store = transaction.objectStore(self._dbInfo.storeName);
19930
+
19931
+ // The reason we don't _save_ null is because IE 10 does
19932
+ // not support saving the `null` type in IndexedDB. How
19933
+ // ironic, given the bug below!
19934
+ // See: https://github.com/mozilla/localForage/issues/161
19935
+ if (value === null) {
19936
+ value = undefined;
19937
+ }
19938
+
19939
+ var req = store.put(value, key);
19940
+
19941
+ transaction.oncomplete = function () {
19942
+ // Cast to undefined so the value passed to
19943
+ // callback/promise is the same as what one would get out
19944
+ // of `getItem()` later. This leads to some weirdness
19945
+ // (setItem('foo', undefined) will return `null`), but
19946
+ // it's not my fault localStorage is our baseline and that
19947
+ // it's weird.
19948
+ if (value === undefined) {
19949
+ value = null;
19950
+ }
19951
+
19952
+ resolve(value);
19953
+ };
19954
+ transaction.onabort = transaction.onerror = function () {
19955
+ var err = req.error ? req.error : req.transaction.error;
19956
+ reject(err);
19957
+ };
19958
+ } catch (e) {
19959
+ reject(e);
19960
+ }
19961
+ });
19962
+ })["catch"](reject);
19963
+ });
19964
+
19965
+ executeCallback(promise, callback);
19966
+ return promise;
19967
+ }
19968
+
19969
+ function removeItem(key, callback) {
19970
+ var self = this;
19971
+
19972
+ key = normalizeKey(key);
19973
+
19974
+ var promise = new Promise$1(function (resolve, reject) {
19975
+ self.ready().then(function () {
19976
+ createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) {
19977
+ if (err) {
19978
+ return reject(err);
19979
+ }
19980
+
19981
+ try {
19982
+ var store = transaction.objectStore(self._dbInfo.storeName);
19983
+ // We use a Grunt task to make this safe for IE and some
19984
+ // versions of Android (including those used by Cordova).
19985
+ // Normally IE won't like `.delete()` and will insist on
19986
+ // using `['delete']()`, but we have a build step that
19987
+ // fixes this for us now.
19988
+ var req = store["delete"](key);
19989
+ transaction.oncomplete = function () {
19990
+ resolve();
19991
+ };
19992
+
19993
+ transaction.onerror = function () {
19994
+ reject(req.error);
19995
+ };
19996
+
19997
+ // The request will be also be aborted if we've exceeded our storage
19998
+ // space.
19999
+ transaction.onabort = function () {
20000
+ var err = req.error ? req.error : req.transaction.error;
20001
+ reject(err);
20002
+ };
20003
+ } catch (e) {
20004
+ reject(e);
20005
+ }
20006
+ });
20007
+ })["catch"](reject);
20008
+ });
20009
+
20010
+ executeCallback(promise, callback);
20011
+ return promise;
20012
+ }
20013
+
20014
+ function clear(callback) {
20015
+ var self = this;
20016
+
20017
+ var promise = new Promise$1(function (resolve, reject) {
20018
+ self.ready().then(function () {
20019
+ createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) {
20020
+ if (err) {
20021
+ return reject(err);
20022
+ }
20023
+
20024
+ try {
20025
+ var store = transaction.objectStore(self._dbInfo.storeName);
20026
+ var req = store.clear();
20027
+
20028
+ transaction.oncomplete = function () {
20029
+ resolve();
20030
+ };
20031
+
20032
+ transaction.onabort = transaction.onerror = function () {
20033
+ var err = req.error ? req.error : req.transaction.error;
20034
+ reject(err);
20035
+ };
20036
+ } catch (e) {
20037
+ reject(e);
20038
+ }
20039
+ });
20040
+ })["catch"](reject);
20041
+ });
20042
+
20043
+ executeCallback(promise, callback);
20044
+ return promise;
20045
+ }
20046
+
20047
+ function length(callback) {
20048
+ var self = this;
20049
+
20050
+ var promise = new Promise$1(function (resolve, reject) {
20051
+ self.ready().then(function () {
20052
+ createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {
20053
+ if (err) {
20054
+ return reject(err);
20055
+ }
20056
+
20057
+ try {
20058
+ var store = transaction.objectStore(self._dbInfo.storeName);
20059
+ var req = store.count();
20060
+
20061
+ req.onsuccess = function () {
20062
+ resolve(req.result);
20063
+ };
20064
+
20065
+ req.onerror = function () {
20066
+ reject(req.error);
20067
+ };
20068
+ } catch (e) {
20069
+ reject(e);
20070
+ }
20071
+ });
20072
+ })["catch"](reject);
20073
+ });
20074
+
20075
+ executeCallback(promise, callback);
20076
+ return promise;
20077
+ }
20078
+
20079
+ function key(n, callback) {
20080
+ var self = this;
20081
+
20082
+ var promise = new Promise$1(function (resolve, reject) {
20083
+ if (n < 0) {
20084
+ resolve(null);
20085
+
20086
+ return;
20087
+ }
20088
+
20089
+ self.ready().then(function () {
20090
+ createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {
20091
+ if (err) {
20092
+ return reject(err);
20093
+ }
20094
+
20095
+ try {
20096
+ var store = transaction.objectStore(self._dbInfo.storeName);
20097
+ var advanced = false;
20098
+ var req = store.openKeyCursor();
20099
+
20100
+ req.onsuccess = function () {
20101
+ var cursor = req.result;
20102
+ if (!cursor) {
20103
+ // this means there weren't enough keys
20104
+ resolve(null);
20105
+
20106
+ return;
20107
+ }
20108
+
20109
+ if (n === 0) {
20110
+ // We have the first key, return it if that's what they
20111
+ // wanted.
20112
+ resolve(cursor.key);
20113
+ } else {
20114
+ if (!advanced) {
20115
+ // Otherwise, ask the cursor to skip ahead n
20116
+ // records.
20117
+ advanced = true;
20118
+ cursor.advance(n);
20119
+ } else {
20120
+ // When we get here, we've got the nth key.
20121
+ resolve(cursor.key);
20122
+ }
20123
+ }
20124
+ };
20125
+
20126
+ req.onerror = function () {
20127
+ reject(req.error);
20128
+ };
20129
+ } catch (e) {
20130
+ reject(e);
20131
+ }
20132
+ });
20133
+ })["catch"](reject);
20134
+ });
20135
+
20136
+ executeCallback(promise, callback);
20137
+ return promise;
20138
+ }
20139
+
20140
+ function keys(callback) {
20141
+ var self = this;
20142
+
20143
+ var promise = new Promise$1(function (resolve, reject) {
20144
+ self.ready().then(function () {
20145
+ createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {
20146
+ if (err) {
20147
+ return reject(err);
20148
+ }
20149
+
20150
+ try {
20151
+ var store = transaction.objectStore(self._dbInfo.storeName);
20152
+ var req = store.openKeyCursor();
20153
+ var keys = [];
20154
+
20155
+ req.onsuccess = function () {
20156
+ var cursor = req.result;
20157
+
20158
+ if (!cursor) {
20159
+ resolve(keys);
20160
+ return;
20161
+ }
20162
+
20163
+ keys.push(cursor.key);
20164
+ cursor["continue"]();
20165
+ };
20166
+
20167
+ req.onerror = function () {
20168
+ reject(req.error);
20169
+ };
20170
+ } catch (e) {
20171
+ reject(e);
20172
+ }
20173
+ });
20174
+ })["catch"](reject);
20175
+ });
20176
+
20177
+ executeCallback(promise, callback);
20178
+ return promise;
20179
+ }
20180
+
20181
+ function dropInstance(options, callback) {
20182
+ callback = getCallback.apply(this, arguments);
20183
+
20184
+ var currentConfig = this.config();
20185
+ options = typeof options !== 'function' && options || {};
20186
+ if (!options.name) {
20187
+ options.name = options.name || currentConfig.name;
20188
+ options.storeName = options.storeName || currentConfig.storeName;
20189
+ }
20190
+
20191
+ var self = this;
20192
+ var promise;
20193
+ if (!options.name) {
20194
+ promise = Promise$1.reject('Invalid arguments');
20195
+ } else {
20196
+ var isCurrentDb = options.name === currentConfig.name && self._dbInfo.db;
20197
+
20198
+ var dbPromise = isCurrentDb ? Promise$1.resolve(self._dbInfo.db) : _getOriginalConnection(options).then(function (db) {
20199
+ var dbContext = dbContexts[options.name];
20200
+ var forages = dbContext.forages;
20201
+ dbContext.db = db;
20202
+ for (var i = 0; i < forages.length; i++) {
20203
+ forages[i]._dbInfo.db = db;
20204
+ }
20205
+ return db;
20206
+ });
20207
+
20208
+ if (!options.storeName) {
20209
+ promise = dbPromise.then(function (db) {
20210
+ _deferReadiness(options);
20211
+
20212
+ var dbContext = dbContexts[options.name];
20213
+ var forages = dbContext.forages;
20214
+
20215
+ db.close();
20216
+ for (var i = 0; i < forages.length; i++) {
20217
+ var forage = forages[i];
20218
+ forage._dbInfo.db = null;
20219
+ }
20220
+
20221
+ var dropDBPromise = new Promise$1(function (resolve, reject) {
20222
+ var req = idb.deleteDatabase(options.name);
20223
+
20224
+ req.onerror = function () {
20225
+ var db = req.result;
20226
+ if (db) {
20227
+ db.close();
20228
+ }
20229
+ reject(req.error);
20230
+ };
20231
+
20232
+ req.onblocked = function () {
20233
+ // Closing all open connections in onversionchange handler should prevent this situation, but if
20234
+ // we do get here, it just means the request remains pending - eventually it will succeed or error
20235
+ console.warn('dropInstance blocked for database "' + options.name + '" until all open connections are closed');
20236
+ };
20237
+
20238
+ req.onsuccess = function () {
20239
+ var db = req.result;
20240
+ if (db) {
20241
+ db.close();
20242
+ }
20243
+ resolve(db);
20244
+ };
20245
+ });
20246
+
20247
+ return dropDBPromise.then(function (db) {
20248
+ dbContext.db = db;
20249
+ for (var i = 0; i < forages.length; i++) {
20250
+ var _forage = forages[i];
20251
+ _advanceReadiness(_forage._dbInfo);
20252
+ }
20253
+ })["catch"](function (err) {
20254
+ (_rejectReadiness(options, err) || Promise$1.resolve())["catch"](function () {});
20255
+ throw err;
20256
+ });
20257
+ });
20258
+ } else {
20259
+ promise = dbPromise.then(function (db) {
20260
+ if (!db.objectStoreNames.contains(options.storeName)) {
20261
+ return;
20262
+ }
20263
+
20264
+ var newVersion = db.version + 1;
20265
+
20266
+ _deferReadiness(options);
20267
+
20268
+ var dbContext = dbContexts[options.name];
20269
+ var forages = dbContext.forages;
20270
+
20271
+ db.close();
20272
+ for (var i = 0; i < forages.length; i++) {
20273
+ var forage = forages[i];
20274
+ forage._dbInfo.db = null;
20275
+ forage._dbInfo.version = newVersion;
20276
+ }
20277
+
20278
+ var dropObjectPromise = new Promise$1(function (resolve, reject) {
20279
+ var req = idb.open(options.name, newVersion);
20280
+
20281
+ req.onerror = function (err) {
20282
+ var db = req.result;
20283
+ db.close();
20284
+ reject(err);
20285
+ };
20286
+
20287
+ req.onupgradeneeded = function () {
20288
+ var db = req.result;
20289
+ db.deleteObjectStore(options.storeName);
20290
+ };
20291
+
20292
+ req.onsuccess = function () {
20293
+ var db = req.result;
20294
+ db.close();
20295
+ resolve(db);
20296
+ };
20297
+ });
20298
+
20299
+ return dropObjectPromise.then(function (db) {
20300
+ dbContext.db = db;
20301
+ for (var j = 0; j < forages.length; j++) {
20302
+ var _forage2 = forages[j];
20303
+ _forage2._dbInfo.db = db;
20304
+ _advanceReadiness(_forage2._dbInfo);
20305
+ }
20306
+ })["catch"](function (err) {
20307
+ (_rejectReadiness(options, err) || Promise$1.resolve())["catch"](function () {});
20308
+ throw err;
20309
+ });
20310
+ });
20311
+ }
20312
+ }
20313
+
20314
+ executeCallback(promise, callback);
20315
+ return promise;
20316
+ }
20317
+
20318
+ var asyncStorage = {
20319
+ _driver: 'asyncStorage',
20320
+ _initStorage: _initStorage,
20321
+ _support: isIndexedDBValid(),
20322
+ iterate: iterate,
20323
+ getItem: getItem,
20324
+ setItem: setItem,
20325
+ removeItem: removeItem,
20326
+ clear: clear,
20327
+ length: length,
20328
+ key: key,
20329
+ keys: keys,
20330
+ dropInstance: dropInstance
20331
+ };
20332
+
20333
+ function isWebSQLValid() {
20334
+ return typeof openDatabase === 'function';
20335
+ }
20336
+
20337
+ // Sadly, the best way to save binary data in WebSQL/localStorage is serializing
20338
+ // it to Base64, so this is how we store it to prevent very strange errors with less
20339
+ // verbose ways of binary <-> string data storage.
20340
+ var BASE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
20341
+
20342
+ var BLOB_TYPE_PREFIX = '~~local_forage_type~';
20343
+ var BLOB_TYPE_PREFIX_REGEX = /^~~local_forage_type~([^~]+)~/;
20344
+
20345
+ var SERIALIZED_MARKER = '__lfsc__:';
20346
+ var SERIALIZED_MARKER_LENGTH = SERIALIZED_MARKER.length;
20347
+
20348
+ // OMG the serializations!
20349
+ var TYPE_ARRAYBUFFER = 'arbf';
20350
+ var TYPE_BLOB = 'blob';
20351
+ var TYPE_INT8ARRAY = 'si08';
20352
+ var TYPE_UINT8ARRAY = 'ui08';
20353
+ var TYPE_UINT8CLAMPEDARRAY = 'uic8';
20354
+ var TYPE_INT16ARRAY = 'si16';
20355
+ var TYPE_INT32ARRAY = 'si32';
20356
+ var TYPE_UINT16ARRAY = 'ur16';
20357
+ var TYPE_UINT32ARRAY = 'ui32';
20358
+ var TYPE_FLOAT32ARRAY = 'fl32';
20359
+ var TYPE_FLOAT64ARRAY = 'fl64';
20360
+ var TYPE_SERIALIZED_MARKER_LENGTH = SERIALIZED_MARKER_LENGTH + TYPE_ARRAYBUFFER.length;
20361
+
20362
+ var toString$1 = Object.prototype.toString;
20363
+
20364
+ function stringToBuffer(serializedString) {
20365
+ // Fill the string into a ArrayBuffer.
20366
+ var bufferLength = serializedString.length * 0.75;
20367
+ var len = serializedString.length;
20368
+ var i;
20369
+ var p = 0;
20370
+ var encoded1, encoded2, encoded3, encoded4;
20371
+
20372
+ if (serializedString[serializedString.length - 1] === '=') {
20373
+ bufferLength--;
20374
+ if (serializedString[serializedString.length - 2] === '=') {
20375
+ bufferLength--;
20376
+ }
20377
+ }
20378
+
20379
+ var buffer = new ArrayBuffer(bufferLength);
20380
+ var bytes = new Uint8Array(buffer);
20381
+
20382
+ for (i = 0; i < len; i += 4) {
20383
+ encoded1 = BASE_CHARS.indexOf(serializedString[i]);
20384
+ encoded2 = BASE_CHARS.indexOf(serializedString[i + 1]);
20385
+ encoded3 = BASE_CHARS.indexOf(serializedString[i + 2]);
20386
+ encoded4 = BASE_CHARS.indexOf(serializedString[i + 3]);
20387
+
20388
+ /*jslint bitwise: true */
20389
+ bytes[p++] = encoded1 << 2 | encoded2 >> 4;
20390
+ bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
20391
+ bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
20392
+ }
20393
+ return buffer;
20394
+ }
20395
+
20396
+ // Converts a buffer to a string to store, serialized, in the backend
20397
+ // storage library.
20398
+ function bufferToString(buffer) {
20399
+ // base64-arraybuffer
20400
+ var bytes = new Uint8Array(buffer);
20401
+ var base64String = '';
20402
+ var i;
20403
+
20404
+ for (i = 0; i < bytes.length; i += 3) {
20405
+ /*jslint bitwise: true */
20406
+ base64String += BASE_CHARS[bytes[i] >> 2];
20407
+ base64String += BASE_CHARS[(bytes[i] & 3) << 4 | bytes[i + 1] >> 4];
20408
+ base64String += BASE_CHARS[(bytes[i + 1] & 15) << 2 | bytes[i + 2] >> 6];
20409
+ base64String += BASE_CHARS[bytes[i + 2] & 63];
20410
+ }
20411
+
20412
+ if (bytes.length % 3 === 2) {
20413
+ base64String = base64String.substring(0, base64String.length - 1) + '=';
20414
+ } else if (bytes.length % 3 === 1) {
20415
+ base64String = base64String.substring(0, base64String.length - 2) + '==';
20416
+ }
20417
+
20418
+ return base64String;
20419
+ }
20420
+
20421
+ // Serialize a value, afterwards executing a callback (which usually
20422
+ // instructs the `setItem()` callback/promise to be executed). This is how
20423
+ // we store binary data with localStorage.
20424
+ function serialize(value, callback) {
20425
+ var valueType = '';
20426
+ if (value) {
20427
+ valueType = toString$1.call(value);
20428
+ }
20429
+
20430
+ // Cannot use `value instanceof ArrayBuffer` or such here, as these
20431
+ // checks fail when running the tests using casper.js...
20432
+ //
20433
+ // TODO: See why those tests fail and use a better solution.
20434
+ if (value && (valueType === '[object ArrayBuffer]' || value.buffer && toString$1.call(value.buffer) === '[object ArrayBuffer]')) {
20435
+ // Convert binary arrays to a string and prefix the string with
20436
+ // a special marker.
20437
+ var buffer;
20438
+ var marker = SERIALIZED_MARKER;
20439
+
20440
+ if (value instanceof ArrayBuffer) {
20441
+ buffer = value;
20442
+ marker += TYPE_ARRAYBUFFER;
20443
+ } else {
20444
+ buffer = value.buffer;
20445
+
20446
+ if (valueType === '[object Int8Array]') {
20447
+ marker += TYPE_INT8ARRAY;
20448
+ } else if (valueType === '[object Uint8Array]') {
20449
+ marker += TYPE_UINT8ARRAY;
20450
+ } else if (valueType === '[object Uint8ClampedArray]') {
20451
+ marker += TYPE_UINT8CLAMPEDARRAY;
20452
+ } else if (valueType === '[object Int16Array]') {
20453
+ marker += TYPE_INT16ARRAY;
20454
+ } else if (valueType === '[object Uint16Array]') {
20455
+ marker += TYPE_UINT16ARRAY;
20456
+ } else if (valueType === '[object Int32Array]') {
20457
+ marker += TYPE_INT32ARRAY;
20458
+ } else if (valueType === '[object Uint32Array]') {
20459
+ marker += TYPE_UINT32ARRAY;
20460
+ } else if (valueType === '[object Float32Array]') {
20461
+ marker += TYPE_FLOAT32ARRAY;
20462
+ } else if (valueType === '[object Float64Array]') {
20463
+ marker += TYPE_FLOAT64ARRAY;
20464
+ } else {
20465
+ callback(new Error('Failed to get type for BinaryArray'));
20466
+ }
20467
+ }
20468
+
20469
+ callback(marker + bufferToString(buffer));
20470
+ } else if (valueType === '[object Blob]') {
20471
+ // Conver the blob to a binaryArray and then to a string.
20472
+ var fileReader = new FileReader();
20473
+
20474
+ fileReader.onload = function () {
20475
+ // Backwards-compatible prefix for the blob type.
20476
+ var str = BLOB_TYPE_PREFIX + value.type + '~' + bufferToString(this.result);
20477
+
20478
+ callback(SERIALIZED_MARKER + TYPE_BLOB + str);
20479
+ };
20480
+
20481
+ fileReader.readAsArrayBuffer(value);
20482
+ } else {
20483
+ try {
20484
+ callback(JSON.stringify(value));
20485
+ } catch (e) {
20486
+ console.error("Couldn't convert value into a JSON string: ", value);
20487
+
20488
+ callback(null, e);
20489
+ }
20490
+ }
20491
+ }
20492
+
20493
+ // Deserialize data we've inserted into a value column/field. We place
20494
+ // special markers into our strings to mark them as encoded; this isn't
20495
+ // as nice as a meta field, but it's the only sane thing we can do whilst
20496
+ // keeping localStorage support intact.
20497
+ //
20498
+ // Oftentimes this will just deserialize JSON content, but if we have a
20499
+ // special marker (SERIALIZED_MARKER, defined above), we will extract
20500
+ // some kind of arraybuffer/binary data/typed array out of the string.
20501
+ function deserialize(value) {
20502
+ // If we haven't marked this string as being specially serialized (i.e.
20503
+ // something other than serialized JSON), we can just return it and be
20504
+ // done with it.
20505
+ if (value.substring(0, SERIALIZED_MARKER_LENGTH) !== SERIALIZED_MARKER) {
20506
+ return JSON.parse(value);
20507
+ }
20508
+
20509
+ // The following code deals with deserializing some kind of Blob or
20510
+ // TypedArray. First we separate out the type of data we're dealing
20511
+ // with from the data itself.
20512
+ var serializedString = value.substring(TYPE_SERIALIZED_MARKER_LENGTH);
20513
+ var type = value.substring(SERIALIZED_MARKER_LENGTH, TYPE_SERIALIZED_MARKER_LENGTH);
20514
+
20515
+ var blobType;
20516
+ // Backwards-compatible blob type serialization strategy.
20517
+ // DBs created with older versions of localForage will simply not have the blob type.
20518
+ if (type === TYPE_BLOB && BLOB_TYPE_PREFIX_REGEX.test(serializedString)) {
20519
+ var matcher = serializedString.match(BLOB_TYPE_PREFIX_REGEX);
20520
+ blobType = matcher[1];
20521
+ serializedString = serializedString.substring(matcher[0].length);
20522
+ }
20523
+ var buffer = stringToBuffer(serializedString);
20524
+
20525
+ // Return the right type based on the code/type set during
20526
+ // serialization.
20527
+ switch (type) {
20528
+ case TYPE_ARRAYBUFFER:
20529
+ return buffer;
20530
+ case TYPE_BLOB:
20531
+ return createBlob([buffer], { type: blobType });
20532
+ case TYPE_INT8ARRAY:
20533
+ return new Int8Array(buffer);
20534
+ case TYPE_UINT8ARRAY:
20535
+ return new Uint8Array(buffer);
20536
+ case TYPE_UINT8CLAMPEDARRAY:
20537
+ return new Uint8ClampedArray(buffer);
20538
+ case TYPE_INT16ARRAY:
20539
+ return new Int16Array(buffer);
20540
+ case TYPE_UINT16ARRAY:
20541
+ return new Uint16Array(buffer);
20542
+ case TYPE_INT32ARRAY:
20543
+ return new Int32Array(buffer);
20544
+ case TYPE_UINT32ARRAY:
20545
+ return new Uint32Array(buffer);
20546
+ case TYPE_FLOAT32ARRAY:
20547
+ return new Float32Array(buffer);
20548
+ case TYPE_FLOAT64ARRAY:
20549
+ return new Float64Array(buffer);
20550
+ default:
20551
+ throw new Error('Unkown type: ' + type);
20552
+ }
20553
+ }
20554
+
20555
+ var localforageSerializer = {
20556
+ serialize: serialize,
20557
+ deserialize: deserialize,
20558
+ stringToBuffer: stringToBuffer,
20559
+ bufferToString: bufferToString
20560
+ };
20561
+
20562
+ /*
20563
+ * Includes code from:
20564
+ *
20565
+ * base64-arraybuffer
20566
+ * https://github.com/niklasvh/base64-arraybuffer
20567
+ *
20568
+ * Copyright (c) 2012 Niklas von Hertzen
20569
+ * Licensed under the MIT license.
20570
+ */
20571
+
20572
+ function createDbTable(t, dbInfo, callback, errorCallback) {
20573
+ t.executeSql('CREATE TABLE IF NOT EXISTS ' + dbInfo.storeName + ' ' + '(id INTEGER PRIMARY KEY, key unique, value)', [], callback, errorCallback);
20574
+ }
20575
+
20576
+ // Open the WebSQL database (automatically creates one if one didn't
20577
+ // previously exist), using any options set in the config.
20578
+ function _initStorage$1(options) {
20579
+ var self = this;
20580
+ var dbInfo = {
20581
+ db: null
20582
+ };
20583
+
20584
+ if (options) {
20585
+ for (var i in options) {
20586
+ dbInfo[i] = typeof options[i] !== 'string' ? options[i].toString() : options[i];
20587
+ }
20588
+ }
20589
+
20590
+ var dbInfoPromise = new Promise$1(function (resolve, reject) {
20591
+ // Open the database; the openDatabase API will automatically
20592
+ // create it for us if it doesn't exist.
20593
+ try {
20594
+ dbInfo.db = openDatabase(dbInfo.name, String(dbInfo.version), dbInfo.description, dbInfo.size);
20595
+ } catch (e) {
20596
+ return reject(e);
20597
+ }
20598
+
20599
+ // Create our key/value table if it doesn't exist.
20600
+ dbInfo.db.transaction(function (t) {
20601
+ createDbTable(t, dbInfo, function () {
20602
+ self._dbInfo = dbInfo;
20603
+ resolve();
20604
+ }, function (t, error) {
20605
+ reject(error);
20606
+ });
20607
+ }, reject);
20608
+ });
20609
+
20610
+ dbInfo.serializer = localforageSerializer;
20611
+ return dbInfoPromise;
20612
+ }
20613
+
20614
+ function tryExecuteSql(t, dbInfo, sqlStatement, args, callback, errorCallback) {
20615
+ t.executeSql(sqlStatement, args, callback, function (t, error) {
20616
+ if (error.code === error.SYNTAX_ERR) {
20617
+ t.executeSql('SELECT name FROM sqlite_master ' + "WHERE type='table' AND name = ?", [dbInfo.storeName], function (t, results) {
20618
+ if (!results.rows.length) {
20619
+ // if the table is missing (was deleted)
20620
+ // re-create it table and retry
20621
+ createDbTable(t, dbInfo, function () {
20622
+ t.executeSql(sqlStatement, args, callback, errorCallback);
20623
+ }, errorCallback);
20624
+ } else {
20625
+ errorCallback(t, error);
20626
+ }
20627
+ }, errorCallback);
20628
+ } else {
20629
+ errorCallback(t, error);
20630
+ }
20631
+ }, errorCallback);
20632
+ }
20633
+
20634
+ function getItem$1(key, callback) {
20635
+ var self = this;
20636
+
20637
+ key = normalizeKey(key);
20638
+
20639
+ var promise = new Promise$1(function (resolve, reject) {
20640
+ self.ready().then(function () {
20641
+ var dbInfo = self._dbInfo;
20642
+ dbInfo.db.transaction(function (t) {
20643
+ tryExecuteSql(t, dbInfo, 'SELECT * FROM ' + dbInfo.storeName + ' WHERE key = ? LIMIT 1', [key], function (t, results) {
20644
+ var result = results.rows.length ? results.rows.item(0).value : null;
20645
+
20646
+ // Check to see if this is serialized content we need to
20647
+ // unpack.
20648
+ if (result) {
20649
+ result = dbInfo.serializer.deserialize(result);
20650
+ }
20651
+
20652
+ resolve(result);
20653
+ }, function (t, error) {
20654
+ reject(error);
20655
+ });
20656
+ });
20657
+ })["catch"](reject);
20658
+ });
20659
+
20660
+ executeCallback(promise, callback);
20661
+ return promise;
20662
+ }
20663
+
20664
+ function iterate$1(iterator, callback) {
20665
+ var self = this;
20666
+
20667
+ var promise = new Promise$1(function (resolve, reject) {
20668
+ self.ready().then(function () {
20669
+ var dbInfo = self._dbInfo;
20670
+
20671
+ dbInfo.db.transaction(function (t) {
20672
+ tryExecuteSql(t, dbInfo, 'SELECT * FROM ' + dbInfo.storeName, [], function (t, results) {
20673
+ var rows = results.rows;
20674
+ var length = rows.length;
20675
+
20676
+ for (var i = 0; i < length; i++) {
20677
+ var item = rows.item(i);
20678
+ var result = item.value;
20679
+
20680
+ // Check to see if this is serialized content
20681
+ // we need to unpack.
20682
+ if (result) {
20683
+ result = dbInfo.serializer.deserialize(result);
20684
+ }
20685
+
20686
+ result = iterator(result, item.key, i + 1);
20687
+
20688
+ // void(0) prevents problems with redefinition
20689
+ // of `undefined`.
20690
+ if (result !== void 0) {
20691
+ resolve(result);
20692
+ return;
20693
+ }
20694
+ }
20695
+
20696
+ resolve();
20697
+ }, function (t, error) {
20698
+ reject(error);
20699
+ });
20700
+ });
20701
+ })["catch"](reject);
20702
+ });
20703
+
20704
+ executeCallback(promise, callback);
20705
+ return promise;
20706
+ }
20707
+
20708
+ function _setItem(key, value, callback, retriesLeft) {
20709
+ var self = this;
20710
+
20711
+ key = normalizeKey(key);
20712
+
20713
+ var promise = new Promise$1(function (resolve, reject) {
20714
+ self.ready().then(function () {
20715
+ // The localStorage API doesn't return undefined values in an
20716
+ // "expected" way, so undefined is always cast to null in all
20717
+ // drivers. See: https://github.com/mozilla/localForage/pull/42
20718
+ if (value === undefined) {
20719
+ value = null;
20720
+ }
20721
+
20722
+ // Save the original value to pass to the callback.
20723
+ var originalValue = value;
20724
+
20725
+ var dbInfo = self._dbInfo;
20726
+ dbInfo.serializer.serialize(value, function (value, error) {
20727
+ if (error) {
20728
+ reject(error);
20729
+ } else {
20730
+ dbInfo.db.transaction(function (t) {
20731
+ tryExecuteSql(t, dbInfo, 'INSERT OR REPLACE INTO ' + dbInfo.storeName + ' ' + '(key, value) VALUES (?, ?)', [key, value], function () {
20732
+ resolve(originalValue);
20733
+ }, function (t, error) {
20734
+ reject(error);
20735
+ });
20736
+ }, function (sqlError) {
20737
+ // The transaction failed; check
20738
+ // to see if it's a quota error.
20739
+ if (sqlError.code === sqlError.QUOTA_ERR) {
20740
+ // We reject the callback outright for now, but
20741
+ // it's worth trying to re-run the transaction.
20742
+ // Even if the user accepts the prompt to use
20743
+ // more storage on Safari, this error will
20744
+ // be called.
20745
+ //
20746
+ // Try to re-run the transaction.
20747
+ if (retriesLeft > 0) {
20748
+ resolve(_setItem.apply(self, [key, originalValue, callback, retriesLeft - 1]));
20749
+ return;
20750
+ }
20751
+ reject(sqlError);
20752
+ }
20753
+ });
20754
+ }
20755
+ });
20756
+ })["catch"](reject);
20757
+ });
20758
+
20759
+ executeCallback(promise, callback);
20760
+ return promise;
20761
+ }
20762
+
20763
+ function setItem$1(key, value, callback) {
20764
+ return _setItem.apply(this, [key, value, callback, 1]);
20765
+ }
20766
+
20767
+ function removeItem$1(key, callback) {
20768
+ var self = this;
20769
+
20770
+ key = normalizeKey(key);
20771
+
20772
+ var promise = new Promise$1(function (resolve, reject) {
20773
+ self.ready().then(function () {
20774
+ var dbInfo = self._dbInfo;
20775
+ dbInfo.db.transaction(function (t) {
20776
+ tryExecuteSql(t, dbInfo, 'DELETE FROM ' + dbInfo.storeName + ' WHERE key = ?', [key], function () {
20777
+ resolve();
20778
+ }, function (t, error) {
20779
+ reject(error);
20780
+ });
20781
+ });
20782
+ })["catch"](reject);
20783
+ });
20784
+
20785
+ executeCallback(promise, callback);
20786
+ return promise;
20787
+ }
20788
+
20789
+ // Deletes every item in the table.
20790
+ // TODO: Find out if this resets the AUTO_INCREMENT number.
20791
+ function clear$1(callback) {
20792
+ var self = this;
20793
+
20794
+ var promise = new Promise$1(function (resolve, reject) {
20795
+ self.ready().then(function () {
20796
+ var dbInfo = self._dbInfo;
20797
+ dbInfo.db.transaction(function (t) {
20798
+ tryExecuteSql(t, dbInfo, 'DELETE FROM ' + dbInfo.storeName, [], function () {
20799
+ resolve();
20800
+ }, function (t, error) {
20801
+ reject(error);
20802
+ });
20803
+ });
20804
+ })["catch"](reject);
20805
+ });
20806
+
20807
+ executeCallback(promise, callback);
20808
+ return promise;
20809
+ }
20810
+
20811
+ // Does a simple `COUNT(key)` to get the number of items stored in
20812
+ // localForage.
20813
+ function length$1(callback) {
20814
+ var self = this;
20815
+
20816
+ var promise = new Promise$1(function (resolve, reject) {
20817
+ self.ready().then(function () {
20818
+ var dbInfo = self._dbInfo;
20819
+ dbInfo.db.transaction(function (t) {
20820
+ // Ahhh, SQL makes this one soooooo easy.
20821
+ tryExecuteSql(t, dbInfo, 'SELECT COUNT(key) as c FROM ' + dbInfo.storeName, [], function (t, results) {
20822
+ var result = results.rows.item(0).c;
20823
+ resolve(result);
20824
+ }, function (t, error) {
20825
+ reject(error);
20826
+ });
20827
+ });
20828
+ })["catch"](reject);
20829
+ });
20830
+
20831
+ executeCallback(promise, callback);
20832
+ return promise;
20833
+ }
20834
+
20835
+ // Return the key located at key index X; essentially gets the key from a
20836
+ // `WHERE id = ?`. This is the most efficient way I can think to implement
20837
+ // this rarely-used (in my experience) part of the API, but it can seem
20838
+ // inconsistent, because we do `INSERT OR REPLACE INTO` on `setItem()`, so
20839
+ // the ID of each key will change every time it's updated. Perhaps a stored
20840
+ // procedure for the `setItem()` SQL would solve this problem?
20841
+ // TODO: Don't change ID on `setItem()`.
20842
+ function key$1(n, callback) {
20843
+ var self = this;
20844
+
20845
+ var promise = new Promise$1(function (resolve, reject) {
20846
+ self.ready().then(function () {
20847
+ var dbInfo = self._dbInfo;
20848
+ dbInfo.db.transaction(function (t) {
20849
+ tryExecuteSql(t, dbInfo, 'SELECT key FROM ' + dbInfo.storeName + ' WHERE id = ? LIMIT 1', [n + 1], function (t, results) {
20850
+ var result = results.rows.length ? results.rows.item(0).key : null;
20851
+ resolve(result);
20852
+ }, function (t, error) {
20853
+ reject(error);
20854
+ });
20855
+ });
20856
+ })["catch"](reject);
20857
+ });
20858
+
20859
+ executeCallback(promise, callback);
20860
+ return promise;
20861
+ }
20862
+
20863
+ function keys$1(callback) {
20864
+ var self = this;
20865
+
20866
+ var promise = new Promise$1(function (resolve, reject) {
20867
+ self.ready().then(function () {
20868
+ var dbInfo = self._dbInfo;
20869
+ dbInfo.db.transaction(function (t) {
20870
+ tryExecuteSql(t, dbInfo, 'SELECT key FROM ' + dbInfo.storeName, [], function (t, results) {
20871
+ var keys = [];
20872
+
20873
+ for (var i = 0; i < results.rows.length; i++) {
20874
+ keys.push(results.rows.item(i).key);
20875
+ }
20876
+
20877
+ resolve(keys);
20878
+ }, function (t, error) {
20879
+ reject(error);
20880
+ });
20881
+ });
20882
+ })["catch"](reject);
20883
+ });
20884
+
20885
+ executeCallback(promise, callback);
20886
+ return promise;
20887
+ }
20888
+
20889
+ // https://www.w3.org/TR/webdatabase/#databases
20890
+ // > There is no way to enumerate or delete the databases available for an origin from this API.
20891
+ function getAllStoreNames(db) {
20892
+ return new Promise$1(function (resolve, reject) {
20893
+ db.transaction(function (t) {
20894
+ t.executeSql('SELECT name FROM sqlite_master ' + "WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'", [], function (t, results) {
20895
+ var storeNames = [];
20896
+
20897
+ for (var i = 0; i < results.rows.length; i++) {
20898
+ storeNames.push(results.rows.item(i).name);
20899
+ }
20900
+
20901
+ resolve({
20902
+ db: db,
20903
+ storeNames: storeNames
20904
+ });
20905
+ }, function (t, error) {
20906
+ reject(error);
20907
+ });
20908
+ }, function (sqlError) {
20909
+ reject(sqlError);
20910
+ });
20911
+ });
20912
+ }
20913
+
20914
+ function dropInstance$1(options, callback) {
20915
+ callback = getCallback.apply(this, arguments);
20916
+
20917
+ var currentConfig = this.config();
20918
+ options = typeof options !== 'function' && options || {};
20919
+ if (!options.name) {
20920
+ options.name = options.name || currentConfig.name;
20921
+ options.storeName = options.storeName || currentConfig.storeName;
20922
+ }
20923
+
20924
+ var self = this;
20925
+ var promise;
20926
+ if (!options.name) {
20927
+ promise = Promise$1.reject('Invalid arguments');
20928
+ } else {
20929
+ promise = new Promise$1(function (resolve) {
20930
+ var db;
20931
+ if (options.name === currentConfig.name) {
20932
+ // use the db reference of the current instance
20933
+ db = self._dbInfo.db;
20934
+ } else {
20935
+ db = openDatabase(options.name, '', '', 0);
20936
+ }
20937
+
20938
+ if (!options.storeName) {
20939
+ // drop all database tables
20940
+ resolve(getAllStoreNames(db));
20941
+ } else {
20942
+ resolve({
20943
+ db: db,
20944
+ storeNames: [options.storeName]
20945
+ });
20946
+ }
20947
+ }).then(function (operationInfo) {
20948
+ return new Promise$1(function (resolve, reject) {
20949
+ operationInfo.db.transaction(function (t) {
20950
+ function dropTable(storeName) {
20951
+ return new Promise$1(function (resolve, reject) {
20952
+ t.executeSql('DROP TABLE IF EXISTS ' + storeName, [], function () {
20953
+ resolve();
20954
+ }, function (t, error) {
20955
+ reject(error);
20956
+ });
20957
+ });
20958
+ }
20959
+
20960
+ var operations = [];
20961
+ for (var i = 0, len = operationInfo.storeNames.length; i < len; i++) {
20962
+ operations.push(dropTable(operationInfo.storeNames[i]));
20963
+ }
20964
+
20965
+ Promise$1.all(operations).then(function () {
20966
+ resolve();
20967
+ })["catch"](function (e) {
20968
+ reject(e);
20969
+ });
20970
+ }, function (sqlError) {
20971
+ reject(sqlError);
20972
+ });
20973
+ });
20974
+ });
20975
+ }
20976
+
20977
+ executeCallback(promise, callback);
20978
+ return promise;
20979
+ }
20980
+
20981
+ var webSQLStorage = {
20982
+ _driver: 'webSQLStorage',
20983
+ _initStorage: _initStorage$1,
20984
+ _support: isWebSQLValid(),
20985
+ iterate: iterate$1,
20986
+ getItem: getItem$1,
20987
+ setItem: setItem$1,
20988
+ removeItem: removeItem$1,
20989
+ clear: clear$1,
20990
+ length: length$1,
20991
+ key: key$1,
20992
+ keys: keys$1,
20993
+ dropInstance: dropInstance$1
20994
+ };
20995
+
20996
+ function isLocalStorageValid() {
20997
+ try {
20998
+ return typeof localStorage !== 'undefined' && 'setItem' in localStorage &&
20999
+ // in IE8 typeof localStorage.setItem === 'object'
21000
+ !!localStorage.setItem;
21001
+ } catch (e) {
21002
+ return false;
21003
+ }
21004
+ }
21005
+
21006
+ function _getKeyPrefix(options, defaultConfig) {
21007
+ var keyPrefix = options.name + '/';
21008
+
21009
+ if (options.storeName !== defaultConfig.storeName) {
21010
+ keyPrefix += options.storeName + '/';
21011
+ }
21012
+ return keyPrefix;
21013
+ }
21014
+
21015
+ // Check if localStorage throws when saving an item
21016
+ function checkIfLocalStorageThrows() {
21017
+ var localStorageTestKey = '_localforage_support_test';
21018
+
21019
+ try {
21020
+ localStorage.setItem(localStorageTestKey, true);
21021
+ localStorage.removeItem(localStorageTestKey);
21022
+
21023
+ return false;
21024
+ } catch (e) {
21025
+ return true;
21026
+ }
21027
+ }
21028
+
21029
+ // Check if localStorage is usable and allows to save an item
21030
+ // This method checks if localStorage is usable in Safari Private Browsing
21031
+ // mode, or in any other case where the available quota for localStorage
21032
+ // is 0 and there wasn't any saved items yet.
21033
+ function _isLocalStorageUsable() {
21034
+ return !checkIfLocalStorageThrows() || localStorage.length > 0;
21035
+ }
21036
+
21037
+ // Config the localStorage backend, using options set in the config.
21038
+ function _initStorage$2(options) {
21039
+ var self = this;
21040
+ var dbInfo = {};
21041
+ if (options) {
21042
+ for (var i in options) {
21043
+ dbInfo[i] = options[i];
21044
+ }
21045
+ }
21046
+
21047
+ dbInfo.keyPrefix = _getKeyPrefix(options, self._defaultConfig);
21048
+
21049
+ if (!_isLocalStorageUsable()) {
21050
+ return Promise$1.reject();
21051
+ }
21052
+
21053
+ self._dbInfo = dbInfo;
21054
+ dbInfo.serializer = localforageSerializer;
21055
+
21056
+ return Promise$1.resolve();
21057
+ }
21058
+
21059
+ // Remove all keys from the datastore, effectively destroying all data in
21060
+ // the app's key/value store!
21061
+ function clear$2(callback) {
21062
+ var self = this;
21063
+ var promise = self.ready().then(function () {
21064
+ var keyPrefix = self._dbInfo.keyPrefix;
21065
+
21066
+ for (var i = localStorage.length - 1; i >= 0; i--) {
21067
+ var key = localStorage.key(i);
21068
+
21069
+ if (key.indexOf(keyPrefix) === 0) {
21070
+ localStorage.removeItem(key);
21071
+ }
21072
+ }
21073
+ });
21074
+
21075
+ executeCallback(promise, callback);
21076
+ return promise;
21077
+ }
21078
+
21079
+ // Retrieve an item from the store. Unlike the original async_storage
21080
+ // library in Gaia, we don't modify return values at all. If a key's value
21081
+ // is `undefined`, we pass that value to the callback function.
21082
+ function getItem$2(key, callback) {
21083
+ var self = this;
21084
+
21085
+ key = normalizeKey(key);
21086
+
21087
+ var promise = self.ready().then(function () {
21088
+ var dbInfo = self._dbInfo;
21089
+ var result = localStorage.getItem(dbInfo.keyPrefix + key);
21090
+
21091
+ // If a result was found, parse it from the serialized
21092
+ // string into a JS object. If result isn't truthy, the key
21093
+ // is likely undefined and we'll pass it straight to the
21094
+ // callback.
21095
+ if (result) {
21096
+ result = dbInfo.serializer.deserialize(result);
21097
+ }
21098
+
21099
+ return result;
21100
+ });
21101
+
21102
+ executeCallback(promise, callback);
21103
+ return promise;
21104
+ }
21105
+
21106
+ // Iterate over all items in the store.
21107
+ function iterate$2(iterator, callback) {
21108
+ var self = this;
21109
+
21110
+ var promise = self.ready().then(function () {
21111
+ var dbInfo = self._dbInfo;
21112
+ var keyPrefix = dbInfo.keyPrefix;
21113
+ var keyPrefixLength = keyPrefix.length;
21114
+ var length = localStorage.length;
21115
+
21116
+ // We use a dedicated iterator instead of the `i` variable below
21117
+ // so other keys we fetch in localStorage aren't counted in
21118
+ // the `iterationNumber` argument passed to the `iterate()`
21119
+ // callback.
21120
+ //
21121
+ // See: github.com/mozilla/localForage/pull/435#discussion_r38061530
21122
+ var iterationNumber = 1;
21123
+
21124
+ for (var i = 0; i < length; i++) {
21125
+ var key = localStorage.key(i);
21126
+ if (key.indexOf(keyPrefix) !== 0) {
21127
+ continue;
21128
+ }
21129
+ var value = localStorage.getItem(key);
21130
+
21131
+ // If a result was found, parse it from the serialized
21132
+ // string into a JS object. If result isn't truthy, the
21133
+ // key is likely undefined and we'll pass it straight
21134
+ // to the iterator.
21135
+ if (value) {
21136
+ value = dbInfo.serializer.deserialize(value);
21137
+ }
21138
+
21139
+ value = iterator(value, key.substring(keyPrefixLength), iterationNumber++);
21140
+
21141
+ if (value !== void 0) {
21142
+ return value;
21143
+ }
21144
+ }
21145
+ });
21146
+
21147
+ executeCallback(promise, callback);
21148
+ return promise;
21149
+ }
21150
+
21151
+ // Same as localStorage's key() method, except takes a callback.
21152
+ function key$2(n, callback) {
21153
+ var self = this;
21154
+ var promise = self.ready().then(function () {
21155
+ var dbInfo = self._dbInfo;
21156
+ var result;
21157
+ try {
21158
+ result = localStorage.key(n);
21159
+ } catch (error) {
21160
+ result = null;
21161
+ }
21162
+
21163
+ // Remove the prefix from the key, if a key is found.
21164
+ if (result) {
21165
+ result = result.substring(dbInfo.keyPrefix.length);
21166
+ }
21167
+
21168
+ return result;
21169
+ });
21170
+
21171
+ executeCallback(promise, callback);
21172
+ return promise;
21173
+ }
21174
+
21175
+ function keys$2(callback) {
21176
+ var self = this;
21177
+ var promise = self.ready().then(function () {
21178
+ var dbInfo = self._dbInfo;
21179
+ var length = localStorage.length;
21180
+ var keys = [];
21181
+
21182
+ for (var i = 0; i < length; i++) {
21183
+ var itemKey = localStorage.key(i);
21184
+ if (itemKey.indexOf(dbInfo.keyPrefix) === 0) {
21185
+ keys.push(itemKey.substring(dbInfo.keyPrefix.length));
21186
+ }
21187
+ }
21188
+
21189
+ return keys;
21190
+ });
21191
+
21192
+ executeCallback(promise, callback);
21193
+ return promise;
21194
+ }
21195
+
21196
+ // Supply the number of keys in the datastore to the callback function.
21197
+ function length$2(callback) {
21198
+ var self = this;
21199
+ var promise = self.keys().then(function (keys) {
21200
+ return keys.length;
21201
+ });
21202
+
21203
+ executeCallback(promise, callback);
21204
+ return promise;
21205
+ }
21206
+
21207
+ // Remove an item from the store, nice and simple.
21208
+ function removeItem$2(key, callback) {
21209
+ var self = this;
21210
+
21211
+ key = normalizeKey(key);
21212
+
21213
+ var promise = self.ready().then(function () {
21214
+ var dbInfo = self._dbInfo;
21215
+ localStorage.removeItem(dbInfo.keyPrefix + key);
21216
+ });
21217
+
21218
+ executeCallback(promise, callback);
21219
+ return promise;
21220
+ }
21221
+
21222
+ // Set a key's value and run an optional callback once the value is set.
21223
+ // Unlike Gaia's implementation, the callback function is passed the value,
21224
+ // in case you want to operate on that value only after you're sure it
21225
+ // saved, or something like that.
21226
+ function setItem$2(key, value, callback) {
21227
+ var self = this;
21228
+
21229
+ key = normalizeKey(key);
21230
+
21231
+ var promise = self.ready().then(function () {
21232
+ // Convert undefined values to null.
21233
+ // https://github.com/mozilla/localForage/pull/42
21234
+ if (value === undefined) {
21235
+ value = null;
21236
+ }
21237
+
21238
+ // Save the original value to pass to the callback.
21239
+ var originalValue = value;
21240
+
21241
+ return new Promise$1(function (resolve, reject) {
21242
+ var dbInfo = self._dbInfo;
21243
+ dbInfo.serializer.serialize(value, function (value, error) {
21244
+ if (error) {
21245
+ reject(error);
21246
+ } else {
21247
+ try {
21248
+ localStorage.setItem(dbInfo.keyPrefix + key, value);
21249
+ resolve(originalValue);
21250
+ } catch (e) {
21251
+ // localStorage capacity exceeded.
21252
+ // TODO: Make this a specific error/event.
21253
+ if (e.name === 'QuotaExceededError' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {
21254
+ reject(e);
21255
+ }
21256
+ reject(e);
21257
+ }
21258
+ }
21259
+ });
21260
+ });
21261
+ });
21262
+
21263
+ executeCallback(promise, callback);
21264
+ return promise;
21265
+ }
21266
+
21267
+ function dropInstance$2(options, callback) {
21268
+ callback = getCallback.apply(this, arguments);
21269
+
21270
+ options = typeof options !== 'function' && options || {};
21271
+ if (!options.name) {
21272
+ var currentConfig = this.config();
21273
+ options.name = options.name || currentConfig.name;
21274
+ options.storeName = options.storeName || currentConfig.storeName;
21275
+ }
21276
+
21277
+ var self = this;
21278
+ var promise;
21279
+ if (!options.name) {
21280
+ promise = Promise$1.reject('Invalid arguments');
21281
+ } else {
21282
+ promise = new Promise$1(function (resolve) {
21283
+ if (!options.storeName) {
21284
+ resolve(options.name + '/');
21285
+ } else {
21286
+ resolve(_getKeyPrefix(options, self._defaultConfig));
21287
+ }
21288
+ }).then(function (keyPrefix) {
21289
+ for (var i = localStorage.length - 1; i >= 0; i--) {
21290
+ var key = localStorage.key(i);
21291
+
21292
+ if (key.indexOf(keyPrefix) === 0) {
21293
+ localStorage.removeItem(key);
21294
+ }
21295
+ }
21296
+ });
21297
+ }
21298
+
21299
+ executeCallback(promise, callback);
21300
+ return promise;
21301
+ }
21302
+
21303
+ var localStorageWrapper = {
21304
+ _driver: 'localStorageWrapper',
21305
+ _initStorage: _initStorage$2,
21306
+ _support: isLocalStorageValid(),
21307
+ iterate: iterate$2,
21308
+ getItem: getItem$2,
21309
+ setItem: setItem$2,
21310
+ removeItem: removeItem$2,
21311
+ clear: clear$2,
21312
+ length: length$2,
21313
+ key: key$2,
21314
+ keys: keys$2,
21315
+ dropInstance: dropInstance$2
21316
+ };
21317
+
21318
+ var sameValue = function sameValue(x, y) {
21319
+ return x === y || typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y);
21320
+ };
21321
+
21322
+ var includes = function includes(array, searchElement) {
21323
+ var len = array.length;
21324
+ var i = 0;
21325
+ while (i < len) {
21326
+ if (sameValue(array[i], searchElement)) {
21327
+ return true;
21328
+ }
21329
+ i++;
21330
+ }
21331
+
21332
+ return false;
21333
+ };
21334
+
21335
+ var isArray = Array.isArray || function (arg) {
21336
+ return Object.prototype.toString.call(arg) === '[object Array]';
21337
+ };
21338
+
21339
+ // Drivers are stored here when `defineDriver()` is called.
21340
+ // They are shared across all instances of localForage.
21341
+ var DefinedDrivers = {};
21342
+
21343
+ var DriverSupport = {};
21344
+
21345
+ var DefaultDrivers = {
21346
+ INDEXEDDB: asyncStorage,
21347
+ WEBSQL: webSQLStorage,
21348
+ LOCALSTORAGE: localStorageWrapper
21349
+ };
21350
+
21351
+ var DefaultDriverOrder = [DefaultDrivers.INDEXEDDB._driver, DefaultDrivers.WEBSQL._driver, DefaultDrivers.LOCALSTORAGE._driver];
21352
+
21353
+ var OptionalDriverMethods = ['dropInstance'];
21354
+
21355
+ var LibraryMethods = ['clear', 'getItem', 'iterate', 'key', 'keys', 'length', 'removeItem', 'setItem'].concat(OptionalDriverMethods);
21356
+
21357
+ var DefaultConfig = {
21358
+ description: '',
21359
+ driver: DefaultDriverOrder.slice(),
21360
+ name: 'localforage',
21361
+ // Default DB size is _JUST UNDER_ 5MB, as it's the highest size
21362
+ // we can use without a prompt.
21363
+ size: 4980736,
21364
+ storeName: 'keyvaluepairs',
21365
+ version: 1.0
21366
+ };
21367
+
21368
+ function callWhenReady(localForageInstance, libraryMethod) {
21369
+ localForageInstance[libraryMethod] = function () {
21370
+ var _args = arguments;
21371
+ return localForageInstance.ready().then(function () {
21372
+ return localForageInstance[libraryMethod].apply(localForageInstance, _args);
21373
+ });
21374
+ };
21375
+ }
21376
+
21377
+ function extend() {
21378
+ for (var i = 1; i < arguments.length; i++) {
21379
+ var arg = arguments[i];
21380
+
21381
+ if (arg) {
21382
+ for (var _key in arg) {
21383
+ if (arg.hasOwnProperty(_key)) {
21384
+ if (isArray(arg[_key])) {
21385
+ arguments[0][_key] = arg[_key].slice();
21386
+ } else {
21387
+ arguments[0][_key] = arg[_key];
21388
+ }
21389
+ }
21390
+ }
21391
+ }
21392
+ }
21393
+
21394
+ return arguments[0];
21395
+ }
21396
+
21397
+ var LocalForage = function () {
21398
+ function LocalForage(options) {
21399
+ _classCallCheck(this, LocalForage);
21400
+
21401
+ for (var driverTypeKey in DefaultDrivers) {
21402
+ if (DefaultDrivers.hasOwnProperty(driverTypeKey)) {
21403
+ var driver = DefaultDrivers[driverTypeKey];
21404
+ var driverName = driver._driver;
21405
+ this[driverTypeKey] = driverName;
21406
+
21407
+ if (!DefinedDrivers[driverName]) {
21408
+ // we don't need to wait for the promise,
21409
+ // since the default drivers can be defined
21410
+ // in a blocking manner
21411
+ this.defineDriver(driver);
21412
+ }
21413
+ }
21414
+ }
21415
+
21416
+ this._defaultConfig = extend({}, DefaultConfig);
21417
+ this._config = extend({}, this._defaultConfig, options);
21418
+ this._driverSet = null;
21419
+ this._initDriver = null;
21420
+ this._ready = false;
21421
+ this._dbInfo = null;
21422
+
21423
+ this._wrapLibraryMethodsWithReady();
21424
+ this.setDriver(this._config.driver)["catch"](function () {});
21425
+ }
21426
+
21427
+ // Set any config values for localForage; can be called anytime before
21428
+ // the first API call (e.g. `getItem`, `setItem`).
21429
+ // We loop through options so we don't overwrite existing config
21430
+ // values.
21431
+
21432
+
21433
+ LocalForage.prototype.config = function config(options) {
21434
+ // If the options argument is an object, we use it to set values.
21435
+ // Otherwise, we return either a specified config value or all
21436
+ // config values.
21437
+ if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object') {
21438
+ // If localforage is ready and fully initialized, we can't set
21439
+ // any new configuration values. Instead, we return an error.
21440
+ if (this._ready) {
21441
+ return new Error("Can't call config() after localforage " + 'has been used.');
21442
+ }
21443
+
21444
+ for (var i in options) {
21445
+ if (i === 'storeName') {
21446
+ options[i] = options[i].replace(/\W/g, '_');
21447
+ }
21448
+
21449
+ if (i === 'version' && typeof options[i] !== 'number') {
21450
+ return new Error('Database version must be a number.');
21451
+ }
21452
+
21453
+ this._config[i] = options[i];
21454
+ }
21455
+
21456
+ // after all config options are set and
21457
+ // the driver option is used, try setting it
21458
+ if ('driver' in options && options.driver) {
21459
+ return this.setDriver(this._config.driver);
21460
+ }
21461
+
21462
+ return true;
21463
+ } else if (typeof options === 'string') {
21464
+ return this._config[options];
21465
+ } else {
21466
+ return this._config;
21467
+ }
21468
+ };
21469
+
21470
+ // Used to define a custom driver, shared across all instances of
21471
+ // localForage.
21472
+
21473
+
21474
+ LocalForage.prototype.defineDriver = function defineDriver(driverObject, callback, errorCallback) {
21475
+ var promise = new Promise$1(function (resolve, reject) {
21476
+ try {
21477
+ var driverName = driverObject._driver;
21478
+ var complianceError = new Error('Custom driver not compliant; see ' + 'https://mozilla.github.io/localForage/#definedriver');
21479
+
21480
+ // A driver name should be defined and not overlap with the
21481
+ // library-defined, default drivers.
21482
+ if (!driverObject._driver) {
21483
+ reject(complianceError);
21484
+ return;
21485
+ }
21486
+
21487
+ var driverMethods = LibraryMethods.concat('_initStorage');
21488
+ for (var i = 0, len = driverMethods.length; i < len; i++) {
21489
+ var driverMethodName = driverMethods[i];
21490
+
21491
+ // when the property is there,
21492
+ // it should be a method even when optional
21493
+ var isRequired = !includes(OptionalDriverMethods, driverMethodName);
21494
+ if ((isRequired || driverObject[driverMethodName]) && typeof driverObject[driverMethodName] !== 'function') {
21495
+ reject(complianceError);
21496
+ return;
21497
+ }
21498
+ }
21499
+
21500
+ var configureMissingMethods = function configureMissingMethods() {
21501
+ var methodNotImplementedFactory = function methodNotImplementedFactory(methodName) {
21502
+ return function () {
21503
+ var error = new Error('Method ' + methodName + ' is not implemented by the current driver');
21504
+ var promise = Promise$1.reject(error);
21505
+ executeCallback(promise, arguments[arguments.length - 1]);
21506
+ return promise;
21507
+ };
21508
+ };
21509
+
21510
+ for (var _i = 0, _len = OptionalDriverMethods.length; _i < _len; _i++) {
21511
+ var optionalDriverMethod = OptionalDriverMethods[_i];
21512
+ if (!driverObject[optionalDriverMethod]) {
21513
+ driverObject[optionalDriverMethod] = methodNotImplementedFactory(optionalDriverMethod);
21514
+ }
21515
+ }
21516
+ };
21517
+
21518
+ configureMissingMethods();
21519
+
21520
+ var setDriverSupport = function setDriverSupport(support) {
21521
+ if (DefinedDrivers[driverName]) {
21522
+ console.info('Redefining LocalForage driver: ' + driverName);
21523
+ }
21524
+ DefinedDrivers[driverName] = driverObject;
21525
+ DriverSupport[driverName] = support;
21526
+ // don't use a then, so that we can define
21527
+ // drivers that have simple _support methods
21528
+ // in a blocking manner
21529
+ resolve();
21530
+ };
21531
+
21532
+ if ('_support' in driverObject) {
21533
+ if (driverObject._support && typeof driverObject._support === 'function') {
21534
+ driverObject._support().then(setDriverSupport, reject);
21535
+ } else {
21536
+ setDriverSupport(!!driverObject._support);
21537
+ }
21538
+ } else {
21539
+ setDriverSupport(true);
21540
+ }
21541
+ } catch (e) {
21542
+ reject(e);
21543
+ }
21544
+ });
21545
+
21546
+ executeTwoCallbacks(promise, callback, errorCallback);
21547
+ return promise;
21548
+ };
21549
+
21550
+ LocalForage.prototype.driver = function driver() {
21551
+ return this._driver || null;
21552
+ };
21553
+
21554
+ LocalForage.prototype.getDriver = function getDriver(driverName, callback, errorCallback) {
21555
+ var getDriverPromise = DefinedDrivers[driverName] ? Promise$1.resolve(DefinedDrivers[driverName]) : Promise$1.reject(new Error('Driver not found.'));
21556
+
21557
+ executeTwoCallbacks(getDriverPromise, callback, errorCallback);
21558
+ return getDriverPromise;
21559
+ };
21560
+
21561
+ LocalForage.prototype.getSerializer = function getSerializer(callback) {
21562
+ var serializerPromise = Promise$1.resolve(localforageSerializer);
21563
+ executeTwoCallbacks(serializerPromise, callback);
21564
+ return serializerPromise;
21565
+ };
21566
+
21567
+ LocalForage.prototype.ready = function ready(callback) {
21568
+ var self = this;
21569
+
21570
+ var promise = self._driverSet.then(function () {
21571
+ if (self._ready === null) {
21572
+ self._ready = self._initDriver();
21573
+ }
21574
+
21575
+ return self._ready;
21576
+ });
21577
+
21578
+ executeTwoCallbacks(promise, callback, callback);
21579
+ return promise;
21580
+ };
21581
+
21582
+ LocalForage.prototype.setDriver = function setDriver(drivers, callback, errorCallback) {
21583
+ var self = this;
21584
+
21585
+ if (!isArray(drivers)) {
21586
+ drivers = [drivers];
21587
+ }
21588
+
21589
+ var supportedDrivers = this._getSupportedDrivers(drivers);
21590
+
21591
+ function setDriverToConfig() {
21592
+ self._config.driver = self.driver();
21593
+ }
21594
+
21595
+ function extendSelfWithDriver(driver) {
21596
+ self._extend(driver);
21597
+ setDriverToConfig();
21598
+
21599
+ self._ready = self._initStorage(self._config);
21600
+ return self._ready;
21601
+ }
21602
+
21603
+ function initDriver(supportedDrivers) {
21604
+ return function () {
21605
+ var currentDriverIndex = 0;
21606
+
21607
+ function driverPromiseLoop() {
21608
+ while (currentDriverIndex < supportedDrivers.length) {
21609
+ var driverName = supportedDrivers[currentDriverIndex];
21610
+ currentDriverIndex++;
21611
+
21612
+ self._dbInfo = null;
21613
+ self._ready = null;
21614
+
21615
+ return self.getDriver(driverName).then(extendSelfWithDriver)["catch"](driverPromiseLoop);
21616
+ }
21617
+
21618
+ setDriverToConfig();
21619
+ var error = new Error('No available storage method found.');
21620
+ self._driverSet = Promise$1.reject(error);
21621
+ return self._driverSet;
21622
+ }
21623
+
21624
+ return driverPromiseLoop();
21625
+ };
21626
+ }
21627
+
21628
+ // There might be a driver initialization in progress
21629
+ // so wait for it to finish in order to avoid a possible
21630
+ // race condition to set _dbInfo
21631
+ var oldDriverSetDone = this._driverSet !== null ? this._driverSet["catch"](function () {
21632
+ return Promise$1.resolve();
21633
+ }) : Promise$1.resolve();
21634
+
21635
+ this._driverSet = oldDriverSetDone.then(function () {
21636
+ var driverName = supportedDrivers[0];
21637
+ self._dbInfo = null;
21638
+ self._ready = null;
21639
+
21640
+ return self.getDriver(driverName).then(function (driver) {
21641
+ self._driver = driver._driver;
21642
+ setDriverToConfig();
21643
+ self._wrapLibraryMethodsWithReady();
21644
+ self._initDriver = initDriver(supportedDrivers);
21645
+ });
21646
+ })["catch"](function () {
21647
+ setDriverToConfig();
21648
+ var error = new Error('No available storage method found.');
21649
+ self._driverSet = Promise$1.reject(error);
21650
+ return self._driverSet;
21651
+ });
21652
+
21653
+ executeTwoCallbacks(this._driverSet, callback, errorCallback);
21654
+ return this._driverSet;
21655
+ };
21656
+
21657
+ LocalForage.prototype.supports = function supports(driverName) {
21658
+ return !!DriverSupport[driverName];
21659
+ };
21660
+
21661
+ LocalForage.prototype._extend = function _extend(libraryMethodsAndProperties) {
21662
+ extend(this, libraryMethodsAndProperties);
21663
+ };
21664
+
21665
+ LocalForage.prototype._getSupportedDrivers = function _getSupportedDrivers(drivers) {
21666
+ var supportedDrivers = [];
21667
+ for (var i = 0, len = drivers.length; i < len; i++) {
21668
+ var driverName = drivers[i];
21669
+ if (this.supports(driverName)) {
21670
+ supportedDrivers.push(driverName);
21671
+ }
21672
+ }
21673
+ return supportedDrivers;
21674
+ };
21675
+
21676
+ LocalForage.prototype._wrapLibraryMethodsWithReady = function _wrapLibraryMethodsWithReady() {
21677
+ // Add a stub for each driver API method that delays the call to the
21678
+ // corresponding driver method until localForage is ready. These stubs
21679
+ // will be replaced by the driver methods as soon as the driver is
21680
+ // loaded, so there is no performance impact.
21681
+ for (var i = 0, len = LibraryMethods.length; i < len; i++) {
21682
+ callWhenReady(this, LibraryMethods[i]);
21683
+ }
21684
+ };
21685
+
21686
+ LocalForage.prototype.createInstance = function createInstance(options) {
21687
+ return new LocalForage(options);
21688
+ };
21689
+
21690
+ return LocalForage;
21691
+ }();
21692
+
21693
+ // The actual localForage object that we expose as a module or via a
21694
+ // global. It's extended by pulling in one of our other libraries.
21695
+
21696
+
21697
+ var localforage_js = new LocalForage();
21698
+
21699
+ module.exports = localforage_js;
21700
+
21701
+ },{"3":3}]},{},[4])(4)
21702
+ });
21703
+ } (localforage$1));
21704
+
21705
+ var localforageExports = localforage$1.exports;
21706
+ var localforage = /*@__PURE__*/getDefaultExportFromCjs(localforageExports);
21707
+
21708
+ var store$1 = localforage.createInstance({
21709
+ name: 'spu-db',
21710
+ storeName: 'axios-cache'
21711
+ });
21712
+ var defaultCachetime$1 = 60 * 1000 * 60 * 24 * 7; // 默认缓存7天
21713
+ // 将数据转换成indexDB能够保存的格式
21714
+ // structuredClone 不支持的格式全部转成null
21715
+ // Error 类型保留
21716
+ var transform2IndexDB = function transform2IndexDB(data) {
21717
+ var reverse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
21718
+ if (!reverse) {
21719
+ if (Object.prototype.toString.call(data) === '[object Array]') {
21720
+ return data.map(transform2IndexDB);
21721
+ } else if (Object.prototype.toString.call(data) === '[object Object]') {
21722
+ return Object.fromEntries(new Map(Object.entries(data).map(function (item) {
21723
+ return [item[0], transform2IndexDB(item[1])];
21724
+ })));
21725
+ } else if (Object.prototype.toString.call(data) === '[object Error]') {
21726
+ return _objectSpread2$1({
21727
+ __error__: true,
21728
+ name: data.name,
21729
+ message: data.message,
21730
+ stack: data.stack
21731
+ }, Object.fromEntries(Object.getOwnPropertyNames(data).filter(function (prop) {
21732
+ return !['name', 'message', 'stack'].includes(prop);
21733
+ }).map(function (prop) {
21734
+ return [prop, transform2IndexDB(data[prop])];
21735
+ })));
21736
+ } else {
21737
+ // 不支持的类型不报错 转换为null
21738
+ try {
21739
+ return structuredClone(data);
21740
+ // return data
21741
+ } catch (err) {
21742
+ // console.error(err)
21743
+ return null;
21744
+ }
21745
+ }
21746
+ } else {
21747
+ if (Object.prototype.toString.call(data) === '[object Array]') {
21748
+ return data.map(function (item) {
21749
+ return transform2IndexDB(item, true);
21750
+ });
21751
+ } else if (Object.prototype.toString.call(data) === '[object Object]') {
21752
+ if (data.__error__) {
21753
+ var error = new Error(data.message);
21754
+ error.name = data.name;
21755
+ error.stack = data.stack;
21756
+ // 恢复其他自定义属性
21757
+ Object.keys(data).forEach(function (key) {
21758
+ if (!['__error__', 'name', 'message', 'stack'].includes(key)) {
21759
+ error[key] = transform2IndexDB(data[key], true);
21760
+ }
21761
+ });
21762
+ return error;
21763
+ } else {
21764
+ return Object.fromEntries(new Map(Object.entries(data).map(function (item) {
21765
+ return [item[0], transform2IndexDB(item[1], true)];
21766
+ })));
21767
+ }
21768
+ } else {
21769
+ // 不支持的类型不报错 转换为null
21770
+ try {
21771
+ return structuredClone(data);
21772
+ // return data
21773
+ } catch (err) {
21774
+ // console.error(err)
21775
+ return null;
21776
+ }
21777
+ }
21778
+ }
21779
+ };
21780
+ // window.addEventListener('online', () => {
21781
+ // console.log('浏览器已恢复在线')
21782
+ // })
21783
+ // window.addEventListener('offline', () => {
21784
+ // console.log('浏览器已离线')
21785
+ // console.log('当前处于离线状态,部分功能受限,恢复联网后将自动同步数据')
21786
+ // })
21787
+ // 生成缓存键 缓存区分租户和人员
21788
+ var generateCacheKey = function generateCacheKey(axiosRequestConfig) {
21789
+ var tenantcode = getUser('tenantcode') || '';
21790
+ var mbcode = getUser('mbcode') || getUser('membercode') || '';
21791
+ var baseURL = (axiosRequestConfig === null || axiosRequestConfig === void 0 ? void 0 : axiosRequestConfig.baseURL) || '';
21792
+ var url = (axiosRequestConfig === null || axiosRequestConfig === void 0 ? void 0 : axiosRequestConfig.url) || '';
21793
+ var method = (axiosRequestConfig === null || axiosRequestConfig === void 0 ? void 0 : axiosRequestConfig.method) || 'get';
21794
+ var params = JSON.stringify((axiosRequestConfig === null || axiosRequestConfig === void 0 ? void 0 : axiosRequestConfig.params) || {});
21795
+ var data = JSON.stringify((axiosRequestConfig === null || axiosRequestConfig === void 0 ? void 0 : axiosRequestConfig.data) || {});
21796
+ return "tenantcode=".concat(tenantcode, "&mbcode=").concat(mbcode, "&baseURL=").concat(baseURL, "&url=").concat(url, "&method=").concat(method, "&params=").concat(params, "&data=").concat(data);
21797
+ };
21798
+ var removeCache = /*#__PURE__*/function () {
21799
+ var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(cachekey) {
21800
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
21801
+ while (1) switch (_context.prev = _context.next) {
21802
+ case 0:
21803
+ _context.next = 2;
21804
+ return store$1.removeItem(cachekey);
21805
+ case 2:
21806
+ case "end":
21807
+ return _context.stop();
21808
+ }
21809
+ }, _callee);
21810
+ }));
21811
+ return function removeCache(_x) {
21812
+ return _ref.apply(this, arguments);
21813
+ };
21814
+ }();
21815
+ var setCache$1 = /*#__PURE__*/function () {
21816
+ var _ref2 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2(cachekey, cache) {
21817
+ return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
21818
+ while (1) switch (_context2.prev = _context2.next) {
21819
+ case 0:
21820
+ _context2.next = 2;
21821
+ return store$1.setItem(cachekey, transform2IndexDB(cache));
21822
+ case 2:
21823
+ case "end":
21824
+ return _context2.stop();
21825
+ }
21826
+ }, _callee2);
21827
+ }));
21828
+ return function setCache(_x2, _x3) {
21829
+ return _ref2.apply(this, arguments);
21830
+ };
21831
+ }();
21832
+ var getCache$1 = /*#__PURE__*/function () {
21833
+ var _ref3 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3(cachekey) {
21834
+ var cacheSource, cache, isusecache;
21835
+ return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
21836
+ while (1) switch (_context3.prev = _context3.next) {
21837
+ case 0:
21838
+ _context3.next = 2;
21839
+ return store$1.getItem(cachekey);
21840
+ case 2:
21841
+ cacheSource = _context3.sent;
21842
+ cache = transform2IndexDB(cacheSource, true);
21843
+ isusecache = false;
21844
+ if (!(cache && Date.now() <= cache.expiretime)) {
21845
+ _context3.next = 9;
21846
+ break;
21847
+ }
21848
+ isusecache = true;
21849
+ _context3.next = 16;
21850
+ break;
21851
+ case 9:
21852
+ if (!(cache && Date.now() > cache.expiretime)) {
21853
+ _context3.next = 15;
21854
+ break;
21855
+ }
21856
+ isusecache = false;
21857
+ // 获取缓存时发现数据过期顺便清掉
21858
+ _context3.next = 13;
21859
+ return removeCache(cachekey);
21860
+ case 13:
21861
+ _context3.next = 16;
21862
+ break;
21863
+ case 15:
21864
+ isusecache = false;
21865
+ case 16:
21866
+ return _context3.abrupt("return", isusecache ? cache : null);
21867
+ case 17:
21868
+ case "end":
21869
+ return _context3.stop();
21870
+ }
21871
+ }, _callee3);
21872
+ }));
21873
+ return function getCache(_x4) {
21874
+ return _ref3.apply(this, arguments);
21875
+ };
21876
+ }();
21877
+ var cacheToAxiosResponse = /*#__PURE__*/function () {
21878
+ var _ref4 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4(cache) {
21879
+ return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
21880
+ while (1) switch (_context4.prev = _context4.next) {
21881
+ case 0:
21882
+ return _context4.abrupt("return", new Promise(function (resolve, reject) {
21883
+ if (cache.success) {
21884
+ return resolve(cache.response);
21885
+ } else {
21886
+ return reject(cache.response);
21887
+ }
21888
+ }));
21889
+ case 1:
21890
+ case "end":
21891
+ return _context4.stop();
21892
+ }
21893
+ }, _callee4);
21894
+ }));
21895
+ return function cacheToAxiosResponse(_x5) {
21896
+ return _ref4.apply(this, arguments);
21897
+ };
21898
+ }();
21899
+ var axiosPromiseToCache = /*#__PURE__*/function () {
21900
+ var _ref5 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(axiosPro, cachetime) {
21901
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
21902
+ while (1) switch (_context5.prev = _context5.next) {
21903
+ case 0:
21904
+ return _context5.abrupt("return", new Promise(function (resolve, reject) {
21905
+ var realCachetime = Number(cachetime || defaultCachetime$1);
21906
+ var success = false;
21907
+ var response = null;
21908
+ axiosPro.then(function (res) {
21909
+ success = true;
21910
+ response = res;
21911
+ })["catch"](function (err) {
21912
+ success = false;
21913
+ response = err;
21914
+ })["finally"](function () {
21915
+ resolve({
21916
+ cachetime: realCachetime,
21917
+ expiretime: Date.now() + realCachetime,
21918
+ success: success,
21919
+ response: response
21920
+ });
21921
+ });
21922
+ }));
21923
+ case 1:
21924
+ case "end":
21925
+ return _context5.stop();
21926
+ }
21927
+ }, _callee5);
21928
+ }));
21929
+ return function axiosPromiseToCache(_x6, _x7) {
21930
+ return _ref5.apply(this, arguments);
21931
+ };
21932
+ }();
21933
+ var axiosCache = /*#__PURE__*/function () {
21934
+ var _ref6 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee7(config, axiosInstance, axiosRequestConfig) {
21935
+ var strategy, cachekey, online, cache, _cache, _cache2, _online, getAndSetCacheIfOnline, _cache4;
21936
+ return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
21937
+ while (1) switch (_context7.prev = _context7.next) {
21938
+ case 0:
21939
+ // 检查是否启用缓存
21940
+ strategy = (config === null || config === void 0 ? void 0 : config.strategy) || 'network-only';
21941
+ cachekey = generateCacheKey(axiosRequestConfig);
21942
+ if (!(strategy === 'network-first')) {
21943
+ _context7.next = 24;
21944
+ break;
21945
+ }
21946
+ _context7.next = 5;
21947
+ return isOnline();
21948
+ case 5:
21949
+ online = _context7.sent;
21950
+ if (!online) {
21951
+ _context7.next = 14;
21952
+ break;
21953
+ }
21954
+ _context7.next = 9;
21955
+ return axiosPromiseToCache(axiosInstance(axiosRequestConfig), config === null || config === void 0 ? void 0 : config.cachetime);
21956
+ case 9:
21957
+ cache = _context7.sent;
21958
+ setCache$1(cachekey, cache);
21959
+ return _context7.abrupt("return", cacheToAxiosResponse(cache));
21960
+ case 14:
21961
+ _context7.next = 16;
21962
+ return getCache$1(cachekey);
21963
+ case 16:
21964
+ _cache = _context7.sent;
21965
+ if (!_cache) {
21966
+ _context7.next = 21;
21967
+ break;
21968
+ }
21969
+ return _context7.abrupt("return", cacheToAxiosResponse(_cache));
21970
+ case 21:
21971
+ return _context7.abrupt("return", new Error('no cache and offline'));
21972
+ case 22:
21973
+ _context7.next = 48;
21974
+ break;
21975
+ case 24:
21976
+ if (!(strategy === 'cache-first')) {
21977
+ _context7.next = 47;
21978
+ break;
21979
+ }
21980
+ _context7.next = 27;
21981
+ return getCache$1(cachekey);
21982
+ case 27:
21983
+ _cache2 = _context7.sent;
21984
+ _context7.next = 30;
21985
+ return isOnline();
21986
+ case 30:
21987
+ _online = _context7.sent;
21988
+ getAndSetCacheIfOnline = /*#__PURE__*/function () {
21989
+ var _ref7 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee6() {
21990
+ var _cache3;
21991
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
21992
+ while (1) switch (_context6.prev = _context6.next) {
21993
+ case 0:
21994
+ if (!_online) {
21995
+ _context6.next = 8;
21996
+ break;
21997
+ }
21998
+ _context6.next = 3;
21999
+ return axiosPromiseToCache(axiosInstance(axiosRequestConfig), config === null || config === void 0 ? void 0 : config.cachetime);
22000
+ case 3:
22001
+ _cache3 = _context6.sent;
22002
+ setCache$1(cachekey, _cache3);
22003
+ return _context6.abrupt("return", _cache3);
22004
+ case 8:
22005
+ return _context6.abrupt("return", null);
22006
+ case 9:
22007
+ case "end":
22008
+ return _context6.stop();
22009
+ }
22010
+ }, _callee6);
22011
+ }));
22012
+ return function getAndSetCacheIfOnline() {
22013
+ return _ref7.apply(this, arguments);
22014
+ };
22015
+ }();
22016
+ if (!_cache2) {
22017
+ _context7.next = 37;
22018
+ break;
22019
+ }
22020
+ getAndSetCacheIfOnline(); // 这里不等返回 是优先使用缓存 但依然在线获取最新数据
22021
+ // debugger
22022
+ return _context7.abrupt("return", cacheToAxiosResponse(_cache2));
22023
+ case 37:
22024
+ if (!_online) {
22025
+ _context7.next = 44;
22026
+ break;
22027
+ }
22028
+ _context7.next = 40;
22029
+ return getAndSetCacheIfOnline();
22030
+ case 40:
22031
+ _cache4 = _context7.sent;
22032
+ return _context7.abrupt("return", cacheToAxiosResponse(_cache4));
22033
+ case 44:
22034
+ return _context7.abrupt("return", new Error('no cache and offline'));
22035
+ case 45:
22036
+ _context7.next = 48;
22037
+ break;
22038
+ case 47:
22039
+ return _context7.abrupt("return", axiosInstance(axiosRequestConfig));
22040
+ case 48:
22041
+ case "end":
22042
+ return _context7.stop();
22043
+ }
22044
+ }, _callee7);
22045
+ }));
22046
+ return function axiosCache(_x8, _x9, _x10) {
22047
+ return _ref6.apply(this, arguments);
22048
+ };
22049
+ }();
22050
+ var removeExpireDataByCachekey = /*#__PURE__*/function () {
22051
+ var _ref8 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee8(cachekey) {
22052
+ var cacheSource;
22053
+ return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
22054
+ while (1) switch (_context8.prev = _context8.next) {
22055
+ case 0:
22056
+ _context8.next = 2;
22057
+ return store$1.getItem(cachekey);
22058
+ case 2:
22059
+ cacheSource = _context8.sent;
22060
+ if (!(cacheSource && Date.now() > cacheSource.expiretime)) {
22061
+ _context8.next = 6;
22062
+ break;
22063
+ }
22064
+ _context8.next = 6;
22065
+ return removeCache(cachekey);
22066
+ case 6:
22067
+ case "end":
22068
+ return _context8.stop();
22069
+ }
22070
+ }, _callee8);
22071
+ }));
22072
+ return function removeExpireDataByCachekey(_x11) {
22073
+ return _ref8.apply(this, arguments);
22074
+ };
22075
+ }();
22076
+ // 清除过期无效数据
22077
+ var removeExpireData$1 = /*#__PURE__*/function () {
22078
+ var _ref9 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee10() {
22079
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
22080
+ while (1) switch (_context10.prev = _context10.next) {
22081
+ case 0:
22082
+ store$1.keys().then( /*#__PURE__*/function () {
22083
+ var _ref10 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee9(keys) {
22084
+ var i, len, key;
22085
+ return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
22086
+ while (1) switch (_context9.prev = _context9.next) {
22087
+ case 0:
22088
+ i = 0, len = keys.length;
22089
+ case 1:
22090
+ if (!(i < len)) {
22091
+ _context9.next = 8;
22092
+ break;
22093
+ }
22094
+ key = keys[i];
22095
+ _context9.next = 5;
22096
+ return removeExpireDataByCachekey(key);
22097
+ case 5:
22098
+ i++;
22099
+ _context9.next = 1;
22100
+ break;
22101
+ case 8:
22102
+ case "end":
22103
+ return _context9.stop();
22104
+ }
22105
+ }, _callee9);
22106
+ }));
22107
+ return function (_x12) {
22108
+ return _ref10.apply(this, arguments);
22109
+ };
22110
+ }())["catch"](function (err) {
22111
+ console.log(err);
22112
+ });
22113
+ case 1:
22114
+ case "end":
22115
+ return _context10.stop();
22116
+ }
22117
+ }, _callee10);
22118
+ }));
22119
+ return function removeExpireData() {
22120
+ return _ref9.apply(this, arguments);
22121
+ };
22122
+ }();
22123
+ var installAxiosCache = function installAxiosCache() {
22124
+ removeExpireData$1();
22125
+ };
22126
+
18776
22127
  var modulekey = '';
18777
22128
  var customerid = '';
18778
22129
  var customertype = '';
@@ -18923,7 +22274,7 @@ var GlobalConfig = /*#__PURE__*/function () {
18923
22274
  }
18924
22275
  _context.prev = 1;
18925
22276
  _context.next = 4;
18926
- return normalAxios$1.post('/api/pemission/rolepermission/globalconfig/getglobalconfigbytype', {
22277
+ return apaasAxios.post('/api/pemission/rolepermission/globalconfig/getglobalconfigbytype', {
18927
22278
  configtype: '1'
18928
22279
  });
18929
22280
  case 4:
@@ -52302,7 +55653,7 @@ var requestServToken = /*#__PURE__*/function () {
52302
55653
  case 0:
52303
55654
  _context.prev = 0;
52304
55655
  _context.next = 3;
52305
- return normalAxios$1.get('/api/teapi/auth/servtoken').then(function (res) {
55656
+ return apaasAxios.get('/api/teapi/auth/servtoken').then(function (res) {
52306
55657
  return res.data;
52307
55658
  });
52308
55659
  case 3:
@@ -52370,15 +55721,253 @@ var getServToken = function getServToken() {
52370
55721
  });
52371
55722
  };
52372
55723
 
52373
- // import { get } from 'lodash-es'
52374
- // import qs from 'qs'
52375
- // function getUrlPaths(url: string): string[] {
52376
- // let path = url.split('?')[0]
52377
- // if (!path) return []
52378
- // path = path.replace('http://', '')
52379
- // path = path.replace('https://', '')
52380
- // return path.split('/')
52381
- // }
55724
+ var defaultCachetime = 60 * 1000 * 60 * 2; // 默认缓存2小时
55725
+ var store = localforage.createInstance({
55726
+ name: 'spu-db',
55727
+ storeName: 'oss-cache'
55728
+ });
55729
+ // 生成缓存键 缓存区分租户和人员
55730
+ var generateCacheobj = function generateCacheobj(_ref) {
55731
+ var _ref$type = _ref.type,
55732
+ type = _ref$type === void 0 ? 'img' : _ref$type,
55733
+ _ref$source = _ref.source,
55734
+ source = _ref$source === void 0 ? '' : _ref$source,
55735
+ _ref$datetime = _ref.datetime,
55736
+ datetime = _ref$datetime === void 0 ? '' : _ref$datetime,
55737
+ _ref$storagetype = _ref.storagetype,
55738
+ storagetype = _ref$storagetype === void 0 ? 'storage' : _ref$storagetype,
55739
+ _ref$cope = _ref.cope,
55740
+ cope = _ref$cope === void 0 ? '' : _ref$cope;
55741
+ var provider = cloudServ.getProvider(storagetype);
55742
+ var copeStr = provider !== null && provider !== void 0 && provider.isAliyun ? getAliyunCope(cope) : getCope(cope);
55743
+ return {
55744
+ key: "type=".concat(type, "&storagetype=").concat(storagetype, "&source=").concat(source, "&datetime=").concat(datetime),
55745
+ copekey: copeStr || 'default'
55746
+ };
55747
+ };
55748
+ var getAllCachesBykey = /*#__PURE__*/function () {
55749
+ var _ref2 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(key) {
55750
+ var allcaches;
55751
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
55752
+ while (1) switch (_context.prev = _context.next) {
55753
+ case 0:
55754
+ _context.next = 2;
55755
+ return store.getItem(key);
55756
+ case 2:
55757
+ allcaches = _context.sent;
55758
+ return _context.abrupt("return", allcaches || null);
55759
+ case 4:
55760
+ case "end":
55761
+ return _context.stop();
55762
+ }
55763
+ }, _callee);
55764
+ }));
55765
+ return function getAllCachesBykey(_x) {
55766
+ return _ref2.apply(this, arguments);
55767
+ };
55768
+ }();
55769
+ var setCache = /*#__PURE__*/function () {
55770
+ var _ref3 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2(cacheobj, cache) {
55771
+ var allcaches;
55772
+ return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
55773
+ while (1) switch (_context2.prev = _context2.next) {
55774
+ case 0:
55775
+ _context2.next = 2;
55776
+ return getAllCachesBykey(cacheobj.key);
55777
+ case 2:
55778
+ allcaches = _context2.sent;
55779
+ if (allcaches) {
55780
+ allcaches[cacheobj.copekey] = cache;
55781
+ } else {
55782
+ allcaches = _defineProperty$1({}, cacheobj.copekey, cache);
55783
+ }
55784
+ _context2.next = 6;
55785
+ return store.setItem(cacheobj.key, allcaches);
55786
+ case 6:
55787
+ case "end":
55788
+ return _context2.stop();
55789
+ }
55790
+ }, _callee2);
55791
+ }));
55792
+ return function setCache(_x2, _x3) {
55793
+ return _ref3.apply(this, arguments);
55794
+ };
55795
+ }();
55796
+ var setCacheByFile = function setCacheByFile(_ref4) {
55797
+ var _globalOptions$osscac;
55798
+ var _ref4$type = _ref4.type,
55799
+ type = _ref4$type === void 0 ? 'img' : _ref4$type,
55800
+ file = _ref4.file,
55801
+ _ref4$source = _ref4.source,
55802
+ source = _ref4$source === void 0 ? '' : _ref4$source,
55803
+ _ref4$datetime = _ref4.datetime,
55804
+ datetime = _ref4$datetime === void 0 ? '' : _ref4$datetime,
55805
+ _ref4$storagetype = _ref4.storagetype,
55806
+ storagetype = _ref4$storagetype === void 0 ? 'storage' : _ref4$storagetype;
55807
+ // 暂时只作用于图片
55808
+ if (!!(globalOptions !== null && globalOptions !== void 0 && (_globalOptions$osscac = globalOptions.osscache) !== null && _globalOptions$osscac !== void 0 && _globalOptions$osscac.flag) && type === 'img') {
55809
+ setCache(generateCacheobj({
55810
+ type: type,
55811
+ source: source,
55812
+ datetime: datetime,
55813
+ storagetype: storagetype,
55814
+ cope: false
55815
+ }), {
55816
+ cachetime: defaultCachetime,
55817
+ expiretime: Date.now() + defaultCachetime,
55818
+ blob: new Blob([file], {
55819
+ type: file.type // 保留原 File 的 MIME 类型(如 image/png)
55820
+ })
55821
+ });
55822
+ }
55823
+ };
55824
+
55825
+ var isExpireData = function isExpireData(cache) {
55826
+ if (Date.now() > cache.expiretime) {
55827
+ return true;
55828
+ }
55829
+ // return true
55830
+ return false;
55831
+ };
55832
+ var getCache = /*#__PURE__*/function () {
55833
+ var _ref5 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3(cacheobj) {
55834
+ var whennomatchcopekeyreturnanyone,
55835
+ allcaches,
55836
+ cache,
55837
+ noExpireData,
55838
+ x,
55839
+ item,
55840
+ _args3 = arguments;
55841
+ return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
55842
+ while (1) switch (_context3.prev = _context3.next) {
55843
+ case 0:
55844
+ whennomatchcopekeyreturnanyone = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : false;
55845
+ _context3.next = 3;
55846
+ return getAllCachesBykey(cacheobj.key);
55847
+ case 3:
55848
+ allcaches = _context3.sent;
55849
+ cache = null;
55850
+ if (allcaches) {
55851
+ // 找出所有没过期的缓存
55852
+ noExpireData = {};
55853
+ for (x in allcaches) {
55854
+ item = allcaches[x];
55855
+ if (!isExpireData(item)) {
55856
+ noExpireData[x] = item;
55857
+ }
55858
+ }
55859
+ cache = noExpireData[cacheobj.copekey] || null;
55860
+ // 当没命中copekey时,返回默认缓存 默认缓存不存在时返回第一个缓存
55861
+ if (!cache && whennomatchcopekeyreturnanyone && Object.keys(noExpireData).length) {
55862
+ cache = noExpireData['default'] || noExpireData[Object.keys(noExpireData)[0]];
55863
+ }
55864
+ }
55865
+ return _context3.abrupt("return", cache);
55866
+ case 7:
55867
+ case "end":
55868
+ return _context3.stop();
55869
+ }
55870
+ }, _callee3);
55871
+ }));
55872
+ return function getCache(_x4) {
55873
+ return _ref5.apply(this, arguments);
55874
+ };
55875
+ }();
55876
+ var removeExpireDataBykey = /*#__PURE__*/function () {
55877
+ var _ref7 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(key) {
55878
+ var allcaches, x, cache;
55879
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
55880
+ while (1) switch (_context5.prev = _context5.next) {
55881
+ case 0:
55882
+ _context5.next = 2;
55883
+ return getAllCachesBykey(key);
55884
+ case 2:
55885
+ allcaches = _context5.sent;
55886
+ if (!allcaches) {
55887
+ _context5.next = 12;
55888
+ break;
55889
+ }
55890
+ for (x in allcaches) {
55891
+ cache = allcaches[x];
55892
+ if (cache && isExpireData(cache)) {
55893
+ delete allcaches[x];
55894
+ }
55895
+ }
55896
+ if (!Object.keys(allcaches).length) {
55897
+ _context5.next = 10;
55898
+ break;
55899
+ }
55900
+ _context5.next = 8;
55901
+ return store.setItem(key, allcaches);
55902
+ case 8:
55903
+ _context5.next = 12;
55904
+ break;
55905
+ case 10:
55906
+ _context5.next = 12;
55907
+ return store.removeItem(key);
55908
+ case 12:
55909
+ case "end":
55910
+ return _context5.stop();
55911
+ }
55912
+ }, _callee5);
55913
+ }));
55914
+ return function removeExpireDataBykey(_x6) {
55915
+ return _ref7.apply(this, arguments);
55916
+ };
55917
+ }();
55918
+ // 清除过期无效数据
55919
+ var removeExpireData = /*#__PURE__*/function () {
55920
+ var _ref8 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee7() {
55921
+ return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
55922
+ while (1) switch (_context7.prev = _context7.next) {
55923
+ case 0:
55924
+ store.keys().then( /*#__PURE__*/function () {
55925
+ var _ref9 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee6(keys) {
55926
+ var i, len, key;
55927
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
55928
+ while (1) switch (_context6.prev = _context6.next) {
55929
+ case 0:
55930
+ i = 0, len = keys.length;
55931
+ case 1:
55932
+ if (!(i < len)) {
55933
+ _context6.next = 8;
55934
+ break;
55935
+ }
55936
+ key = keys[i];
55937
+ _context6.next = 5;
55938
+ return removeExpireDataBykey(key);
55939
+ case 5:
55940
+ i++;
55941
+ _context6.next = 1;
55942
+ break;
55943
+ case 8:
55944
+ case "end":
55945
+ return _context6.stop();
55946
+ }
55947
+ }, _callee6);
55948
+ }));
55949
+ return function (_x7) {
55950
+ return _ref9.apply(this, arguments);
55951
+ };
55952
+ }())["catch"](function (err) {
55953
+ console.log(err);
55954
+ });
55955
+ case 1:
55956
+ case "end":
55957
+ return _context7.stop();
55958
+ }
55959
+ }, _callee7);
55960
+ }));
55961
+ return function removeExpireData() {
55962
+ return _ref8.apply(this, arguments);
55963
+ };
55964
+ }();
55965
+ var installOssCache = function installOssCache(options) {
55966
+ var _options$osscache;
55967
+ defaultCachetime = (options === null || options === void 0 || (_options$osscache = options.osscache) === null || _options$osscache === void 0 ? void 0 : _options$osscache.cachetime) || defaultCachetime;
55968
+ removeExpireData();
55969
+ };
55970
+
52382
55971
  var getContentType = function getContentType(suffix) {
52383
55972
  var map = {
52384
55973
  '.jpg': 'image/jpeg',
@@ -52480,7 +56069,7 @@ var getUrl = /*#__PURE__*/function () {
52480
56069
  copeStr = provider !== null && provider !== void 0 && provider.isAliyun ? getAliyunCope(cope) : getCope(cope);
52481
56070
  contentType = getContentType(suffix);
52482
56071
  if (!(provider !== null && provider !== void 0 && provider.isAliyun)) {
52483
- _context.next = 26;
56072
+ _context.next = 25;
52484
56073
  break;
52485
56074
  }
52486
56075
  ossClient = new AliClient({
@@ -52495,11 +56084,10 @@ var getUrl = /*#__PURE__*/function () {
52495
56084
  responseHeader = {
52496
56085
  // 'content-type': contentType || undefined,
52497
56086
  'content-disposition': 'attachment; filename=' + (filename && encodeURIComponent(filename)) // 阿里云提供的下载名字
52498
- };
52499
-
52500
- if (contentType) {
52501
- responseHeader['content-type'] = contentType;
52502
- }
56087
+ }; // TODO 阿里云不在提供,会报错
56088
+ // if (contentType) {
56089
+ // responseHeader['content-type'] = contentType
56090
+ // }
52503
56091
  ossUrl = ossClient.signatureUrl(objectKey, {
52504
56092
  response: responseHeader,
52505
56093
  process: copeStr
@@ -52509,9 +56097,9 @@ var getUrl = /*#__PURE__*/function () {
52509
56097
  // ossUrl = ossUrl.replace(paths[1] + '/' + paths[2], paths[1])
52510
56098
  // }
52511
56099
  return _context.abrupt("return", ossUrl);
52512
- case 26:
56100
+ case 25:
52513
56101
  if (!(provider !== null && provider !== void 0 && provider.isHuawei)) {
52514
- _context.next = 43;
56102
+ _context.next = 42;
52515
56103
  break;
52516
56104
  }
52517
56105
  obs = new ObsClient({
@@ -52523,7 +56111,7 @@ var getUrl = /*#__PURE__*/function () {
52523
56111
  if (objectKey && objectKey[0] === '/') {
52524
56112
  objectKey = objectKey.slice(1);
52525
56113
  }
52526
- _context.prev = 29;
56114
+ _context.prev = 28;
52527
56115
  Params = {
52528
56116
  // Method: 'get',
52529
56117
  Bucket: storageConfig.cloudserv_storage_storagebucket,
@@ -52543,17 +56131,17 @@ var getUrl = /*#__PURE__*/function () {
52543
56131
  // if (expires) setCacheUrl(cacheKey, signedUrl, +expires)
52544
56132
  // 华为云通过 createSignedUrlSync 生产的签名链接默认带有 :80 或者 :443 端口 后端删除时需要去除
52545
56133
  return _context.abrupt("return", signedUrl.replace(/:(80|443)/, ''));
52546
- case 37:
52547
- _context.prev = 37;
52548
- _context.t0 = _context["catch"](29);
56134
+ case 36:
56135
+ _context.prev = 36;
56136
+ _context.t0 = _context["catch"](28);
52549
56137
  console.error(_context.t0);
52550
56138
  throw Error(_context.t0);
52551
- case 41:
52552
- _context.next = 56;
56139
+ case 40:
56140
+ _context.next = 55;
52553
56141
  break;
52554
- case 43:
56142
+ case 42:
52555
56143
  if (!(provider !== null && provider !== void 0 && provider.isMinio)) {
52556
- _context.next = 55;
56144
+ _context.next = 54;
52557
56145
  break;
52558
56146
  }
52559
56147
  s3Params = {
@@ -52591,18 +56179,18 @@ var getUrl = /*#__PURE__*/function () {
52591
56179
  });
52592
56180
  });
52593
56181
  };
52594
- _context.next = 51;
56182
+ _context.next = 50;
52595
56183
  return getSignedUrlPro();
52596
- case 51:
56184
+ case 50:
52597
56185
  _signedUrl = _context.sent;
52598
56186
  return _context.abrupt("return", _signedUrl);
52599
- case 55:
56187
+ case 54:
52600
56188
  throw Error("\u6682\u4E0D\u652F\u6301".concat(provider === null || provider === void 0 ? void 0 : provider.name, "\u5B58\u50A8\u7C7B\u578B"));
52601
- case 56:
56189
+ case 55:
52602
56190
  case "end":
52603
56191
  return _context.stop();
52604
56192
  }
52605
- }, _callee, null, [[29, 37]]);
56193
+ }, _callee, null, [[28, 36]]);
52606
56194
  }));
52607
56195
  return function getUrl(_x) {
52608
56196
  return _ref2.apply(this, arguments);
@@ -52655,36 +56243,31 @@ var downloadFile = /*#__PURE__*/function () {
52655
56243
  });
52656
56244
  case 6:
52657
56245
  url = _context2.sent;
52658
- // axios.get(url, {
52659
- // responseType: 'blob',
52660
- // isSendToken: false,
52661
- // isShowErrorMessage: false
52662
- // }).then((response: any) => {
52663
- // // console.log(response)
52664
- // // debugger
52665
- // downloadFileByBlob(response.data, filename)
52666
- // }).catch((e) => {
52667
- // console.log(e)
52668
- // throw Error(e)
52669
- // })
52670
56246
  provider = cloudServ.getProvider(storagetype);
52671
- if (provider !== null && provider !== void 0 && provider.isAliyun) {
52672
- downloadFileByUrl(url, filename);
52673
- } else {
52674
- normalAxios$1.get(url, {
52675
- responseType: 'blob',
52676
- isSendToken: false,
52677
- isShowErrorMessage: false
52678
- }).then(function (response) {
52679
- // console.log(response)
52680
- // debugger
52681
- downloadFileByBlob(response.data, filename);
52682
- })["catch"](function (e) {
52683
- console.log(e);
52684
- throw Error(e);
52685
- });
56247
+ if (!(provider !== null && provider !== void 0 && provider.isAliyun)) {
56248
+ _context2.next = 12;
56249
+ break;
52686
56250
  }
52687
- case 9:
56251
+ downloadFileByUrl(url, filename);
56252
+ _context2.next = 14;
56253
+ break;
56254
+ case 12:
56255
+ _context2.next = 14;
56256
+ return normalAxios$1.get(url, {
56257
+ responseType: 'blob',
56258
+ isSendToken: false,
56259
+ isShowErrorMessage: false
56260
+ }).then(function (response) {
56261
+ // console.log(response)
56262
+ // debugger
56263
+ if (Object.prototype.toString.call(response.data) === '[object Blob]') {
56264
+ downloadFileByBlob(response.data, filename);
56265
+ }
56266
+ })["catch"](function (e) {
56267
+ console.log(e);
56268
+ throw Error(e);
56269
+ });
56270
+ case 14:
52688
56271
  case "end":
52689
56272
  return _context2.stop();
52690
56273
  }
@@ -52694,8 +56277,175 @@ var downloadFile = /*#__PURE__*/function () {
52694
56277
  return _ref4.apply(this, arguments);
52695
56278
  };
52696
56279
  }();
56280
+ // 根据文件信息生成blob
56281
+ var getBlob = /*#__PURE__*/function () {
56282
+ var _ref6 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4(_ref5) {
56283
+ var _globalOptions$osscac;
56284
+ var _ref5$type, type, _ref5$source, source, _ref5$filename, filename, _ref5$datetime, datetime, _ref5$storagetype, storagetype, _ref5$cope, cope, cacheobj, online, requestBlob, cache, _cache;
56285
+ return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
56286
+ while (1) switch (_context4.prev = _context4.next) {
56287
+ case 0:
56288
+ _ref5$type = _ref5.type, type = _ref5$type === void 0 ? 'img' : _ref5$type, _ref5$source = _ref5.source, source = _ref5$source === void 0 ? '' : _ref5$source, _ref5$filename = _ref5.filename, filename = _ref5$filename === void 0 ? '' : _ref5$filename, _ref5$datetime = _ref5.datetime, datetime = _ref5$datetime === void 0 ? '' : _ref5$datetime, _ref5$storagetype = _ref5.storagetype, storagetype = _ref5$storagetype === void 0 ? 'storage' : _ref5$storagetype, _ref5$cope = _ref5.cope, cope = _ref5$cope === void 0 ? '' : _ref5$cope;
56289
+ cacheobj = generateCacheobj({
56290
+ type: type,
56291
+ source: source,
56292
+ datetime: datetime,
56293
+ storagetype: storagetype,
56294
+ cope: cope
56295
+ });
56296
+ _context4.next = 4;
56297
+ return isOnline();
56298
+ case 4:
56299
+ online = _context4.sent;
56300
+ requestBlob = /*#__PURE__*/function () {
56301
+ var _ref7 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3() {
56302
+ var issetcache,
56303
+ blob,
56304
+ url,
56305
+ response,
56306
+ _args3 = arguments;
56307
+ return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
56308
+ while (1) switch (_context3.prev = _context3.next) {
56309
+ case 0:
56310
+ issetcache = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : false;
56311
+ blob = null;
56312
+ if (!online) {
56313
+ _context3.next = 16;
56314
+ break;
56315
+ }
56316
+ _context3.prev = 3;
56317
+ _context3.next = 6;
56318
+ return getUrl({
56319
+ type: type,
56320
+ source: source,
56321
+ datetime: datetime,
56322
+ storagetype: storagetype,
56323
+ filename: filename,
56324
+ cope: cope
56325
+ });
56326
+ case 6:
56327
+ url = _context3.sent;
56328
+ _context3.next = 9;
56329
+ return normalAxios$1.get(url, {
56330
+ responseType: 'blob',
56331
+ isSendToken: false,
56332
+ isShowErrorMessage: false,
56333
+ isShowLoading: false
56334
+ });
56335
+ case 9:
56336
+ response = _context3.sent;
56337
+ // console.log(response)
56338
+ if (Object.prototype.toString.call(response.data) === '[object Blob]') {
56339
+ blob = response.data;
56340
+ if (issetcache) {
56341
+ setCache(cacheobj, {
56342
+ cachetime: defaultCachetime,
56343
+ expiretime: Date.now() + defaultCachetime,
56344
+ blob: blob
56345
+ });
56346
+ }
56347
+ }
56348
+ _context3.next = 16;
56349
+ break;
56350
+ case 13:
56351
+ _context3.prev = 13;
56352
+ _context3.t0 = _context3["catch"](3);
56353
+ console.error(_context3.t0);
56354
+ case 16:
56355
+ return _context3.abrupt("return", blob);
56356
+ case 17:
56357
+ case "end":
56358
+ return _context3.stop();
56359
+ }
56360
+ }, _callee3, null, [[3, 13]]);
56361
+ }));
56362
+ return function requestBlob() {
56363
+ return _ref7.apply(this, arguments);
56364
+ };
56365
+ }(); // 暂时只作用于图片
56366
+ if (!(!!(globalOptions !== null && globalOptions !== void 0 && (_globalOptions$osscac = globalOptions.osscache) !== null && _globalOptions$osscac !== void 0 && _globalOptions$osscac.flag) && type === 'img')) {
56367
+ _context4.next = 27;
56368
+ break;
56369
+ }
56370
+ if (!online) {
56371
+ _context4.next = 21;
56372
+ break;
56373
+ }
56374
+ _context4.next = 10;
56375
+ return getCache(cacheobj);
56376
+ case 10:
56377
+ cache = _context4.sent;
56378
+ if (!cache) {
56379
+ _context4.next = 16;
56380
+ break;
56381
+ }
56382
+ requestBlob(true);
56383
+ return _context4.abrupt("return", cache.blob);
56384
+ case 16:
56385
+ _context4.next = 18;
56386
+ return requestBlob(true);
56387
+ case 18:
56388
+ return _context4.abrupt("return", _context4.sent);
56389
+ case 19:
56390
+ _context4.next = 25;
56391
+ break;
56392
+ case 21:
56393
+ _context4.next = 23;
56394
+ return getCache(cacheobj, true);
56395
+ case 23:
56396
+ _cache = _context4.sent;
56397
+ return _context4.abrupt("return", (_cache === null || _cache === void 0 ? void 0 : _cache.blob) || null);
56398
+ case 25:
56399
+ _context4.next = 30;
56400
+ break;
56401
+ case 27:
56402
+ _context4.next = 29;
56403
+ return requestBlob(false);
56404
+ case 29:
56405
+ return _context4.abrupt("return", _context4.sent);
56406
+ case 30:
56407
+ case "end":
56408
+ return _context4.stop();
56409
+ }
56410
+ }, _callee4);
56411
+ }));
56412
+ return function getBlob(_x3) {
56413
+ return _ref6.apply(this, arguments);
56414
+ };
56415
+ }();
56416
+ var getObjectURL = /*#__PURE__*/function () {
56417
+ var _ref9 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(_ref8) {
56418
+ var _ref8$type, type, _ref8$source, source, _ref8$filename, filename, _ref8$datetime, datetime, _ref8$storagetype, storagetype, _ref8$cope, cope, blob;
56419
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
56420
+ while (1) switch (_context5.prev = _context5.next) {
56421
+ case 0:
56422
+ _ref8$type = _ref8.type, type = _ref8$type === void 0 ? 'img' : _ref8$type, _ref8$source = _ref8.source, source = _ref8$source === void 0 ? '' : _ref8$source, _ref8$filename = _ref8.filename, filename = _ref8$filename === void 0 ? '' : _ref8$filename, _ref8$datetime = _ref8.datetime, datetime = _ref8$datetime === void 0 ? '' : _ref8$datetime, _ref8$storagetype = _ref8.storagetype, storagetype = _ref8$storagetype === void 0 ? 'storage' : _ref8$storagetype, _ref8$cope = _ref8.cope, cope = _ref8$cope === void 0 ? '' : _ref8$cope;
56423
+ _context5.next = 3;
56424
+ return getBlob({
56425
+ type: type,
56426
+ source: source,
56427
+ datetime: datetime,
56428
+ storagetype: storagetype,
56429
+ filename: filename,
56430
+ cope: cope
56431
+ });
56432
+ case 3:
56433
+ blob = _context5.sent;
56434
+ return _context5.abrupt("return", blob ? URL.createObjectURL(blob) : '');
56435
+ case 5:
56436
+ case "end":
56437
+ return _context5.stop();
56438
+ }
56439
+ }, _callee5);
56440
+ }));
56441
+ return function getObjectURL(_x4) {
56442
+ return _ref9.apply(this, arguments);
56443
+ };
56444
+ }();
52697
56445
  var downloadService = {
52698
56446
  getUrl: getUrl,
56447
+ getBlob: getBlob,
56448
+ getObjectURL: getObjectURL,
52699
56449
  downloadFile: downloadFile
52700
56450
  };
52701
56451
 
@@ -53178,12 +56928,14 @@ var upload = /*#__PURE__*/function () {
53178
56928
  // debugger
53179
56929
  promise = new Promise( /*#__PURE__*/function () {
53180
56930
  var _ref3 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2(resolve, reject) {
53181
- var ossClient, obs, uploadRes, s3, params, _upload;
56931
+ var uploadflag, rejectV, ossClient, obs, uploadRes, s3, params, _upload;
53182
56932
  return _regeneratorRuntime$1().wrap(function _callee2$(_context3) {
53183
56933
  while (1) switch (_context3.prev = _context3.next) {
53184
56934
  case 0:
56935
+ uploadflag = false;
56936
+ rejectV = null;
53185
56937
  if (!(provider !== null && provider !== void 0 && provider.isAliyun)) {
53186
- _context3.next = 5;
56938
+ _context3.next = 7;
53187
56939
  break;
53188
56940
  }
53189
56941
  ossClient = new AliClient({
@@ -53212,16 +56964,7 @@ var upload = /*#__PURE__*/function () {
53212
56964
  // console.log('httpUploadProgress', p)
53213
56965
  onprogress && onprogress(p, _checkpoint);
53214
56966
  if (p === 1) {
53215
- resolve({
53216
- key: osskey,
53217
- source: source,
53218
- filename: file.name,
53219
- type: type,
53220
- date: date,
53221
- datetime: datetime,
53222
- storage: storagetype,
53223
- file: file
53224
- });
56967
+ uploadflag = true;
53225
56968
  }
53226
56969
  case 2:
53227
56970
  case "end":
@@ -53237,13 +56980,13 @@ var upload = /*#__PURE__*/function () {
53237
56980
  }, _callee);
53238
56981
  }))["catch"](function (error) {
53239
56982
  console.error(error);
53240
- reject(error);
56983
+ rejectV = error;
53241
56984
  });
53242
- _context3.next = 28;
56985
+ _context3.next = 23;
53243
56986
  break;
53244
- case 5:
56987
+ case 7:
53245
56988
  if (!(provider !== null && provider !== void 0 && provider.isHuawei)) {
53246
- _context3.next = 20;
56989
+ _context3.next = 22;
53247
56990
  break;
53248
56991
  }
53249
56992
  obs = new ObsClient({
@@ -53257,8 +57000,8 @@ var upload = /*#__PURE__*/function () {
53257
57000
  // server: storageConfig.cloudserv_storage_storageendpoint,
53258
57001
  // security_token: 'gQ5jbi1zb3V0aHdlc3QtMogAsKjYcI5CQldRAvQQJysdkZ7tAt6arLsoWHFGCaco8s8FPk6wtbslHWhvg2SZh3QMM4aUA4FhPEWQt9A7gXoC_Lh4DpF6hhHIxUyACKgakNHNPdPegy5G9-sibBXkGueIY1X3K12tzpjbyd08esLKEEu-M_QmfDoDdkgOcyidITc-lOg5EzXb27f91Ym26u2mAMTaNjCLRulJ4rziLSW6IAprSx8LUkuQQE-wUz-tMzVL9oFiVykHz980o0Y0CNdCIwn98Y-xbMdslZ3U8raydy6Wnf2LchXc0ajvMix0gg-CV0tpA4cgiZFqPxwEDXSv42hvfccboWlpGmOVR3llHLUirrlgFod8rhm-Rmk6MIfQw4NA8rddow1Gx6g-MugFV5arMDLfsOhqeSFQRJWizb3q50zk6GcUFulewitxP8HSkXMGt_rDDYCcCEmdu15D3imX5431Mbdt0qCgxH80OPCDmFXw0xMOsggxE0PBVexVY2x3wHGeql3JNyevUZAhqlskNNu77ui2Vnp-ZbHMcxgDLcPuAULINId4V_QGdhAkDaxQk53AE237DAFXtlyWWaBRMsTNVnpq9mCXJup9pdBbjLRVAO4OxfYVnwwvl-w_mb-xCgOf5EPHqA_zbZF8z-ad6JjWgLOQCHaawE7kNGHIQwAgzneik33wP2jPlG1ak9KEWyXr1n2QMJCmDM3bIrRit5_8LLFoPjXcwurBjZ-AomM_ztOe34sdr357atlQcPD7a2xWtrvn9mnqqndg12m7QxnwkmJsOYK4ZO5Hoyb2vd_NX2Nd9PaSIVAcFw=='
53259
57002
  // })
53260
- _context3.prev = 7;
53261
- _context3.next = 10;
57003
+ _context3.prev = 9;
57004
+ _context3.next = 12;
53262
57005
  return obsMultiUpload(obs, file, {
53263
57006
  bucket: storageConfig.cloudserv_storage_storagebucket,
53264
57007
  key: osskey,
@@ -53267,9 +57010,68 @@ var upload = /*#__PURE__*/function () {
53267
57010
  onprogress && onprogress(percent);
53268
57011
  }
53269
57012
  });
53270
- case 10:
57013
+ case 12:
53271
57014
  uploadRes = _context3.sent;
53272
57015
  if (uploadRes) {
57016
+ uploadflag = true;
57017
+ }
57018
+ _context3.next = 20;
57019
+ break;
57020
+ case 16:
57021
+ _context3.prev = 16;
57022
+ _context3.t0 = _context3["catch"](9);
57023
+ console.error(_context3.t0);
57024
+ rejectV = _context3.t0;
57025
+ case 20:
57026
+ _context3.next = 23;
57027
+ break;
57028
+ case 22:
57029
+ if (provider !== null && provider !== void 0 && provider.isMinio || provider !== null && provider !== void 0 && provider.isAwss3) {
57030
+ // debugger
57031
+ // debugger
57032
+ s3 = new S3Client({
57033
+ accessKeyId: servToken.accesskeyid,
57034
+ secretAccessKey: servToken.accesskeysecret,
57035
+ sessionToken: servToken.securitytoken,
57036
+ region: storageConfig.cloudserv_storage_region,
57037
+ endpoint: storageConfig.cloudserv_storage_storageendpoint,
57038
+ signatureVersion: 'v4',
57039
+ s3ForcePathStyle: provider !== null && provider !== void 0 && provider.isMinio ? true : undefined
57040
+ });
57041
+ params = {
57042
+ Bucket: storageConfig.cloudserv_storage_storagebucket,
57043
+ Key: osskey,
57044
+ Body: file
57045
+ };
57046
+ _upload = s3.upload(params, {}).on('httpUploadProgress', function (e) {
57047
+ var precent = parseInt(e.loaded, 10) / parseInt(e.total, 10);
57048
+ // console.log('httpUploadProgress')
57049
+ // console.log(e)
57050
+ // console.log(precent)
57051
+ onprogress && onprogress(precent);
57052
+ });
57053
+ _upload.send(function (err, data) {
57054
+ if (err) {
57055
+ console.error(err);
57056
+ rejectV = err;
57057
+ } else {
57058
+ uploadflag = true;
57059
+ }
57060
+ });
57061
+ } else {
57062
+ rejectV = new Error("\u6682\u4E0D\u652F\u6301".concat(provider === null || provider === void 0 ? void 0 : provider.name, "\u5B58\u50A8\u7C7B\u578B"));
57063
+ // throw Error(`暂不支持${provider?.name}存储类型`)
57064
+ }
57065
+ case 23:
57066
+ if (uploadflag) {
57067
+ // 暂时只作用于图片
57068
+ setCacheByFile({
57069
+ type: type,
57070
+ source: source,
57071
+ datetime: datetime,
57072
+ storagetype: storagetype,
57073
+ file: file
57074
+ });
53273
57075
  resolve({
53274
57076
  key: osskey,
53275
57077
  source: source,
@@ -53280,71 +57082,14 @@ var upload = /*#__PURE__*/function () {
53280
57082
  storage: storagetype,
53281
57083
  file: file
53282
57084
  });
57085
+ } else {
57086
+ reject(rejectV);
53283
57087
  }
53284
- _context3.next = 18;
53285
- break;
53286
- case 14:
53287
- _context3.prev = 14;
53288
- _context3.t0 = _context3["catch"](7);
53289
- console.error(_context3.t0);
53290
- reject(_context3.t0);
53291
- case 18:
53292
- _context3.next = 28;
53293
- break;
53294
- case 20:
53295
- if (!(provider !== null && provider !== void 0 && provider.isMinio || provider !== null && provider !== void 0 && provider.isAwss3)) {
53296
- _context3.next = 27;
53297
- break;
53298
- }
53299
- // debugger
53300
- // debugger
53301
- s3 = new S3Client({
53302
- accessKeyId: servToken.accesskeyid,
53303
- secretAccessKey: servToken.accesskeysecret,
53304
- sessionToken: servToken.securitytoken,
53305
- region: storageConfig.cloudserv_storage_region,
53306
- endpoint: storageConfig.cloudserv_storage_storageendpoint,
53307
- signatureVersion: 'v4',
53308
- s3ForcePathStyle: provider !== null && provider !== void 0 && provider.isMinio ? true : undefined
53309
- });
53310
- params = {
53311
- Bucket: storageConfig.cloudserv_storage_storagebucket,
53312
- Key: osskey,
53313
- Body: file
53314
- };
53315
- _upload = s3.upload(params, {}).on('httpUploadProgress', function (e) {
53316
- var precent = parseInt(e.loaded, 10) / parseInt(e.total, 10);
53317
- // console.log('httpUploadProgress')
53318
- // console.log(e)
53319
- // console.log(precent)
53320
- onprogress && onprogress(precent);
53321
- });
53322
- _upload.send(function (err, data) {
53323
- if (err) {
53324
- console.error(err);
53325
- reject(err);
53326
- } else {
53327
- resolve({
53328
- key: osskey,
53329
- source: source,
53330
- filename: file.name,
53331
- type: type,
53332
- date: date,
53333
- datetime: datetime,
53334
- storage: storagetype,
53335
- file: file
53336
- });
53337
- }
53338
- });
53339
- _context3.next = 28;
53340
- break;
53341
- case 27:
53342
- throw Error("\u6682\u4E0D\u652F\u6301".concat(provider === null || provider === void 0 ? void 0 : provider.name, "\u5B58\u50A8\u7C7B\u578B"));
53343
- case 28:
57088
+ case 24:
53344
57089
  case "end":
53345
57090
  return _context3.stop();
53346
57091
  }
53347
- }, _callee2, null, [[7, 14]]);
57092
+ }, _callee2, null, [[9, 16]]);
53348
57093
  }));
53349
57094
  return function (_x2, _x3) {
53350
57095
  return _ref3.apply(this, arguments);
@@ -70154,7 +73899,7 @@ var SpuExpandexp = /*#__PURE__*/function (_HTMLElement) {
70154
73899
  event: 'exportopenmodal'
70155
73900
  });
70156
73901
  } else {
70157
- normalAxios$1.post('/api/expandexp/global/searchExpGloConfig', {
73902
+ apaasAxios.post('/api/expandexp/global/searchExpGloConfig', {
70158
73903
  key: 'export-config-switch',
70159
73904
  tenantcode: getUser('tenantcode'),
70160
73905
  productcode: getUser('productcode')
@@ -70186,7 +73931,7 @@ var SpuExpandexp = /*#__PURE__*/function (_HTMLElement) {
70186
73931
  } else if (_this5.data.expandStatus === '2') {
70187
73932
  _this5.data.iscompress = '1';
70188
73933
  // 获取文件水印开关
70189
- normalAxios$1.post('/api/expandexp/global/searchWatermarkConfig', '', {
73934
+ apaasAxios.post('/api/expandexp/global/searchWatermarkConfig', '', {
70190
73935
  isShowLoading: false
70191
73936
  }).then(function (res) {
70192
73937
  var _res$data2;
@@ -70270,7 +74015,7 @@ var SpuExpandexp = /*#__PURE__*/function (_HTMLElement) {
70270
74015
  }
70271
74016
  };
70272
74017
  finallyPost = mergedata ? merge$5(mergedata, post) : post;
70273
- normalAxios$1.post(this.props.exportapi, finallyPost).then(function (res) {
74018
+ apaasAxios.post(this.props.exportapi, finallyPost).then(function (res) {
70274
74019
  // console.log(res)
70275
74020
  var result = res === null || res === void 0 ? void 0 : res.data;
70276
74021
  if ((result === null || result === void 0 ? void 0 : result.code) === 200 && result !== null && result !== void 0 && result.data) {
@@ -70405,7 +74150,7 @@ var SpuExpandexp = /*#__PURE__*/function (_HTMLElement) {
70405
74150
  // return false
70406
74151
  // console.log(this.data)
70407
74152
  // console.log(this.data.exportDataItem)
70408
- normalAxios$1.post('/api/teapi/queue/impexp/cancel', {
74153
+ apaasAxios.post('/api/teapi/queue/impexp/cancel', {
70409
74154
  dynamicid: this.data.exportId
70410
74155
  }).then(function (res) {
70411
74156
  if ((res === null || res === void 0 ? void 0 : res.code) === 200 && res !== null && res !== void 0 && res.data) {
@@ -70453,7 +74198,7 @@ var SpuExpandexp = /*#__PURE__*/function (_HTMLElement) {
70453
74198
  return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
70454
74199
  while (1) switch (_context4.prev = _context4.next) {
70455
74200
  case 0:
70456
- normalAxios$1.post("/api/teapi/queue/impexp/expStatus?dynamicid=".concat(this.data.exportId), {}, {
74201
+ apaasAxios.post("/api/teapi/queue/impexp/expStatus?dynamicid=".concat(this.data.exportId), {}, {
70457
74202
  isShowLoading: false
70458
74203
  }).then(function (res) {
70459
74204
  var _res$data3;
@@ -70657,6 +74402,12 @@ var getDefaultGlobalOptions = function getDefaultGlobalOptions() {
70657
74402
  moduleversion: arr[2] || '',
70658
74403
  storageproxyprefix: '',
70659
74404
  isfixapptokenexpired: false,
74405
+ isoptimizesingleloginlogic: false,
74406
+ osscache: {
74407
+ flag: false,
74408
+ cachetime: 60 * 1000 * 60 * 2 // 默认缓存2小时
74409
+ },
74410
+
70660
74411
  singleLoginCallback: null,
70661
74412
  router: null
70662
74413
  };
@@ -70668,10 +74419,12 @@ var install = function install(app, options) {
70668
74419
  merge$5(globalOptions, options);
70669
74420
  installStorageProxy(globalOptions);
70670
74421
  installUrlquery();
70671
- installAxios(globalOptions);
74422
+ installAxios();
74423
+ installAxiosCache();
70672
74424
  installSpuConfig(globalOptions);
70673
74425
  installWxworksuitePlugin(); // 安装企微第三方应用插件
70674
74426
  installAuth(globalOptions);
74427
+ installOssCache(globalOptions);
70675
74428
  installApaasSpuTrack();
70676
74429
  installTest(globalOptions);
70677
74430
  console.log("@smart100/spu-web-plugin@".concat(version, " install!"));
@@ -70680,7 +74433,7 @@ var install = function install(app, options) {
70680
74433
  console.log("@smart100/spu-web-plugin@".concat(version, " globalOptions"));
70681
74434
  console.log(globalOptions);
70682
74435
  // setTimeout(() => {
70683
- // console.error('888')
74436
+ // console.error('8877778')
70684
74437
  // }, 1000)
70685
74438
  // if (install.installed) return
70686
74439
  // install.installed = true
@@ -70701,4 +74454,4 @@ var SPUWebPlugin = {
70701
74454
  version: version
70702
74455
  };
70703
74456
 
70704
- export { AMapLoader, Module, normalAxios$1 as apaasAxios, normalAxios$1 as axios, checkLogin, index as components, decrypt, normalizeEncryData as decryptAxiosResponseData, SPUWebPlugin as default, downloadService, encrypt, expandexp, functionCheck, getAddress, getCloudServ, getDistance, getLocation, getRefreshToken, getServToken, getServerTime, getToken, getTokenExpires, getUniqueid, getUser, v4 as getUuid, globalConfig, globalOptions, isInApp, isdebugger, isvirtuallocation, lsProxy, mapService, setRefreshToken, setTitle, setToken, setTokenExpires, singleLogin, spuAxios, spuConfig, ssProxy, updateToken, uploadService, wxworkSuite };
74457
+ export { AMapLoader, Module, apaasAxios, apaasAxios as axios, axiosCache, checkLogin, index as components, decrypt, normalizeEncryData as decryptAxiosResponseData, SPUWebPlugin as default, downloadService, encrypt, expandexp, functionCheck, getAddress, getCloudServ, getDistance, getLocation, getRefreshToken, getServToken, getServerTime, getToken, getTokenExpires, getUniqueid, getUser, v4 as getUuid, globalConfig, globalOptions, isInApp, isOnline, isdebugger, isvirtuallocation, lsProxy, mapService, normalAxios$1 as normalAxios, setRefreshToken, setTitle, setToken, setTokenExpires, singleLogin, spuAxios, spuConfig, ssProxy, updateToken, uploadService, wxworkSuite };