@tmagic/form 1.5.0-beta.4 → 1.5.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.
@@ -1,9 +1,11 @@
1
1
  import { toRaw, defineComponent, inject, ref, computed, watchEffect, watch, resolveComponent, openBlock, createElementBlock, normalizeStyle, normalizeClass, createBlock, resolveDynamicComponent, Fragment, createVNode, unref, withCtx, createElementVNode, createCommentVNode, renderList, createTextVNode, toDisplayString, withDirectives, vShow, renderSlot, onMounted, Teleport, toRefs, mergeProps, getCurrentInstance, reactive, onBeforeUnmount, vModelText, provide, onBeforeMount, nextTick, resolveDirective, createSlots, withModifiers } from 'vue';
2
2
  import { WarningFilled, CaretBottom, CaretRight, Delete, CaretTop, Grid, ArrowUp, ArrowDown, FullScreen } from '@element-plus/icons-vue';
3
3
  import { cloneDeep, isEqual, isEmpty } from 'lodash-es';
4
- import { TMagicFormItem, TMagicTooltip, TMagicIcon, TMagicButton, TMagicCheckbox, TMagicCard, TMagicCol, TMagicRow, TMagicSteps, TMagicStep, useZIndex, TMagicTable, TMagicTableColumn, TMagicUpload, TMagicPagination, tMagicMessage, getConfig as getConfig$1, TMagicBadge, TMagicCascader, TMagicCheckboxGroup, TMagicColorPicker, TMagicDatePicker, TMagicForm, TMagicInput, TMagicDialog, TMagicInputNumber, TMagicRadioGroup, TMagicRadio, TMagicSelect, TMagicSwitch, TMagicPopover, TMagicTimePicker, TMagicDrawer, TMagicScrollbar } from '@tmagic/design';
4
+ import { TMagicFormItem, TMagicTooltip, TMagicIcon, TMagicButton, TMagicCheckbox, TMagicCard, TMagicCol, TMagicRow, TMagicSteps, TMagicStep, useZIndex, TMagicTable, TMagicTableColumn, TMagicUpload, TMagicPagination, tMagicMessage, getDesignConfig, TMagicBadge, TMagicCascader, TMagicCheckboxGroup, TMagicColorPicker, TMagicDatePicker, TMagicForm, TMagicInput, TMagicDialog, TMagicInputNumber, TMagicRadioGroup, TMagicRadio, TMagicSelect, TMagicSwitch, TMagicPopover, TMagicTimePicker, TMagicDrawer, TMagicScrollbar } from '@tmagic/design';
5
+ import dayjs from 'dayjs';
6
+ import utc from 'dayjs/plugin/utc';
5
7
  import Sortable from 'sortablejs';
6
- import { sleep, asyncLoadJs, datetimeFormatter, getValueByKeyPath, isNumber } from '@tmagic/utils';
8
+ import { sleep, asyncLoadJs, getValueByKeyPath, isNumber } from '@tmagic/utils';
7
9
 
8
10
  const isTableSelect = (type) => typeof type === "string" && ["table-select", "tableSelect"].includes(type);
9
11
  const asyncLoadConfig = (value, initValue2, { asyncLoad, name, type }) => {
@@ -164,8 +166,26 @@ const initValue = async (mForm, { initValues, config }) => {
164
166
  }
165
167
  return valuesTmp || {};
166
168
  };
169
+ const datetimeFormatter = (v, defaultValue = "-", format = "YYYY-MM-DD HH:mm:ss") => {
170
+ if (v) {
171
+ let time;
172
+ if (["x", "timestamp"].includes(format)) {
173
+ time = dayjs(v).valueOf();
174
+ } else if (typeof v === "string" && v.includes("Z") || v.constructor === Date) {
175
+ dayjs.extend(utc);
176
+ time = dayjs(v).utcOffset(8).format(format);
177
+ } else {
178
+ time = dayjs(v).format(format);
179
+ }
180
+ if (time !== "Invalid Date") {
181
+ return time;
182
+ }
183
+ return defaultValue;
184
+ }
185
+ return defaultValue;
186
+ };
167
187
 
168
- const _hoisted_1$d = ["id", "data-magic-id"];
188
+ const _hoisted_1$d = ["data-tmagic-id"];
169
189
  const _hoisted_2$8 = ["innerHTML", "title"];
170
190
  const _hoisted_3$5 = ["innerHTML"];
171
191
  const _hoisted_4$4 = ["innerHTML"];
@@ -319,8 +339,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
319
339
  const _component_Container = resolveComponent("Container", true);
320
340
  return _ctx.config ? (openBlock(), createElementBlock("div", {
321
341
  key: 0,
322
- id: _ctx.config.id,
323
- "data-magic-id": _ctx.config.id,
342
+ "data-tmagic-id": _ctx.config.id,
324
343
  style: normalizeStyle(_ctx.config.tip ? "display: flex;align-items: baseline;" : ""),
325
344
  class: normalizeClass(`m-form-container m-container-${type.value || ""} ${_ctx.config.className || ""}`)
326
345
  }, [
@@ -1567,6 +1586,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1567
1586
  }
1568
1587
  timer = setTimeout(() => {
1569
1588
  swapArray(index, index - 1);
1589
+ timer = void 0;
1570
1590
  }, 300);
1571
1591
  };
1572
1592
  const topHandler = (index) => {
@@ -1585,6 +1605,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1585
1605
  }
1586
1606
  timer = setTimeout(() => {
1587
1607
  swapArray(index, index + 1);
1608
+ timer = void 0;
1588
1609
  }, 300);
1589
1610
  };
