sard-uniapp 1.13.3 → 1.14.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/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # [1.14.0](https://github.com/sutras/sard-uniapp/compare/v1.13.3...v1.14.0) (2025-05-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * cascader 新增 change-on-select 属性 ([71c1329](https://github.com/sutras/sard-uniapp/commit/71c13291780eea13ac7c198ae31a39e0dc49d531))
7
+
8
+
9
+
1
10
  ## [1.13.3](https://github.com/sutras/sard-uniapp/compare/v1.13.2...v1.13.3) (2025-05-12)
2
11
 
3
12
 
@@ -112,7 +112,8 @@ export default _defineComponent({
112
112
  options: { type: Array, required: false },
113
113
  fieldKeys: { type: Object, required: false },
114
114
  hintText: { type: String, required: false },
115
- labelRender: { type: Function, required: false }
115
+ labelRender: { type: Function, required: false },
116
+ changeOnSelect: { type: Boolean, required: false }
116
117
  }, defaultCascaderProps),
117
118
  emits: ["update:model-value", "change", "select"],
118
119
  setup(__props, { expose: __expose, emit: __emit }) {
@@ -177,31 +178,25 @@ export default _defineComponent({
177
178
  if (selectBack) {
178
179
  nextTabs = nextTabs.slice(0, tabIndex + 1);
179
180
  }
180
- if (!isLastOption(option)) {
181
+ const isLast = isLastOption(option);
182
+ if (!isLast) {
181
183
  const nextTab = {
182
184
  options: option[mergedFieldKeys.value.children],
183
185
  selected: null
184
186
  };
185
187
  nextTabs.push(nextTab);
186
- tabsCurrent.value = nextTabs.length - 1;
187
- } else {
188
- tabsCurrent.value = tabIndex;
189
- const nextValue = option[mergedFieldKeys.value.value];
190
- innerValue.value = nextValue;
191
- emit(
192
- "update:model-value",
193
- nextValue,
194
- nextTabs.map((tab) => tab.selected)
195
- );
196
- emit(
197
- "change",
198
- nextValue,
199
- nextTabs.map((tab) => tab.selected)
200
- );
201
188
  }
189
+ tabsCurrent.value = isLast ? tabIndex : nextTabs.length - 1;
202
190
  tempValue = option[mergedFieldKeys.value.value];
203
191
  tabs.value = nextTabs;
204
192
  emit("select", option, tabIndex);
193
+ if (isLast || props.changeOnSelect) {
194
+ const nextValue = option[mergedFieldKeys.value.value];
195
+ innerValue.value = nextValue;
196
+ const selectedOptions = nextTabs.map((tab) => tab.selected).filter(Boolean);
197
+ emit("update:model-value", nextValue, selectedOptions);
198
+ emit("change", nextValue, selectedOptions);
199
+ }
205
200
  };
206
201
  const innerPaceholder = computed(() => {
207
202
  return props.hintText || t("pleaseSelect");
@@ -20,6 +20,7 @@ export interface CascaderProps {
20
20
  fieldKeys?: CascaderFieldKeys;
21
21
  hintText?: string;
22
22
  labelRender?: (option: CascaderOption) => string;
23
+ changeOnSelect?: boolean;
23
24
  }
24
25
  export declare const defaultCascaderProps: {
25
26
  options: () => never[];
@@ -23,11 +23,13 @@
23
23
  <sar-cascader
24
24
  v-if="already"
25
25
  :model-value="popoutValue"
26
- @change="onChange"
27
26
  :options="options"
28
27
  :field-keys="fieldKeys"
29
- :placeholder="hintText"
28
+ :hint-text="hintText"
29
+ :change-on-select="changeOnSelect"
30
+ :label-render="labelRender"
30
31
  @select="(option, tabIndex) => $emit('select', option, tabIndex)"
32
+ @change="onChange"
31
33
  >
32
34
  <template #top="{ tabIndex }">
33
35
  <slot name="top" :tab-index="tabIndex"></slot>
@@ -77,6 +79,7 @@ export default _defineComponent({
77
79
  fieldKeys: { type: Object, required: false },
78
80
  hintText: { type: String, required: false },
79
81
  labelRender: { type: Function, required: false },
82
+ changeOnSelect: { type: Boolean, required: false },
80
83
  placeholder: { type: String, required: false },
81
84
  readonly: { type: Boolean, required: false },
82
85
  disabled: { type: Boolean, required: false },
@@ -114,10 +117,12 @@ export default _defineComponent({
114
117
  }
115
118
  };
116
119
  const onConfirm = () => {
117
- innerValue.value = popoutValue.value;
118
- emit("update:model-value", popoutValue.value, popoutOptions.value);
119
- emit("change", popoutValue.value, popoutOptions.value);
120
- inputValue.value = getInputValue();
120
+ if (popoutValue.value !== innerValue.value) {
121
+ innerValue.value = popoutValue.value;
122
+ inputValue.value = getInputValue();
123
+ emit("update:model-value", innerValue.value, popoutOptions.value);
124
+ emit("change", innerValue.value, popoutOptions.value);
125
+ }
121
126
  };
122
127
  const inputValue = ref("");
123
128
  const fieldkeys = computed(() => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "sard-uniapp",
3
3
  "name": "sard-uniapp",
4
4
  "displayName": "sard-uniapp",
5
- "version": "1.13.3",
5
+ "version": "1.14.0",
6
6
  "description": "sard-uniapp 是一套基于 Uniapp + Vue3 框架开发的兼容多端的 UI 组件库",
7
7
  "main": "index.js",
8
8
  "scripts": {