App.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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. uni.removeStorageSync("updated");
  162. plus.runtime.install(updated.packgePath, {
  163. force: true,
  164. });
  165. uni.setStorage({
  166. key: "updated",
  167. data: {
  168. completed: true,
  169. packgePath: updated.packgePath,
  170. },
  171. success: (res) => {
  172. console.log("成功安装上次的更新,应用需要重启才能继续完成");
  173. },
  174. });
  175. uni.showModal({
  176. title: "温馨提示",
  177. content: "应用将重启以完成更新",
  178. showCancel: false,
  179. complete: () => {
  180. plus.runtime.restart();
  181. },
  182. });
  183. } else {
  184. //获取当前系统版本信息
  185. plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
  186. //请求后台接口 解析数据 对比版本
  187. that.$Request.getT("/app/user/selectNewApp").then((res) => {
  188. res = res.data[0];
  189. if (res.wgtUrl && widgetInfo.version < res.version) {
  190. let downloadLink = "";
  191. let androidLink = res.androidWgtUrl;
  192. let iosLink = res.iosWgtUrl;
  193. let ready = false;
  194. //校验是是不是热更新
  195. if (res.wgtUrl.match(RegExp(/.wgt/))) {
  196. // 判断系统类型
  197. if (plus.os.name.toLowerCase() === "android") {
  198. console.log("安卓系统");
  199. if (androidLink && androidLink !== "#") {
  200. // 我这里默认#也是没有地址,请根据业务自行修改
  201. console.log("发现下载地址");
  202. // 安卓:创建下载任务
  203. if (androidLink.match(RegExp(/.wgt/))) {
  204. console.log("确认wgt热更新包");
  205. downloadLink = androidLink;
  206. ready = true;
  207. } else {
  208. console.log("安卓推荐.wgt强制更新,.apk的强制更新请您自行修改程序");
  209. }
  210. } else {
  211. console.log("下载地址是空的,无法继续");
  212. }
  213. } else {
  214. console.log("苹果系统");
  215. if (iosLink && iosLink !== "#") {
  216. // 我这里默认#也是没有地址,请根据业务自行修改
  217. console.log("发现下载地址");
  218. // 苹果(A):进行热更新(如果iosLink是wgt更新包的下载地址)判断文件名中是否含有.wgt
  219. if (iosLink.match(RegExp(/.wgt/))) {
  220. console.log("确认wgt热更新包");
  221. downloadLink = iosLink;
  222. ready = true;
  223. } else {
  224. console.log("苹果只支持.wgt强制更新");
  225. }
  226. } else {
  227. console.log("下载地址是空的,无法继续");
  228. }
  229. }
  230. if (ready) {
  231. console.log("任务开始");
  232. let downloadTask = uni.downloadFile({
  233. url: downloadLink,
  234. success: (res) => {
  235. if (res.statusCode === 200) {
  236. // 保存下载的安装包
  237. console.log("保存安装包");
  238. uni.saveFile({
  239. tempFilePath: res.tempFilePath,
  240. success: (res) => {
  241. const packgePath = res.savedFilePath;
  242. // 保存更新记录到stroage,下次启动app时安装更新
  243. uni.setStorage({
  244. key: "updated",
  245. data: {
  246. completed: false,
  247. packgePath: packgePath,
  248. },
  249. success: () => {
  250. console.log("成功保存记录");
  251. },
  252. });
  253. // 任务完成,关闭下载任务
  254. console.log(
  255. "任务完成,关闭下载任务,下一次启动应用时将安装更新"
  256. );
  257. downloadTask.abort();
  258. downloadTask = null;
  259. },
  260. });
  261. }
  262. },
  263. });
  264. } else {
  265. console.log("下载地址未准备,无法开启下载任务");
  266. }
  267. } else {
  268. //不是热更新是在线更新 校验是否强制升级
  269. if (res.method == "true") {
  270. uni.showModal({
  271. showCancel: false,
  272. confirmText: "立即更新",
  273. title: "发现新版本",
  274. content: res.des,
  275. success: (res) => {
  276. if (res.confirm) {
  277. that.$queue.showLoading("下载中...");
  278. if (uni.getSystemInfoSync().platform == "android") {
  279. uni.downloadFile({
  280. url: androidLink,
  281. success: (downloadResult) => {
  282. if (downloadResult.statusCode === 200) {
  283. plus.runtime.install(
  284. downloadResult.tempFilePath,
  285. {
  286. force: false,
  287. },
  288. (d) => {
  289. console.log("install success...");
  290. plus.runtime.restart();
  291. },
  292. (e) => {
  293. console.error("install fail...");
  294. }
  295. );
  296. }
  297. },
  298. });
  299. }
  300. if (uni.getSystemInfoSync().platform == "ios") {
  301. plus.runtime.openURL(iosLink, function (res) {});
  302. }
  303. } else if (res.cancel) {
  304. console.log("取消");
  305. }
  306. },
  307. });
  308. } else {
  309. uni.showModal({
  310. title: "发现新版本",
  311. confirmText: "立即更新",
  312. cancelText: "下次更新",
  313. content: res.des,
  314. success: (res) => {
  315. if (res.confirm) {
  316. that.$queue.showLoading("下载中...");
  317. if (uni.getSystemInfoSync().platform == "android") {
  318. uni.downloadFile({
  319. url: androidLink,
  320. success: (downloadResult) => {
  321. if (downloadResult.statusCode === 200) {
  322. plus.runtime.install(
  323. downloadResult.tempFilePath,
  324. {
  325. force: false,
  326. },
  327. (d) => {
  328. console.log("install success...");
  329. plus.runtime.restart();
  330. },
  331. (e) => {
  332. console.error("install fail...");
  333. }
  334. );
  335. }
  336. },
  337. });
  338. }
  339. if (uni.getSystemInfoSync().platform == "ios") {
  340. plus.runtime.openURL(iosLink, function (res) {});
  341. }
  342. } else if (res.cancel) {
  343. console.log("取消");
  344. }
  345. },
  346. });
  347. }
  348. }
  349. }
  350. });
  351. });
  352. }
  353. //#endif
  354. },
  355. onShow: function () {
  356. // uni.removeStorageSync('firstLogin');
  357. // uni.removeStorageSync('firstUpload');
  358. //关键词过滤 602
  359. this.$Request.getT("/app/common/type/602").then((res) => {
  360. if (res.code == 0) {
  361. if (res.data && res.data.value) {
  362. this.$queue.setData("chatSearchKeys", res.data.value);
  363. }
  364. }
  365. });
  366. // 小程序是否上线
  367. // this.$Request.get('/app/common/type/238').then(res => {
  368. // if (res.code == 0) {
  369. // // #ifdef MP-WEIXIN
  370. // this.$queue.setData('XCXIsSelect', res.data.value);
  371. // // #endif
  372. // // #ifndef MP-WEIXIN
  373. // this.$queue.setData('XCXIsSelect', '是');
  374. // // #endif
  375. // }
  376. // });
  377. this.$Request.get("/app/common/type/257").then((res) => {
  378. if (res.code == 0) {
  379. // #ifdef MP-WEIXIN
  380. this.$queue.setData("XCXIsSelect", res.data.value);
  381. // #endif
  382. // #ifndef MP-WEIXIN
  383. this.$queue.setData("XCXIsSelect", "是");
  384. // #endif
  385. }
  386. });
  387. //用户客服
  388. // 企业微信链接 274
  389. this.$Request.get("/app/common/type/322").then((res) => {
  390. if (res.code == 0) {
  391. this.$queue.setData("kefu", res.data.value);
  392. }
  393. });
  394. // 企业微信客服APPID 275
  395. this.$Request.get("/app/common/type/324").then((res) => {
  396. if (res.code == 0) {
  397. this.$queue.setData("kefuAppid", res.data.value);
  398. }
  399. });
  400. //企业端客服
  401. this.$Request.get("/app/common/type/321").then((res) => {
  402. if (res.code == 0) {
  403. this.$queue.setData("kefuq", res.data.value);
  404. }
  405. });
  406. // 企业微信客服APPID 275
  407. this.$Request.get("/app/common/type/323").then((res) => {
  408. if (res.code == 0) {
  409. this.$queue.setData("kefuAppidq", res.data.value);
  410. }
  411. });
  412. // 企业会员每天免费联系次数 421
  413. this.$Request.get("/app/common/type/421").then((res) => {
  414. if (res.code == 0) {
  415. this.$queue.setData("vipMsgNum", res.data.value);
  416. }
  417. });
  418. // 企业非会员每天免费联系次数 422
  419. this.$Request.get("/app/common/type/422").then((res) => {
  420. if (res.code == 0) {
  421. this.$queue.setData("msgNum", res.data.value);
  422. }
  423. });
  424. // 企业会员每次联系价格 419
  425. this.$Request.get("/app/common/type/419").then((res) => {
  426. if (res.code == 0) {
  427. this.$queue.setData("vipMsgPrice", res.data.value);
  428. }
  429. });
  430. // 企业非会员每次联系价格 420
  431. this.$Request.get("/app/common/type/420").then((res) => {
  432. if (res.code == 0) {
  433. this.$queue.setData("msgPrice", res.data.value);
  434. }
  435. });
  436. //腾讯云实时语音SDKAppID
  437. this.$Request.get("/app/common/type/814").then((res) => {
  438. if (res.code == 0) {
  439. uni.setStorageSync("sdkAppId", res.data.value);
  440. }
  441. });
  442. console.log("App Show");
  443. // #ifdef H5
  444. // let sysTem = uni.getSystemInfoSync()
  445. // if (sysTem.model == 'PC') { //如果是pc访问移动端域名
  446. // this.$Request.get('/app/common/type/432').then(res => {
  447. // if (res.code == 0) {
  448. // if (res.data.value == '是') {
  449. // this.$Request.get('/app/common/type/433').then(ree => {
  450. // if (ree.code == 0) {
  451. // if (ree.data.value) {
  452. // window.location.href = ree.data.value;
  453. // }
  454. // }
  455. // })
  456. // }
  457. // }
  458. // })
  459. // }
  460. // #endif
  461. // #ifdef APP-PLUS
  462. if (uni.getSystemInfoSync().platform == "android") {
  463. let clientid = plus.push.getClientInfo().clientid;
  464. let userId = this.$queue.getData("userId");
  465. if (userId) {
  466. this.$Request
  467. .postT("/app/user/updateClientId?clientId=" + clientid + "&userId=" + userId)
  468. .then((res) => {});
  469. }
  470. }
  471. //#endif
  472. //#ifdef H5
  473. let isopen = false;
  474. this.$Request.get("/app/common/type/237").then((res) => {
  475. if (res.data.value == "是") {
  476. isopen = true;
  477. }
  478. });
  479. if (isopen) {
  480. let ua = navigator.userAgent.toLowerCase();
  481. if (ua.indexOf("micromessenger") !== -1) {
  482. let openid = uni.getStorageSync("openid");
  483. let userId = uni.getStorageSync("userId");
  484. let that = this;
  485. if (!openid) {
  486. if (
  487. window.location.href.indexOf("?code=") !== -1 ||
  488. window.location.href.indexOf("&code=") !== -1
  489. ) {
  490. let code;
  491. if (window.location.href.indexOf("?code=") !== -1) {
  492. code = window.location.href.split("?code=")[1].split("&")[0];
  493. } else {
  494. code = window.location.href.split("&code=")[1].split("&")[0];
  495. }
  496. this.$Request.get("/app/Login/getOpenId?code=" + code).then((ret) => {
  497. uni.setStorageSync("openId", ret.data);
  498. this.$Request
  499. .get("/app/Login/openid/login?openId=" + ret.data)
  500. .then((res) => {
  501. this.$queue.setData("userId", res.user.userId);
  502. this.$queue.setData("token", res.token);
  503. this.$queue.setData("phone", res.user.phone);
  504. this.$queue.setData("userName", res.user.userName);
  505. this.$queue.setData("avatar", res.user.avatar);
  506. this.$queue.setData("invitationCode", res.user.invitationCode);
  507. this.$queue.setData("inviterCode", res.user.inviterCode);
  508. });
  509. });
  510. } else {
  511. this.$Request.get("/app/common/type/108").then((res) => {
  512. if (res.data.value == "是") {
  513. window.location.href =
  514. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  515. that.$queue.getWxAppid() +
  516. "&redirect_uri=" +
  517. window.location.href.split("#")[0] +
  518. "&response_type=code&scope=snsapi_userinfo#wechat_redirect";
  519. }
  520. });
  521. }
  522. }
  523. if (userId && openid) {
  524. this.$Request
  525. .get("/app/Login/bindOpenId?userId=" + userId + "&openId=" + openid)
  526. .then((res) => {
  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. .popup-content .popup-text-permission{
  571. padding: 100rpx;
  572. color: #343546;
  573. }
  574. </style>