App.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. this.$Request.get('/app/Login/getRiderOpenId?code=' + code).then(ret => {
  286. this.$queue.setData('openid', ret.data)
  287. this.$Request.get('/app/Login/wxOpenIdLogin?openId=' + ret.data + '&userType=2')
  288. .then(res => {
  289. this.$queue.setData("userId", res.user.userId);
  290. this.$queue.setData("token", res.token);
  291. this.$queue.setData("phone", res.user.phone);
  292. this.$queue.setData("userName", res.user.userName);
  293. this.$queue.setData("avatar", res.user.avatar);
  294. this.$queue.setData("invitationCode", res.user.invitationCode);
  295. this.$queue.setData("inviterCode", res.user.inviterCode);
  296. });
  297. });
  298. } else {
  299. window.location.href =
  300. 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
  301. that.$queue.getWxAppid() +
  302. '&redirect_uri=' +
  303. window.location.href.split('#')[0] +
  304. '&response_type=code&scope=snsapi_userinfo#wechat_redirect';
  305. }
  306. } else {
  307. this.$Request.get('/app/Login/wxOpenIdLogin?openId=' + openid + '&userType=2').then(res => {
  308. this.$queue.setData("userId", res.user.userId);
  309. this.$queue.setData("token", res.token);
  310. this.$queue.setData("phone", res.user.phone);
  311. this.$queue.setData("userName", res.user.userName);
  312. this.$queue.setData("avatar", res.user.avatar);
  313. this.$queue.setData("invitationCode", res.user.invitationCode);
  314. this.$queue.setData("inviterCode", res.user.inviterCode);
  315. });
  316. }
  317. }
  318. //#endif
  319. },
  320. onShow: function() {
  321. console.log('App Show')
  322. // #ifdef APP-PLUS
  323. if (uni.getSystemInfoSync().platform == 'android') {
  324. let clientid = plus.push.getClientInfo().clientid;
  325. let userId = this.$queue.getData('userId');
  326. if (userId) {
  327. // console.log(clientid, '----', userId)
  328. this.$Request.postT('/app/user/updateRiderClientId?clientId=' + clientid).then(
  329. res => {
  330. // console.log(res,'------------------')
  331. });
  332. }
  333. }
  334. //#endif
  335. // this.$Request.get('/app/common/type/308').then(res => {
  336. // if (res.code == 0) {
  337. // // #ifdef MP-WEIXIN
  338. // this.$queue.setData('XCXIsSelect', res.data.value);
  339. // // #endif
  340. // // #ifndef MP-WEIXIN
  341. // this.$queue.setData('XCXIsSelect', '是');
  342. // // #endif
  343. // }
  344. // });
  345. this.$Request.get('/app/common/type/341').then(res => {
  346. if (res.code == 0) {
  347. // #ifdef MP-WEIXIN
  348. this.$queue.setData('XCXIsSelect', res.data.value);
  349. // #endif
  350. // #ifndef MP-WEIXIN
  351. this.$queue.setData('XCXIsSelect', '是');
  352. // #endif
  353. }
  354. });
  355. //腾讯地图名字
  356. this.$Request.getT('/app/common/type/318').then(res => {
  357. if (res.code == 0) {
  358. if (res.data && res.data.value) {
  359. this.$queue.setData('mapName', res.data.value)
  360. }
  361. }
  362. });
  363. //腾讯地图key
  364. this.$Request.getT('/app/common/type/317').then(res => {
  365. if (res.code == 0) {
  366. if (res.data && res.data.value) {
  367. this.$queue.setData('mapKey', res.data.value)
  368. }
  369. }
  370. });
  371. this.$Request.getT('/app/common/type/331').then(res => {
  372. if (res.code === 0) {
  373. uni.setStorageSync('tuiguang', res.data.value)
  374. }
  375. });
  376. this.$Request.getT('/app/common/type/332').then(res => {
  377. if (res.code === 0) {
  378. uni.setStorageSync('tuiguangImg', res.data.value)
  379. }
  380. });
  381. // 判断账号是否封禁
  382. this.userId = this.$queue.getData("userId")
  383. if (this.userId) {
  384. this.$Request.getT('/app/userinfo/bannedFlag').then(res => {
  385. if (res.code == 0) {
  386. if (res.data == 2) {
  387. uni.showModal({
  388. title: '账号已被封禁',
  389. content: '请在【我的】【我的客服】申诉,申诉成功后重新登录',
  390. showCancel: false,
  391. cancelText: '',
  392. confirmText: '我知道了',
  393. success: res => {
  394. uni.clearStorageSync()
  395. },
  396. fail: () => {},
  397. complete: () => {}
  398. });
  399. }
  400. }
  401. })
  402. }
  403. },
  404. onHide: function() {
  405. console.log('App Hide')
  406. }
  407. }
  408. </script>
  409. <style lang="scss">
  410. /*每个页面公共css */
  411. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  412. @import "uview-ui/index.scss";
  413. @import 'components/colorui/main.css';
  414. @import 'components/colorui/icon.css';
  415. </style>