App.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. <script>
  2. import { openPushAd } from '@/common/pushAdStore.js'
  3. export default {
  4. onLaunch: function () {
  5. uni.removeStorageSync('web_config')
  6. // #ifdef APP-PLUS
  7. // 初始化极光推送
  8. this.initJPush()
  9. // #endif
  10. let that = this;
  11. this.$queue.connectSocket()
  12. that.$queue.changeTabbar(that.$queue.getData('userType')||1)
  13. uni.removeStorageSync('filter')
  14. // #ifdef APP || H5
  15. uni.setStorageSync("isDial", false);
  16. setInterval(() => {
  17. // #ifdef H5 || APP
  18. let userId = uni.getStorageSync("userId");
  19. if (uni.getStorageSync("token")) {
  20. that.$Request.get("/app/chat/selectUserChatVideo").then((res) => {
  21. if (res.code == 0 && res.data) {
  22. // videoStatus 状态 1是发起 2是通话中 3是已取消 4是已拒绝 5是已结束 不过他只会返回1和2
  23. if (res.data.videoStatus) {
  24. console.log(res.data);
  25. uni.setStorageSync("videoStatus", res.data.videoStatus);
  26. uni.setStorageSync("messageType", res.data.messageType); //4视频通话 5语音通话
  27. if (res.data.videoStatus == 1) {
  28. console.log(uni.getStorageSync("isDial"));
  29. if (!uni.getStorageSync("isDial")) {
  30. uni.setStorageSync("isDial", true); //跳转通话页面 做标识 true 已跳转 false 未跳转
  31. uni.navigateTo({
  32. url:
  33. "/my/videoVoice/videoVoice?byUserId=" +
  34. res.data.userId +
  35. "&chatContentId=" +
  36. res.data.chatContentId +
  37. "&isRol=2&messageType=" +
  38. res.data.messageType +
  39. "&chatConversationId=" +
  40. res.data.chatConversationId +
  41. "&postPushId=" +
  42. res.data.postPushId +
  43. "&resumesId=" +
  44. res.data.resumesId +
  45. "&userType=" +
  46. res.data.userType,
  47. });
  48. }
  49. }
  50. }
  51. } else {
  52. uni.setStorageSync("videoStatus", 4);
  53. }
  54. });
  55. }
  56. // #endif
  57. }, 5000);
  58. // #endif
  59. // #ifdef MP-WEIXIN
  60. if (!uni.getStorageSync("token")) {
  61. uni.login({
  62. provider: "weixin",
  63. success: function (loginRes) {
  64. console.log(loginRes, "************");
  65. let data = {
  66. code: loginRes.code,
  67. };
  68. that.$Request.get("/app/Login/wxLogin", data).then((res) => {
  69. if (res.code == 0) {
  70. uni.setStorageSync("openId", res.data.open_id);
  71. uni.setStorageSync("unionId", res.data.unionId);
  72. uni.setStorageSync("sessionkey", res.data.session_key);
  73. let inviterCode = "";
  74. if (uni.getStorageSync("inviterCode")) {
  75. inviterCode = uni.getStorageSync("inviterCode");
  76. }
  77. let sendData = {
  78. openId: uni.getStorageSync("openId"),
  79. unionId: uni.getStorageSync("unionId"),
  80. userName: "游客",
  81. avatar: "",
  82. sex: "1", //性别
  83. inviterCode: inviterCode, //别人登录进来携带你的邀请码
  84. };
  85. let phoneNum = false;
  86. uni.setStorageSync("sendDataList", sendData);
  87. that.$Request.getT("/app/common/type/188").then((ret) => {
  88. if (ret.code == 0) {
  89. if (ret.data && ret.data.value && ret.data.value == "是") {
  90. phoneNum = true;
  91. let flag = res.data.flag;
  92. if (flag == "2" && phoneNum) {
  93. //需要授权手机号则走手机号授权
  94. uni.setStorageSync("weixinPhone", true);
  95. } else {
  96. //不需要手机号则则直接走授权登录
  97. uni.setStorageSync("weixinPhone", false);
  98. }
  99. } else {
  100. uni.setStorageSync("weixinPhone", false);
  101. }
  102. }
  103. });
  104. }
  105. });
  106. },
  107. });
  108. }
  109. // #endif
  110. setInterval((d) => {
  111. //定时器,定时去调取聊天未读消息
  112. let userId = uni.getStorageSync("userId");
  113. let token = uni.getStorageSync('token')
  114. if (userId && token) {
  115. this.$Request.get("/app/chat/selectChatCount").then((res) => {
  116. if (res.code === 0) {
  117. let chatCount = res.data.chatCount;
  118. let messageCount = res.data.messageCount;
  119. uni.setStorageSync("messageCount", messageCount);
  120. // #ifdef APP-PLUS
  121. plus.runtime.setBadgeNumber(chatCount + messageCount)
  122. // #endif
  123. uni.$emit('chatUnreadCount', chatCount || 0)
  124. let num = chatCount + messageCount;
  125. if (num == 0) {
  126. uni.removeTabBarBadge({
  127. index: 2,
  128. });
  129. return;
  130. }
  131. uni.setTabBarBadge({
  132. index: 2,
  133. text: num + "",
  134. });
  135. }
  136. });
  137. }
  138. }, 6000);
  139. //#ifdef APP-PLUS
  140. // APP检测更新 具体打包流程可以参考:https://ask.dcloud.net.cn/article/35667
  141. plus.screen.lockOrientation("portrait-primary"); //竖屏正方向锁定
  142. //获取是否热更新过
  143. const updated = uni.getStorageSync("updated"); // 尝试读取storage
  144. if (updated.completed === true) {
  145. // 如果上次刚更新过
  146. // 删除安装包及安装记录
  147. console.log("安装记录被删除,更新成功");
  148. uni.removeSavedFile({
  149. filePath: updated.packgePath,
  150. success: (res) => {
  151. uni.removeStorageSync("updated");
  152. },
  153. });
  154. } else if (updated.completed === false) {
  155. console.log('安装未完成,继续安装')
  156. uni.removeStorageSync("updated");
  157. plus.runtime.install(updated.packgePath, {
  158. force: true,
  159. });
  160. uni.setStorage({
  161. key: "updated",
  162. data: {
  163. completed: true,
  164. packgePath: updated.packgePath,
  165. },
  166. success: (res) => {
  167. console.log("成功安装上次的更新,应用需要重启才能继续完成");
  168. },
  169. });
  170. uni.showModal({
  171. title: "温馨提示",
  172. content: "应用将重启以完成更新",
  173. showCancel: false,
  174. complete: () => {
  175. plus.runtime.restart();
  176. },
  177. });
  178. } else {
  179. console.log('获取当前系统版本信息')
  180. //获取当前系统版本信息
  181. plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
  182. //请求后台接口 解析数据 对比版本
  183. that.$Request.getT("/app/user/selectNewApp").then((res) => {
  184. res = res.data[0];
  185. console.log('当前版本:',widgetInfo.version+'线上版本:'+res.version)
  186. if (res.wgtUrl && widgetInfo.version < res.version) {
  187. console.log('进入更新逻辑')
  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. if(true){
  242. console.log('直接进行安装')
  243. uni.removeStorageSync("updated");
  244. plus.runtime.install(packgePath, {
  245. force: true,
  246. }, (res) => {
  247. console.log('安装成功', res)
  248. }, (err) => {
  249. console.log('安装失败', err)
  250. });
  251. uni.setStorage({
  252. key: "updated",
  253. data: {
  254. completed: true,
  255. packgePath: packgePath,
  256. },
  257. success: (res) => {
  258. console.log("成功安装上次的更新,应用需要重启才能继续完成");
  259. },
  260. });
  261. uni.showModal({
  262. title: "温馨提示",
  263. content: "应用将重启以完成更新",
  264. showCancel: false,
  265. complete: () => {
  266. plus.runtime.restart();
  267. },
  268. });
  269. }else{
  270. uni.setStorage({
  271. key: "updated",
  272. data: {
  273. completed: false,
  274. packgePath: packgePath,
  275. },
  276. success: () => {
  277. console.log("成功保存记录");
  278. },
  279. });
  280. }
  281. // 任务完成,关闭下载任务
  282. console.log(
  283. "任务完成,关闭下载任务,下一次启动应用时将安装更新"
  284. );
  285. downloadTask.abort();
  286. downloadTask = null;
  287. },
  288. });
  289. }
  290. },
  291. });
  292. } else {
  293. console.log("下载地址未准备,无法开启下载任务");
  294. }
  295. } else {
  296. //不是热更新是在线更新 校验是否强制升级
  297. if (res.method == "true") {
  298. uni.showModal({
  299. showCancel: false,
  300. confirmText: "立即更新",
  301. title: "发现新版本",
  302. content: res.des,
  303. success: (res) => {
  304. if (res.confirm) {
  305. that.$queue.showLoading("下载中...");
  306. if (uni.getSystemInfoSync().platform == "android") {
  307. uni.downloadFile({
  308. url: androidLink,
  309. success: (downloadResult) => {
  310. if (downloadResult.statusCode === 200) {
  311. plus.runtime.install(
  312. downloadResult.tempFilePath,
  313. {
  314. force: false,
  315. },
  316. (d) => {
  317. console.log("install success...");
  318. plus.runtime.restart();
  319. },
  320. (e) => {
  321. console.error("install fail...");
  322. }
  323. );
  324. }
  325. },
  326. });
  327. }
  328. if (uni.getSystemInfoSync().platform == "ios") {
  329. plus.runtime.openURL(iosLink, function (res) {});
  330. }
  331. } else if (res.cancel) {
  332. console.log("取消");
  333. }
  334. },
  335. });
  336. } else {
  337. uni.showModal({
  338. title: "发现新版本",
  339. confirmText: "立即更新",
  340. cancelText: "下次更新",
  341. content: res.des,
  342. success: (res) => {
  343. if (res.confirm) {
  344. that.$queue.showLoading("下载中...");
  345. if (uni.getSystemInfoSync().platform == "android") {
  346. uni.downloadFile({
  347. url: androidLink,
  348. success: (downloadResult) => {
  349. if (downloadResult.statusCode === 200) {
  350. plus.runtime.install(
  351. downloadResult.tempFilePath,
  352. {
  353. force: false,
  354. },
  355. (d) => {
  356. console.log("install success...");
  357. plus.runtime.restart();
  358. },
  359. (e) => {
  360. console.error("install fail...");
  361. }
  362. );
  363. }
  364. },
  365. });
  366. }
  367. if (uni.getSystemInfoSync().platform == "ios") {
  368. plus.runtime.openURL(iosLink, function (res) {});
  369. }
  370. } else if (res.cancel) {
  371. console.log("取消");
  372. }
  373. },
  374. });
  375. }
  376. }
  377. }
  378. });
  379. });
  380. }
  381. //#endif
  382. // #ifdef APP-PLUS
  383. // 检查是否首次启动 - 引导页逻辑
  384. let firstUpload = uni.getStorageSync("firstUpload") || false;
  385. let token = this.$queue.getData('token')
  386. let userType = this.$queue.getData('userType')
  387. let companyStatus = this.$queue.getData('companyStatus')
  388. if (!firstUpload) {
  389. // 跳转到引导页
  390. uni.reLaunch({
  391. url: "/pages/my/jobApplicant/startPage",
  392. success: () => {
  393. // 标记已经显示过引导页
  394. uni.setStorageSync("firstUpload", true);
  395. }
  396. });
  397. // 这里需要return,避免执行后面的代码
  398. return;
  399. } else if (
  400. token &&
  401. (!userType || (userType == 2 && companyStatus != 2))
  402. ) {
  403. // 有登录token,但是没有userType,跳转选择角色页面,强制用户选择
  404. // 有登录token,并且userType为2,但是公司状态没有通过
  405. uni.reLaunch({
  406. url: '/pages/my/jobApplicant/guidePage',
  407. })
  408. return
  409. } else if (token && userType) {
  410. // 已经登录,且有userType
  411. uni.reLaunch({
  412. url: '/pages/index/index',
  413. })
  414. }
  415. // #endif
  416. },
  417. onShow: function () {
  418. // uni.removeStorageSync('firstLogin');
  419. // uni.removeStorageSync('firstUpload');
  420. //关键词过滤 602
  421. this.$Request.getT("/app/common/type/602").then((res) => {
  422. if (res.code == 0) {
  423. if (res.data && res.data.value) {
  424. this.$queue.setData("chatSearchKeys", res.data.value);
  425. }
  426. }
  427. });
  428. // 小程序是否上线
  429. // this.$Request.get('/app/common/type/238').then(res => {
  430. // if (res.code == 0) {
  431. // // #ifdef MP-WEIXIN
  432. // this.$queue.setData('XCXIsSelect', res.data.value);
  433. // // #endif
  434. // // #ifndef MP-WEIXIN
  435. // this.$queue.setData('XCXIsSelect', '是');
  436. // // #endif
  437. // }
  438. // });
  439. this.$Request.get("/app/common/type/257").then((res) => {
  440. if (res.code == 0) {
  441. // #ifdef MP-WEIXIN
  442. this.$queue.setData("XCXIsSelect", res.data.value);
  443. // #endif
  444. // #ifndef MP-WEIXIN
  445. this.$queue.setData("XCXIsSelect", "是");
  446. // #endif
  447. }
  448. });
  449. //用户客服
  450. // 企业微信链接 274
  451. this.$Request.get("/app/common/type/322").then((res) => {
  452. if (res.code == 0) {
  453. this.$queue.setData("kefu", res.data.value);
  454. }
  455. });
  456. // 企业微信客服APPID 275
  457. this.$Request.get("/app/common/type/324").then((res) => {
  458. if (res.code == 0) {
  459. this.$queue.setData("kefuAppid", res.data.value);
  460. }
  461. });
  462. //企业端客服
  463. this.$Request.get("/app/common/type/321").then((res) => {
  464. if (res.code == 0) {
  465. this.$queue.setData("kefuq", res.data.value);
  466. }
  467. });
  468. // 企业微信客服APPID 275
  469. this.$Request.get("/app/common/type/323").then((res) => {
  470. if (res.code == 0) {
  471. this.$queue.setData("kefuAppidq", res.data.value);
  472. }
  473. });
  474. // 企业会员每天免费联系次数 421
  475. this.$Request.get("/app/common/type/421").then((res) => {
  476. if (res.code == 0) {
  477. this.$queue.setData("vipMsgNum", res.data.value);
  478. }
  479. });
  480. // 企业非会员每天免费联系次数 422
  481. this.$Request.get("/app/common/type/422").then((res) => {
  482. if (res.code == 0) {
  483. this.$queue.setData("msgNum", res.data.value);
  484. }
  485. });
  486. // 企业会员每次联系价格 419
  487. this.$Request.get("/app/common/type/419").then((res) => {
  488. if (res.code == 0) {
  489. this.$queue.setData("vipMsgPrice", res.data.value);
  490. }
  491. });
  492. // 企业非会员每次联系价格 420
  493. this.$Request.get("/app/common/type/420").then((res) => {
  494. if (res.code == 0) {
  495. this.$queue.setData("msgPrice", res.data.value);
  496. }
  497. });
  498. //腾讯云实时语音SDKAppID
  499. this.$Request.get("/app/common/type/814").then((res) => {
  500. if (res.code == 0) {
  501. uni.setStorageSync("sdkAppId", res.data.value);
  502. }
  503. });
  504. console.log("App Show");
  505. // #ifdef H5
  506. // let sysTem = uni.getSystemInfoSync()
  507. // if (sysTem.model == 'PC') { //如果是pc访问移动端域名
  508. // this.$Request.get('/app/common/type/432').then(res => {
  509. // if (res.code == 0) {
  510. // if (res.data.value == '是') {
  511. // this.$Request.get('/app/common/type/433').then(ree => {
  512. // if (ree.code == 0) {
  513. // if (ree.data.value) {
  514. // window.location.href = ree.data.value;
  515. // }
  516. // }
  517. // })
  518. // }
  519. // }
  520. // })
  521. // }
  522. // #endif
  523. // #ifdef APP-PLUS
  524. if (uni.getSystemInfoSync().platform == "android") {
  525. let clientid = plus.push.getClientInfo().clientid;
  526. let userId = this.$queue.getData("userId");
  527. if (userId) {
  528. this.$Request
  529. .postT("/app/user/updateClientId?clientId=" + clientid + "&userId=" + userId)
  530. .then((res) => {});
  531. }
  532. }
  533. //#endif
  534. //#ifdef H5
  535. let isopen = false;
  536. this.$Request.get("/app/common/type/237").then((res) => {
  537. if (res.data.value == "是") {
  538. isopen = true;
  539. }
  540. });
  541. if (isopen) {
  542. let ua = navigator.userAgent.toLowerCase();
  543. if (ua.indexOf("micromessenger") !== -1) {
  544. let openid = uni.getStorageSync("openid");
  545. let userId = uni.getStorageSync("userId");
  546. let that = this;
  547. if (!openid) {
  548. if (
  549. window.location.href.indexOf("?code=") !== -1 ||
  550. window.location.href.indexOf("&code=") !== -1
  551. ) {
  552. let code;
  553. if (window.location.href.indexOf("?code=") !== -1) {
  554. code = window.location.href.split("?code=")[1].split("&")[0];
  555. } else {
  556. code = window.location.href.split("&code=")[1].split("&")[0];
  557. }
  558. this.$Request.get("/app/Login/getOpenId?code=" + code).then((ret) => {
  559. uni.setStorageSync("openId", ret.data);
  560. this.$Request
  561. .get("/app/Login/openid/login?openId=" + ret.data)
  562. .then((res) => {
  563. this.$queue.setData("userId", res.user.userId);
  564. this.$queue.setData("token", res.token);
  565. this.$queue.setData("phone", res.user.phone);
  566. this.$queue.setData("userName", res.user.userName);
  567. this.$queue.setData("avatar", res.user.avatar);
  568. this.$queue.setData("invitationCode", res.user.invitationCode);
  569. this.$queue.setData("inviterCode", res.user.inviterCode);
  570. });
  571. });
  572. } else {
  573. this.$Request.get("/app/common/type/108").then((res) => {
  574. if (res.data.value == "是") {
  575. window.location.href =
  576. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  577. that.$queue.getWxAppid() +
  578. "&redirect_uri=" +
  579. window.location.href.split("#")[0] +
  580. "&response_type=code&scope=snsapi_userinfo#wechat_redirect";
  581. }
  582. });
  583. }
  584. }
  585. if (userId && openid) {
  586. this.$Request
  587. .get("/app/Login/bindOpenId?userId=" + userId + "&openId=" + openid)
  588. .then((res) => {
  589. });
  590. }
  591. }
  592. }
  593. //#endif
  594. },
  595. onHide: function () {
  596. console.log("App Hide");
  597. },
  598. methods: {
  599. // 初始化极光推送
  600. initJPush() {
  601. // 确保在App环境下执行(H5/小程序不支持)
  602. if (uni.getSystemInfoSync().platform === 'android' || uni.getSystemInfoSync().platform === 'ios') {
  603. const jpushModule = uni.requireNativePlugin('JG-JPush')
  604. if (!jpushModule) {
  605. console.error('极光推送插件未找到,请检查导入和调试基座')
  606. return;
  607. }
  608. jpushModule.initJPushService()
  609. // 监听:点击通知(用户点击通知栏的通知)
  610. jpushModule.addNotificationListener((res) => {
  611. console.log('点击了通知:', res)
  612. // 统一活动广告:extras 带 adImage / imageUrl / img 时弹出(与 page 可同时存在)
  613. if (res.notificationEventType == 'notificationOpened' && res.extras && res.extras?.notice_type == 'system_notice') {
  614. setTimeout(() => {
  615. // 跳转我的页面后再打开公告
  616. uni.switchTab({
  617. url: '/pages/index/index',
  618. success: () => {
  619. openPushAd({
  620. adImage: res.extras?.notice_image_url
  621. })
  622. }
  623. })
  624. }, 500)
  625. }
  626. // 可在这里跳转到指定页面(比如根据通知的extra参数跳转)
  627. if (res.notificationEventType == 'notificationOpened' && res.extras && res.extras.page) {
  628. // tab页面
  629. // /pages/index/index
  630. // /pages/talentSearch/index
  631. // /pages/index/game/gameList
  632. // /pages/msg/index
  633. // /pages/my/index
  634. const tabPages = [
  635. '/pages/index/index',
  636. '/pages/talentSearch/index',
  637. '/pages/index/game/gameList',
  638. '/pages/msg/index',
  639. '/pages/my/index'
  640. ]
  641. setTimeout(() => {
  642. if (tabPages.includes(res.extras?.page)) {
  643. uni.switchTab({
  644. url: res.extras.page // 例如:/pages/detail/detail?id=123
  645. })
  646. } else {
  647. uni.navigateTo({
  648. url: res.extras.page
  649. })
  650. }
  651. }, 500)
  652. }
  653. })
  654. const saveRid = (rid) => {
  655. if (!rid) return false
  656. this.$queue.setData('registerID', rid)
  657. console.log('jpushModule registerID:', rid)
  658. return true
  659. }
  660. const tryGetRid = (maxTry = 12) => {
  661. let n = 0
  662. const run = () => {
  663. jpushModule.getRegistrationID((res) => {
  664. console.log('获取设备ID', res)
  665. // 不同版本字段名可能不同,这里做兼容
  666. const rid = res?.registerID || res?.registrationID || res?.registrationId
  667. if (res?.code === 0 && saveRid(rid)) return
  668. n++
  669. if (n >= maxTry) {
  670. console.warn('jpushModule registerID empty after retry:', res)
  671. return
  672. }
  673. setTimeout(run, 400 * n) // 递增重试
  674. })
  675. }
  676. run()
  677. }
  678. jpushModule.addConnectEventListener && jpushModule.addConnectEventListener((result) => {
  679. console.log('jpushModule connect:', result)
  680. if (result.connectEnable) {
  681. tryGetRid(12)
  682. }
  683. })
  684. tryGetRid(12)
  685. // jpushModule.getRegistrationID((res) => {
  686. // if (res.code === 0) {
  687. // console.log('获取设备ID', res)
  688. // this.$queue.setData('registerID', res?.registerID || '')
  689. // } else {
  690. // console.error('获取RegistrationID失败:', res)
  691. // }
  692. // })
  693. }
  694. },
  695. }
  696. };
  697. </script>
  698. <style lang="scss">
  699. /*每个页面公共css */
  700. @import "uview-ui/index.scss";
  701. @import "components/colorui/main.css";
  702. @import "components/colorui/icon.css";
  703. page {
  704. background-color: #ffffff;
  705. color: #343546;
  706. }
  707. .bg {
  708. background-color: #f7f7f7;
  709. }
  710. /*文本省略*/
  711. .m-ellipsis {
  712. overflow: hidden;
  713. white-space: nowrap;
  714. text-overflow: ellipsis;
  715. }
  716. .m-ellipsis-l2,
  717. .m-ellipsis-l3 {
  718. display: -webkit-box;
  719. overflow: hidden;
  720. text-overflow: ellipsis;
  721. -webkit-box-orient: vertical;
  722. word-break: break-all;
  723. }
  724. .m-ellipsis-l2 {
  725. -webkit-line-clamp: 2;
  726. }
  727. .m-ellipsis-l3 {
  728. -webkit-line-clamp: 3;
  729. }
  730. .popup-content .popup-text-permission{
  731. padding: 100rpx;
  732. color: #343546;
  733. }
  734. </style>