首页 > 其他分享 >uniapp中u-input点击事件失效

uniapp中u-input点击事件失效

时间:2024-08-05 11:09:30浏览次数:14  
标签:uniapp form color res 31 height 点击 input font

uniapp中u-input点击事件失效

img

当给u-input设置了disabled/readonly属性后,pc浏览器中点击事件失效,但是app/移动端h5中却仍有效

解决办法

给外边包上一个盒子设置点击事件,给input加上css属性:pointer-events:none

pointer-events CSS 属性指定在什么情况下 (如果有) 某个特定的图形元素可以成为鼠标事件的 target (en-US)。

除了指示该元素不是鼠标事件的目标之外,值none表示鼠标事件“穿透”该元素并且指定该元素“下面”的任何东西。

demo1

<view @click='handleClick'>
    <u--input
    style="pointer-events:none"
    :disabled="true"
    placeholder="请输入"/>
</view>

demo2

<template>
  <view>
    <view class="formBody">
      <u-form
        class="apply-form-field"
        :model="form"
        ref="form"
        :rules="rules"
        :errorType="errorType"
      >
        <u-form-item
          required
          label-width="150"
          label="养护站"
          right-icon="arrow-right"
          prop="maintenanceStationName"
        >
          <u-col @click="maintenanceStationIdShow = true">
            <u-input
              style="pointer-events: none"
              placeholder="选择养护站"
              v-model="form.maintenanceStationName"
              @click="maintenanceStationIdShow = true"
              disabled
            />
          </u-col>
          <u-picker
            range-key="siteName"
            v-model="maintenanceStationIdShow"
            :range="maintenanceStationList"
            mode="selector"
            @confirm="maintenanceStationIdConfirm"
          >
          </u-picker>
        </u-form-item>

        <u-form-item
          label-width="150"
          label="处置人员"
          right-icon="arrow-right"
          prop="disposePeopleName"
        >
          <u-col @click="disposePeopleNameShow = true">
            <u-input
              style="pointer-events: none"
              placeholder="选择处置人员"
              v-model="form.disposePeopleName"
              @click="disposePeopleNameShow = true"
              disabled
            />
          </u-col>
          <u-picker
            range-key="nickName"
            v-model="disposePeopleNameShow"
            :range="disposePeopleNameList"
            mode="selector"
            @confirm="applicantUserNameConfirm"
          ></u-picker>
        </u-form-item>

        <u-form-item
          label-width="150"
          label="联系方式"
          right-icon="none"
          prop="phone"
        >
          <u-input
            @focus="toTop"
            @blur="toBeJust"
            v-model="form.phone"
            disabled
          />
        </u-form-item>

        <u-form-item
          label-width="150"
          prop="diseaseLevel"
          label="优先级"
          right-icon="arrow-right"
        >
          <u-col @click="diseaseLevelShow = true">
            <u-input
              style="pointer-events: none"
              placeholder="选择优先级"
              :value="
                $getLabel(
                  diseaseLevelList,
                  'diseaseLevel',
                  form,
                  'dictValue',
                  'dictLabel'
                )
              "
              @click="diseaseLevelShow = true"
              disabled
            />
          </u-col>
          <u-picker
            range-key="dictLabel"
            v-model="diseaseLevelShow"
            :range="diseaseLevelList"
            mode="selector"
            @confirm="diseaseLevelConfirm"
          >
          </u-picker>
        </u-form-item>

        <u-form-item
          label-width="150"
          prop="deadline"
          label="截止时间"
          right-icon="none"
        >
          <u-col @click="timeShow = true">
            <u-input
              style="pointer-events: none"
              rightIcon="clock"
              placeholder="选择巡检时间"
              v-model="form.deadline"
              @click="timeShow = true"
              disabled
            />
          </u-col>
          <u-picker
            :params="params"
            v-model="timeShow"
            mode="time"
            @confirm="timeConfirm"
          >
          </u-picker>
        </u-form-item>

        <u-form-item
          label-position="top"
          label-width="150"
          label="处置内容"
          right-icon="none"
          prop="disposeContent"
        >
          <u-input
            @focus="toTop"
            @blur="toBeJust"
            v-model="form.disposeContent"
            type="textarea"
            placeholder="请输入处置内容"
          />
        </u-form-item>
      </u-form>
    </view>

    <view class="bottomBox">
      <view class="bottomBox-icon"> </view>
      <view class="bottomBox-box">
        <view class="none" @click="back">取消</view>
        <view class="sure" @click="submitForm">确定</view>
      </view>
    </view>
  </view>
</template>

