queue.js 16 KB

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