queue.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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. },
  206. fail: (err) => {
  207. callback(false)
  208. console.log(err)
  209. }
  210. });
  211. uploadTask.onProgressUpdate((res) => {
  212. uni.showLoading({
  213. title: '上传进度' + res.progress + '%',
  214. })
  215. if (res.progress >= 100) {
  216. uni.hideLoading()
  217. }
  218. })
  219. },
  220. array_column: function(arr, column_key, index_key = null) {
  221. if (index_key === null) {
  222. return arr.map(item => item[column_key]);
  223. }
  224. return arr.reduce((result, item) => {
  225. result[item[index_key]] = item[column_key];
  226. return result;
  227. }, {});
  228. },
  229. isCurrentMonth: function(date) {
  230. const now = new Date();
  231. return now.getFullYear() === date.getFullYear() &&
  232. now.getMonth() === date.getMonth();
  233. },
  234. getHighestEducation: function(educations) {
  235. // 定义学历等级映射(从低到高)
  236. const educationLevels = {
  237. '小学': 1,
  238. '初中': 2,
  239. '高中': 3,
  240. '中专': 4,
  241. '大专': 5,
  242. '本科': 6,
  243. '硕士': 7,
  244. '博士': 8,
  245. '博士后': 9
  246. };
  247. let highestEducation = null;
  248. let highestLevel = -1;
  249. educations.forEach(edu => {
  250. const level = educationLevels[edu.degree] || 0;
  251. if (level > highestLevel) {
  252. highestLevel = level;
  253. highestEducation = edu.degree;
  254. }
  255. });
  256. return highestEducation;
  257. },
  258. //职业状态
  259. resumesStatus() {
  260. return [{
  261. value: '0',
  262. text: '离职-随时到岗',
  263. recommended: true
  264. },
  265. {
  266. value: '1',
  267. text: '在职-月内到岗',
  268. recommended: true
  269. },
  270. {
  271. value: '2',
  272. text: '在职-考虑机会',
  273. recommended: false
  274. },
  275. {
  276. value: '3',
  277. text: '在职-暂不考虑',
  278. recommended: false
  279. }
  280. ]
  281. },
  282. appConfirm: function(content = '请确认您的操作?', callback, title = '操作提示', button = ["继续", "取消"]) {
  283. // #ifndef APP-PLUS
  284. uni.showModal({
  285. title: title,
  286. content: content,
  287. success: function(res) {
  288. if (res.confirm) {
  289. callback(true)
  290. } else
  291. callback(false)
  292. }
  293. });
  294. return
  295. //#endif
  296. // #ifdef APP-PLUS
  297. plus.nativeUI.confirm(content, function(e) {
  298. if (e.index == 0)
  299. callback(true)
  300. else
  301. callback(false)
  302. }, title, button);
  303. //#endif
  304. },
  305. isDateExpired: function(targetDate) {
  306. const currentTimestamp = new Date().getTime();
  307. const targetTimestamp = new Date(targetDate).getTime();
  308. const rest = targetTimestamp < currentTimestamp
  309. if (rest)
  310. return [true, 0]
  311. // 计算毫秒差
  312. const diffInMs = targetTimestamp - currentTimestamp;
  313. // 转换为小时(向上取整确保显示完整小时)
  314. const hours = Math.ceil(diffInMs / (1000 * 60 * 60));
  315. return [rest, hours > 0 ? hours : 0]; // 返回非负值
  316. },
  317. convert12to24: function(time12h) {
  318. // 使用正则表达式匹配12小时制格式
  319. const regex = /^(0?[1-9]|1[0-2]):([0-5]\d)\s?(AM|PM)$/i;
  320. const match = time12h.match(regex);
  321. if (!match) {
  322. throw new Error('无效的时间格式,请使用如 "2:00 PM" 或 "02:00 PM" 的格式');
  323. }
  324. let hour = parseInt(match[1], 10);
  325. const minute = match[2];
  326. const period = match[3].toUpperCase();
  327. // 处理AM/PM转换逻辑
  328. if (period === 'PM' && hour !== 12) {
  329. hour += 12;
  330. } else if (period === 'AM' && hour === 12) {
  331. hour = 0;
  332. }
  333. // 格式化为两位数
  334. const hour24 = hour.toString().padStart(2, '0');
  335. return `${hour24}:${minute}`;
  336. },
  337. changeTabbar: function(res) {
  338. setTimeout(() => {
  339. if (res == 1) {
  340. uni.setTabBarItem({
  341. index: 0,
  342. text: '首页',
  343. iconPath: "/static/tabbar/Home.png",
  344. selectedIconPath: "/static/tabbar/Iconly_Bold_Home.png",
  345. })
  346. uni.setTabBarItem({
  347. index: 1,
  348. text: '急聘',
  349. "pagePath": "/pages/index/game/gameList",
  350. "iconPath": "/static/tabbar/jipin.png",
  351. "selectedIconPath": "/static/tabbar/ACjipin.png",
  352. })
  353. } else {
  354. uni.setTabBarItem({
  355. index: 0,
  356. text: '牛人',
  357. iconPath: "/static/tabbar/niu.png",
  358. selectedIconPath: "/static/tabbar/niu2.png",
  359. })
  360. uni.setTabBarItem({
  361. index: 1,
  362. "pagePath": "/pages/talentSearch/index",
  363. "iconPath": "/static/tabbar/Hrsearch.png",
  364. "selectedIconPath": "/static/tabbar/ACsearch.png",
  365. "text": "搜索"
  366. })
  367. }
  368. // 可以在这里添加 tabbar 更新后的后续操作
  369. console.log('tabbar 更新完成');
  370. }, 100);
  371. },
  372. // 核心年龄计算函数
  373. calculateAgeFromBirthday: function(birthday) {
  374. const birthDate = new Date(birthday);
  375. const currentDate = new Date();
  376. // 验证日期有效性
  377. if (isNaN(birthDate.getTime())) {
  378. throw new Error('无效的生日日期');
  379. }
  380. if (birthDate > currentDate) {
  381. throw new Error('生日日期不能晚于当前日期');
  382. }
  383. let years = currentDate.getFullYear() - birthDate.getFullYear();
  384. let months = currentDate.getMonth() - birthDate.getMonth();
  385. let days = currentDate.getDate() - birthDate.getDate();
  386. // 处理天数负数情况
  387. if (days < 0) {
  388. months--;
  389. // 获取上个月的天数
  390. const lastMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0);
  391. days += lastMonth.getDate();
  392. }
  393. // 处理月份负数情况
  394. if (months < 0) {
  395. years--;
  396. months += 12;
  397. }
  398. return years;
  399. },
  400. // 筛选求职列表
  401. getFilterData: function() {
  402. const condition = {
  403. education: '', //学历
  404. experience: '', //经验
  405. industry: '', //行业
  406. salaryRange: '', //薪资
  407. companyPeople: '' //公司规模
  408. }
  409. //获取选中的筛选条件
  410. if (uni.getStorageSync('filter') && (uni.getStorageSync('filter')).length > 0) {
  411. let filter = uni.getStorageSync('filter')
  412. filter.map(item => {
  413. let arr = []
  414. item.list.map(ite => {
  415. if (ite.value != '不限') {
  416. arr.push(ite.value)
  417. }
  418. })
  419. switch (item.name) {
  420. case '学历要求':
  421. condition.education = arr.join(',')
  422. break;
  423. case '薪资范围(单选)':
  424. condition.salaryRange = arr.join(',')
  425. break;
  426. case '经验要求':
  427. condition.experience = arr.join(',')
  428. break;
  429. case '公司规模':
  430. condition.companyPeople = arr.join(',')
  431. break;
  432. case '行业':
  433. condition.industry = arr.join(',')
  434. break;
  435. }
  436. })
  437. // console.log(filter)
  438. }
  439. return condition
  440. },
  441. //APP获取手机权限鉴权
  442. // APP获取手机权限鉴权(优化版,兼容全权限+多系统)
  443. checkPermission(permission, tip) {
  444. return new Promise((resolve) => {
  445. const permisionObj = uni.getAppAuthorizeSetting && uni.getAppAuthorizeSetting();
  446. if (!permisionObj || !permisionObj.getSetting) {
  447. console.log('当前环境不支持 getAppAuthorizeSetting');
  448. resolve(true); // 默认放行
  449. return;
  450. }
  451. const system = uni.getSystemInfoSync().platform;
  452. let realScope = permission;
  453. const scopeMap = {
  454. 'microphone': 'microphone',
  455. 'camera': 'camera',
  456. 'location': 'scope.userLocation',
  457. 'albumRead': system === 'ios' ? 'photos' : 'storage',
  458. 'albumWrite': system === 'ios' ? 'writePhotosAlbum' : 'storage',
  459. };
  460. if (permission === 'album') realScope = scopeMap.albumRead;
  461. else if (permission === 'albumWrite') realScope = scopeMap.albumWrite;
  462. else if (scopeMap[permission]) realScope = scopeMap[permission];
  463. console.log('准备检测权限:', realScope);
  464. permisionObj.getSetting({
  465. success: (res) => {
  466. console.log('权限状态', res.authSetting);
  467. const authStatus = res.authSetting[realScope];
  468. if (authStatus === true) {
  469. resolve(true);
  470. } else if (authStatus === false) {
  471. uni.showModal({
  472. title: '权限不足',
  473. content: `${tip},请前往设置开启权限`,
  474. confirmText: '去设置',
  475. cancelText: '取消',
  476. success: (modalRes) => {
  477. if (modalRes.confirm) {
  478. permisionObj.openAppAuthorizeSetting({
  479. success: () => resolve(false),
  480. fail: () => resolve(false)
  481. });
  482. } else {
  483. resolve(false);
  484. }
  485. }
  486. });
  487. } else {
  488. permisionObj.authorize({
  489. scope: realScope,
  490. success: () => resolve(true),
  491. fail: (err) => {
  492. console.log('权限授权失败', err);
  493. resolve(false);
  494. }
  495. });
  496. }
  497. },
  498. fail: (err) => {
  499. console.log('getSetting失败', err);
  500. resolve(false);
  501. }
  502. });
  503. });
  504. }
  505. };