App.vue 21 KB

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