From f801f4fb11ff8ca08417a9ddf0231fb570fa26e3 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期一, 24 七月 2023 16:47:51 +0800
Subject: [PATCH] fix 修复 固定页面header穿模问题

---
 src/views/system/post/index.vue |  137 ++++++++++++++++++++++-----------------------
 1 files changed, 66 insertions(+), 71 deletions(-)

diff --git a/src/views/system/post/index.vue b/src/views/system/post/index.vue
index e82cfa2..b1cddd3 100644
--- a/src/views/system/post/index.vue
+++ b/src/views/system/post/index.vue
@@ -109,7 +109,6 @@
 <script setup name="Post" lang="ts">
 import { listPost, addPost, delPost, getPost, updatePost } from "@/api/system/post";
 import { PostForm, PostQuery, PostVO } from "@/api/system/post/types";
-import { ComponentInternalInstance } from "vue";
 
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 const { sys_normal_disable } = toRefs<any>(proxy?.useDict("sys_normal_disable"));
@@ -122,121 +121,117 @@
 const multiple = ref(true);
 const total = ref(0);
 
-const postFormRef = ref(ElForm);
-const queryFormRef = ref(ElForm);
+const postFormRef = ref<ElFormInstance>();
+const queryFormRef = ref<ElFormInstance>();
 
 const dialog = reactive<DialogOption>({
-    visible: false,
-    title: ''
+  visible: false,
+  title: ''
 });
 
 const initFormData: PostForm = {
-    postId: undefined,
-    postCode: '',
-    postName: '',
-    postSort: 0,
-    status: "0",
-    remark: ''
+  postId: undefined,
+  postCode: '',
+  postName: '',
+  postSort: 0,
+  status: "0",
+  remark: ''
 }
 
 const data = reactive<PageData<PostForm, PostQuery>>({
-    form: {...initFormData},
-    queryParams: {
-        pageNum: 1,
-        pageSize: 10,
-        postCode: '',
-        postName: '',
-        status: ''
-    },
-    rules: {
-        postName: [{ required: true, message: "宀椾綅鍚嶇О涓嶈兘涓虹┖", trigger: "blur" }],
-        postCode: [{ required: true, message: "宀椾綅缂栫爜涓嶈兘涓虹┖", trigger: "blur" }],
-        postSort: [{ required: true, message: "宀椾綅椤哄簭涓嶈兘涓虹┖", trigger: "blur" }],
-    }
+  form: { ...initFormData },
+  queryParams: {
+    pageNum: 1,
+    pageSize: 10,
+    postCode: '',
+    postName: '',
+    status: ''
+  },
+  rules: {
+    postName: [{ required: true, message: "宀椾綅鍚嶇О涓嶈兘涓虹┖", trigger: "blur" }],
+    postCode: [{ required: true, message: "宀椾綅缂栫爜涓嶈兘涓虹┖", trigger: "blur" }],
+    postSort: [{ required: true, message: "宀椾綅椤哄簭涓嶈兘涓虹┖", trigger: "blur" }],
+  }
 });
 
 const { queryParams, form, rules } = toRefs<PageData<PostForm, PostQuery>>(data);
 
 /** 鏌ヨ宀椾綅鍒楄〃 */
 const getList = async () => {
-    loading.value = true;
-    const res = await listPost(queryParams.value);
-    postList.value = res.rows;
-    total.value = res.total;
-    loading.value = false;
+  loading.value = true;
+  const res = await listPost(queryParams.value);
+  postList.value = res.rows;
+  total.value = res.total;
+  loading.value = false;
 }
 /** 鍙栨秷鎸夐挳 */
 const cancel = () => {
-    reset();
-    dialog.visible = false;
+  reset();
+  dialog.visible = false;
 }
 /** 琛ㄥ崟閲嶇疆 */
 const reset = () => {
-    form.value = {...initFormData};
-    postFormRef.value.resetFields();
+  form.value = { ...initFormData };
+  postFormRef.value?.resetFields();
 }
 /** 鎼滅储鎸夐挳鎿嶄綔 */
 const handleQuery = () => {
-    queryParams.value.pageNum = 1;
-    getList();
+  queryParams.value.pageNum = 1;
+  getList();
 }
 /** 閲嶇疆鎸夐挳鎿嶄綔 */
 const resetQuery = () => {
-    queryFormRef.value.resetFields();
-    handleQuery();
+  queryFormRef.value?.resetFields();
+  handleQuery();
 }
 /** 澶氶�夋閫変腑鏁版嵁 */
 const handleSelectionChange = (selection: PostVO[]) => {
-    ids.value = selection.map(item => item.postId);
-    single.value = selection.length != 1;
-    multiple.value = !selection.length;
+  ids.value = selection.map(item => item.postId);
+  single.value = selection.length != 1;
+  multiple.value = !selection.length;
 }
 /** 鏂板鎸夐挳鎿嶄綔 */
 const handleAdd = () => {
-    dialog.visible = true;
-    dialog.title = "娣诲姞宀椾綅";
-    nextTick(() => {
-        reset();
-    })
+  reset();
+  dialog.visible = true;
+  dialog.title = "娣诲姞宀椾綅";
 }
 /** 淇敼鎸夐挳鎿嶄綔 */
