zenglf
2023-08-17 7442a435d058bd17d6fc679e1b7956bf3a5d32ae
src/components/jeecg/JVxeTable/components/JVxeTable.js
@@ -107,9 +107,9 @@
      // caseId,表格唯一标识
      caseId: `_j-vxe-${randomString(8)}_`,
      // 内置columns
      _innerColumns: [],
      innerColumns: [],
      // 内置 EditRules
      _innerEditRules: [],
      innerEditRules: [],
      // 记录滚动条位置
      scroll: {top: 0, left: 0},
      // 当前是否正在滚动
@@ -156,14 +156,14 @@
      excludeCode:[],
      // 联动下拉选项(用于隔离不同的下拉选项)
      // 内部联动配置,map
      _innerLinkageConfig: null,
      innerLinkageConfig: null,
    }
  },
  computed: {
    // vxe 最终 columns
    vxeColumns() {
      this._innerColumns.forEach(column => {
      this.innerColumns.forEach(column => {
        let renderOptions = {
          caseId: this.caseId,
          bordered: this.bordered,
@@ -184,11 +184,11 @@
          }
        }
        // 处理联动列,联动列只能作用于 select 组件
        if (column.$type === JVXETypes.select && this._innerLinkageConfig != null) {
        if (column.$type === JVXETypes.select && this.innerLinkageConfig != null) {
          // 判断当前列是否是联动列
          if (this._innerLinkageConfig.has(column.key)) {
          if (this.innerLinkageConfig.has(column.key)) {
            renderOptions.linkage = {
              config: this._innerLinkageConfig.get(column.key),
              config: this.innerLinkageConfig.get(column.key),
              getLinkageOptionsSibling: this.getLinkageOptionsSibling,
              getLinkageOptionsAsync: this.getLinkageOptionsAsync,
              linkageSelectChange: this.linkageSelectChange,
@@ -224,11 +224,11 @@
        }
        // update--end--autor:lvdandan-----date:20201211------for:JT-118 【online】 日期、时间控件长度较小
      })
      return this._innerColumns
      return this.innerColumns
    },
    // vxe 最终 editRules
    vxeEditRules() {
      return Object.assign({}, this.editRules, this._innerEditRules)
      return Object.assign({}, this.editRules, this.innerEditRules)
    },
    // vxe 最终 props
    vxeProps() {
@@ -302,8 +302,8 @@
            this.$set(data, this.dragSortKey, idx + 1)
          }
          // 处理联动回显数据
          if (this._innerLinkageConfig != null) {
            for (let configItem of this._innerLinkageConfig.values()) {
          if (this.innerLinkageConfig != null) {
            for (let configItem of this.innerLinkageConfig.values()) {
              this.autoSetLinkageOptionsByData(data, '', configItem, 0)
            }
          }
@@ -341,8 +341,8 @@
      handler(columns) {
        //获取不需要显示列
        this.loadExcludeCode()
        let _innerColumns = []
        let _innerEditRules = {}
        let innerColumns = []
        let innerEditRules = {}
        let {rowNumber, rowSelection, rowExpand, dragSort} = this
        let expandColumn, seqColumn, checkboxColumn, radioColumn, dragSortColumn
        if (Array.isArray(columns)) {
@@ -422,7 +422,7 @@
                    rules.push(Object.assign({}, rule, replace))
                  }
                }
                _innerEditRules[col.key] = rules
                innerEditRules[col.key] = rules
              }
              // 处理统计列
              // sum = 求和、average = 平均值
@@ -435,7 +435,7 @@
                  }
                })
              }
              _innerColumns.push(col)
              innerColumns.push(col)
            }
          })
        }
@@ -445,7 +445,7 @@
          if (seqColumn) {
            col = Object.assign(col, seqColumn, {type: 'seq'})
          }
          _innerColumns.unshift(col)
          innerColumns.unshift(col)
        }
        // 判断是否开启了可选择行
        if (rowSelection) {
@@ -462,7 +462,7 @@
          if (this.rowSelectionType === 'checkbox' && checkboxColumn) {
            col = Object.assign(col, checkboxColumn, {type: 'checkbox'})
          }
          _innerColumns.unshift(col)
          innerColumns.unshift(col)
        }
        // 是否可展开行
        if (rowExpand) {
@@ -474,7 +474,7 @@
          if (expandColumn) {
            col = Object.assign(col, expandColumn, {type: 'expand'})
          }
          _innerColumns.unshift(col)
          innerColumns.unshift(col)
        }
        // 是否可拖动排序
        if (dragSort) {
@@ -486,11 +486,11 @@
          if (dragSortColumn) {
            col = Object.assign(col, dragSortColumn, {type: JVXETypes.rowDragSort})
          }
          _innerColumns.unshift(col)
          innerColumns.unshift(col)
        }
        this._innerColumns = _innerColumns
        this._innerEditRules = _innerEditRules
        this.innerColumns = innerColumns
        this.innerEditRules = innerEditRules
      }
    },
    // watch linkageConfig
