@xjw_/vue3-npm-system 1.0.9 → 1.1.0

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.
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import Cookies from "js-cookie";
2
2
  import axios from "axios";
3
- import { ElMessage } from "element-plus";
4
- import { defineComponent, computed, openBlock, createElementBlock, mergeProps, createElementVNode, ref, watch, resolveComponent, createBlock, provide, withCtx, createVNode, normalizeStyle, renderSlot, inject, normalizeClass, createCommentVNode, Fragment, renderList, createSlots, getCurrentInstance, toDisplayString, useSlots, withKeys, unref, createTextVNode, withDirectives, vShow, nextTick, onMounted, normalizeProps, guardReactiveProps } from "vue";
3
+ import { ElMessage, ElInput, ElOption, ElCascader, ElDatePicker, ElSelect } from "element-plus";
4
+ import { defineComponent, computed, openBlock, createElementBlock, mergeProps, createElementVNode, ref, watch, resolveComponent, createBlock, provide, withCtx, createVNode, normalizeStyle, renderSlot, inject, normalizeClass, createCommentVNode, Fragment, renderList, createSlots, getCurrentInstance, toDisplayString, useSlots, onMounted, unref, withKeys, createTextVNode, withDirectives, resolveDynamicComponent, vShow, nextTick, normalizeProps, guardReactiveProps } from "vue";
5
5
  function debounce$1(func, wait) {
6
6
  let timeout = null;
7
7
  return function(...args) {
@@ -1309,7 +1309,7 @@ const _hoisted_13$1 = { class: "" };
1309
1309
  const _hoisted_14$1 = { class: "" };
1310
1310
  const _hoisted_15$1 = { key: 1 };
1311
1311
  const _hoisted_16$1 = { class: "" };
1312
- const _hoisted_17 = { class: "" };
1312
+ const _hoisted_17$1 = { class: "" };
1313
1313
  const _hoisted_18 = { class: "" };
1314
1314
  const _hoisted_19 = { class: "" };
1315
1315
  const _hoisted_20 = { class: "report-body" };
@@ -1579,7 +1579,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1579
1579
  ])) : createCommentVNode("", true),
1580
1580
  __props.customHeader2Label ? (openBlock(), createElementBlock("div", _hoisted_15$1, [
1581
1581
  createElementVNode("span", _hoisted_16$1, toDisplayString(__props.customHeader2Label) + ":", 1),
1582
- createElementVNode("span", _hoisted_17, toDisplayString(__props.customHeader2 || ""), 1)
1582
+ createElementVNode("span", _hoisted_17$1, toDisplayString(__props.customHeader2 || ""), 1)
1583
1583
  ])) : createCommentVNode("", true),
