曹睿
4 天以前 2362a3399f333aec47afc83caf0bfb1887af24a5
src/views/basicData/product/index.vue
@@ -55,7 +55,7 @@
                >
                  编辑
                </el-button>
                <el-button type="primary" link @click="openProDia('add', data)">
                <el-button type="primary" link @click="openProDia('add', data)" :disabled="node.level >= 3">
                  添加产品
                </el-button>
                <el-button
@@ -99,7 +99,7 @@
        @pagination="pagination"
      ></PIMTable>
    </div>
    <el-dialog v-model="productDia" title="产品" width="400px">
    <el-dialog v-model="productDia" title="产品" width="400px" @keydown.enter.prevent>
      <el-form
        :model="form"
        label-width="140px"
@@ -114,6 +114,7 @@
                v-model="form.productName"
                placeholder="请输入产品名称"
                clearable
                @keydown.enter.prevent
              />
            </el-form-item>
          </el-col>
@@ -131,6 +132,7 @@
      title="规格型号"
      width="400px"
      @close="closeModelDia"
      @keydown.enter.prevent
    >
      <el-form
        :model="modelForm"
@@ -146,6 +148,7 @@
                v-model="modelForm.model"
                placeholder="请输入规格型号"
                clearable
                @keydown.enter.prevent
              />
            </el-form-item>
          </el-col>
@@ -157,6 +160,7 @@
                v-model="modelForm.unit"
                placeholder="请输入单位"
                clearable
                @keydown.enter.prevent
              />
            </el-form-item>
          </el-col>
@@ -315,16 +319,53 @@
  proxy.$refs.formRef.resetFields();
  productDia.value = false;
};
// 封装一个安全的确认框,彻底阻止Enter键触发
const safeConfirm = (message, title) => {
  // 标记是否是鼠标点击(点击按钮会触发focus事件)
  let isMouseClick = false;
  return new Promise((resolve, reject) => {
    const box = ElMessageBox.confirm(message, title, {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
      beforeClose: (action, instance, done) => {
        if (action === "confirm") {
          // 只有鼠标点击时才允许确认
          if (isMouseClick) {
            done();
            resolve();
          } else {
            // Enter键触发时阻止
            done(false);
          }
        } else {
          // 取消操作直接允许
          done();
          reject();
        }
      }
    });
    // 监听确认按钮的focus事件(鼠标点击会触发,Enter键不会)
    setTimeout(() => {
      const confirmBtn = document.querySelector('.el-message-box__btns .el-button--primary');
      if (confirmBtn) {
        confirmBtn.addEventListener('focus', () => {
          isMouseClick = true;
        });
      }
    }, 0); // 延迟获取,确保DOM已渲染
  });
};
// 删除产品
// 删除产品
const remove = (node, data) => {
  let ids = [];
  ids.push(data.id);
  ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "删除提示", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
  let ids = [data.id];
  // 使用封装的safeConfirm
  safeConfirm("选中的内容将被删除,是否确认删除?", "删除提示")
    .then(() => {
      // 确认删除逻辑
      tableLoading.value = true;
      delProduct(ids)
        .then((res) => {
@@ -400,11 +441,7 @@
    proxy.$modal.msgWarning("请选择数据");
    return;
  }
  ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "删除提示", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
  safeConfirm("选中的内容将被删除,是否确认删除?", "删除提示")
    .then(() => {
      tableLoading.value = true;
      delProductModel(ids)