ZengTao
2024-05-10 e808f9e89ad6bd5d252e1aad42daa676b481b0ca
CanadaMes-ui/src/views/Electrical/Positioning1.vue
@@ -31,7 +31,7 @@
        tag="el-button"
        type="text"
        active-class="blue-button"
        >{{ $t("Parameter") }}</router-link
        >{{ $t("Manual/Automatic") }}</router-link
      >
    </el-breadcrumb>
@@ -158,19 +158,14 @@
                >{{ $t("Set") }}</el-button
              >
              <div
                class="button-row"
                style="
                  display: flex;
                  justify-content: flex-start;
                  flex-wrap: wrap;
                "
              >
            </div>
            <div class="button-row" style="display: flex; justify-content: space-between; flex-wrap: wrap;">
                <el-button
                  v-if="item.button"
                  v-model="item.button.value"
                  :name="item.button.name"
                  style="width: 160px"
                  :class="{
                    dow: item.button.value === 0,
                    op: item.button.value === 1,
@@ -184,14 +179,40 @@
                  {{ item.button.name }}
                </el-button>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- <el-button @click="submitDataToBackend">提交数据到后端</el-button> -->
    <div>
    <el-dialog
      :visible="isPromptVisible"
      title="Prompt"
      width="30%"
      :close-on-click-modal="false"
      @close="handleCloseDialog"
    >
      <el-input v-model="password2" type="password" :placeholder="$t('Please enter the password')"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">{{ $t('Home') }}</el-button>
        <el-button type="primary" @click="handleConfirm">{{ $t('Confirm') }}</el-button>
      </span>
    </el-dialog>
  </div>
  </div>
</template>
  
<script>
let socket;
@@ -209,8 +230,12 @@
      A02: "",
      B01: "",
      B02: "",
      password: 1,
      password:"" ,
      password2:"" ,
      jianju: "",
      isPromptVisible: false,
    };
  },
  activated() {
@@ -223,9 +248,78 @@
    }
    this.$forceUpdate();
    this.load();
// 调用函数,显示密码输入对话框
this.showPasswordPrompt();
    
  },
  methods: {
    showPasswordPrompt() {
      this.isPromptVisible = true;
    },
    handleCancel() {
      this.$router.push('/home');
      this.isPromptVisible = false;
    },
    handleConfirm() {
      // 验证密码并执行相应操作
      if (this.password === this.password2) {
        // 密码正确,执行操作
        console.log('Password correct, perform operation');
        this.$message.success(this.$t('success password'));
        this.isPromptVisible = false;
        this.password2="";
        // 在这里执行你的操作
      } else {
        this.$message.error(this.$t('Incorrect password'));
        this.showPasswordPrompt();
      }
    },
    handleCloseDialog() {
      // 在这里处理弹框关闭事件,如果需要的话
      console.log('Dialog closed');
    },
  //   showPasswordPrompt() {
  //   // 显示遮罩层
  //   this.isPromptVisible = true;
  //   this.$prompt(
  //     this.$t('Are you sure to perform this operation?'),
  //     this.$t('prompt'),
  //     {
  //       inputType: 'password',
  //       inputPlaceholder: this.$t('Please enter the password'),
  //       confirmButtonText: this.$t('Yes'),
  //       showClose: false, // 不显示右上角的关闭按钮
  //       showCancelButton: false, // 不显示取消按钮
  //       type: 'warning',
  //     }
  //   ).then(({ value }) => {
  //     // 验证密码是否正确
  //     if (value !== this.password) {
  //       this.$message.error(this.$t('Incorrect password'));
  //       // 不关闭对话框,重新触发密码输入对话框
  //       this.showPasswordPrompt();
  //     } else {
  //       // 密码正确,执行操作
  //       // 这里可以添加你想要执行的操作
  //       // 如果没有操作,可以省略这个 else 代码块
  //     }
  //   }).catch(() => {
  //     // 如果用户取消操作,也不做任何处理
  //     console.log('取消1');
  //   }).finally(() => {
  //     // 关闭遮罩层
  //     this.isPromptVisible = false;
  //   });
  // },
    load(){
SelectPassword().then(res => {
@@ -316,36 +410,10 @@
      // 提交数据到后端
      const jsonString = JSON.stringify(jsonObject);
      this.$prompt(
    this.$t('Are you sure to perform this operation?'),
    this.$t('prompt'),
    {
      inputType: 'password',
      inputPlaceholder: this.$t('Please enter the password'),
      confirmButtonText: this.$t('Yes'),
      cancelButtonText: this.$t('No'),
      type: 'warning',
    }
  ).then(({ value }) => {
    // 验证密码是否正确
    if (value !== this.password) {
      this.$message.error(this.$t('Incorrect password'));
      return ;
    }else{
      console.log("提交以下数据到后端:", jsonString);
  console.log("提交以下数据到后端:", jsonString);
      socket?.send(jsonString);
    }
  }).catch(() => {
    // 取消操作
    console.log('取消1');
  });
      
      event.target.blur(); // 取消输入框焦点
    },
@@ -546,4 +614,11 @@
.blue-button {
  background-color: skyblue;
}
.op {
  background-color: #66b1ff;
}
.dow {
  background-color: #A0A0A0;
}
</style>