Browse Source

fix: Fix ts type error

main
xingyu 2 years ago
parent
commit
81283bcd24
  1. 3
      src/components/Button/src/BasicButton.vue
  2. 2
      src/components/CardList/src/CardList.vue
  3. 4
      src/components/Cropper/src/CropperAvatar.vue
  4. 16
      src/components/FormDesign/src/components/VFormDesign/components/FormItemProps.vue
  5. 75
      src/components/FormDesign/src/components/VFormDesign/components/FormProps.vue
  6. 2
      src/components/FormDesign/src/components/VFormDesign/modules/CollapseItem.vue
  7. 35
      src/components/FormDesign/src/typings/v-form-component.ts
  8. 35
      src/components/Icon/src/IconPicker.vue
  9. 6
      src/directives/clickOutside.ts
  10. 4
      src/directives/repeatClick.ts
  11. 4
      src/directives/ripple/index.ts
  12. 31
      src/utils/propTypes.ts
  13. 5
      src/utils/props.ts
  14. 4
      src/views/base/login/useLogin.ts

3
src/components/Button/src/BasicButton.vue

@ -1,11 +1,12 @@
<script lang="ts" setup> <script lang="ts" setup>
import { Button, theme } from 'ant-design-vue' import { Button, theme } from 'ant-design-vue'
import type { ComponentOptionsMixin } from 'vue'
import { computed, unref } from 'vue' import { computed, unref } from 'vue'
import { buttonProps } from './props' import { buttonProps } from './props'
import { useAttrs } from '@/hooks/core/useAttrs' import { useAttrs } from '@/hooks/core/useAttrs'
import { Icon } from '@/components/Icon' import { Icon } from '@/components/Icon'
defineOptions({ name: 'AButton', extends: Button, indeterminate: false }) defineOptions({ name: 'AButton', extends: Button as ComponentOptionsMixin, indeterminate: false })
const props = defineProps(buttonProps) const props = defineProps(buttonProps)
const { useToken } = theme const { useToken } = theme
const { token } = useToken() const { token } = useToken()

2
src/components/CardList/src/CardList.vue

@ -93,7 +93,7 @@ function sliderChange(n: number) {
fetch() fetch()
} }
async function handleDelete(id) { async function handleDelete(id: number) {
emit('delete', id) emit('delete', id)
} }
</script> </script>

4
src/components/Cropper/src/CropperAvatar.vue

@ -18,7 +18,9 @@ const props = defineProps({
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, name }) => 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 },
}) })

16
src/components/FormDesign/src/components/VFormDesign/components/FormItemProps.vue

