queue.js 15 KB

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