1590
1611
  const bottomHandler = (index) => {
@@ -1973,8 +1994,8 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
1973
1994
  },
1974
1995
  emits: ["change", "addDiffCount"],
1975
1996
  setup(__props, { emit: __emit }) {
1976
- const tabPaneComponent = getConfig$1("components")?.tabPane;
1977
- const tabsComponent = getConfig$1("components")?.tabs;
1997
+ const tabPaneComponent = getDesignConfig("components")?.tabPane;
1998
+ const tabsComponent = getDesignConfig("components")?.tabs;
1978
1999
  const getActive = (mForm2, props2, activeTabName2) => {
1979
2000
  const { config, model, prop } = props2;
1980
2001
  const { active } = config;
@@ -2457,7 +2478,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2457
2478
  const props = __props;
2458
2479
  const emit = __emit;
2459
2480
  useAddField(props.prop);
2460
- props.model[props.name] = datetimeFormatter(props.model[props.name], "");
2481
+ props.model[props.name] = datetimeFormatter(props.model[props.name], "", "YYYY/MM/DD");
2461
2482
  const changeHandler = (v) => {
2462
2483
  emit("change", v);
2463
2484
  };
@@ -2469,8 +2490,8 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
2469
2490
  size: _ctx.size,
2470
2491
  placeholder: _ctx.config.placeholder,
2471
2492
  disabled: _ctx.disabled,
2472
- format: _ctx.config.format,
2473
- "value-format": _ctx.config.valueFormat || "YYYY/MM/DD HH:mm:ss",
2493
+ format: _ctx.config.format || "YYYY/MM/DD",
2494
+ "value-format": _ctx.config.valueFormat || "YYYY/MM/DD",
2474
2495
  onChange: changeHandler
2475
2496
  }, null, 8, ["modelValue", "size", "placeholder", "disabled", "format", "value-format"]);
2476
2497
  };
@@ -2534,7 +2555,11 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2534
2555
  return;
2535
2556
  }
2536
2557
  if (Array.isArray(v)) {
2537
- props.model[item] = datetimeFormatter(v[index]?.toString(), "");
2558
+ props.model[item] = datetimeFormatter(
2559
+ v[index]?.toString(),
2560
+ "",
2561
+ props.config.valueFormat || "YYYY/MM/DD HH:mm:ss"
2562
+ );
2538
2563
  } else {
2539
2564
  props.model[item] = void 0;
2540
2565
  }
@@ -2546,7 +2571,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2546
2571
  emit(
2547
2572
  "change",
2548
2573
  value2.map((item) => {
2549
- if (item) return datetimeFormatter(item, "");
2574
+ if (item) return datetimeFormatter(item, "", props.config.valueFormat || "YYYY/MM/DD HH:mm:ss");
2550
2575
  return void 0;
2551
2576
  })
2552
2577
  );
@@ -2569,8 +2594,11 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2569
2594
  "unlink-panels": true,
2570
2595
  disabled: _ctx.disabled,
2571
2596
  "default-time": _ctx.config.defaultTime,
2597
+ "value-format": _ctx.config.valueFormat || "YYYY/MM/DD HH:mm:ss",
2598
+ "date-format": _ctx.config.dateFormat || "YYYY/MM/DD",
2599
+ "time-format": _ctx.config.timeFormat || "HH:mm:ss",
2572
2600
  onChange: changeHandler
2573
- }, null, 8, ["modelValue", "size", "disabled", "default-time"]);
2601
+ }, null, 8, ["modelValue", "size", "disabled", "default-time", "value-format", "date-format", "time-format"]);
2574
2602
  };
2575
2603
  }
2576
2604
  });
@@ -2601,7 +2629,11 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
2601
2629
  if (value === "Invalid Date") {
2602
2630
  props.model[props.name] = "";
2603
2631
  } else {
2604
- props.model[props.name] = datetimeFormatter(props.model[props.name], "", props.config.valueFormat);
2632
+ props.model[props.name] = datetimeFormatter(
2633
+ props.model[props.name],
2634
+ "",
2635
+ props.config.valueFormat || "YYYY/MM/DD HH:mm:ss"
2636
+ );
2605
2637
  }
2606
2638
  }
2607
2639
  const changeHandler = (v) => {
@@ -3416,8 +3448,8 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3416
3448
  setup(__props, { emit: __emit }) {
3417
3449
  const props = __props;
3418
3450
  const emit = __emit;
3419
- const optionComponent = getConfig$1("components")?.option;
3420
- const optionGroupComponent = getConfig$1("components")?.optionGroup;
3451
+ const optionComponent = getDesignConfig("components")?.option;
3452
+ const optionGroupComponent = getDesignConfig("components")?.optionGroup;
3421
3453
  if (!props.model) throw new Error("不能没有model");
3422
3454
  useAddField(props.prop);
3423
3455
  const tMagicSelect = ref();
@@ -4168,7 +4200,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
4168
4200
  return;
4169
4201
  }
4170
4202
  if (Array.isArray(v)) {
4171
- props.model[item] = datetimeFormatter(v[index]?.toString(), "");
4203
+ props.model[item] = v[index];
4172
4204
  } else {
4173
4205
  props.model[item] = void 0;
4174
4206
  }
@@ -4527,4 +4559,4 @@ const index = {
4527
4559
  }
4528
4560
  };
