@tmagic/editor 1.3.0-beta.5 → 1.3.0-beta.6

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.
@@ -38,7 +38,7 @@
38
38
  },
39
39
  __name: "CodeEditor",
40
40
  props: {
41
- initValues: {},
41
+ initValues: { default: "" },
42
42
  modifiedValues: {},
43
43
  type: {},
44
44
  language: { default: "javascript" },
@@ -786,47 +786,72 @@
786
786
  ...BaseFormConfig(),
787
787
  ...config,
788
788
  {
789
- type: "panel",
790
- title: "数据定义",
789
+ type: "tab",
791
790
  items: [
792
791
  {
793
- name: "fields",
794
- type: "data-source-fields",
795
- defaultValue: () => []
796
- }
797
- ]
798
- },
799
- {
800
- type: "panel",
801
- title: "方法定义",
802
- items: [
792
+ title: "数据定义",
793
+ items: [
794
+ {
795
+ name: "fields",
796
+ type: "data-source-fields",
797
+ defaultValue: () => []
798
+ }
799
+ ]
800
+ },
803
801
  {
804
- name: "methods",
805
- type: "data-source-methods",
806
- defaultValue: () => []
807
- }
808
- ]
809
- },
810
- {
811
- type: "panel",
812
- title: "事件配置",
813
- display: false,
814
- items: [
802
+ title: "方法定义",
803
+ items: [
804
+ {
805
+ name: "methods",
806
+ type: "data-source-methods",
807
+ defaultValue: () => []
808
+ }
809
+ ]
810
+ },
815
811
  {
816
- name: "events",
817
- src: "datasource",
818
- type: "event-select"
819
- }
820
- ]
821
- },
822
- {
823
- type: "panel",
824
- title: "mock数据",
825
- items: [
812
+ title: "事件配置",
813
+ display: false,
814
+ items: [
815
+ {
816
+ name: "events",
817
+ src: "datasource",
818
+ type: "event-select"
819
+ }
820
+ ]
821
+ },
822
+ {
823
+ title: "mock数据",
824
+ items: [
825
+ {
826
+ name: "mocks",
827
+ type: "data-source-mocks",
828
+ defaultValue: () => []
829
+ }
830
+ ]
831
+ },
832
+ {
833
+ title: "请求参数裁剪",
834
+ display: (formState, { model }) => model.type === "http",
835
+ items: [
836
+ {
837
+ name: "beforeRequest",
838
+ type: "vs-code",
839
+ parse: true,
840
+ height: "600px"
841
+ }
842
+ ]
843
+ },
826
844
  {
827
- name: "mocks",
828
- type: "data-source-mocks",
829
- defaultValue: () => []
845
+ title: "响应数据裁剪",
846
+ display: (formState, { model }) => model.type === "http",
847
+ items: [
848
+ {
849
+ name: "afterResponse",
850
+ type: "vs-code",
851
+ parse: true,
852
+ height: "600px"
853
+ }
854
+ ]
830
855
  }
831
856
  ]
832
857
  }
@@ -841,6 +866,62 @@
841
866
  return fillConfig$1(configs[type] || []);
842
867
  }
843
868
  };
869
+ const getFormValue = (type, values) => {
870
+ if (type !== "http") {
871
+ return values;
872
+ }
873
+ return {
874
+ beforeRequest: `(options, context) => {
875
+ /**
876
+ * 用户可以直接编写函数,在原始接口调用之前,会运行该函数,将这个函数的返回值作为该数据源接口的入参
877
+ *
878
+ * options: HttpOptions
879
+ *
880
+ * interface HttpOptions {
881
+ * // 请求链接
882
+ * url: string;
883
+ * // query参数
884
+ * params?: Record<string, string>;
885
+ * // body数据
886
+ * data?: Record<string, any>;
887
+ * // 请求头
888
+ * headers?: Record<string, string>;
889
+ * // 请求方法 GET/POST
890
+ * method?: Method;
891
+ * }
892
+ *
893
+ * context:上下文对象
894
+ *
895
+ * interface Content {
896
+ * app: AppCore;
897
+ * dataSource: HttpDataSource;
898
+ * }
899
+ *
900
+ * return: HttpOptions
901
+ */
902
+
903
+ // 此处的返回值会作为这个接口的入参
904
+ return options;
905
+ }`,
906
+ afterResponse: `(response, context) => {
907
+ /**
908
+ * 用户可以直接编写函数,在原始接口返回之后,会运行该函数,将这个函数的返回值作为该数据源接口的返回
909
+
910
+ * context:上下文对象
911
+ *
912
+ * interface Content {
913
+ * app: AppCore;
914
+ * dataSource: HttpDataSource;
915
+ * }
916
+ *
917
+ */
918
+
919
+ // 此处的返回值会作为这个接口的返回值
920
+ return response;
921
+ }`,
922
+ ...values
923
+ };
924
+ };
844
925
  const getDisplayField = (dataSources, key) => {
845
926
  const displayState = [];
846
927
  const matches = key.matchAll(/\$\{([\s\S]+?)\}/g);
@@ -1026,7 +1107,7 @@
1026
1107
  this.get("configs")[type] = config;
1027
1108
  }
1028
1109
  getFormValue(type = "base") {
1029
- return this.get("values")[type];
1110
+ return getFormValue(type, this.get("values")[type]);
1030
1111
  }
1031
1112
  setFormValue(type, value) {
1032
1113
  this.get("values")[type] = value;
@@ -4625,6 +4706,7 @@
4625
4706
  };
4626
4707
  const deleteHandler = (index) => {
4627
4708
  records.value.splice(index, 1);
4709
+ emit("change", getValue());
4628
4710
  };
4629
4711
  return (_ctx, _cache) => {
4630
4712
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$m, [
@@ -10376,6 +10458,7 @@
10376
10458
  exports.getDefaultConfig = getDefaultConfig;
10377
10459
  exports.getDisplayField = getDisplayField;
10378
10460
  exports.getFormConfig = getFormConfig;
10461
+ exports.getFormValue = getFormValue;
10379
10462
  exports.getGuideLineFromCache = getGuideLineFromCache;
10380
10463
  exports.getInitPositionStyle = getInitPositionStyle;
10381
10464
  exports.getNodeIndex = getNodeIndex;