App.vue 16 KB

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