App.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. // setInterval(d => { //定时器,定时去调取聊天未读消息
  5. // let userId = uni.getStorageSync('userId')
  6. // if (userId) {
  7. // this.$Request.get('/app/chat/selectChatCount').then(res => {
  8. // if (res.code === 0) {
  9. // let chatCount = res.data.chatCount
  10. // let messageCount = res.data.messageCount
  11. // uni.setStorageSync('messageCount', messageCount)
  12. // let num = chatCount + messageCount
  13. // if (num == 0) {
  14. // uni.removeTabBarBadge({
  15. // index: 1
  16. // })
  17. // return;
  18. // }
  19. // uni.setTabBarBadge({
  20. // index: 1,
  21. // text: num + ""
  22. // })
  23. // }
  24. // });
  25. // }
  26. // }, 3000);
  27. //#ifdef APP-PLUS
  28. // APP检测更新 具体打包流程可以参考:https://ask.dcloud.net.cn/article/35667
  29. plus.screen.lockOrientation('portrait-primary'); //竖屏正方向锁定
  30. //获取是否热更新过
  31. const updated = uni.getStorageSync('updated'); // 尝试读取storage
  32. if (updated.completed === true) {
  33. // 如果上次刚更新过
  34. // 删除安装包及安装记录
  35. console.log('安装记录被删除,更新成功');
  36. uni.removeSavedFile({
  37. filePath: updated.packgePath,
  38. success: res => {
  39. uni.removeStorageSync('updated');
  40. }
  41. });
  42. } else if (updated.completed === false) {
  43. uni.removeStorageSync('updated');
  44. plus.runtime.install(updated.packgePath, {
  45. force: true
  46. });
  47. uni.setStorage({
  48. key: 'updated',
  49. data: {
  50. completed: true,
  51. packgePath: updated.packgePath
  52. },
  53. success: res => {
  54. console.log('成功安装上次的更新,应用需要重启才能继续完成');
  55. }
  56. });
  57. uni.showModal({
  58. title: '温馨提示',
  59. content: '应用将重启以完成更新',
  60. showCancel: false,
  61. complete: () => {
  62. plus.runtime.restart();
  63. }
  64. });
  65. } else {
  66. //获取当前系统版本信息
  67. plus.runtime.getProperty(plus.runtime.appid, widgetInfo => {
  68. //请求后台接口 解析数据 对比版本
  69. let data = {
  70. classify: 1
  71. }
  72. this.$Request.getT('/app/user/selectNewApp', data).then(res => {
  73. res = res.data[0];
  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. let that = this;
  80. //校验是是不是热更新
  81. if (res.wgtUrl.match(RegExp(/.wgt/))) {
  82. // 判断系统类型
  83. if (plus.os.name.toLowerCase() === 'android') {
  84. console.log('安卓系统');
  85. if (androidLink && androidLink !== '#') {
  86. // 我这里默认#也是没有地址,请根据业务自行修改
  87. console.log('发现下载地址');
  88. // 安卓:创建下载任务
  89. if (androidLink.match(RegExp(/.wgt/))) {
  90. console.log('确认wgt热更新包');
  91. downloadLink = androidLink;
  92. ready = true;
  93. } else {
  94. console.log('安卓推荐.wgt强制更新,.apk的强制更新请您自行修改程序');
  95. }
  96. } else {
  97. console.log('下载地址是空的,无法继续');
  98. }
  99. } else {
  100. console.log('苹果系统');
  101. if (iosLink && iosLink !== '#') {
  102. // 我这里默认#也是没有地址,请根据业务自行修改
  103. console.log('发现下载地址');
  104. // 苹果(A):进行热更新(如果iosLink是wgt更新包的下载地址)判断文件名中是否含有.wgt
  105. if (iosLink.match(RegExp(/.wgt/))) {
  106. console.log('确认wgt热更新包');
  107. downloadLink = iosLink;
  108. ready = true;
  109. } else {
  110. console.log('苹果只支持.wgt强制更新');
  111. }
  112. } else {
  113. console.log('下载地址是空的,无法继续');
  114. }
  115. }
  116. if (ready) {
  117. console.log('任务开始');
  118. let downloadTask = uni.downloadFile({
  119. url: downloadLink,
  120. success: res => {
  121. if (res.statusCode === 200) {
  122. // 保存下载的安装包
  123. console.log('保存安装包');
  124. uni.saveFile({
  125. tempFilePath: res.tempFilePath,
  126. success: res => {
  127. const packgePath = res
  128. .savedFilePath;
  129. // 保存更新记录到stroage,下次启动app时安装更新
  130. uni.setStorage({
  131. key: 'updated',
  132. data: {
  133. completed: false,
  134. packgePath: packgePath
  135. },
  136. success: () => {
  137. console
  138. .log(
  139. '成功保存记录'
  140. );
  141. }
  142. });
  143. // 任务完成,关闭下载任务
  144. console.log(
  145. '任务完成,关闭下载任务,下一次启动应用时将安装更新'
  146. );
  147. downloadTask.abort();
  148. downloadTask = null;
  149. }
  150. });
  151. }
  152. }
  153. });
  154. } else {
  155. console.log('下载地址未准备,无法开启下载任务');
  156. }
  157. } else {
  158. //不是热更新是在线更新 校验是否强制升级
  159. if (res.method == 'true') {
  160. uni.showModal({
  161. showCancel: false,
  162. confirmText: '立即更新',
  163. title: '发现新版本',
  164. content: res.des,
  165. success: res => {
  166. if (res.confirm) {
  167. that.$queue.showLoading('下载中...');
  168. if (uni.getSystemInfoSync().platform ==
  169. 'android') {
  170. uni.downloadFile({
  171. url: androidLink,
  172. success: downloadResult => {
  173. if (downloadResult
  174. .statusCode ===
  175. 200) {
  176. plus.runtime
  177. .install(
  178. downloadResult
  179. .tempFilePath, {
  180. force: false
  181. },
  182. d => {
  183. console
  184. .log(
  185. 'install success...'
  186. );
  187. plus.runtime
  188. .restart();
  189. },
  190. e => {
  191. console
  192. .error(
  193. 'install fail...'
  194. );
  195. }
  196. );
  197. }
  198. }
  199. });
  200. }
  201. if (uni.getSystemInfoSync().platform ==
  202. 'ios') {
  203. plus.runtime.openURL(iosLink, function(
  204. res) {});
  205. }
  206. } else if (res.cancel) {
  207. console.log('取消');
  208. }
  209. }
  210. });
  211. } else {
  212. uni.showModal({
  213. title: '发现新版本',
  214. confirmText: '立即更新',
  215. cancelText: '下次更新',
  216. content: res.des,
  217. success: res => {
  218. if (res.confirm) {
  219. that.$queue.showLoading('下载中...');
  220. if (uni.getSystemInfoSync().platform ==
  221. 'android') {
  222. uni.downloadFile({
  223. url: androidLink,
  224. success: downloadResult => {
  225. if (downloadResult
  226. .statusCode ===
  227. 200) {
  228. plus.runtime
  229. .install(
  230. downloadResult
  231. .tempFilePath, {
  232. force: false
  233. },
  234. d => {
  235. console
  236. .log(
  237. 'install success...'
  238. );
  239. plus.runtime
  240. .restart();
  241. },
  242. e => {
  243. console
  244. .error(
  245. 'install fail...'
  246. );
  247. }
  248. );
  249. }
  250. }
  251. });
  252. }
  253. if (uni.getSystemInfoSync().platform ==
  254. 'ios') {
  255. plus.runtime.openURL(iosLink, function(
  256. res) {});
  257. }
  258. } else if (res.cancel) {
  259. console.log('取消');
  260. }
  261. }
  262. });
  263. }
  264. }
  265. }
  266. });
  267. });
  268. }
  269. //#endif
  270. },
  271. onShow: function() {
  272. this.$Request.get('/app/common/type/297').then(res => {
  273. if (res.code == 0) {
  274. // #ifdef MP-WEIXIN
  275. this.$queue.setData('XCXIsSelect', res.data.value);
  276. // #endif
  277. // #ifndef MP-WEIXIN
  278. this.$queue.setData('XCXIsSelect', '是');
  279. // #endif
  280. }
  281. });
  282. // this.$Request.get('/app/common/type/297').then(res => {
  283. // if (res.code == 0) {
  284. // // #ifdef MP-WEIXIN
  285. // this.$queue.setData('XCXIsSelect', res.data.value);
  286. // // #endif
  287. // // #ifndef MP-WEIXIN
  288. // this.$queue.setData('XCXIsSelect', '是');
  289. // // #endif
  290. // }
  291. // });
  292. // 用户端联系方式 1 手机号 2企业微信 301
  293. this.$Request.get('/app/common/type/301').then(res => {
  294. if (res.code == 0) {
  295. this.$queue.setData('kefu', res.data.value);
  296. }
  297. });
  298. // 用户端客服手机号 302
  299. this.$Request.get('/app/common/type/302').then(res => {
  300. if (res.code == 0) {
  301. this.$queue.setData('kefuPhone', res.data.value);
  302. }
  303. });
  304. // 用户端企业微信AppId 303
  305. this.$Request.get('/app/common/type/303').then(res => {
  306. if (res.code == 0) {
  307. this.$queue.setData('kefuAppId', res.data.value);
  308. }
  309. });
  310. //用户端企业微信链接 304
  311. this.$Request.get('/app/common/type/304').then(res => {
  312. if (res.code == 0) {
  313. this.$queue.setData('kefuUrl', res.data.value);
  314. }
  315. });
  316. //是否开启会员 321
  317. this.$Request.get('/app/common/type/321').then(res => {
  318. if (res.code == 0) {
  319. this.$queue.setData('hyCheck', res.data.value);
  320. }
  321. });
  322. //是否开启推广 322
  323. this.$Request.get('/app/common/type/322').then(res => {
  324. if (res.code == 0) {
  325. this.$queue.setData('tgCheck', res.data.value);
  326. }
  327. });
  328. //超出公里数 324
  329. this.$Request.get('/app/common/type/324').then(res => {
  330. if (res.code == 0) {
  331. this.$queue.setData('glsNum', res.data.value);
  332. }
  333. });
  334. //用户是否可以取消订单 377
  335. this.$Request.get('/app/common/type/377').then(res => {
  336. if (res.code == 0) {
  337. this.$queue.setData('yhqxSel', res.data.value);
  338. }
  339. });
  340. // 提现底部提示 326
  341. this.$Request.get('/app/common/type/326').then(res => {
  342. if (res.code == 0) {
  343. this.$queue.setData('txMsg', res.data.value);
  344. }
  345. });
  346. //是否开启阿里云隐私电话 383
  347. this.$Request.get('/app/common/type/383').then(res => {
  348. if (res.code == 0) {
  349. this.$queue.setData('aliphone', res.data.value);
  350. }
  351. });
  352. // 是否开启微信提现 389
  353. this.$Request.get('/app/common/type/389').then(res => {
  354. if (res.code == 0) {
  355. this.$queue.setData('wxTxSel', res.data.value);
  356. }
  357. });
  358. // 是否开启银联提现 378
  359. this.$Request.get('/app/common/type/378').then(res => {
  360. if (res.code == 0) {
  361. this.$queue.setData('ylTxSel', res.data.value);
  362. }
  363. });
  364. // 是否开启为技师充值 390
  365. this.$Request.get('/app/common/type/390').then(res => {
  366. if (res.code == 0) {
  367. this.$queue.setData('jsczSel', res.data.value);
  368. }
  369. });
  370. // 忙时时间切换 1半个小时 2一个小时 392
  371. this.$Request.get('/app/common/type/392').then(res => {
  372. if (res.code == 0) {
  373. this.$queue.setData('msTimeDate', res.data.value);
  374. }
  375. });
  376. // 取消订单扣除百分比 419
  377. this.$Request.get('/app/common/type/419').then(res => {
  378. if (res.code == 0) {
  379. this.$queue.setData('closeKC', res.data.value);
  380. }
  381. });
  382. // 技师详情顶部图高度 421
  383. this.$Request.get('/app/common/type/421').then(res => {
  384. if (res.code == 0) {
  385. this.$queue.setData('imageHeight', res.data.value);
  386. }
  387. });
  388. // 是否开启用户端删除订单 427
  389. this.$Request.get('/app/common/type/427').then(res => {
  390. if (res.code == 0) {
  391. this.$queue.setData('userDeletaSel', res.data.value);
  392. }
  393. });
  394. // 邀请好友是否使用公众号分享 805
  395. this.$Request.get('/app/common/type/805').then(res => {
  396. if (res.code == 0) {
  397. // #ifdef H5
  398. this.$queue.setData('gzhYaoQing', res.data.value);
  399. // #endif
  400. // #ifndef H5
  401. this.$queue.setData('gzhYaoQing', '否');
  402. // #endif
  403. }
  404. });
  405. let userId = this.$queue.getData("userId")
  406. if (userId) {
  407. this.$Request.getT('/app/user/selectUserById').then(res => {
  408. if (res.code == 0) {
  409. if (res.data && res.data.status == 2) {
  410. uni.showModal({
  411. title: '账号已被封禁',
  412. content: '请在【我的客服】申诉,申诉成功后重新登录',
  413. showCancel: false,
  414. cancelText: '',
  415. confirmText: '我知道了',
  416. success: res => {
  417. uni.clearStorageSync()
  418. },
  419. fail: () => {},
  420. complete: () => {}
  421. });
  422. }
  423. }
  424. })
  425. }
  426. console.log('App Show')
  427. // #ifdef APP-PLUS
  428. let clientid = plus.push.getClientInfo().clientid;
  429. let sysPhone = 1;
  430. if (plus.os.name.toLowerCase() === 'android') {
  431. sysPhone = 1;
  432. } else {
  433. sysPhone = 2;
  434. }
  435. let userIds = this.$queue.getData('userId');
  436. if (userIds) {
  437. this.$Request.postT('/app/user/updateClientId?clientId=' + clientid + '&userId=' + userIds + '&sysPhone=' + sysPhone).then(
  438. res => {});
  439. }
  440. //#endif
  441. // #ifdef H5
  442. let ua = navigator.userAgent.toLowerCase();
  443. console.log(ua.indexOf('micromessenger'))
  444. if (ua.indexOf('micromessenger') === -1) {
  445. this.$Request.get('/app/common/type/318').then(res => {
  446. if (res.code == 0 && res.data && res.data.value === '否') {
  447. if (window.location.href.indexOf('/pages/my/erweimaRegister') === -1) {
  448. uni.reLaunch({
  449. url: '/pages/my/erweimaRegister'
  450. })
  451. }
  452. }
  453. });
  454. }
  455. // #endif
  456. },
  457. onHide: function() {
  458. console.log('App Hide')
  459. }
  460. }
  461. </script>
  462. <style lang="scss">
  463. /*每个页面公共css */
  464. @import "uview-ui/index.scss";
  465. @import 'components/colorui/main.css';
  466. @import 'components/colorui/icon.css';
  467. page {
  468. background-color: #FFFFFF;
  469. color: #343546;
  470. }
  471. .bg {
  472. background-color: #F7F7F7;
  473. }
  474. </style>