feat: 新增 useCrudSchemas demo
This commit is contained in:
parent
c0f4517b87
commit
ae0628e3af
|
@ -345,15 +345,15 @@ const adminList = [
|
||||||
meta: {
|
meta: {
|
||||||
title: 'useValidator'
|
title: 'useValidator'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'useCrudSchemas',
|
||||||
|
component: 'views/hooks/useCrudSchemas',
|
||||||
|
name: 'UseCrudSchemas',
|
||||||
|
meta: {
|
||||||
|
title: 'useCrudSchemas'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// {
|
|
||||||
// path: 'useCrudSchemas',
|
|
||||||
// component: 'views/hooks/useCrudSchemas',
|
|
||||||
// name: 'UseCrudSchemas',
|
|
||||||
// meta: {
|
|
||||||
// title: 'useCrudSchemas'
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -616,7 +616,7 @@ const testList: string[] = [
|
||||||
'/hooks/useWatermark',
|
'/hooks/useWatermark',
|
||||||
'/hooks/useTagsView',
|
'/hooks/useTagsView',
|
||||||
'/hooks/useValidator',
|
'/hooks/useValidator',
|
||||||
// '/hooks/useCrudSchemas',
|
'/hooks/useCrudSchemas',
|
||||||
'/level',
|
'/level',
|
||||||
'/level/menu1',
|
'/level/menu1',
|
||||||
'/level/menu1/menu1-1',
|
'/level/menu1/menu1-1',
|
||||||
|
|
|
@ -17,7 +17,7 @@ const props = defineProps({
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({})
|
default: () => ({})
|
||||||
},
|
},
|
||||||
deep: propTypes.number.def(1),
|
deep: propTypes.number.def(5),
|
||||||
showLength: propTypes.bool.def(true),
|
showLength: propTypes.bool.def(true),
|
||||||
showLineNumbers: propTypes.bool.def(true),
|
showLineNumbers: propTypes.bool.def(true),
|
||||||
showLineNumber: propTypes.bool.def(true),
|
showLineNumber: propTypes.bool.def(true),
|
||||||
|
|
|
@ -387,15 +387,15 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
|
||||||
meta: {
|
meta: {
|
||||||
title: 'useValidator'
|
title: 'useValidator'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'useCrudSchemas',
|
||||||
|
component: () => import('@/views/hooks/useCrudSchemas.vue'),
|
||||||
|
name: 'UseCrudSchemas',
|
||||||
|
meta: {
|
||||||
|
title: 'useCrudSchemas'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// {
|
|
||||||
// path: 'useCrudSchemas',
|
|
||||||
// component: () => import('@/views/hooks/useCrudSchemas.vue'),
|
|
||||||
// name: 'UseCrudSchemas',
|
|
||||||
// meta: {
|
|
||||||
// title: 'useCrudSchemas'
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,223 +1,186 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// import { ContentWrap } from '@/components/ContentWrap'
|
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
|
||||||
// import { Search } from '@/components/Search'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
// import { useI18n } from '@/hooks/web/useI18n'
|
import { reactive } from 'vue'
|
||||||
// import { ElButton, ElTag } from 'element-plus'
|
import { JsonEditor } from '@/components/JsonEditor'
|
||||||
// import { Table } from '@/components/Table'
|
import { ContentWrap } from '@/components/ContentWrap'
|
||||||
// import { getTableListApi, delTableListApi } from '@/api/table'
|
import { ElRow, ElCol } from 'element-plus'
|
||||||
// import { useTable } from '@/hooks/web/useTable'
|
|
||||||
// import { TableData } from '@/api/table/types'
|
|
||||||
// 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()
|
const { t } = useI18n()
|
||||||
|
|
||||||
// const { register, tableObject, methods } = useTable<TableData>({
|
const crudSchemas = reactive<CrudSchema[]>([
|
||||||
// getListApi: getTableListApi,
|
{
|
||||||
// delListApi: delTableListApi,
|
field: 'selection',
|
||||||
// response: {
|
search: {
|
||||||
// list: 'list',
|
hidden: true
|
||||||
// total: 'total'
|
},
|
||||||
// }
|
form: {
|
||||||
// })
|
hidden: true
|
||||||
|
},
|
||||||
|
detail: {
|
||||||
|
hidden: true
|
||||||
|
},
|
||||||
|
table: {
|
||||||
|
type: 'selection'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'index',
|
||||||
|
label: t('tableDemo.index'),
|
||||||
|
type: 'index',
|
||||||
|
search: {
|
||||||
|
hidden: true
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
hidden: true
|
||||||
|
},
|
||||||
|
detail: {
|
||||||
|
hidden: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'title',
|
||||||
|
label: t('tableDemo.title'),
|
||||||
|
search: {
|
||||||
|
component: 'Input'
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
component: 'Input',
|
||||||
|
colProps: {
|
||||||
|
span: 24
|
||||||
|
}
|
||||||
|
},
|
||||||
|
detail: {
|
||||||
|
span: 24
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'author',
|
||||||
|
label: t('tableDemo.author'),
|
||||||
|
search: {
|
||||||
|
hidden: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'display_time',
|
||||||
|
label: t('tableDemo.displayTime'),
|
||||||
|
search: {
|
||||||
|
hidden: true
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
component: 'DatePicker',
|
||||||
|
componentProps: {
|
||||||
|
type: 'datetime',
|
||||||
|
valueFormat: 'YYYY-MM-DD HH:mm:ss'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'importance',
|
||||||
|
label: t('tableDemo.importance'),
|
||||||
|
search: {
|
||||||
|
hidden: true
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
style: {
|
||||||
|
width: '100%'
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '重要',
|
||||||
|
value: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '良好',
|
||||||
|
value: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '一般',
|
||||||
|
value: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'pageviews',
|
||||||
|
label: t('tableDemo.pageviews'),
|
||||||
|
search: {
|
||||||
|
hidden: true
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
component: 'InputNumber',
|
||||||
|
value: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'content',
|
||||||
|
label: t('exampleDemo.content'),
|
||||||
|
search: {
|
||||||
|
hidden: true
|
||||||
|
},
|
||||||
|
table: {
|
||||||
|
show: false
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
component: 'Editor',
|
||||||
|
colProps: {
|
||||||
|
span: 24
|
||||||
|
}
|
||||||
|
},
|
||||||
|
detail: {
|
||||||
|
span: 24
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'action',
|
||||||
|
width: '260px',
|
||||||
|
label: t('tableDemo.action'),
|
||||||
|
search: {
|
||||||
|
hidden: true
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
hidden: true
|
||||||
|
},
|
||||||
|
detail: {
|
||||||
|
hidden: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
// const { getList, setSearchParams } = methods
|
const { allSchemas } = useCrudSchemas(crudSchemas)
|
||||||
|
|
||||||
// getList()
|
|
||||||
|
|
||||||
// const { t } = useI18n()
|
|
||||||
|
|
||||||
// const crudSchemas = reactive<CrudSchema[]>([
|
|
||||||
// {
|
|
||||||
// field: 'index',
|
|
||||||
// label: t('tableDemo.index'),
|
|
||||||
// type: 'index',
|
|
||||||
// form: {
|
|
||||||
// show: false
|
|
||||||
// },
|
|
||||||
// detail: {
|
|
||||||
// show: false
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// field: 'title',
|
|
||||||
// label: t('tableDemo.title'),
|
|
||||||
// search: {
|
|
||||||
// show: true
|
|
||||||
// },
|
|
||||||
// form: {
|
|
||||||
// colProps: {
|
|
||||||
// span: 24
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// detail: {
|
|
||||||
// span: 24
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// field: 'author',
|
|
||||||
// label: t('tableDemo.author')
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// field: 'display_time',
|
|
||||||
// label: t('tableDemo.displayTime'),
|
|
||||||
// form: {
|
|
||||||
// component: 'DatePicker',
|
|
||||||
// componentProps: {
|
|
||||||
// type: 'datetime',
|
|
||||||
// valueFormat: 'YYYY-MM-DD HH:mm:ss'
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// field: 'importance',
|
|
||||||
// label: t('tableDemo.importance'),
|
|
||||||
// formatter: (_: Recordable, __: TableColumn, cellValue: number) => {
|
|
||||||
// return h(
|
|
||||||
// ElTag,
|
|
||||||
// {
|
|
||||||
// type: cellValue === 1 ? 'success' : cellValue === 2 ? 'warning' : 'danger'
|
|
||||||
// },
|
|
||||||
// () =>
|
|
||||||
// cellValue === 1
|
|
||||||
// ? t('tableDemo.important')
|
|
||||||
// : cellValue === 2
|
|
||||||
// ? t('tableDemo.good')
|
|
||||||
// : t('tableDemo.commonly')
|
|
||||||
// )
|
|
||||||
// },
|
|
||||||
// search: {
|
|
||||||
// show: true,
|
|
||||||
// component: 'Select',
|
|
||||||
// componentProps: {
|
|
||||||
// options: dictStore.getDictObj.importance
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// form: {
|
|
||||||
// component: 'Select',
|
|
||||||
// componentProps: {
|
|
||||||
// options: [
|
|
||||||
// {
|
|
||||||
// label: '重要',
|
|
||||||
// value: 3
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// label: '良好',
|
|
||||||
// value: 2
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// label: '一般',
|
|
||||||
// value: 1
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// field: 'importance2',
|
|
||||||
// label: `${t('tableDemo.importance')}2`,
|
|
||||||
// search: {
|
|
||||||
// show: true,
|
|
||||||
// component: 'Select',
|
|
||||||
// dictName: 'importance'
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// field: 'importance3',
|
|
||||||
// label: `${t('tableDemo.importance')}3`,
|
|
||||||
// search: {
|
|
||||||
// show: true,
|
|
||||||
// component: 'Select',
|
|
||||||
// api: async () => {
|
|
||||||
// const res = await getDictOneApi()
|
|
||||||
// return res.data
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// field: 'pageviews',
|
|
||||||
// label: t('tableDemo.pageviews'),
|
|
||||||
// form: {
|
|
||||||
// component: 'InputNumber',
|
|
||||||
// value: 0
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// field: 'content',
|
|
||||||
// label: t('exampleDemo.content'),
|
|
||||||
// table: {
|
|
||||||
// show: false
|
|
||||||
// },
|
|
||||||
// form: {
|
|
||||||
// component: 'Editor',
|
|
||||||
// colProps: {
|
|
||||||
// span: 24
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// detail: {
|
|
||||||
// span: 24
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// field: 'action',
|
|
||||||
// width: '260px',
|
|
||||||
// label: t('tableDemo.action'),
|
|
||||||
// form: {
|
|
||||||
// show: false
|
|
||||||
// },
|
|
||||||
// detail: {
|
|
||||||
// show: false
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// ])
|
|
||||||
|
|
||||||
// const { allSchemas } = useCrudSchemas(crudSchemas)
|
|
||||||
|
|
||||||
// const delLoading = ref(false)
|
|
||||||
|
|
||||||
// const delData = async (row: TableData | null, multiple: boolean) => {
|
|
||||||
// tableObject.currentRow = row
|
|
||||||
// const { delList, getSelections } = methods
|
|
||||||
// const selections = await getSelections()
|
|
||||||
// delLoading.value = true
|
|
||||||
// await delList(
|
|
||||||
// multiple ? selections.map((v) => v.id) : [tableObject.currentRow?.id as string],
|
|
||||||
// multiple
|
|
||||||
// ).finally(() => {
|
|
||||||
// delLoading.value = false
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ContentWrap>
|
<ContentWrap title="useCrudSchemas">
|
||||||
<!-- <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
|
<ElRow :gutter="20">
|
||||||
|
<ElCol :span="24">
|
||||||
<div class="mb-10px">
|
<ContentWrap title="原始数据数据" class="mt-20px">
|
||||||
<ElButton :loading="delLoading" type="danger" @click="delData(null, true)">
|
<JsonEditor v-model="crudSchemas" />
|
||||||
{{ t('exampleDemo.del') }}
|
</ContentWrap>
|
||||||
</ElButton>
|
</ElCol>
|
||||||
</div>
|
<ElCol :span="24">
|
||||||
|
<ContentWrap title="查询组件数据结构" class="mt-20px">
|
||||||
<Table
|
<JsonEditor v-model="allSchemas.searchSchema" />
|
||||||
v-model:pageSize="tableObject.pageSize"
|
</ContentWrap>
|
||||||
v-model:currentPage="tableObject.currentPage"
|
</ElCol>
|
||||||
:columns="allSchemas.tableColumns"
|
<ElCol :span="24">
|
||||||
:data="tableObject.tableList"
|
<ContentWrap title="表单组件数据结构" class="mt-20px">
|
||||||
:loading="tableObject.loading"
|
<JsonEditor v-model="allSchemas.formSchema" />
|
||||||
:pagination="{
|
</ContentWrap>
|
||||||
total: tableObject.total
|
</ElCol>
|
||||||
}"
|
<ElCol :span="24">
|
||||||
@register="register"
|
<ContentWrap title="表格组件数据结构" class="mt-20px">
|
||||||
>
|
<JsonEditor v-model="allSchemas.tableColumns" />
|
||||||
<template #action="{ row }">
|
</ContentWrap>
|
||||||
<ElButton type="danger" @click="delData(row, false)">
|
</ElCol>
|
||||||
{{ t('exampleDemo.del') }}
|
<ElCol :span="24">
|
||||||
</ElButton>
|
<ContentWrap title="表格组件数据结构" class="mt-20px">
|
||||||
</template>
|
<JsonEditor v-model="allSchemas.detailSchema" />
|
||||||
</Table> -->
|
</ContentWrap>
|
||||||
|
</ElCol>
|
||||||
|
</ElRow>
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue