Commit 63a2296b by 郭有超

修改creator请求字库的请求方式

1 parent e2d5b92c
No preview for this file type
No preview for this file type
......@@ -91,6 +91,30 @@ var SSdk = (function() {
xhr.send(body);
}
this.load_asset_with_retry = function(res_path, cb_success, cb_error) {
// console.log("res_path",res_path);
let retry_count = 0;
let load_func = () => {
cc.loader.load(res_path, (err, load_data) => {
if (!err) {
cb_success && cb_success(load_data);
} else {
retry_count++;
if (retry_count < this.max_retry_count) {
load_func();
} else {
cb_error && cb_error(err);
cc.warn("加载资源文件失败", res_path);
}
}
});
};
load_func();
}
/**@description SDK 初始化 传递当前SDK是否开启 请求当下的敏感词库 */
this.init = function() {
this._s_content = word;
......@@ -100,10 +124,10 @@ var SSdk = (function() {
data["app_id"] = this._app_id;
data["app_secret"] = this._app_secret;
var self = this;
this.post("https://maple-test.icesimba.cn/maple/notoken/sensitive/word/download", JSON.stringify(data), function(res) {
this.post("https://maple.icesimba.cn/maple/notoken/sensitive/word/download", JSON.stringify(data), function(res) {
var download_data = JSON.parse(res);
self.set_s_md5(download_data.obj.md5);
this.get(download_data.obj.url, "", function(tres) {
this.load_asset_with_retry(download_data.obj.url, function(tres) {
var sumtdata = "[\"" + tres.replace(/\r\n/g, "\",\"") + "\"]";
var tdata = sumtdata.replace("\"石国 \"", "石国 ");
// 将敏感词库换成JSON数组
......@@ -111,7 +135,9 @@ var SSdk = (function() {
}, function(res) {
console.log("下载失败的字体", res);
})
}.bind(this), function(res) { console.log("请求失败", res) });
}.bind(this), function(res) {
console.log("请求失败", res)
});
} else {
this._log("敏感词库初始化失败 需要开启敏感词库");
......
......@@ -83,6 +83,27 @@ class SSdk{
xhr.send(body);
}
public load_asset_with_retry(res_path, cb_success?:Function, cb_error?:Function) {
// console.log("res_path",res_path);
let retry_count = 0;
const load_func = () => {
cc.loader.load(res_path, (err, load_data) => {
if (!err) {
cb_success && cb_success(load_data);
} else {
retry_count++;
if (retry_count < this.max_retry_count) {
load_func();
} else {
cb_error && cb_error(err);
cc.warn("加载资源文件失败", res_path);
}
}
});
};
load_func();
}
public post(url: string, body: string, success?: Function, fail?: Function) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
......@@ -111,16 +132,17 @@ class SSdk{
this.post("https://maple.icesimba.cn/maple/notoken/sensitive/word/download", JSON.stringify(data), (res) => {
var download_data = JSON.parse(res);
self.set_s_md5(download_data.obj.md5);
this.get(download_data.obj.url, "", function(tres) {
self.load_asset_with_retry(download_data.obj.url, function(tres) {
var sumtdata = "[\"" + tres.replace(/\r\n/g, "\",\"") + "\"]";
var tdata = sumtdata.replace("\"石国 \"", "石国 ");
// 将敏感词库换成JSON数组
self._s_content = JSON.parse(tdata);
console.log("下载词库成功");
}, function(res) {
console.log("下载失败的字体", res);
// console.log("下载失败的字体", res);
})
}, function(res) {
console.log("请求失败", res)
// console.log("请求失败", res)
});
} else {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!