4529
4561
 
4530
- export { _sfc_main$n as MCascader, _sfc_main$m as MCheckbox, _sfc_main$l as MCheckboxGroup, _sfc_main$k as MColorPicker, _sfc_main$x as MContainer, _sfc_main$j as MDate, _sfc_main$h as MDateTime, _sfc_main$i as MDaterange, _sfc_main$g as MDisplay, _sfc_main$f as MDynamicField, _sfc_main$w as MFieldset, _sfc_main$d as MForm, _sfc_main as MFormBox, _sfc_main$c as MFormDialog, _sfc_main$1 as MFormDrawer, _sfc_main$u as MGroupList, _sfc_main$e as MHidden, _sfc_main$b as MLink, _sfc_main$a as MNumber, _sfc_main$9 as MNumberRange, _sfc_main$t as MPanel, _sfc_main$8 as MRadioGroup, _sfc_main$r as MRow, _sfc_main$7 as MSelect, _sfc_main$6 as MSwitch, _sfc_main$p as MTable, _sfc_main$o as MTabs, _sfc_main$5 as MText, _sfc_main$4 as MTextarea, _sfc_main$3 as MTime, _sfc_main$2 as MTimerange, createForm, createValues, index as default, display, filterFunction, getRules, initValue, useAddField };
4562
+ export { _sfc_main$n as MCascader, _sfc_main$m as MCheckbox, _sfc_main$l as MCheckboxGroup, _sfc_main$k as MColorPicker, _sfc_main$x as MContainer, _sfc_main$j as MDate, _sfc_main$h as MDateTime, _sfc_main$i as MDaterange, _sfc_main$g as MDisplay, _sfc_main$f as MDynamicField, _sfc_main$w as MFieldset, _sfc_main$d as MForm, _sfc_main as MFormBox, _sfc_main$c as MFormDialog, _sfc_main$1 as MFormDrawer, _sfc_main$u as MGroupList, _sfc_main$e as MHidden, _sfc_main$b as MLink, _sfc_main$a as MNumber, _sfc_main$9 as MNumberRange, _sfc_main$t as MPanel, _sfc_main$8 as MRadioGroup, _sfc_main$r as MRow, _sfc_main$7 as MSelect, _sfc_main$6 as MSwitch, _sfc_main$p as MTable, _sfc_main$o as MTabs, _sfc_main$5 as MText, _sfc_main$4 as MTextarea, _sfc_main$3 as MTime, _sfc_main$2 as MTimerange, createForm, createValues, datetimeFormatter, index as default, display, filterFunction, getRules, initValue, useAddField };
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('@element-plus/icons-vue'), require('lodash-es'), require('@tmagic/design'), require('sortablejs'), require('@tmagic/utils')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'vue', '@element-plus/icons-vue', 'lodash-es', '@tmagic/design', 'sortablejs', '@tmagic/utils'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicForm = {}, global.Vue, global.iconsVue, global.lodashEs, global.design, global.Sortable, global.utils));
5
- })(this, (function (exports, vue, iconsVue, lodashEs, design, Sortable, utils) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('@element-plus/icons-vue'), require('lodash-es'), require('@tmagic/design'), require('dayjs'), require('dayjs/plugin/utc'), require('sortablejs'), require('@tmagic/utils')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vue', '@element-plus/icons-vue', 'lodash-es', '@tmagic/design', 'dayjs', 'dayjs/plugin/utc', 'sortablejs', '@tmagic/utils'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicForm = {}, global.Vue, global.iconsVue, global.lodashEs, global.design, global.dayjs, global.utc, global.Sortable, global.utils));
5
+ })(this, (function (exports, vue, iconsVue, lodashEs, design, dayjs, utc, Sortable, utils) { 'use strict';
6
6
 
7
7
  const isTableSelect = (type) => typeof type === "string" && ["table-select", "tableSelect"].includes(type);
8
8
  const asyncLoadConfig = (value, initValue2, { asyncLoad, name, type }) => {
@@ -163,8 +163,26 @@
163
163
  }
164
164
  return valuesTmp || {};
165
165
  };
166
+ const datetimeFormatter = (v, defaultValue = "-", format = "YYYY-MM-DD HH:mm:ss") => {
167
+ if (v) {
168
+ let time;
169
+ if (["x", "timestamp"].includes(format)) {
170
+ time = dayjs(v).valueOf();
171
+ } else if (typeof v === "string" && v.includes("Z") || v.constructor === Date) {
172
+ dayjs.extend(utc);
173
+ time = dayjs(v).utcOffset(8).format(format);
174
+ } else {
175
+ time = dayjs(v).format(format);
176
+ }
177
+ if (time !== "Invalid Date") {
178
+ return time;
179
+ }
180
+ return defaultValue;
181
+ }
182
+ return defaultValue;
183
+ };
166
184
 
167
- const _hoisted_1$d = ["id", "data-magic-id"];
185
+ const _hoisted_1$d = ["data-tmagic-id"];
168
186
  const _hoisted_2$8 = ["innerHTML", "title"];
169
187
  const _hoisted_3$5 = ["innerHTML"];
170
188
  const _hoisted_4$4 = ["innerHTML"];
@@ -318,8 +336,7 @@
318
336
  const _component_Container = vue.resolveComponent("Container", true);
319
337
  return _ctx.config ? (vue.openBlock(), vue.createElementBlock("div", {
320
338
  key: 0,
321
- id: _ctx.config.id,
322
- "data-magic-id": _ctx.config.id,
339
+ "data-tmagic-id": _ctx.config.id,
323
340
  style: vue.normalizeStyle(_ctx.config.tip ? "display: flex;align-items: baseline;" : ""),
324
341
  class: vue.normalizeClass(`m-form-container m-container-${type.value || ""} ${_ctx.config.className || ""}`)
325
342
  }, [
@@ -1566,6 +1583,7 @@
1566
1583
  }
1567
1584
  timer = setTimeout(() => {
1568
1585
  swapArray(index, index - 1);
1586
+ timer = void 0;
1569
1587
  }, 300);
1570
1588
  };
1571
1589
  const topHandler = (index) => {
@@ -1584,6 +1602,7 @@
1584
1602
  }
1585
1603
  timer = setTimeout(() => {
1586
1604
  swapArray(index, index + 1);
1605
+ timer = void 0;
1587
1606
  }, 300);
1588
1607
  };
1589
1608
  const bottomHandler = (index) => {
@@ -1972,8 +1991,8 @@
1972
1991
  },
1973
1992
  emits: ["change", "addDiffCount"],
1974
1993
  setup(__props, { emit: __emit }) {
1975
- const tabPaneComponent = design.getConfig("components")?.tabPane;
1976
- const tabsComponent = design.getConfig("components")?.tabs;
1994
+ const tabPaneComponent = design.getDesignConfig("components")?.tabPane;
1995
+ const tabsComponent = design.getDesignConfig("components")?.tabs;
1977
1996
  const getActive = (mForm2, props2, activeTabName2) => {
1978
1997
  const { config, model, prop } = props2;
1979
1998
  const { active } = config;
@@ -2456,7 +2475,7 @@
2456
2475
  const props = __props;
2457
2476
  const emit = __emit;
2458
2477
  useAddField(props.prop);
2459
- props.model[props.name] = utils.datetimeFormatter(props.model[props.name], "");
2478
+ props.model[props.name] = datetimeFormatter(props.model[props.name], "", "YYYY/MM/DD");
2460
2479
  const changeHandler = (v) => {
2461
2480
  emit("change", v);
2462
2481
  };
@@ -2468,8 +2487,8 @@
2468
2487
  size: _ctx.size,
2469
2488
  placeholder: _ctx.config.placeholder,
2470
2489
  disabled: _ctx.disabled,
2471
- format: _ctx.config.format,
2472
- "value-format": _ctx.config.valueFormat || "YYYY/MM/DD HH:mm:ss",
2490
+ format: _ctx.config.format || "YYYY/MM/DD",
2491
+ "value-format": _ctx.config.valueFormat || "YYYY/MM/DD",
2473
2492
  onChange: changeHandler
2474
2493
  }, null, 8, ["modelValue", "size", "placeholder", "disabled", "format", "value-format"]);
2475
2494
  };
@@ -2533,7 +2552,11 @@
2533
2552
  return;
2534
2553
  }