1584
1584
  createElementVNode("div", null, [
1585
1585
  createElementVNode("span", _hoisted_18, toDisplayString(__props.customHeader3Label) + toDisplayString(__props.customHeader3Label ? ":" : ""), 1),
@@ -1686,6 +1686,7 @@ const _hoisted_13 = {
1686
1686
  const _hoisted_14 = { class: "search-top-extra-content" };
1687
1687
  const _hoisted_15 = { class: "search-top__actions" };
1688
1688
  const _hoisted_16 = { class: "search-form__buttons" };
1689
+ const _hoisted_17 = { class: "search-form__buttons" };
1689
1690
  const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1690
1691
  __name: "XSearchBar",
1691
1692
  props: {
@@ -1741,6 +1742,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1741
1742
  text3: {
1742
1743
  type: String,
1743
1744
  default: ""
1745
+ },
1746
+ searchList: {
1747
+ type: Array,
1748
+ default: () => []
1749
+ },
1750
+ selectOptions: {
1751
+ type: Object,
1752
+ default: () => ({})
1744
1753
  }
1745
1754
  },
1746
1755
  emits: ["update:modelValue", "update:queryForm", "list-update", "data-reset"],
@@ -1751,6 +1760,13 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1751
1760
  const showMore = ref(false);
1752
1761
  const queryFormRef = ref();
1753
1762
  const vxeFormRef = ref();
1763
+ const dynamicFormRef = ref();
1764
+ const componentMap = {
1765
+ "el-input": ElInput,
1766
+ "el-select": ElSelect,
1767
+ "el-date-picker": ElDatePicker,
1768
+ "el-cascader": ElCascader
1769
+ };
1754
1770
  const combinedQueries = computed({
1755
1771
  get() {
1756
1772
  if (props.modelValue !== void 0 && props.modelValue !== null) {
@@ -1768,6 +1784,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1768
1784
  });
1769
1785
  const hasFormSlot = computed(() => !!slots.form);
1770
1786
  const hasVxeFormSlot = computed(() => !!slots.vxeForm);
1787
+ const hasDynamicFields = computed(() => parsedSearchList.value.length > 0);
1771
1788
  const vxeFormSpan = computed(() => Math.floor(24 / props.columns));
1772
1789
  const formContainerStyle = computed(() => ({
1773
1790
  "--form-columns": props.columns
@@ -1775,6 +1792,73 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1775
1792
  const buttonItemSpan = computed(() => {
1776
1793
  return 24;
1777
1794
  });
1795
+ const parsedSearchList = computed(() => {
1796
+ return (props.searchList || []).map((item) => {
1797
+ let attribute = {};
1798
+ if (typeof item.attribute === "string") {
1799
+ try {
1800
+ attribute = JSON.parse(item.attribute);
1801
+ } catch {
1802
+ attribute = {};
1803
+ }
1804
+ } else if (item.attribute && typeof item.attribute === "object") {
1805
+ attribute = item.attribute;
1806
+ }
1807
+ let dictKey = {};
1808
+ if (typeof item.dictKey === "string") {
1809
+ try {
1810
+ dictKey = JSON.parse(item.dictKey);
1811
+ } catch {
1812
+ dictKey = {};
1813
+ }
1814
+ } else if (item.dictKey && typeof item.dictKey === "object") {
1815
+ dictKey = item.dictKey;
1816
+ }
1817
+ return { ...item, attribute, dictKey };
1818
+ });
1819
+ });
1820
+ const dynamicRules = computed(() => {
1821
+ const result = {};
1822
+ parsedSearchList.value.forEach((item) => {
1823
+ var _a;
1824
+ if ((_a = item.attribute) == null ? void 0 : _a.required) {
1825
+ result[item.fieldJavaName] = [
1826
+ { required: true, message: `请输入${item.fieldName}`, trigger: "blur" }
1827
+ ];
1828
+ }
1829
+ });
1830
+ return result;
1831
+ });
1832
+ function resolveComponent$1(fieldType) {
1833
+ return componentMap[fieldType] || ElInput;
1834
+ }
1835
+ function shouldBindOptions(item) {
1836
+ return item.fieldType === "el-cascader";
1837
+ }
1838
+ function initDefaultValues() {
1839
+ if (!parsedSearchList.value.length) return;
1840
+ parsedSearchList.value.forEach((item) => {
1841
+ const dk = item.dictKey;
1842
+ if (!dk || !dk.default) return;
1843
+ if (dk.default === "1") {
1844
+ props.queryForm[item.fieldJavaName] = dk.defaultValue;
1845
+ } else if (dk.default === "2") {
1846
+ const now = /* @__PURE__ */ new Date();
1847
+ if (dk.defaultValue === 1) {
1848
+ const firstDay = new Date(now.getFullYear(), now.getMonth(), 1);
1849
+ props.queryForm[item.fieldJavaName] = formatDate2(firstDay);
1850
+ } else {
1851
+ props.queryForm[item.fieldJavaName] = formatDate2(now);
1852
+ }
1853
+ }
1854
+ });
1855
+ }
1856
+ function formatDate2(date) {
1857
+ const y = date.getFullYear();
1858
+ const m = String(date.getMonth() + 1).padStart(2, "0");
1859
+ const d = String(date.getDate()).padStart(2, "0");
1860
+ return `${y}-${m}-${d}`;
1861
+ }
1778
1862
  function reset() {
1779
1863
  combinedQueries.value = "";
1780
1864
  if (props.modelValue !== void 0 && props.modelValue !== null) {
@@ -1785,6 +1869,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1785
1869
  queryFormRef.value.resetFields();
1786
1870
  });
1787
1871
  }
1872
+ if (hasDynamicFields.value && dynamicFormRef.value && typeof dynamicFormRef.value.resetFields === "function") {
1873
+ nextTick(() => {
1874
+ dynamicFormRef.value.resetFields();
1875
+ });
1876
+ }
1788
1877
  if (hasVxeFormSlot.value && vxeFormRef.value && typeof vxeFormRef.value.reset === "function") {
1789
1878
  vxeFormRef.value.reset();
1790
1879
  }
@@ -1840,18 +1929,38 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1840
1929
  });
1841
1930
  });
1842
1931
  }
1932
+ if (hasDynamicFields.value && dynamicFormRef.value && typeof dynamicFormRef.value.validate === "function") {
1933
+ return new Promise((resolve, reject) => {
1934
+ dynamicFormRef.value.validate((valid) => {
1935
+ if (valid) {
1936
+ showMore.value = false;
1937
+ emit("list-update", 1);
1938
+ resolve(true);
1939
+ } else {
1940
+ showMore.value = true;
1941
+ reject(false);
1942
+ }
1943
+ });
1944
+ });
1945
+ }
1843
1946
  } else {
1844
1947
  showMore.value = false;
1845
1948
  emit("list-update", 1);
1846
1949
  return Promise.resolve(true);
1847
1950
  }
1848
1951
  }