@ -3,15 +3,7 @@
--> -->
<script lang="ts" setup> <script lang="ts" setup>
import { computed, watch } from 'vue' import { computed, watch } from 'vue'
import { import { Checkbox, Col, Empty, Form, FormItem, Input, Switch } from 'ant-design-vue'
Checkbox,
Col,
Empty,
Form,
FormItem,
Input,
Switch,
} from 'ant-design-vue'
import { isArray } from 'lodash-es' import { isArray } from 'lodash-es'
import { import {
advanceFormItemColProps, advanceFormItemColProps,
@ -23,6 +15,8 @@ import {
import { useFormDesignState } from '../../../hooks/useFormDesignState' import { useFormDesignState } from '../../../hooks/useFormDesignState'
import RuleProps from './RuleProps.vue' import RuleProps from './RuleProps.vue'
defineOptions({ name: 'FormItemProps' })
const { formConfig } = useFormDesignState() const { formConfig } = useFormDesignState()
watch( watch(
@ -31,9 +25,9 @@ watch(
if (formConfig.value.currentItem) { if (formConfig.value.currentItem) {
formConfig.value.currentItem.itemProps = formConfig.value.currentItem.itemProps || {} formConfig.value.currentItem.itemProps = formConfig.value.currentItem.itemProps || {}
formConfig.value.currentItem.itemProps.labelCol formConfig.value.currentItem.itemProps.labelCol
= formConfig.value.currentItem.itemProps.labelCol || {} = formConfig.value.currentItem.itemProps.labelCol || {}
formConfig.value.currentItem.itemProps.wrapperCol formConfig.value.currentItem.itemProps.wrapperCol
= formConfig.value.currentItem.itemProps.wrapperCol || {} = formConfig.value.currentItem.itemProps.wrapperCol || {}
} }
}, },
{ deep: true, immediate: true }, { deep: true, immediate: true },

75
src/components/FormDesign/src/components/VFormDesign/components/FormProps.vue

@ -2,6 +2,7 @@
* @Description: 右侧属性面板控件 表单属性面板 * @Description: 右侧属性面板控件 表单属性面板
--> -->
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from 'vue'
import type { RadioChangeEvent } from 'ant-design-vue' import type { RadioChangeEvent } from 'ant-design-vue'
import { import {
Checkbox, Checkbox,
@ -9,11 +10,12 @@ import {
Form, Form,
FormItem, FormItem,
InputNumber, InputNumber,
Radio,
Slider, Slider,
} from 'ant-design-vue' } from 'ant-design-vue'
import { useFormDesignState } from '../../../hooks/useFormDesignState' import { useFormDesignState } from '../../../hooks/useFormDesignState'
defineOptions({ name: 'FormProps' })
const { formConfig } = useFormDesignState() const { formConfig } = useFormDesignState()
formConfig.value = formConfig.value || { formConfig.value = formConfig.value || {
@ -21,10 +23,17 @@ formConfig.value = formConfig.value || {
wrapperCol: { span: 24 }, wrapperCol: { span: 24 },
} }
function lableLayoutChange(e: RadioChangeEvent) { function labelLayoutChange(e: RadioChangeEvent) {
if (e.target.value === 'Grid') if (e.target.value === 'Grid')
formConfig.value.layout = 'horizontal' formConfig.value.layout = 'horizontal'
} }
const sliderSpan = computed(() => {
if (formConfig.value.labelLayout)
return Number(formConfig.value.labelCol!.span)
return 0
})
</script> </script>
<template> <template>
@ -33,33 +42,33 @@ function lableLayoutChange(e: RadioChangeEvent) {
<!-- <e-upload v-model="fileList"></e-upload> --> <!-- <e-upload v-model="fileList"></e-upload> -->
<FormItem label="表单布局"> <FormItem label="表单布局">
<Radio.Group v-model:value="formConfig.layout" button-style="solid"> <RadioGroup v-model:value="formConfig.layout" button-style="solid">
<Radio.Button value="horizontal"> <RadioButton value="horizontal">
水平 水平
</Radio.Button> </RadioButton>
<Radio.Button value="vertical" :disabled="formConfig.labelLayout === 'Grid'"> <RadioButton value="vertical" :disabled="formConfig.labelLayout === 'Grid'">
垂直 垂直
</Radio.Button> </RadioButton>
<Radio.Button value="inline" :disabled="formConfig.labelLayout === 'Grid'"> <RadioButton value="inline" :disabled="formConfig.labelLayout === 'Grid'">
行内 行内
</Radio.Button> </RadioButton>
</Radio.Group> </RadioGroup>
</FormItem> </FormItem>
<!-- <Row> --> <!-- <Row> -->
<FormItem label="标签布局"> <FormItem label="标签布局">
<Radio.Group <RadioGroup
v-model:value="formConfig.labelLayout" v-model:value="formConfig.labelLayout"
button-style="solid" button-style="solid"
@change="lableLayoutChange" @change="labelLayoutChange"
> >
<Radio.Button value="flex"> <RadioButton value="flex">
固定 固定
</Radio.Button> </RadioButton>
<Radio.Button value="Grid" :disabled="formConfig.layout !== 'horizontal'"> <RadioButton value="Grid" :disabled="formConfig.layout !== 'horizontal'">
栅格 栅格
</Radio.Button> </RadioButton>
</Radio.Group> </RadioGroup>
</FormItem> </FormItem>
<!-- </Row> --> <!-- </Row> -->
<FormItem v-show="formConfig.labelLayout === 'flex'" label="标签宽度(px)"> <FormItem v-show="formConfig.labelLayout === 'flex'" label="标签宽度(px)">
@ -72,35 +81,35 @@ function lableLayoutChange(e: RadioChangeEvent) {
</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="标签对齐">
<Radio.Group v-model:value="formConfig.labelAlign" button-style="solid"> <RadioGroup v-model:value="formConfig.labelAlign" button-style="solid">
<Radio.Button value="left"> <RadioButton value="left">
靠左 靠左
</Radio.Button> </RadioButton>
<Radio.Button value="right"> <RadioButton value="right">
靠右 靠右
</Radio.Button> </RadioButton>
</Radio.Group> </RadioGroup>
</FormItem> </FormItem>
<FormItem label="控件大小"> <FormItem label="控件大小">
<Radio.Group v-model:value="formConfig.size" button-style="solid"> <RadioGroup v-model:value="formConfig.size" button-style="solid">
<Radio.Button value="default"> <RadioButton value="default">
默认 默认
</Radio.Button> </RadioButton>
<Radio.Button value="small"> <RadioButton value="small">
</Radio.Button> </RadioButton>
<Radio.Button value="large"> <RadioButton value="large">
</Radio.Button> </RadioButton>
</Radio.Group> </RadioGroup>
</FormItem> </FormItem>
</div> </div>
<FormItem label="表单属性"> <FormItem label="表单属性">

2
src/components/FormDesign/src/components/VFormDesign/modules/CollapseItem.vue

@ -7,7 +7,7 @@ import { useDesign } from '@/hooks/web/useDesign'
const props = defineProps( const props = defineProps(
{ {
list: { list: {
type: Array as unknown as any[], type: Array as PropType<IVFormComponent[]>,
default: () => [], default: () => [],
}, },
handleListPush: { handleListPush: {

35
src/components/FormDesign/src/typings/v-form-component.ts

@ -4,12 +4,12 @@ import type { ComponentOptions } from 'vue'
import type { SelectValue } from 'ant-design-vue/lib/select' import type { SelectValue } from 'ant-design-vue/lib/select'
import type { validateOptions } from 'ant-design-vue/lib/form/useForm' import type { validateOptions } from 'ant-design-vue/lib/form/useForm'
import type { RuleError } from 'ant-design-vue/lib/form/interface' import type { RuleError } from 'ant-design-vue/lib/form/interface'
import type { FormLayout, FormProps } from 'ant-design-vue/lib/form/Form'
import type { IVFormMethods } from '../hooks/useVFormMethods' import type { IVFormMethods } from '../hooks/useVFormMethods'
import type { IAnyObject } from './base-type' import type { IAnyObject } from './base-type'
import type { ColEx } from '@/components/Form/src/types' import type { ColEx } from '@/components/Form/src/types'
import type { FormItem } from '@/components/Form' import type { FormItem } from '@/components/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

35
src/components/Icon/src/IconPicker.vue

@ -9,18 +9,26 @@ import SvgIcon from './SvgIcon.vue'
import { useDesign } from '@/hooks/web/useDesign' import { useDesign } from '@/hooks/web/useDesign'
import { ScrollContainer } from '@/components/Container' import { ScrollContainer } from '@/components/Container'
import { propTypes } from '@/utils/propTypes'
import { usePagination } from '@/hooks/web/usePagination' import { usePagination } from '@/hooks/web/usePagination'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { copyText } from '@/utils/copyTextToClipboard' import { copyText } from '@/utils/copyTextToClipboard'
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']).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'])
function getIcons() { function getIcons() {
@ -36,7 +44,7 @@ function getIcons() {
} }
function getSvgIcons() { function getSvgIcons() {
return svgIcons.map(icon => icon.replace('icon-', '')) return svgIcons.map((icon: string) => icon.replace('icon-', ''))
} }
const isSvgMode = props.mode === 'svg' const isSvgMode = props.mode === 'svg'
@ -87,7 +95,10 @@ function handleSearchChange(e: ChangeEvent) {
</script> </script>
<template> <template>
<Input v-model:value="currentSelect" disabled :style="{ width }" :placeholder="t('component.icon.placeholder')" :class="prefixCls"> <Input
v-model:value="currentSelect" disabled :style="{ width }" :placeholder="t('component.icon.placeholder')"
:class="prefixCls"
>
<template #addonAfter> <template #addonAfter>
<Popover v-model="open" placement="bottomLeft" trigger="click" :overlay-class-name="`${prefixCls}-popover`"> <Popover v-model="open" placement="bottomLeft" trigger="click" :overlay-class-name="`${prefixCls}-popover`">
<template #title> <template #title>
@ -101,12 +112,10 @@ function handleSearchChange(e: ChangeEvent) {
<ScrollContainer class="border border-t-0 border-solid"> <ScrollContainer class="border border-t-0 border-solid">
<ul class="flex flex-wrap px-2"> <ul class="flex flex-wrap px-2">
<li <li
v-for="icon in getPaginationList" v-for="icon in getPaginationList" :key="icon"
:key="icon"
:class="currentSelect === icon ? 'border border-primary' : ''" :class="currentSelect === icon ? 'border border-primary' : ''"
class="mr-1 mt-1 w-1/8 flex cursor-pointer items-center justify-center border border-solid p-2 hover:border-primary" class="mr-1 mt-1 w-1/8 flex cursor-pointer items-center justify-center border border-solid p-2 hover:border-primary"
:title="icon" :title="icon" @click="handleClick(icon)"
@click="handleClick(icon)"
> >
<!-- <Icon :icon="icon" :prefix="prefix" /> --> <!-- <Icon :icon="icon" :prefix="prefix" /> -->
<SvgIcon v-if="isSvgMode" :name="icon" /> <SvgIcon v-if="isSvgMode" :name="icon" />

6
src/directives/clickOutside.ts

@ -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)
}) })
} }

4
src/directives/repeatClick.ts

@ -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) if ((e as MouseEvent).button !== 0)
return return
startTime = Date.now() startTime = Date.now()
once(document as any, 'mouseup', clear) once(document as any, 'mouseup', clear)

4
src/directives/ripple/index.ts

@ -29,9 +29,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,

31
src/utils/propTypes.ts

@ -1,6 +1,6 @@
import type { CSSProperties, VNodeChild } from 'vue' import type { CSSProperties, VNodeChild } from 'vue'
import type { VueTypeValidableDef, VueTypesInterface } from 'vue-types' import type { VueTypeValidableDef, VueTypesInterface } from 'vue-types'
import { createTypes } from 'vue-types' import { createTypes, toValidableType } from 'vue-types'
export type VueNode = VNodeChild | JSX.Element export type VueNode = VNodeChild | JSX.Element
@ -10,7 +10,7 @@ type PropTypes = VueTypesInterface & {
// readonly trueBool: VueTypeValidableDef<boolean>; // readonly trueBool: VueTypeValidableDef<boolean>;
} }
const propTypes = createTypes({ const newPropTypes = createTypes({
func: undefined, func: undefined,
bool: undefined, bool: undefined,
string: undefined, string: undefined,
@ -19,17 +19,18 @@ const propTypes = createTypes({
integer: undefined, integer: undefined,
}) as PropTypes }) as PropTypes
// propTypes.extend([ class propTypes extends newPropTypes {
// { // a native-like validator that supports the `.validable` method
// name: 'style', static override get style() {
// getter: true, return toValidableType('style', {
// type: [String, Object], type: [String, Object],
// default: undefined })
// }, }
// {
// name: 'VNodeChild', static override get VNodeChild() {
// getter: true, return toValidableType('VNodeChild', {
// type: undefined type: undefined,
// } })
// ]) }
}
export { propTypes } export { propTypes }

5
src/utils/props.ts

@ -109,7 +109,7 @@ export function buildProp<T = never, D extends BuildPropType<T, V, C> = never, R
: undefined : undefined
return { return {
type: typeof type === 'object' && type && Object.getOwnPropertySymbols(type).includes(wrapperKey) ? type[wrapperKey] : type, type: typeof type === 'object' && type && Object.getOwnPropertySymbols(type).includes(wrapperKey) && type ? type[wrapperKey] : type,
required: !!required, required: !!required,
default: defaultValue, default: defaultValue,
validator: _validator, validator: _validator,
@ -152,7 +152,8 @@ export function buildProps<
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>(arr: T) => Object.keys(arr as any) as Array<keyof T> export const keyOf = <T extends object>(arr: T) => Object.keys(arr) as Array<keyof T>
export const mutable = <T extends readonly any[] | Record<string, unknown>>(val: T) => val as Mutable<typeof val> export const mutable = <T extends readonly any[] | Record<string, unknown>>(val: T) => val as Mutable<typeof val>
export const componentSize = ['large', 'medium', 'small', 'mini'] as const export const componentSize = ['large', 'medium', 'small', 'mini'] as const

4
src/views/base/login/useLogin.ts

@ -115,12 +115,12 @@ export function useFormRules(formData?: Recordable) {
return { getFormRules } return { getFormRules }
} }
function createRule(message: string) { function createRule(message: string): Rule[] {
return [ return [
{ {
required: true, required: true,
message, message,
trigger: 'change', trigger: 'change',
}, },
] as RuleObject[] ]
} }