App.vue 4.5 KB

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