|
|
@@ -1,8 +1,9 @@
|
|
|
var sync_db_list = [
|
|
|
+ { script: "sync/table_channel.php", count: -1, finished: 0, enable: false },
|
|
|
{ script: "sync/table_article.php", count: -1, finished: 0, enable: false },
|
|
|
- { script: "sync/table_term.php", count: -1, finished: 0, enable: false },
|
|
|
{ script: "sync/table_article_collect.php", count: -1, finished: 0, enable: false },
|
|
|
- { script: "sync/table_channel.php", count: -1, finished: 0, enable: false },
|
|
|
+ { script: "sync/table_term_channel.php", count: -1, finished: 0, enable: false },
|
|
|
+ { script: "sync/table_term_editor.php", count: -1, finished: 0, enable: false },
|
|
|
{ script: "sync/table_sentence.php", count: -1, finished: 0, enable: true },
|
|
|
];
|
|
|
var isStop = false;
|
|
|
@@ -15,13 +16,13 @@ function sync_pull() {
|
|
|
sync_curr_do_db = 0;
|
|
|
isStop = false;
|
|
|
$("#sync_log").html("working"); //
|
|
|
- sync_do_db($("#sync_server_address").val(), $("#sync_local_address").val(), 1);
|
|
|
+ sync_do_db($("#sync_server_address").val(), $("#sync_local_address").val(), 0);
|
|
|
}
|
|
|
function sync_push() {
|
|
|
isStop = false;
|
|
|
sync_curr_do_db = 0;
|
|
|
$("#sync_log").html("working"); //
|
|
|
- sync_do_db($("#sync_local_address").val(), $("#sync_server_address").val(), 1);
|
|
|
+ sync_do_db($("#sync_local_address").val(), $("#sync_server_address").val(), 0);
|
|
|
}
|
|
|
function sync_stop() {
|
|
|
isStop = true;
|
|
|
@@ -29,6 +30,7 @@ function sync_stop() {
|
|
|
var retryCount = 0;
|
|
|
function sync_do_db(src, dest, time = 1) {
|
|
|
let size = 500;
|
|
|
+ //找到下一个有效的数据库
|
|
|
while (sync_db_list[sync_curr_do_db].enable == false) {
|
|
|
sync_curr_do_db++;
|
|
|
if (sync_curr_do_db >= sync_db_list.length) {
|
|
|
@@ -36,7 +38,16 @@ function sync_do_db(src, dest, time = 1) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
+ if (time == 0) {
|
|
|
+ time = localStorage.getItem(sync_db_list[sync_curr_do_db].script + src);
|
|
|
+ if (time) {
|
|
|
+ time = parseInt(time);
|
|
|
+ } else {
|
|
|
+ time = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
if (sync_db_list[sync_curr_do_db].count < 0) {
|
|
|
+ //获取全部数据条数,用来绘制进度条
|
|
|
$.get(
|
|
|
"sync.php",
|
|
|
{
|
|
|
@@ -76,10 +87,14 @@ function sync_do_db(src, dest, time = 1) {
|
|
|
console.error(error + " data:" + data);
|
|
|
return;
|
|
|
}
|
|
|
+ let myDate = new Date();
|
|
|
+ myDate.setTime(result.time);
|
|
|
+
|
|
|
$("#sync_log").html(
|
|
|
$("#sync_log").html() +
|
|
|
"<div><h2>" +
|
|
|
sync_db_list[sync_curr_do_db].script +
|
|
|
+ myDate +
|
|
|
"</h2>" +
|
|
|
result.message +
|
|
|
"</div>"
|
|
|
@@ -89,12 +104,14 @@ function sync_do_db(src, dest, time = 1) {
|
|
|
return;
|
|
|
}
|
|
|
if (result.error > 0 && retryCount < 2) {
|
|
|
+ //失败重试
|
|
|
retryCount++;
|
|
|
sync_do_db(src, dest, time);
|
|
|
return;
|
|
|
}
|
|
|
retryCount = 0;
|
|
|
sync_db_list[sync_curr_do_db].finished += parseInt(result.src_row);
|
|
|
+ localStorage.setItem(sync_db_list[sync_curr_do_db].script + src, result.time);
|
|
|
if (result.src_row >= size) {
|
|
|
//没弄完,接着弄
|
|
|
sync_do_db(src, dest, result.time);
|
|
|
@@ -118,21 +135,35 @@ function sync_do_db(src, dest, time = 1) {
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+function db_selected(obj) {
|
|
|
+ let index = $(obj).attr("index");
|
|
|
+ sync_db_list[index].enable = obj.checked;
|
|
|
+}
|
|
|
+
|
|
|
function render_progress() {
|
|
|
let html = "";
|
|
|
- for (const iterator of sync_db_list) {
|
|
|
- let spanWidth = parseInt((500 * iterator.finished) / iterator.count);
|
|
|
+ for (let index = 0; index < sync_db_list.length; index++) {
|
|
|
+ const element = sync_db_list[index];
|
|
|
+ let spanWidth = parseInt((500 * element.finished) / element.count);
|
|
|
+ html += "<div style='width:500px;background-color:white;color:black;'>";
|
|
|
+ html += "<input type='checkbox' index='" + index + "' ";
|
|
|
+ if (element.enable) {
|
|
|
+ html += "checked";
|
|
|
+ }
|
|
|
+ html += " onclick='db_selected(this)' />";
|
|
|
html +=
|
|
|
- "<div style='width:500px;background-color:white;color:black;'><span style='background-color:green;display:inline-block;width:" +
|
|
|
+ "<span style='background-color:green;display:inline-block;width:" +
|
|
|
spanWidth +
|
|
|
"px;'>" +
|
|
|
- iterator.script +
|
|
|
+ element.script +
|
|
|
"|" +
|
|
|
- iterator.finished +
|
|
|
+ element.finished +
|
|
|
"/" +
|
|
|
- iterator.count +
|
|
|
+ element.count +
|
|
|
"<span></div>";
|
|
|
}
|
|
|
+
|
|
|
$("#sync_result").html(html);
|
|
|
}
|
|
|
function login() {
|