更新
This commit is contained in:
parent
331b233e60
commit
deaa9de232
41
kinit-admin/src/api/vadmin/system/dict.ts
Normal file
41
kinit-admin/src/api/vadmin/system/dict.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import request from '@/config/axios'
|
||||
|
||||
export const getDictTypeListApi = (params: any): Promise<IResponse> => {
|
||||
return request.get({ url: '/vadmin/system/dict/types/', params })
|
||||
}
|
||||
|
||||
export const addDictTypeListApi = (data: any): Promise<IResponse> => {
|
||||
return request.post({ url: '/vadmin/system/dict/types/', data })
|
||||
}
|
||||
|
||||
export const delDictTypeListApi = (data: any): Promise<IResponse> => {
|
||||
return request.delete({ url: '/vadmin/system/dict/types/', data })
|
||||
}
|
||||
|
||||
export const putDictTypeListApi = (data: any): Promise<IResponse> => {
|
||||
return request.put({ url: `/vadmin/system/dict/types/${data.id}/`, data })
|
||||
}
|
||||
|
||||
export const getDictTypeApi = (dataId: number): Promise<IResponse> => {
|
||||
return request.get({ url: `/vadmin/system/dict/types/${dataId}/` })
|
||||
}
|
||||
|
||||
export const getDictDetailsListApi = (params: any): Promise<IResponse> => {
|
||||
return request.get({ url: '/vadmin/system/dict/details/', params })
|
||||
}
|
||||
|
||||
export const addDictDetailsListApi = (data: any): Promise<IResponse> => {
|
||||
return request.post({ url: '/vadmin/system/dict/details/', data })
|
||||
}
|
||||
|
||||
export const delDictDetailsListApi = (data: any): Promise<IResponse> => {
|
||||
return request.delete({ url: '/vadmin/system/dict/details/', data })
|
||||
}
|
||||
|
||||
export const putDictDetailsListApi = (data: any): Promise<IResponse> => {
|
||||
return request.put({ url: `/vadmin/system/dict/details/${data.id}/`, data })
|
||||
}
|
||||
|
||||
export const getDictDetailsApi = (dataId: number): Promise<IResponse> => {
|
||||
return request.get({ url: `/vadmin/system/dict/details/${dataId}/` })
|
||||
}
|
@ -30,7 +30,11 @@ export const useRenderSelect = (slots: Slots) => {
|
||||
const labelAlias = item?.componentProps?.optionsAlias?.labelField
|
||||
const valueAlias = item?.componentProps?.optionsAlias?.valueField
|
||||
return (
|
||||
<ElOption label={option[labelAlias || 'label']} value={option[valueAlias || 'value']}>
|
||||
<ElOption
|
||||
label={option[labelAlias || 'label']}
|
||||
value={option[valueAlias || 'value']}
|
||||
disabled={option.disabled}
|
||||
>
|
||||
{{
|
||||
default: () =>
|
||||
// option 插槽名规则,{field}-option
|
||||
|
@ -17,8 +17,9 @@ const props = defineProps({
|
||||
|
||||
const rules = reactive({
|
||||
name: [required()],
|
||||
role_key: [required()],
|
||||
order: [required()]
|
||||
is_active: [required()],
|
||||
role_ids: [required()],
|
||||
telephone: [required()]
|
||||
})
|
||||
|
||||
const { register, methods, elFormRef } = useForm({
|
||||
@ -40,7 +41,6 @@ watch(
|
||||
|
||||
const getRoleOptions = async () => {
|
||||
const res = await getRoleOptionsApi()
|
||||
console.log('111111', res)
|
||||
if (res) {
|
||||
const { setSchema } = methods
|
||||
setSchema([
|
||||
@ -53,7 +53,7 @@ const getRoleOptions = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// getRoleOptions()
|
||||
getRoleOptions()
|
||||
|
||||
defineExpose({
|
||||
elFormRef,
|
||||
|
@ -65,19 +65,6 @@ export const schema = reactive<FormSchema[]>([
|
||||
},
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: 'password',
|
||||
label: '用户密码',
|
||||
colProps: {
|
||||
span: 12
|
||||
},
|
||||
component: 'InputPassword',
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '100%'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'gender',
|
||||
label: '性别',
|
||||
@ -137,34 +124,13 @@ export const schema = reactive<FormSchema[]>([
|
||||
style: {
|
||||
width: '100%'
|
||||
},
|
||||
// optionsAlias: {
|
||||
// labelField: 'name',
|
||||
// valueField: 'id'
|
||||
// },
|
||||
options: [
|
||||
{
|
||||
value: 'Option1',
|
||||
label: 'Option1'
|
||||
},
|
||||
{
|
||||
value: 'Option2',
|
||||
label: 'Option2',
|
||||
disabled: true
|
||||
},
|
||||
{
|
||||
value: 'Option3',
|
||||
label: 'Option3'
|
||||
},
|
||||
{
|
||||
value: 'Option4',
|
||||
label: 'Option4'
|
||||
},
|
||||
{
|
||||
value: 'Option5',
|
||||
label: 'Option5'
|
||||
}
|
||||
]
|
||||
optionsAlias: {
|
||||
labelField: 'name',
|
||||
valueField: 'id'
|
||||
},
|
||||
multiple: true,
|
||||
collapseTags: true
|
||||
},
|
||||
value: ''
|
||||
value: []
|
||||
}
|
||||
])
|
||||
|
@ -47,6 +47,7 @@ const AddAction = () => {
|
||||
const updateAction = async (row: any) => {
|
||||
const res = await getUserApi(row.id)
|
||||
dialogTitle.value = '编辑'
|
||||
res.data.role_ids = res.data.roles.map((item: any) => item.id)
|
||||
tableObject.currentRow = res.data
|
||||
dialogVisible.value = true
|
||||
actionType.value = 'edit'
|
||||
|
@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import { Form } from '@/components/Form'
|
||||
import { useForm } from '@/hooks/web/useForm'
|
||||
import { PropType, reactive, watch } from 'vue'
|
||||
import { useValidator } from '@/hooks/web/useValidator'
|
||||
import { schema } from './dict.data'
|
||||
|
||||
const { required } = useValidator()
|
||||
|
||||
const props = defineProps({
|
||||
currentRow: {
|
||||
type: Object as PropType<Nullable<any>>,
|
||||
default: () => null
|
||||
}
|
||||
})
|
||||
|
||||
const rules = reactive({
|
||||
dict_name: [required()],
|
||||
dict_type: [required()],
|
||||
disabled: [required()]
|
||||
})
|
||||
|
||||
const { register, methods, elFormRef } = useForm({
|
||||
schema: schema
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.currentRow,
|
||||
(currentRow) => {
|
||||
if (!currentRow) return
|
||||
const { setValues } = methods
|
||||
setValues(currentRow)
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
immediate: true
|
||||
}
|
||||
)
|
||||
|
||||
defineExpose({
|
||||
elFormRef,
|
||||
getFormData: methods.getFormData
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Form :rules="rules" @register="register" />
|
||||
</template>
|
@ -0,0 +1,88 @@
|
||||
import { reactive } from 'vue'
|
||||
|
||||
export const columns = reactive<TableColumn[]>([
|
||||
{
|
||||
field: 'id',
|
||||
label: '字典编号'
|
||||
},
|
||||
{
|
||||
field: 'label',
|
||||
label: '字典标签'
|
||||
},
|
||||
{
|
||||
field: 'value',
|
||||
label: '字典键值'
|
||||
},
|
||||
{
|
||||
field: 'order',
|
||||
label: '字典排序'
|
||||
},
|
||||
{
|
||||
field: 'disabled',
|
||||
label: '是否禁用'
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
label: '备注'
|
||||
},
|
||||
{
|
||||
field: 'create_datetime',
|
||||
label: '创建时间'
|
||||
},
|
||||
{
|
||||
field: 'action',
|
||||
width: '260px',
|
||||
label: '操作'
|
||||
}
|
||||
])
|
||||
|
||||
export const schema = reactive<FormSchema[]>([
|
||||
{
|
||||
field: 'dict_name',
|
||||
label: '字典名称',
|
||||
colProps: {
|
||||
span: 24
|
||||
},
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: 'dict_type',
|
||||
label: '字典类型',
|
||||
colProps: {
|
||||
span: 24
|
||||
},
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: 'disabled',
|
||||
label: '是否禁用',
|
||||
colProps: {
|
||||
span: 24
|
||||
},
|
||||
component: 'Radio',
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '100%'
|
||||
},
|
||||
options: [
|
||||
{
|
||||
label: '启用',
|
||||
value: false
|
||||
},
|
||||
{
|
||||
label: '禁用',
|
||||
value: true
|
||||
}
|
||||
]
|
||||
},
|
||||
value: false
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
label: '备注',
|
||||
colProps: {
|
||||
span: 24
|
||||
},
|
||||
component: 'Input'
|
||||
}
|
||||
])
|
@ -0,0 +1,84 @@
|
||||
import { reactive } from 'vue'
|
||||
|
||||
export const columns = reactive<TableColumn[]>([
|
||||
{
|
||||
field: 'id',
|
||||
label: '字典编号'
|
||||
},
|
||||
{
|
||||
field: 'dict_name',
|
||||
label: '字典名称'
|
||||
},
|
||||
{
|
||||
field: 'dict_type',
|
||||
label: '字典类型'
|
||||
},
|
||||
{
|
||||
field: 'disabled',
|
||||
label: '是否禁用'
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
label: '备注'
|
||||
},
|
||||
{
|
||||
field: 'create_datetime',
|
||||
label: '创建时间'
|
||||
},
|
||||
{
|
||||
field: 'action',
|
||||
width: '260px',
|
||||
label: '操作'
|
||||
}
|
||||
])
|
||||
|
||||
export const schema = reactive<FormSchema[]>([
|
||||
{
|
||||
field: 'dict_name',
|
||||
label: '字典名称',
|
||||
colProps: {
|
||||
span: 24
|
||||
},
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: 'dict_type',
|
||||
label: '字典类型',
|
||||
colProps: {
|
||||
span: 24
|
||||
},
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: 'disabled',
|
||||
label: '是否禁用',
|
||||
colProps: {
|
||||
span: 24
|
||||
},
|
||||
component: 'Radio',
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '100%'
|
||||
},
|
||||
options: [
|
||||
{
|
||||
label: '启用',
|
||||
value: false
|
||||
},
|
||||
{
|
||||
label: '禁用',
|
||||
value: true
|
||||
}
|
||||
]
|
||||
},
|
||||
value: false
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
label: '备注',
|
||||
colProps: {
|
||||
span: 24
|
||||
},
|
||||
component: 'Input'
|
||||
}
|
||||
])
|
135
kinit-admin/src/views/vadmin/system/dict/detail.vue
Normal file
135
kinit-admin/src/views/vadmin/system/dict/detail.vue
Normal file
@ -0,0 +1,135 @@
|
||||
<script setup lang="ts">
|
||||
import { ContentWrap } from '@/components/ContentWrap'
|
||||
import { Table } from '@/components/Table'
|
||||
import {
|
||||
getDictDetailsListApi,
|
||||
addDictDetailsListApi,
|
||||
delDictDetailsListApi,
|
||||
putDictDetailsListApi,
|
||||
getDictDetailsApi
|
||||
} from '@/api/vadmin/system/dict'
|
||||
import { useTable } from '@/hooks/web/useTable'
|
||||
import { columns } from './components/detail.data'
|
||||
import { ref, unref } from 'vue'
|
||||
import Write from './components/Write.vue'
|
||||
import { Dialog } from '@/components/Dialog'
|
||||
import { ElButton, ElMessage } from 'element-plus'
|
||||
import { useI18n } from '@/hooks/web/useI18n'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { register, tableObject, methods } = useTable({
|
||||
getListApi: getDictDetailsListApi,
|
||||
delListApi: delDictDetailsListApi,
|
||||
response: {
|
||||
data: 'data',
|
||||
count: 'count'
|
||||
},
|
||||
props: {
|
||||
columns
|
||||
}
|
||||
})
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('')
|
||||
const actionType = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
// 添加事件
|
||||
const AddAction = () => {
|
||||
dialogTitle.value = t('exampleDemo.add')
|
||||
tableObject.currentRow = null
|
||||
dialogVisible.value = true
|
||||
actionType.value = 'add'
|
||||
}
|
||||
|
||||
// 编辑事件
|
||||
const updateAction = async (row: any) => {
|
||||
const res = await getDictDetailsApi(row.id)
|
||||
dialogTitle.value = '编辑'
|
||||
tableObject.currentRow = res.data
|
||||
dialogVisible.value = true
|
||||
actionType.value = 'edit'
|
||||
}
|
||||
|
||||
// 删除事件
|
||||
const delData = async (row: any) => {
|
||||
tableObject.currentRow = row
|
||||
const { delListApi } = methods
|
||||
loading.value = true
|
||||
await delListApi([row.id], false).finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
const writeRef = ref<ComponentRef<typeof Write>>()
|
||||
|
||||
const save = async () => {
|
||||
const write = unref(writeRef)
|
||||
await write?.elFormRef?.validate(async (isValid) => {
|
||||
if (isValid) {
|
||||
loading.value = true
|
||||
let data = await write?.getFormData()
|
||||
if (!data) {
|
||||
loading.value = false
|
||||
return ElMessage.error('未获取到数据')
|
||||
}
|
||||
const res = ref({})
|
||||
if (actionType.value === 'add') {
|
||||
res.value = await addDictDetailsListApi(data)
|
||||
} else if (actionType.value === 'edit') {
|
||||
res.value = await putDictDetailsListApi(data)
|
||||
}
|
||||
if (res.value) {
|
||||
dialogVisible.value = false
|
||||
getList()
|
||||
}
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const { getList } = methods
|
||||
|
||||
getList()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ContentWrap>
|
||||
<div class="mb-10px">
|
||||
<ElButton type="primary" @click="AddAction">{{ t('exampleDemo.add') }}</ElButton>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
v-model:limit="tableObject.limit"
|
||||
v-model:page="tableObject.page"
|
||||
:data="tableObject.tableData"
|
||||
:loading="tableObject.loading"
|
||||
:selection="false"
|
||||
:pagination="{
|
||||
total: tableObject.count
|
||||
}"
|
||||
@register="register"
|
||||
>
|
||||
<template #action="{ row }">
|
||||
<ElButton type="primary" text size="small" @click="updateAction(row)">
|
||||
{{ t('exampleDemo.edit') }}
|
||||
</ElButton>
|
||||
<ElButton type="danger" text size="small" @click="delData(row)">
|
||||
{{ t('exampleDemo.del') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</Table>
|
||||
|
||||
<Dialog v-model="dialogVisible" :title="dialogTitle" width="700px">
|
||||
<Write ref="writeRef" :current-row="tableObject.currentRow" />
|
||||
|
||||
<template #footer>
|
||||
<ElButton type="primary" :loading="loading" @click="save">
|
||||
{{ t('exampleDemo.save') }}
|
||||
</ElButton>
|
||||
<ElButton @click="dialogVisible = false">{{ t('dialogDemo.close') }}</ElButton>
|
||||
</template>
|
||||
</Dialog>
|
||||
</ContentWrap>
|
||||
</template>
|
135
kinit-admin/src/views/vadmin/system/dict/index.vue
Normal file
135
kinit-admin/src/views/vadmin/system/dict/index.vue
Normal file
@ -0,0 +1,135 @@
|
||||
<script setup lang="ts">
|
||||
import { ContentWrap } from '@/components/ContentWrap'
|
||||
import { Table } from '@/components/Table'
|
||||
import {
|
||||
getDictTypeListApi,
|
||||
addDictTypeListApi,
|
||||
delDictTypeListApi,
|
||||
putDictTypeListApi,
|
||||
getDictTypeApi
|
||||
} from '@/api/vadmin/system/dict'
|
||||
import { useTable } from '@/hooks/web/useTable'
|
||||
import { columns } from './components/dict.data'
|
||||
import { ref, unref } from 'vue'
|
||||
import Write from './components/Write.vue'
|
||||
import { Dialog } from '@/components/Dialog'
|
||||
import { ElButton, ElMessage } from 'element-plus'
|
||||
import { useI18n } from '@/hooks/web/useI18n'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { register, tableObject, methods } = useTable({
|
||||
getListApi: getDictTypeListApi,
|
||||
delListApi: delDictTypeListApi,
|
||||
response: {
|
||||
data: 'data',
|
||||
count: 'count'
|
||||
},
|
||||
props: {
|
||||
columns
|
||||
}
|
||||
})
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('')
|
||||
const actionType = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
// 添加事件
|
||||
const AddAction = () => {
|
||||
dialogTitle.value = t('exampleDemo.add')
|
||||
tableObject.currentRow = null
|
||||
dialogVisible.value = true
|
||||
actionType.value = 'add'
|
||||
}
|
||||
|
||||
// 编辑事件
|
||||
const updateAction = async (row: any) => {
|
||||
const res = await getDictTypeApi(row.id)
|
||||
dialogTitle.value = '编辑'
|
||||
tableObject.currentRow = res.data
|
||||
dialogVisible.value = true
|
||||
actionType.value = 'edit'
|
||||
}
|
||||
|
||||
// 删除事件
|
||||
const delData = async (row: any) => {
|
||||
tableObject.currentRow = row
|
||||
const { delListApi } = methods
|
||||
loading.value = true
|
||||
await delListApi([row.id], false).finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
const writeRef = ref<ComponentRef<typeof Write>>()
|
||||
|
||||
const save = async () => {
|
||||
const write = unref(writeRef)
|
||||
await write?.elFormRef?.validate(async (isValid) => {
|
||||
if (isValid) {
|
||||
loading.value = true
|
||||
let data = await write?.getFormData()
|
||||
if (!data) {
|
||||
loading.value = false
|
||||
return ElMessage.error('未获取到数据')
|
||||
}
|
||||
const res = ref({})
|
||||
if (actionType.value === 'add') {
|
||||
res.value = await addDictTypeListApi(data)
|
||||
} else if (actionType.value === 'edit') {
|
||||
res.value = await putDictTypeListApi(data)
|
||||
}
|
||||
if (res.value) {
|
||||
dialogVisible.value = false
|
||||
getList()
|
||||
}
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const { getList } = methods
|
||||
|
||||
getList()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ContentWrap>
|
||||
<div class="mb-10px">
|
||||
<ElButton type="primary" @click="AddAction">{{ t('exampleDemo.add') }}</ElButton>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
v-model:limit="tableObject.limit"
|
||||
v-model:page="tableObject.page"
|
||||
:data="tableObject.tableData"
|
||||
:loading="tableObject.loading"
|
||||
:selection="false"
|
||||
:pagination="{
|
||||
total: tableObject.count
|
||||
}"
|
||||
@register="register"
|
||||
>
|
||||
<template #action="{ row }">
|
||||
<ElButton type="primary" text size="small" @click="updateAction(row)">
|
||||
{{ t('exampleDemo.edit') }}
|
||||
</ElButton>
|
||||
<ElButton type="danger" text size="small" @click="delData(row)">
|
||||
{{ t('exampleDemo.del') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</Table>
|
||||
|
||||
<Dialog v-model="dialogVisible" :title="dialogTitle" width="700px">
|
||||
<Write ref="writeRef" :current-row="tableObject.currentRow" />
|
||||
|
||||
<template #footer>
|
||||
<ElButton type="primary" :loading="loading" @click="save">
|
||||
{{ t('exampleDemo.save') }}
|
||||
</ElButton>
|
||||
<ElButton @click="dialogVisible = false">{{ t('dialogDemo.close') }}</ElButton>
|
||||
</template>
|
||||
</Dialog>
|
||||
</ContentWrap>
|
||||
</template>
|
38
kinit-api/alembic/versions/1d13c64e1444_update.py
Normal file
38
kinit-api/alembic/versions/1d13c64e1444_update.py
Normal file
@ -0,0 +1,38 @@
|
||||
"""update
|
||||
|
||||
Revision ID: 1d13c64e1444
|
||||
Revises: ab5fb033599e
|
||||
Create Date: 2022-10-05 21:17:42.029110
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '1d13c64e1444'
|
||||
down_revision = 'ab5fb033599e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('vadmin_system_dict_details', sa.Column('disabled', sa.Boolean(), nullable=True, comment='字典状态,是否禁用'))
|
||||
op.add_column('vadmin_system_dict_details', sa.Column('order', sa.Integer(), nullable=True, comment='字典排序'))
|
||||
op.drop_column('vadmin_system_dict_details', 'status')
|
||||
op.drop_column('vadmin_system_dict_details', 'sort')
|
||||
op.add_column('vadmin_system_dict_type', sa.Column('disabled', sa.Boolean(), nullable=True, comment='字典状态,是否禁用'))
|
||||
op.drop_column('vadmin_system_dict_type', 'status')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('vadmin_system_dict_type', sa.Column('status', mysql.TINYINT(display_width=1), autoincrement=False, nullable=True, comment='字典状态,是否可用'))
|
||||
op.drop_column('vadmin_system_dict_type', 'disabled')
|
||||
op.add_column('vadmin_system_dict_details', sa.Column('sort', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True, comment='字典排序'))
|
||||
op.add_column('vadmin_system_dict_details', sa.Column('status', mysql.TINYINT(display_width=1), autoincrement=False, nullable=True, comment='字典状态,是否可用'))
|
||||
op.drop_column('vadmin_system_dict_details', 'order')
|
||||
op.drop_column('vadmin_system_dict_details', 'disabled')
|
||||
# ### end Alembic commands ###
|
42
kinit-api/alembic/versions/203b11efd025_update.py
Normal file
42
kinit-api/alembic/versions/203b11efd025_update.py
Normal file
@ -0,0 +1,42 @@
|
||||
"""update
|
||||
|
||||
Revision ID: 203b11efd025
|
||||
Revises: 1d13c64e1444
|
||||
Create Date: 2022-10-05 21:43:34.894121
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '203b11efd025'
|
||||
down_revision = '1d13c64e1444'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('vadmin_system_dict_details', sa.Column('label', sa.String(length=50), nullable=False, comment='字典标签'))
|
||||
op.add_column('vadmin_system_dict_details', sa.Column('value', sa.String(length=50), nullable=False, comment='字典键值'))
|
||||
op.drop_index('ix_vadmin_system_dict_details_dict_label', table_name='vadmin_system_dict_details')
|
||||
op.drop_index('ix_vadmin_system_dict_details_dict_value', table_name='vadmin_system_dict_details')
|
||||
op.create_index(op.f('ix_vadmin_system_dict_details_label'), 'vadmin_system_dict_details', ['label'], unique=False)
|
||||
op.create_index(op.f('ix_vadmin_system_dict_details_value'), 'vadmin_system_dict_details', ['value'], unique=False)
|
||||
op.drop_column('vadmin_system_dict_details', 'dict_label')
|
||||
op.drop_column('vadmin_system_dict_details', 'dict_value')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('vadmin_system_dict_details', sa.Column('dict_value', mysql.VARCHAR(length=50), nullable=False, comment='字典键值'))
|
||||
op.add_column('vadmin_system_dict_details', sa.Column('dict_label', mysql.VARCHAR(length=50), nullable=False, comment='字典标签'))
|
||||
op.drop_index(op.f('ix_vadmin_system_dict_details_value'), table_name='vadmin_system_dict_details')
|
||||
op.drop_index(op.f('ix_vadmin_system_dict_details_label'), table_name='vadmin_system_dict_details')
|
||||
op.create_index('ix_vadmin_system_dict_details_dict_value', 'vadmin_system_dict_details', ['dict_value'], unique=False)
|
||||
op.create_index('ix_vadmin_system_dict_details_dict_label', 'vadmin_system_dict_details', ['dict_label'], unique=False)
|
||||
op.drop_column('vadmin_system_dict_details', 'value')
|
||||
op.drop_column('vadmin_system_dict_details', 'label')
|
||||
# ### end Alembic commands ###
|
@ -26,9 +26,12 @@ class UserDal(DalBase):
|
||||
"""
|
||||
password = data.telephone[5:12] if settings.DEFAULT_PASSWORD == "0" else settings.DEFAULT_PASSWORD
|
||||
data.password = self.model.get_password_hash(password)
|
||||
obj = await super(UserDal, self).create_data(data.dict(exclude={"role_ids"}), True, options, schema)
|
||||
obj = self.model(**data.dict(exclude={'role_ids'}))
|
||||
for data_id in data.role_ids:
|
||||
obj.roles.append(await RoleDal(db=self.db).get_data(data_id=data_id))
|
||||
self.db.add(obj)
|
||||
await self.db.flush()
|
||||
await self.db.refresh(obj)
|
||||
if options:
|
||||
obj = await self.get_data(obj.id, options=options)
|
||||
if return_obj:
|
||||
|
@ -17,8 +17,8 @@ from core.validator import ValiDatetime
|
||||
class Menu(BaseModel):
|
||||
title: str
|
||||
icon: Optional[str] = None
|
||||
component: str
|
||||
path: str
|
||||
component: Optional[str] = None
|
||||
path: Optional[str] = None
|
||||
disabled: bool = False
|
||||
hidden: bool = False
|
||||
order: Optional[int] = None
|
||||
|
@ -42,6 +42,14 @@ async def put_user(data_id: int, data: schemas.User, auth: Auth = Depends(login_
|
||||
return SuccessResponse(await crud.UserDal(auth.db).put_data(data_id, data))
|
||||
|
||||
|
||||
@app.get("/users/{data_id}/", summary="获取用户信息")
|
||||
async def get_user(data_id: int, auth: Auth = Depends(login_auth)):
|
||||
model = models.VadminUser
|
||||
options = [model.roles]
|
||||
schema = schemas.UserOut
|
||||
return SuccessResponse(await crud.UserDal(auth.db).get_data(data_id, options, schema))
|
||||
|
||||
|
||||
###########################################################
|
||||
# 角色管理
|
||||
###########################################################
|
||||
|
@ -17,7 +17,7 @@ class VadminDictType(BaseModel):
|
||||
|
||||
dict_name = Column(String(50), index=True, nullable=False, comment="字典名称")
|
||||
dict_type = Column(String(50), index=True, nullable=False, comment="字典类型")
|
||||
status = Column(Boolean, default=True, comment="字典状态,是否可用")
|
||||
disabled = Column(Boolean, default=False, comment="字典状态,是否禁用")
|
||||
remark = Column(String(255), comment="备注")
|
||||
details = relationship("VadminDictDetails", back_populates="dict_type")
|
||||
|
||||
@ -26,11 +26,11 @@ class VadminDictDetails(BaseModel):
|
||||
__tablename__ = "vadmin_system_dict_details"
|
||||
__table_args__ = ({'comment': '字典详情表'})
|
||||
|
||||
dict_label = Column(String(50), index=True, nullable=False, comment="字典标签")
|
||||
dict_value = Column(String(50), index=True, nullable=False, comment="字典键值")
|
||||
status = Column(Boolean, default=True, comment="字典状态,是否可用")
|
||||
label = Column(String(50), index=True, nullable=False, comment="字典标签")
|
||||
value = Column(String(50), index=True, nullable=False, comment="字典键值")
|
||||
disabled = Column(Boolean, default=False, comment="字典状态,是否禁用")
|
||||
is_default = Column(Boolean, default=False, comment="是否默认")
|
||||
sort = Column(Integer, comment="字典排序")
|
||||
order = Column(Integer, comment="字典排序")
|
||||
dict_type_id = Column(Integer, ForeignKey("vadmin_system_dict_type.id", ondelete='CASCADE'), comment="关联字典类型")
|
||||
dict_type = relationship("VadminDictType", foreign_keys=dict_type_id, back_populates="details")
|
||||
remark = Column(String(255), comment="备注")
|
||||
|
@ -17,7 +17,7 @@ from core.validator import ValiDatetime
|
||||
class DictType(BaseModel):
|
||||
dict_name: str
|
||||
dict_type: str
|
||||
status: Optional[bool] = True
|
||||
disabled: Optional[bool] = False
|
||||
remark: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
@ -26,7 +26,7 @@ class DictType(BaseModel):
|
||||
"example": {
|
||||
"dict_name": "用户性别",
|
||||
"dict_type": "sys_user_sex",
|
||||
"status": True,
|
||||
"disabled": False,
|
||||
"remark": "性别选择"
|
||||
}
|
||||
}
|
||||
@ -42,12 +42,12 @@ class DictTypeSimpleOut(DictType):
|
||||
|
||||
|
||||
class DictDetails(BaseModel):
|
||||
dict_label: str
|
||||
dict_value: str
|
||||
status: Optional[bool] = True
|
||||
label: str
|
||||
value: str
|
||||
disabled: Optional[bool] = False
|
||||
is_default: Optional[bool] = False
|
||||
remark: Optional[str] = None
|
||||
sort: Optional[str] = None
|
||||
order: Optional[str] = None
|
||||
dict_data: int
|
||||
|
||||
|
||||
|
@ -18,7 +18,7 @@ app = APIRouter()
|
||||
###########################################################
|
||||
# 字典类型管理
|
||||
###########################################################
|
||||
@app.get("/dictTypes/", summary="获取字典类型列表")
|
||||
@app.get("/dict/types/", summary="获取字典类型列表")
|
||||
async def get_dict_types(params: Params = Depends(paging), auth: Auth = Depends(login_auth),
|
||||
dict_name: Optional[str] = Query(None, title="字典名称", description="查询字典名称")):
|
||||
datas = await crud.DictTypeDal(auth.db).get_datas(params.page, params.limit, dict_name=dict_name)
|
||||
@ -26,35 +26,35 @@ async def get_dict_types(params: Params = Depends(paging), auth: Auth = Depends(
|
||||
return SuccessResponse(datas, count=count)
|
||||
|
||||
|
||||
@app.post("/dictTypes/", summary="创建字典类型")
|
||||
@app.post("/dict/types/", summary="创建字典类型")
|
||||
async def create_dict_types(data: schemas.DictType, auth: Auth = Depends(login_auth)):
|
||||
return SuccessResponse(await crud.DictTypeDal(auth.db).create_data(data=data))
|
||||
|
||||
|
||||
@app.delete("/dictTypes/", summary="批量删除字典类型")
|
||||
@app.delete("/dict/types/", summary="批量删除字典类型")
|
||||
async def delete_dict_types(ids: list = Depends(id_list), auth: Auth = Depends(login_auth)):
|
||||
await crud.DictTypeDal(auth.db).delete_datas(ids=ids)
|
||||
return SuccessResponse("删除成功")
|
||||
|
||||
|
||||
@app.put("/dictTypes/{data_id}/", summary="更新字典类型")
|
||||
async def put_dict_types(data_id: int, data: schemas.DictType, auth: Auth = Depends(login_auth)):
|
||||
return SuccessResponse(await crud.DictTypeDal(auth.db).put_data(data_id, data))
|
||||
|
||||
|
||||
@app.get("/dictTypes/{data_id}/", summary="获取字典类型详细")
|
||||
async def get_dict_type(data_id: int, auth: Auth = Depends(login_auth)):
|
||||
schema = schemas.DictTypeSimpleOut
|
||||
return SuccessResponse(await crud.DictTypeDal(auth.db).get_data(data_id, None, schema))
|
||||
|
||||
|
||||
@app.post("/dictTypes/details/", summary="获取多个字典类型下的字典元素列表")
|
||||
@app.post("/dict/types/details/", summary="获取多个字典类型下的字典元素列表")
|
||||
async def post_dicts_details(auth: Auth = Depends(login_auth),
|
||||
dict_types: List[str] = Body(None, title="字典元素列表", description="查询字典元素列表")):
|
||||
datas = await crud.DictTypeDal(auth.db).get_dicts_details(dict_types)
|
||||
return SuccessResponse(datas)
|
||||
|
||||
|
||||
@app.put("/dict/types/{data_id}/", summary="更新字典类型")
|
||||
async def put_dict_types(data_id: int, data: schemas.DictType, auth: Auth = Depends(login_auth)):
|
||||
return SuccessResponse(await crud.DictTypeDal(auth.db).put_data(data_id, data))
|
||||
|
||||
|
||||
@app.get("/dict/types/{data_id}/", summary="获取字典类型详细")
|
||||
async def get_dict_type(data_id: int, auth: Auth = Depends(login_auth)):
|
||||
schema = schemas.DictTypeSimpleOut
|
||||
return SuccessResponse(await crud.DictTypeDal(auth.db).get_data(data_id, None, schema))
|
||||
|
||||
|
||||
###########################################################
|
||||
# 字典元素管理
|
||||
###########################################################
|
||||
|
Loading…
x
Reference in New Issue
Block a user