From e64f4b83c8f6cd01ea352ad7040e205613ea87d3 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期五, 14 七月 2023 22:39:34 +0800 Subject: [PATCH] update 优化 toggleRowSelection 缺失一个参数警告问题 --- src/views/system/dept/index.vue | 192 ++++++++++++++++++++++++----------------------- 1 files changed, 97 insertions(+), 95 deletions(-) diff --git a/src/views/system/dept/index.vue b/src/views/system/dept/index.vue index 4e7750d..a1dcb9f 100644 --- a/src/views/system/dept/index.vue +++ b/src/views/system/dept/index.vue @@ -4,7 +4,7 @@ <div class="mb-[10px]" v-show="showSearch"> <el-card shadow="hover"> <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="68px"> - <el-form-item label="鑿滃崟鍚嶇О" prop="menuName"> + <el-form-item label="閮ㄩ棬鍚嶇О" prop="deptName"> <el-input v-model="queryParams.deptName" placeholder="璇疯緭鍏ラ儴闂ㄥ悕绉�" clearable @keyup.enter="handleQuery" /> </el-form-item> <el-form-item label="鐘舵��" prop="status"> @@ -132,14 +132,12 @@ <script setup name="Dept" lang="ts"> import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept" -import { ComponentInternalInstance } from 'vue'; import { DeptForm, DeptQuery, DeptVO } from "@/api/system/dept/types"; -import { ElTable, ElForm } from "element-plus"; interface DeptOptionsType { - deptId: number | string; - deptName: string; - children: DeptOptionsType[]; + deptId: number | string; + deptName: string; + children: DeptOptionsType[]; } @@ -154,142 +152,146 @@ const dialog = reactive<DialogOption>({ - visible: false, - title: '' + visible: false, + title: '' }); -const deptTableRef = ref(ElTable); -const queryFormRef = ref(ElForm); -const deptFormRef = ref(ElForm); +const deptTableRef = ref<ElTableInstance>(); +const queryFormRef = ref<ElFormInstance>(); +const deptFormRef = ref<ElFormInstance>(); const initFormData: DeptForm = { - deptId: undefined, - parentId: undefined, - deptName: undefined, - orderNum: 0, - leader: undefined, - phone: undefined, - email: undefined, - status: "0" + deptId: undefined, + parentId: undefined, + deptName: undefined, + orderNum: 0, + leader: undefined, + phone: undefined, + email: undefined, + status: "0" } const data = reactive<PageData<DeptForm, DeptQuery>>({ - form: {...initFormData}, - queryParams: { - pageNum: 1, - pageSize: 10, - deptName: undefined, - status: undefined - }, - rules: { - parentId: [{ required: true, message: "涓婄骇閮ㄩ棬涓嶈兘涓虹┖", trigger: "blur" }], - deptName: [{ required: true, message: "閮ㄩ棬鍚嶇О涓嶈兘涓虹┖", trigger: "blur" }], - orderNum: [{ required: true, message: "鏄剧ず鎺掑簭涓嶈兘涓虹┖", trigger: "blur" }], - email: [{ type: "email", message: "璇疯緭鍏ユ纭殑閭鍦板潃", trigger: ["blur", "change"] }], - phone: [{ pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "璇疯緭鍏ユ纭殑鎵嬫満鍙风爜", trigger: "blur" }] - }, + form: { ...initFormData }, + queryParams: { + pageNum: 1, + pageSize: 10, + deptName: undefined, + status: undefined + }, + rules: { + parentId: [{ required: true, message: "涓婄骇閮ㄩ棬涓嶈兘涓虹┖", trigger: "blur" }], + deptName: [{ required: true, message: "閮ㄩ棬鍚嶇О涓嶈兘涓虹┖", trigger: "blur" }], + orderNum: [{ required: true, message: "鏄剧ず鎺掑簭涓嶈兘涓虹┖", trigger: "blur" }], + email: [{ type: "email", message: "璇疯緭鍏ユ纭殑閭鍦板潃", trigger: ["blur", "change"] }], + phone: [{ pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "璇疯緭鍏ユ纭殑鎵嬫満鍙风爜", trigger: "blur" }] + }, }) const { queryParams, form, rules } = toRefs<PageData<DeptForm, DeptQuery>>(data) /** 鏌ヨ鑿滃崟鍒楄〃 */ const getList = async () => { - loading.value = true; - const res = await listDept(queryParams.value); - const data = proxy?.handleTree<DeptVO>(res.data, "deptId") - if (data) { - deptList.value = data - } - loading.value = false + loading.value = true; + const res = await listDept(queryParams.value); + const data = proxy?.handleTree<DeptVO>(res.data, "deptId") + if (data) { + deptList.value = data + } + loading.value = false } /** 鍙栨秷鎸夐挳 */ const cancel = () => { - reset() - dialog.visible = false + reset() + dialog.visible = false } /** 琛ㄥ崟閲嶇疆 */ const reset = () => { - form.value = {...initFormData}; - deptFormRef.value.resetFields(); + form.value = { ...initFormData }; + deptFormRef.value?.resetFields(); } /** 鎼滅储鎸夐挳鎿嶄綔 */ const handleQuery = () => { - getList(); + getList(); } /** 閲嶇疆鎸夐挳鎿嶄綔 */ const resetQuery = () => { - queryFormRef.value.resetFields(); - handleQuery() + queryFormRef.value?.resetFields(); + handleQuery() } /** 鏂板鎸夐挳鎿嶄綔 */ const handleAdd = (row?: DeptVO) => { - listDept().then(res => { - const data = proxy?.handleTree<DeptOptionsType>(res.data, "deptId"); - if (data) { - deptOptions.value = data - dialog.visible = true; - dialog.title = "娣诲姞閮ㄩ棬"; - nextTick(() => { - reset(); - if (row && row.deptId) { - form.value.parentId = row?.deptId; - } - }) + listDept().then(res => { + const data = proxy?.handleTree<DeptOptionsType>(res.data, "deptId"); + if (data) { + deptOptions.value = data + dialog.visible = true; + dialog.title = "娣诲姞閮ㄩ棬"; + nextTick(() => { + reset(); + if (row && row.deptId) { + form.value.parentId = row?.deptId; } - }) + }) + } + }) } /** 灞曞紑/鎶樺彔鎿嶄綔 */ const handleToggleExpandAll = () => { - isExpandAll.value = !isExpandAll.value; - toggleExpandAll(deptList.value, isExpandAll.value) + isExpandAll.value = !isExpandAll.value; + toggleExpandAll(deptList.value, isExpandAll.value) } /** 灞曞紑/鎶樺彔鎵�鏈� */ const toggleExpandAll = (data: DeptVO[], status: boolean) => { - data.forEach((item) => { - deptTableRef.value.toggleRowExpansion(item, status) - if(item.children && item.children.length > 0) toggleExpandAll(item.children, status) - }) + data.forEach((item) => { + deptTableRef.value?.toggleRowExpansion(item, status) + if (item.children && item.children.length > 0) toggleExpandAll(item.children, status) + }) } /** 淇敼鎸夐挳鎿嶄綔 */ const handleUpdate = async (row: DeptVO) => { - const res = await getDept(row.deptId); - dialog.visible = true; - dialog.title = "淇敼閮ㄩ棬"; - nextTick(async () => { - reset(); - form.value = res.data - const response = await listDeptExcludeChild(row.deptId); - const data = proxy?.handleTree<DeptOptionsType>(response.data, "deptId") - if (data) { - deptOptions.value = data; - if (data.length === 0) { - const noResultsOptions: DeptOptionsType = { deptId: res.data.parentId, deptName: res.data.parentName, children: [] }; - deptOptions.value.push(noResultsOptions); - } - } - }) + const res = await getDept(row.deptId); + dialog.visible = true; + dialog.title = "淇敼閮ㄩ棬"; + await nextTick(async () => { + reset(); + form.value = res.data + const response = await listDeptExcludeChild(row.deptId); + const data = proxy?.handleTree<DeptOptionsType>(response.data, "deptId") + if (data) { + deptOptions.value = data; + if (data.length === 0) { + const noResultsOptions: DeptOptionsType = { + deptId: res.data.parentId, + deptName: res.data.parentName, + children: [] + }; + deptOptions.value.push(noResultsOptions); + } + } + }) } /** 鎻愪氦鎸夐挳 */ const submitForm = () => { - deptFormRef.value.validate(async (valid: boolean) => { - if (valid) { - form.value.deptId ? await updateDept(form.value) : await addDept(form.value); - proxy?.$modal.msgSuccess("鎿嶄綔鎴愬姛"); - dialog.visible = false; - getList(); - } - }) + deptFormRef.value?.validate(async (valid: boolean) => { + if (valid) { + form.value.deptId ? await updateDept(form.value) : await addDept(form.value); + proxy?.$modal.msgSuccess("鎿嶄綔鎴愬姛"); + dialog.visible = false; + await getList(); + } + }) } /** 鍒犻櫎鎸夐挳鎿嶄綔 */ const handleDelete = async (row: DeptVO) => { - await proxy?.$modal.confirm('鏄惁纭鍒犻櫎鍚嶇О涓�"' + row.deptName + '"鐨勬暟鎹」?'); - await delDept(row.deptId); - getList(); - proxy?.$modal.msgSuccess("鍒犻櫎鎴愬姛"); + await proxy?.$modal.confirm('鏄惁纭鍒犻櫎鍚嶇О涓�"' + row.deptName + '"鐨勬暟鎹」?'); + await delDept(row.deptId); + await getList(); + proxy?.$modal.msgSuccess("鍒犻櫎鎴愬姛"); } onMounted(() => { - getList(); + getList(); }); </script> -- Gitblit v1.9.3