starfish-form-custom 1.0.19 → 1.0.21

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.
@@ -8,7 +8,9 @@
8
8
  </el-tooltip>
9
9
  </div>
10
10
  <div class="control" :style="{marginLeft: labelalign != 'top'?labelWidth + 'px': ''}">
11
- <el-checkbox-group v-model="data[item.data.fieldName]" :class="{'vertical-group': item.data.arrangeMent === 'vertical'}" v-if="!drag && data[item.data.fieldName]" :size="size" :disabled="item.data.state === 'disabled' || item.data.state === 'readonly'">
11
+ <!-- 只读的时候就只展示文本 -->
12
+ <span v-if="!drag && data[item.data.fieldName] && item.data.state === 'readonly'">{{ data[item.data.fieldName].join(',') || '--' }}</span>
13
+ <el-checkbox-group v-model="data[item.data.fieldName]" :class="{'vertical-group': item.data.arrangeMent === 'vertical'}" v-else-if="!drag && data[item.data.fieldName]" :size="size" :disabled="item.data.state === 'disabled' || item.data.state === 'readonly'">
12
14
  <el-checkbox v-for="(sitem, sindex) in item.data.itemConfig.items" :key="sindex" :label="sitem.value">{{ sitem.label }}</el-checkbox>
13
15
  </el-checkbox-group>
14
16
  <el-checkbox-group v-model="item.data.itemConfig.value" :class="{'vertical-group': item.data.arrangeMent === 'vertical'}" v-if="drag" :size="size" :disabled="item.data.state === 'disabled' || item.data.state === 'readonly'">
@@ -23,6 +23,8 @@
23
23
  ></el-date-picker>
24
24
 
25
25
  <!-- 实际运行时的组件 -->
26
+ <!-- 只读的时候就展示文字 -->
27
+ <span v-if="!drag && item.data.state === 'readonly'">{{ formatReadonlyDate(data[item.data.fieldName], item.data.format) }}</span>
26
28
  <el-date-picker
27
29
  v-model="data[item.data.fieldName]"
28
30
  width="240px"
@@ -30,7 +32,7 @@
30
32
  :format="item.data.format"
31
33
  :value-format="item.data.format"
32
34
  :placeholder="item.data.placeholder"
33
- v-if="!drag"
35
+ v-else-if="!drag"
34
36
  :size="size"
35
37
  :disabled="item.data.state === 'disabled'"
36
38
  :readonly="item.data.state === 'readonly'"
@@ -48,7 +50,7 @@
48
50
  nameCn: "日期",
49
51
  icon: "icon-24gl-calendar",
