queue.js 17 KB

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