-const handleUpdate = (row?: PostVO) => {
-    dialog.visible = true;
-    dialog.title = "淇敼宀椾綅";
-    nextTick(async () => {
-        reset();
-        const postId = row?.postId || ids.value[0];
-        const res = await getPost(postId);
-        form.value = res.data;
-    })
+const handleUpdate = async (row?: PostVO) => {
+  reset();
+  const postId = row?.postId || ids.value[0];
+  const res = await getPost(postId);
+  Object.assign(form.value, res.data);
+  dialog.visible = true;
+  dialog.title = "淇敼宀椾綅";
 }
 /** 鎻愪氦鎸夐挳 */
 const submitForm = () => {
-    postFormRef.value.validate(async (valid: boolean) => {
-        if (valid) {
-            form.value.postId ? await updatePost(form.value) : await addPost(form.value);
-            proxy?.$modal.msgSuccess("鎿嶄綔鎴愬姛");
-            dialog.visible = false;
-            getList();
-        }
-    });
+  postFormRef.value?.validate(async (valid: boolean) => {
+    if (valid) {
+      form.value.postId ? await updatePost(form.value) : await addPost(form.value);
+      proxy?.$modal.msgSuccess("鎿嶄綔鎴愬姛");
+      dialog.visible = false;
+      await getList();
+    }
+  });
 }
 /** 鍒犻櫎鎸夐挳鎿嶄綔 */
 const handleDelete = async (row?: PostVO) => {
-    const postIds = row?.postId || ids.value;
-    await proxy?.$modal.confirm('鏄惁纭鍒犻櫎宀椾綅缂栧彿涓�"' + postIds + '"鐨勬暟鎹」锛�');
-    await delPost(postIds);
-    getList();
-    proxy?.$modal.msgSuccess("鍒犻櫎鎴愬姛");
+  const postIds = row?.postId || ids.value;
+  await proxy?.$modal.confirm('鏄惁纭鍒犻櫎宀椾綅缂栧彿涓�"' + postIds + '"鐨勬暟鎹」锛�');
+  await delPost(postIds);
+  await getList();
+  proxy?.$modal.msgSuccess("鍒犻櫎鎴愬姛");
 }
 /** 瀵煎嚭鎸夐挳鎿嶄綔 */
 const handleExport = () => {
-    proxy?.download("system/post/export", {
-        ...queryParams.value
-    }, `post_${new Date().getTime()}.xlsx`);
+  proxy?.download("system/post/export", {
+    ...queryParams.value
+  }, `post_${new Date().getTime()}.xlsx`);
 }
 
 onMounted(() => {
-    getList();
+  getList();
 });
 </script>

--
Gitblit v1.9.3