50
52
  formConfig: getFormConfig("Date", [
51
- { fieldName: "default", component: "Date" },
53
+ { fieldName: "default", component: "DateTime" },
52
54
  { fieldName: "placeholder", component: "Text" },
53
55
  { fieldName: "format", component: "Selected" },
54
56
  { fieldName: "state", component: "Radio" },
@@ -73,9 +75,43 @@
73
75
  };
74
76
 
75
77
  return formatTypeMap[format] || 'date';
78
+ };
79
+ // 格式化只读日期显示
80
+ const formatReadonlyDate = (dateValue: any, format: string) => {
81
+ if (!dateValue) return '--';
82
+
83
+ // 如果已经是格式化好的字符串,直接返回
84
+ if (typeof dateValue === 'string') {
85
+ return dateValue;
86
+ }
87
+
88
+ // 如果是日期对象,进行格式化
89
+ if (dateValue instanceof Date) {
90
+ const year = dateValue.getFullYear();
91
+ const month = String(dateValue.getMonth() + 1).padStart(2, '0');
92
+ const day = String(dateValue.getDate()).padStart(2, '0');
93
+ const hours = String(dateValue.getHours()).padStart(2, '0');
94
+ const minutes = String(dateValue.getMinutes()).padStart(2, '0');
95
+ const seconds = String(dateValue.getSeconds()).padStart(2, '0');
96
+
97
+ const formatMap: Record<string, string> = {
98
+ 'YYYY': `${year}`,
99
+ 'YYYY-MM': `${year}-${month}`,
100
+ 'YYYY-MM-DD': `${year}-${month}-${day}`,
101
+ 'YYYY-MM-DD HH': `${year}-${month}-${day} ${hours}`,
102
+ 'YYYY-MM-DD HH:mm': `${year}-${month}-${day} ${hours}:${minutes}`,
103
+ 'YYYY-MM-DD HH:mm:ss': `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
104
+ };
105
+
106
+ return formatMap[format] || `${year}-${month}-${day}`;
107
+ }
108
+
109
+ // 其他情况返回原始值
110
+ return String(dateValue);
76
111
  };
77
112
  return {
78
- getPickerType
113
+ getPickerType,
114
+ formatReadonlyDate
79
115
  };
80
116
  },
81
117
  });
@@ -37,10 +37,12 @@
37
37
  :disabled="item.data.state === 'disabled' || item.data.state === 'readonly'"
38
38
  v-if="drag"
39
39
  />
40
+ <!-- 只读展示文字 -->
41
+ <span v-if="!drag && item.data.state === 'readonly'">{{ formatReadonlyNumber(data[item.data.fieldName], item.data.precision) }}</span>
40
42
  <el-input-number
41
43
  v-model="data[item.data.fieldName]"
42
44
  width="240px"
43
- v-if="!drag"
45
+ v-else-if="!drag"
44
46
  :controls-position="item.data.type == 2 ? 'right' : ''"
45
47
  :disabled="item.data.state === 'disabled' || item.data.state === 'readonly'"
46
48
  :precision="item.data.precision"
@@ -78,7 +80,30 @@ export default defineComponent({
78
80
  setup(props) {
79
81
  const vm = getCurrentInstance() as ComponentInternalInstance;
80
82
  useWatch(props);
83
+ // 格式化只读数字显示
84
+ const formatReadonlyNumber = (value: any, precision: number) => {
85
+ if (value === null || value === undefined || value === '') {
86
+ return '-';
87
+ }
88
+
89
+ // 转换为数字
90
+ const numValue = Number(value);
91
+
92
+ // 检查是否为有效数字
93
+ if (isNaN(numValue)) {
94
+ return String(value);
95
+ }
96
+
97
+ // 如果有精度设置,进行格式化
98
+ if (precision !== undefined && precision !== null) {
99
+ return numValue.toFixed(precision);
100
+ }
101
+
102
+ // 如果没有精度设置,直接返回数字
103
+ return String(numValue);
104
+ };
81
105
  return {
106
+ formatReadonlyNumber,
82
107
  execFunc(type: string) {
83
108
  if (props.item.data.action && props.item.data.action[type]) {
84
109
  window.VApp.$Flex.funcExec(props.item.data.action[type], vm.proxy, [
@@ -29,8 +29,9 @@
29
29
  class="control"
30
30
  :style="{ marginLeft: labelalign != 'top' ? labelWidth + 'px' : '' }"
31
31
  >
32
+ <span v-if="!drag && item.data.state === 'readonly'">{{ data[item.data.fieldName] || '--' }}</span>
32
33
  <el-radio-group
33
- v-if="!drag"
34
+ v-else-if="!drag"
34
35
  v-model="data[item.data.fieldName]"
35
36
  :size="size"
36
37
  :class="{'vertical-group': item.data.arrangeMent === 'vertical'}"
@@ -24,11 +24,24 @@
24
24
  class="control"
25
25
  :style="{ marginLeft: labelalign != 'top' ? labelWidth + 'px' : '' }"
26
26
  >
27
- <el-collapse
27
+ <el-dropdown @command="handleDropdown" style="margin-top: 10px">
28
+ <el-button type="success">
29
+ 新增规则<i class="el-icon-arrow-down el-icon--right"></i>
30
+ </el-button>
31
+ <template #dropdown>
32
+ <el-dropdown-menu>
33
+ <el-dropdown-item command="enum">默认枚举</el-dropdown-item>
34
+ <el-dropdown-item command="func">自定义函数规则</el-dropdown-item>
35
+ <el-dropdown-item command="high">高级模式</el-dropdown-item>
36
+ </el-dropdown-menu>
37
+ </template>
38
+ </el-dropdown>
39
+ <el-collapse
28
40
  v-if="
29
41
  Array.isArray(data[item.data.fieldName]) &&
30
42
  data[item.data.fieldName].length > 0
31
43
  "
44
+ style="margin-top: 16px;"
32
45
  >
33
46
  <el-collapse-item
34
47
  :title="itemList.title"
@@ -68,28 +81,9 @@
68
81
  >规则表单编辑</el-button
69
82
  >
70
83
  </div>
71
- <el-button
72
- type="danger"
73
- circle
74
- @click="deleteRule(index)"
75
- style="margin-left: 10px"
76
- >
77
- <el-icon><Delete /></el-icon>
78
- </el-button>
84
+ <el-icon @click="deleteRule(index)" style="margin-left: 10px" :size="14"><Delete /></el-icon>
79
85
  </el-collapse-item>
80
86
  </el-collapse>
81
- <el-dropdown @command="handleDropdown" style="margin-top: 10px">
82
- <el-button type="success">
83
- 新增规则<i class="el-icon-arrow-down el-icon--right"></i>
84
- </el-button>
85
- <template #dropdown>
86
- <el-dropdown-menu>
87
- <el-dropdown-item command="enum">默认枚举</el-dropdown-item>
88
- <el-dropdown-item command="func">自定义函数规则</el-dropdown-item>
89
- <el-dropdown-item command="high">高级模式</el-dropdown-item>
90
- </el-dropdown-menu>
91
- </template>
92
- </el-dropdown>
93
87
  </div>
94
88
  <CustomDialog ref="codeMyDialog">
95
89
  <div
@@ -43,11 +43,12 @@
43
43
  :value="items.value"
44
44
  />
45
45
  </el-select>
46
+ <span v-if="!drag && item.data.state === 'readonly'">{{ data[item.data.fieldName] || '--' }}</span>
46
47
  <el-select
47
48
  v-model="data[item.data.fieldName]"
48
49
  width="240px"
49
50
  :placeholder="item.data.placeholder"
50
- v-if="!drag"
51
+ v-else-if="!drag"
51
52
  :size="size"
52
53
  :disabled="item.data.state === 'disabled' || item.data.state === 'readonly'"
53
54
  @focus="execFunc('onFocus')"
@@ -44,11 +44,12 @@
44
44
  :value="items.value"
45
45
  />
46
46
  </el-select>
47
+ <span v-if="!drag && item.data.state === 'readonly'">{{ data[item.data.fieldName].join(',') || '--' }}</span>
47
48
  <el-select
48
49
  v-model="data[item.data.fieldName]"
49
50
  width="240px"
50
51
  :placeholder="item.data.placeholder"
51
- v-if="!drag"
52
+ v-else-if="!drag"
52
53
  multiple
53
54
  :size="size"
54
55
  :disabled="item.data.state === 'disabled' || item.data.state === 'readonly'"
@@ -41,11 +41,12 @@
41
41
  :minlength="item.data.minLength"
42
42
  :class="'input-' + item.data.align"
43
43
  />
44
+ <span v-if="!drag && item.data.state === 'readonly'">{{ data[item.data.fieldName] || '--' }}</span>
44
45
  <el-input
45
46
  v-model="data[item.data.fieldName]"
46
47
  width="200px"
47
48
  :placeholder="item.data.placeholder"
48
- v-if="!drag"
49
+ v-else-if="!drag"
49
50
  :size="size"
50
51
  :disabled="item.data.state === 'disabled'"
51
52
  :readonly="item.data.state === 'readonly'"
@@ -40,9 +40,10 @@
40
40
  :autosize="item.data.autoHeight"
41
41
  :size="size"
42
42
  />
43
+ <span v-if="!drag && item.data.state === 'readonly'">{{ data[item.data.fieldName] || '--' }}</span>
43
44
  <el-input
44
45
  type="textarea"
45
- v-if="!drag"
46
+ v-else-if="!drag"
46
47
  v-model="data[item.data.fieldName]"
47
48
  :placeholder="item.data.placeholder"
48
49
  :disabled="item.data.state === 'disabled'"
@@ -6,7 +6,7 @@
6
6
  <draggable class="draggable-box" animation="300" ghostClass="itemGhost" v-model="colItem.list" @add="addControl($event, index)" group="starfish-form" @choose="chooseClick($event, index)" item-key="id" @update="changePos($event, index)">
7
7
  <template #item="{ element, index }">
8
8
  <Shape v-if="element.data" :active="currentId == element.id" :currentId="element.id" :currentIndex="index" :list="colItem.list">
9
- <component :is="element.ControlType" :drag="true" :item="element" :data="{}"></component>
9
+ <component :is="element.ControlType" :drag="true" size="default" :item="element" :data="{}"></component>
10
10
  </Shape>
11
11
  </template>
12
12
  </draggable>
@@ -16,10 +16,10 @@
16
16
  <el-col class="grid-col" v-for="(colItem, index) in item.data.columns" :key="index" :span="colItem.span">
17
17
  <template v-for="listItem in colItem.list" >
18
18
  <el-form-item :prop="listItem.data.fieldName" :key="listItem.id" v-if="!listItem.layout">
19
- <component ref="controlObj" @change="$emit('change')" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false"></component>
19
+ <component ref="controlObj" @change="$emit('change')" :is="listItem.ControlType" :item="listItem" size="default" :data="data || '{}'" :drag="false"></component>
20
20
  </el-form-item>
21
21
  <template v-else>
22
- <component ref="controlObj" @change="$emit('change')" :key="listItem.id" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false"></component>
22
+ <component ref="controlObj" @change="$emit('change')" :key="listItem.id" :is="listItem.ControlType" size="default" :item="listItem" :data="data || '{}'" :drag="false"></component>
23
23
  </template>
24
24
  </template>
25
25
  </el-col>
@@ -6,17 +6,17 @@
6
6
  <template v-if="drag">
7
7
  <draggable class="draggable-box" animation="300" ghostClass="itemGhost" v-model="tdItem.list" @add="addControl($event, tdItem.list, index, tdIndex)" group="starfish-form" @choose="chooseClick($event, tdItem.list)" item-key="id" @update="changePos($event, tdItem.list)">
8
8
  <template #item="{ element, index }">
9
- <Shape v-if="element.data" :active="currentId == element.id" :currentIndex="index" :currentId="element.id" :len="tdItem.list.length" :item="element"> <component :is="element.ControlType" :drag="true" :item="element" :data="{}"></component></Shape>
9
+ <Shape v-if="element.data" :active="currentId == element.id" :currentIndex="index" :currentId="element.id" :len="tdItem.list.length" :item="element"> <component :is="element.ControlType" size="default" :drag="true" :item="element" :data="{}"></component></Shape>
10
10
  </template>
11
11
  </draggable>
12
12
  </template>
13
13
  <template v-else-if="!drag && tdItem.list.length > 0">
14
14
  <template v-for="listItem in tdItem.list">
15
15
  <el-form-item :prop="listItem.data.fieldName" :key="listItem.id" v-if="!listItem.layout">
16
- <component ref="controlObj" @change="$emit('change')" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false" ></component>
16
+ <component ref="controlObj" @change="$emit('change')" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" size="default" :drag="false" ></component>
17
17
  </el-form-item>
18
18
  <template v-else>
19
- <component ref="controlObj" @change="$emit('change')" :key="listItem.id" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false" ></component>
19
+ <component ref="controlObj" @change="$emit('change')" size="default" :key="listItem.id" :is="listItem.ControlType" :item="listItem" :data="data || '{}'" :drag="false" ></component>
20
20
  </template>
21
21
  </template>
22
22
  </template>
@@ -551,7 +551,7 @@ function getMoren(
551
551
  placeholder: "",
552
552
  showRule: "{}",
553
553
  required: false,
554
- rule: "[]",
554
+ rule: "[]"
555
555
  },
556
556
  },
557
557
  placeholder: {
@@ -968,6 +968,7 @@ interface Config {
968
968
  fieldName: string;
969
969
  component: string;
970
970
  label?: string;
971
+ format?: string;
971
972
  }
972
973
 
973
974
  interface FormConfigReturn {