cloud-web-corejs 1.0.54-dev.652 → 1.0.54-dev.653

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloud-web-corejs",
3
3
  "private": false,
4
- "version": "1.0.54-dev.652",
4
+ "version": "1.0.54-dev.653",
5
5
  "scripts": {
6
6
  "dev": "vue-cli-service serve",
7
7
  "lint": "eslint --ext .js,.vue src",
@@ -10,7 +10,7 @@
10
10
  :format="field.options.format" :value-format="field.options.valueFormat"
11
11
  :placeholder="getI18nLabel(field.options.placeholder || '选择日期')"
12
12
  @focus="handleFocusCustomEvent" @blur="handleBlurCustomEvent"
13
- @change="handleChangeEvent"
13
+ @change="handleDateChangeEvent"
14
14
  :picker-options="pickerOptions"
15
15
  >
16
16
  </el-date-picker>
@@ -25,11 +25,12 @@ import FormItemWrapper from './form-item-wrapper'
25
25
  import emitter from '../../../../../components/xform/utils/emitter'
26
26
  import i18n from "../../../../../components/xform/utils/i18n";
27
27
  import fieldMixin from "../../../../../components/xform/form-designer/form-widget/field-widget/fieldMixin";
28
+ import dateLimitMixin from "../../../../../components/xform/form-designer/form-widget/field-widget/mixins/date-limit-mixin";
28
29
 
29
30
  export default {
30
31
  name: "date-widget",
31
32
  componentName: 'FieldWidget', //必须固定为FieldWidget,用于接收父级组件的broadcast事件
32
- mixins: [emitter, fieldMixin, i18n],
33
+ mixins: [emitter, fieldMixin, i18n, dateLimitMixin],
33
34
  props: {
34
35
  field: Object,
35
36
  parentWidget: Object,
@@ -73,6 +74,20 @@ export default {
73
74
  return this.fieldModel ? this.fieldModel : ''
74
75
  },
75
76
  },
77
+ watch: {
78
+ "field.options.limitStartField"() {
79
+ this.initDateLimitPickerOptions();
80
+ },
81
+ "field.options.limitEndField"() {
82
+ this.initDateLimitPickerOptions();
83
+ },
84
+ "field.options.minDate"() {
85
+ this.initDateLimitPickerOptions();
86
+ },
87
+ "field.options.maxDate"() {
88
+ this.initDateLimitPickerOptions();
89
+ },
90
+ },
76
91
  beforeCreate() {
77
92
  /* 这里不能访问方法和属性!! */
78
93
  },
@@ -86,19 +101,12 @@ export default {
86
101
  this.buildFieldRules()
87
102
 
88
103
  this.handleOnCreated()
89
-
90
- if(['year','month','date'].includes(this.field.options.type)){
91
- this.pickerOptions.shortcuts = [{
92
- text: this.$t1('此刻'),
93
- onClick(picker) {
94
- picker.$emit('pick', new Date());
95
- }
96
- }]
97
- }
104
+ this.initDateLimitPickerOptions()
98
105
  },
99
106
 
100
107
  mounted() {
101
108
  this.handleOnMounted()
109
+ this.initDateLimitWatch()
102
110
  },
103
111
 
104
112
  beforeDestroy() {
@@ -106,11 +114,16 @@ export default {
106
114
  },
107
115
 
108
116
  methods: {
117
+ handleDateChangeEvent(value) {
118
+ if (this.isDateLimitViolated(value)) {
119
+ this.$message.warning(this.getDateLimitViolationMessage());
120
+ this.fieldModel = this.oldFieldValue;
121
+ return;
122
+ }
123
+ this.handleChangeEvent(value);
124
+ },
109
125
  setNow() {
110
126
  this.$refs.fieldEditor.panel.changeToNow()
111
- /*this.selectedDate = new Date();
112
- // 可选:点击后自动关闭弹窗
113
- this.$refs.datePicker.pickerVisible = false;*/
114
127
  }
115
128
  }
116
129
  }
@@ -0,0 +1,157 @@
1
+ export default {
2
+ methods: {
3
+ getDateLimitOptions() {
4
+ return this.field.options || {};
5
+ },
6
+ initDateLimitPickerOptions() {
7
+ const pickerOptions = { ...(this.pickerOptions || {}) };
8
+ if (["year", "month", "date", "datetime"].includes(this.field.options.type)) {
9
+ if (!pickerOptions.shortcuts) {
10
+ pickerOptions.shortcuts = [
11
+ {
12
+ text: this.$t1("此刻"),
13
+ onClick(picker) {
14
+ picker.$emit("pick", new Date());
15
+ },
16
+ },
17
+ ];
18
+ }
19
+ }
20
+ pickerOptions.disabledDate = (time) => this.isDateLimitDisabled(time);
21
+ this.pickerOptions = pickerOptions;
22
+ },
23
+ initDateLimitWatch() {
24
+ if (this.designState) {
25
+ return;
26
+ }
27
+ const { limitStartField, limitEndField } = this.getDateLimitOptions();
28
+ if (limitStartField) {
29
+ this.$watch(
30
+ () => this.getDateLimitLinkedValue(limitStartField),
31
+ () => {
32
+ this.initDateLimitPickerOptions();
33
+ }
34
+ );
35
+ }
36
+ if (limitEndField) {
37
+ this.$watch(
38
+ () => this.getDateLimitLinkedValue(limitEndField),
39
+ () => {
40
+ this.initDateLimitPickerOptions();
41
+ }
42
+ );
43
+ }
44
+ },
45
+ getDateLimitDataSource() {
46
+ return this.tableParam && this.tableParam.row
47
+ ? this.tableParam.row
48
+ : this.formModel;
49
+ },
50
+ getDateLimitLinkedValue(fieldName) {
51
+ if (!fieldName) {
52
+ return null;
53
+ }
54
+ const dataSource = this.getDateLimitDataSource();
55
+ return dataSource ? dataSource[fieldName] : null;
56
+ },
57
+ parseDateLimitValue(val) {
58
+ if (val === null || val === undefined || val === "") {
59
+ return null;
60
+ }
61
+ const date = new Date(String(val).replace(/-/g, "/"));
62
+ return isNaN(date.getTime()) ? null : date.getTime();
63
+ },
64
+ normalizeDateLimitDayTime(time, isEnd) {
65
+ const date = new Date(time);
66
+ if (this.field.options.type === "datetime") {
67
+ return date.getTime();
68
+ }
69
+ date.setHours(isEnd ? 23 : 0, isEnd ? 59 : 0, isEnd ? 59 : 0, isEnd ? 999 : 0);
70
+ return date.getTime();
71
+ },
72
+ isDateLimitDisabled(time) {
73
+ const options = this.getDateLimitOptions();
74
+ const currentTime = time.getTime();
75
+
76
+ const minDate = this.parseDateLimitValue(options.minDate);
77
+ if (minDate !== null && currentTime < this.normalizeDateLimitDayTime(minDate, false)) {
78
+ return true;
79
+ }
80
+
81
+ const maxDate = this.parseDateLimitValue(options.maxDate);
82
+ if (maxDate !== null && currentTime > this.normalizeDateLimitDayTime(maxDate, true)) {
83
+ return true;
84
+ }
85
+
86
+ if (options.limitStartField) {
87
+ const startTime = this.parseDateLimitValue(
88
+ this.getDateLimitLinkedValue(options.limitStartField)
89
+ );
90
+ if (startTime !== null && currentTime < this.normalizeDateLimitDayTime(startTime, false)) {
91
+ return true;
92
+ }
93
+ }
94
+
95
+ if (options.limitEndField) {
96
+ const endTime = this.parseDateLimitValue(
97
+ this.getDateLimitLinkedValue(options.limitEndField)
98
+ );
99
+ if (endTime !== null && currentTime > this.normalizeDateLimitDayTime(endTime, true)) {
100
+ return true;
101
+ }
102
+ }
103
+
104
+ return false;
105
+ },
106
+ isDateLimitViolated(value) {
107
+ if (value === null || value === undefined || value === "") {
108
+ return false;
109
+ }
110
+ const currentTime = this.parseDateLimitValue(value);
111
+ if (currentTime === null) {
112
+ return false;
113
+ }
114
+
115
+ const options = this.getDateLimitOptions();
116
+ const minDate = this.parseDateLimitValue(options.minDate);
117
+ if (minDate !== null && currentTime < this.normalizeDateLimitDayTime(minDate, false)) {
118
+ return true;
119
+ }
120
+
121
+ const maxDate = this.parseDateLimitValue(options.maxDate);
122
+ if (maxDate !== null && currentTime > this.normalizeDateLimitDayTime(maxDate, true)) {
123
+ return true;
124
+ }
125
+
126
+ if (options.limitStartField) {
127
+ const startTime = this.parseDateLimitValue(
128
+ this.getDateLimitLinkedValue(options.limitStartField)
129
+ );
130
+ if (startTime !== null && currentTime < this.normalizeDateLimitDayTime(startTime, false)) {
131
+ return true;
132
+ }
133
+ }
134
+
135
+ if (options.limitEndField) {
136
+ const endTime = this.parseDateLimitValue(
137
+ this.getDateLimitLinkedValue(options.limitEndField)
138
+ );
139
+ if (endTime !== null && currentTime > this.normalizeDateLimitDayTime(endTime, true)) {
140
+ return true;
141
+ }
142
+ }
143
+
144
+ return false;
145
+ },
146
+ getDateLimitViolationMessage() {
147
+ const options = this.getDateLimitOptions();
148
+ if (options.limitEndField && !options.limitStartField) {
149
+ return "开始时间不能大于结束时间";
150
+ }
151
+ if (options.limitStartField && !options.limitEndField) {
152
+ return "结束时间不能小于开始时间";
153
+ }
154
+ return "日期超出允许范围";
155
+ },
156
+ },
157
+ };
@@ -834,6 +834,7 @@ export default {
834
834
  this.openWidgetPropertyDialog({
835
835
  row: row,
836
836
  columnSelectedWidget: selectedWidget,
837
+ tableColumns: this.optionModel.tableColumns,
837
838
  index: index,
838
839
  columnEditFields: columnEditFields,
839
840
  callback: (columnOption) => {
@@ -13,7 +13,7 @@
13
13
  @close="handleClose"
14
14
  >
15
15
  <div class="cont">
16
- <el-form label-width="150px" class="edit-tree-button-group-form">
16
+ <el-form label-width="166px" class="edit-tree-button-group-form">
17
17
  <el-form-item label="新增按钮唯一名称">
18
18
  <el-input
19
19
  v-model="row.rowAddAuthName"
@@ -0,0 +1,157 @@
1
+ <template>
2
+ <div>
3
+ <el-form-item label="关联开始字段">
4
+ <el-select
5
+ v-if="dateFieldOptions.length"
6
+ v-model="optionModel.limitStartField"
7
+ filterable
8
+ clearable
9
+ placeholder="不能小于该字段值"
10
+ >
11
+ <el-option
12
+ v-for="item in dateFieldOptions"
13
+ :key="item.value"
14
+ :label="item.label"
15
+ :value="item.value"
16
+ ></el-option>
17
+ </el-select>
18
+ <el-input
19
+ v-else
20
+ v-model="optionModel.limitStartField"
21
+ placeholder="请输入开始字段属性名"
22
+ clearable
23
+ ></el-input>
24
+ </el-form-item>
25
+ <el-form-item label="关联结束字段">
26
+ <el-select
27
+ v-if="dateFieldOptions.length"
28
+ v-model="optionModel.limitEndField"
29
+ filterable
30
+ clearable
31
+ placeholder="不能大于该字段值"
32
+ >
33
+ <el-option
34
+ v-for="item in dateFieldOptions"
35
+ :key="item.value"
36
+ :label="item.label"
37
+ :value="item.value"
38
+ ></el-option>
39
+ </el-select>
40
+ <el-input
41
+ v-else
42
+ v-model="optionModel.limitEndField"
43
+ placeholder="请输入结束字段属性名"
44
+ clearable
45
+ ></el-input>
46
+ </el-form-item>
47
+ <el-form-item label="最小日期">
48
+ <el-date-picker
49
+ v-model="optionModel.minDate"
50
+ :type="pickerType"
51
+ :format="optionModel.format"
52
+ :value-format="optionModel.valueFormat"
53
+ style="width: 100%"
54
+ clearable
55
+ placeholder="留空则不限制"
56
+ ></el-date-picker>
57
+ </el-form-item>
58
+ <el-form-item label="最大日期">
59
+ <el-date-picker
60
+ v-model="optionModel.maxDate"
61
+ :type="pickerType"
62
+ :format="optionModel.format"
63
+ :value-format="optionModel.valueFormat"
64
+ style="width: 100%"
65
+ clearable
66
+ placeholder="留空则不限制"
67
+ ></el-date-picker>
68
+ </el-form-item>
69
+ </div>
70
+ </template>
71
+
72
+ <script>
73
+ import i18n from "../../../../../../components/xform/utils/i18n";
74
+ import propertyMixin from "../../../../../../components/xform/form-designer/setting-panel/property-editor/propertyMixin";
75
+ import { loopHandleWidget } from "../../../../../../components/xform/utils/util";
76
+
77
+ export default {
78
+ name: "date-dateLimit-editor",
79
+ mixins: [i18n, propertyMixin],
80
+ props: {
81
+ designer: Object,
82
+ selectedWidget: Object,
83
+ optionModel: Object,
84
+ tableColumns: Array,
85
+ },
86
+ computed: {
87
+ pickerType() {
88
+ return this.optionModel.type || "date";
89
+ },
90
+ currentFieldKey() {
91
+ return this.getFieldKeyByOptions(this.optionModel);
92
+ },
93
+ dateFieldOptions() {
94
+ let options = [];
95
+ if (this.tableColumns && this.tableColumns.length) {
96
+ this.collectDateFieldsFromColumns(this.tableColumns, options);
97
+ } else if (this.designer && this.designer.widgetList) {
98
+ loopHandleWidget(this.designer.widgetList, (widget) => {
99
+ if (widget.type !== "date" || widget.id === this.selectedWidget.id) {
100
+ return;
101
+ }
102
+ let fieldKey = this.getFieldKeyByOptions(widget.options);
103
+ if (fieldKey && fieldKey !== this.currentFieldKey) {
104
+ options.push({
105
+ value: fieldKey,
106
+ label: widget.options.label || fieldKey,
107
+ });
108
+ }
109
+ });
110
+ }
111
+ return options;
112
+ },
113
+ },
114
+ methods: {
115
+ getFieldKeyByOptions(options) {
116
+ if (!options) {
117
+ return "";
118
+ }
119
+ return (options.keyNameEnabled && options.keyName) || options.name || "";
120
+ },
121
+ collectDateFieldsFromColumns(columns, options) {
122
+ columns.forEach((col) => {
123
+ if (col.children && col.children.length) {
124
+ this.collectDateFieldsFromColumns(col.children, options);
125
+ return;
126
+ }
127
+ if (!this.isDateColumn(col)) {
128
+ return;
129
+ }
130
+ let fieldKey = col.prop;
131
+ if (col.columnOption) {
132
+ fieldKey = this.getFieldKeyByOptions(col.columnOption) || fieldKey;
133
+ }
134
+ if (col.editColumnOption) {
135
+ fieldKey =
136
+ this.getFieldKeyByOptions(col.editColumnOption) || fieldKey;
137
+ }
138
+ if (fieldKey && fieldKey !== this.currentFieldKey) {
139
+ options.push({
140
+ value: fieldKey,
141
+ label: col.label || fieldKey,
142
+ });
143
+ }
144
+ });
145
+ },
146
+ isDateColumn(col) {
147
+ return (
148
+ col.formatS === "date" ||
149
+ col.formatS === "editDate" ||
150
+ col.editFormatS === "editDate" ||
151
+ col.widget?.type === "date" ||
152
+ col.editWidget?.type === "date"
153
+ );
154
+ },
155
+ },
156
+ };
157
+ </script>
@@ -43,6 +43,7 @@ const COMMON_PROPERTIES = {
43
43
  htmlContent: "htmlContent-editor",
44
44
  format: "format-editor",
45
45
  valueFormat: "valueFormat-editor",
46
+ dateLimit: "dateLimit-editor",
46
47
  defaultTime: "defaultTime-editor",
47
48
  filterable: "filterable-editor",
48
49
  allowCreate: "allowCreate-editor",
@@ -1523,6 +1523,11 @@ export const basicFields = [
1523
1523
  editable: !1,
1524
1524
  format: "yyyy-MM-dd",
1525
1525
  valueFormat: "yyyy-MM-dd",
1526
+ dateLimit: null,
1527
+ limitStartField: null,
1528
+ limitEndField: null,
1529
+ minDate: null,
1530
+ maxDate: null,
1526
1531
  required: !1,
1527
1532
  requiredHint: "",
1528
1533
  validation: "",