Skip to content

Commit

Permalink
fix: remove DemoList type
Browse files Browse the repository at this point in the history
  • Loading branch information
chansee97 committed Aug 20, 2024
1 parent f20d2a5 commit efc1ccb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 69 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nova-admin",
"type": "module",
"version": "0.9.7",
"version": "0.9.8",
"private": true,
"description": "a clean and concise back-end management template based on Vue3, Vite5, Typescript, and Naive UI.",
"author": {
Expand Down
15 changes: 0 additions & 15 deletions src/typings/entities/demoList.d.ts

This file was deleted.

36 changes: 16 additions & 20 deletions src/views/list/commonList/components/TableModal.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<script setup lang="ts">
type FormModel = Pick<Entity.DemoList, 'name' | 'age' | 'gender' | 'address' | 'email' | 'role' | 'disabled'>
const props = withDefaults(defineProps<Props>(), {
type: 'add',
modalData: null,
})
const emit = defineEmits<Emits>()
const defaultFormModal: FormModel = {
name: '',
age: 0,
gender: null,
const defaultFormModal: Entity.User = {
userName: '',
gender: 0,
email: '',
address: '',
role: 'user',
disabled: true,
role: [],
}
const formModel = ref({ ...defaultFormModal })
Expand Down Expand Up @@ -81,26 +77,26 @@ watch(
<n-form label-placement="left" :model="formModel" label-align="left" :label-width="80">
<n-grid :cols="24" :x-gap="18">
<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 :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 :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 :span="12" label="邮箱" path="email">
<n-input v-model:value="formModel.email" />
</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-form>
<template #action>
Expand Down
50 changes: 17 additions & 33 deletions src/views/list/commonList/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { DataTableColumns, FormInst } from 'naive-ui'
import { NButton, NPopconfirm, NSpace, NSwitch, NTag } from 'naive-ui'
import TableModal from './components/TableModal.vue'
import { fetchUserList } from '@/service'
import { fetchUserPage } from '@/service'
import { useBoolean } from '@/hooks'
import { Gender } from '@/constants'
Expand All @@ -18,14 +18,14 @@ const initialModel = {
const model = ref({ ...initialModel })
const formRef = ref<FormInst | null>()
function sendMail(id: number) {
function sendMail(id?: number) {
window.$message.success(`删除用户id:${id}`)
}
const columns: DataTableColumns<Entity.DemoList> = [
const columns: DataTableColumns<Entity.User> = [
{
title: '姓名',
align: 'center',
key: 'name',
key: 'userName',
},
{
title: '年龄',
Expand Down Expand Up @@ -55,34 +55,18 @@ const columns: DataTableColumns<Entity.DemoList> = [
align: 'center',
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: '状态',
align: 'center',
key: 'disabled',
key: 'status',
render: (row) => {
return (
<NSwitch
value={row.disabled}
onUpdateValue={(value: boolean) =>
handleUpdateDisabled(value, row.id)}
value={row.status}
checked-value={1}
unchecked-value={0}
onUpdateValue={(value: 0 | 1) =>
handleUpdateDisabled(value, row.id!)}
>
{{ checked: () => '启用', unchecked: () => '禁用' }}
</NSwitch>
Expand Down Expand Up @@ -114,19 +98,19 @@ const columns: DataTableColumns<Entity.DemoList> = [
},
]
const listData = ref<Entity.DemoList[]>([])
function handleUpdateDisabled(disabled: boolean, id: number) {
const listData = ref<Entity.User[]>([])
function handleUpdateDisabled(value: 0 | 1, id: number) {
const index = listData.value.findIndex(item => item.id === id)
if (index > -1)
listData.value[index].disabled = disabled
listData.value[index].status = value
}
onMounted(() => {
getUserList()
})
async function getUserList() {
startLoading()
await fetchUserList().then((res: any) => {
await fetchUserPage().then((res: any) => {
listData.value = res.data.list
endLoading()
})
Expand All @@ -144,12 +128,12 @@ function setModalType(type: ModalType) {
modalType.value = type
}
const editData = ref<Entity.DemoList | null>(null)
function setEditData(data: Entity.DemoList | null) {
const editData = ref<Entity.User | null>(null)
function setEditData(data: Entity.User | null) {
editData.value = data
}
function handleEditTable(row: Entity.DemoList) {
function handleEditTable(row: Entity.User) {
setEditData(row)
setModalType('edit')
openModal()
Expand Down

0 comments on commit efc1ccb

Please sign in to comment.