1952
+ onMounted(() => {
1953
+ initDefaultValues();
1954
+ });
1955
+ watch(() => props.searchList, () => {
1956
+ initDefaultValues();
1957
+ }, { deep: true });
1849
1958
  __expose({
1850
1959
  queryFormRef,
1851
- vxeFormRef
1960
+ vxeFormRef,
1961
+ dynamicFormRef
1852
1962
  });
1853
1963
  return (_ctx, _cache) => {
1854
- const _component_el_input = resolveComponent("el-input");
1855
1964
  const _component_el_button = resolveComponent("el-button");
1856
1965
  const _component_vxe_form_item = resolveComponent("vxe-form-item");
1857
1966
  const _component_vxe_form = resolveComponent("vxe-form");
@@ -1864,7 +1973,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1864
1973
  createElementVNode("div", _hoisted_3$1, [
1865
1974
  __props.showInput ? (openBlock(), createElementBlock("span", _hoisted_4$1, "快捷搜索 ")) : createCommentVNode("", true),
1866
1975
  __props.showInput ? (openBlock(), createElementBlock("div", _hoisted_5$1, [
1867
- createVNode(_component_el_input, {
1976
+ createVNode(unref(ElInput), {
1868
1977
  type: "text",
1869
1978
  onKeyup: withKeys(searchParentList, ["enter"]),
1870
1979
  modelValue: combinedQueries.value,
@@ -2038,7 +2147,81 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2038
2147
  }, 8, ["span"])) : createCommentVNode("", true)
2039
2148
  ]),
2040
2149
  _: 3
2041
- }, 8, ["data", "rules", "span", "title-width"])) : createCommentVNode("", true)
2150
+ }, 8, ["data", "rules", "span", "title-width"])) : createCommentVNode("", true),
2151
+ hasDynamicFields.value ? (openBlock(), createBlock(XElForm, {
2152
+ key: 2,
2153
+ rules: dynamicRules.value,
2154
+ model: __props.queryForm,
2155
+ ref_key: "dynamicFormRef",
2156
+ ref: dynamicFormRef,
2157
+ span: vxeFormSpan.value,
2158
+ "label-width": __props.titleWidth,
2159
+ "label-position": "top"
2160
+ }, {
2161
+ default: withCtx(() => [
2162
+ (openBlock(true), createElementBlock(Fragment, null, renderList(parsedSearchList.value, (item) => {
2163
+ return openBlock(), createBlock(XElFormItem, {
2164
+ key: item.fieldJavaName,
2165
+ label: item.fieldName,
2166
+ prop: item.fieldJavaName
2167
+ }, {
2168
+ default: withCtx(() => [
2169
+ (openBlock(), createBlock(resolveDynamicComponent(resolveComponent$1(item.fieldType)), mergeProps({
2170
+ modelValue: __props.queryForm[item.fieldJavaName],
2171
+ "onUpdate:modelValue": ($event) => __props.queryForm[item.fieldJavaName] = $event
2172
+ }, { ref_for: true }, item.attribute, {
2173
+ options: shouldBindOptions(item) ? __props.selectOptions[item.fieldJavaName] || [] : void 0
2174
+ }), {
2175
+ default: withCtx(() => [
2176
+ item.fieldType === "el-select" ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(__props.selectOptions[item.fieldJavaName] || [], (option, idx) => {
2177
+ var _a, _b;
2178
+ return openBlock(), createBlock(unref(ElOption), {
2179
+ key: idx,
2180
+ label: option[((_a = item.dictKey) == null ? void 0 : _a.label) || "label"],
2181
+ value: option[((_b = item.dictKey) == null ? void 0 : _b.value) || "value"]
2182
+ }, null, 8, ["label", "value"]);
2183
+ }), 128)) : createCommentVNode("", true)
2184
+ ]),
2185
+ _: 2
2186
+ }, 1040, ["modelValue", "onUpdate:modelValue", "options"]))
2187
+ ]),
2188
+ _: 2
2189
+ }, 1032, ["label", "prop"]);
2190
+ }), 128)),
2191
+ !__props.showSearch ? (openBlock(), createBlock(XElFormItem, {
2192
+ key: 0,
2193
+ label: "",
2194
+ span: buttonItemSpan.value
2195
+ }, {
2196
+ default: withCtx(() => [
2197
+ createElementVNode("div", _hoisted_17, [
2198
+ createVNode(_component_el_button, {
2199
+ plain: "",
2200
+ onClick: reset
2201
+ }, {
2202
+ default: withCtx(() => _cache[9] || (_cache[9] = [
2203
+ createTextVNode("重 置")
2204
+ ])),
2205
+ _: 1,
2206
+ __: [9]
2207
+ }),
2208
+ createVNode(_component_el_button, {
2209
+ type: "primary",
2210
+ onClick: searchParentList
2211
+ }, {
2212
+ default: withCtx(() => _cache[10] || (_cache[10] = [
2213
+ createTextVNode("查 询")
2214
+ ])),
2215
+ _: 1,
2216
+ __: [10]
2217
+ })
2218
+ ])
2219
+ ]),
2220
+ _: 1
2221
+ }, 8, ["span"])) : createCommentVNode("", true)
2222
+ ]),
2223
+ _: 1
2224
+ }, 8, ["rules", "model", "span", "label-width"])) : createCommentVNode("", true)
2042
2225
  ], 4)
2043
2226
  ], 2), [
2044
2227
  [vShow, showMore.value || !__props.showSearch]
@@ -2047,7 +2230,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2047
2230
  };
2048
2231
  }
2049
2232
  });
2050
- const XSearchBar = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-39635b04"]]);
2233
+ const XSearchBar = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-7caed879"]]);
2051
2234
  const _hoisted_1 = { class: "x-split-layout__sidebar-menu" };
2052
2235
  const _hoisted_2 = ["onClick"];
2053
2236
  const _hoisted_3 = { class: "x-split-layout__menu-icon" };