queue.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /**
  2. *
  3. * @author maxd
  4. * @date 2019.8.1
  5. */
  6. module.exports = {
  7. //微信的appId
  8. getWxAppid() {
  9. return 'wxd0bec3a917085e78'
  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 'https://zp.xianmaxiong.com'
  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. getChatSearchKeys: function(key) {
  59. let list = uni.getStorageSync("chatSearchKeys");
  60. let keys = key.replace(/\s*/g, "")
  61. let over = false
  62. for (var i = 0; i < keys.length; i++) {
  63. // console.error(keys[i])
  64. if (list.indexOf(keys[i]) != -1) {
  65. over = true;
  66. // return over;
  67. }
  68. }
  69. return over;
  70. },
  71. setJson: function(key, value) {
  72. let jsonString = JSON.stringify(value);
  73. try {
  74. uni.setStorageSync(key, jsonString);
  75. } catch (e) {
  76. // error
  77. }
  78. },
  79. setData: function(key, value) {
  80. try {
  81. uni.setStorageSync(key, value);
  82. } catch (e) {
  83. // error
  84. }
  85. },
  86. getData: function(key) {
  87. try {
  88. const value = uni.getStorageSync(key);
  89. if (value) {
  90. return value;
  91. }
  92. } catch (e) {
  93. // error
  94. }
  95. },
  96. getJson: function(key) {
  97. try {
  98. const value = uni.getStorageSync(key);
  99. if (value) {
  100. return JSON.parse(value);
  101. }
  102. } catch (e) {
  103. // error
  104. }
  105. },
  106. clear: function() {
  107. uni.clearStorage();
  108. },
  109. get: function(key) { //获取队列里面全部的数据
  110. let data = this.getJson(key);
  111. if (data instanceof Array) {
  112. return data;
  113. }
  114. return [];
  115. },
  116. insert: function(param) { //队列插入数据
  117. param.capacityNum = param.capacityNum || 100; //队列容量 默认队列中超过100条数据,自动删除尾部
  118. let data = this.getJson(param.key);
  119. if (data instanceof Array) {
  120. if (data.length > param.capacityNum) {
  121. let total = data.length - param.capacityNum;
  122. for (let i = 0; i < total; i++) {
  123. data.pop();
  124. }
  125. }
  126. data.unshift(param.value);
  127. } else {
  128. data = [];
  129. data.push(param.value);
  130. }
  131. this.setJson(param.key, data);
  132. },
  133. removeItem: function(key, itemIds) { //提供itemIds数组 批量删除队列中的某项数据
  134. let data = this.getJson(key);
  135. if (data instanceof Array) {
  136. for (let i = 0; i < itemIds.length; i++) {
  137. for (let p = 0; p < data.length; p++) {
  138. if (itemIds[i] === data[p].itemid) {
  139. data.splice(p, 1);
  140. break;
  141. }
  142. }
  143. }
  144. this.setJson(key, data);
  145. }
  146. },
  147. isExist: function(key, itemId) { //检测某条数据在队列中是否存在
  148. let data = this.getJson(key);
  149. if (data instanceof Array) {
  150. for (let p = 0; p < data.length; p++) {
  151. if (itemId === data[p].itemid) {
  152. return true;
  153. }
  154. }
  155. }
  156. return false;
  157. },
  158. isExistPdd: function(key, itemId) { //检测某条数据在队列中是否存在
  159. let data = this.getJson(key);
  160. if (data instanceof Array) {
  161. for (let p = 0; p < data.length; p++) {
  162. if (itemId === data[p].goodsId) {
  163. return true;
  164. }
  165. }
  166. }
  167. return false;
  168. },
  169. isExistJd: function(key, itemId) { //检测某条数据在队列中是否存在
  170. let data = this.getJson(key);
  171. if (data instanceof Array) {
  172. for (let p = 0; p < data.length; p++) {
  173. if (itemId === data[p].skuId) {
  174. return true;
  175. }
  176. }
  177. }
  178. return false;
  179. },
  180. remove: function(key) { //删除某条队列
  181. try {
  182. uni.removeStorageSync(key);
  183. //localStorage.removeItem(key)
  184. } catch (e) {
  185. // error
  186. }
  187. },
  188. getCount: function(key) { //获取队列中全部数据数量
  189. let data = this.getJson(key);
  190. if (data instanceof Array) {
  191. return data.length;
  192. }
  193. return 0;
  194. },
  195. };