<script>
import { isOpenMode } from "@/common/normal";
import diseaseDisposal from "../../../../common/api/system/workbench/diseaseDisposal";

export default {
  data() {
    return {
      disposePeopleNameShow: false,
      diseaseLevelShow: false,
      timeShow: false,
      maintenanceStationIdShow: false,
      rules: {
        maintenanceStationName: [
          {
            required: true,
            message: "请选择养护站",
            trigger: ["blur"],
          },
        ],
      },
      errorType: ["message", "border"],
      form: {},
      params: {
        year: true,
        month: true,
        day: true,
        hour: true,
        minute: true,
        second: true,
      },
      maintenanceStationList: [],
      disposePeopleNameList: [],
      diseaseLevelList: [],
    };
  },
  methods: {
    toTop() {
      let num = isOpenMode();
      if (num === 3 || num === 2) {
        return;
      } else {
        const bottomBox = document.querySelector(".bottomBox");
        bottomBox.style.bottom = -100 + "px";

        const formBody = document.querySelector(".formBody");
        formBody.style.height =
          "calc(100vh - var(--window-top) - var(--window-bottom))";
      }
    },

    toBeJust() {
      const bottomBox = document.querySelector(".bottomBox");
      bottomBox.style.bottom = 0;

      const formBody = document.querySelector(".formBody");
      formBody.style.height =
        "calc(100vh - var(--window-top) - var(--window-bottom) - 96px)";
    },

    getApplicantUserNameList() {
      this.$u.api.diseaseReporting.getUser().then((res) => {
        this.disposePeopleNameList = res.data;
      });
    },

    getMaintenanceStationList() {
      this.$u.api.diseaseDisposal.maintenanceStationList().then((res) => {
        if (res.code === 1) this.maintenanceStationList = res.data;
      });
    },

    getUpstreamDownstreamList() {
      var params = {
        dictType: "direct_manage_task_priority",
      };
      this.$u.api.normal.getDict(params).then((res) => {
        this.diseaseLevelList = res.data;
      });
    },

    applicantUserNameConfirm(e) {
      this.form.disposePeopleId = this.disposePeopleNameList[e].userId;
      this.form.disposePeopleName = this.disposePeopleNameList[e].nickName;
      this.form.phone = this.disposePeopleNameList[e].phone;
    },

    maintenanceStationIdConfirm(e) {
      this.form.maintenanceStationName =
        this.maintenanceStationList[e].siteName;
      this.form.maintenanceStationId = this.maintenanceStationList[e].id;
    },

    timeConfirm(e) {
      this.form.deadline = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}:${e.second}`;
    },

    diseaseLevelConfirm(e) {
      this.form.diseaseLevel = this.diseaseLevelList[e].dictValue;
    },

    back() {
      uni.navigateBack({
        delta: 1,
      });
    },

    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          console.log(this.form);
          this.$u.api.diseaseDisposal
            .saveDiseaseDisposal(this.form)
            .then((res) => {
              if (res.code === 1) {
                this.$u.toast("处置成功");
                setTimeout(() => {
                  this.back();
                }, 1000);
              }
            });
        } else {
          return false;
        }
      });
    },
  },
  onl oad(option) {
    this.form.diseaseClaimId = option.id;
  },
  onShow() {
    this.form.disposePeopleId = this.vuex_user.sysUser.userId;
    this.form.disposePeopleName = this.vuex_user.sysUser.nickName;
    this.form.phone = this.vuex_user.sysUser.phone;

    this.getApplicantUserNameList();
    this.getUpstreamDownstreamList();
    this.getMaintenanceStationList();
  },
  mounted() {
    this.$refs.form.setRules(this.rules);
    let windowHeight = 0;
    uni.getSystemInfo({
      success: (res) => {
        windowHeight = res.windowHeight;
      },
    });

    const windowResizeCallback = (res) => {
      if (res.size.windowHeight < windowHeight) {
        this.toTop();
      } else {
        this.toBeJust();
      }
    };
    uni.onWindowResize(windowResizeCallback);
  },
};
</script>

<style lang="scss" scoped>
page {
  height: 100%;
  background-color: #f5f5f5;
}

::v-deep .u-form-item {
  padding: 16px 32rpx !important;
  font-size: 17px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #1f1f1f;
  font-size: 32rpx !important;
}

.line {
  height: 12px;
  width: 100%;
  background-color: #f5f5f5;
}

.tips {
  padding: 0px 32rpx 0 32rpx;
  margin-top: 4px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(31, 31, 31, 0.4);
}

.bottomBox {
  width: 100%;
  position: absolute;
  bottom: 0px;
  height: 96px;
  z-index: 999;
  background: #ffffff;
  box-shadow: inset 0px 1px 0px 0px rgba(25, 31, 37, 0.12);
  /*border: 2px solid red;*/
  display: flex;
  justify-content: space-between;

  &-icon {
    width: 55%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10rpx 60rpx 0;

    &-iconBox {
      display: flex;
      flex-direction: column;
      align-items: center;
      font-size: 28rpx;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #1f1f1f;
      height: 44px;

      .u-icon {
        font-size: 40rpx;
        margin-bottom: 12rpx;
      }
    }
  }

  &-box {
    margin-top: 8px;
    display: flex;
    align-items: center;
    padding: 0 32rpx;
    flex: 1;

    view {
      width: 50%;
      height: 44px;
      border-radius: 4px;
      border: 1px solid rgba(31, 31, 31, 0.1);
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 34rpx;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
    }

    .none {
      color: #1f1f1f;
      margin-right: 16rpx;
    }

    .none:active {
      background: rgba(31, 31, 31, 0.17);
    }

    .sure {
      background: #3296fa;
      color: #ffffff;
    }

    .sure:active {
      background: rgba(32, 116, 212, 1);
    }
  }
}

.formBody {
  position: absolute;
  height: calc(100vh - var(--window-top) - var(--window-bottom) - 96px);
  overflow-y: auto;
  width: 100%;
}
</style>

标签:uniapp,form,color,res,31,height,点击,input,font
From: https://www.cnblogs.com/ProgrammerMao-001/p/18342776

相关文章

  • vue-seamless-scroll插件点击事件不生效
    vue-seamless-scroll点击事件不生效问题:在使用此插件时发现,列表内容前几行还是能正常点击的,但是从第二次出现的列表开始就没有点击事件了原因:因为html元素是复制出来的(滚动组件是将后面的复制出来一份,进行填铺页面,方便滚动)解决:往滚动组件的父节点上添加绑定事件(js冒泡机制),通过......
  • STM32之GPIO(General Purpose Input/Output,通用型输入输出)
    文章目录前言一、GPIO简介二、GPIO结构2.1GPIO基本结构2.2GPIO位结构2.2.1输入部分2.2.1输出部分四、GPIO模式4.1浮空/上拉/下拉输入4.2模拟输入4.3开漏/推挽输出4.4复用开漏/推挽输出前言提示:本文主要用作在学习江协科大STM32入门教程后做的归纳总结笔......
  • Java基于微信小程序的高校大学生新生迎新管理系统 uniapp
    文末获取资源,收藏关注不迷路文章目录项目介绍技术介绍项目界面关键代码目录项目介绍随着信息技术的飞速发展,信息化已经深入到社会生活的各个领域。高校作为科研的前沿阵地,一直走在科技发展的前列,特别是在信息化方面。如今,大部分高校都建立了数字化、信息化的校园平......
  • EFCore执行自定义SQL时格式化错误:Input string was not in a correct format.
      记录一下EFCore执行自定义SQL报System.FormatException异常的问题,这个异常可能是“Inputstringwasnotinacorrectformat.”,也可能是其它格式化异常,比如:System.ArgumentException:“Formatoftheinitializationstringdoesnotconformtospecificationstartingat......
  • uniapp Promise封装全局uni.request网络请求
    前言:在一个项目开发时,我们除了页面布局之外,就是数据处理了,封装一个全局的网络请求,有助于我们处理一些公用逻辑代码,更加专注于业务代码官方api说明:https://uniapp.dcloud.net.cn/api/request/request.html一般我们只关注这几个参数url也就是我们的baseurl,根域名header......
  • 基于ssm+vue.js+uniapp的宠物领养系统附带文章和源代码部署视频讲解等
    文章目录前言详细视频演示具体实现截图技术栈后端框架SSM前端框架Vue持久层框架MyBaits系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言......
  • Java毕业设计基于微信小程序的在线学习和测试系统 Uniapp
    文末获取资源,收藏关注不迷路文章目录项目介绍技术介绍项目界面关键代码目录项目介绍随着信息时代的快速发展,互联网的优势和普及,人们生活水平的不断提高,工作时间的繁忙,使得在线学习平台的开发成为必需。在线学习平台主要是借助计算机,通过对在线学习平台管理所需的信......
  • 基于SpringBoot+Vue+uniapp的高校校园交友微信小程序(源码+lw+部署文档+讲解等)
    文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言......
  • 基于SpringBoot+Vue+uniapp的走失人员的报备平台(源码+lw+部署文档+讲解等)
    文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言......
  • 基于SpringBoot+Vue+uniapp的投票评选系统(源码+lw+部署文档+讲解等)
    文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言......