UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

72 lines (65 loc) 1.93 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var axios = require('axios'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios); /** * 获取 i18n token * * @export * @param {string} appId appId * @param {string} appKey appKey * @returns {Promise<string>} token * @example * ```ts * getI18nToken('appId', 'appKey').then(token => { * console.log('token', token) * }) * ``` */ function getI18nToken(appId, appKey) { return new Promise(function (resolve, reject) { axios__default["default"]({ url: '/api/openapi/token', params: { app_id: appId, app_key: appKey } }).then(function (res) { var _a, _b; var token = ((_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.access_token) || ''; console.log("[i18n] token is ".concat(token)); resolve(token); })["catch"](function (err) { reject(err); }); }); } function importI18nDict(_a) { var projectId = _a.projectId, _b = _a.moduleCode, moduleCode = _b === void 0 ? 'default' : _b, _c = _a.versionCode, versionCode = _c === void 0 ? 'v1.0' : _c, accessToken = _a.accessToken, data = _a.data; return new Promise(function (resolve, reject) { axios__default["default"]({ url: '/api/openapi/dict/imports', data: { project_id: projectId, module_code: moduleCode, version_code: versionCode, access_token: accessToken, data: data }, method: 'POST' }).then(function (res) { resolve(res); })["catch"](function (err) { reject(err); }); }); } exports.getI18nToken = getI18nToken; exports.importI18nDict = importI18nDict;