Aucune description

setting.js 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. mui.init();
  2. //初始化单页view
  3. var viewApi = mui('#app').view({
  4. defaultPage: '#setting'
  5. });
  6. window.addEventListener('refresh', function(e){//执行刷新
  7. adminTx();
  8. });
  9. var a = localStorage.getItem('token')
  10. var mineTx;
  11. //初始化单页的区域滚动
  12. mui('.mui-scroll-wrapper').scroll();
  13. function adminTx() {
  14. mui.ajax(huayi.config.callcenter_url + '/UserAccount/GetNowUser', {
  15. data: {
  16. token: a,
  17. },
  18. dataType: 'json', //服务器返回json格式数据
  19. type: 'get', //HTTP请求类型
  20. timeout: 10000, //超时时间设置为10秒;
  21. headers: {
  22. 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
  23. },
  24. success: function(data) {
  25. var RoleCode = data.data.role.F_RoleCode;
  26. $(".F_UserName").text(data.data.user.F_UserName);
  27. $(".rolname").text(data.data.user.F_UserCode);
  28. if(!data.data.FileUrl[0].F_Url) {
  29. $('.top_left img').attr("src", "img/3.png");
  30. }else{
  31. $('.top_left img').attr("src", data.data.FileUrl[0].F_Url);
  32. }
  33. },
  34. error: function(xhr, type, errorThrown) {
  35. //异常处理;
  36. }
  37. });
  38. }
  39. // //检测网络连接
  40. mui.plusReady(function() {
  41. var Code_;
  42. var NewCode_;
  43. var server = huayi.config.callcenter_url + "ApplicationsRefresh/GetInfo?"; //获取升级描述文件服务器地址
  44. document.addEventListener("netchange", wainshow, false);
  45. plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
  46. // $("#Vb").text(wgtinfo.version);
  47. // var
  48. // $('.update').text(Code_);
  49. console.log("当前应用版本:" + wgtinfo.version + "---" + plus.runtime.version);
  50. localStorage.setItem("Code", wgtinfo.version) //缓存保存版本号;
  51. Code_ = localStorage.getItem("Code");
  52. $('.update').text(Code_);
  53. // Gx();
  54. });
  55. //检查更新
  56. document.getElementById("update").addEventListener('tap', function() {
  57. var server = huayi.config.callcenter_url + "ApplicationsRefresh/GetInfo?"; //获取升级描述文件服务器地址
  58. mui.ajax(server, {
  59. data: {
  60. isNew: true,
  61. token: a
  62. },
  63. dataType: 'json', //服务器返回json格式数据
  64. type: 'post', //HTTP请求类型
  65. timeout: 10000, //超时时间设置为10秒;
  66. headers: {
  67. 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
  68. },
  69. success: function(data) {
  70. if(data.state == "success") {
  71. NewCode_ = data.data.F_VersionCode;
  72. localStorage.setItem("Code", NewCode_); //缓存保存版本号;
  73. if(Code_ != NewCode_) {
  74. var Codes = localStorage.setItem("Code", NewCode_);
  75. console.log(Codes);
  76. plus.nativeUI.confirm("发现新版本", function(event) {
  77. var tapIndex = event.index;
  78. if(tapIndex == 0) {
  79. plus.runtime.openURL(data.data.F_DownUrl);
  80. } else {
  81. mui.toast("取消更新");
  82. }
  83. }, "提示", ["立即更新", "取消", ])
  84. }
  85. } else {
  86. mui.toast(data.message);
  87. }
  88. },
  89. error: function(data) {
  90. //异常处理;
  91. console.log(data.message);
  92. }
  93. })
  94. });
  95. var backcount = 0;
  96. mui.back = function() {
  97. if(mui.os.ios) return;
  98. if(backcount > 0) {
  99. if(window.plus) plus.runtime.quit();
  100. return;
  101. };
  102. mui.toast('再按一次退出应用');
  103. backcount++;
  104. setTimeout(function() {
  105. backcount = 0;
  106. }, 2000);
  107. };
  108. });
  109. //检测网络连接
  110. function wainshow() {
  111. if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
  112. mui.toast("网络异常,请检查网络设置!");
  113. } else {
  114. mui.toast("网络连接");
  115. }
  116. }
  117. //常见问题
  118. // document.getElementById('Question').addEventListener('tap', function() {
  119. // var nwaiting = plus.nativeUI.showWaiting();
  120. // webviewShow = plus.webview.create("Common/portrait_head.html"); //后台创建webview并打开show.html
  121. // webviewShow.addEventListener("loaded", function() { //注册新webview的载入完成事件
  122. // nwaiting.close(); //新webview的载入完毕后关闭等待框
  123. // webviewShow.show("slide-in-right", 300); //把新webview窗体显示出来,显示动画效果为速度300毫秒的右侧移入动画
  124. // }, false);
  125. // });
  126. //常见问题
  127. document.getElementById('Bom').addEventListener('tap', function() {
  128. var nwaiting = plus.nativeUI.showWaiting();
  129. webviewShow = plus.webview.create("Common/Setting-Bm.html"); //后台创建webview并打开show.html
  130. webviewShow.addEventListener("loaded", function() { //注册新webview的载入完成事件
  131. nwaiting.close(); //新webview的载入完毕后关闭等待框
  132. webviewShow.show("slide-in-right", 300); //把新webview窗体显示出来,显示动画效果为速度300毫秒的右侧移入动画
  133. }, false);
  134. });
  135. //退出
  136. document.getElementById('exit').addEventListener('tap', function() {
  137. var btnArray = [{
  138. title: "注销当前账号"
  139. }, {
  140. title: "直接关闭应用"
  141. }];
  142. plus.nativeUI.actionSheet({
  143. cancel: "取消",
  144. buttons: btnArray
  145. }, function(event) {
  146. var index = event.index;
  147. switch(index) {
  148. case 1:
  149. //注销账号
  150. plus.runtime.restart();
  151. break;
  152. case 2:
  153. plus.runtime.quit();
  154. break;
  155. }
  156. });
  157. }, false);
  158. function logout() {
  159. $.ajax({
  160. url: huayi.config.callcenter_url + "Login/Logout",
  161. data: {
  162. token: a
  163. },
  164. dataType: "json",
  165. type: 'post', //HTTP请求类型
  166. success: function(res) {
  167. if(res.state == "success") {
  168. localStorage.clear();
  169. mui.alert(res.data);
  170. }
  171. }
  172. });
  173. }
  174. function Clean() {
  175. $("#mobile").val('');
  176. $("#title").val('');
  177. $("#content").val('');
  178. }
  179. var view = viewApi.view;
  180. (function($) {
  181. //处理view的后退与webview后退
  182. var oldBack = $.back;
  183. $.back = function() {
  184. if(viewApi.canBack()) { //如果view可以后退,则执行view的后退
  185. viewApi.back();
  186. } else { //执行webview后退
  187. oldBack();
  188. }
  189. };
  190. //监听页面切换事件方案1,通过view元素监听所有页面切换事件,目前提供pageBeforeShow|pageShow|pageBeforeBack|pageBack四种事件(before事件为动画开始前触发)
  191. //第一个参数为事件名称,第二个参数为事件回调,其中e.detail.page为当前页面的html对象
  192. view.addEventListener('pageBeforeShow', function(e) {
  193. // console.log(e.detail.page.id + ' beforeShow');
  194. });
  195. view.addEventListener('pageShow', function(e) {
  196. // console.log(e.detail.page.id + ' show');
  197. });
  198. view.addEventListener('pageBeforeBack', function(e) {
  199. // console.log(e.detail.page.id + ' beforeBack');
  200. });
  201. view.addEventListener('pageBack', function(e) {
  202. // console.log(e.detail.page.id + ' back');
  203. });
  204. })(mui);
  205. //点击两次就退出软件