App.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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. uni.setStorage({
  248. key: "updated",
  249. data: {
  250. completed: false,
  251. packgePath: packgePath,
  252. },
  253. success: () => {
  254. console.log("成功保存记录");
  255. },
  256. });
  257. // 任务完成,关闭下载任务
  258. console.log(
  259. "任务完成,关闭下载任务,下一次启动应用时将安装更新"
  260. );
  261. downloadTask.abort();
  262. downloadTask = null;
  263. },
  264. });
  265. }
  266. },
  267. });
  268. } else {
  269. console.log("下载地址未准备,无法开启下载任务");
  270. }
  271. } else {
  272. //不是热更新是在线更新 校验是否强制升级
  273. if (res.method == "true") {
  274. uni.showModal({
  275. showCancel: false,
  276. confirmText: "立即更新",
  277. title: "发现新版本",
  278. content: res.des,
  279. success: (res) => {
  280. if (res.confirm) {
  281. that.$queue.showLoading("下载中...");
  282. if (uni.getSystemInfoSync().platform == "android") {
  283. uni.downloadFile({
  284. url: androidLink,
  285. success: (downloadResult) => {
  286. if (downloadResult.statusCode === 200) {
  287. plus.runtime.install(
  288. downloadResult.tempFilePath,
  289. {
  290. force: false,
  291. },
  292. (d) => {
  293. console.log("install success...");
  294. plus.runtime.restart();
  295. },
  296. (e) => {
  297. console.error("install fail...");
  298. }
  299. );
  300. }
  301. },
  302. });
  303. }
  304. if (uni.getSystemInfoSync().platform == "ios") {
  305. plus.runtime.openURL(iosLink, function (res) {});
  306. }
  307. } else if (res.cancel) {
  308. console.log("取消");
  309. }
  310. },
  311. });
  312. } else {
  313. uni.showModal({
  314. title: "发现新版本",
  315. confirmText: "立即更新",
  316. cancelText: "下次更新",
  317. content: res.des,
  318. success: (res) => {
  319. if (res.confirm) {
  320. that.$queue.showLoading("下载中...");
  321. if (uni.getSystemInfoSync().platform == "android") {
  322. uni.downloadFile({
  323. url: androidLink,
  324. success: (downloadResult) => {
  325. if (downloadResult.statusCode === 200) {
  326. plus.runtime.install(
  327. downloadResult.tempFilePath,
  328. {
  329. force: false,
  330. },
  331. (d) => {
  332. console.log("install success...");
  333. plus.runtime.restart();
  334. },
  335. (e) => {
  336. console.error("install fail...");
  337. }
  338. );
  339. }
  340. },
  341. });
  342. }
  343. if (uni.getSystemInfoSync().platform == "ios") {
  344. plus.runtime.openURL(iosLink, function (res) {});
  345. }
  346. } else if (res.cancel) {
  347. console.log("取消");
  348. }
  349. },
  350. });
  351. }
  352. }
  353. }
  354. });
  355. });
  356. }
  357. //#endif
  358. },
  359. onShow: function () {
  360. // uni.removeStorageSync('firstLogin');
  361. // uni.removeStorageSync('firstUpload');
  362. //关键词过滤 602
  363. this.$Request.getT("/app/common/type/602").then((res) => {
  364. if (res.code == 0) {
  365. if (res.data && res.data.value) {
  366. this.$queue.setData("chatSearchKeys", res.data.value);
  367. }
  368. }
  369. });
  370. // 小程序是否上线
  371. // this.$Request.get('/app/common/type/238').then(res => {
  372. // if (res.code == 0) {
  373. // // #ifdef MP-WEIXIN
  374. // this.$queue.setData('XCXIsSelect', res.data.value);
  375. // // #endif
  376. // // #ifndef MP-WEIXIN
  377. // this.$queue.setData('XCXIsSelect', '是');
  378. // // #endif
  379. // }
  380. // });
  381. this.$Request.get("/app/common/type/257").then((res) => {
  382. if (res.code == 0) {
  383. // #ifdef MP-WEIXIN
  384. this.$queue.setData("XCXIsSelect", res.data.value);
  385. // #endif
  386. // #ifndef MP-WEIXIN
  387. this.$queue.setData("XCXIsSelect", "是");
  388. // #endif
  389. }
  390. });
  391. //用户客服
  392. // 企业微信链接 274
  393. this.$Request.get("/app/common/type/322").then((res) => {
  394. if (res.code == 0) {
  395. this.$queue.setData("kefu", res.data.value);
  396. }
  397. });
  398. // 企业微信客服APPID 275
  399. this.$Request.get("/app/common/type/324").then((res) => {
  400. if (res.code == 0) {
  401. this.$queue.setData("kefuAppid", res.data.value);
  402. }
  403. });
  404. //企业端客服
  405. this.$Request.get("/app/common/type/321").then((res) => {
  406. if (res.code == 0) {
  407. this.$queue.setData("kefuq", res.data.value);
  408. }
  409. });
  410. // 企业微信客服APPID 275
  411. this.$Request.get("/app/common/type/323").then((res) => {
  412. if (res.code == 0) {
  413. this.$queue.setData("kefuAppidq", res.data.value);
  414. }
  415. });
  416. // 企业会员每天免费联系次数 421
  417. this.$Request.get("/app/common/type/421").then((res) => {
  418. if (res.code == 0) {
  419. this.$queue.setData("vipMsgNum", res.data.value);
  420. }
  421. });
  422. // 企业非会员每天免费联系次数 422
  423. this.$Request.get("/app/common/type/422").then((res) => {
  424. if (res.code == 0) {
  425. this.$queue.setData("msgNum", res.data.value);
  426. }
  427. });
  428. // 企业会员每次联系价格 419
  429. this.$Request.get("/app/common/type/419").then((res) => {
  430. if (res.code == 0) {
  431. this.$queue.setData("vipMsgPrice", res.data.value);
  432. }
  433. });
  434. // 企业非会员每次联系价格 420
  435. this.$Request.get("/app/common/type/420").then((res) => {
  436. if (res.code == 0) {
  437. this.$queue.setData("msgPrice", res.data.value);
  438. }
  439. });
  440. //腾讯云实时语音SDKAppID
  441. this.$Request.get("/app/common/type/814").then((res) => {
  442. if (res.code == 0) {
  443. uni.setStorageSync("sdkAppId", res.data.value);
  444. }
  445. });
  446. console.log("App Show");
  447. // #ifdef H5
  448. // let sysTem = uni.getSystemInfoSync()
  449. // if (sysTem.model == 'PC') { //如果是pc访问移动端域名
  450. // this.$Request.get('/app/common/type/432').then(res => {
  451. // if (res.code == 0) {
  452. // if (res.data.value == '是') {
  453. // this.$Request.get('/app/common/type/433').then(ree => {
  454. // if (ree.code == 0) {
  455. // if (ree.data.value) {
  456. // window.location.href = ree.data.value;
  457. // }
  458. // }
  459. // })
  460. // }
  461. // }
  462. // })
  463. // }
  464. // #endif
  465. // #ifdef APP-PLUS
  466. if (uni.getSystemInfoSync().platform == "android") {
  467. let clientid = plus.push.getClientInfo().clientid;
  468. let userId = this.$queue.getData("userId");
  469. if (userId) {
  470. this.$Request
  471. .postT("/app/user/updateClientId?clientId=" + clientid + "&userId=" + userId)
  472. .then((res) => {});
  473. }
  474. }
  475. //#endif
  476. //#ifdef H5
  477. let isopen = false;
  478. this.$Request.get("/app/common/type/237").then((res) => {
  479. if (res.data.value == "是") {
  480. isopen = true;
  481. }
  482. });
  483. if (isopen) {
  484. let ua = navigator.userAgent.toLowerCase();
  485. if (ua.indexOf("micromessenger") !== -1) {
  486. let openid = uni.getStorageSync("openid");
  487. let userId = uni.getStorageSync("userId");
  488. let that = this;
  489. if (!openid) {
  490. if (
  491. window.location.href.indexOf("?code=") !== -1 ||
  492. window.location.href.indexOf("&code=") !== -1
  493. ) {
  494. let code;
  495. if (window.location.href.indexOf("?code=") !== -1) {
  496. code = window.location.href.split("?code=")[1].split("&")[0];
  497. } else {
  498. code = window.location.href.split("&code=")[1].split("&")[0];
  499. }
  500. this.$Request.get("/app/Login/getOpenId?code=" + code).then((ret) => {
  501. uni.setStorageSync("openId", ret.data);
  502. this.$Request
  503. .get("/app/Login/openid/login?openId=" + ret.data)
  504. .then((res) => {
  505. this.$queue.setData("userId", res.user.userId);
  506. this.$queue.setData("token", res.token);
  507. this.$queue.setData("phone", res.user.phone);
  508. this.$queue.setData("userName", res.user.userName);
  509. this.$queue.setData("avatar", res.user.avatar);
  510. this.$queue.setData("invitationCode", res.user.invitationCode);
  511. this.$queue.setData("inviterCode", res.user.inviterCode);
  512. });
  513. });
  514. } else {
  515. this.$Request.get("/app/common/type/108").then((res) => {
  516. if (res.data.value == "是") {
  517. window.location.href =
  518. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  519. that.$queue.getWxAppid() +
  520. "&redirect_uri=" +
  521. window.location.href.split("#")[0] +
  522. "&response_type=code&scope=snsapi_userinfo#wechat_redirect";
  523. }
  524. });
  525. }
  526. }
  527. if (userId && openid) {
  528. this.$Request
  529. .get("/app/Login/bindOpenId?userId=" + userId + "&openId=" + openid)
  530. .then((res) => {
  531. });
  532. }
  533. }
  534. }
  535. //#endif
  536. },
  537. onHide: function () {
  538. console.log("App Hide");
  539. },
  540. };
  541. </script>
  542. <style lang="scss">
  543. /*每个页面公共css */
  544. @import "uview-ui/index.scss";
  545. @import "components/colorui/main.css";
  546. @import "components/colorui/icon.css";
  547. page {
  548. background-color: #ffffff;
  549. color: #343546;
  550. }
  551. .bg {
  552. background-color: #f7f7f7;
  553. }
  554. /*文本省略*/
  555. .m-ellipsis {
  556. overflow: hidden;
  557. white-space: nowrap;
  558. text-overflow: ellipsis;
  559. }
  560. .m-ellipsis-l2,
  561. .m-ellipsis-l3 {
  562. display: -webkit-box;
  563. overflow: hidden;
  564. text-overflow: ellipsis;
  565. -webkit-box-orient: vertical;
  566. word-break: break-all;
  567. }
  568. .m-ellipsis-l2 {
  569. -webkit-line-clamp: 2;
  570. }
  571. .m-ellipsis-l3 {
  572. -webkit-line-clamp: 3;
  573. }
  574. .popup-content .popup-text-permission{
  575. padding: 100rpx;
  576. color: #343546;
  577. }
  578. </style>