From 3933947446a45a2027e97e6df5f0b0e94f32ddbd Mon Sep 17 00:00:00 2001
From: "chen.home" <1147347984@qq.com>
Date: Tue, 30 Aug 2022 00:39:35 +0800
Subject: [PATCH] =?UTF-8?q?feat(components):=20=E5=A2=9E=E5=8A=A0=E5=88=97?=
=?UTF-8?q?=E8=A1=A8=E5=BC=B9=E5=87=BA=E8=A1=A8=E5=8D=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/typings/business.d.ts | 13 ++
.../list/commonList/components/TableModal.vue | 121 ++++++++++++++++++
src/views/list/commonList/index.vue | 51 +++++---
3 files changed, 167 insertions(+), 18 deletions(-)
create mode 100644 src/views/list/commonList/components/TableModal.vue
diff --git a/src/typings/business.d.ts b/src/typings/business.d.ts
index 5647940..4d31cc9 100644
--- a/src/typings/business.d.ts
+++ b/src/typings/business.d.ts
@@ -47,3 +47,16 @@ declare namespace Message {
date: string;
}
}
+
+declare namespace CommonList {
+ interface UserList {
+ id: number;
+ name: string;
+ age: number;
+ gender: '0' | '1' | null;
+ email: string;
+ address: string;
+ role: 'super' | 'admin' | 'user';
+ disabled: boolean;
+ }
+}
diff --git a/src/views/list/commonList/components/TableModal.vue b/src/views/list/commonList/components/TableModal.vue
new file mode 100644
index 0000000..5df6627
--- /dev/null
+++ b/src/views/list/commonList/components/TableModal.vue
@@ -0,0 +1,121 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 取消
+ 提交
+
+
+
+
+
+
+
+
diff --git a/src/views/list/commonList/index.vue b/src/views/list/commonList/index.vue
index ab4d680..f25283f 100644
--- a/src/views/list/commonList/index.vue
+++ b/src/views/list/commonList/index.vue
@@ -33,7 +33,7 @@
-
+
新建
@@ -48,6 +48,7 @@
+
@@ -58,9 +59,11 @@ import { onMounted, ref, h } from 'vue';
import { fetchUserList } from '@/service';
import type { DataTableColumns } from 'naive-ui';
import { NButton, NPopconfirm, NSpace, NSwitch, NTag, FormInst } from 'naive-ui';
-import { useLoading } from '@/hook';
+import { useLoading, useBoolean } from '@/hook';
+import TableModal from './components/TableModal.vue';
const { loading, startLoading, endLoading } = useLoading(false);
+const { bool: visible, setTrue: openModal } = useBoolean(false);
const initialModel = { condition_1: '', condition_2: '', condition_3: '', condition_4: '' };
const model = ref({ ...initialModel });
@@ -82,7 +85,7 @@ const columns: DataTableColumns = [
align: 'center',
key: 'gender',
render: (row) => {
- const rowData = row as unknown as UserList;
+ const rowData = row as unknown as CommonList.UserList;
const tagType = {
'0': {
label: '女',
@@ -113,7 +116,7 @@ const columns: DataTableColumns = [
align: 'center',
key: 'role',
render: (row) => {
- const rowData = row as unknown as UserList;
+ const rowData = row as unknown as CommonList.UserList;
const tagType = {
super: 'primary',
admin: 'warning',
@@ -127,7 +130,7 @@ const columns: DataTableColumns = [
align: 'center',
key: 'disabled',
render: (row) => {
- const rowData = row as unknown as UserList;
+ const rowData = row as unknown as CommonList.UserList;
return (
handleUpdateDisabled(disabled, rowData.id)}>
@@ -141,10 +144,10 @@ const columns: DataTableColumns = [
align: 'center',
key: 'actions',
render: (row) => {
- const rowData = row as unknown as UserList;
+ const rowData = row as unknown as CommonList.UserList;
return (
- sendMail(rowData.id)}>
+ handleEditTable(rowData)}>
编辑
sendMail(rowData.id)}>
@@ -167,17 +170,8 @@ function handleUpdateDisabled(disabled: boolean, id: number) {
listData.value[index].disabled = disabled;
}
}
-interface UserList {
- id: number;
- name: string;
- age: number;
- gender: '0' | '1' | null;
- email: string;
- address: string;
- role: 'super' | 'admin' | 'user';
- disabled: boolean;
-}
-const listData = ref([]);
+
+const listData = ref([]);
onMounted(() => {
getUserList();
@@ -195,6 +189,27 @@ function changePage(page: number, size: number) {
function handleResetSearch() {
model.value = { ...initialModel };
}
+
+type ModalType = 'add' | 'edit';
+const modalType = ref('add');
+function setModalType(type: ModalType) {
+ modalType.value = type;
+}
+
+const editData = ref(null);
+function setEditData(data: CommonList.UserList | null) {
+ editData.value = data;
+}
+
+function handleEditTable(rowData: CommonList.UserList) {
+ setEditData(rowData);
+ setModalType('edit');
+ openModal();
+}
+function handleAddTable() {
+ openModal();
+ setModalType('add');
+}