@@ -501,7 +501,7 @@
        if (Array.isArray(this.linkageConfig) && this.linkageConfig.length > 0) {
          // 获取联动的key顺序
          let getLcKeys = (key, arr) => {
            let col = this._innerColumns.find(col => col.key === key)
            let col = this.innerColumns.find(col => col.key === key)
            if (col) {
              arr.push(col.key)
              if (col.linkageKey) {
@@ -520,9 +520,9 @@
            }
            keys.forEach(k => configMap.set(k, configItem))
          })
          this._innerLinkageConfig = configMap
          this.innerLinkageConfig = configMap
        } else {
          this._innerLinkageConfig = null
          this.innerLinkageConfig = null
        }
      }
    },
@@ -715,7 +715,12 @@
    resetScrollTop(top) {
      this.scrollTo(null, (top == null || top === '') ? this.scroll.top : top)
    },
    clearAllData() {
      let {xTable} = this.$refs.vxe.$refs
        // issues/2784
        // 先清空所有数据
        xTable.loadData([])
    },
    /**
     * 加载新数据,和 loadData 不同的是,用该方法加载的数据都是相当于点新增按钮新增的数据。
     * 适用于不是数据库里查出来的没有id的临时数据
@@ -734,8 +739,8 @@
            this.$set(data, this.dragSortKey, idx + 1)
          }
          // 处理联动回显数据
          if (this._innerLinkageConfig != null) {
            for (let configItem of this._innerLinkageConfig.values()) {
          if (this.innerLinkageConfig != null) {
            for (let configItem of this.innerLinkageConfig.values()) {
              this.autoSetLinkageOptionsByData(data, '', configItem, 0)
            }
          }
@@ -763,6 +768,8 @@
        console.warn(`JVxeTable.setValues:必须传递数组`)
        return
      }
      // 是否更新了数据
      let updated = false
      values.forEach((item, idx) => {
        let {rowKey, values: record} = item
        let {row} = this.getIfRowById(rowKey)
@@ -775,6 +782,7 @@
            let oldValue = row[colKey]
            let newValue = record[colKey]
            if (newValue !== oldValue) {
              updated = true
              this.$set(row, colKey, newValue)
              // 触发 valueChange 事件
              this.trigger('valueChange', {
@@ -791,6 +799,14 @@
          }
        })
      })
      // 【issues/3828】数据更新后,重新计算统计列
      if (updated && this.statistics.has) {
        this.$nextTick(async () => {
          let {xTable} = this.$refs.vxe.$refs;
          await xTable.updateCache(true);
          await xTable.updateData();
        });
      }
    },
    /** 获取所有的数据,包括values、deleteIds */
@@ -1242,10 +1258,10 @@
          record[col.key] = createValue({row: record, column, $table: xTable})
        }
        // update-begin--author:sunjianlei---date:20210819------for: 处理联动列,联动列只能作用于 select 组件
        if (col.$type === JVXETypes.select && this._innerLinkageConfig != null) {
        if (col.$type === JVXETypes.select && this.innerLinkageConfig != null) {
          // 判断当前列是否是联动列
          if (this._innerLinkageConfig.has(col.key)) {
            let configItem = this._innerLinkageConfig.get(col.key)
          if (this.innerLinkageConfig.has(col.key)) {
            let configItem = this.innerLinkageConfig.get(col.key)
            this.getLinkageOptionsAsync(configItem, '')
          }
        }
@@ -1402,11 +1418,11 @@
  {title: '网址', value: 'url', pattern: /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/},
  {title: '电子邮件', value: 'e', pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/},
  {title: '手机号码', value: 'm', pattern: /^1[3456789]\d{9}$/},
  {title: '邮政编码', value: 'p', pattern: /^[1-9]\d{5}$/},
  {title: '邮政编码', value: 'p', pattern: /^[0-9]{6}$/},
  {title: '字母', value: 's', pattern: /^[A-Z|a-z]+$/},
  {title: '数字', value: 'n', pattern: /^-?\d+(\.?\d+|\d?)$/},
  {title: '整数', value: 'z', pattern: /^-?\d+$/},
  {title: '金额', value: 'money', pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/},
  {title: '金额', value: 'money', pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,5}))$/},
]
/** 旧版handler转为新版Validator */
@@ -1442,4 +1458,4 @@
    }
  }
  return Promise.resolve()
}
}