App.vue 21 KB

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