2535
2554
  if (Array.isArray(v)) {
2536
- props.model[item] = utils.datetimeFormatter(v[index]?.toString(), "");
2555
+ props.model[item] = datetimeFormatter(
2556
+ v[index]?.toString(),
2557
+ "",
2558
+ props.config.valueFormat || "YYYY/MM/DD HH:mm:ss"
2559
+ );
2537
2560
  } else {
2538
2561
  props.model[item] = void 0;
2539
2562
  }
@@ -2545,7 +2568,7 @@
2545
2568
  emit(
2546
2569
  "change",
2547
2570
  value2.map((item) => {
2548
- if (item) return utils.datetimeFormatter(item, "");
2571
+ if (item) return datetimeFormatter(item, "", props.config.valueFormat || "YYYY/MM/DD HH:mm:ss");
2549
2572
  return void 0;
2550
2573
  })
2551
2574
  );
@@ -2568,8 +2591,11 @@
2568
2591
  "unlink-panels": true,
2569
2592
  disabled: _ctx.disabled,
2570
2593
  "default-time": _ctx.config.defaultTime,
2594
+ "value-format": _ctx.config.valueFormat || "YYYY/MM/DD HH:mm:ss",
2595
+ "date-format": _ctx.config.dateFormat || "YYYY/MM/DD",
2596
+ "time-format": _ctx.config.timeFormat || "HH:mm:ss",
2571
2597
  onChange: changeHandler
2572
- }, null, 8, ["modelValue", "size", "disabled", "default-time"]);
2598
+ }, null, 8, ["modelValue", "size", "disabled", "default-time", "value-format", "date-format", "time-format"]);
2573
2599
  };
2574
2600
  }
2575
2601
  });
@@ -2600,7 +2626,11 @@
2600
2626
  if (value === "Invalid Date") {
2601
2627
  props.model[props.name] = "";
2602
2628
  } else {
2603
- props.model[props.name] = utils.datetimeFormatter(props.model[props.name], "", props.config.valueFormat);
2629
+ props.model[props.name] = datetimeFormatter(
2630
+ props.model[props.name],
2631
+ "",
2632
+ props.config.valueFormat || "YYYY/MM/DD HH:mm:ss"
2633
+ );
2604
2634
  }
