App.vue 21 KB

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