form-custom-test 3.0.214 → 3.0.215

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.
@@ -69198,13 +69198,13 @@ function registerIcon(app) {
69198
69198
  if (typeof window !== "undefined") {
69199
69199
  let loadSvg = function() {
69200
69200
  var body = document.body;
69201
- var svgDom = document.getElementById("__svg__icons__dom__1782180395662__");
69201
+ var svgDom = document.getElementById("__svg__icons__dom__1782180945157__");
69202
69202
  if (!svgDom) {
69203
69203
  svgDom = document.createElementNS("http://www.w3.org/2000/svg", "svg");
69204
69204
  svgDom.style.position = "absolute";
69205
69205
  svgDom.style.width = "0";
69206
69206
  svgDom.style.height = "0";
69207
- svgDom.id = "__svg__icons__dom__1782180395662__";
69207
+ svgDom.id = "__svg__icons__dom__1782180945157__";
69208
69208
  svgDom.setAttribute("xmlns", "http://www.w3.org/2000/svg");
69209
69209
  svgDom.setAttribute("xmlns:link", "http://www.w3.org/1999/xlink");
69210
69210
  }
@@ -80207,10 +80207,96 @@ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
80207
80207
  }, 8, ["designer", "field", "rules", "design-state", "parent-widget", "parent-list", "index-of-parent-list", "sub-form-row-index", "sub-form-col-index", "sub-form-row-id"]);
80208
80208
  }
80209
80209
  var AssetSelectWidget = /* @__PURE__ */ _export_sfc$1(_sfc_main$a, [["render", _sfc_render$a]]);
