mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-04-05 12:44:27 +08:00
fix: remove DemoList
type
This commit is contained in:
parent
f20d2a5fb6
commit
efc1ccbc9a
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "nova-admin",
|
"name": "nova-admin",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.9.7",
|
"version": "0.9.8",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "a clean and concise back-end management template based on Vue3, Vite5, Typescript, and Naive UI.",
|
"description": "a clean and concise back-end management template based on Vue3, Vite5, Typescript, and Naive UI.",
|
||||||
"author": {
|
"author": {
|
||||||
|
15
src/typings/entities/demoList.d.ts
vendored
15
src/typings/entities/demoList.d.ts
vendored
@ -1,15 +0,0 @@
|
|||||||
/// <reference path="../global.d.ts"/>
|
|
||||||
|
|
||||||
/* 角色数据库表字段 */
|
|
||||||
namespace Entity {
|
|
||||||
interface DemoList {
|
|
||||||
id: number
|
|
||||||
name: string
|
|
||||||
age: number
|
|
||||||
gender: '0' | '1' | null
|
|
||||||
email: string
|
|
||||||
address: string
|
|
||||||
role: Entity.RoleType
|
|
||||||
disabled: boolean
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +1,14 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
type FormModel = Pick<Entity.DemoList, 'name' | 'age' | 'gender' | 'address' | 'email' | 'role' | 'disabled'>
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
type: 'add',
|
type: 'add',
|
||||||
modalData: null,
|
modalData: null,
|
||||||
})
|
})
|
||||||
const emit = defineEmits<Emits>()
|
const emit = defineEmits<Emits>()
|
||||||
const defaultFormModal: FormModel = {
|
const defaultFormModal: Entity.User = {
|
||||||
name: '',
|
userName: '',
|
||||||
age: 0,
|
gender: 0,
|
||||||
gender: null,
|
|
||||||
email: '',
|
email: '',
|
||||||
address: '',
|
role: [],
|
||||||
role: 'user',
|
|
||||||
disabled: true,
|
|
||||||
}
|
}
|
||||||
const formModel = ref({ ...defaultFormModal })
|
const formModel = ref({ ...defaultFormModal })
|
||||||
|
|
||||||
@ -81,26 +77,26 @@ watch(
|
|||||||
<n-form label-placement="left" :model="formModel" label-align="left" :label-width="80">
|
<n-form label-placement="left" :model="formModel" label-align="left" :label-width="80">
|
||||||
<n-grid :cols="24" :x-gap="18">
|
<n-grid :cols="24" :x-gap="18">
|
||||||
<n-form-item-grid-item :span="12" label="用户名" path="name">
|
<n-form-item-grid-item :span="12" label="用户名" path="name">
|
||||||
<n-input v-model:value="formModel.name" />
|
<n-input v-model:value="formModel.userName" />
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item :span="12" label="年龄" path="age">
|
<n-form-item-grid-item :span="12" label="年龄" path="age">
|
||||||
<n-input-number v-model:value="formModel.age" />
|
<n-input-number v-model:value="formModel.gender" />
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item :span="12" label="性别" path="gender">
|
<n-form-item-grid-item :span="12" label="性别" path="gender">
|
||||||
<n-input v-model:value="formModel.gender" />
|
<n-radio-group v-model:value="formModel.gender">
|
||||||
|
<n-space>
|
||||||
|
<n-radio :value="1">
|
||||||
|
男
|
||||||
|
</n-radio>
|
||||||
|
<n-radio :value="0">
|
||||||
|
女
|
||||||
|
</n-radio>
|
||||||
|
</n-space>
|
||||||
|
</n-radio-group>
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item :span="12" label="邮箱" path="email">
|
<n-form-item-grid-item :span="12" label="邮箱" path="email">
|
||||||
<n-input v-model:value="formModel.email" />
|
<n-input v-model:value="formModel.email" />
|
||||||
</n-form-item-grid-item>
|
</n-form-item-grid-item>
|
||||||
<n-form-item-grid-item :span="12" label="地址" path="address">
|
|
||||||
<n-input v-model:value="formModel.address" />
|
|
||||||
</n-form-item-grid-item>
|
|
||||||
<n-form-item-grid-item :span="12" label="角色" path="role">
|
|
||||||
<n-input v-model:value="formModel.role" />
|
|
||||||
</n-form-item-grid-item>
|
|
||||||
<n-form-item-grid-item :span="12" label="状态" path="disabled">
|
|
||||||
<n-switch v-model:value="formModel.disabled" />
|
|
||||||
</n-form-item-grid-item>
|
|
||||||
</n-grid>
|
</n-grid>
|
||||||
</n-form>
|
</n-form>
|
||||||
<template #action>
|
<template #action>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import type { DataTableColumns, FormInst } from 'naive-ui'
|
import type { DataTableColumns, FormInst } from 'naive-ui'
|
||||||
import { NButton, NPopconfirm, NSpace, NSwitch, NTag } from 'naive-ui'
|
import { NButton, NPopconfirm, NSpace, NSwitch, NTag } from 'naive-ui'
|
||||||
import TableModal from './components/TableModal.vue'
|
import TableModal from './components/TableModal.vue'
|
||||||
import { fetchUserList } from '@/service'
|
import { fetchUserPage } from '@/service'
|
||||||
import { useBoolean } from '@/hooks'
|
import { useBoolean } from '@/hooks'
|
||||||
import { Gender } from '@/constants'
|
import { Gender } from '@/constants'
|
||||||
|
|
||||||
@ -18,14 +18,14 @@ const initialModel = {
|
|||||||
const model = ref({ ...initialModel })
|
const model = ref({ ...initialModel })
|
||||||
|
|
||||||
const formRef = ref<FormInst | null>()
|
const formRef = ref<FormInst | null>()
|
||||||
function sendMail(id: number) {
|
function sendMail(id?: number) {
|
||||||
window.$message.success(`删除用户id:${id}`)
|
window.$message.success(`删除用户id:${id}`)
|
||||||
}
|
}
|
||||||
const columns: DataTableColumns<Entity.DemoList> = [
|
const columns: DataTableColumns<Entity.User> = [
|
||||||
{
|
{
|
||||||
title: '姓名',
|
title: '姓名',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
key: 'name',
|
key: 'userName',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '年龄',
|
title: '年龄',
|
||||||
@ -55,34 +55,18 @@ const columns: DataTableColumns<Entity.DemoList> = [
|
|||||||
align: 'center',
|
align: 'center',
|
||||||
key: 'email',
|
key: 'email',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: '地址',
|
|
||||||
align: 'center',
|
|
||||||
key: 'address',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '角色',
|
|
||||||
align: 'center',
|
|
||||||
key: 'role',
|
|
||||||
render: (row) => {
|
|
||||||
const tagType: Record<Entity.RoleType, NaiveUI.ThemeColor> = {
|
|
||||||
super: 'primary',
|
|
||||||
admin: 'warning',
|
|
||||||
user: 'success',
|
|
||||||
}
|
|
||||||
return <NTag type={tagType[row.role]}>{row.role}</NTag>
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: '状态',
|
title: '状态',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
key: 'disabled',
|
key: 'status',
|
||||||
render: (row) => {
|
render: (row) => {
|
||||||
return (
|
return (
|
||||||
<NSwitch
|
<NSwitch
|
||||||
value={row.disabled}
|
value={row.status}
|
||||||
onUpdateValue={(value: boolean) =>
|
checked-value={1}
|
||||||
handleUpdateDisabled(value, row.id)}
|
unchecked-value={0}
|
||||||
|
onUpdateValue={(value: 0 | 1) =>
|
||||||
|
handleUpdateDisabled(value, row.id!)}
|
||||||
>
|
>
|
||||||
{{ checked: () => '启用', unchecked: () => '禁用' }}
|
{{ checked: () => '启用', unchecked: () => '禁用' }}
|
||||||
</NSwitch>
|
</NSwitch>
|
||||||
@ -114,11 +98,11 @@ const columns: DataTableColumns<Entity.DemoList> = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const listData = ref<Entity.DemoList[]>([])
|
const listData = ref<Entity.User[]>([])
|
||||||
function handleUpdateDisabled(disabled: boolean, id: number) {
|
function handleUpdateDisabled(value: 0 | 1, id: number) {
|
||||||
const index = listData.value.findIndex(item => item.id === id)
|
const index = listData.value.findIndex(item => item.id === id)
|
||||||
if (index > -1)
|
if (index > -1)
|
||||||
listData.value[index].disabled = disabled
|
listData.value[index].status = value
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@ -126,7 +110,7 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
async function getUserList() {
|
async function getUserList() {
|
||||||
startLoading()
|
startLoading()
|
||||||
await fetchUserList().then((res: any) => {
|
await fetchUserPage().then((res: any) => {
|
||||||
listData.value = res.data.list
|
listData.value = res.data.list
|
||||||
endLoading()
|
endLoading()
|
||||||
})
|
})
|
||||||
@ -144,12 +128,12 @@ function setModalType(type: ModalType) {
|
|||||||
modalType.value = type
|
modalType.value = type
|
||||||
}
|
}
|
||||||
|
|
||||||
const editData = ref<Entity.DemoList | null>(null)
|
const editData = ref<Entity.User | null>(null)
|
||||||
function setEditData(data: Entity.DemoList | null) {
|
function setEditData(data: Entity.User | null) {
|
||||||
editData.value = data
|
editData.value = data
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleEditTable(row: Entity.DemoList) {
|
function handleEditTable(row: Entity.User) {
|
||||||
setEditData(row)
|
setEditData(row)
|
||||||
setModalType('edit')
|
setModalType('edit')
|
||||||
openModal()
|
openModal()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user