queue.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /**
  2. *
  3. * @author maxd
  4. * @date 2019.8.1
  5. */
  6. import configdata from './config'
  7. module.exports = {
  8. //微信的appId
  9. getWxAppid() {
  10. return 'wxd0bec3a917085e78'
  11. },
  12. //全局邀请码
  13. getInvitation() {
  14. return uni.getStorageSync("publicRelation")
  15. },
  16. //获取APP下载地址
  17. getAppDownUrl() {
  18. return uni.getStorageSync("appurl")
  19. },
  20. //全局域名 部分html中需要单独替换 需要修改config中的网络请求域名
  21. publicYuMing() {
  22. return 'https://zp.xianmaxiong.com'
  23. },
  24. logout() {
  25. this.remove("token");
  26. this.remove("userId");
  27. this.remove("mobile");
  28. this.remove("openid");
  29. this.remove("nickName");
  30. this.remove("relation");
  31. this.remove("image_url");
  32. this.remove("relation_id");
  33. this.remove("isInvitation");
  34. this.remove("member");
  35. },
  36. loginClear() {
  37. this.remove("token");
  38. this.remove("userId");
  39. this.remove("mobile");
  40. this.remove("nickName");
  41. this.remove("image_url");
  42. this.remove("relation_id");
  43. this.remove("isInvitation");
  44. this.remove("member");
  45. },
  46. showLoading(title) {
  47. uni.showLoading({
  48. title: title
  49. });
  50. },
  51. showToast(title) {
  52. uni.showToast({
  53. title: title,
  54. mask: false,
  55. duration: 2000,
  56. icon: "none"
  57. });
  58. },
  59. getChatSearchKeys: function(key) {
  60. let list = uni.getStorageSync("chatSearchKeys");
  61. let keys = key.replace(/\s*/g, "")
  62. let over = false
  63. for (var i = 0; i < keys.length; i++) {
  64. // console.error(keys[i])
  65. if (list.indexOf(keys[i]) != -1) {
  66. over = true;
  67. // return over;
  68. }
  69. }
  70. return over;
  71. },
  72. setJson: function(key, value) {
  73. let jsonString = JSON.stringify(value);
  74. try {
  75. uni.setStorageSync(key, jsonString);
  76. } catch (e) {
  77. // error
  78. }
  79. },
  80. setData: function(key, value) {
  81. try {
  82. uni.setStorageSync(key, value);
  83. } catch (e) {
  84. // error
  85. }
  86. },
  87. getData: function(key) {
  88. try {
  89. const value = uni.getStorageSync(key);
  90. if (value) {
  91. return value;
  92. }
  93. } catch (e) {
  94. // error
  95. }
  96. },
  97. getJson: function(key) {
  98. try {
  99. const value = uni.getStorageSync(key);
  100. if (value) {
  101. return JSON.parse(value);
  102. }
  103. } catch (e) {
  104. // error
  105. }
  106. },
  107. clear: function() {
  108. uni.clearStorage();
  109. },
  110. get: function(key) { //获取队列里面全部的数据
  111. let data = this.getJson(key);
  112. if (data instanceof Array) {
  113. return data;
  114. }
  115. return [];
  116. },
  117. insert: function(param) { //队列插入数据
  118. param.capacityNum = param.capacityNum || 100; //队列容量 默认队列中超过100条数据,自动删除尾部
  119. let data = this.getJson(param.key);
  120. if (data instanceof Array) {
  121. if (data.length > param.capacityNum) {
  122. let total = data.length - param.capacityNum;
  123. for (let i = 0; i < total; i++) {
  124. data.pop();
  125. }
  126. }
  127. data.unshift(param.value);
  128. } else {
  129. data = [];
  130. data.push(param.value);
  131. }
  132. this.setJson(param.key, data);
  133. },
  134. removeItem: function(key, itemIds) { //提供itemIds数组 批量删除队列中的某项数据
  135. let data = this.getJson(key);
  136. if (data instanceof Array) {
  137. for (let i = 0; i < itemIds.length; i++) {
  138. for (let p = 0; p < data.length; p++) {
  139. if (itemIds[i] === data[p].itemid) {
  140. data.splice(p, 1);
  141. break;
  142. }
  143. }
  144. }
  145. this.setJson(key, data);
  146. }
  147. },
  148. isExist: function(key, itemId) { //检测某条数据在队列中是否存在
  149. let data = this.getJson(key);
  150. if (data instanceof Array) {
  151. for (let p = 0; p < data.length; p++) {
  152. if (itemId === data[p].itemid) {
  153. return true;
  154. }
  155. }
  156. }
  157. return false;
  158. },
  159. isExistPdd: function(key, itemId) { //检测某条数据在队列中是否存在
  160. let data = this.getJson(key);
  161. if (data instanceof Array) {
  162. for (let p = 0; p < data.length; p++) {
  163. if (itemId === data[p].goodsId) {
  164. return true;
  165. }
  166. }
  167. }
  168. return false;
  169. },
  170. isExistJd: function(key, itemId) { //检测某条数据在队列中是否存在
  171. let data = this.getJson(key);
  172. if (data instanceof Array) {
  173. for (let p = 0; p < data.length; p++) {
  174. if (itemId === data[p].skuId) {
  175. return true;
  176. }
  177. }
  178. }
  179. return false;
  180. },
  181. remove: function(key) { //删除某条队列
  182. try {
  183. uni.removeStorageSync(key);
  184. //localStorage.removeItem(key)
  185. } catch (e) {
  186. // error
  187. }
  188. },
  189. getCount: function(key) { //获取队列中全部数据数量
  190. let data = this.getJson(key);
  191. if (data instanceof Array) {
  192. return data.length;
  193. }
  194. return 0;
  195. },
  196. uploadFile:function(path,callback){
  197. const uploadTask=uni.uploadFile({ // 上传接口
  198. url: configdata.APIHOST1 + '/alioss/upload', //真实的接口地址
  199. filePath: path,
  200. name: 'file',
  201. success: (uploadFileRes) => {
  202. let content = JSON.parse(uploadFileRes.data).data;
  203. uni.hideLoading();
  204. callback(content)
  205. },fail:(err)=>{
  206. callback(false)
  207. console.log(err)
  208. }
  209. });
  210. uploadTask.onProgressUpdate((res) => {
  211. uni.showLoading({
  212. title: '上传进度' + res.progress+'%',
  213. })
  214. if(res.progress>=100){
  215. uni.hideLoading()
  216. }
  217. })
  218. },
  219. array_column:function (arr, column_key, index_key = null) {
  220. if (index_key === null) {
  221. return arr.map(item => item[column_key]);
  222. }
  223. return arr.reduce((result, item) => {
  224. result[item[index_key]] = item[column_key];
  225. return result;
  226. }, {});
  227. },
  228. isCurrentMonth:function (date) {
  229. const now = new Date();
  230. return now.getFullYear() === date.getFullYear() &&
  231. now.getMonth() === date.getMonth();
  232. },
  233. getHighestEducation:function (educations) {
  234. // 定义学历等级映射(从低到高)
  235. const educationLevels = {
  236. '小学': 1,
  237. '初中': 2,
  238. '高中': 3,
  239. '中专': 4,
  240. '大专': 5,
  241. '本科': 6,
  242. '硕士': 7,
  243. '博士': 8,
  244. '博士后': 9
  245. };
  246. let highestEducation = null;
  247. let highestLevel = -1;
  248. educations.forEach(edu => {
  249. const level = educationLevels[edu.degree] || 0;
  250. if (level > highestLevel) {
  251. highestLevel = level;
  252. highestEducation = edu.degree;
  253. }
  254. });
  255. return highestEducation;
  256. }
  257. };