api.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. static host() {
  27. return envHost;
  28. }
  29. static special(special_id) {
  30. return this.host() + "/mobile/index.php?act=special&op=index&page=10&curpage=1&client_type=ajax&special_id=" + special_id;
  31. }
  32. static brands() {
  33. return this.host() + "/mobile/index.php?act=brand&op=home&client_type=ajax";
  34. }
  35. static functionList() {
  36. return this.host() + "/mobile/index.php?client_type=ajax&act=category&op=index"
  37. }
  38. static goodsDetail(goods_id) {
  39. return this.host() + `/mobile/index.php?goods_id=${goods_id}&act=goods_common&op=index&client_type=ajax`
  40. }
  41. static searchSuggest() {
  42. return this.host() + '/mobile/index.php?act=search&op=history&curpage=1&client_type=ajax'
  43. }
  44. static search() {
  45. return this.host() + '/mobile/index.php?act=search&op=suggest_words&client_type=ajax'
  46. }
  47. static goodsContent(goods_id) {
  48. return this.host() + `/mobile/index.php?act=goods_common&op=detail_ajax&goods_id=${goods_id}&client_type=ajax`
  49. }
  50. static memberInfo() {
  51. return this.host() + '/mobile/index.php?act=member_info&op=get&client_type=ajax'
  52. }
  53. static shoppingCart() {
  54. return this.host() + '/mobile/index.php?act=cart&op=list&client_type=ajax'
  55. }
  56. static changeOrderState(action, order_id) {
  57. return this.host() + '/mobile/index.php?act=member_order&op=change_state&client_type=ajax&act_type=' + action + "&order_id=" + order_id
  58. }
  59. static orderList() {
  60. return this.host() + '/mobile/index.php?act=member_order&page=30&op=list&page=15&client_type=ajax'
  61. }
  62. static refundOrder(order_sn) {
  63. return this.host() + '/mobile/index.php?act=member_refund&op=order_refund&client_type=ajax&order_sn=' + order_sn
  64. }
  65. static deliverInfo(order_id) {
  66. return this.host() + '/mobile/index.php?act=member_order&op=search_deliver&order_id=' + order_id
  67. }
  68. static shoppingCartEdit(quantity, cart_id) {
  69. return this.host() + `/mobile/index.php?quantity=${quantity}&act=cart&op=edit&cart_id=${cart_id}&client_type=ajax`
  70. }
  71. static shoppingCartAdd(quantity, goods_id) {
  72. return this.host() + `/mobile/index.php?quantity=${quantity}&act=cart&goods_id=${goods_id}&op=addex&client_type=ajax`
  73. }
  74. static userBonus() {
  75. return this.host() + '/mobile/index.php?act=cart&op=rate_money&client_type=ajax'
  76. }
  77. static addressList() {
  78. return this.host() + '/mobile/index.php?act=member_address&op=address_list&client_type=ajax';
  79. }
  80. static homeTabs() {
  81. return this.host() + "/mobile/index.php?act=mshop&op=tabs&client_type=ajax"
  82. }
  83. static login(mobile, code) {
  84. return this.host() + `/mobile/index.php?act=login&op=bind_mobile&client_type=ajax&mobile=${mobile}&code=${code}`;
  85. }
  86. static getCode(mobile) {
  87. return this.host() + `/mobile/index.php?act=login&op=getcodex&client_type=ajax&mobile=${mobile}&type=register`;
  88. }
  89. static getFCode() {
  90. return this.host() + '/mobile/index.php?act=member_fcode&op=list&curpage=1&client_type=ajax';
  91. }
  92. static stepFirst(ifcart, cart_id, goods_id, num) {
  93. let goods_datas = '';
  94. if (ifcart == 0) {
  95. goods_datas = goods_id + '|' + num;
  96. }
  97. else {
  98. goods_datas = cart_id;
  99. }
  100. return this.host() + `/mobile/index.php?act=member_buy&op=step_first&curpage=1&ifcart=${ifcart}&cart_id=${goods_datas}&client_type=ajax`;
  101. }
  102. static stepSecond(cart_ids, goods_id, goods_num, addr_id, inv_id, vat_hash, offpay_hash, offpay_hash_batch) {
  103. let ifcart = cart_ids !== '' ? true : false;
  104. let iscart = ifcart ? 1 : 0;
  105. let cartids = ifcart ? cart_ids : (goods_id + '|' + goods_num);
  106. 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}`;
  107. }
  108. static getAddress() {
  109. return this.host() + '/mobile/index.php?act=app_update&op=area&curpage=1&client_type=ajax';
  110. }
  111. static addAddress(true_name, area_id, address, mobile) {
  112. 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}`;
  113. }
  114. static setDefaultAddress(id, is_default) {
  115. return this.host() + `/mobile/index.php?act=member_address&op=set_default&curpage=1&client_type=ajax&address_id=${id}&is_default=${is_default}`;
  116. }
  117. static paySn(pay_sn) {
  118. return this.host() + `/mobile/index.php?act=member_order&op=pay_info&curpage=1&pay_sn=${pay_sn}&client_type=ajax`;
  119. }
  120. static init_url() {
  121. if (enter_url == "") {
  122. enter_url = window.location.href;
  123. }
  124. }
  125. static create_share(data, href) {
  126. if (mobile.iOS()) {
  127. gWxShare = new WechatShare(data, this.sign_url());
  128. return gWxShare;
  129. }
  130. else {
  131. return new WechatShare(data, this.sign_url());
  132. }
  133. }
  134. static sign_url() {
  135. let temp;
  136. if (mobile.iOS()) {
  137. Api.init_url();
  138. temp = enter_url;
  139. } else {
  140. temp = window.location.href;
  141. }
  142. return decodeURIComponent(temp);
  143. }
  144. }
  145. export default Api