t-comm
Version:
专业、稳定、纯粹的工具库
63 lines (60 loc) • 1.59 kB
JavaScript
import axios from '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({
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({
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);
});
});
}
export { getI18nToken, importI18nDict };