chore: Fix ts type error (#3100)

* chore: fix onUploadProgress params type error

* fix(BasicButton): extends type error

* fix: useFormRules 类型问题

* fix: IFormConfig 类型问题

* chore: 设定CollapseItem list参数的类型

* chore: 修复sliderSpan类型错误

* chore: 改写成setup组件

* fix: static func type error

* chore: 设定listener 函数 evt类型为Event

* chore(props): 消除ts类型错误

* chore: 移除多余的类型转换

* Update domUtils.ts

* chore: 消除iconPicker类型错误

* Update domUtils.ts

* chore(clickOutside): 消除类型错误

* Update repeatClick.ts

* Update index.ts

* chore: 补全参数类型

* fix(Cropper): avatar uploadapi 类型问题
This commit is contained in:
invalid w 2023-10-08 17:30:19 +08:00 committed by GitHub
parent 986430513b
commit 1e95706f8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 116 additions and 153 deletions

View File

@ -2,6 +2,7 @@ import { UploadApiResult } from './model/uploadModel';
import { defHttp } from '/@/utils/http/axios'; import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams } from '/#/axios'; import { UploadFileParams } from '/#/axios';
import { useGlobSetting } from '/@/hooks/setting'; import { useGlobSetting } from '/@/hooks/setting';
import { AxiosProgressEvent } from 'axios';
const { uploadUrl = '' } = useGlobSetting(); const { uploadUrl = '' } = useGlobSetting();
@ -10,7 +11,7 @@ const { uploadUrl = '' } = useGlobSetting();
*/ */
export function uploadApi( export function uploadApi(
params: UploadFileParams, params: UploadFileParams,
onUploadProgress: (progressEvent: ProgressEvent) => void, onUploadProgress: (progressEvent: AxiosProgressEvent) => void,
) { ) {
return defHttp.uploadFile<UploadApiResult>( return defHttp.uploadFile<UploadApiResult>(
{ {

View File

@ -10,14 +10,14 @@
<script lang="ts" setup> <script lang="ts" setup>
import { Button } from 'ant-design-vue'; import { Button } from 'ant-design-vue';
import { computed, unref } from 'vue'; import { ComponentOptionsMixin, computed, unref } from 'vue';
import Icon from '@/components/Icon/Icon.vue'; import Icon from '@/components/Icon/Icon.vue';
import { buttonProps } from './props'; import { buttonProps } from './props';
import { useAttrs } from '@vben/hooks'; import { useAttrs } from '@vben/hooks';
defineOptions({ defineOptions({
name: 'AButton', name: 'AButton',
extends: Button, extends: Button as ComponentOptionsMixin,
inheritAttrs: false, inheritAttrs: false,
}); });

View File

@ -157,22 +157,22 @@
pageSize, pageSize,
current: page, current: page,
total, total,
showTotal: (total) => `${total}`, showTotal: (total: number) => `${total}`,
onChange: pageChange, onChange: pageChange,
onShowSizeChange: pageSizeChange, onShowSizeChange: pageSizeChange,
}); });
function pageChange(p, pz) { function pageChange(p: number, pz: number) {
page.value = p; page.value = p;
pageSize.value = pz; pageSize.value = pz;
fetch(); fetch();
} }
function pageSizeChange(_current, size) { function pageSizeChange(_current, size: number) {
pageSize.value = size; pageSize.value = size;
fetch(); fetch();
} }
async function handleDelete(id) { async function handleDelete(id: number) {
emit('delete', id); emit('delete', id);
} }
</script> </script>

View File

@ -54,7 +54,10 @@
showBtn: { type: Boolean, default: true }, showBtn: { type: Boolean, default: true },
btnProps: { type: Object as PropType<ButtonProps> }, btnProps: { type: Object as PropType<ButtonProps> },
btnText: { type: String, default: '' }, btnText: { type: String, default: '' },
uploadApi: { type: Function as PropType<({ file: Blob, name: string }) => Promise<void>> }, uploadApi: {
type: Function as PropType<({ file, name }: { file: Blob; name: string }) => Promise<void>>,
},
size: { type: Number, default: 5 }, size: { type: Number, default: 5 },
}; };

View File

