api.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import WechatShare from '../wechat/WechatShare.js';
  2. let envHost = process.env.API_ROOT;
  3. let enter_url = "";
  4. let gWxShare = null;
  5. let mobile = {
  6. Android: function() {
  7. return navigator.userAgent.match(/Android/i);
  8. },
  9. BlackBerry: function() {
  10. return navigator.userAgent.match(/BlackBerry/i);
  11. },
  12. iOS: function() {
  13. return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  14. },
  15. Opera: function() {
  16. return navigator.userAgent.match(/Opera Mini/i);
  17. },
  18. Windows: function() {
  19. return navigator.userAgent.match(/IEMobile/i);
  20. },
  21. any: function() {
  22. return (mobile.Android() || mobile.BlackBerry() || mobile.iOS() || mobile.Opera() || mobile.Windows());
  23. }
  24. };
  25. class Api
  26. {
  27. static host() {
  28. return envHost;
  29. }
  30. static special(special_id) {
  31. return this.host() + "/mobile/index.php?act=special&op=index&page=10&curpage=1&client_type=ajax&special_id=" + special_id;
  32. }
  33. static brands() {
  34. return this.host() + "/mobile/index.php?act=brand&op=home&client_type=ajax";
  35. }
  36. static functionList() {
  37. return this.host() + "/mobile/index.php?client_type=ajax&act=category&op=index"
  38. }
  39. static goodsDetail(goods_id) {
  40. return this.host() + `/mobile/index.php?goods_id=${goods_id}&act=goods_common&op=index&client_type=ajax`
  41. }
  42. static searchSuggest() {
  43. return this.host() + '/mobile/index.php?act=search&op=history&curpage=1&client_type=ajax'
  44. }
  45. static search() {
  46. return this.host() + '/mobile/index.php?act=search&op=suggest_words&client_type=ajax'
  47. }
  48. static goodsContent(goods_id) {
  49. return this.host() + `/mobile/index.php?act=goods_common&op=detail_ajax&goods_id=${goods_id}&client_type=ajax`
  50. }
  51. static memberInfo() {
  52. return this.host() + '/mobile/index.php?act=member_info&op=get&client_type=ajax'
  53. }
  54. static shoppingCart() {
  55. return this.host() + '/mobile/index.php?act=cart&op=list&client_type=ajax'
  56. }
  57. static changeOrderState(action, order_id) {
  58. return this.host() + '/mobile/index.php?act=member_order&op=change_state&client_type=ajax&act_type=' + action + "&order_id=" + order_id
  59. }
  60. static orderList() {
  61. return this.host() + '/mobile/index.php?act=member_order&page=30&op=list&page=15&client_type=ajax'
  62. }
  63. static refundOrder(order_sn) {
  64. return this.host() + '/mobile/index.php?act=member_refund&op=order_refund&client_type=ajax&order_sn=' + order_sn
  65. }
  66. static deliverInfo(order_id) {
  67. return this.host() + '/mobile/index.php?act=member_order&op=search_deliver&order_id=' + order_id
  68. }
  69. static shoppingCartEdit(quantity, cart_id) {
  70. return this.host() + `/mobile/index.php?quantity=${quantity}&act=cart&op=edit&cart_id=${cart_id}&client_type=ajax`
  71. }
  72. static shoppingCartAdd(quantity, goods_id) {
  73. return this.host() + `/mobile/index.php?quantity=${quantity}&act=cart&goods_id=${goods_id}&op=addex&client_type=ajax`
  74. }
  75. static userBonus() {
  76. return this.host() + '/mobile/index.php?act=cart&op=rate_money&client_type=ajax'
  77. }
  78. static addressList() {
  79. return this.host() + '/mobile/index.php?act=member_address&op=address_list&client_type=ajax';
  80. }
  81. static homeTabs() {
  82. return this.host() + "/mobile/index.php?act=mshop&op=tabs&client_type=ajax"
  83. }
  84. static login(mobile, code) {
  85. return this.host() + `/mobile/index.php?act=login&op=bind_mobile&client_type=ajax&mobile=${mobile}&code=${code}`;
  86. }
  87. static getCode(mobile) {
  88. return this.host() + `/mobile/index.php?act=login&op=getcodex&client_type=ajax&mobile=${mobile}&type=register`;
  89. }
  90. static getFCode() {
  91. return this.host() + '/mobile/index.php?act=member_fcode&op=list&curpage=1&client_type=ajax';
  92. }
  93. static stepFirst(ifcart, cart_id, goods_id, num) {
  94. let goods_datas = '';
  95. if (ifcart == 0) {
  96. goods_datas = goods_id + '|' + num;
  97. }
  98. else {
  99. goods_datas = cart_id;
  100. }
  101. return this.host() + `/mobile/index.php?act=member_buy&op=step_first&curpage=1&ifcart=${ifcart}&cart_id=${goods_datas}&client_type=ajax`;
  102. }
  103. static stepSecond(cart_ids, goods_id, goods_num, addr_id, inv_id, vat_hash, offpay_hash, offpay_hash_batch) {
  104. let ifcart = cart_ids !== '' ? true : false;
  105. let iscart = ifcart ? 1 : 0;
  106. let cartids = ifcart ? cart_ids : (goods_id + '|' + goods_num);
  107. return this.host() + `/mobile/index.php?client_type=ajax&act=member_buy&op=step_second&payment=jspay&usebonus=1&ifcart=${iscart}&cart_id=${cartids}&address_id=${addr_id}&invoice_id=${inv_id}&vat_hash=${vat_hash}&offpay_hash=${offpay_hash}&offpay_hash_batch=${offpay_hash_batch}`;
  108. }
  109. static getAddress() {
  110. return this.host() + '/mobile/index.php?act=app_update&op=area&curpage=1&client_type=ajax';
  111. }
  112. static addAddress(true_name, area_id, address, mobile) {
  113. return this.host() + `/mobile/index.php?act=member_address&op=address_add&curpage=1&client_type=ajax&true_name=${true_name}&area_id=${area_id}&address=${address}&mob_phone=${mobile}`;
  114. }
  115. static setDefaultAddress(id, is_default) {
  116. return this.host() + `/mobile/index.php?act=member_address&op=set_default&curpage=1&client_type=ajax&address_id=${id}&is_default=${is_default}`;
  117. }
  118. static paySn(pay_sn) {
  119. return this.host() + `/mobile/index.php?act=member_order&op=pay_info&curpage=1&pay_sn=${pay_sn}&client_type=ajax`;
  120. }
  121. static init_url(href)
  122. {
  123. enter_url = href;
  124. }
  125. static create_share(data,href)
  126. {
  127. if(mobile.iOS())
  128. {
  129. if(gWxShare == null) {
  130. gWxShare = new WechatShare(data,href);
  131. } else {
  132. gWxShare.register(data);
  133. }
  134. return gWxShare;
  135. }
  136. else
  137. {
  138. return new WechatShare(data,href);
  139. }
  140. }
  141. static sign_url(href)
  142. {
  143. if(mobile.iOS()) {
  144. return enter_url;
  145. } else {
  146. return href;
  147. }
  148. }
  149. }
  150. export default Api