App.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. setInterval(d => { //定时器,定时去调取聊天未读消息
  5. let userId = uni.getStorageSync('userId')
  6. let token = uni.getStorageSync('token')
  7. // console.log("userId"+userId+ " token"+token)
  8. if (userId && token) {
  9. this.$Request.getT('/app/ordersChat/selectRiderAllUnreadCount').then(res => {
  10. if (res.code === 0) {
  11. let chatCount = res.data
  12. let messageCount = res.data
  13. uni.setStorageSync('messageCount', messageCount)
  14. let num = chatCount + messageCount
  15. if (num == 0) {
  16. uni.removeTabBarBadge({
  17. index: 1
  18. })
  19. return;
  20. }
  21. uni.setTabBarBadge({
  22. index: 1,
  23. text: num + ""
  24. })
  25. }
  26. });
  27. }
  28. }, 3000);
  29. //#ifdef APP-PLUS
  30. // APP检测更新 具体打包流程可以参考:https://ask.dcloud.net.cn/article/35667
  31. plus.screen.lockOrientation('portrait-primary'); //竖屏正方向锁定
  32. //获取是否热更新过
  33. const updated = uni.getStorageSync('updated'); // 尝试读取storage
  34. let that = this;
  35. if (updated.completed === true) {
  36. // 如果上次刚更新过
  37. // 删除安装包及安装记录
  38. console.log('安装记录被删除,更新成功');
  39. uni.removeSavedFile({
  40. filePath: updated.packgePath,
  41. success: res => {
  42. uni.removeStorageSync('updated');
  43. }
  44. });
  45. } else if (updated.completed === false) {
  46. uni.removeStorageSync('updated');
  47. plus.runtime.install(updated.packgePath, {
  48. force: true
  49. });
  50. uni.setStorage({
  51. key: 'updated',
  52. data: {
  53. completed: true,
  54. packgePath: updated.packgePath
  55. },
  56. success: res => {
  57. console.log('成功安装上次的更新,应用需要重启才能继续完成');
  58. }
  59. });
  60. uni.showModal({
  61. title: '温馨提示',
  62. content: '应用将重启以完成更新',
  63. showCancel: false,
  64. complete: () => {
  65. plus.runtime.restart();
  66. }
  67. });
  68. } else {
  69. //获取当前系统版本信息
  70. plus.runtime.getProperty(plus.runtime.appid, widgetInfo => {
  71. //请求后台接口 解析数据 对比版本
  72. that.$Request.getT('/app/user/selectNewApp').then(res => {
  73. res = res.data[1];
  74. if (res.wgtUrl && widgetInfo.version < res.version) {
  75. let downloadLink = '';
  76. let androidLink = res.androidWgtUrl;
  77. let iosLink = res.iosWgtUrl;
  78. let ready = false;
  79. //校验是是不是热更新
  80. if (res.wgtUrl.match(RegExp(/.wgt/))) {
  81. // 判断系统类型
  82. if (plus.os.name.toLowerCase() === 'android') {
  83. console.log('安卓系统');
  84. if (androidLink && androidLink !== '#') {
  85. // 我这里默认#也是没有地址,请根据业务自行修改
  86. console.log('发现下载地址');
  87. // 安卓:创建下载任务
  88. if (androidLink.match(RegExp(/.wgt/))) {
  89. console.log('确认wgt热更新包');
  90. downloadLink = androidLink;
  91. ready = true;
  92. } else {
  93. console.log('安卓推荐.wgt强制更新,.apk的强制更新请您自行修改程序');
  94. }
  95. } else {
  96. console.log('下载地址是空的,无法继续');
  97. }
  98. } else {
  99. console.log('苹果系统');
  100. if (iosLink && iosLink !== '#') {
  101. // 我这里默认#也是没有地址,请根据业务自行修改
  102. console.log('发现下载地址');
  103. // 苹果(A):进行热更新(如果iosLink是wgt更新包的下载地址)判断文件名中是否含有.wgt
  104. if (iosLink.match(RegExp(/.wgt/))) {
  105. console.log('确认wgt热更新包');
  106. downloadLink = iosLink;
  107. ready = true;
  108. } else {
  109. console.log('苹果只支持.wgt强制更新');
  110. }
  111. } else {
  112. console.log('下载地址是空的,无法继续');
  113. }
  114. }
  115. if (ready) {
  116. console.log('任务开始');
  117. let downloadTask = uni.downloadFile({
  118. url: downloadLink,
  119. success: res => {
  120. if (res.statusCode === 200) {
  121. // 保存下载的安装包
  122. console.log('保存安装包');
  123. uni.saveFile({
  124. tempFilePath: res.tempFilePath,
  125. success: res => {
  126. const packgePath = res
  127. .savedFilePath;
  128. // 保存更新记录到stroage,下次启动app时安装更新
  129. uni.setStorage({
  130. key: 'updated',
  131. data: {
  132. completed: false,
  133. packgePath: packgePath
  134. },
  135. success: () => {
  136. console
  137. .log(
  138. '成功保存记录'
  139. );
  140. }
  141. });
  142. // 任务完成,关闭下载任务
  143. console.log(
  144. '任务完成,关闭下载任务,下一次启动应用时将安装更新'
  145. );
  146. downloadTask.abort();
  147. downloadTask = null;
  148. }
  149. });
  150. }
  151. }
  152. });
  153. } else {
  154. console.log('下载地址未准备,无法开启下载任务');
  155. }
  156. } else {
  157. //不是热更新是在线更新 校验是否强制升级
  158. if (res.method == 'true') {
  159. uni.showModal({
  160. showCancel: false,
  161. confirmText: '立即更新',
  162. title: '发现新版本',
  163. content: res.des,
  164. success: res => {
  165. if (res.confirm) {
  166. that.$queue.showLoading('下载中...');
  167. if (uni.getSystemInfoSync().platform ==
  168. 'android') {
  169. uni.downloadFile({
  170. url: androidLink,
  171. success: downloadResult => {
  172. if (downloadResult
  173. .statusCode ===
  174. 200) {
  175. plus.runtime
  176. .install(
  177. downloadResult
  178. .tempFilePath, {
  179. force: false
  180. },
  181. d => {
  182. console
  183. .log(
  184. 'install success...'
  185. );
  186. plus.runtime
  187. .restart();
  188. },
  189. e => {
  190. console
  191. .error(
  192. 'install fail...'
  193. );
  194. }
  195. );
  196. }
  197. }
  198. });
  199. }
  200. if (uni.getSystemInfoSync().platform ==
  201. 'ios') {
  202. plus.runtime.openURL(iosLink, function(
  203. res) {});
  204. }
  205. } else if (res.cancel) {
  206. console.log('取消');
  207. }
  208. }
  209. });
  210. } else {
  211. uni.showModal({
  212. title: '发现新版本',
  213. confirmText: '立即更新',
  214. cancelText: '下次更新',
  215. content: res.des,
  216. success: res => {
  217. if (res.confirm) {
  218. that.$queue.showLoading('下载中...');
  219. if (uni.getSystemInfoSync().platform ==
  220. 'android') {
  221. uni.downloadFile({
  222. url: androidLink,
  223. success: downloadResult => {
  224. if (downloadResult
  225. .statusCode ===
  226. 200) {
  227. plus.runtime
  228. .install(
  229. downloadResult
  230. .tempFilePath, {
  231. force: false
  232. },
  233. d => {
  234. console
  235. .log(
  236. 'install success...'
  237. );
  238. plus.runtime
  239. .restart();
  240. },
  241. e => {
  242. console
  243. .error(
  244. 'install fail...'
  245. );
  246. }
  247. );
  248. }
  249. }
  250. });
  251. }
  252. if (uni.getSystemInfoSync().platform ==
  253. 'ios') {
  254. plus.runtime.openURL(iosLink, function(
  255. res) {});
  256. }
  257. } else if (res.cancel) {
  258. console.log('取消');
  259. }
  260. }
  261. });
  262. }
  263. }
  264. }
  265. });
  266. });
  267. }
  268. //#endif
  269. //#ifdef H5
  270. let ua = navigator.userAgent.toLowerCase();
  271. if (ua.indexOf('micromessenger') !== -1) {
  272. let openid = uni.getStorageSync('openid');
  273. let userId = uni.getStorageSync('userId');
  274. let that = this;
  275. console.log(openid)
  276. if (!openid) {
  277. if (window.location.href.indexOf('?code=') !== -1 || window.location.href.indexOf('&code=') !==
  278. -1) {
  279. let code;
  280. if (window.location.href.indexOf('?code=') !== -1) {
  281. code = window.location.href.split('?code=')[1].split('&')[0];
  282. } else {
  283. code = window.location.href.split('&code=')[1].split('&')[0];
  284. }
  285. let data = {
  286. code: code
  287. };
  288. this.$Request.get('/app/Login/getRiderOpenId',data).then(ret => {
  289. this.$queue.setData('openid', ret.data)
  290. let data2 = {
  291. openId: ret.data,
  292. userType:2
  293. };
  294. this.$Request.get('/app/Login/wxOpenIdLogin',data2)
  295. .then(res => {
  296. this.$queue.setData("userId", res.user.userId);
  297. this.$queue.setData("token", res.token);
  298. this.$queue.setData("phone", res.user.phone);
  299. this.$queue.setData("userName", res.user.userName);
  300. this.$queue.setData("avatar", res.user.avatar);
  301. this.$queue.setData("invitationCode", res.user.invitationCode);
  302. this.$queue.setData("inviterCode", res.user.inviterCode);
  303. });
  304. });
  305. } else {
  306. window.location.href =
  307. 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
  308. that.$queue.getWxAppid() +
  309. '&redirect_uri=' +
  310. window.location.href.split('#')[0] +
  311. '&response_type=code&scope=snsapi_userinfo#wechat_redirect';
  312. }
  313. } else {
  314. let data3 = {
  315. openId: openid,
  316. userType:2
  317. };
  318. this.$Request.get('/app/Login/wxOpenIdLogin',data3).then(res => {
  319. this.$queue.setData("userId", res.user.userId);
  320. this.$queue.setData("token", res.token);
  321. this.$queue.setData("phone", res.user.phone);
  322. this.$queue.setData("userName", res.user.userName);
  323. this.$queue.setData("avatar", res.user.avatar);
  324. this.$queue.setData("invitationCode", res.user.invitationCode);
  325. this.$queue.setData("inviterCode", res.user.inviterCode);
  326. });
  327. }
  328. }
  329. //#endif
  330. },
  331. onShow: function() {
  332. console.log('App Show')
  333. // #ifdef APP-PLUS
  334. if (uni.getSystemInfoSync().platform == 'android') {
  335. let clientid = plus.push.getClientInfo().clientid;
  336. let userId = this.$queue.getData('userId');
  337. if (userId) {
  338. // console.log(clientid, '----', userId)
  339. this.$Request.postT('/app/user/updateRiderClientId?clientId=' + clientid).then(
  340. res => {
  341. // console.log(res,'------------------')
  342. });
  343. }
  344. }
  345. //#endif
  346. // this.$Request.get('/app/common/type/308').then(res => {
  347. // if (res.code == 0) {
  348. // // #ifdef MP-WEIXIN
  349. // this.$queue.setData('XCXIsSelect', res.data.value);
  350. // // #endif
  351. // // #ifndef MP-WEIXIN
  352. // this.$queue.setData('XCXIsSelect', '是');
  353. // // #endif
  354. // }
  355. // });
  356. this.$Request.get('/app/common/type/341').then(res => {
  357. if (res.code == 0) {
  358. // #ifdef MP-WEIXIN
  359. this.$queue.setData('XCXIsSelect', res.data.value);
  360. // #endif
  361. // #ifndef MP-WEIXIN
  362. this.$queue.setData('XCXIsSelect', '是');
  363. // #endif
  364. }
  365. });
  366. //腾讯地图名字
  367. this.$Request.getT('/app/common/type/318').then(res => {
  368. if (res.code == 0) {
  369. if (res.data && res.data.value) {
  370. this.$queue.setData('mapName', res.data.value)
  371. }
  372. }
  373. });
  374. //腾讯地图key
  375. this.$Request.getT('/app/common/type/317').then(res => {
  376. if (res.code == 0) {
  377. if (res.data && res.data.value) {
  378. this.$queue.setData('mapKey', res.data.value)
  379. }
  380. }
  381. });
  382. this.$Request.getT('/app/common/type/331').then(res => {
  383. if (res.code === 0) {
  384. uni.setStorageSync('tuiguang', res.data.value)
  385. }
  386. });
  387. this.$Request.getT('/app/common/type/332').then(res => {
  388. if (res.code === 0) {
  389. uni.setStorageSync('tuiguangImg', res.data.value)
  390. }
  391. });
  392. // 判断账号是否封禁
  393. this.userId = this.$queue.getData("userId")
  394. if (this.userId) {
  395. this.$Request.getT('/app/userinfo/bannedFlag').then(res => {
  396. if (res.code == 0) {
  397. if (res.data == 2) {
  398. uni.showModal({
  399. title: '账号已被封禁',
  400. content: '请在【我的】【我的客服】申诉,申诉成功后重新登录',
  401. showCancel: false,
  402. cancelText: '',
  403. confirmText: '我知道了',
  404. success: res => {
  405. uni.clearStorageSync()
  406. },
  407. fail: () => {},
  408. complete: () => {}
  409. });
  410. }
  411. }
  412. })
  413. }
  414. },
  415. onHide: function() {
  416. console.log('App Hide')
  417. }
  418. }
  419. </script>
  420. <style lang="scss">
  421. /*每个页面公共css */
  422. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  423. @import "uview-ui/index.scss";
  424. @import 'components/colorui/main.css';
  425. @import 'components/colorui/icon.css';
  426. </style>