2605
2635
  }
2606
2636
  const changeHandler = (v) => {
@@ -3415,8 +3445,8 @@
3415
3445
  setup(__props, { emit: __emit }) {
3416
3446
  const props = __props;
3417
3447
  const emit = __emit;
3418
- const optionComponent = design.getConfig("components")?.option;
3419
- const optionGroupComponent = design.getConfig("components")?.optionGroup;
3448
+ const optionComponent = design.getDesignConfig("components")?.option;
3449
+ const optionGroupComponent = design.getDesignConfig("components")?.optionGroup;
3420
3450
  if (!props.model) throw new Error("不能没有model");
3421
3451
  useAddField(props.prop);
3422
3452
  const tMagicSelect = vue.ref();
@@ -4167,7 +4197,7 @@
4167
4197
  return;
4168
4198
  }
4169
4199
  if (Array.isArray(v)) {
4170
- props.model[item] = utils.datetimeFormatter(v[index]?.toString(), "");
4200
+ props.model[item] = v[index];
4171
4201
  } else {
4172
4202
  props.model[item] = void 0;
4173
4203
  }
@@ -4559,6 +4589,7 @@
4559
4589
  exports.MTimerange = _sfc_main$2;
4560
4590
  exports.createForm = createForm;
4561
4591
  exports.createValues = createValues;
4592
+ exports.datetimeFormatter = datetimeFormatter;
4562
4593
  exports.default = index;
4563
4594
  exports.display = display;
4564
4595
  exports.filterFunction = filterFunction;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.0-beta.4",
2
+ "version": "1.5.0-beta.6",
3
3
  "name": "@tmagic/form",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -36,6 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@element-plus/icons-vue": "^2.3.1",
39
+ "dayjs": "^1.11.11",
39
40
  "lodash-es": "^4.17.21",
40
41
  "sortablejs": "^1.15.2"
41
42
  },
@@ -53,8 +54,8 @@
53
54
  "peerDependencies": {
54
55
  "vue": "^3.4.35",
55
56
  "typescript": "*",
56
- "@tmagic/design": "1.5.0-beta.4",
57
- "@tmagic/utils": "1.5.0-beta.4"
57
+ "@tmagic/design": "1.5.0-beta.6",
58
+ "@tmagic/utils": "1.5.0-beta.6"
58
59
  },
