app.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. var urls = function() {
  2. //var host = "http://192.168.100.3:7979";
  3. var host = "http://192.168.5.104:7979";
  4. //var host = "http://app.biboacgn.com";
  5. var url = {
  6. "path": host,
  7. "sendMessage": host + "/app/user/sendMessage", //发送短信
  8. "login": host + "/app/user/login", //用户登录
  9. "userInfo": host + "/app/user/userInfo", //用户信息
  10. "edit_info": host + "/app/user/edit", //编辑用户信息
  11. "user_upload": host + "/app/user/uploadHeader", //用户上传头像
  12. "main": host + "/app/main", //首页加载数据
  13. "feedback": host + "/app/other/feedback", //意见反馈
  14. "agreement": host + "/app/other/agreement", //服务条款
  15. "guide": host + "/app/other/guide/", //萌新必读
  16. };
  17. return url;
  18. }
  19. /**
  20. *一些常用参数
  21. */
  22. function getConstant() {
  23. var str = {
  24. "qq": 2060514344,
  25. "group": 642999141,
  26. "phone": "13541009237"
  27. }
  28. return str;
  29. }
  30. /**
  31. * i
  32. * @param 窗口id
  33. * @param 窗口地址url
  34. * @param 传递参数
  35. * @param 跳转动画
  36. */
  37. function open(id, url, para, anim) {
  38. anim == null || undefined ? 'pop-in' : anim;
  39. mui.openWindow({
  40. id: id,
  41. url: url,
  42. show: {
  43. aniShow: anim
  44. },
  45. styles: {
  46. popGesture: 'hide'
  47. },
  48. waiting: {
  49. autoShow: true,
  50. title: '正在加载...',
  51. },
  52. extras: {
  53. param: para
  54. },
  55. createNew: true,
  56. hardwareAccelerated: true
  57. });
  58. }
  59. /**
  60. *判断是否登录
  61. */
  62. var hasLogin = function() {
  63. var user = localStorage.getItem("user");
  64. return user == null || user == '' ? false : true;
  65. }
  66. /**
  67. *软件第一次运行
  68. */
  69. var first = function() {
  70. var f = localStorage.getItem("first");
  71. return f == null || f == '' ? true : false;
  72. }
  73. /**
  74. *获取用户信息
  75. */
  76. var getUser = function() {
  77. var user = localStorage.getItem("user");
  78. return JSON.parse(user);
  79. }
  80. var getToken = function() {
  81. return localStorage.getItem("token");
  82. }
  83. /**
  84. *
  85. * @param 请求url
  86. * @param 请求参数
  87. * @param 回调回调
  88. */
  89. function request(url, param, callback) {
  90. //plus.nativeUI.showWaiting("正在加载...");
  91. mui.ajax(url, {
  92. data: param,
  93. dataType: 'json', //服务器返回json格式数据
  94. type: 'post', //HTTP请求类型
  95. contentType: "application/x-www-form-urlencoded; charset=utf-8",
  96. beforeSend: function(req) {
  97. if(hasLogin()) {
  98. req.setRequestHeader("token", getToken());
  99. req.setRequestHeader("phone", getUser().account);
  100. }
  101. },
  102. success: callback,
  103. error: function(xhr, type, errorThrown) {
  104. //plus.nativeUI.closeWaiting();
  105. }
  106. });
  107. }
  108. //获取订单状态
  109. var getState = function(index) {
  110. if(index == 0) {
  111. return '等待发货';
  112. }
  113. if(index == 1) {
  114. return '等待收货';
  115. }
  116. if(index == 2) {
  117. return '已确认收货 等待归还衣服';
  118. }
  119. if(index == 3) {
  120. return '等待客服收货';
  121. }
  122. if(index == 4) {
  123. return '客服已确认收货 等待退款';
  124. }
  125. if(index == 5) {
  126. return '交易完成';
  127. }
  128. if(index == 6) {
  129. return '申请取消订单中 等待同意';
  130. }
  131. if(index == 7) {
  132. return '订单已取消';
  133. }
  134. }
  135. //手机格式验证
  136. function isPhone(phone) {
  137. var reg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
  138. if(reg.test(phone)) {
  139. return true;
  140. } else {
  141. return false;
  142. }
  143. return false;
  144. }
  145. /**
  146. * 切换到指定qq联系人
  147. * @param {Object} qq
  148. */
  149. function callqq(qq) {
  150. if(plus.os.name == "Android") {
  151. var main = plus.android.runtimeMainActivity();
  152. var Intent = plus.android.importClass('android.content.Intent');
  153. var Uri = plus.android.importClass('android.net.Uri');
  154. var intent = new Intent(Intent.ACTION_VIEW, Uri.parse("mqqwpa://im/chat?chat_type=wpa&uin=" + qq));
  155. main.startActivity(intent);
  156. } else {
  157. plus.runtime.launchApplication({
  158. action: "mqq://im/chat?chat_type=wpa&uin=" + qq + "&version=1&src_type=web"
  159. }, function(e) {
  160. plus.nativeUI.confirm("检查到您未安装qq,请先到appstore搜索下载?", function(i) {
  161. if(i.index == 0) {
  162. iosAppstore("itunes.apple.com/cn/app/mqq/");
  163. }
  164. });
  165. });
  166. }
  167. }
  168. //当月小于10时,后面加个0;
  169. function p(s) {
  170. return s < 10 ? '0' + s : s;
  171. }
  172. /**
  173. * 复制文本到剪贴板
  174. * @param {Object} copy_content
  175. */
  176. function copy(copy_content) {
  177. //判断是安卓还是ios
  178. if(mui.os.ios) {
  179. //ios
  180. var UIPasteboard = plus.ios.importClass("UIPasteboard");
  181. var generalPasteboard = UIPasteboard.generalPasteboard();
  182. //设置/获取文本内容:
  183. generalPasteboard.plusCallMethod({
  184. setValue: ""+copy_content,
  185. forPasteboardType: "public.utf8-plain-text"
  186. });
  187. generalPasteboard.plusCallMethod({
  188. valueForPasteboardType: "public.utf8-plain-text"
  189. });
  190. } else {
  191. //安卓
  192. var Context = plus.android.importClass("android.content.Context");
  193. var main = plus.android.runtimeMainActivity();
  194. var clip = main.getSystemService(Context.CLIPBOARD_SERVICE);
  195. plus.android.invoke(clip, "setText", "" + copy_content);
  196. }
  197. }
  198. /**
  199. * 初始化剪裁
  200. * @param {Object} ratio 裁剪框比例1是正方形,0NaN是无限制,16:9/4:3/2:3
  201. * @param {Object} path 剪裁图像路径
  202. */
  203. function getClipper(ratio, path) {
  204. var cropper = null;
  205. document.getElementById("clipp").style.display = 'block';
  206. document.getElementById("image").src = path;
  207. var image = document.getElementById("image");
  208. cropper = new Cropper(image, {
  209. aspectRatio: ratio,
  210. viewMode: 1,
  211. });
  212. return cropper;
  213. }