js输入框部分内容不可编辑,其余正常输入,el-input和el-select输入框和多个下拉框联动后的内容不可修改

news2024/7/6 18:17:56

在这里插入图片描述

            <tr>
            //格式
            // required自定义指令
              <e-td :required="!read" label>
                <span>地区:</span>
              </e-td>
              <td>
              //v-if="!read && this.data.nationCode == 148"显示逻辑
                <div
                  class="table-cell-flex"
                  style="width:450px"
                  v-if="!read && this.data.nationCode == 148"
                >
                  <el-form-item prop="nationCode" class="address">
                    <el-select
                      placeholder="国家"
                      v-model="data.nationCode"
                      @change="getprovince(data.nationCode, 1)"
                    >
                    //change事件单独使用不生效需要watch监听一下
                      <el-option
                        v-for="item in nationList"
                        :key="item.code"
                        :label="item.codeName"
                        :value="item.codeCode"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item prop="proviceCode" class="address">
                    <el-select
                      placeholder="省级地区"
                      v-model="data.proviceCode"
                      @change="getCityList(data.proviceCode, 1)"
                    >
                      <el-option
                        v-for="item in proviceList"
                        :key="item.code"
                        :label="item.codeName"
                        :value="item.codeCode"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item class="el-form-item" prop="cityCode">
                    <el-select
                      placeholder="市级地区"
                      v-model="data.cityCode"
                      @change="getCountyList(data.cityCode, 1)"
                    >
                      <el-option
                        v-for="item in cityList"
                        :key="item.code"
                        :label="item.codeName"
                        :value="item.codeCode"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item class="el-form-item" prop="countyCode">
                    <el-select
                      @change="getCountyName(data.countyCode, 1)"
                      v-model="data.countyCode"
                      placeholder="区级地区"
                    >
                      <el-option
                        v-for="item in countyList"
                        :key="item.code"
                        :label="item.codeName"
                        :value="item.codeCode"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </div>
                <div
                  class="table-cell-flex"
                  style="width:450px"
                  v-else-if="!read && this.data.nationCode != 148"
                >
                  <el-form-item prop="nationCode" class="address">
                    <el-select
                      placeholder="国家"
                      v-model="data.nationCode"
                      @change="getprovince(data.nationCode, 1)"
                    >
                      <el-option
                        v-for="item in nationList"
                        :key="item.code"
                        :label="item.codeName"
                        :value="item.codeCode"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <div class="el-form-item">
                    <el-form-item class="address">
                      <el-select
                        placeholder="省级地区"
                        v-model="data.proviceCode"
                        @change="getCityList(data.proviceCode, 1)"
                      >
                        <el-option
                          v-for="item in proviceList"
                          :key="item.code"
                          :label="item.codeName"
                          :value="item.codeCode"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </div>
                  <div class="el-form-item">
                    <el-form-item class="el-form-item">
                      <el-select
                        placeholder="市级地区"
                        v-model="data.cityCode"
                        @change="getCountyList(data.cityCode, 1)"
                      >
                        <el-option
                          v-for="item in cityList"
                          :key="item.code"
                          :label="item.codeName"
                          :value="item.codeCode"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </div>
                  <div class="el-form-item">
                    <el-form-item class="el-form-item">
                      <el-select
                        @change="getCountyName(data.countyCode, 1)"
                        v-model="data.countyCode"
                        placeholder="区级地区"
                      >
                        <el-option
                          v-for="item in countyList"
                          :key="item.code"
                          :label="item.codeName"
                          :value="item.codeCode"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </div>
                </div>
                <span v-else>
                  <template v-if="data.nationProviceCityName">
                    <span
                      :style="
                        equal(
                          'nationProviceCityName',
                          data.nationProviceCityName
                        )
                      "
                    >
                      {{ data.nationProviceCityName }}
                    </span>
                  </template>
                  <template v-else-if="data.regProvinceAndCityAndCountyName">
                    <span
                      :style="
                        equal(
                          'regProvinceAndCityAndCountyName',
                          data.regProvinceAndCityAndCountyName
                        )
                      "
                      >{{ data.regProvinceAndCityAndCountyName }}</span
                    >
                  </template>
                  <template v-else>
                    <span :style="equal('proviceName', data.proviceName)">{{
                      data.proviceName
                    }}</span>
                    <span :style="equal('cityName', data.cityName)">{{
                      data.cityName
                    }}</span>
                    <span :style="equal('countyName', data.countyName)">{{
                      data.countyName
                    }}</span>
                  </template>
                </span>
              </td>
              <e-td :required="!read" label>
                <span>详细地址:</span>
              </e-td>
              <td>
                <div class="table-cell-flex">
                  <el-form-item v-if="!read" prop="compAddress">
                    <el-input
                      v-model="data.compAddress"
                      @keydown.delete.native="onDeleteKeyDown"
                      @keydown.native="onKeyDown"
                      @compositionstart.native="onCompositionStart"
                      @compositionend.native="compositionend"
                      placeholder="请输入详细地址"
                    ></el-input>
                  </el-form-item>
                  <span
                    v-else
                    :style="equal('compAddress', data.compAddress)"
                    >{{ data.compAddress }}</span
                  >
                </div>
              </td>
            </tr>
