App.vue 21 KB

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