queue.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. *
  3. * @author maxd
  4. * @date 2019.8.1
  5. */
  6. module.exports = {
  7. //微信的appId
  8. getWxAppid() {
  9. return 'wx41da4b0848b8baae'
  10. },
  11. //全局邀请码
  12. getInvitation() {
  13. return uni.getStorageSync("publicRelation")
  14. },
  15. //获取APP下载地址
  16. getAppDownUrl() {
  17. return uni.getStorageSync("appurl")
  18. },
  19. //全局域名 部分html中需要单独替换 需要修改config中的网络请求域名
  20. publicYuMing() {
  21. return 'http://smam.qd-xiaomage.com:9210'
  22. },
  23. logout() {
  24. this.remove("token");
  25. this.remove("userId");
  26. this.remove("mobile");
  27. this.remove("openid");
  28. this.remove("nickName");
  29. this.remove("relation");
  30. this.remove("image_url");
  31. this.remove("relation_id");
  32. this.remove("isInvitation");
  33. this.remove("member");
  34. },
  35. loginClear() {
  36. this.remove("token");
  37. this.remove("userId");
  38. this.remove("mobile");
  39. this.remove("nickName");
  40. this.remove("image_url");
  41. this.remove("relation_id");
  42. this.remove("isInvitation");
  43. this.remove("member");
  44. },
  45. showLoading(title) {
  46. uni.showLoading({
  47. title: title
  48. });
  49. },
  50. showToast(title) {
  51. uni.showToast({
  52. title: title,
  53. mask: false,
  54. duration: 2000,
  55. icon: "none"
  56. });
  57. },
  58. setJson: function(key, value) {
  59. let jsonString = JSON.stringify(value);
  60. try {
  61. uni.setStorageSync(key, jsonString);
  62. } catch (e) {
  63. // error
  64. }
  65. },
  66. setData: function(key, value) {
  67. try {
  68. uni.setStorageSync(key, value);
  69. } catch (e) {
  70. // error
  71. }
  72. },
  73. getData: function(key) {
  74. try {
  75. const value = uni.getStorageSync(key);
  76. if (value) {
  77. return value;
  78. }
  79. } catch (e) {
  80. // error
  81. }
  82. },
  83. getJson: function(key) {
  84. try {
  85. const value = uni.getStorageSync(key);
  86. if (value) {
  87. return JSON.parse(value);
  88. }
  89. } catch (e) {
  90. // error
  91. }
  92. },
  93. clear: function() {
  94. uni.clearStorage();
  95. },
  96. get: function(key) { //获取队列里面全部的数据
  97. let data = this.getJson(key);
  98. if (data instanceof Array) {
  99. return data;
  100. }
  101. return [];
  102. },
  103. insert: function(param) { //队列插入数据
  104. param.capacityNum = param.capacityNum || 100; //队列容量 默认队列中超过100条数据,自动删除尾部
  105. let data = this.getJson(param.key);
  106. if (data instanceof Array) {
  107. if (data.length > param.capacityNum) {
  108. let total = data.length - param.capacityNum;
  109. for (let i = 0; i < total; i++) {
  110. data.pop();
  111. }
  112. }
  113. data.unshift(param.value);
  114. } else {
  115. data = [];
  116. data.push(param.value);
  117. }
  118. this.setJson(param.key, data);
  119. },
  120. removeItem: function(key, itemIds) { //提供itemIds数组 批量删除队列中的某项数据
  121. let data = this.getJson(key);
  122. if (data instanceof Array) {
  123. for (let i = 0; i < itemIds.length; i++) {
  124. for (let p = 0; p < data.length; p++) {
  125. if (itemIds[i] === data[p].itemid) {
  126. data.splice(p, 1);
  127. break;
  128. }
  129. }
  130. }
  131. this.setJson(key, data);
  132. }
  133. },
  134. isExist: function(key, itemId) { //检测某条数据在队列中是否存在
  135. let data = this.getJson(key);
  136. if (data instanceof Array) {
  137. for (let p = 0; p < data.length; p++) {
  138. if (itemId === data[p].itemid) {
  139. return true;
  140. }
  141. }
  142. }
  143. return false;
  144. },
  145. isExistPdd: function(key, itemId) { //检测某条数据在队列中是否存在
  146. let data = this.getJson(key);
  147. if (data instanceof Array) {
  148. for (let p = 0; p < data.length; p++) {
  149. if (itemId === data[p].goodsId) {
  150. return true;
  151. }
  152. }
  153. }
  154. return false;
  155. },
  156. isExistJd: function(key, itemId) { //检测某条数据在队列中是否存在
  157. let data = this.getJson(key);
  158. if (data instanceof Array) {
  159. for (let p = 0; p < data.length; p++) {
  160. if (itemId === data[p].skuId) {
  161. return true;
  162. }
  163. }
  164. }
  165. return false;
  166. },
  167. remove: function(key) { //删除某条队列
  168. try {
  169. uni.removeStorageSync(key);
  170. //localStorage.removeItem(key)
  171. } catch (e) {
  172. // error
  173. }
  174. },
  175. getCount: function(key) { //获取队列中全部数据数量
  176. let data = this.getJson(key);
  177. if (data instanceof Array) {
  178. return data.length;
  179. }
  180. return 0;
  181. },
  182. };