@ -73,7 +73,6 @@
import SvgIcon from './SvgIcon.vue'; import SvgIcon from './SvgIcon.vue';
import iconsData from '../data/icons.data'; import iconsData from '../data/icons.data';
import { propTypes } from '/@/utils/propTypes';
import { usePagination } from '/@/hooks/web/usePagination'; import { usePagination } from '/@/hooks/web/usePagination';
import { useDebounceFn } from '@vueuse/core'; import { useDebounceFn } from '@vueuse/core';
import { useI18n } from '/@/hooks/web/useI18n'; import { useI18n } from '/@/hooks/web/useI18n';
@ -98,15 +97,23 @@
} }
function getSvgIcons() { function getSvgIcons() {
return svgIcons.map((icon) => icon.replace('icon-', '')); return svgIcons.map((icon: string) => icon.replace('icon-', ''));
} }
const props = defineProps({ export interface Props {
value: propTypes.string, value?: string;
width: propTypes.string.def('100%'), width?: string;
pageSize: propTypes.number.def(140), pageSize?: number;
copy: propTypes.bool.def(true), copy?: boolean;
mode: propTypes.oneOf<('svg' | 'iconify')[]>(['svg', 'iconify']).def('iconify'), mode?: 'svg' | 'iconify';
}
const props = withDefaults(defineProps<Props>(), {
value: '',
width: '100%',
pageSize: 140,
copy: false,
mode: 'iconify',
}); });
const emit = defineEmits(['change', 'update:value']); const emit = defineEmits(['change', 'update:value']);
@ -152,7 +159,8 @@
} }
function handleSearchChange(e: Event) { function handleSearchChange(e: Event) {
const value = e.target.value; const value = (e.target as HTMLInputElement).value;
if (!value) { if (!value) {
setCurrentPage(1); setCurrentPage(1);
currentList.value = icons; currentList.value = icons;

View File

@ -17,10 +17,10 @@ const nodeList: FlushList = new Map();
let startClick: MouseEvent; let startClick: MouseEvent;
if (!isServer) { if (!isServer) {
on(document, 'mousedown', (e: MouseEvent) => (startClick = e)); on(document, 'mousedown', (e: Event) => (startClick = e as MouseEvent));
on(document, 'mouseup', (e: MouseEvent) => { on(document, 'mouseup', (e: Event) => {
for (const { documentHandler } of nodeList.values()) { for (const { documentHandler } of nodeList.values()) {
documentHandler(e, startClick); documentHandler(e as MouseEvent, startClick);
} }
}); });
} }

View File

@ -18,8 +18,8 @@ const repeatDirective: Directive = {
interval = null; interval = null;
}; };
on(el, 'mousedown', (e: MouseEvent): void => { on(el, 'mousedown', (e: Event): void => {
if ((e as any).button !== 0) return; if ((e as MouseEvent).button !== 0) return;
startTime = Date.now(); startTime = Date.now();
once(document as any, 'mouseup', clear); once(document as any, 'mouseup', clear);
interval && clearInterval(interval); interval && clearInterval(interval);

View File

@ -28,9 +28,9 @@ const RippleDirective: Directive & RippleProto = {
const background = bg || RippleDirective.background; const background = bg || RippleDirective.background;
const zIndex = RippleDirective.zIndex; const zIndex = RippleDirective.zIndex;
el.addEventListener(options.event, (event: EventType) => { el.addEventListener(options.event, (event: Event) => {
rippler({ rippler({
event, event: event as EventType,
el, el,
background, background,
zIndex, zIndex,

View File

@ -1,5 +1,5 @@
import type { App } from 'vue'; import type { App } from 'vue';
import type { I18n, I18nOptions } from 'vue-i18n'; import type { I18nOptions } from 'vue-i18n';
import { createI18n } from 'vue-i18n'; import { createI18n } from 'vue-i18n';
import { setHtmlPageLang, setLoadLocalePool } from './helper'; import { setHtmlPageLang, setLoadLocalePool } from './helper';
@ -39,6 +39,6 @@ async function createI18nOptions(): Promise<I18nOptions> {
// setup i18n instance with glob // setup i18n instance with glob
export async function setupI18n(app: App) { export async function setupI18n(app: App) {
const options = await createI18nOptions(); const options = await createI18nOptions();
i18n = createI18n(options) as I18n; i18n = createI18n(options);
app.use(i18n); app.use(i18n);
} }

View File

@ -158,7 +158,7 @@ export function off(
export function once(el: HTMLElement, event: string, fn: EventListener): void { export function once(el: HTMLElement, event: string, fn: EventListener): void {
const listener = function (this: any, ...args: unknown[]) { const listener = function (this: any, ...args: unknown[]) {
if (fn) { if (fn) {
fn.apply(this, args); fn.apply(this, args as [evt: Event]);
} }
off(el, event, listener); off(el, event, listener);
}; };

View File

@ -20,13 +20,13 @@ const newPropTypes = createTypes({
// 从 vue-types v5.0 开始extend()方法已经废弃当前已改为官方推荐的ES6+方法 https://dwightjack.github.io/vue-types/advanced/extending-vue-types.html#the-extend-method // 从 vue-types v5.0 开始extend()方法已经废弃当前已改为官方推荐的ES6+方法 https://dwightjack.github.io/vue-types/advanced/extending-vue-types.html#the-extend-method
class propTypes extends newPropTypes { class propTypes extends newPropTypes {
// a native-like validator that supports the `.validable` method // a native-like validator that supports the `.validable` method
static get style() { static override get style() {
return toValidableType('style', { return toValidableType('style', {
type: [String, Object], type: [String, Object],
}); });
} }
static get VNodeChild() { static override get VNodeChild() {
return toValidableType('VNodeChild', { return toValidableType('VNodeChild', {
type: undefined, type: undefined,
}); });

View File

@ -129,7 +129,7 @@ export function buildProp<
return { return {
type: type:
typeof type === 'object' && Object.getOwnPropertySymbols(type).includes(wrapperKey) typeof type === 'object' && Object.getOwnPropertySymbols(type).includes(wrapperKey) && type
? type[wrapperKey] ? type[wrapperKey]
: type, : type,
required: !!required, required: !!required,
@ -175,9 +175,10 @@ export const buildProps = <
: never; : never;
}; };
export const definePropType = <T>(val: any) => ({ [wrapperKey]: val } as PropWrapper<T>); export const definePropType = <T>(val: any) => ({ [wrapperKey]: val }) as PropWrapper<T>;
export const keyOf = <T extends object>(arr: T) => Object.keys(arr) as Array<keyof T>;
export const keyOf = <T>(arr: T) => Object.keys(arr) as Array<keyof T>;
export const mutable = <T extends readonly any[] | Record<string, unknown>>(val: T) => export const mutable = <T extends readonly any[] | Record<string, unknown>>(val: T) =>
val as Mutable<typeof val>; val as Mutable<typeof val>;

View File

@ -61,8 +61,8 @@
</div> </div>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup name="FormItemProps">
import { computed, defineComponent, watch } from 'vue'; import { computed, watch } from 'vue';
import { import {
baseFormItemControlAttrs, baseFormItemControlAttrs,
baseFormItemProps, baseFormItemProps,
@ -70,76 +70,36 @@
advanceFormItemColProps, advanceFormItemColProps,
} from '../../VFormDesign/config/formItemPropsConfig'; } from '../../VFormDesign/config/formItemPropsConfig';
import { import { Empty, Input, Form, FormItem, Switch, Checkbox, Col } from 'ant-design-vue';
Empty,
Input,
Form,
FormItem,
Switch,
Checkbox,
Select,
Slider,
Col,
RadioGroup,
} from 'ant-design-vue';
import RuleProps from './RuleProps.vue'; import RuleProps from './RuleProps.vue';
import { useFormDesignState } from '../../../hooks/useFormDesignState'; import { useFormDesignState } from '../../../hooks/useFormDesignState';
import { isArray } from 'lodash-es'; import { isArray } from 'lodash-es';
export default defineComponent({ const { formConfig } = useFormDesignState();
name: 'FormItemProps',
components: { watch(
RuleProps, () => formConfig.value,
Empty, () => {
Input, if (formConfig.value.currentItem) {
Form, formConfig.value.currentItem.itemProps = formConfig.value.currentItem.itemProps || {};
FormItem, formConfig.value.currentItem.itemProps.labelCol =
Switch, formConfig.value.currentItem.itemProps.labelCol || {};
Checkbox, formConfig.value.currentItem.itemProps.wrapperCol =
Select, formConfig.value.currentItem.itemProps.wrapperCol || {};
Slider, }
Col,
RadioGroup,
}, },
// props: {} as PropsOptions, { deep: true, immediate: true },
);
const showProps = (exclude: string[] | undefined) => {
if (!exclude) {
return true;
}
return isArray(exclude) ? !exclude.includes(formConfig.value.currentItem!.component) : true;
};
setup() { const controlPropsList = computed(() => {
const { formConfig } = useFormDesignState(); return baseFormItemControlAttrs.filter((item) => {
return showProps(item.exclude);
watch( });
() => formConfig.value,
() => {
if (formConfig.value.currentItem) {
formConfig.value.currentItem.itemProps = formConfig.value.currentItem.itemProps || {};
formConfig.value.currentItem.itemProps.labelCol =
formConfig.value.currentItem.itemProps.labelCol || {};
formConfig.value.currentItem.itemProps.wrapperCol =
formConfig.value.currentItem.itemProps.wrapperCol || {};
}
},
{ deep: true, immediate: true },
);
const showProps = (exclude: string[] | undefined) => {
if (!exclude) {
return true;
}
return isArray(exclude) ? !exclude.includes(formConfig.value.currentItem!.component) : true;
};
const controlPropsList = computed(() => {
return baseFormItemControlAttrs.filter((item) => {
return showProps(item.exclude);
});
});
return {
baseFormItemProps,
advanceFormItemProps,
advanceFormItemColProps,
formConfig,
controlPropsList,
showProps,
};
},
}); });
</script> </script>

View File

@ -42,10 +42,10 @@
</FormItem> </FormItem>
<div v-if="formConfig.labelLayout === 'Grid'"> <div v-if="formConfig.labelLayout === 'Grid'">
<FormItem label="labelCol"> <FormItem label="labelCol">
<Slider v-model:value="formConfig.labelCol!.span" :max="24" /> <Slider v-model:value="sliderSpan" :max="24" />
</FormItem> </FormItem>
<FormItem label="wrapperCol"> <FormItem label="wrapperCol">
<Slider v-model:value="formConfig.wrapperCol!.span" :max="24" /> <Slider v-model:value="sliderSpan" :max="24" />
</FormItem> </FormItem>
<FormItem label="标签对齐"> <FormItem label="标签对齐">
@ -75,8 +75,8 @@
</Form> </Form>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup name="FormProps">
import { defineComponent } from 'vue'; import { computed } from 'vue';
import { useFormDesignState } from '../../../hooks/useFormDesignState'; import { useFormDesignState } from '../../../hooks/useFormDesignState';
import { import {
InputNumber, InputNumber,
@ -86,36 +86,25 @@
RadioChangeEvent, RadioChangeEvent,
Form, Form,
FormItem, FormItem,
Radio,
} from 'ant-design-vue'; } from 'ant-design-vue';
export default defineComponent({ const { formConfig } = useFormDesignState();
name: 'FormProps',
components: {
InputNumber,
Slider,
Checkbox,
RadioGroup: Radio.Group,
RadioButton: Radio.Button,
Form,
FormItem,
Col,
},
setup() {
const { formConfig } = useFormDesignState();
formConfig.value = formConfig.value || { formConfig.value = formConfig.value || {
labelCol: { span: 24 }, labelCol: { span: 24 },
wrapperCol: { span: 24 }, wrapperCol: { span: 24 },
}; };
const lableLayoutChange = (e: RadioChangeEvent) => { const lableLayoutChange = (e: RadioChangeEvent) => {
if (e.target.value === 'Grid') { if (e.target.value === 'Grid') {
formConfig.value.layout = 'horizontal'; formConfig.value.layout = 'horizontal';
} }
}; };
return { formConfig, lableLayoutChange }; const sliderSpan = computed(() => {
}, if (formConfig.value.labelLayout) {
return Number(formConfig.value.labelCol!.span);
}
return 0;
}); });
</script> </script>

View File

@ -31,7 +31,7 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, reactive } from 'vue'; import { defineComponent, reactive, PropType } from 'vue';
import { IVFormComponent } from '../../../typings/v-form-component'; import { IVFormComponent } from '../../../typings/v-form-component';
import draggable from 'vuedraggable'; import draggable from 'vuedraggable';
import Icon from '@/components/Icon/Icon.vue'; import Icon from '@/components/Icon/Icon.vue';
@ -42,7 +42,7 @@
components: { draggable, Icon }, components: { draggable, Icon },
props: { props: {
list: { list: {
type: [Array], type: [Array] as PropType<IVFormComponent[]>,
default: () => [], default: () => [],
}, },
handleListPush: { handleListPush: {

View File

@ -8,8 +8,8 @@ import { SelectValue } from 'ant-design-vue/lib/select';
import { validateOptions } from 'ant-design-vue/lib/form/useForm'; import { validateOptions } from 'ant-design-vue/lib/form/useForm';
import { RuleError } from 'ant-design-vue/lib/form/interface'; import { RuleError } from 'ant-design-vue/lib/form/interface';
import { FormItem } from '/@/components/Form'; import { FormItem } from '/@/components/Form';
import { FormLayout, FormProps } from 'ant-design-vue/lib/form/Form';
type LayoutType = 'horizontal' | 'vertical' | 'inline';
type labelLayout = 'flex' | 'Grid'; type labelLayout = 'flex' | 'Grid';
export type PropsTabKey = 1 | 2 | 3; export type PropsTabKey = 1 | 2 | 3;
type ColSpanType = number | string; type ColSpanType = number | string;
@ -75,28 +75,25 @@ declare type namesType = string | string[];
/** /**
* *
*/ */
export interface IFormConfig { export type PickAntFormConfig = Pick<
// 表单项配置列表 FormProps,
// schemas: IVFormComponent[]; | 'layout'
// 表单配置 | 'size'
// config: { | 'colon'
layout?: LayoutType; | 'labelAlign'
| 'disabled'
| 'labelCol'
| 'wrapperCol'
| 'hideRequiredMark'
>;
// 使用extends 而不使用 &联结 是为了避免 type:check指令类型重载错误
export interface IFormConfig extends PickAntFormConfig {
labelLayout?: labelLayout; labelLayout?: labelLayout;
labelWidth?: number; labelWidth?: number;
labelCol?: Partial<IACol>;
wrapperCol?: Partial<IACol>;
hideRequiredMark?: boolean;
// Whether to disable
schemas: IVFormComponent[]; schemas: IVFormComponent[];
disabled?: boolean;
labelAlign?: 'left' | 'right';
// Internal component size of the form
size?: 'default' | 'small' | 'large';
// };
// 当前选中项
currentItem?: IVFormComponent; currentItem?: IVFormComponent;
activeKey?: PropsTabKey; activeKey?: PropsTabKey;
colon?: boolean;
} }
export interface AForm { export interface AForm {
@ -118,7 +115,7 @@ export interface AForm {
* @default 'horizontal' * @default 'horizontal'
* @type string * @type string
*/ */
layout: 'horizontal' | 'inline' | 'vertical'; layout: FormLayout;
/** /**
* The layout for input controls, same as labelCol * The layout for input controls, same as labelCol

View File

@ -1,5 +1,9 @@
import type { ValidationRule, FormInstance } from 'ant-design-vue/lib/form/Form'; import type { FormInstance } from 'ant-design-vue/lib/form/Form';
import type { RuleObject, NamePath } from 'ant-design-vue/lib/form/interface'; import type {
RuleObject,
NamePath,
Rule as ValidationRule,
} from 'ant-design-vue/lib/form/interface';
import { ref, computed, unref, Ref } from 'vue'; import { ref, computed, unref, Ref } from 'vue';
import { useI18n } from '/@/hooks/web/useI18n'; import { useI18n } from '/@/hooks/web/useI18n';
@ -115,7 +119,7 @@ export function useFormRules(formData?: Recordable) {
return { getFormRules }; return { getFormRules };
} }
function createRule(message: string) { function createRule(message: string): ValidationRule[] {
return [ return [
{ {
required: true, required: true,