App.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <script>
  2. export default {
  3. onLaunch: function () {
  4. let that = this;
  5. this.$queue.connectSocket()
  6. that.$queue.changeTabbar(that.$queue.getData('userType')||1)
  7. uni.removeStorageSync('filter')
  8. // #ifdef APP
  9. // 检查是否首次启动 - 引导页逻辑
  10. let firstUpload = uni.getStorageSync("firstUpload") || false;
  11. let token = this.$queue.getData('token')
  12. let userType = this.$queue.getData('userType')
  13. let companyStatus = this.$queue.getData('companyStatus')
  14. if (!firstUpload) {
  15. // 跳转到引导页
  16. uni.reLaunch({
  17. url: "/pages/my/jobApplicant/startPage",
  18. success: () => {
  19. // 标记已经显示过引导页
  20. uni.setStorageSync("firstUpload", true);
  21. }
  22. });
  23. // 这里需要return,避免执行后面的代码
  24. return;
  25. } else if (
  26. token &&
  27. (!userType || (userType == 2 && companyStatus != 2))
  28. ) {
  29. // 有登录token,但是没有userType,跳转选择角色页面,强制用户选择
  30. // 有登录token,并且userType为2,但是公司状态没有通过
  31. uni.reLaunch({
  32. url: '/pages/my/jobApplicant/guidePage',
  33. })
  34. return
  35. } else if (token && userType) {
  36. // 已经登录,且有userType
  37. uni.reLaunch({
  38. url: '/pages/index/index',
  39. })
  40. }
  41. // #endif
  42. // #ifdef APP || H5
  43. uni.setStorageSync("isDial", false);
  44. setInterval(() => {
  45. // #ifdef H5 || APP
  46. let userId = uni.getStorageSync("userId");
  47. if (uni.getStorageSync("token")) {
  48. that.$Request.get("/app/chat/selectUserChatVideo").then((res) => {
  49. if (res.code == 0 && res.data) {
  50. // videoStatus 状态 1是发起 2是通话中 3是已取消 4是已拒绝 5是已结束 不过他只会返回1和2
  51. if (res.data.videoStatus) {
  52. console.log(res.data);
  53. uni.setStorageSync("videoStatus", res.data.videoStatus);
  54. uni.setStorageSync("messageType", res.data.messageType); //4视频通话 5语音通话
  55. if (res.data.videoStatus == 1) {
  56. console.log(uni.getStorageSync("isDial"));
  57. if (!uni.getStorageSync("isDial")) {
  58. uni.setStorageSync("isDial", true); //跳转通话页面 做标识 true 已跳转 false 未跳转
  59. uni.navigateTo({
  60. url:
  61. "/my/videoVoice/videoVoice?byUserId=" +
  62. res.data.userId +
  63. "&chatContentId=" +
  64. res.data.chatContentId +
  65. "&isRol=2&messageType=" +
  66. res.data.messageType +
  67. "&chatConversationId=" +
  68. res.data.chatConversationId +
  69. "&postPushId=" +
  70. res.data.postPushId +
  71. "&resumesId=" +
  72. res.data.resumesId +
  73. "&userType=" +
  74. res.data.userType,
  75. });
  76. }
  77. }
  78. }
  79. } else {
  80. uni.setStorageSync("videoStatus", 4);
  81. }
  82. });
  83. }
  84. // #endif
  85. }, 5000);
  86. // #endif
  87. // #ifdef MP-WEIXIN
  88. if (!uni.getStorageSync("token")) {
  89. uni.login({
  90. provider: "weixin",
  91. success: function (loginRes) {
  92. console.log(loginRes, "************");
  93. let data = {
  94. code: loginRes.code,
  95. };
  96. that.$Request.get("/app/Login/wxLogin", data).then((res) => {
  97. if (res.code == 0) {
  98. uni.setStorageSync("openId", res.data.open_id);
  99. uni.setStorageSync("unionId", res.data.unionId);
  100. uni.setStorageSync("sessionkey", res.data.session_key);
  101. let inviterCode = "";
  102. if (uni.getStorageSync("inviterCode")) {
  103. inviterCode = uni.getStorageSync("inviterCode");
  104. }
  105. let sendData = {
  106. openId: uni.getStorageSync("openId"),
  107. unionId: uni.getStorageSync("unionId"),
  108. userName: "游客",
  109. avatar: "",
  110. sex: "1", //性别
  111. inviterCode: inviterCode, //别人登录进来携带你的邀请码
  112. };
  113. let phoneNum = false;
  114. uni.setStorageSync("sendDataList", sendData);
  115. that.$Request.getT("/app/common/type/188").then((ret) => {
  116. if (ret.code == 0) {
  117. if (ret.data && ret.data.value && ret.data.value == "是") {
  118. phoneNum = true;
  119. let flag = res.data.flag;
  120. if (flag == "2" && phoneNum) {
  121. //需要授权手机号则走手机号授权
  122. uni.setStorageSync("weixinPhone", true);
  123. } else {
  124. //不需要手机号则则直接走授权登录
  125. uni.setStorageSync("weixinPhone", false);
  126. }
  127. } else {
  128. uni.setStorageSync("weixinPhone", false);
  129. }
  130. }
  131. });
  132. }
  133. });
  134. },
  135. });
  136. }
  137. // #endif
  138. setInterval((d) => {
  139. //定时器,定时去调取聊天未读消息
  140. let userId = uni.getStorageSync("userId");
  141. if (userId) {
  142. this.$Request.get("/app/chat/selectChatCount").then((res) => {
  143. if (res.code === 0) {
  144. let chatCount = res.data.chatCount;
  145. let messageCount = res.data.messageCount;
  146. uni.setStorageSync("messageCount", messageCount);
  147. let num = chatCount + messageCount;
  148. if (num == 0) {
  149. uni.removeTabBarBadge({
  150. index: 2,
  151. });
  152. return;
  153. }
  154. uni.setTabBarBadge({
  155. index: 2,
  156. text: num + "",
  157. });
  158. }
  159. });
  160. }
  161. }, 6000);
  162. //#ifdef APP-PLUS
  163. // APP检测更新 具体打包流程可以参考:https://ask.dcloud.net.cn/article/35667
  164. plus.screen.lockOrientation("portrait-primary"); //竖屏正方向锁定
  165. //获取是否热更新过
  166. const updated = uni.getStorageSync("updated"); // 尝试读取storage
  167. if (updated.completed === true) {
  168. // 如果上次刚更新过
  169. // 删除安装包及安装记录
  170. console.log("安装记录被删除,更新成功");
  171. uni.removeSavedFile({
  172. filePath: updated.packgePath,
  173. success: (res) => {
  174. uni.removeStorageSync("updated");
  175. },
  176. });
  177. } else if (updated.completed === false) {
  178. console.log('安装未完成,继续安装')
  179. uni.removeStorageSync("updated");
  180. plus.runtime.install(updated.packgePath, {
  181. force: true,
  182. });
  183. uni.setStorage({
  184. key: "updated",
  185. data: {
  186. completed: true,
  187. packgePath: updated.packgePath,
  188. },
  189. success: (res) => {
  190. console.log("成功安装上次的更新,应用需要重启才能继续完成");
  191. },
  192. });
  193. uni.showModal({
  194. title: "温馨提示",
  195. content: "应用将重启以完成更新",
  196. showCancel: false,
  197. complete: () => {
  198. plus.runtime.restart();
  199. },
  200. });
  201. } else {
  202. console.log('获取当前系统版本信息')
  203. //获取当前系统版本信息
  204. plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
  205. //请求后台接口 解析数据 对比版本
  206. that.$Request.getT("/app/user/selectNewApp").then((res) => {
  207. res = res.data[0];
  208. console.log('当前版本:',widgetInfo.version+'线上版本:'+res.version)
  209. if (res.wgtUrl && widgetInfo.version < res.version) {
  210. console.log('进入更新逻辑')
  211. let downloadLink = "";
  212. let androidLink = res.androidWgtUrl;
  213. let iosLink = res.iosWgtUrl;
  214. let ready = false;
  215. //校验是是不是热更新
  216. if (res.wgtUrl.match(RegExp(/.wgt/))) {
  217. // 判断系统类型
  218. if (plus.os.name.toLowerCase() === "android") {
  219. console.log("安卓系统");
  220. if (androidLink && androidLink !== "#") {
  221. // 我这里默认#也是没有地址,请根据业务自行修改
  222. console.log("发现下载地址");
  223. // 安卓:创建下载任务
  224. if (androidLink.match(RegExp(/.wgt/))) {
  225. console.log("确认wgt热更新包");
  226. downloadLink = androidLink;
  227. ready = true;
  228. } else {
  229. console.log("安卓推荐.wgt强制更新,.apk的强制更新请您自行修改程序");
  230. }
  231. } else {
  232. console.log("下载地址是空的,无法继续");
  233. }
  234. } else {
  235. console.log("苹果系统");
  236. if (iosLink && iosLink !== "#") {
  237. // 我这里默认#也是没有地址,请根据业务自行修改
  238. console.log("发现下载地址");
  239. // 苹果(A):进行热更新(如果iosLink是wgt更新包的下载地址)判断文件名中是否含有.wgt
  240. if (iosLink.match(RegExp(/.wgt/))) {
  241. console.log("确认wgt热更新包");
  242. downloadLink = iosLink;
  243. ready = true;
  244. } else {
  245. console.log("苹果只支持.wgt强制更新");
  246. }
  247. } else {
  248. console.log("下载地址是空的,无法继续");
  249. }
  250. }
  251. if (ready) {
  252. console.log("任务开始");
  253. let downloadTask = uni.downloadFile({
  254. url: downloadLink,
  255. success: (res) => {
  256. if (res.statusCode === 200) {
  257. // 保存下载的安装包
  258. console.log("保存安装包");
  259. uni.saveFile({
  260. tempFilePath: res.tempFilePath,
  261. success: (res) => {
  262. const packgePath = res.savedFilePath;
  263. // 保存更新记录到stroage,下次启动app时安装更新
  264. if(true){
  265. console.log('直接进行安装')
  266. uni.removeStorageSync("updated");
  267. plus.runtime.install(packgePath, {
  268. force: true,
  269. });
  270. uni.setStorage({
  271. key: "updated",
  272. data: {
  273. completed: true,
  274. packgePath: packgePath,
  275. },
  276. success: (res) => {
  277. console.log("成功安装上次的更新,应用需要重启才能继续完成");
  278. },
  279. });
  280. uni.showModal({
  281. title: "温馨提示",
  282. content: "应用将重启以完成更新",
  283. showCancel: false,
  284. complete: () => {
  285. plus.runtime.restart();
  286. },
  287. });
  288. }else{
  289. uni.setStorage({
  290. key: "updated",
  291. data: {
  292. completed: false,
  293. packgePath: packgePath,
  294. },
  295. success: () => {
  296. console.log("成功保存记录");
  297. },
  298. });
  299. }
  300. // 任务完成,关闭下载任务
  301. console.log(
  302. "任务完成,关闭下载任务,下一次启动应用时将安装更新"
  303. );
  304. downloadTask.abort();
  305. downloadTask = null;
  306. },
  307. });
  308. }
  309. },
  310. });
  311. } else {
  312. console.log("下载地址未准备,无法开启下载任务");
  313. }
  314. } else {
  315. //不是热更新是在线更新 校验是否强制升级
  316. if (res.method == "true") {
  317. uni.showModal({
  318. showCancel: false,
  319. confirmText: "立即更新",
  320. title: "发现新版本",
  321. content: res.des,
  322. success: (res) => {
  323. if (res.confirm) {
  324. that.$queue.showLoading("下载中...");
  325. if (uni.getSystemInfoSync().platform == "android") {
  326. uni.downloadFile({
  327. url: androidLink,
  328. success: (downloadResult) => {
  329. if (downloadResult.statusCode === 200) {
  330. plus.runtime.install(
  331. downloadResult.tempFilePath,
  332. {
  333. force: false,
  334. },
  335. (d) => {
  336. console.log("install success...");
  337. plus.runtime.restart();
  338. },
  339. (e) => {
  340. console.error("install fail...");
  341. }
  342. );
  343. }
  344. },
  345. });
  346. }
  347. if (uni.getSystemInfoSync().platform == "ios") {
  348. plus.runtime.openURL(iosLink, function (res) {});
  349. }
  350. } else if (res.cancel) {
  351. console.log("取消");
  352. }
  353. },
  354. });
  355. } else {
  356. uni.showModal({
  357. title: "发现新版本",
  358. confirmText: "立即更新",
  359. cancelText: "下次更新",
  360. content: res.des,
  361. success: (res) => {
  362. if (res.confirm) {
  363. that.$queue.showLoading("下载中...");
  364. if (uni.getSystemInfoSync().platform == "android") {
  365. uni.downloadFile({
  366. url: androidLink,
  367. success: (downloadResult) => {
  368. if (downloadResult.statusCode === 200) {
  369. plus.runtime.install(
  370. downloadResult.tempFilePath,
  371. {
  372. force: false,
  373. },
  374. (d) => {
  375. console.log("install success...");
  376. plus.runtime.restart();
  377. },
  378. (e) => {
  379. console.error("install fail...");
  380. }
  381. );
  382. }
  383. },
  384. });
  385. }
  386. if (uni.getSystemInfoSync().platform == "ios") {
  387. plus.runtime.openURL(iosLink, function (res) {});
  388. }
  389. } else if (res.cancel) {
  390. console.log("取消");
  391. }
  392. },
  393. });
  394. }
  395. }
  396. }
  397. });
  398. });
  399. }
  400. //#endif
  401. },
  402. onShow: function () {
  403. // uni.removeStorageSync('firstLogin');
  404. // uni.removeStorageSync('firstUpload');
  405. //关键词过滤 602
  406. this.$Request.getT("/app/common/type/602").then((res) => {
  407. if (res.code == 0) {
  408. if (res.data && res.data.value) {
  409. this.$queue.setData("chatSearchKeys", res.data.value);
  410. }
  411. }
  412. });
  413. // 小程序是否上线
  414. // this.$Request.get('/app/common/type/238').then(res => {
  415. // if (res.code == 0) {
  416. // // #ifdef MP-WEIXIN
  417. // this.$queue.setData('XCXIsSelect', res.data.value);
  418. // // #endif
  419. // // #ifndef MP-WEIXIN
  420. // this.$queue.setData('XCXIsSelect', '是');
  421. // // #endif
  422. // }
  423. // });
  424. this.$Request.get("/app/common/type/257").then((res) => {
  425. if (res.code == 0) {
  426. // #ifdef MP-WEIXIN
  427. this.$queue.setData("XCXIsSelect", res.data.value);
  428. // #endif
  429. // #ifndef MP-WEIXIN
  430. this.$queue.setData("XCXIsSelect", "是");
  431. // #endif
  432. }
  433. });
  434. //用户客服
  435. // 企业微信链接 274
  436. this.$Request.get("/app/common/type/322").then((res) => {
  437. if (res.code == 0) {
  438. this.$queue.setData("kefu", res.data.value);
  439. }
  440. });
  441. // 企业微信客服APPID 275
  442. this.$Request.get("/app/common/type/324").then((res) => {
  443. if (res.code == 0) {
  444. this.$queue.setData("kefuAppid", res.data.value);
  445. }
  446. });
  447. //企业端客服
  448. this.$Request.get("/app/common/type/321").then((res) => {
  449. if (res.code == 0) {
  450. this.$queue.setData("kefuq", res.data.value);
  451. }
  452. });
  453. // 企业微信客服APPID 275
  454. this.$Request.get("/app/common/type/323").then((res) => {
  455. if (res.code == 0) {
  456. this.$queue.setData("kefuAppidq", res.data.value);
  457. }
  458. });
  459. // 企业会员每天免费联系次数 421
  460. this.$Request.get("/app/common/type/421").then((res) => {
  461. if (res.code == 0) {
  462. this.$queue.setData("vipMsgNum", res.data.value);
  463. }
  464. });
  465. // 企业非会员每天免费联系次数 422
  466. this.$Request.get("/app/common/type/422").then((res) => {
  467. if (res.code == 0) {
  468. this.$queue.setData("msgNum", res.data.value);
  469. }
  470. });
  471. // 企业会员每次联系价格 419
  472. this.$Request.get("/app/common/type/419").then((res) => {
  473. if (res.code == 0) {
  474. this.$queue.setData("vipMsgPrice", res.data.value);
  475. }
  476. });
  477. // 企业非会员每次联系价格 420
  478. this.$Request.get("/app/common/type/420").then((res) => {
  479. if (res.code == 0) {
  480. this.$queue.setData("msgPrice", res.data.value);
  481. }
  482. });
  483. //腾讯云实时语音SDKAppID
  484. this.$Request.get("/app/common/type/814").then((res) => {
  485. if (res.code == 0) {
  486. uni.setStorageSync("sdkAppId", res.data.value);
  487. }
  488. });
  489. console.log("App Show");
  490. // #ifdef H5
  491. // let sysTem = uni.getSystemInfoSync()
  492. // if (sysTem.model == 'PC') { //如果是pc访问移动端域名
  493. // this.$Request.get('/app/common/type/432').then(res => {
  494. // if (res.code == 0) {
  495. // if (res.data.value == '是') {
  496. // this.$Request.get('/app/common/type/433').then(ree => {
  497. // if (ree.code == 0) {
  498. // if (ree.data.value) {
  499. // window.location.href = ree.data.value;
  500. // }
  501. // }
  502. // })
  503. // }
  504. // }
  505. // })
  506. // }
  507. // #endif
  508. // #ifdef APP-PLUS
  509. if (uni.getSystemInfoSync().platform == "android") {
  510. let clientid = plus.push.getClientInfo().clientid;
  511. let userId = this.$queue.getData("userId");
  512. if (userId) {
  513. this.$Request
  514. .postT("/app/user/updateClientId?clientId=" + clientid + "&userId=" + userId)
  515. .then((res) => {});
  516. }
  517. }
  518. //#endif
  519. //#ifdef H5
  520. let isopen = false;
  521. this.$Request.get("/app/common/type/237").then((res) => {
  522. if (res.data.value == "是") {
  523. isopen = true;
  524. }
  525. });
  526. if (isopen) {
  527. let ua = navigator.userAgent.toLowerCase();
  528. if (ua.indexOf("micromessenger") !== -1) {
  529. let openid = uni.getStorageSync("openid");
  530. let userId = uni.getStorageSync("userId");
  531. let that = this;
  532. if (!openid) {
  533. if (
  534. window.location.href.indexOf("?code=") !== -1 ||
  535. window.location.href.indexOf("&code=") !== -1
  536. ) {
  537. let code;
  538. if (window.location.href.indexOf("?code=") !== -1) {
  539. code = window.location.href.split("?code=")[1].split("&")[0];
  540. } else {
  541. code = window.location.href.split("&code=")[1].split("&")[0];
  542. }
  543. this.$Request.get("/app/Login/getOpenId?code=" + code).then((ret) => {
  544. uni.setStorageSync("openId", ret.data);
  545. this.$Request
  546. .get("/app/Login/openid/login?openId=" + ret.data)
  547. .then((res) => {
  548. this.$queue.setData("userId", res.user.userId);
  549. this.$queue.setData("token", res.token);
  550. this.$queue.setData("phone", res.user.phone);
  551. this.$queue.setData("userName", res.user.userName);
  552. this.$queue.setData("avatar", res.user.avatar);
  553. this.$queue.setData("invitationCode", res.user.invitationCode);
  554. this.$queue.setData("inviterCode", res.user.inviterCode);
  555. });
  556. });
  557. } else {
  558. this.$Request.get("/app/common/type/108").then((res) => {
  559. if (res.data.value == "是") {
  560. window.location.href =
  561. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  562. that.$queue.getWxAppid() +
  563. "&redirect_uri=" +
  564. window.location.href.split("#")[0] +
  565. "&response_type=code&scope=snsapi_userinfo#wechat_redirect";
  566. }
  567. });
  568. }
  569. }
  570. if (userId && openid) {
  571. this.$Request
  572. .get("/app/Login/bindOpenId?userId=" + userId + "&openId=" + openid)
  573. .then((res) => {
  574. });
  575. }
  576. }
  577. }
  578. //#endif
  579. },
  580. onHide: function () {
  581. console.log("App Hide");
  582. },
  583. };
  584. </script>
  585. <style lang="scss">
  586. /*每个页面公共css */
  587. @import "uview-ui/index.scss";
  588. @import "components/colorui/main.css";
  589. @import "components/colorui/icon.css";
  590. page {
  591. background-color: #ffffff;
  592. color: #343546;
  593. }
  594. .bg {
  595. background-color: #f7f7f7;
  596. }
  597. /*文本省略*/
  598. .m-ellipsis {
  599. overflow: hidden;
  600. white-space: nowrap;
  601. text-overflow: ellipsis;
  602. }
  603. .m-ellipsis-l2,
  604. .m-ellipsis-l3 {
  605. display: -webkit-box;
  606. overflow: hidden;
  607. text-overflow: ellipsis;
  608. -webkit-box-orient: vertical;
  609. word-break: break-all;
  610. }
  611. .m-ellipsis-l2 {
  612. -webkit-line-clamp: 2;
  613. }
  614. .m-ellipsis-l3 {
  615. -webkit-line-clamp: 3;
  616. }
  617. .popup-content .popup-text-permission{
  618. padding: 100rpx;
  619. color: #343546;
  620. }
  621. </style>