Skip to content

Commit 8651e8a

Browse files
authored
Merge pull request #1877 from DevCloudFE/dev
update main from dev
2 parents 7c9acbf + 69917a5 commit 8651e8a

File tree

18 files changed

+301
-53
lines changed

18 files changed

+301
-53
lines changed

packages/devui-vue/devui/action-timeline/src/action-timeline.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export default defineComponent({
4848
<div class={timelineItemClass(index, parentIndex, actionData, item)}>
4949
<div class="vertical-list-item-top">
5050
<div class="vertical-list-item-top-left">
51-
<div class={itemIconClass(item, true)}>
51+
{ctx.slots.iconContent?.({ option: item }) || <div class={itemIconClass(item, true)}>
5252
{!item.icon && <div class="list-empty-icon-dot"></div>}
5353
<em class={itemIconClass(item)}></em>
54-
</div>
54+
</div>}
5555
<div class="vertical-list-item-top-left-title">{ctx.slots.title?.({ option: item })}</div>
5656
</div>
5757
<div class="dp-action-timeline-item-data">{item.createdAt}</div>
@@ -62,10 +62,10 @@ export default defineComponent({
6262
const renderHorizontalBody = (actionData: ActionData, parentIndex: number) =>
6363
actionData.actions?.map((item, index) => (
6464
<div class={timelineItemClass(index, parentIndex, actionData, item)}>
65-
<div class={itemIconClass(item, true)}>
65+
{ctx.slots.iconContent?.({ option: item }) || <div class={itemIconClass(item, true)}>
6666
{!item.icon && <div class="list-empty-icon-dot"></div>}
6767
<em class={itemIconClass(item)}></em>
68-
</div>
68+
</div>}
6969
<div class="dp-action-timeline-list-data">{ctx.slots.content?.({ option: item })}</div>
7070
<div class="dp-action-timeline-item-date">{item.createdAt}</div>
7171
{!(actionData.actions && data?.value && index === actionData.actions.length - 1 && parentIndex === data?.value?.length - 1) && (
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const getPropsSlot = (slots, props, prop = 'default') => {
1+
export const getPropsSlot = (slots: any, props: any, prop = 'default') => {
22
return props[prop] ?? slots[prop]?.();
33
};

packages/devui-vue/devui/category-search/src/composables/use-category-search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ref, computed, toRefs, provide, watch, onMounted, reactive } from 'vue';
22
import type { Ref, SetupContext } from 'vue';
3-
import { mergeWith, cloneDeep, merge } from 'lodash-es';
3+
import { mergeWith, cloneDeep, merge } from 'lodash';
44
import RadioMenu from '../components/radio-menu';
55
import CheckboxMenu from '../components/checkbox-menu';
66
import LabelMenu from '../components/label-menu';

packages/devui-vue/devui/editor-md/src/components/toolbar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ import './toolbar.scss';
66
export default defineComponent({
77
name: 'DMdToolbar',
88
setup() {
9-
const { toolbars, toolbarConfig } = useToolbar();
10-
9+
const { toolbars, toolbarConfig, customToolbars } = useToolbar();
10+
const tempToolbars = { ...toolbars, ...customToolbars?.value };
1111
return () => (
1212
<div class="md-toolbar-container">
1313
{toolbarConfig.value.map((item, index) =>
1414
Array.isArray(item) ? (
1515
<>
1616
{item.map((key, idx) => (
17-
<ToolbarItem config={toolbars[key]} key={`${index}-${idx}`} />
17+
<ToolbarItem config={tempToolbars[key]} key={`${index}-${idx}`} />
1818
))}
1919
<span class="md-toolbar-span"></span>
2020
</>
2121
) : (
22-
<ToolbarItem config={toolbars[item]} key={index} />
22+
<ToolbarItem config={tempToolbars[item]} key={index} />
2323
)
2424
)}
2525
</div>

packages/devui-vue/devui/editor-md/src/composables/use-editor-md-toolbar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { inject } from 'vue';
22
import { EditorMdInjectionKey, IEditorMdInjection } from '../editor-md-types';
33

44
export function useToolbar() {
5-
const { toolbars, toolbarConfig } = inject(EditorMdInjectionKey) as IEditorMdInjection;
5+
const { toolbars, toolbarConfig, customToolbars } = inject(EditorMdInjectionKey) as IEditorMdInjection;
66

7-
return { toolbars, toolbarConfig };
7+
return { toolbars, toolbarConfig, customToolbars };
88
}

packages/devui-vue/devui/editor-md/src/composables/use-editor-md.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,10 @@ export function useEditorMd(props: EditorMdProps, ctx: SetupContext) {
414414
renderRef,
415415
containerRef,
416416
toolbars,
417+
toolbarConfig,
417418
previewHtmlList,
418419
isHintShow,
420+
customToolbars,
419421
getEditorIns,
420422
onPaste,
421423
previewContentChange,

packages/devui-vue/devui/editor-md/src/editor-md-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export interface IEditorMdInjection {
136136
showFullscreen: Ref<boolean>;
137137
toolbars: Record<string, IToolbarItemConfig>;
138138
toolbarConfig: Ref<ToolbarConfigProp>;
139+
customToolbars: Ref<Record<string, IToolbarItemConfig> | undefined> | undefined;
139140
getEditorIns: () => any;
140141
t: (name: string) => string;
141142
}

packages/devui-vue/devui/editor-md/src/editor-md.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default defineComponent({
1717
const {
1818
mode,
1919
toolbarConfig,
20+
customToolbars,
2021
editorContainerHeight,
2122
hidePreviewView,
2223
placeholder,
@@ -66,6 +67,7 @@ export default defineComponent({
6667
showFullscreen,
6768
toolbars,
6869
toolbarConfig,
70+
customToolbars,
6971
getEditorIns,
7072
t: locale,
7173
});

packages/devui-vue/devui/editor-md/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ export function locale(key: string): string {
8484
loading: '正在加载中...',
8585
pasting: '您粘贴内容较多, 正在努力加载中,请耐心等待...',
8686
};
87-
return localeMap[key];
87+
return localeMap[key] || key;
8888
}

packages/devui-vue/devui/input-number/__tests__/input-number.spec.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,20 @@ describe('d-input-number', () => {
279279
expect(selectFn).toBeCalledTimes(2);
280280
});
281281
});
282+
283+
284+
it('allowEmpty', async () => {
285+
const num = ref();
286+
const wrapper = mount({
287+
setup() {
288+
return () => <DInputNumber v-model={num.value} allowEmpty={true} ></DInputNumber>;
289+
},
290+
});
291+
num.value = undefined;
292+
const inputInner = wrapper.find(ns.e('input-box'));
293+
expect((inputInner.element as HTMLInputElement).value).toBeNull;
294+
num.value = 51;
295+
expect((inputInner.element as HTMLInputElement).value).toBe('51');
296+
num.value = '';
297+
expect((inputInner.element as HTMLInputElement).value).toBeNull;
298+
});

packages/devui-vue/devui/input-number/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export default {
88
category: '数据录入',
99
status: '50%',
1010
install(app: App): void {
11-
app.component(InputNumber.name, InputNumber);
11+
app.component(InputNumber.name as string, InputNumber);
1212
}
1313
};

packages/devui-vue/devui/input-number/src/input-number-types.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import type { PropType, ExtractPropTypes, ComputedRef, Ref, CSSProperties, Input
33
export type ISize = 'lg' | 'md' | 'sm';
44

55
export const inputNumberProps = {
6+
modelValue: {
7+
type: [Number, String] as PropType<number | string | null | undefined>,
8+
},
69
placeholder: {
710
type: String,
811
},
@@ -25,9 +28,6 @@ export const inputNumberProps = {
2528
size: {
2629
type: String as PropType<ISize>,
2730
},
28-
modelValue: {
29-
type: Number,
30-
},
3131
precision: {
3232
type: Number,
3333
},
@@ -39,13 +39,17 @@ export const inputNumberProps = {
3939
type: Boolean,
4040
default: true,
4141
},
42+
allowEmpty: {
43+
type: Boolean,
44+
default: false,
45+
}
4246
} as const;
4347

4448
export type InputNumberProps = ExtractPropTypes<typeof inputNumberProps>;
4549

4650
export interface IState {
47-
currentValue: number | string | undefined;
48-
userInputValue: number | string | undefined;
51+
currentValue: number | string | undefined | null;
52+
userInputValue: number | string | undefined | null;
4953
}
5054

5155
export interface UseExpose {
@@ -62,7 +66,7 @@ export interface UseRender {
6266
}
6367

6468
export interface UseEvent {
65-
inputVal: ComputedRef<number | string | undefined>;
69+
inputVal: ComputedRef<number | string | undefined | null>;
6670
minDisabled: ComputedRef<boolean>;
6771
maxDisabled: ComputedRef<boolean>;
6872
onAdd: () => void;

packages/devui-vue/devui/input-number/src/use-input-number.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import { computed, reactive, toRefs, watch, ref, inject } from 'vue';
1+
import { computed, reactive, toRefs, watch, ref, inject, InjectionKey } from 'vue';
22
import type { SetupContext, Ref, CSSProperties } from 'vue';
33
import { InputNumberProps, UseEvent, UseRender, IState, UseExpose } from './input-number-types';
44
import { useNamespace } from '../../shared/hooks/use-namespace';
55
import { isNumber, isUndefined } from '../../shared/utils';
6-
import { FORM_TOKEN } from '../../form';
6+
import { FORM_TOKEN, type FormProps } from '../../form';
77

88
const ns = useNamespace('input-number');
99

1010
export function useRender(props: InputNumberProps, ctx: SetupContext): UseRender {
11-
const formContext = inject(FORM_TOKEN, undefined);
11+
const formContext: FormProps | undefined | any = inject(FORM_TOKEN, undefined); // 修复ts语法错误组件不被d-from组件引用时,formContext未被定义
1212
const { style, class: customClass, ...otherAttrs } = ctx.attrs;
1313
const customStyle = { style: style as CSSProperties };
14-
1514
const inputNumberSize = computed(() => props.size || formContext?.size || 'md');
1615

1716
const wrapClass = computed(() => [
@@ -56,12 +55,12 @@ export function useExpose(ctx: SetupContext): UseExpose {
5655
return { inputRef };
5756
}
5857

59-
function getPrecision(pre: number | undefined): number {
58+
function getPrecision(pre: string | number | undefined | null): number {
6059
let precision = 0;
6160
if (isUndefined(pre)) {
6261
return precision;
6362
}
64-
const preString = pre.toString();
63+
const preString = (pre as string).toString();
6564
const dotIndex = preString.indexOf('.');
6665
if (dotIndex !== -1) {
6766
precision = preString.length - dotIndex - 1;
@@ -89,8 +88,8 @@ export function useEvent(props: InputNumberProps, ctx: SetupContext, inputRef: R
8988
return state.userInputValue;
9089
}
9190
let currentValue = state.currentValue;
92-
if (currentValue === '' || isUndefined(currentValue) || Number.isNaN(currentValue)) {
93-
return '';
91+
if (!currentValue && currentValue !== 0) {
92+
return null;
9493
}
9594
if (isNumber(currentValue)) {
9695
// todo 小数精度 确认是否应该以正则处理
@@ -111,17 +110,16 @@ export function useEvent(props: InputNumberProps, ctx: SetupContext, inputRef: R
111110
};
112111

113112
const correctValue = (value: number | string | undefined | null) => {
113+
if ((!value && value !== 0) && props.allowEmpty) { // 当用户开始允许空值时 value不为0的false全返回null(即'',null,undefined,NaN都会反回null设计与dev_ui_ag版本一致)
114+
return null;
115+
}
114116
// 校验正则
115117
const valueStr = value + '';
116118
if (props.reg && !valueStr.match(new RegExp(props.reg))) {
117119
return undefined;
118120
}
119121

120122
let newVal = Number(value);
121-
// 不是0 是假值或者是NaN返回undefined
122-
if (newVal !== 0 && (!Number(value) || Number.isNaN(newVal))) {
123-
return undefined;
124-
}
125123

126124
// 精度限制存在才做转换
127125
if (!isUndefined(props.precision)) {
@@ -135,14 +133,14 @@ export function useEvent(props: InputNumberProps, ctx: SetupContext, inputRef: R
135133
return newVal;
136134
};
137135

138-
const setCurrentValue = (value: number | string | undefined) => {
136+
const setCurrentValue = (value: number | string | undefined | null) => {
139137
const oldVal = state.currentValue;
140138
const newVal = correctValue(value);
141139

142140
state.userInputValue = undefined;
143141

144-
// 0 可以被更新
145-
if (newVal !== 0 && !newVal) {
142+
// 0 和 '' 可以被更新
143+
if (newVal !== 0 && newVal !== null && !newVal) {
146144
ctx.emit('update:modelValue', oldVal);
147145
return;
148146
}

packages/devui-vue/devui/svg-icons/index.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ export function SearchIcon(): JSX.Element {
1818
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg">
1919
<g id="dv-search-icon" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
2020
<path
21-
d={`M7.71295742,1.53283795 C11.0266659,1.53283795 13.7129574,4.21912945 13.7129574,7.53283795 C13.7129574,9.0690006
22-
13.1356609,10.4703284 12.1861834,11.5317059 L14.5333041,13.8784875 C14.7285663,14.0737497 14.7285663,14.3903321
23-
14.5333041,14.5855943 C14.3597378,14.7591606 14.0903134,14.7784458 13.8954453,14.6434497 L13.8261974,14.5855943
24-
L11.4604434,12.2188804 C10.4336319,13.0411023 9.13072017,13.5328379 7.71295742,13.5328379 C4.39924893,13.5328379
25-
1.71295742,10.8465464 1.71295742,7.53283795 C1.71295742,4.21912945 4.39924893,1.53283795 7.71295742,1.53283795 Z M7.71295742,2.53283795
26-
C4.95153368,2.53283795 2.71295742,4.7714142 2.71295742,7.53283795 C2.71295742,10.2942617 4.95153368,12.5328379 7.71295742,12.5328379
27-
C10.4743812,12.5328379 12.7129574,10.2942617 12.7129574,7.53283795 C12.7129574,4.7714142 10.4743812,2.53283795 7.71295742,2.53283795 Z`}
21+
d="M7.71295742,1.53283795 C11.0266659,1.53283795 13.7129574,4.21912945 13.7129574,7.53283795
22+
C13.7129574,9.0690006 13.1356609,10.4703284 12.1861834,11.5317059 L14.5333041,13.8784875 C14.7285663,14.0737497
23+
14.7285663,14.3903321 14.5333041,14.5855943 C14.3597378,14.7591606 14.0903134,14.7784458 13.8954453,14.6434497
24+
L13.8261974,14.5855943 L11.4604434,12.2188804 C10.4336319,13.0411023 9.13072017,13.5328379 7.71295742,13.5328379
25+
C4.39924893,13.5328379 1.71295742,10.8465464 1.71295742,7.53283795 C1.71295742,4.21912945 4.39924893,1.53283795
26+
7.71295742,1.53283795 Z M7.71295742,2.53283795 C4.95153368,2.53283795 2.71295742,4.7714142 2.71295742,7.53283795
27+
C2.71295742,10.2942617 4.95153368,12.5328379 7.71295742,12.5328379 C10.4743812,12.5328379 12.7129574,10.2942617
28+
12.7129574,7.53283795 C12.7129574,4.7714142 10.4743812,2.53283795 7.71295742,2.53283795 Z"
2829
id="形状结合"
2930
fill="#71757F"
3031
fill-rule="nonzero"></path>
@@ -38,14 +39,14 @@ export function InputClearIcon(): JSX.Element {
3839
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg">
3940
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
4041
<path
41-
d="M8,1 C11.8659932,1 15,4.13400675 15,8 C15,11.8659932 11.8659932,15 8,15 C4.13400675,15 1,11.8659932 1,8 C1,4.13400675 \
42-
4.13400675,1 8,1 Z M5.87867966,5.17157288 C5.68341751,4.97631073 5.36683502,4.97631073 5.17157288,5.17157288 \
43-
C4.99800652,5.34513923 4.97872137,5.61456363 5.11371742,5.80943177 L5.17157288,5.87867966 L7.29218611,7.99929289 \
44-
L5.17157288,10.1213203 C4.97631073,10.3165825 4.97631073,10.633165 5.17157288,10.8284271 C5.34513923,11.0019935 \
45-
5.61456363,11.0212786 5.80943177,10.8862826 L5.87867966,10.8284271 L7.99929289,8.70639967 L10.1213203,10.8284271 \
46-
C10.3165825,11.0236893 10.633165,11.0236893 10.8284271,10.8284271 C11.0019935,10.6548608 11.0212786,10.3854364 \
47-
10.8862826,10.1905682 L10.8284271,10.1213203 L8.70710678,8 L10.8284271,5.87867966 C11.0236893,5.68341751 \
48-
11.0236893,5.36683502 10.8284271,5.17157288 C10.6548608,4.99800652 10.3854364,4.97872137 10.1905682,5.11371742 \
42+
d="M8,1 C11.8659932,1 15,4.13400675 15,8 C15,11.8659932 11.8659932,15 8,15 C4.13400675,15 1,11.8659932 1,8 C1,4.13400675
43+
4.13400675,1 8,1 Z M5.87867966,5.17157288 C5.68341751,4.97631073 5.36683502,4.97631073 5.17157288,5.17157288
44+
C4.99800652,5.34513923 4.97872137,5.61456363 5.11371742,5.80943177 L5.17157288,5.87867966 L7.29218611,7.99929289
45+
L5.17157288,10.1213203 C4.97631073,10.3165825 4.97631073,10.633165 5.17157288,10.8284271 C5.34513923,11.0019935
46+
5.61456363,11.0212786 5.80943177,10.8862826 L5.87867966,10.8284271 L7.99929289,8.70639967 L10.1213203,10.8284271
47+
C10.3165825,11.0236893 10.633165,11.0236893 10.8284271,10.8284271 C11.0019935,10.6548608 11.0212786,10.3854364
48+
10.8862826,10.1905682 L10.8284271,10.1213203 L8.70710678,8 L10.8284271,5.87867966 C11.0236893,5.68341751
49+
11.0236893,5.36683502 10.8284271,5.17157288 C10.6548608,4.99800652 10.3854364,4.97872137 10.1905682,5.11371742
4950
L10.1213203,5.17157288 L8,7.29289322 L5.87867966,5.17157288 Z"
5051
id="形状"
5152
fill="#D5D5DB"

0 commit comments

Comments
 (0)