upgrade_action.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. {extend name="base" /}
  2. {block name="resources"}
  3. <script type="text/javascript" src="SHOP_JS/progressbar.js"></script>
  4. <link rel="stylesheet" type="text/css" href="SHOP_CSS/upgrade/style.css" media="screen">
  5. <link rel="stylesheet" type="text/css" href="SHOP_CSS/upgrade/jquery.easy-pie-chart.css" media="screen">
  6. <style>
  7. .chart{
  8. display:inline-block;
  9. float:unset;
  10. }
  11. .up-footer{padding:20px;text-align:center;}
  12. .up-footer button{
  13. background-color: #067cf3;
  14. padding:8px 15px;
  15. color:#FFF;
  16. border:none;
  17. border-radius:3px;
  18. font-size:15px;
  19. margin: 0 10px;
  20. cursor: pointer;
  21. }
  22. /*.up-footer button:nth-child(2){
  23. display: none;
  24. }*/
  25. .install-content{
  26. margin-top:40px;
  27. padding: 10px 0 10px 20px;
  28. border: 1px solid #AAD2E5;
  29. background-color: #E1F2FA;
  30. }
  31. .panel-title{
  32. font-size:15px;
  33. margin:7px auto;
  34. line-height:30px;
  35. color: #31708f;
  36. border-bottom:1px solid #aad2e5 !important;
  37. }
  38. .step-title{
  39. color: #31708f;
  40. font-weight:bold;
  41. }
  42. .step-text{
  43. color: #31708f;
  44. }
  45. #container {
  46. width: 300px;
  47. height: 300px;
  48. margin: 50px auto;
  49. position: relative;
  50. }
  51. .alert-warning-word {
  52. background-color: #FCF8E3;
  53. border-top: 1px solid #FBEED5;
  54. border-bottom: 1px solid #FBEED5;
  55. padding: 5px 20px;
  56. line-height: 30px;
  57. color: #C09853;
  58. }
  59. .complete-title{text-align: center;font-size: 24px;padding-bottom: 20px;color:#FF6A00;border:0px}
  60. .complete-ontent{text-align: center;font-size: 14px;}
  61. .complete-word{color:#FF6A00}
  62. .complete-ontent-nex{text-align: center;font-size: 14px;padding: 10px 0px;}
  63. .complete-url{text-align: center;font-size: 14px;padding-bottom: 20px;}
  64. .complete-close{cursor:pointer;display: block;background: #FF6A00; width: 70px;height: 35px;color: #fff;font-size: 16px;text-align: center;line-height: 35px;border-radius: 5px;margin: 0 auto;}
  65. </style>
  66. {/block}
  67. {block name="main"}
  68. <div class="tips-wrap">
  69. <div id="container"></div>
  70. <div style="clear:both;"></div>
  71. <div class="alert alert-warning alert-warning-word">
  72. <strong>警告!</strong>版本升级中,请不要关闭当前页面!
  73. </div>
  74. <div class="install-content alert alert-info">
  75. <div class="panel panel-default">
  76. <div class="panel-heading">
  77. <h3 class="panel-title">
  78. 详细过程
  79. </h3>
  80. </div>
  81. <div class="panel-body">
  82. <span class="step-title">升级操作&nbsp;:&nbsp;</span><span class="step-text action-name"></span><br/>
  83. <span class="step-title">整体进度&nbsp;:&nbsp;</span><span class="step-text count-percent">0%</span><br/>
  84. <span class="step-title">操作显示&nbsp;:&nbsp;</span><span class="step-text step-content"></span>
  85. </div>
  86. </div>
  87. </div>
  88. <div class="space-10"></div>
  89. <div class="up-view" >
  90. <div class="up-footer">
  91. <button class="up-btn" onclick="upgradeStart();">开始升级</button>
  92. <button class="up-btn" onclick="downloadFile();">下载升级文件</button>
  93. </div>
  94. </div>
  95. </div>
  96. {/block}
  97. {block name="script"}
  98. <script type="text/javascript">
  99. var action_type = 'upgrade';
  100. var upgrade_obj = {
  101. 'data' : [],
  102. 'total_action' : {
  103. 'list' : [
  104. 'backupFile',
  105. 'backupSql',
  106. 'downloadFile',
  107. 'upgradeStart',//升级开始
  108. 'executeFile',
  109. 'executeSql',
  110. 'upgradeEnd',//升级结束
  111. ],
  112. 'method' : '',
  113. 'status' : {},
  114. 'error_message' : '',
  115. },
  116. 'download_file' : {
  117. 'index' : -1,
  118. 'error_index' : -1,
  119. 'error_num' : 0,
  120. 'error_limit' : 10,
  121. 'download_root': ''
  122. },
  123. 'backup_sql' : {
  124. 'last_table' : '',
  125. 'index' : 0,
  126. 'series' : 1,
  127. },
  128. 'version' : {
  129. 'current' : 0,
  130. 'upgrade' : 0,
  131. 'newVersion' : 0
  132. }
  133. };
  134. var is_down = false;
  135. var is_trigger = true;
  136. //总操作控制
  137. upgrade_obj.totalActionControl = function(){
  138. var that = this;
  139. var method = that.total_action.method;
  140. var index = that.total_action.list.indexOf(method);
  141. if(index < 0){
  142. method = that.total_action.method = that.total_action.list[0];
  143. that.total_action.status[method] = 'start';
  144. that[method]();
  145. }else{
  146. var status = that.total_action.status[method];
  147. if(status === 'end'){
  148. index ++;
  149. if(index < that.total_action.list.length){
  150. method = that.total_action.method = that.total_action.list[index];
  151. that.total_action.status[method] = 'start';
  152. that[method]();
  153. }else{
  154. that.totalActionEnd();
  155. }
  156. }else{
  157. }
  158. }
  159. }
  160. //总操作完成
  161. upgrade_obj.totalActionEnd = function(){
  162. setActionName('升级完成');
  163. var html = "";
  164. html += "<div>";
  165. html += '<h1 class="complete-title" style>升级成功!</h1>';
  166. html += '<p class="complete-ontent">您已从版本V'+ this.version.current +'升级到版本<span class="complete-word">V'+ this.version.upgrade +'</span></p>';
  167. html += '<p class="complete-ontent-nex">最新版本为V'+ this.version.newVersion +'</p>';
  168. html += '<p class="complete-url">下载文件存储路径为: 网站根目录/upload/upgrade/'+ this.version.current +'_'+ this.version.upgrade +'</p>';
  169. html += '<span onclick="close_popup()" class="complete-close">确认</span>';
  170. html += '</div>';
  171. layer.open({
  172. title: '温馨提示',
  173. skin: 'layer-tips-class',
  174. type: 1,
  175. area: ['450px'],
  176. content: html,
  177. closeBtn: 0
  178. });
  179. // layer.msg('升级完成', function(index, layero){
  180. // window.location.href = ns.url("shop/upgrade/upgrade");
  181. // })
  182. }
  183. //备份文件
  184. upgrade_obj.backupFile = function(){
  185. var that = this;
  186. var method = 'backupFile';
  187. setActionName('备份系统文件...');
  188. $.ajax({
  189. type:'post',
  190. url : ns.url("shop/upgrade/backupFile"),
  191. dataType : 'json',
  192. success:function(res){
  193. if(res.code >= 0){
  194. that.total_action.status[method] = 'end';
  195. }else{
  196. that.total_action.status[method] = 'error';
  197. setActionContent(res.message);
  198. }
  199. that.totalActionControl();
  200. }
  201. })
  202. }
  203. //备份sql
  204. upgrade_obj.backupSql = function(){
  205. var that = this;
  206. var method = 'backupSql';
  207. var last_table = that.backup_sql.last_table;
  208. var index = that.backup_sql.index;
  209. var series = that.backup_sql.series;
  210. if(!last_table){
  211. setActionName('备份数据库文件...');
  212. }
  213. $.ajax({
  214. type:'post',
  215. url : ns.url("shop/upgrade/backupSql"),
  216. dataType : 'json',
  217. data : {
  218. last_table : last_table,
  219. index : index,
  220. series : series,
  221. },
  222. success:function(res){
  223. if(res.code >= 0){
  224. var data = res.data;
  225. //判断是否备份完成
  226. if(data.is_backup_end){
  227. that.total_action.status[method] = 'end';
  228. that.totalActionControl();
  229. }else{
  230. that.backup_sql.last_table = data.last_table;
  231. that.backup_sql.index = data.index;
  232. that.backup_sql.series = data.series;
  233. setActionContent(res.message);
  234. that.backupSql();
  235. }
  236. }else{
  237. that.total_action.status[method] = 'error';
  238. setActionContent(res.message);
  239. that.totalActionControl();
  240. }
  241. }
  242. })
  243. }
  244. //下载文件操作
  245. upgrade_obj.downloadFile = function(){
  246. var that = this;
  247. setActionName('文件下载');
  248. if(that.data.files.length > 0){
  249. that.downloadFileControl();
  250. }else{
  251. that.total_action.status['downloadFile'] = 'end';
  252. if (action_type == 'upgrade') {
  253. that.totalActionControl();
  254. }
  255. }
  256. }
  257. //下载文件控制
  258. upgrade_obj.downloadFileControl = function(){
  259. //验证文件是否完成
  260. var that = this;
  261. that.download_file.index ++;
  262. var files = that.data['files'];
  263. if(that.download_file.index < files.length && is_down == false){
  264. that.downloadFileExec();
  265. }else{
  266. that.download_file.index = -1;
  267. that.total_action.status['downloadFile'] = 'end';
  268. if (action_type == 'upgrade' && is_down == false) {
  269. setActionContent("文件下载完成");
  270. downComplete();
  271. that.totalActionControl();
  272. } else if(action_type == 'upgrade' && is_down == true){
  273. setActionContent("文件下载完成");
  274. setCountPercent(1);
  275. that.totalActionControl();
  276. } else {
  277. setActionContent("文件下载完成,升级文件已下载到:网站根目录/" + that.download_file.download_root + "目录下");
  278. }
  279. }
  280. }
  281. //执行下载文件
  282. upgrade_obj.downloadFileExec = function(){
  283. if(is_trigger && is_down == true){
  284. verificationDown();
  285. }
  286. var that = this;
  287. var download_file_index = that.download_file.index;
  288. $.ajax({
  289. type:'post',
  290. url : ns.url("shop/upgrade/download"),
  291. dataType : 'json',
  292. data:{
  293. 'action_type': action_type,
  294. 'tag' : 'system_upgrade',
  295. 'download_file_index':download_file_index
  296. },
  297. success:function(data){
  298. if(data.code >= 0){
  299. //显示进度条和下载文件
  300. that.download_file.download_root = data.download_root;
  301. that.version.current = data.current;
  302. that.version.upgrade = data.upgrade;
  303. that.version.newVersion = data.newVersion;
  304. setCountPercent((that.download_file.index + 1) / that.data.files.length);
  305. setActionContent(that.data.files[that.download_file.index]['file_path']);
  306. that.downloadFileControl();
  307. }else{
  308. //如果下载文件有错误可以在一定时间后重新发起请求
  309. if(that.download_file.index === that.download_file.error_index){
  310. that.download_file.error_num ++;
  311. }else{
  312. that.download_file.error_num = 1;
  313. }
  314. if(that.download_file.error_num <= that.download_file.error_limit){
  315. that.download_file.index --;
  316. setActionContent("文件下载出错,即将重新发起请求");
  317. setTimeout(function(){
  318. that.downloadFileControl();
  319. }, 300);
  320. }else{
  321. setActionContent("文件下载出错,已达到最大错误次数,请稍后重新进行系统升级");
  322. layer.msg('error',data.message);
  323. }
  324. }
  325. }
  326. })
  327. }
  328. //覆盖文件
  329. upgrade_obj.executeFile = function(){
  330. var that = this;
  331. var method = 'executeFile';
  332. setActionName('覆盖文件');
  333. if(that.data.files.length > 0){
  334. $.ajax({
  335. type:'post',
  336. url : ns.url("shop/upgrade/executeFile"),
  337. dataType : 'json',
  338. data:{},
  339. success:function(data){
  340. if(data.code >= 0){
  341. //显示进度条和下载文件
  342. that.total_action.status[method] = 'end';
  343. that.totalActionControl();
  344. }else{
  345. layer.msg(data.message);
  346. }
  347. }
  348. })
  349. }else{
  350. that.total_action.status[method] = 'end';
  351. that.totalActionControl();
  352. }
  353. }
  354. //执行sql
  355. upgrade_obj.executeSql = function(){
  356. var that = this;
  357. var method = 'executeSql';
  358. setActionName('执行数据库脚本');
  359. $.ajax({
  360. type:'post',
  361. url : ns.url("shop/upgrade/executeSql"),
  362. dataType : 'json',
  363. success:function(data){
  364. if(data.code >= 0){
  365. that.total_action.status[method] = 'end';
  366. that.totalActionControl();
  367. }else{
  368. layer.msg(data.message);
  369. setActionContent(data.message);
  370. that.executeRecovery();
  371. }
  372. }
  373. })
  374. }
  375. //开始系统升级
  376. upgrade_obj.upgradeStart = function(){
  377. var that = this;
  378. var method = 'upgradeStart';
  379. setActionName('开始系统升级...');
  380. $.ajax({
  381. type:'post',
  382. url : ns.url("shop/upgrade/upgradeStart"),
  383. dataType : 'json',
  384. success:function(res){
  385. if(res.code >= 0){
  386. that.total_action.status[method] = 'end';
  387. }else{
  388. that.total_action.status[method] = 'error';
  389. setActionContent(res.message);
  390. }
  391. that.totalActionControl();
  392. }
  393. })
  394. }
  395. //结束系统升级
  396. upgrade_obj.upgradeEnd = function(){
  397. var that = this;
  398. var method = 'upgradeEnd';
  399. setActionName('结束系统升级...');
  400. $.ajax({
  401. type:'post',
  402. url : ns.url("shop/upgrade/upgradeEnd"),
  403. dataType : 'json',
  404. success:function(res){
  405. if(res.code >= 0){
  406. that.total_action.status[method] = 'end';
  407. that.totalActionControl();
  408. }else{
  409. that.total_action.status[method] = 'error';
  410. layer.msg(res.message);
  411. setActionContent(res.message);
  412. that.executeRecovery();
  413. }
  414. }
  415. })
  416. }
  417. //执行sql
  418. upgrade_obj.executeRecovery = function(){
  419. var that = this;
  420. setActionName('升级出错,系统正在执行回滚操作,请勿关闭浏览器');
  421. $.ajax({
  422. type:'post',
  423. url : ns.url("shop/upgrade/executeRecovery"),
  424. dataType : 'json',
  425. data : {
  426. upgrade_no : that.data.upgrade_no,
  427. },
  428. success:function(data){
  429. if(data.code >= 0){
  430. setActionName('回滚完成');
  431. layer.msg('回滚完成', function(index, layero){
  432. window.location.href = ns.url("shop/upgrade/upgrade");
  433. })
  434. }else{
  435. layer.msg(data.message);
  436. }
  437. }
  438. })
  439. }
  440. var container = document.querySelector('#container');
  441. var bar = new ProgressBar.Circle(container, {
  442. color: '#067cf3',
  443. strokeWidth: 5, // 正好是从圆心开始画起,>50会越过圆心,<50画出的是圆环
  444. trailWidth: 0, // 也设置为50,就是一个未填充的圆形,而不是圆环。要么设置为0
  445. easing: 'easeInOut',
  446. duration: 10,
  447. text: {
  448. style: {
  449. color: '#31708f',
  450. display: 'inline-block',
  451. position: 'absolute',
  452. top: '50%',
  453. left: '50%',
  454. transform: 'translate(-50%,-50%)'
  455. },
  456. autoStyleContainer: false
  457. },
  458. fill: '#e1f2fa', // 圆形内容区域填充色,当需要画圆环时,效果应该最好。
  459. from: { color: '#aaa', width: 1},
  460. to: { color: '#333', width: 5},
  461. step: function(state, circle) {
  462. circle.path.setAttribute('stroke-width', state.width);
  463. var value = Math.round(circle.value() * 100);
  464. circle.setText(value+'%');
  465. }
  466. });
  467. bar.text.style.fontFamily = '"Raleway", Helvetica, sans-serif';
  468. bar.text.style.fontSize = '32px';
  469. //升级操作
  470. function upgradeStart(){
  471. action_type = 'upgrade';
  472. $(".up-btn").attr('disabled',true);
  473. $(".up-footer .up-btn").css({"background-color":"#c0c1c1", "cursor": "not-allowed"});
  474. upgrade_obj.totalActionControl();
  475. }
  476. //控制进度条
  477. function setProgress(width, text){
  478. var barValue = width / 100;
  479. width = width.toFixed(2);
  480. bar.animate(barValue);
  481. $(".count-percent").text(width+"%");
  482. $(".step-content").text(text);
  483. }
  484. //设置操作名称
  485. function setActionName(action_name)
  486. {
  487. $(".action-name").text(action_name);
  488. }
  489. //设置统计进度
  490. function setCountPercent(percent)
  491. {
  492. bar.animate(percent);
  493. percent = percent * 100;
  494. percent = percent.toFixed(2);
  495. $(".count-percent").text(percent + "%");
  496. }
  497. //设置操作名称
  498. function setActionContent(content){
  499. $(".step-content").text(content);
  500. }
  501. /**
  502. * 获取升级信息
  503. */
  504. function getUpgradeInfo() {
  505. $.ajax({
  506. type:'post',
  507. url : ns.url("shop/upgrade/upgradeAction"),
  508. dataType : 'json',
  509. success:function(res){
  510. if(res.code >= 0){
  511. upgrade_obj.data = res.data;
  512. }
  513. }
  514. })
  515. }
  516. /**
  517. * 下载升级文件
  518. */
  519. function downloadFile(){
  520. action_type = 'download';
  521. $(".up-btn").attr('disabled',true);
  522. $(".up-footer .up-btn").css({"background-color":"#c0c1c1", "cursor": "not-allowed"});
  523. upgrade_obj.downloadFile();
  524. }
  525. $(function(){
  526. getUpgradeInfo();
  527. })
  528. function downComplete(){
  529. $.ajax({
  530. type:'post',
  531. url : ns.url("shop/upgrade/downComplete"),
  532. dataType : 'json',
  533. })
  534. }
  535. function verificationDown(){
  536. is_trigger = false;
  537. $.ajax({
  538. type:'post',
  539. url : ns.url("shop/upgrade/verificationDown"),
  540. dataType : 'json',
  541. success:function(res){
  542. is_down = res;
  543. }
  544. })
  545. }
  546. function close_popup() {
  547. window.location.href = ns.url("shop/upgrade/upgrade")
  548. }
  549. </script>
  550. {/block}