80210
+ const DEFAULT_DICT_API = "/unified-dict/sysItemDict/page";
80211
+ const DEFAULT_DICT_PARAMS = { current: 1, size: 1e4 };
80212
+ function normalizeDictRecords(records) {
80213
+ if (!Array.isArray(records)) {
80214
+ return {};
80215
+ }
80216
+ return records.reduce((prev, cur) => {
80217
+ var _a2, _b2, _c2, _d, _e;
80218
+ const dictType = cur.dictType;
80219
+ if (!dictType) {
80220
+ return prev;
80221
+ }
80222
+ if (!prev[dictType]) {
80223
+ prev[dictType] = [];
80224
+ }
80225
+ prev[dictType].push(__spreadValues({
80226
+ label: (_b2 = (_a2 = cur.label) != null ? _a2 : cur.dictLabel) != null ? _b2 : "",
80227
+ value: (_e = (_d = (_c2 = cur.itemValue) != null ? _c2 : cur.dictValue) != null ? _d : cur.value) != null ? _e : ""
80228
+ }, cur));
80229
+ return prev;
80230
+ }, {});
80231
+ }
80210
80232
  class DictManager {
80211
80233
  constructor() {
80212
80234
  this.dictCache = {};
80213
80235
  this.loading = false;
80236
+ this._loaded = false;
80237
+ this._listeners = [];
80238
+ this._fetchPromise = null;
80239
+ }
80240
+ onLoaded(fn) {
80241
+ if (typeof fn !== "function") {
80242
+ return () => {
80243
+ };
80244
+ }
80245
+ if (this._loaded) {
80246
+ fn(this.dictCache);
80247
+ return () => {
80248
+ };
80249
+ }
80250
+ this._listeners.push(fn);
80251
+ return () => {
80252
+ this._listeners = this._listeners.filter((item) => item !== fn);
80253
+ };
80254
+ }
80255
+ _notifyLoaded() {
80256
+ this._loaded = true;
80257
+ this._listeners.forEach((fn) => {
80258
+ try {
80259
+ fn(this.dictCache);
80260
+ } catch (error) {
80261
+ console.error("[dictManager] onLoaded callback error:", error);
80262
+ }
80263
+ });
80264
+ }
80265
+ fetchFromApi(service2, options = {}) {
80266
+ const {
80267
+ url = DEFAULT_DICT_API,
80268
+ params = DEFAULT_DICT_PARAMS,
80269
+ force = false,
80270
+ customFetch
80271
+ } = options;
80272
+ if (this._fetchPromise && !force) {
80273
+ return this._fetchPromise;
80274
+ }
80275
+ if (this._loaded && Object.keys(this.dictCache).length > 0 && !force) {
80276
+ return Promise.resolve(this.dictCache);
80277
+ }
80278
+ this.loading = true;
80279
+ const requestPromise = typeof customFetch === "function" ? Promise.resolve().then(() => customFetch()).then((result) => {
80280
+ if (result && !Array.isArray(result) && typeof result === "object") {
80281
+ return result;
80282
+ }
80283
+ return normalizeDictRecords(Array.isArray(result) ? result : []);
80284
+ }) : service2.post(url, params).then((res) => {
80285
+ var _a2, _b2, _c2, _d;
80286
+ const records = (_d = (_c2 = (_b2 = (_a2 = res == null ? void 0 : res.data) == null ? void 0 : _a2.records) != null ? _b2 : res == null ? void 0 : res.records) != null ? _c2 : res == null ? void 0 : res.data) != null ? _d : [];
80287
+ return normalizeDictRecords(Array.isArray(records) ? records : []);
80288
+ });
80289
+ this._fetchPromise = requestPromise.then((dictData) => {
80290
+ this.init(dictData || {});
80291
+ this._notifyLoaded();
80292
+ return dictData;
80293
+ }).catch((error) => {
80294
+ console.warn("[form-custom-test] \u5B57\u5178\u6570\u636E\u52A0\u8F7D\u5931\u8D25:", error);
80295
+ return {};
80296
+ }).finally(() => {
80297
+ this.loading = false;
80298
+ });
80299
+ return this._fetchPromise;
80214
80300
  }
80215
80301
  init(dictData) {
80216
80302
  this.dictCache = dictData || {};
@@ -80263,7 +80349,6 @@ class DictManager {
80263
80349
  return this.mapToOptionItems(this.getDictData(dictCode));
80264
80350
  }
80265
80351
  getDictTypeOptions() {
80266
- console.log("this.dictCache", this.dictCache);
80267
80352
  return Object.keys(this.dictCache || {}).map((dictType) => ({
80268
80353
  label: dictType,
80269
80354
  value: dictType
@@ -80271,6 +80356,8 @@ class DictManager {
80271
80356
  }
80272
80357
  clear() {
80273
80358
  this.dictCache = {};
80359
+ this._loaded = false;
80360
+ this._fetchPromise = null;
80274
80361
  if (typeof window !== "undefined") {
80275
80362
  window.dictCache = {};
80276
80363
  }
@@ -80367,8 +80454,14 @@ const _sfc_main$9 = {
80367
80454
  },
80368
80455
  mounted() {
80369
80456
  this.handleOnMounted();
80457
+ this._offDictLoaded = dictManager.onLoaded(() => {
80458
+ this.loadDictOptions();
80459
+ });
80370
80460
  },
80371
80461
  beforeUnmount() {
80462
+ if (this._offDictLoaded) {
80463
+ this._offDictLoaded();
80464
+ }
80372
80465
  this.unregisterFromRefList();
80373
80466
  },
80374
80467
  methods: {
@@ -80565,7 +80658,7 @@ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
80565
80658
  _: 1
80566
80659
  }, 8, ["designer", "field", "rules", "design-state", "parent-widget", "parent-list", "index-of-parent-list", "sub-form-row-index", "sub-form-col-index", "sub-form-row-id"]);
80567
80660
  }
80568
- var DictSelectWidget = /* @__PURE__ */ _export_sfc$1(_sfc_main$9, [["render", _sfc_render$9], ["__scopeId", "data-v-07bda0ac"]]);
80661
+ var DictSelectWidget = /* @__PURE__ */ _export_sfc$1(_sfc_main$9, [["render", _sfc_render$9], ["__scopeId", "data-v-6f18008b"]]);
80569
80662
  var dictSelectDictCodeEditor_vue_vue_type_style_index_0_scoped_true_lang = "";
80570
80663
  const _sfc_main$8 = {
80571
80664
  name: "dict-select-dictCode-editor",
@@ -80594,6 +80687,15 @@ const _sfc_main$8 = {
80594
80687
  },
80595
80688
  mounted() {
80596
80689
  this.$nextTick(() => this.refreshDictTypeOptions());
80690
+ this._offDictLoaded = dictManager.onLoaded(() => {
80691
+ this.refreshDictTypeOptions();
80692
+ this.syncOptionItemsFromDict();
80693
+ });
80694
+ },
80695
+ beforeUnmount() {
80696
+ if (this._offDictLoaded) {
80697
+ this._offDictLoaded();
80698
+ }
80597
80699
  },
80598
80700
  methods: {
80599
80701
  refreshDictTypeOptions() {
@@ -80653,7 +80755,7 @@ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
80653
80755
  _: 1
80654
80756
  }, 8, ["label"]);
80655
80757
  }
80656
- var DictSelectDictCodeEditor = /* @__PURE__ */ _export_sfc$1(_sfc_main$8, [["render", _sfc_render$8], ["__scopeId", "data-v-5b750108"]]);
80758
+ var DictSelectDictCodeEditor = /* @__PURE__ */ _export_sfc$1(_sfc_main$8, [["render", _sfc_render$8], ["__scopeId", "data-v-2dfeafae"]]);
80657
80759
  var detailDialog_vue_vue_type_style_index_0_scoped_true_lang = "";
80658
80760
  const _sfc_main$7 = {
80659
80761
  name: "detail-dialog",
@@ -82876,6 +82978,18 @@ const loadExtension = function(app) {
82876
82978
  addCustomWidgetSchema(customInputSchema);
82877
82979
  app.component(CustomInputWidget.name, CustomInputWidget);
82878
82980
  };
82981
+ function setupDict(app, service2, options = {}) {
82982
+ const dictConfig = options.dict || {};
82983
+ app.config.globalProperties.$dictManager = dictManager;
82984
+ app.provide("dictManager", dictManager);
82985
+ if (typeof window !== "undefined") {
82986
+ window.dictManager = dictManager;
82987
+ }
82988
+ if (dictConfig.autoLoad !== false && service2) {
82989
+ dictManager.fetchFromApi(service2, dictConfig);
82990
+ }
82991
+ return dictManager;
82992
+ }
82879
82993
  const { cookies } = useCookies();
82880
82994
  function getElMessage(app) {
82881
82995
  var _a2, _b2, _c2;
@@ -82897,7 +83011,7 @@ if (typeof window !== "undefined" && !window.Sortable) {
82897
83011
  window.Sortable = SortableLib;
82898
83012
  }
82899
83013
  const Draggable = (_c = VuedraggableCjs == null ? void 0 : VuedraggableCjs.default) != null ? _c : VuedraggableCjs;
82900
- VFormDesigner.install = function(app) {
83014
+ VFormDesigner.install = function(app, options = {}) {
82901
83015
  addDirective(app);
82902
83016
  loadExtension(app);
82903
83017
  app.use(ContainerWidgets);
@@ -82910,8 +83024,12 @@ VFormDesigner.install = function(app) {
82910
83024
  app.provide("ElMessage", getElMessage(app));
82911
83025
  app.config.globalProperties.$cookies = cookies;
82912
83026
  app.provide("cookies", cookies);
83027
+ if (typeof window !== "undefined") {
83028
+ window.service = service$1;
83029
+ }
83030
+ setupDict(app, service$1, options);
82913
83031
  };
82914
- VFormRender.install = function(app) {
83032
+ VFormRender.install = function(app, options = {}) {
82915
83033
  loadExtension(app);
82916
83034
  app.use(ContainerItems);
82917
83035
  registerIcon(app);
@@ -82920,12 +83038,16 @@ VFormRender.install = function(app) {
82920
83038
  app.provide("service", service$1);
82921
83039
  app.config.globalProperties.$cookies = cookies;
82922
83040
  app.provide("cookies", cookies);
83041
+ if (typeof window !== "undefined") {
83042
+ window.service = service$1;
83043
+ }
83044
+ setupDict(app, service$1, options);
82923
83045
  };
82924
83046
  const components = [
82925
83047
  VFormDesigner,
82926
83048
  VFormRender
82927
83049
  ];
82928
- const install = (app) => {
83050
+ const install = (app, options = {}) => {
82929
83051
  addDirective(app);
82930
83052
  loadExtension(app);
82931
83053
  app.use(ContainerWidgets);
@@ -82941,10 +83063,12 @@ const install = (app) => {
82941
83063
  if (typeof window !== "undefined") {
82942
83064
  window.service = service$1;
82943
83065
  }
83066
+ setupDict(app, service$1, options);
82944
83067
  };
82945
83068
  var install$1 = {
82946
83069
  install,
82947
83070
  VFormDesigner,
82948
- VFormRender
83071
+ VFormRender,
83072
+ dictManager
82949
83073
  };
82950
83074
  export { install$1 as default };