59
60
  "peerDependenciesMeta": {
60
61
  "typescript": {
@@ -1,8 +1,7 @@
1
1
  <template>
2
2
  <div
3
3
  v-if="config"
4
- :id="config.id"
5
- :data-magic-id="config.id"
4
+ :data-tmagic-id="config.id"
6
5
  :style="config.tip ? 'display: flex;align-items: baseline;' : ''"
7
6
  :class="`m-form-container m-container-${type || ''} ${config.className || ''}`"
8
7
  >
@@ -206,7 +206,7 @@ import {
206
206
  } from '@tmagic/design';
207
207
  import { asyncLoadJs, sleep } from '@tmagic/utils';
208
208
 
209
- import { ColumnConfig, FormState, SortProp, TableConfig } from '../schema';
209
+ import { FormState, SortProp, TableColumnConfig, TableConfig } from '../schema';
210
210
  import { display as displayFunc, initValue } from '../utils/form';
211
211
 
212
212
  import Container from './Container.vue';
@@ -484,7 +484,7 @@ const toggleRowSelection = (row: any, selected: boolean) => {
484
484
  tMagicTable.value?.toggleRowSelection.call(tMagicTable.value, row, selected);
485
485
  };
486
486
 
487
- const makeConfig = (config: ColumnConfig, row: any) => {
487
+ const makeConfig = (config: TableColumnConfig, row: any) => {
488
488
  const newConfig = cloneDeep(config);
489
489
  if (typeof config.itemsFunction === 'function') {
490
490
  newConfig.items = config.itemsFunction(row);
@@ -500,6 +500,7 @@ const upHandler = (index: number) => {
500
500
 
501
501
  timer = setTimeout(() => {
502
502
  swapArray(index, index - 1);
503
+ timer = undefined;
503
504
  }, 300);
504
505
  };
505
506
 
@@ -525,6 +526,7 @@ const downHandler = (index: number) => {
525
526
 
526
527
  timer = setTimeout(() => {
527
528
  swapArray(index, index + 1);
529
+ timer = undefined;
528
530
  }, 300);
529
531
  };
530
532
 
@@ -73,7 +73,7 @@
73
73
  import { computed, inject, ref, watchEffect } from 'vue';
74
74
  import { cloneDeep, isEmpty } from 'lodash-es';
75
75
 
76
- import { getConfig, TMagicBadge } from '@tmagic/design';
76
+ import { getDesignConfig, TMagicBadge } from '@tmagic/design';
77
77
 
78
78
  import { FormState, TabConfig, TabPaneConfig } from '../schema';
79
79
  import { display as displayFunc, filterFunction } from '../utils/form';
@@ -88,8 +88,8 @@ type DiffCount = {
88
88
  [tabIndex: number]: number;
89
89
  };
90
90
 
91
- const tabPaneComponent = getConfig('components')?.tabPane;
92
- const tabsComponent = getConfig('components')?.tabs;
91
+ const tabPaneComponent = getDesignConfig('components')?.tabPane;
92
+ const tabsComponent = getDesignConfig('components')?.tabs;
93
93
 
94
94
  const getActive = (mForm: FormState | undefined, props: any, activeTabName: string) => {
95
95
  const { config, model, prop } = props;
@@ -5,17 +5,17 @@
5
5
  :size="size"
6
6
  :placeholder="config.placeholder"
7
7
  :disabled="disabled"
8
- :format="config.format"
9
- :value-format="config.valueFormat || 'YYYY/MM/DD HH:mm:ss'"
8
+ :format="config.format || 'YYYY/MM/DD'"
9
+ :value-format="config.valueFormat || 'YYYY/MM/DD'"
10
10
  @change="changeHandler"
11
11
  ></TMagicDatePicker>
12
12
  </template>
13
13
 
14
14
  <script lang="ts" setup>
15
15
  import { TMagicDatePicker } from '@tmagic/design';
16
- import { datetimeFormatter } from '@tmagic/utils';
17
16
 
18
17
  import type { DateConfig, FieldProps } from '../schema';
18
+ import { datetimeFormatter } from '../utils/form';
19
19
  import { useAddField } from '../utils/useAddField';
20
20
 
21
21
  defineOptions({
@@ -30,7 +30,7 @@ const emit = defineEmits<{
30
30
 
31
31
  useAddField(props.prop);
32
32
 
33
- props.model[props.name] = datetimeFormatter(props.model[props.name], '');
33
+ props.model[props.name] = datetimeFormatter(props.model[props.name], '', 'YYYY/MM/DD');
34
34
 
35
35
  const changeHandler = (v: string) => {
36
36
  emit('change', v);
@@ -15,9 +15,9 @@
15
15
 
16
16
  <script lang="ts" setup>
17
17
  import { TMagicDatePicker } from '@tmagic/design';
18
- import { datetimeFormatter } from '@tmagic/utils';
19
18
 
20
19
  import type { DateTimeConfig, FieldProps } from '../schema';
20
+ import { datetimeFormatter } from '../utils/form';
21
21
  import { useAddField } from '../utils/useAddField';
22
22
 
23
23
  defineOptions({
@@ -37,7 +37,11 @@ if (props.model) {
37
37
  if (value === 'Invalid Date') {
38
38
  props.model[props.name] = '';
39
39
  } else {
40
- props.model[props.name] = datetimeFormatter(props.model[props.name], '', props.config.valueFormat);
40
+ props.model[props.name] = datetimeFormatter(
41
+ props.model[props.name],
42
+ '',
43
+ props.config.valueFormat || 'YYYY/MM/DD HH:mm:ss',
44
+ );
41
45
  }
42
46
  }
43
47
 
@@ -9,6 +9,9 @@
9
9
  :unlink-panels="true"
10
10
  :disabled="disabled"
11
11
  :default-time="config.defaultTime"
12
+ :value-format="config.valueFormat || 'YYYY/MM/DD HH:mm:ss'"
13
+ :date-format="config.dateFormat || 'YYYY/MM/DD'"
14
+ :time-format="config.timeFormat || 'HH:mm:ss'"
12
15
  @change="changeHandler"
13
16
  ></TMagicDatePicker>
14
17
  </template>
@@ -17,9 +20,9 @@
17
20
  import { ref, watch } from 'vue';
18
21
 
19
22
  import { TMagicDatePicker } from '@tmagic/design';
20
- import { datetimeFormatter } from '@tmagic/utils';
21
23
 
22
24
  import type { DaterangeConfig, FieldProps } from '../schema';
25
+ import { datetimeFormatter } from '../utils/form';
23
26
  import { useAddField } from '../utils/useAddField';
24
27
 
25
28
  defineOptions({
@@ -71,7 +74,11 @@ const setValue = (v: Date[] | Date) => {
71
74
  return;
72
75
  }
73
76
  if (Array.isArray(v)) {
74
- props.model[item] = datetimeFormatter(v[index]?.toString(), '');
77
+ props.model[item] = datetimeFormatter(
78
+ v[index]?.toString(),
79
+ '',
80
+ props.config.valueFormat || 'YYYY/MM/DD HH:mm:ss',
81
+ );
75
82
  } else {
76
83
  props.model[item] = undefined;
77
84
  }
@@ -85,7 +92,7 @@ const changeHandler = (v: Date[]) => {
85
92
  emit(
86
93
  'change',
87
94
  value.map((item?: Date) => {
88
- if (item) return datetimeFormatter(item, '');
95
+ if (item) return datetimeFormatter(item, '', props.config.valueFormat || 'YYYY/MM/DD HH:mm:ss');
89
96
  return undefined;
90
97
  }),
91
98
  );
@@ -80,7 +80,7 @@
80
80
  <script lang="ts" setup>
81
81
  import { inject, nextTick, onBeforeMount, ref, watch, watchEffect } from 'vue';
82
82
 
83
- import { getConfig as getDesignConfig, TMagicSelect } from '@tmagic/design';
83
+ import { getDesignConfig, TMagicSelect } from '@tmagic/design';
84
84
  import { getValueByKeyPath } from '@tmagic/utils';
85
85
 
86
86
  import type { FieldProps, FormState, SelectConfig, SelectGroupOption, SelectOption } from '../schema';
@@ -17,7 +17,6 @@
17
17
  import { ref, watch } from 'vue';
18
18
 
19
19
  import { TMagicTimePicker } from '@tmagic/design';
20
- import { datetimeFormatter } from '@tmagic/utils';
21
20
 
22
21
  import type { DaterangeConfig, FieldProps } from '../schema';
23
22
  import { useAddField } from '../utils/useAddField';
@@ -59,7 +58,7 @@ const setValue = (v: Date[] | Date) => {
59
58
  return;
60
59
  }
61
60
  if (Array.isArray(v)) {
62
- props.model[item] = datetimeFormatter(v[index]?.toString(), '');
61
+ props.model[item] = v[index];
63
62
  } else {
64
63
  props.model[item] = undefined;
65
64
  }
package/src/index.ts CHANGED
@@ -91,14 +91,14 @@ export { default as MDynamicField } from './fields/DynamicField.vue';
91
91
 
92
92
  export const createForm = <T extends [] = []>(config: FormConfig | T) => config;
93
93
 
94
- export interface InstallOptions {
94
+ export interface FormInstallOptions {
95
95
  [key: string]: any;
96
96
  }
97
97
 
98
- const defaultInstallOpt: InstallOptions = {};
98
+ const defaultInstallOpt: FormInstallOptions = {};
99
99
 
100
100
  export default {
101
- install(app: App, opt: InstallOptions = {}) {
101
+ install(app: App, opt: FormInstallOptions = {}) {
102
102
  const option = Object.assign(defaultInstallOpt, opt);
103
103
 
104
104
  // eslint-disable-next-line no-param-reassign
package/src/schema.ts CHANGED
@@ -296,6 +296,9 @@ export interface DaterangeConfig extends FormItem {
296
296
  type: 'daterange';
297
297
  defaultTime?: Date[];
298
298
  names?: string[];
299
+ valueFormat?: string;
300
+ dateFormat?: string;
301
+ timeFormat?: string;
299
302
  }
300
303
 
301
304
  /**
@@ -632,7 +635,7 @@ export interface PanelConfig extends FormItem, ContainerCommonConfig {
632
635
  schematic?: string;
633
636
  }
634
637
 
635
- export interface ColumnConfig extends FormItem {
638
+ export interface TableColumnConfig extends FormItem {
636
639
  name?: string;
637
640
  label: string;
638
641
  width?: string | number;
@@ -645,9 +648,9 @@ export interface ColumnConfig extends FormItem {
645
648
  */
646
649
  export interface TableConfig extends FormItem {
647
650
  type: 'table' | 'groupList' | 'group-list';
648
- items: ColumnConfig[];
649
- tableItems?: ColumnConfig[];
650
- groupItems?: ColumnConfig[];
651
+ items: TableColumnConfig[];
652
+ tableItems?: TableColumnConfig[];
653
+ groupItems?: TableColumnConfig[];
651
654
  enableToggleMode?: boolean;
652
655
  /** 最大行数 */
653
656
  max?: number;
package/src/utils/form.ts CHANGED
@@ -18,6 +18,8 @@
18
18
 
19
19
  /* eslint-disable no-param-reassign */
20
20
  import { toRaw } from 'vue';
21
+ import dayjs from 'dayjs';
22
+ import utc from 'dayjs/plugin/utc';
21
23
  import { cloneDeep } from 'lodash-es';
22
24
 
23
25
  import {
@@ -271,3 +273,28 @@ export const initValue = async (
271
273
 
272
274
  return valuesTmp || {};
273
275
  };
276
+
277
+ export const datetimeFormatter = (
278
+ v: string | Date,
279
+ defaultValue = '-',
280
+ format = 'YYYY-MM-DD HH:mm:ss',
281
+ ): string | number => {
282
+ if (v) {
283
+ let time: string | number;
284
+ if (['x', 'timestamp'].includes(format)) {
285
+ time = dayjs(v).valueOf();
286
+ } else if ((typeof v === 'string' && v.includes('Z')) || v.constructor === Date) {
287
+ dayjs.extend(utc);
288
+ // UTC字符串时间或Date对象格式化为北京时间
289
+ time = dayjs(v).utcOffset(8).format(format);
290
+ } else {
291
+ time = dayjs(v).format(format);
292
+ }
293
+
294
+ if (time !== 'Invalid Date') {
295
+ return time;
296
+ }
297
+ return defaultValue;
298
+ }
299
+ return defaultValue;
300
+ };
package/types/index.d.ts CHANGED
@@ -232,6 +232,9 @@ interface DaterangeConfig extends FormItem {
232
232
  type: 'daterange';
233
233
  defaultTime?: Date[];
234
234
  names?: string[];
235
+ valueFormat?: string;
236
+ dateFormat?: string;
237
+ timeFormat?: string;
235
238
  }
236
239
  /**
237
240
  * html编辑器
@@ -520,7 +523,7 @@ interface PanelConfig extends FormItem, ContainerCommonConfig {
520
523
  title?: string;
521
524
  schematic?: string;
522
525
  }
523
- interface ColumnConfig extends FormItem {
526
+ interface TableColumnConfig extends FormItem {
524
527
  name?: string;
525
528
  label: string;
526
529
  width?: string | number;
@@ -532,9 +535,9 @@ interface ColumnConfig extends FormItem {
532
535
  */
533
536
  interface TableConfig extends FormItem {
534
537
  type: 'table' | 'groupList' | 'group-list';
535
- items: ColumnConfig[];
536
- tableItems?: ColumnConfig[];
537
- groupItems?: ColumnConfig[];
538
+ items: TableColumnConfig[];
539
+ tableItems?: TableColumnConfig[];
540
+ groupItems?: TableColumnConfig[];
538
541
  enableToggleMode?: boolean;
539
542
  /** 最大行数 */
540
543
  max?: number;
@@ -614,6 +617,7 @@ declare const initValue: (mForm: FormState | undefined, { initValues, config }:
614
617
  initValues: FormValue;
615
618
  config: FormConfig;
616
619
  }) => Promise<FormValue>;
620
+ declare const datetimeFormatter: (v: string | Date, defaultValue?: string, format?: string) => string | number;
617
621
 
618
622
  declare const useAddField: (prop?: string) => void;
619
623
 
@@ -3229,11 +3233,11 @@ type __VLS_TypePropsToOption<T> = {
3229
3233
  };
3230
3234
 
3231
3235
  declare const createForm: <T extends [] = []>(config: FormConfig | T) => FormConfig | T;
3232
- interface InstallOptions {
3236
+ interface FormInstallOptions {
3233
3237
  [key: string]: any;
3234
3238
  }
3235
3239
  declare const _default: {
3236
- install(app: App, opt?: InstallOptions): void;
3240
+ install(app: App, opt?: FormInstallOptions): void;
3237
3241
  };
3238
3242
 
3239
- export { type CascaderConfig, type CascaderOption, type CheckboxConfig, type CheckboxGroupConfig, type CheckboxGroupOption, type ChildConfig, type ColorPickConfig, type ColumnConfig, type ComponentConfig, type ContainerCommonConfig, type DateConfig, type DateTimeConfig, type DaterangeConfig, type DisplayConfig, type DynamicFieldConfig, type FieldProps, type FieldsetConfig, type FilterFunction, type FormConfig, type FormItem, type FormState, type FormValue, type GroupListConfig, type HiddenConfig, type HtmlField, type Input, type InstallOptions, type LinkConfig, _default$2 as MCascader, _default$c as MCheckbox, _default$7 as MCheckboxGroup, _default$8 as MColorPicker, _default$r as MContainer, _default$f as MDate, _default$e as MDateTime, _default$a as MDaterange, _default$5 as MDisplay, _default$1 as MDynamicField, _default$q as MFieldset, _default$v as MForm, _default$s as MFormBox, _default$u as MFormDialog, _default$t as MFormDrawer, _default$l as MGroupList, _default$g as MHidden, _default$4 as MLink, _default$j as MNumber, _default$i as MNumberRange, _default$p as MPanel, _default$6 as MRadioGroup, _default$o as MRow, _default$3 as MSelect, _default$b as MSwitch, _default$m as MTable, _default$n as MTabs, _default$k as MText, _default$h as MTextarea, _default$d as MTime, _default$9 as MTimerange, type NumberConfig, type NumberRangeConfig, type PanelConfig, type RadioGroupConfig, type RowConfig, type Rule, type SelectConfig, type SelectConfigGroupOption, type SelectConfigOption, type SelectGroupOption, type SelectOption, type SortProp, type StepConfig, type SwitchConfig, type TabConfig, type TabPaneConfig, type TableConfig, type TextConfig, type TextareaConfig, type TimeConfig, type TypeFunction, type ValidateError, createForm, createValues, _default as default, display, filterFunction, getRules, initValue, useAddField };
3243
+ export { type CascaderConfig, type CascaderOption, type CheckboxConfig, type CheckboxGroupConfig, type CheckboxGroupOption, type ChildConfig, type ColorPickConfig, type ComponentConfig, type ContainerCommonConfig, type DateConfig, type DateTimeConfig, type DaterangeConfig, type DisplayConfig, type DynamicFieldConfig, type FieldProps, type FieldsetConfig, type FilterFunction, type FormConfig, type FormInstallOptions, type FormItem, type FormState, type FormValue, type GroupListConfig, type HiddenConfig, type HtmlField, type Input, type LinkConfig, _default$2 as MCascader, _default$c as MCheckbox, _default$7 as MCheckboxGroup, _default$8 as MColorPicker, _default$r as MContainer, _default$f as MDate, _default$e as MDateTime, _default$a as MDaterange, _default$5 as MDisplay, _default$1 as MDynamicField, _default$q as MFieldset, _default$v as MForm, _default$s as MFormBox, _default$u as MFormDialog, _default$t as MFormDrawer, _default$l as MGroupList, _default$g as MHidden, _default$4 as MLink, _default$j as MNumber, _default$i as MNumberRange, _default$p as MPanel, _default$6 as MRadioGroup, _default$o as MRow, _default$3 as MSelect, _default$b as MSwitch, _default$m as MTable, _default$n as MTabs, _default$k as MText, _default$h as MTextarea, _default$d as MTime, _default$9 as MTimerange, type NumberConfig, type NumberRangeConfig, type PanelConfig, type RadioGroupConfig, type RowConfig, type Rule, type SelectConfig, type SelectConfigGroupOption, type SelectConfigOption, type SelectGroupOption, type SelectOption, type SortProp, type StepConfig, type SwitchConfig, type TabConfig, type TabPaneConfig, type TableColumnConfig, type TableConfig, type TextConfig, type TextareaConfig, type TimeConfig, type TypeFunction, type ValidateError, createForm, createValues, datetimeFormatter, _default as default, display, filterFunction, getRules, initValue, useAddField };