App.vue 18 KB

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