watch: {
//监听用来联动和获取选择的名称,并且区分是手动修改还是初始化  不区分之前内容会被清空这样修改的时候再清空详细地址
    // 国家
    'data.nationCode': {
      handler: function(newval, oldval) {
        console.log(newval, 'new')
        console.log(oldval, 'old')
        if (newval) {
          this.getprovince(newval)
        }
      },
      immediate: true
    },
    // 省级地区
    'data.proviceCode': {
      handler: function(newval, oldval) {
        console.log(newval, 'new')
        console.log(oldval, 'old')
        if (newval) {
          this.getCityList(newval)
        }
      },
      immediate: true
    },
    'data.cityCode': {
      handler: function(newval, oldval) {
        console.log(newval, 'new')
        console.log(oldval, 'old')
        if (newval) {
          this.getCountyList(newval)
        }
      },
      immediate: true
    },
    'data.countyCode': {
      handler: function(newval) {
        if (newval) {
          this.getCountyName(newval)
        }
      },
      immediate: true
    },
    },
    methods: {
     // 获取国家
    async getnationList() {
      let params = {
        classCode: 'countryRegionsAndProvinces',
        higherCode: 0
      }
      let data = await this.$api.common.getDictionary(params)
      if (data) {
        this.nationList = data
      }
    },
    // 获取省市
    async getprovince(val, isempty) {
      let params = {
        classCode: 'countryRegionsAndProvinces',
        higherCode: val
      }
      //代码可以自行简化
      let data = await this.$api.common.getDictionary(params)
      if (data) {
        this.proviceList = data
        if (isempty == 1) {
          this.proviceName = ''
          this.cityName = ''
          this.countyName = ''
          this.data.compAddress = ''
          this.data.proviceCode = ''
          this.data.cityCode = ''
          this.data.countyCode = ''
          this.cityList = []
          this.countyList = []
        }
        },// 获取城市
    async getCityList(code, isempty) {
      let params = {
        classCode: 'countryRegionsAndProvinces',
        higherCode: code
      }
      let data = await this.$api.common.getDictionary(params)
      if (data) {
        this.cityList = data
        if (isempty == 1) {
          this.cityName = ''
          this.countyName = ''
          this.data.cityCode = ''
          this.data.countyCode = ''
          this.countyList = []
          this.proviceName = this.getRessName(
            this.data.proviceCode,
            this.proviceList
          )
          this.data.compAddress =
            this.proviceName + this.cityName + this.countyName
    
          this.ress = this.proviceName + this.cityName + this.countyName
        }
      }
    },
    // 获取乡镇
    async getCountyList(code, isempty) {
      let params = {
        classCode: 'countryRegionsAndProvinces',
        higherCode: code
      }
      let data = await this.$api.common.getDictionary(params)
      if (data) {
        this.countyList = data
        if (isempty == 1) {
          this.cityName = ''
          this.data.countyCode = ''
          this.countyName = ''
          this.proviceName = this.getRessName(
            this.data.proviceCode,
            this.proviceList
          )
          this.cityName = this.getRessName(this.data.cityCode, this.cityList)

          this.data.compAddress =
            this.proviceName + this.cityName + this.countyName
            //ress data里记得定义一下用来获取选择的地址的长度在输入的时候做校验用
          this.ress = this.proviceName + this.cityName + this.countyName
        }
      }
    },
    getCountyName(val, isempty) {
      if (isempty == 1) {
        this.countyName = ''
        this.proviceName = this.getRessName(
          this.data.proviceCode,
          this.proviceList
        )
        this.cityName = this.getRessName(this.data.cityCode, this.cityList)

        this.countyName = this.getRessName(
          this.data.countyCode,
          this.countyList
        )
        this.data.compAddress =
          this.proviceName + this.cityName + this.countyName
        this.ress = this.proviceName + this.cityName + this.countyName
      }
    },
    // 输入限制
    onDeleteKeyDown(e) {
      let { selectionStart, selectionEnd } = e.target
      // 如果包含不能删除的区域位置,阻止删除
      if (!(selectionStart > this.ress.length || selectionEnd < 0)) {
        e.preventDefault()
      }
    },
    onKeyDown(e) {
      // 如果包含不能删除的区域,禁止
      if (
        !(
          e.target.selectionStart > this.ress.length - 1 ||
          e.target.selectionEnd < 0
        )
      ) {
        e.preventDefault()
      }
    },
    // 输入法键盘字符下不可输入,记录输入的起始位置
    onCompositionStart(e) {
      this.checkText = e.data //记录选中的文字
      this.startVal = e.target.selectionStart
    },

    // 当在不可编辑的范围内输入时结合输入文字开始位置this.startVal和输入结束
    // e.target.selectionEnd位置,通过字符串截取并接还原原来的字符。
    compositionend(e) {
      if (this.startVal !== null) {
        this.$nextTick(() => {
          if (this.startVal < this.ress.length) {
            let targetVal = e.target.value
            let startTarget = targetVal.substring(0, this.startVal)
            let endTarget = targetVal.substring(e.target.selectionEnd)
            e.target.value = startTarget + this.checkText + endTarget
          }
        })
      }
    },
    //	获取省市区名称
    getRessName(codeCode, arr) {
      return arr.find(o => o.id == Number(codeCode))
        ? arr.find(o => o.id == Number(codeCode)).codeName
        : ''
    },
        }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1314811.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

百华鞋业入围全国老年用品标准编制参编单位

12月8日&#xff0c;中国轻工业信息中心组织召开了中国轻工业适老系列标准研讨会。中国轻工业联合会信息统计部&#xff08;中国轻工业信息中心&#xff09;副主任马真出席会议并讲话。中国轻工业信息中心标准工作负责人孟慧敏介绍了相关标准制定情况。会议由中国轻工业信息中心…

Cellinx NVT 摄像机 GetFileContent.cgi任意文件读取漏洞 (CVE-2023-23063)

0x01 产品简介 Cellinx NVT IP PTZ是韩国Cellinx公司的一个摄像机设备。 0x02 漏洞概述 Cellinx NVT v1.0.6.002b版本存在安全漏洞&#xff0c;该漏洞源于存在本地文件泄露漏洞&#xff0c;攻击者可读取系统密码等敏感信息。 0x03 复现环境 FOFA&#xff1a;body"loc…

LAMP平台——构建PHP运行环境

在构建LAMP平台时&#xff0c;各组件的安装顺序依次为Linux、Apache、MySQL、PHP。其中Apache和 MySQL的安装并没有严格的顺序&#xff1b;而PHP环境的安装一般放到最后&#xff0c;负责沟通Web服务器和数据库 系统以协同工作。 PHP 即 Hypertext Preprocessor&#xff08;超级…

连续型随机变量的概率密度

如果对于随机变量的分布函数&#xff0c;存在非负可积函数&#xff0c;使得对于任意实数&#xff0c;有&#xff1a; 那么就称为连续型随机变量&#xff0c;称为的概率密度函数&#xff0c;简称密度函数。

Spring 6(一)【Spring 入门】

前言 好久没有写博客了&#xff0c;最近刚忙完考试&#xff0c;眼下又是英语四六级。Flink 按说应该是大数据学习的主线任务&#xff0c;但是长时间学一门技术还是心累的。正好之前对 Java 注解有了进一步的熟悉&#xff0c;一直想着熟悉巩固。所以&#xff0c;今天开始就来深入…

Chapter 7 - 3. Congestion Management in Ethernet Storage Networks以太网存储网络的拥塞管理

Pause Threshold for Long Distance Links长途链路的暂停阈值 This section uses the following basic concepts: 本节使用以下基本概念: Bit Time (BT): It is the time taken to transmit one bit. It is the reciprocal of the bit rate. For example, BT of a 10 GbE po…

微信小程序ios中非cover组件点击重复触发地图tap事件

现象&#xff1a; map中使用view组件的click事件会重复触发地图的tap组件&#xff0c;只在ios上出现 <map id"maps" style"width: 100vw;height: 100vh;" :latitude"latitude" :longitude"longitude":markers"markers"…

P with Spacy:自定义文本分类管道

一、说明 Spacy 是一个功能强大的 NLP 库&#xff0c;其中许多 NLP 任务&#xff08;如标记化、词干提取、词性标记和命名实体解析&#xff09;均通过预训练模型提供开箱即用的功能。所有这些任务都由管道对象以及逐步应用于给定文本的不同函数的内部抽象来包装。该管道可以通过…

STM32_HAL库—IWDG看门狗

一、CubeMX设置 1、晶振配置&#xff08;72M&#xff09; 2、数据配置 超时时间 Tout prv / LSI * rlv (s) 其中prv是预分频器寄存器的值&#xff0c;rlv是重装载寄存器的值&#xff0c;而LSI值默认是40kHz&#xff0c;如下所示。 3、代码实现 int main(){while(1){HAL_IW…

C++ 学习系列 -- 模板 template

一 C 模板介绍&#xff1f; C 为什么引入模板&#xff1f; 我的理解是&#xff1a; C 引入模板的概念&#xff0c;是为了复用重复的代码&#xff0c;当某些代码除了操作的数据类型不同以外&#xff0c;其他逻辑全都相同&#xff0c;此时就适合采用模板的方式。 定义模板类或者…

Linux的文件系统 内核结构

Linux的文件系统 Q1&#xff1a;什么是文件系统&#xff1f; A&#xff1a;在学术的角度下&#xff0c;文件系统指“操作系统用于明确存储设备组织文件的方法”&#xff0c;是“文件管理系统”的简称&#xff0c;本质也是代码&#xff0c;一段程序 Q2&#xff1a;文件系统&…

使用opencv的Canny算子实现图像边缘检测

1 边缘检测介绍 图像边缘检测技术是图像处理和计算机视觉等领域最基本的问题&#xff0c;也是经典的技术难题之一。如何快速、精确地提取图像边缘信息&#xff0c;一直是国内外的研究热点&#xff0c;同时边缘的检测也是图像处理中的一个难题。早期的经典算法包括边缘算子方法…

代码随想录-刷题第二十八天

93. 复原 IP 地址 题目链接&#xff1a;93. 复原 IP 地址 思路&#xff1a;切割问题&#xff0c;原理上还是抽象成树形结构&#xff0c;然后使用回溯法。 131 题的要求是&#xff1a;让你把字符串 s 切分成若干个合法的回文串&#xff0c;返回所有的切分方法。 本题的要求是…

知识|基于混合模式的多余度飞控全数字仿真系统研究

*余度&#xff08;Redundancy&#xff09;&#xff1a;一种确保安全的设计手段&#xff0c;使得出现两个及以上故障时&#xff0c;才会引起既定不希望发生的工作状态。 飞行控制软件主要完成飞行传感器数据处理、飞行姿态控制和余度管理任务&#xff0c;对保证飞机安全性和可靠…

GroupMixFormer:基于Group-Mix注意力的视觉Transformer

文章目录 摘要1、简介2、相关工作2.1、视觉转换器2.2、全面的自注意力建模 3、组混合注意力和GroupMixFormer3.1. 动机&#xff1a;从个体到群体3.2. GMA: 混合组以获得更好的注意力3.3. 架构配置 4、实验4.1、实现细节4.2. 与最先进模型的比较4.3. 消融实验 5、结论 摘要 htt…

[论文笔记] chatgpt系列 SparseMOE—GPT4的MOE结构

SparseMOE: 稀疏激活的MOE Swtich MOE,所有token要在K个专家网络中,选择一个专家网络。 显存增加。 Experts Choice:路由MOE:​​​​​​​ 由专家选择token。这样不同的专家都选择到某个token,也可以不选择该token。 由于FFN层的时间复杂度和attention层不同,FFN层的时…

[Vulnhub靶机] DC-1

[Vulnhub靶机] DC-1靶机渗透思路及方法&#xff08;个人分享&#xff09; 靶机下载地址&#xff1a; https://download.vulnhub.com/dc/DC-1.zip 靶机地址&#xff1a;192.168.67.25 攻击机地址&#xff1a;192.168.67.3 一、信息收集 1.使用 arp-scan 命令扫描网段内存活的…

代码随想录刷题题Day14

刷题的第十四天&#xff0c;希望自己能够不断坚持下去&#xff0c;迎来蜕变。&#x1f600;&#x1f600;&#x1f600; 刷题语言&#xff1a;C Day14 任务 ● 110.平衡二叉树 ● 257. 二叉树的所有路径 ● 404.左叶子之和 1 平衡二叉树 二叉树节点的深度&#xff1a;指从根节…

数据库系列之简要对比下GaussDB和OpenGauss数据库

GaussDB作为一款企业级的数据库产品&#xff0c;和开源数据库OpenGauss之间又是什么样的关系&#xff0c;刚开始接触的时候是一头雾水&#xff0c;因此本文简要对比下二者的区别&#xff0c;以加深了解。 1、GaussDB和OpenGauss数据库简要对比 GaussDB是华为基于PostgreSQL数据…

用Python快速从深层嵌套 JSON 中找到特定的 Value

有时候&#xff0c;我们拿到一个JSON数据的时候&#xff0c;会难以看出其逻辑层次结构。 这时候就需要我们进行代码解析了。 代码&#xff1a; import jsondef find_json_value(data_json, value, path""):if isinstance(data_json, dict):for k, v in data_json.…