App.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <script>
  2. import { GLOBALDATA, frontEndConfig, menu } from './config';
  3. import { common } from '@kasite/uni-app-base';
  4. import {
  5. useFrontEndConfigVersion,
  6. useSetFrontEndConfig,
  7. useAppStatus,
  8. useGetUpdateManager,
  9. useSmallProgramLogin,
  10. useSmallProgramLoginDiy,
  11. useGetSysAppPageList,
  12. usePreserMember,
  13. useSetFrontEndForm,
  14. useSetMenuList,
  15. useGetMemberIdByEncryptData,
  16. } from './hook';
  17. import { nextTick } from 'vue';
  18. let app = null;
  19. const beforeMain = async () => {
  20. common.showLoading();
  21. // 获取前端当前配置信息版本号 并控制是否 前端配置信息是否要重新获取
  22. await useFrontEndConfigVersion();
  23. // 获取前端配置信息
  24. let has = await useSetFrontEndConfig();
  25. // 判断获取配置信息是否成功 不成功不让往下
  26. if (has) return;
  27. // 判断应用状态,非运行中的应用跳转对应状态的缺省页
  28. // await useAppStatus();
  29. common.hideLoading();
  30. if (!app.globalData.logSuccess) {
  31. main();
  32. } else {
  33. // 配置判断是否需要互联网医院Websocket
  34. if (app.globalData.hasWebsocket) {
  35. // 链接websocket
  36. connectWebsocket(true);
  37. }
  38. }
  39. };
  40. const main = async function () {
  41. let isUpdateManager = false;
  42. // #ifndef APP || H5 || WEB
  43. // 判断如果是在开发过程 不检查是否存在新版本
  44. isUpdateManager =
  45. app.globalData.accountInfo.miniProgram.envVersion == 'develop'
  46. ? false
  47. : await useGetUpdateManager();
  48. // #endif
  49. /**如果有新版本 return */
  50. if (isUpdateManager) {
  51. return;
  52. }
  53. common.showLoading();
  54. // 同步获取设备信息
  55. app.globalData.smallPro_systemInfo = JSON.stringify(uni.getSystemInfoSync());
  56. // const resp = await useSmallProgramLogin(app);
  57. const resp = await useSmallProgramLoginDiy(app);
  58. if (resp) {
  59. // await getEncryptData();
  60. app.globalData.logSuccess = true;
  61. // await useGetSysAppPageList();
  62. // await usePreserMember();
  63. // 判断前端配置信息有修改获取form表单存储为空从新获取一遍form表单
  64. // if (
  65. // uni.getStorageSync('frontEndConfigRequest') ||
  66. // common.isEmpty(uni.getStorageSync('formConfigList'))
  67. // ) {
  68. // await useSetFrontEndForm(frontEndConfig);
  69. // }
  70. // 判断前端配置信息有修改获取菜单存储为空从新获取一遍菜单
  71. // if (
  72. // uni.getStorageSync('frontEndConfigRequest') ||
  73. // common.isEmpty(uni.getStorageSync('menuList'))
  74. // ) {
  75. // await useSetMenuList(menu);
  76. // }
  77. common.hideLoading();
  78. // 配置判断是否需要互联网医院Websocket
  79. if (app.globalData.hasWebsocket) {
  80. // 链接websocket
  81. // connectWebsocket(true);
  82. }
  83. /**判断是否登录成功回调 */
  84. if (app.loginReadyCallBack && typeof app.loginReadyCallBack == 'function') {
  85. app.loginReadyCallBack();
  86. }
  87. }
  88. };
  89. /** 解密 */
  90. const getEncryptData = async () => {
  91. // 只在 H5/WEB 端解析 URL 上的 EncryptData,兼容外部跳转进来的完整地址
  92. let encryptData = '';
  93. // #ifdef H5 || WEB
  94. try {
  95. // 例: https://fzsclqyy.com/KasiteWeb/module/hcrmUserCenter/index.html?EncryptData=xxx&token=xxx&openid=xxx#/
  96. // 先截掉 hash 部分,再解析 ? 后面的查询参数
  97. const url = (typeof window !== 'undefined' && window.location && window.location.href) ? window.location.href : '';
  98. const queryPart = url.split('?')[1]?.split('#')[0] || '';
  99. if (queryPart) {
  100. const params = new URLSearchParams(queryPart);
  101. encryptData = params.get('EncryptData') || '';
  102. }
  103. } catch (e) {
  104. console.error('解析 EncryptData 失败', e);
  105. }
  106. // #endif
  107. await useGetMemberIdByEncryptData(encryptData);
  108. }
  109. export default {
  110. globalData: GLOBALDATA,
  111. onLaunch: function (options) {
  112. console.log('App Launch');
  113. console.log('应用启动路径:', options.path);
  114. // #ifndef APP || WEB || H5 || MP-BAIDU || MP-TOUTIAO || MP-LARK
  115. // 保存 当前账号信息
  116. app = this.$scope;
  117. app.globalData.accountInfo = uni.getAccountInfoSync();
  118. // #endif
  119. // WEB只需要获取一次
  120. // #ifdef WEB
  121. app = getApp();
  122. beforeMain();
  123. // #endif
  124. },
  125. onShow: function (options) {
  126. console.log('App Show');
  127. console.log('应用启动路径:', options.path);
  128. // #ifndef WEB
  129. beforeMain();
  130. // #endif
  131. },
  132. onHide: function () {
  133. console.log('App Hide');
  134. },
  135. methods: {
  136. loginReadyCallBack: () => {},
  137. },
  138. };
  139. </script>
  140. <style lang="scss">
  141. @import '/theme/index';
  142. /* 隐藏所有页面的 navigationBar */
  143. uni-page-head {
  144. display: none;
  145. }
  146. </style>