queue.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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 configdata.h5Url
  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. //职业状态
  258. resumesStatus(){
  259. return [{
  260. value: '0',
  261. text: '离职-随时到岗',
  262. recommended: true
  263. },
  264. {
  265. value: '1',
  266. text: '在职-月内到岗',
  267. recommended: true
  268. },
  269. {
  270. value: '2',
  271. text: '在职-考虑机会',
  272. recommended: false
  273. },
  274. {
  275. value: '3',
  276. text: '在职-暂不考虑',
  277. recommended: false
  278. }
  279. ]
  280. },
  281. appConfirm:function(content='请确认您的操作?',callback,title='操作提示',button=["继续","取消"]){
  282. // #ifndef APP-PLUS
  283. uni.showModal({
  284. title: title,
  285. content: content,
  286. success: function(res) {
  287. if (res.confirm) {
  288. callback(true)
  289. }else
  290. callback(false)
  291. }
  292. });
  293. return
  294. //#endif
  295. // #ifdef APP-PLUS
  296. plus.nativeUI.confirm(content, function(e){
  297. if(e.index==0)
  298. callback(true)
  299. else
  300. callback(false)
  301. },title,button);
  302. //#endif
  303. },
  304. isDateExpired:function (targetDate) {
  305. const currentTimestamp = new Date().getTime();
  306. const targetTimestamp = new Date(targetDate).getTime();
  307. const rest=targetTimestamp < currentTimestamp
  308. if(rest)
  309. return [true,0]
  310. // 计算毫秒差
  311. const diffInMs = targetTimestamp -currentTimestamp;
  312. // 转换为小时(向上取整确保显示完整小时)
  313. const hours = Math.ceil(diffInMs / (1000 * 60 * 60));
  314. return [rest,hours > 0 ? hours : 0]; // 返回非负值
  315. },
  316. convert12to24:function (time12h) {
  317. // 使用正则表达式匹配12小时制格式
  318. const regex = /^(0?[1-9]|1[0-2]):([0-5]\d)\s?(AM|PM)$/i;
  319. const match = time12h.match(regex);
  320. if (!match) {
  321. throw new Error('无效的时间格式,请使用如 "2:00 PM" 或 "02:00 PM" 的格式');
  322. }
  323. let hour = parseInt(match[1], 10);
  324. const minute = match[2];
  325. const period = match[3].toUpperCase();
  326. // 处理AM/PM转换逻辑
  327. if (period === 'PM' && hour !== 12) {
  328. hour += 12;
  329. } else if (period === 'AM' && hour === 12) {
  330. hour = 0;
  331. }
  332. // 格式化为两位数
  333. const hour24 = hour.toString().padStart(2, '0');
  334. return `${hour24}:${minute}`;
  335. },
  336. changeTabbar:function(res){
  337. setTimeout(() => {
  338. if(res==1){
  339. uni.setTabBarItem({
  340. index: 0,
  341. text: '首页',
  342. iconPath: "/static/tabbar/Home.png",
  343. selectedIconPath: "/static/tabbar/Iconly_Bold_Home.png",
  344. })
  345. uni.setTabBarItem({
  346. index: 1,
  347. text: '急聘',
  348. "pagePath": "/pages/index/game/gameList",
  349. "iconPath": "/static/tabbar/jipin.png",
  350. "selectedIconPath": "/static/tabbar/ACjipin.png",
  351. })
  352. }else{
  353. uni.setTabBarItem({
  354. index: 0,
  355. text: '牛人',
  356. iconPath: "/static/tabbar/niu.png",
  357. selectedIconPath: "/static/tabbar/niu2.png",
  358. })
  359. uni.setTabBarItem({
  360. index: 1,
  361. "pagePath": "/pages/talentSearch/index",
  362. "iconPath": "/static/tabbar/Hrsearch.png",
  363. "selectedIconPath": "/static/tabbar/ACsearch.png",
  364. "text": "搜索"
  365. })
  366. }
  367. // 可以在这里添加 tabbar 更新后的后续操作
  368. console.log('tabbar 更新完成');
  369. },100);
  370. },
  371. // 核心年龄计算函数
  372. calculateAgeFromBirthday:function(birthday) {
  373. const birthDate = new Date(birthday);
  374. const currentDate = new Date();
  375. // 验证日期有效性
  376. if (isNaN(birthDate.getTime())) {
  377. throw new Error('无效的生日日期');
  378. }
  379. if (birthDate > currentDate) {
  380. throw new Error('生日日期不能晚于当前日期');
  381. }
  382. let years = currentDate.getFullYear() - birthDate.getFullYear();
  383. let months = currentDate.getMonth() - birthDate.getMonth();
  384. let days = currentDate.getDate() - birthDate.getDate();
  385. // 处理天数负数情况
  386. if (days < 0) {
  387. months--;
  388. // 获取上个月的天数
  389. const lastMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0);
  390. days += lastMonth.getDate();
  391. }
  392. // 处理月份负数情况
  393. if (months < 0) {
  394. years--;
  395. months += 12;
  396. }
  397. return years;
  398. }
  399. };