queue.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /**
  2. *
  3. * @author maxd
  4. * @date 2019.8.1
  5. */
  6. import configdata from './config'
  7. // #ifdef APP-PLUS
  8. import permision from "../js_sdk/wa-permission/permission.js"
  9. // #endif
  10. module.exports = {
  11. //微信的appId
  12. getWxAppid() {
  13. return 'wxd0bec3a917085e78'
  14. },
  15. //全局邀请码
  16. getInvitation() {
  17. return uni.getStorageSync("publicRelation")
  18. },
  19. //获取APP下载地址
  20. getAppDownUrl() {
  21. return uni.getStorageSync("appurl")
  22. },
  23. //全局域名 部分html中需要单独替换 需要修改config中的网络请求域名
  24. publicYuMing() {
  25. return configdata.h5Url
  26. },
  27. logout() {
  28. this.remove("token");
  29. this.remove("userId");
  30. this.remove("mobile");
  31. this.remove("openid");
  32. this.remove("nickName");
  33. this.remove("relation");
  34. this.remove("image_url");
  35. this.remove("relation_id");
  36. this.remove("isInvitation");
  37. this.remove("member");
  38. },
  39. loginClear() {
  40. this.remove("token");
  41. this.remove("userId");
  42. this.remove("mobile");
  43. this.remove("nickName");
  44. this.remove("image_url");
  45. this.remove("relation_id");
  46. this.remove("isInvitation");
  47. this.remove("member");
  48. },
  49. showLoading(title) {
  50. uni.showLoading({
  51. title: title
  52. });
  53. },
  54. showToast(title) {
  55. uni.showToast({
  56. title: title,
  57. mask: false,
  58. duration: 2000,
  59. icon: "none"
  60. });
  61. },
  62. getChatSearchKeys: function(key) {
  63. let list = uni.getStorageSync("chatSearchKeys");
  64. let keys = key.replace(/\s*/g, "")
  65. let over = false
  66. for (var i = 0; i < keys.length; i++) {
  67. // console.error(keys[i])
  68. if (list.indexOf(keys[i]) != -1) {
  69. over = true;
  70. // return over;
  71. }
  72. }
  73. return over;
  74. },
  75. setJson: function(key, value) {
  76. let jsonString = JSON.stringify(value);
  77. try {
  78. uni.setStorageSync(key, jsonString);
  79. } catch (e) {
  80. // error
  81. }
  82. },
  83. setData: function(key, value) {
  84. try {
  85. uni.setStorageSync(key, value);
  86. } catch (e) {
  87. // error
  88. }
  89. },
  90. getData: function(key) {
  91. try {
  92. const value = uni.getStorageSync(key);
  93. if (value) {
  94. return value;
  95. }
  96. } catch (e) {
  97. // error
  98. }
  99. },
  100. getJson: function(key) {
  101. try {
  102. const value = uni.getStorageSync(key);
  103. if (value) {
  104. return JSON.parse(value);
  105. }
  106. } catch (e) {
  107. // error
  108. }
  109. },
  110. clear: function() {
  111. uni.clearStorage();
  112. },
  113. get: function(key) { //获取队列里面全部的数据
  114. let data = this.getJson(key);
  115. if (data instanceof Array) {
  116. return data;
  117. }
  118. return [];
  119. },
  120. insert: function(param) { //队列插入数据
  121. param.capacityNum = param.capacityNum || 100; //队列容量 默认队列中超过100条数据,自动删除尾部
  122. let data = this.getJson(param.key);
  123. if (data instanceof Array) {
  124. if (data.length > param.capacityNum) {
  125. let total = data.length - param.capacityNum;
  126. for (let i = 0; i < total; i++) {
  127. data.pop();
  128. }
  129. }
  130. data.unshift(param.value);
  131. } else {
  132. data = [];
  133. data.push(param.value);
  134. }
  135. this.setJson(param.key, data);
  136. },
  137. removeItem: function(key, itemIds) { //提供itemIds数组 批量删除队列中的某项数据
  138. let data = this.getJson(key);
  139. if (data instanceof Array) {
  140. for (let i = 0; i < itemIds.length; i++) {
  141. for (let p = 0; p < data.length; p++) {
  142. if (itemIds[i] === data[p].itemid) {
  143. data.splice(p, 1);
  144. break;
  145. }
  146. }
  147. }
  148. this.setJson(key, data);
  149. }
  150. },
  151. isExist: function(key, itemId) { //检测某条数据在队列中是否存在
  152. let data = this.getJson(key);
  153. if (data instanceof Array) {
  154. for (let p = 0; p < data.length; p++) {
  155. if (itemId === data[p].itemid) {
  156. return true;
  157. }
  158. }
  159. }
  160. return false;
  161. },
  162. isExistPdd: function(key, itemId) { //检测某条数据在队列中是否存在
  163. let data = this.getJson(key);
  164. if (data instanceof Array) {
  165. for (let p = 0; p < data.length; p++) {
  166. if (itemId === data[p].goodsId) {
  167. return true;
  168. }
  169. }
  170. }
  171. return false;
  172. },
  173. isExistJd: function(key, itemId) { //检测某条数据在队列中是否存在
  174. let data = this.getJson(key);
  175. if (data instanceof Array) {
  176. for (let p = 0; p < data.length; p++) {
  177. if (itemId === data[p].skuId) {
  178. return true;
  179. }
  180. }
  181. }
  182. return false;
  183. },
  184. remove: function(key) { //删除某条队列
  185. try {
  186. uni.removeStorageSync(key);
  187. //localStorage.removeItem(key)
  188. } catch (e) {
  189. // error
  190. }
  191. },
  192. getCount: function(key) { //获取队列中全部数据数量
  193. let data = this.getJson(key);
  194. if (data instanceof Array) {
  195. return data.length;
  196. }
  197. return 0;
  198. },
  199. uploadFile: function(path, callback) {
  200. const uploadTask = uni.uploadFile({ // 上传接口
  201. url: configdata.APIHOST1 + '/alioss/upload', //真实的接口地址
  202. filePath: path,
  203. name: 'file',
  204. success: (uploadFileRes) => {
  205. let content = JSON.parse(uploadFileRes.data).data;
  206. uni.hideLoading();
  207. callback(content)
  208. },
  209. fail: (err) => {
  210. callback(false)
  211. console.log(err)
  212. }
  213. });
  214. uploadTask.onProgressUpdate((res) => {
  215. uni.showLoading({
  216. title: '上传进度' + res.progress + '%',
  217. })
  218. if (res.progress >= 100) {
  219. uni.hideLoading()
  220. }
  221. })
  222. },
  223. array_column: function(arr, column_key, index_key = null) {
  224. if (index_key === null) {
  225. return arr.map(item => item[column_key]);
  226. }
  227. return arr.reduce((result, item) => {
  228. result[item[index_key]] = item[column_key];
  229. return result;
  230. }, {});
  231. },
  232. isCurrentMonth: function(date) {
  233. const now = new Date();
  234. return now.getFullYear() === date.getFullYear() &&
  235. now.getMonth() === date.getMonth();
  236. },
  237. getHighestEducation: function(educations) {
  238. // 定义学历等级映射(从低到高)
  239. const educationLevels = {
  240. '小学': 1,
  241. '初中': 2,
  242. '高中': 3,
  243. '中专': 4,
  244. '大专': 5,
  245. '本科': 6,
  246. '硕士': 7,
  247. '博士': 8,
  248. '博士后': 9
  249. };
  250. let highestEducation = null;
  251. let highestLevel = -1;
  252. educations.forEach(edu => {
  253. const level = educationLevels[edu.degree] || 0;
  254. if (level > highestLevel) {
  255. highestLevel = level;
  256. highestEducation = edu.degree;
  257. }
  258. });
  259. return highestEducation;
  260. },
  261. //职业状态
  262. resumesStatus() {
  263. return [{
  264. value: '0',
  265. text: '离职-随时到岗',
  266. recommended: true
  267. },
  268. {
  269. value: '1',
  270. text: '在职-月内到岗',
  271. recommended: true
  272. },
  273. {
  274. value: '2',
  275. text: '在职-考虑机会',
  276. recommended: false
  277. },
  278. {
  279. value: '3',
  280. text: '在职-暂不考虑',
  281. recommended: false
  282. }
  283. ]
  284. },
  285. appConfirm: function(content = '请确认您的操作?', callback, title = '操作提示', button = ["继续", "取消"]) {
  286. // #ifndef APP-PLUS
  287. uni.showModal({
  288. title: title,
  289. content: content,
  290. success: function(res) {
  291. if (res.confirm) {
  292. callback(true)
  293. } else
  294. callback(false)
  295. }
  296. });
  297. return
  298. //#endif
  299. // #ifdef APP-PLUS
  300. plus.nativeUI.confirm(content, function(e) {
  301. if (e.index == 0)
  302. callback(true)
  303. else
  304. callback(false)
  305. }, title, button);
  306. //#endif
  307. },
  308. isDateExpired: function(targetDate) {
  309. const currentTimestamp = new Date().getTime();
  310. const targetTimestamp = new Date(targetDate).getTime();
  311. const rest = targetTimestamp < currentTimestamp
  312. if (rest)
  313. return [true, 0]
  314. // 计算毫秒差
  315. const diffInMs = targetTimestamp - currentTimestamp;
  316. // 转换为小时(向上取整确保显示完整小时)
  317. const hours = Math.ceil(diffInMs / (1000 * 60 * 60));
  318. return [rest, hours > 0 ? hours : 0]; // 返回非负值
  319. },
  320. convert12to24: function(time12h) {
  321. // 使用正则表达式匹配12小时制格式
  322. const regex = /^(0?[1-9]|1[0-2]):([0-5]\d)\s?(AM|PM)$/i;
  323. const match = time12h.match(regex);
  324. if (!match) {
  325. throw new Error('无效的时间格式,请使用如 "2:00 PM" 或 "02:00 PM" 的格式');
  326. }
  327. let hour = parseInt(match[1], 10);
  328. const minute = match[2];
  329. const period = match[3].toUpperCase();
  330. // 处理AM/PM转换逻辑
  331. if (period === 'PM' && hour !== 12) {
  332. hour += 12;
  333. } else if (period === 'AM' && hour === 12) {
  334. hour = 0;
  335. }
  336. // 格式化为两位数
  337. const hour24 = hour.toString().padStart(2, '0');
  338. return `${hour24}:${minute}`;
  339. },
  340. changeTabbar: function(res) {
  341. setTimeout(() => {
  342. if (res == 1) {
  343. uni.setTabBarItem({
  344. index: 0,
  345. text: '首页',
  346. iconPath: "/static/tabbar/Home.png",
  347. selectedIconPath: "/static/tabbar/Iconly_Bold_Home.png",
  348. })
  349. uni.setTabBarItem({
  350. index: 1,
  351. text: '急聘',
  352. "pagePath": "/pages/index/game/gameList",
  353. "iconPath": "/static/tabbar/jipin.png",
  354. "selectedIconPath": "/static/tabbar/ACjipin.png",
  355. })
  356. } else {
  357. uni.setTabBarItem({
  358. index: 0,
  359. text: '牛人',
  360. iconPath: "/static/tabbar/niu.png",
  361. selectedIconPath: "/static/tabbar/niu2.png",
  362. })
  363. uni.setTabBarItem({
  364. index: 1,
  365. "pagePath": "/pages/talentSearch/index",
  366. "iconPath": "/static/tabbar/Hrsearch.png",
  367. "selectedIconPath": "/static/tabbar/ACsearch.png",
  368. "text": "搜索"
  369. })
  370. }
  371. // 可以在这里添加 tabbar 更新后的后续操作
  372. console.log('tabbar 更新完成');
  373. }, 100);
  374. },
  375. // 核心年龄计算函数
  376. calculateAgeFromBirthday: function(birthday) {
  377. const birthDate = new Date(birthday);
  378. const currentDate = new Date();
  379. // 验证日期有效性
  380. if (isNaN(birthDate.getTime())) {
  381. throw new Error('无效的生日日期');
  382. }
  383. if (birthDate > currentDate) {
  384. throw new Error('生日日期不能晚于当前日期');
  385. }
  386. let years = currentDate.getFullYear() - birthDate.getFullYear();
  387. let months = currentDate.getMonth() - birthDate.getMonth();
  388. let days = currentDate.getDate() - birthDate.getDate();
  389. // 处理天数负数情况
  390. if (days < 0) {
  391. months--;
  392. // 获取上个月的天数
  393. const lastMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0);
  394. days += lastMonth.getDate();
  395. }
  396. // 处理月份负数情况
  397. if (months < 0) {
  398. years--;
  399. months += 12;
  400. }
  401. return years;
  402. },
  403. // 筛选求职列表
  404. getFilterData: function() {
  405. const condition = {
  406. education: '', //学历
  407. experience: '', //经验
  408. industry: '', //行业
  409. salaryRange: '', //薪资
  410. companyPeople: '' //公司规模
  411. }
  412. //获取选中的筛选条件
  413. if (uni.getStorageSync('filter') && (uni.getStorageSync('filter')).length > 0) {
  414. let filter = uni.getStorageSync('filter')
  415. filter.map(item => {
  416. let arr = []
  417. item.list.map(ite => {
  418. if (ite.value != '不限') {
  419. arr.push(ite.value)
  420. }
  421. })
  422. switch (item.name) {
  423. case '学历要求':
  424. condition.education = arr.join(',')
  425. break;
  426. case '薪资范围(单选)':
  427. condition.salaryRange = arr.join(',')
  428. break;
  429. case '经验要求':
  430. condition.experience = arr.join(',')
  431. break;
  432. case '公司规模':
  433. condition.companyPeople = arr.join(',')
  434. break;
  435. case '行业':
  436. condition.industry = arr.join(',')
  437. break;
  438. }
  439. })
  440. // console.log(filter)
  441. }
  442. return condition
  443. },
  444. //APP获取手机权限鉴权
  445. // APP获取手机权限鉴权(优化版,兼容全权限+多系统)
  446. async checkPermission(permission, tip, that,perpop='permission') {
  447. // 权限映射配置
  448. let permisionID = '';
  449. let permisionIosID = '';
  450. if (permission == 'location') {
  451. permisionID = 'android.permission.ACCESS_FINE_LOCATION';
  452. permisionIosID = 'location';
  453. }
  454. if (permission == 'camera') {
  455. permisionID = 'android.permission.CAMERA,android.permission.READ_EXTERNAL_STORAGE';
  456. permisionIosID = 'camera,photoLibrary';
  457. }
  458. if (permission == 'microphone') {
  459. permisionID = 'android.permission.RECORD_AUDIO';
  460. permisionIosID = 'record';
  461. }
  462. return new Promise(async (resolve) => {
  463. // #ifdef H5
  464. resolve(true);
  465. return;
  466. // #endif
  467. // 特殊处理:相机权限在非iOS平台显示自定义弹窗
  468. if (uni.getSystemInfoSync().platform != 'ios') {
  469. switch(perpop){
  470. case 'permission':
  471. that.$refs.permission.open();
  472. break
  473. case 'microphonePermission':
  474. that.$refs.microphonePermission.open();
  475. break
  476. case 'locationPermission':
  477. that.$refs.locationPermission.open();
  478. break
  479. default:
  480. console.warn('未知权限类型:', perpop);
  481. }
  482. }
  483. // Android 平台处理
  484. if (uni.getSystemInfoSync().platform === 'android') {
  485. if (permisionID == '') {
  486. resolve(true);
  487. return;
  488. }
  489. try {
  490. const result = await permision.requestAndroidPermission(permisionID);
  491. console.log(result);
  492. switch(perpop){
  493. case 'permission':
  494. that.$refs.permission.close();
  495. break
  496. case 'microphonePermission':
  497. that.$refs.microphonePermission.close();
  498. break
  499. case 'locationPermission':
  500. that.$refs.locationPermission.close();
  501. break
  502. default:
  503. console.warn('未知权限类型:', perpop);
  504. }
  505. if (result == 1) {
  506. console.log("已获得授权");
  507. resolve(true);
  508. } else if (result == 0) {
  509. console.log("未获得授权");
  510. resolve(false);
  511. } else {
  512. console.log("权限被拒绝");
  513. // 显示确认对话框
  514. this.appConfirm("权限被拒绝," + tip, function(res) {
  515. if (res) {
  516. uni.openAppAuthorizeSetting();
  517. }
  518. resolve(false);
  519. });
  520. }
  521. } catch (error) {
  522. console.error("权限请求失败:", error);
  523. resolve(false);
  524. }
  525. }
  526. // iOS 平台处理
  527. else {
  528. if (permisionIosID == '') {
  529. resolve(true);
  530. return;
  531. }
  532. const iosPermissions = permisionIosID.split(',');
  533. let allGranted = true;
  534. for (let i = 0; i < iosPermissions.length; i++) {
  535. const currentPermission = iosPermissions[i];
  536. const result = permision.judgeIosPermission(currentPermission);
  537. console.log(`iOS权限 ${currentPermission}:`, result);
  538. if (!result) {
  539. allGranted = false;
  540. console.log(`未获得 ${currentPermission} 授权`);
  541. // 特殊处理相机和相册权限
  542. /* if (currentPermission == 'camera' || currentPermission == 'photoLibrary') {
  543. that.$refs.camera?.open();
  544. } */
  545. } else {
  546. console.log(`已获得 ${currentPermission} 授权`);
  547. }
  548. }
  549. resolve(allGranted);
  550. }
  551. });
  552. }
  553. };