queue.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. value: '4',
  297. text: '实习',
  298. recommended: false
  299. }
  300. ]
  301. },
  302. appConfirm: function(content = '请确认您的操作?', callback, title = '操作提示', button = ["继续", "取消"]) {
  303. // #ifndef APP-PLUS
  304. uni.showModal({
  305. title: title,
  306. content: content,
  307. success: function(res) {
  308. if (res.confirm) {
  309. callback(true)
  310. } else
  311. callback(false)
  312. }
  313. });
  314. return
  315. //#endif
  316. // #ifdef APP-PLUS
  317. plus.nativeUI.confirm(content, function(e) {
  318. if (e.index == 0)
  319. callback(true)
  320. else
  321. callback(false)
  322. }, title, button);
  323. //#endif
  324. },
  325. isDateExpired: function(targetDate) {
  326. const currentTimestamp = new Date().getTime();
  327. const targetTimestamp = new Date(targetDate).getTime();
  328. const rest = targetTimestamp < currentTimestamp
  329. if (rest)
  330. return [true, 0]
  331. // 计算毫秒差
  332. const diffInMs = targetTimestamp - currentTimestamp;
  333. // 转换为小时(向上取整确保显示完整小时)
  334. const hours = Math.ceil(diffInMs / (1000 * 60 * 60));
  335. return [rest, hours > 0 ? hours : 0]; // 返回非负值
  336. },
  337. convert12to24: function(time12h) {
  338. // 使用正则表达式匹配12小时制格式
  339. const regex = /^(0?[1-9]|1[0-2]):([0-5]\d)\s?(AM|PM)$/i;
  340. const match = time12h.match(regex);
  341. if (!match) {
  342. throw new Error('无效的时间格式,请使用如 "2:00 PM" 或 "02:00 PM" 的格式');
  343. }
  344. let hour = parseInt(match[1], 10);
  345. const minute = match[2];
  346. const period = match[3].toUpperCase();
  347. // 处理AM/PM转换逻辑
  348. if (period === 'PM' && hour !== 12) {
  349. hour += 12;
  350. } else if (period === 'AM' && hour === 12) {
  351. hour = 0;
  352. }
  353. // 格式化为两位数
  354. const hour24 = hour.toString().padStart(2, '0');
  355. return `${hour24}:${minute}`;
  356. },
  357. changeTabbar: function(res) {
  358. setTimeout(() => {
  359. if (res == 1) {
  360. uni.setTabBarItem({
  361. index: 0,
  362. text: '首页',
  363. iconPath: "/static/tabbar/Home.png",
  364. selectedIconPath: "/static/tabbar/Iconly_Bold_Home.png",
  365. })
  366. uni.setTabBarItem({
  367. index: 1,
  368. text: '急聘',
  369. pagePath: "/pages/index/game/gameList",
  370. iconPath: "/static/tabbar/jipin.png",
  371. selectedIconPath: "/static/tabbar/ACjipin.png",
  372. })
  373. } else {
  374. uni.setTabBarItem({
  375. index: 0,
  376. text: '牛人',
  377. iconPath: "/static/tabbar/niu.png",
  378. selectedIconPath: "/static/tabbar/niu2.png",
  379. })
  380. uni.setTabBarItem({
  381. index: 1,
  382. pagePath: "/pages/talentSearch/index",
  383. iconPath: "/static/tabbar/Hrsearch.png",
  384. selectedIconPath: "/static/tabbar/ACsearch.png",
  385. text: "搜索"
  386. })
  387. }
  388. // 可以在这里添加 tabbar 更新后的后续操作
  389. console.log('tabbar 更新完成');
  390. }, 100);
  391. },
  392. // 核心年龄计算函数
  393. calculateAgeFromBirthday: function(birthday) {
  394. const birthDate = new Date(birthday);
  395. const currentDate = new Date();
  396. // 验证日期有效性
  397. if (isNaN(birthDate.getTime())) {
  398. throw new Error('无效的生日日期');
  399. }
  400. if (birthDate > currentDate) {
  401. throw new Error('生日日期不能晚于当前日期');
  402. }
  403. let years = currentDate.getFullYear() - birthDate.getFullYear();
  404. let months = currentDate.getMonth() - birthDate.getMonth();
  405. let days = currentDate.getDate() - birthDate.getDate();
  406. // 处理天数负数情况
  407. if (days < 0) {
  408. months--;
  409. // 获取上个月的天数
  410. const lastMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0);
  411. days += lastMonth.getDate();
  412. }
  413. // 处理月份负数情况
  414. if (months < 0) {
  415. years--;
  416. months += 12;
  417. }
  418. return years;
  419. },
  420. // 筛选求职列表
  421. getFilterData: function() {
  422. const condition = {
  423. education: '', //学历
  424. experience: '', //经验
  425. industry: '', //行业
  426. salaryRange: '', //薪资
  427. companyPeople: '' //公司规模
  428. }
  429. //获取选中的筛选条件
  430. if (uni.getStorageSync('filter') && (uni.getStorageSync('filter')).length > 0) {
  431. let filter = uni.getStorageSync('filter')
  432. filter.map(item => {
  433. let arr = []
  434. item.list.map(ite => {
  435. if (ite.value != '不限') {
  436. arr.push(ite.value)
  437. }
  438. })
  439. switch (item.name) {
  440. case '学历要求':
  441. condition.education = arr.join(',')
  442. break;
  443. case '薪资范围(单选)':
  444. condition.salaryRange = arr.join(',')
  445. break;
  446. case '经验要求':
  447. condition.experience = arr.join(',')
  448. break;
  449. case '公司规模':
  450. condition.companyPeople = arr.join(',')
  451. break;
  452. case '行业':
  453. condition.industry = arr.join(',')
  454. break;
  455. }
  456. })
  457. // console.log(filter)
  458. }
  459. return condition
  460. },
  461. //APP获取手机权限鉴权
  462. // APP获取手机权限鉴权(优化版,兼容全权限+多系统)
  463. async checkPermission(permission, tip, that,perpop='permission') {
  464. // 权限映射配置
  465. let permisionID = '';
  466. let permisionIosID = '';
  467. return new Promise(async (resolve) => {
  468. // #ifdef H5
  469. resolve(true);
  470. return;
  471. // #endif
  472. const appAuthorizeSetting = uni.getAppAuthorizeSetting()
  473. if (permission == 'location') {
  474. permisionID = 'android.permission.ACCESS_FINE_LOCATION';
  475. permisionIosID = 'location';
  476. if(appAuthorizeSetting.locationAuthorized=='authorized'){
  477. resolve(true);
  478. return
  479. }
  480. }
  481. if (permission == 'camera') {
  482. permisionID = 'android.permission.CAMERA,android.permission.READ_EXTERNAL_STORAGE';
  483. permisionIosID = 'camera,photoLibrary';
  484. if(appAuthorizeSetting.cameraAuthorized=='authorized'){
  485. resolve(true);
  486. return
  487. }
  488. }
  489. if (permission == 'microphone') {
  490. permisionID = 'android.permission.RECORD_AUDIO';
  491. permisionIosID = 'record';
  492. if(appAuthorizeSetting.microphoneAuthorized=='authorized'){
  493. resolve(true);
  494. return
  495. }
  496. }
  497. // 特殊处理:相机权限在非iOS平台显示自定义弹窗
  498. if (uni.getSystemInfoSync().platform != 'ios') {
  499. switch(perpop){
  500. case 'permission':
  501. that.$refs.permission.open();
  502. break
  503. case 'microphonePermission':
  504. that.$refs.microphonePermission.open();
  505. break
  506. case 'locationPermission':
  507. that.$refs.locationPermission.open();
  508. break
  509. default:
  510. console.warn('未知权限类型:', perpop);
  511. }
  512. }
  513. // Android 平台处理
  514. if (uni.getSystemInfoSync().platform === 'android') {
  515. if (permisionID == '') {
  516. resolve(true);
  517. return;
  518. }
  519. try {
  520. const result = await permision.requestAndroidPermission(permisionID);
  521. console.log(result);
  522. switch(perpop){
  523. case 'permission':
  524. that.$refs.permission.close();
  525. break
  526. case 'microphonePermission':
  527. that.$refs.microphonePermission.close();
  528. break
  529. case 'locationPermission':
  530. that.$refs.locationPermission.close();
  531. break
  532. default:
  533. console.warn('未知权限类型:', perpop);
  534. }
  535. if (result == 1) {
  536. console.log("已获得授权");
  537. resolve(true);
  538. } else if (result == 0) {
  539. console.log("未获得授权");
  540. resolve(false);
  541. } else {
  542. console.log("权限被拒绝");
  543. // 显示确认对话框
  544. this.appConfirm("权限被拒绝," + tip, function(res) {
  545. if (res) {
  546. uni.openAppAuthorizeSetting();
  547. }
  548. resolve(false);
  549. });
  550. }
  551. } catch (error) {
  552. console.error("权限请求失败:", error);
  553. resolve(false);
  554. }
  555. }
  556. // iOS 平台处理
  557. else {
  558. if (permisionIosID == '') {
  559. resolve(true);
  560. return;
  561. }
  562. const iosPermissions = permisionIosID.split(',');
  563. let allGranted = 0;
  564. for (let i = 0; i < iosPermissions.length; i++) {
  565. const currentPermission = iosPermissions[i];
  566. allGranted = permision.judgeIosPermission(currentPermission);
  567. console.log('权限状态码:',allGranted)
  568. }
  569. if(allGranted==0){
  570. console.log('第一次授权')
  571. resolve(true);
  572. }else if(allGranted==3){
  573. console.log('已授权')
  574. resolve(true);
  575. }else{
  576. this.appConfirm("权限被拒绝," + tip, function(res) {
  577. if (res) {
  578. uni.openAppAuthorizeSetting();
  579. }
  580. resolve(false);
  581. });
  582. }
  583. }
  584. });
  585. },
  586. appShare(scene,that) {
  587. uni.share({
  588. provider: "weixin", //分享服务提供商(即weixin|qq|sinaweibo)
  589. scene: scene, //场景,可取值参考下面说明。
  590. type: 0, //分享形式 0:图文 1:纯文字 2:纯图片 3:音乐 4:视频 5:小程序
  591. summary: '亿职赞APP新上线,欢迎前来体验',
  592. href:configdata.h5Url+'/pages/index/download',
  593. imageUrl:configdata.h5Url+'/40x40.png',
  594. success: function(res) {
  595. that.shows = false; //成功后关闭底部弹框
  596. },
  597. fail: (err) =>{
  598. this.showToast('分享失败')
  599. that.shows = false;
  600. }
  601. });
  602. },
  603. connectSocket() {
  604. let that = this
  605. let userId = this.getData('userId');
  606. if(!userId)
  607. return;
  608. uni.closeSocket()
  609. uni.connectSocket({
  610. url: configdata.WSHOST1 + '' + userId,
  611. data() {
  612. return {
  613. msg: 'Hello'
  614. }
  615. },
  616. header: {
  617. 'content-type': 'application/json'
  618. },
  619. method: 'GET',
  620. success(res) {
  621. // 这里是接口调用成功的回调,不是连接成功的回调,请注意
  622. console.log('连接成功',res)
  623. that.onSocketMsg();
  624. },
  625. fail(err) {
  626. console.log('连接失败',res)
  627. // 这里是接口调用失败的回调,不是连接失败的回调,请注意
  628. }
  629. })
  630. },
  631. onSocketMsg(){
  632. let that = this
  633. uni.onSocketMessage((res) => {
  634. if (res.data === 'HeartBeat') return // 忽略心跳包
  635. let msg
  636. try {
  637. msg = JSON.parse(res.data)
  638. } catch (e) {
  639. // console.log('消息不是JSON格式:', res.data)
  640. return
  641. }
  642. if (msg.type === 'kickOut') {
  643. uni.showModal({
  644. title: '提示',
  645. content: msg.content,
  646. showCancel: false,
  647. success() {
  648. that.logout();
  649. uni.reLaunch({ url: '/pages/public/loginphone?type=1' })
  650. }
  651. })
  652. }
  653. })
  654. },
  655. sendImMessage(userId,content,messageType,chatConversationId,recordId){
  656. let data = {
  657. userId,
  658. content,
  659. messageType,
  660. chatConversationId
  661. }
  662. if(recordId){
  663. data = {
  664. ...data,
  665. recordId
  666. }
  667. }
  668. data = JSON.stringify(data);
  669. return new Promise(async (resolve,reject) => {
  670. uni.sendSocketMessage({
  671. data: data,
  672. success(res) {
  673. resolve(res)
  674. },
  675. fail(err) {
  676. reject(err);
  677. }
  678. })
  679. })
  680. }
  681. };