@lark-apaas/client-toolkit 1.1.32-alpha.1 → 1.1.32-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,11 @@ async function getSourceMap() {
28
28
  }
29
29
  const childApi = {
30
30
  getRoutes,
31
+ updateAppInfo: (appInfo)=>{
32
+ dispatchEvent(new CustomEvent('MiaoDaMetaInfoChanged', {
33
+ detail: appInfo
34
+ }));
35
+ },
31
36
  getSourceMap,
32
37
  apiProxy: {
33
38
  api_get: api_get,
@@ -28,16 +28,19 @@ const useAppInfo = ()=>{
28
28
  const handleMetaInfoChanged = async (info)=>{
29
29
  if (!info) info = await getAppInfo(true);
30
30
  updateDomInfo(info);
31
- setAppInfo(info);
31
+ setAppInfo((prev)=>({
32
+ ...prev,
33
+ ...info
34
+ }));
32
35
  };
33
36
  handleMetaInfoChanged();
34
- const onMessage = (e)=>{
35
- const data = e.data;
36
- if (data?.type === 'MiaoDaMetaInfoChanged') return void handleMetaInfoChanged(data.data);
37
+ const onUpdate = (e)=>{
38
+ const info = e.detail;
39
+ handleMetaInfoChanged(info);
37
40
  };
38
- window.addEventListener('message', onMessage);
41
+ window.addEventListener('MiaoDaMetaInfoChanged', onUpdate);
39
42
  return ()=>{
40
- window.removeEventListener('message', onMessage);
43
+ window.removeEventListener('MiaoDaMetaInfoChanged', onUpdate);
41
44
  };
42
45
  }, []);
43
46
  return {
@@ -1,3 +1,4 @@
1
+ import { AppInfoPayload } from "./common";
1
2
  export interface IframeMessage<T = unknown> {
2
3
  type: string;
3
4
  data: T;
@@ -55,6 +56,8 @@ export interface ParentApi {
55
56
  export interface ChildApi {
56
57
  getRoutes: () => Promise<any[]>;
57
58
  getSourceMap: () => Promise<string>;
59
+ /** 更新应用信息 */
60
+ updateAppInfo: (appInfo: AppInfoPayload) => void;
58
61
  apiProxy: {
59
62
  api_get: (url: string, config?: any) => Promise<any>;
60
63
  api_post: (url: string, data?: any, config?: any) => Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.1.32-alpha.1",
3
+ "version": "1.1.32-alpha.3",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [