Merge pull request #181 from kailong321200875/develop

This commit is contained in:
Archer 2022-10-09 17:43:13 +08:00 committed by GitHub
commit e33e2569bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
60 changed files with 219 additions and 170 deletions

View File

@ -7,13 +7,14 @@ import { useWindowSize } from '@vueuse/core'
import { useAppStore } from '@/store/modules/app'
import { setCssVar } from '@/utils'
import { useDesign } from '@/hooks/web/useDesign'
import { ElementPlusSize } from '@/types/elementPlus'
const { variables } = useDesign()
const appStore = useAppStore()
const props = defineProps({
size: propTypes.oneOf<ElememtPlusSize[]>(['default', 'small', 'large']).def('default')
size: propTypes.oneOf<ElementPlusSize[]>(['default', 'small', 'large']).def('default')
})
provide('configGlobal', props)

View File

@ -4,7 +4,7 @@ import { PropType, ref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useDesign } from '@/hooks/web/useDesign'
import type { RouteLocationNormalizedLoaded } from 'vue-router'
import { contextMenuSchema } from '../../../types/contextMenu'
const { getPrefixCls } = useDesign()
const prefixCls = getPrefixCls('context-menu')

View File

@ -4,6 +4,7 @@ import { useDesign } from '@/hooks/web/useDesign'
import { propTypes } from '@/utils/propTypes'
import { ref, unref, PropType, computed, useAttrs } from 'vue'
import { useAppStore } from '@/store/modules/app'
import { DescriptionsSchema } from '@/types/descriptions'
const appStore = useAppStore()

View File

@ -1,5 +1,6 @@
import Form from './src/Form.vue'
import { ElForm } from 'element-plus'
import { FormSchema, FormSetPropsType } from '@/types/form'
export interface FormExpose {
setValues: (data: Recordable) => void

View File

@ -20,6 +20,7 @@ import { findIndex } from '@/utils'
import { set } from 'lodash-es'
import { FormProps } from './types'
import { Icon } from '@/components/Icon'
import { FormSchema, FormSetPropsType } from '@/types/form'
const { getPrefixCls } = useDesign()

View File

@ -20,6 +20,7 @@ import {
} from 'element-plus'
import { InputPassword } from '@/components/InputPassword'
import { Editor } from '@/components/Editor'
import { ComponentName } from '@/types/components'
const componentMap: Recordable<Component, ComponentName> = {
Radio: ElRadioGroup,

View File

@ -1,3 +1,4 @@
import { FormSchema } from '@/types/form'
import { ElCheckbox, ElCheckboxButton } from 'element-plus'
import { defineComponent } from 'vue'

View File

@ -1,3 +1,4 @@
import { FormSchema } from '@/types/form'
import { ElRadio, ElRadioButton } from 'element-plus'
import { defineComponent } from 'vue'

View File

@ -1,6 +1,8 @@
import { ElOption, ElOptionGroup } from 'element-plus'
import { getSlot } from '@/utils/tsxHelper'
import { Slots } from 'vue'
import { FormSchema } from '@/types/form'
import { ComponentOptions } from '@/types/components'
export const useRenderSelect = (slots: Slots) => {
// 渲染 select options

View File

@ -2,6 +2,7 @@ import { useI18n } from '@/hooks/web/useI18n'
import type { Slots } from 'vue'
import { getSlot } from '@/utils/tsxHelper'
import { PlaceholderMoel } from './types'
import { FormSchema } from '@/types/form'
const { t } = useI18n()

View File

@ -1,3 +1,5 @@
import { FormSchema } from '@/types/form'
export interface PlaceholderMoel {
placeholder?: string
startPlaceholder?: string

View File

@ -1,8 +1,9 @@
<script setup lang="ts">
import { PropType } from 'vue'
import { Highlight } from '@//components/Highlight'
import { Highlight } from '@/components/Highlight'
import { useDesign } from '@/hooks/web/useDesign'
import { propTypes } from '@/utils/propTypes'
import { TipSchema } from '@/types/infoTip';
const { getPrefixCls } = useDesign()

View File

@ -6,6 +6,7 @@ import { cloneDeep } from 'lodash-es'
import { propTypes } from '@/utils/propTypes'
import { useDesign } from '@/hooks/web/useDesign'
import { isString } from '@/utils/is'
import { QrcodeLogo } from '@/types/qrcode'
const props = defineProps({
// img canvas,imglogo

View File

@ -7,6 +7,7 @@ import { useI18n } from '@/hooks/web/useI18n'
import { useForm } from '@/hooks/web/useForm'
import { findIndex } from '@/utils'
import { cloneDeep } from 'lodash-es'
import { FormSchema } from '@/types/form'
const { t } = useI18n()

View File

@ -5,6 +5,7 @@ import { useAppStore } from '@/store/modules/app'
import { useI18n } from '@/hooks/web/useI18n'
import { propTypes } from '@/utils/propTypes'
import { useDesign } from '@/hooks/web/useDesign'
import { ElementPlusSize } from '@/types/elementPlus'
const { getPrefixCls } = useDesign()
@ -20,7 +21,7 @@ const appStore = useAppStore()
const sizeMap = computed(() => appStore.sizeMap)
const setCurrentSize = (size: ElememtPlusSize) => {
const setCurrentSize = (size: ElementPlusSize) => {
appStore.setCurrentSize(size)
}
</script>

View File

@ -1,5 +1,6 @@
import Table from './src/Table.vue'
import { ElTable } from 'element-plus'
import { TableSetPropsType } from '@/types/table'
export interface TableExpose {
setProps: (props: Recordable) => void

View File

@ -6,6 +6,7 @@ import { setIndex } from './helper'
import { getSlot } from '@/utils/tsxHelper'
import type { TableProps } from './types'
import { set } from 'lodash-es'
import { TableColumn, TableSlotDefault, Pagination, TableSetPropsType } from '../../../types/table'
export default defineComponent({
name: 'Table',

View File

@ -1,3 +1,5 @@
import { Pagination, TableColumn } from '@/types/table'
export type TableProps = {
pageSize?: number
currentPage?: number

View File

@ -1,3 +1,4 @@
import { ConfigGlobalTypes } from '@/types/configGlobal'
import { inject } from 'vue'
export const useConfigGlobal = () => {

View File

@ -4,6 +4,9 @@ import { findIndex } from '@/utils'
import { useDictStoreWithOut } from '@/store/modules/dict'
import { useI18n } from '@/hooks/web/useI18n'
import type { AxiosPromise } from 'axios'
import { FormSchema } from '@/types/form'
import { TableColumn } from '@/types/table'
import { DescriptionsSchema } from '@/types/descriptions'
export type CrudSchema = Omit<TableColumn, 'children'> & {
search?: CrudSearchParams

View File

@ -2,6 +2,7 @@ import type { Form, FormExpose } from '@/components/Form'
import type { ElForm } from 'element-plus'
import { ref, unref, nextTick } from 'vue'
import type { FormProps } from '@/components/Form/src/types'
import { FormSchema, FormSetPropsType } from '@/types/form'
export const useForm = (props?: FormProps) => {
// From实例

View File

@ -1,6 +1,7 @@
import { h } from 'vue'
import type { VNode } from 'vue'
import { Icon } from '@/components/Icon'
import { IconTypes } from '@/types/icon'
export const useIcon = (props: IconTypes): VNode => {
return h(Icon, props)

View File

@ -4,6 +4,7 @@ import { ref, reactive, watch, computed, unref, nextTick } from 'vue'
import { get } from 'lodash-es'
import type { TableProps } from '@/components/Table/src/types'
import { useI18n } from '@/hooks/web/useI18n'
import { TableSetPropsType } from '@/types/table'
const { t } = useI18n()
@ -144,17 +145,13 @@ export const useTable = <T = any>(config?: UseTableConfig<T>) => {
},
// 与Search组件结合
setSearchParams: (data: Recordable) => {
tableObject.currentPage = 1
tableObject.params = Object.assign(tableObject.params, {
pageSize: tableObject.pageSize,
pageIndex: 1,
pageIndex: tableObject.currentPage,
...data
})
// 页码不等于1时更新页码重新获取数据页码等于1时重新获取数据
if (tableObject.currentPage !== 1) {
tableObject.currentPage = 1
} else {
methods.getList()
}
},
// 删除数据
delList: async (ids: string[] | number[], multiple: boolean, message = true) => {

View File

@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
import { store } from '../index'
import { setCssVar, humpToUnderline } from '@/utils'
import { ElMessage } from 'element-plus'
import { ElementPlusSize } from '@/types/elementPlus'
import { useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache()
@ -169,10 +170,10 @@ export const useAppStore = defineStore('app', {
getIsDark(): boolean {
return this.isDark
},
getCurrentSize(): ElememtPlusSize {
getCurrentSize(): ElementPlusSize {
return this.currentSize
},
getSizeMap(): ElememtPlusSize[] {
getSizeMap(): ElementPlusSize[] {
return this.sizeMap
},
getMobile(): boolean {
@ -254,7 +255,7 @@ export const useAppStore = defineStore('app', {
}
wsCache.set('isDark', this.isDark)
},
setCurrentSize(currentSize: ElememtPlusSize) {
setCurrentSize(currentSize: ElementPlusSize) {
this.currentSize = currentSize
wsCache.set('currentSize', this.currentSize)
},

View File

@ -3,6 +3,7 @@ import { store } from '../index'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import en from 'element-plus/es/locale/lang/en'
import { useCache } from '@/hooks/web/useCache'
import { LocaleDropdownType } from '@/types/localeDropdown'
const { wsCache } = useCache()

52
src/types/components.d.ts vendored Normal file
View File

@ -0,0 +1,52 @@
export type ComponentName =
| 'Radio'
| 'RadioButton'
| 'Checkbox'
| 'CheckboxButton'
| 'Input'
| 'Autocomplete'
| 'InputNumber'
| 'Select'
| 'Cascader'
| 'Switch'
| 'Slider'
| 'TimePicker'
| 'DatePicker'
| 'Rate'
| 'ColorPicker'
| 'Transfer'
| 'Divider'
| 'TimeSelect'
| 'SelectV2'
| 'InputPassword'
| 'Editor'
export type ColProps = {
span?: number
xs?: number
sm?: number
md?: number
lg?: number
xl?: number
tag?: string
}
export type ComponentOptions = {
label?: string
value?: FormValueType
disabled?: boolean
key?: string | number
children?: ComponentOptions[]
options?: ComponentOptions[]
} & Recordable
export type ComponentOptionsAlias = {
labelField?: string
valueField?: string
}
export type ComponentProps = {
optionsAlias?: ComponentOptionsAlias
options?: ComponentOptions[]
optionsSlot?: boolean
} & Recordable

4
src/types/configGlobal.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
import { ElementPlusSize } from './elementPlus'
export interface ConfigGlobalTypes {
size?: ElementPlusSize
}

7
src/types/contextMenu.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
export type contextMenuSchema = {
disabled?: boolean
divided?: boolean
icon?: string
label: string
command?: (item: contextMenuSchema) => void
}

View File

@ -1,4 +1,4 @@
declare interface DescriptionsSchema {
export interface DescriptionsSchema {
span?: number // 占多少分
field: string // 字段名
label?: string // label名

3
src/types/elementPlus.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export type ElementPlusSize = 'default' | 'small' | 'large'
export type ElementPlusInfoType = 'success' | 'info' | 'warning' | 'danger'

45
src/types/form.d.ts vendored Normal file
View File

@ -0,0 +1,45 @@
import type { CSSProperties } from 'vue'
import { ColProps, ComponentProps, ComponentName } from '@/types/components'
import { FormValueType, FormValueType } from '@/types/form'
import type { AxiosPromise } from 'axios'
export type FormSetPropsType = {
field: string
path: string
value: any
}
export type FormValueType = string | number | string[] | number[] | boolean | undefined | null
export type FormItemProps = {
labelWidth?: string | number
required?: boolean
rules?: Recordable
error?: string
showMessage?: boolean
inlineMessage?: boolean
style?: CSSProperties
}
export type FormSchema = {
// 唯一值
field: string
// 标题
label?: string
// 提示
labelMessage?: string
// col组件属性
colProps?: ColProps
// 表单组件属性slots对应的是表单组件的插槽规则${field}-xxx具体可以查看element-plus文档
componentProps?: { slots?: Recordable } & ComponentProps
// formItem组件属性
formItemProps?: FormItemProps
// 渲染的组件
component?: ComponentName
// 初始值
value?: FormValueType
// 是否隐藏
hidden?: boolean
// 远程加载下拉项
api?: <T = any>() => AxiosPromise<T>
}

View File

@ -1,4 +1,4 @@
declare interface IconTypes {
export interface IconTypes {
size?: number
color?: string
icon: string

View File

@ -1,4 +1,4 @@
declare interface TipSchema {
export interface TipSchema {
label: string
keys?: string[]
}

View File

@ -1,9 +1,9 @@
declare interface Language {
export interface Language {
el: Recordable
name: string
}
declare interface LocaleDropdownType {
export interface LocaleDropdownType {
lang: LocaleType
name?: string
elLocale?: Language

View File

@ -1,4 +1,4 @@
declare interface QrcodeLogo {
export interface QrcodeLogo {
src?: string
logoSize?: number
bgColor?: string

View File

@ -1,16 +1,16 @@
declare type TableColumn = {
export type TableColumn = {
field: string
label?: string
children?: TableColumn[]
} & Recordable
declare type TableSlotDefault = {
export type TableSlotDefault = {
row: Recordable
column: TableColumn
$index: number
} & Recordable
declare interface Pagination {
export interface Pagination {
small?: boolean
background?: boolean
pageSize?: number
@ -29,7 +29,7 @@ declare interface Pagination {
hideOnSinglePage?: boolean
}
declare interface TableSetPropsType {
export interface TableSetPropsType {
field: string
path: string
value: any

View File

@ -6,6 +6,7 @@ import { getUserListApi } from '@/api/login'
import { UserType } from '@/api/login/types'
import { ref, h } from 'vue'
import { ElButton } from 'element-plus'
import { TableColumn, TableSlotDefault } from '@/types/table'
interface Params {
pageIndex?: number

View File

@ -6,6 +6,7 @@ import { getUserListApi } from '@/api/login'
import { UserType } from '@/api/login/types'
import { ref, h } from 'vue'
import { ElButton } from 'element-plus'
import { TableColumn, TableSlotDefault } from '@/types/table'
interface Params {
pageIndex?: number

View File

@ -6,6 +6,7 @@ import { Form } from '@/components/Form'
import { ElFormItem, ElInput, ElButton } from 'element-plus'
import { useValidator } from '@/hooks/web/useValidator'
import { useForm } from '@/hooks/web/useForm'
import { DescriptionsSchema } from '@/types/descriptions'
const { required } = useValidator()

View File

@ -7,6 +7,7 @@ import { ref, reactive, unref } from 'vue'
import { Form, FormExpose } from '@/components/Form'
import { useValidator } from '@/hooks/web/useValidator'
import { getDictOneApi } from '@/api/common'
import { FormSchema } from '@/types/form'
const { required } = useValidator()

View File

@ -5,6 +5,8 @@ import { useI18n } from '@/hooks/web/useI18n'
import { useIcon } from '@/hooks/web/useIcon'
import { ContentWrap } from '@/components/ContentWrap'
import { useAppStore } from '@/store/modules/app'
import { FormSchema } from '@/types/form'
import { ComponentOptions } from '@/types/components'
const appStore = useAppStore()

View File

@ -6,6 +6,7 @@ import { reactive, unref, ref } from 'vue'
import { ElButton } from 'element-plus'
import { useValidator } from '@/hooks/web/useValidator'
import { getDictOneApi } from '@/api/common'
import { FormSchema } from '@/types/form'
const { required } = useValidator()

View File

@ -7,6 +7,7 @@ import { reactive, unref, ref } from 'vue'
import { ElButton } from 'element-plus'
import { useValidator } from '@/hooks/web/useValidator'
import { getDictOneApi } from '@/api/common'
import { FormSchema } from '@/types/form'
const { required } = useValidator()

View File

@ -6,6 +6,7 @@ import { reactive, ref, unref } from 'vue'
import { useValidator } from '@/hooks/web/useValidator'
import { ElButton } from 'element-plus'
import { getDictOneApi } from '@/api/common'
import { FormSchema } from '@/types/form'
const { required } = useValidator()

View File

@ -6,6 +6,7 @@ import { getTableListApi } from '@/api/table'
import { TableData } from '@/api/table/types'
import { ref, h } from 'vue'
import { ElTag, ElButton } from 'element-plus'
import { TableColumn, TableSlotDefault } from '@/types/table'
interface Params {
pageIndex?: number

View File

@ -7,6 +7,7 @@ import { TableData } from '@/api/table/types'
import { ref, h, reactive, unref } from 'vue'
import { ElTag, ElButton } from 'element-plus'
import { useTable } from '@/hooks/web/useTable'
import { Pagination, TableColumn, TableSlotDefault } from '@/types/table'
const { t } = useI18n()

View File

@ -7,6 +7,7 @@ import { TableData } from '@/api/table/types'
import { ref, h, reactive, unref } from 'vue'
import { ElTag, ElButton } from 'element-plus'
import { useTable } from '@/hooks/web/useTable'
import { Pagination, TableColumn, TableSlotDefault } from '@/types/table'
const { register, tableObject, methods, elTableRef } = useTable<TableData>({
getListApi: getTableListApi,

View File

@ -12,6 +12,7 @@ import { h, ref, unref, reactive } from 'vue'
import Write from './components/Write.vue'
import Detail from './components/Detail.vue'
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
import { TableColumn } from '@/types/table'
const { register, tableObject, methods } = useTable<TableData>({
getListApi: getTableListApi,

View File

@ -4,6 +4,7 @@ import type { TableData } from '@/api/table/types'
import { Descriptions } from '@/components/Descriptions'
import { useI18n } from '@/hooks/web/useI18n'
import { ElTag } from 'element-plus'
import { DescriptionsSchema } from '@/types/descriptions'
const { t } = useI18n()

View File

@ -4,6 +4,7 @@ import { useForm } from '@/hooks/web/useForm'
import { PropType, reactive, watch } from 'vue'
import { TableData } from '@/api/table/types'
import { useValidator } from '@/hooks/web/useValidator'
import { FormSchema } from '@/types/form'
const { required } = useValidator()

View File

@ -11,6 +11,7 @@ import { h, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useEmitt } from '@/hooks/web/useEmitt'
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
import { TableColumn } from '@/types/table'
defineOptions({
name: 'ExamplePage'

View File

@ -4,6 +4,7 @@ import type { TableData } from '@/api/table/types'
import { Descriptions } from '@/components/Descriptions'
import { useI18n } from '@/hooks/web/useI18n'
import { ElTag } from 'element-plus'
import { DescriptionsSchema } from '@/types/descriptions'
const { t } = useI18n()

View File

@ -6,6 +6,7 @@ import { TableData } from '@/api/table/types'
import { useI18n } from '@/hooks/web/useI18n'
import { useValidator } from '@/hooks/web/useValidator'
import { IDomEditor } from '@wangeditor/editor'
import { FormSchema } from '@/types/form'
const { required } = useValidator()

View File

@ -12,6 +12,7 @@ import { useRouter } from 'vue-router'
import type { RouteLocationNormalizedLoaded, RouteRecordRaw } from 'vue-router'
import { UserType } from '@/api/login/types'
import { useValidator } from '@/hooks/web/useValidator'
import { FormSchema } from '@/types/form'
const { required } = useValidator()

View File

@ -5,6 +5,7 @@ import { useI18n } from '@/hooks/web/useI18n'
import { useForm } from '@/hooks/web/useForm'
import { ElButton, ElInput, FormRules } from 'element-plus'
import { useValidator } from '@/hooks/web/useValidator'
import { FormSchema } from '@/types/form'
const emit = defineEmits(['to-login'])

View File

@ -11,6 +11,7 @@ import { h, ref, reactive } from 'vue'
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
import { useDictStore } from '@/store/modules/dict'
import { getDictOneApi } from '@/api/common'
import { TableColumn } from '@/types/table'
const dictStore = useDictStore()

View File

@ -1,3 +0,0 @@
declare interface ConfigGlobalTypes {
size?: ElememtPlusSize
}

View File

@ -1,7 +0,0 @@
declare type contextMenuSchema = {
disabled?: boolean
divided?: boolean
icon?: string
label: string
command?: (item: contextMenuSchema) => viod
}

View File

@ -1,97 +0,0 @@
import type { CSSProperties } from 'vue'
declare global {
declare type ComponentName =
| 'Radio'
| 'RadioButton'
| 'Checkbox'
| 'CheckboxButton'
| 'Input'
| 'Autocomplete'
| 'InputNumber'
| 'Select'
| 'Cascader'
| 'Switch'
| 'Slider'
| 'TimePicker'
| 'DatePicker'
| 'Rate'
| 'ColorPicker'
| 'Transfer'
| 'Divider'
| 'TimeSelect'
| 'SelectV2'
| 'InputPassword'
| 'Editor'
declare type ColProps = {
span?: number
xs?: number
sm?: number
md?: number
lg?: number
xl?: number
tag?: string
}
declare type FormValueType = string | number | string[] | number[] | boolean | undefined | null
declare type FormItemProps = {
labelWidth?: string | number
required?: boolean
rules?: Recordable
error?: string
showMessage?: boolean
inlineMessage?: boolean
style?: CSSProperties
}
declare type ComponentOptions = {
label?: string
value?: FormValueType
disabled?: boolean
key?: string | number
children?: ComponentOptions[]
options?: ComponentOptions[]
} & Recordable
declare type ComponentOptionsAlias = {
labelField?: string
valueField?: string
}
declare type ComponentProps = {
optionsAlias?: ComponentOptionsAlias
options?: ComponentOptions[]
optionsSlot?: boolean
} & Recordable
declare type FormSchema = {
// 唯一值
field: string
// 标题
label?: string
// 提示
labelMessage?: string
// col组件属性
colProps?: ColProps
// 表单组件属性slots对应的是表单组件的插槽规则${field}-xxx具体可以查看element-plus文档
componentProps?: { slots?: Recordable } & ComponentProps
// formItem组件属性
formItemProps?: FormItemProps
// 渲染的组件
component?: ComponentName
// 初始值
value?: FormValueType
// 是否隐藏
hidden?: boolean
// 远程加载下拉项
api?: <T = any>() => AxiosPromise<T>
}
declare type FormSetPropsType = {
field: string
path: string
value: any
}
}

7
types/global.d.ts vendored
View File

@ -1,3 +1,5 @@
import type { CSSProperties } from 'vue'
declare global {
declare interface Fn<T = any> {
(...arg: T[]): T
}
@ -6,10 +8,6 @@ declare type Nullable<T> = T | null
declare type ElRef<T extends HTMLElement = HTMLDivElement> = Nullable<T>
declare type ElememtPlusSize = 'default' | 'small' | 'large'
declare type ElementPlusInfoType = 'success' | 'info' | 'warning' | 'danger'
declare type Recordable<T = any, K = string> = Record<K extends null | undefined ? string : K, T>
declare type ComponentRef<T> = InstanceType<T>
@ -38,3 +36,4 @@ declare interface IResponse<T = any> {
code: string
data: T extends any ? T : T & any
}
}