App.vue 17 KB

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