vue 表单当用户修改字段,点击关闭弹窗时,检测用户是否有修改

<template>
  <div>
    <el-dialog
      append-to-body
      destroy-on-close
      :visible.sync="visible"
      :modal="!isFromShare"
      :show-close="!isFromShare"
      :close-on-click-modal="false"
      @closed="dialogClose"
      :before-close="handleBeforeClose"
    >
      <div slot="title">
        <div>
          <slot name="fill-form-tabs"></slot>
          <div class="header-detail">
            <div class="header-left">
            </div>
          </div>
        </div>
      </div>
      <!--  -->
      <div
        class="dialog-container"
        style="display: flex; flex-direction: row; width: 100%"
      >
        <div
          class="dialog-body"
          v-loading="saveFormLoading"
          element-loading-spinner="el-loading"
          element-loading-background="rgba(255, 255, 255, 0.1)"
          style="flex: 3"
        >
          <div @scroll="handleScroll($event)" class="body-container">
            <form-web
              ref="formEdit"
            ></form-web>
          </div>
          <div v-if="showFooter" class="body-btns">
            <!-- 按钮组件 -->
            <ui-button-group
              :saveDocument="saveDocument"
            ></ui-button-group>
          </div>
        </div>

      </div>
    </el-dialog>
  </div>
</template>
<script>
import form from "@/components/form-ui/web/form";

import { _eq } from "@zgg-core-utils/relyUtil";
export default {
 
  name: "form-bus-web",
  mixins: [],
  components: {

  },
  props: {

  },
  computed: {
    allowEdit() {
      if (this.actionType === "readonly") {
        return false;
      }

      if (!isEmpty(this.roleAuthForMe)) {
        if (this.actionType == "add") {
          if (
            !(
              this.roleAuthForMe.clickEvents &&
              this.roleAuthForMe.clickEvents.includes("add")
            )
          ) {
            return false;
          }
        } else if (this.actionType == "edit") {
          if (
            !(
              this.roleAuthForMe.clickEvents &&
              this.roleAuthForMe.clickEvents.includes("edit")
            )
          ) {
            return false;
          }
        }
    },
    },
 
  data() {
    return {
      isModified: false,
      isSaveModified: false,
    };
  },
  created() {

  },

  methods: {
    close() {
      if (!this.isWorkflow && this.allowEdit && this.actionType == "edit") {
        this.checkFormModify();
        if (this.isModified) {
          this.$confirm("确定退出编辑?", "有修改的内容未保存", {
            type: "warning",
          })
            .then(() => {
              this.isModified = false;
              this.$emit("close", this.$refs.formEdit);
              this.visible = false;
            })
            .catch(() => {
              this.isModified = false;
            });
        } else {
          this.$emit("close", this.$refs.formEdit);
          this.visible = false;
        }
      } else {
        this.$emit("close", this.$refs.formEdit);
        this.visible = false;
      }
    },
    handleBeforeClose(done) {
      if (!this.isWorkflow && this.allowEdit && this.actionType == "edit") {
        this.checkFormModify();
        if (this.isModified) {
          this.$confirm("确定退出编辑?", "有修改的内容未保存", {
            type: "warning",
          })
            .then(() => {
              this.isModified = false;
              done();
            })
            .catch(() => {
              this.isModified = false;
            });
        } else {
          done();
        }
      } else {
        done();
      }
    },
    checkFormModify() {
      if (this.isSaveModified) {
        //保存过了
        return;
      }
      let tempRef = this.$refs["formEdit"];
      let document = tempRef.form;
      let originalDocument = tempRef.originalDocument;
      if (originalDocument) {
        console.log(originalDocument, "原有数据");
        console.log(document, "修改后的数据");
        let isEq = _eq(originalDocument, document);
        if (!isEq) {
          this.isModified = true;
        }
      }
    },
    saveDocument(callback, isReferenceSave = false) {
      this.isModified = false;
      this.isSaveModified = true;
    },




  },
};
</script>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值