Skip to content

Commit

Permalink
Merge pull request #1877 from DevCloudFE/dev
Browse files Browse the repository at this point in the history
update main from dev
  • Loading branch information
GreatZPP authored Jun 3, 2024
2 parents 7c9acbf + 69917a5 commit 8651e8a
Show file tree
Hide file tree
Showing 18 changed files with 301 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export default defineComponent({
<div class={timelineItemClass(index, parentIndex, actionData, item)}>
<div class="vertical-list-item-top">
<div class="vertical-list-item-top-left">
<div class={itemIconClass(item, true)}>
{ctx.slots.iconContent?.({ option: item }) || <div class={itemIconClass(item, true)}>
{!item.icon && <div class="list-empty-icon-dot"></div>}
<em class={itemIconClass(item)}></em>
</div>
</div>}
<div class="vertical-list-item-top-left-title">{ctx.slots.title?.({ option: item })}</div>
</div>
<div class="dp-action-timeline-item-data">{item.createdAt}</div>
Expand All @@ -62,10 +62,10 @@ export default defineComponent({
const renderHorizontalBody = (actionData: ActionData, parentIndex: number) =>
actionData.actions?.map((item, index) => (
<div class={timelineItemClass(index, parentIndex, actionData, item)}>
<div class={itemIconClass(item, true)}>
{ctx.slots.iconContent?.({ option: item }) || <div class={itemIconClass(item, true)}>
{!item.icon && <div class="list-empty-icon-dot"></div>}
<em class={itemIconClass(item)}></em>
</div>
</div>}
<div class="dp-action-timeline-list-data">{ctx.slots.content?.({ option: item })}</div>
<div class="dp-action-timeline-item-date">{item.createdAt}</div>
{!(actionData.actions && data?.value && index === actionData.actions.length - 1 && parentIndex === data?.value?.length - 1) && (
Expand Down
2 changes: 1 addition & 1 deletion packages/devui-vue/devui/breadcrumb/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const getPropsSlot = (slots, props, prop = 'default') => {
export const getPropsSlot = (slots: any, props: any, prop = 'default') => {
return props[prop] ?? slots[prop]?.();
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ref, computed, toRefs, provide, watch, onMounted, reactive } from 'vue';
import type { Ref, SetupContext } from 'vue';
import { mergeWith, cloneDeep, merge } from 'lodash-es';
import { mergeWith, cloneDeep, merge } from 'lodash';
import RadioMenu from '../components/radio-menu';
import CheckboxMenu from '../components/checkbox-menu';
import LabelMenu from '../components/label-menu';
Expand Down
8 changes: 4 additions & 4 deletions packages/devui-vue/devui/editor-md/src/components/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import './toolbar.scss';
export default defineComponent({
name: 'DMdToolbar',
setup() {
const { toolbars, toolbarConfig } = useToolbar();

const { toolbars, toolbarConfig, customToolbars } = useToolbar();
const tempToolbars = { ...toolbars, ...customToolbars?.value };
return () => (
<div class="md-toolbar-container">
{toolbarConfig.value.map((item, index) =>
Array.isArray(item) ? (
<>
{item.map((key, idx) => (
<ToolbarItem config={toolbars[key]} key={`${index}-${idx}`} />
<ToolbarItem config={tempToolbars[key]} key={`${index}-${idx}`} />
))}
<span class="md-toolbar-span"></span>
</>
) : (
<ToolbarItem config={toolbars[item]} key={index} />
<ToolbarItem config={tempToolbars[item]} key={index} />
)
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { inject } from 'vue';
import { EditorMdInjectionKey, IEditorMdInjection } from '../editor-md-types';

export function useToolbar() {
const { toolbars, toolbarConfig } = inject(EditorMdInjectionKey) as IEditorMdInjection;
const { toolbars, toolbarConfig, customToolbars } = inject(EditorMdInjectionKey) as IEditorMdInjection;

return { toolbars, toolbarConfig };
return { toolbars, toolbarConfig, customToolbars };
}
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ export function useEditorMd(props: EditorMdProps, ctx: SetupContext) {
renderRef,
containerRef,
toolbars,
toolbarConfig,
previewHtmlList,
isHintShow,
customToolbars,
getEditorIns,
onPaste,
previewContentChange,
Expand Down
1 change: 1 addition & 0 deletions packages/devui-vue/devui/editor-md/src/editor-md-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export interface IEditorMdInjection {
showFullscreen: Ref<boolean>;
toolbars: Record<string, IToolbarItemConfig>;
toolbarConfig: Ref<ToolbarConfigProp>;
customToolbars: Ref<Record<string, IToolbarItemConfig> | undefined> | undefined;
getEditorIns: () => any;
t: (name: string) => string;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/devui-vue/devui/editor-md/src/editor-md.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineComponent({
const {
mode,
toolbarConfig,
customToolbars,
editorContainerHeight,
hidePreviewView,
placeholder,
Expand Down Expand Up @@ -66,6 +67,7 @@ export default defineComponent({
showFullscreen,
toolbars,
toolbarConfig,
customToolbars,
getEditorIns,
t: locale,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/devui-vue/devui/editor-md/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ export function locale(key: string): string {
loading: '正在加载中...',
pasting: '您粘贴内容较多, 正在努力加载中,请耐心等待...',
};
return localeMap[key];
return localeMap[key] || key;
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,20 @@ describe('d-input-number', () => {
expect(selectFn).toBeCalledTimes(2);
});
});


it('allowEmpty', async () => {
const num = ref();
const wrapper = mount({
setup() {
return () => <DInputNumber v-model={num.value} allowEmpty={true} ></DInputNumber>;
},
});
num.value = undefined;
const inputInner = wrapper.find(ns.e('input-box'));
expect((inputInner.element as HTMLInputElement).value).toBeNull;
num.value = 51;
expect((inputInner.element as HTMLInputElement).value).toBe('51');
num.value = '';
expect((inputInner.element as HTMLInputElement).value).toBeNull;
});
2 changes: 1 addition & 1 deletion packages/devui-vue/devui/input-number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default {
category: '数据录入',
status: '50%',
install(app: App): void {
app.component(InputNumber.name, InputNumber);
app.component(InputNumber.name as string, InputNumber);
}
};
16 changes: 10 additions & 6 deletions packages/devui-vue/devui/input-number/src/input-number-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { PropType, ExtractPropTypes, ComputedRef, Ref, CSSProperties, Input
export type ISize = 'lg' | 'md' | 'sm';

export const inputNumberProps = {
modelValue: {
type: [Number, String] as PropType<number | string | null | undefined>,
},
placeholder: {
type: String,
},
Expand All @@ -25,9 +28,6 @@ export const inputNumberProps = {
size: {
type: String as PropType<ISize>,
},
modelValue: {
type: Number,
},
precision: {
type: Number,
},
Expand All @@ -39,13 +39,17 @@ export const inputNumberProps = {
type: Boolean,
default: true,
},
allowEmpty: {
type: Boolean,
default: false,
}
} as const;

export type InputNumberProps = ExtractPropTypes<typeof inputNumberProps>;

export interface IState {
currentValue: number | string | undefined;
userInputValue: number | string | undefined;
currentValue: number | string | undefined | null;
userInputValue: number | string | undefined | null;
}

export interface UseExpose {
Expand All @@ -62,7 +66,7 @@ export interface UseRender {
}

export interface UseEvent {
inputVal: ComputedRef<number | string | undefined>;
inputVal: ComputedRef<number | string | undefined | null>;
minDisabled: ComputedRef<boolean>;
maxDisabled: ComputedRef<boolean>;
onAdd: () => void;
Expand Down
28 changes: 13 additions & 15 deletions packages/devui-vue/devui/input-number/src/use-input-number.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { computed, reactive, toRefs, watch, ref, inject } from 'vue';
import { computed, reactive, toRefs, watch, ref, inject, InjectionKey } from 'vue';
import type { SetupContext, Ref, CSSProperties } from 'vue';
import { InputNumberProps, UseEvent, UseRender, IState, UseExpose } from './input-number-types';
import { useNamespace } from '../../shared/hooks/use-namespace';
import { isNumber, isUndefined } from '../../shared/utils';
import { FORM_TOKEN } from '../../form';
import { FORM_TOKEN, type FormProps } from '../../form';

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

export function useRender(props: InputNumberProps, ctx: SetupContext): UseRender {
const formContext = inject(FORM_TOKEN, undefined);
const formContext: FormProps | undefined | any = inject(FORM_TOKEN, undefined); // 修复ts语法错误组件不被d-from组件引用时,formContext未被定义
const { style, class: customClass, ...otherAttrs } = ctx.attrs;
const customStyle = { style: style as CSSProperties };

const inputNumberSize = computed(() => props.size || formContext?.size || 'md');

const wrapClass = computed(() => [
Expand Down Expand Up @@ -56,12 +55,12 @@ export function useExpose(ctx: SetupContext): UseExpose {
return { inputRef };
}

function getPrecision(pre: number | undefined): number {
function getPrecision(pre: string | number | undefined | null): number {
let precision = 0;
if (isUndefined(pre)) {
return precision;
}
const preString = pre.toString();
const preString = (pre as string).toString();
const dotIndex = preString.indexOf('.');
if (dotIndex !== -1) {
precision = preString.length - dotIndex - 1;
Expand Down Expand Up @@ -89,8 +88,8 @@ export function useEvent(props: InputNumberProps, ctx: SetupContext, inputRef: R
return state.userInputValue;
}
let currentValue = state.currentValue;
if (currentValue === '' || isUndefined(currentValue) || Number.isNaN(currentValue)) {
return '';
if (!currentValue && currentValue !== 0) {
return null;
}
if (isNumber(currentValue)) {
// todo 小数精度 确认是否应该以正则处理
Expand All @@ -111,17 +110,16 @@ export function useEvent(props: InputNumberProps, ctx: SetupContext, inputRef: R
};

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

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

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

const setCurrentValue = (value: number | string | undefined) => {
const setCurrentValue = (value: number | string | undefined | null) => {
const oldVal = state.currentValue;
const newVal = correctValue(value);

state.userInputValue = undefined;

// 0 可以被更新
if (newVal !== 0 && !newVal) {
// 0 和 '' 可以被更新
if (newVal !== 0 && newVal !== null && !newVal) {
ctx.emit('update:modelValue', oldVal);
return;
}
Expand Down
31 changes: 16 additions & 15 deletions packages/devui-vue/devui/svg-icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ export function SearchIcon(): JSX.Element {
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g id="dv-search-icon" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<path
d={`M7.71295742,1.53283795 C11.0266659,1.53283795 13.7129574,4.21912945 13.7129574,7.53283795 C13.7129574,9.0690006
13.1356609,10.4703284 12.1861834,11.5317059 L14.5333041,13.8784875 C14.7285663,14.0737497 14.7285663,14.3903321
14.5333041,14.5855943 C14.3597378,14.7591606 14.0903134,14.7784458 13.8954453,14.6434497 L13.8261974,14.5855943
L11.4604434,12.2188804 C10.4336319,13.0411023 9.13072017,13.5328379 7.71295742,13.5328379 C4.39924893,13.5328379
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
C4.95153368,2.53283795 2.71295742,4.7714142 2.71295742,7.53283795 C2.71295742,10.2942617 4.95153368,12.5328379 7.71295742,12.5328379
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`}
d="M7.71295742,1.53283795 C11.0266659,1.53283795 13.7129574,4.21912945 13.7129574,7.53283795
C13.7129574,9.0690006 13.1356609,10.4703284 12.1861834,11.5317059 L14.5333041,13.8784875 C14.7285663,14.0737497
14.7285663,14.3903321 14.5333041,14.5855943 C14.3597378,14.7591606 14.0903134,14.7784458 13.8954453,14.6434497
L13.8261974,14.5855943 L11.4604434,12.2188804 C10.4336319,13.0411023 9.13072017,13.5328379 7.71295742,13.5328379
C4.39924893,13.5328379 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 C4.95153368,2.53283795 2.71295742,4.7714142 2.71295742,7.53283795
C2.71295742,10.2942617 4.95153368,12.5328379 7.71295742,12.5328379 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"
id="形状结合"
fill="#71757F"
fill-rule="nonzero"></path>
Expand All @@ -38,14 +39,14 @@ export function InputClearIcon(): JSX.Element {
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<path
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 \
4.13400675,1 8,1 Z M5.87867966,5.17157288 C5.68341751,4.97631073 5.36683502,4.97631073 5.17157288,5.17157288 \
C4.99800652,5.34513923 4.97872137,5.61456363 5.11371742,5.80943177 L5.17157288,5.87867966 L7.29218611,7.99929289 \
L5.17157288,10.1213203 C4.97631073,10.3165825 4.97631073,10.633165 5.17157288,10.8284271 C5.34513923,11.0019935 \
5.61456363,11.0212786 5.80943177,10.8862826 L5.87867966,10.8284271 L7.99929289,8.70639967 L10.1213203,10.8284271 \
C10.3165825,11.0236893 10.633165,11.0236893 10.8284271,10.8284271 C11.0019935,10.6548608 11.0212786,10.3854364 \
10.8862826,10.1905682 L10.8284271,10.1213203 L8.70710678,8 L10.8284271,5.87867966 C11.0236893,5.68341751 \
11.0236893,5.36683502 10.8284271,5.17157288 C10.6548608,4.99800652 10.3854364,4.97872137 10.1905682,5.11371742 \
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
4.13400675,1 8,1 Z M5.87867966,5.17157288 C5.68341751,4.97631073 5.36683502,4.97631073 5.17157288,5.17157288
C4.99800652,5.34513923 4.97872137,5.61456363 5.11371742,5.80943177 L5.17157288,5.87867966 L7.29218611,7.99929289
L5.17157288,10.1213203 C4.97631073,10.3165825 4.97631073,10.633165 5.17157288,10.8284271 C5.34513923,11.0019935
5.61456363,11.0212786 5.80943177,10.8862826 L5.87867966,10.8284271 L7.99929289,8.70639967 L10.1213203,10.8284271
C10.3165825,11.0236893 10.633165,11.0236893 10.8284271,10.8284271 C11.0019935,10.6548608 11.0212786,10.3854364
10.8862826,10.1905682 L10.8284271,10.1213203 L8.70710678,8 L10.8284271,5.87867966 C11.0236893,5.68341751
11.0236893,5.36683502 10.8284271,5.17157288 C10.6548608,4.99800652 10.3854364,4.97872137 10.1905682,5.11371742
L10.1213203,5.17157288 L8,7.29289322 L5.87867966,5.17157288 Z"
id="形状"
fill="#D5D5DB"
Expand Down
Loading

0 comments on commit 8651e8a

Please sign in to comment.