VUE3给table的head添加popover筛选、时间去除时分秒、字符串替换某字符

1. VUE3给table的head添加popover筛选

html 复制代码
<el-table
      ref="processTableRef"
      class="process-table"
      row-key="secuId"
      :data="pagingData"
      style="width: 100%"
      highlight-current-row
      :height="stockListHeight"
      :default-expand-all="isExpand"
      :expand-row-keys="expandRowKeys"
      v-if="reloadeTable"
    >
      <el-table-column type="expand">
        <template #default="props">
          <div class="table-expand" v-if="!!props.row.eventContent">
            <div class="el-form-item" v-html="formatText(props.row.eventContent)"></div>
          </div>
          <div v-else class="expand-empty"><span>暂无数据</span></div>
        </template>
      </el-table-column>
      <el-table-column label="债券代码" show-overflow-tooltip prop="secuId">
        <template #header>
          <el-popover placement="right" trigger="click">
            <el-select
              :teleported="false"
              ref="bondCodeSelection"
              multiple
              filterable
              collapse-tags
              clearable
              v-model="securityIds"
              placeholder
              @change="bondCodeVisibleChange"
              @remove-tag="bondCodeVisible = false"
            >
              <el-option v-for="item in selectIdData" :key="item.value" :value="item.value" :label="item.value"></el-option>
            </el-select>
            <template #reference>
              <label>
                债券代码
                <i v-if="securityIds.length < 1" style="margin-left: 10px; cursor: pointer" class="el-icon-search"></i>
                <i v-else style="margin-left: 10px; color: var(--ems-red); cursor: pointer" class="el-icon-search"></i>
              </label>
            </template>
          </el-popover>
        </template>
        <template #default="props">{{ props.row.secuId }}</template>
      </el-table-column>
</el-table>
javascript 复制代码
const bondCodeSelection = ref()
let securityIds: any = ref([])
let bondCodeVisible = ref(false)

const bondCodeVisibleChange = () => {
  bondCodeVisible.value = false
  bondCodeSelection.value.blur()
}
//筛选下拉框选项,bondTenderStocks为接口获取数据列表
let selectIdData = computed(() => {
  let map = new Set()
  let securitys: any = []
  bondTenderStocks.value.forEach((item: any) => {
    if (map.has(item.secuId) === false) {
      map.add(item.secuId)
      securitys.push({
        text: item.secuId + ' ' + item.secuNm,
        value: item.secuId
      })
    }
  })
  return securitys
})

let displayData = computed(() => {
  let initData = JSON.parse(JSON.stringify(tableData.value))

  // 债券代码
  if (securityIds.value.length !== 0) {
    let securitySet = new Set()
    securityIds.value.forEach((security: any) => securitySet.add(security))
    initData = initData.filter((item: any) => securitySet.has(item.secuId))
  }

  return initData
})

2.时间去除时分秒

javascript 复制代码
function getDate(date: any) {
  if (!date) {
    return ''
  }
    
    // 将字符串转换为 Date 对象  
    var date = new Date(dateString);  
  
    // 使用 toISOString 方法获取日期时间字符串的简化版本,然后提取年月日部分  
    var formattedDate = date.toISOString().split('T')[0];  
    return formattedDate
}

ex:date = "2023-11-02 00:00:00"

3.字符串替换某字符

javascript 复制代码
<div class="el-form-item" v-html="formatText(props.row.eventContent)"></div>

function formatText(text: any) {
  if (!text) {
    return ''
  }
  let result = text
  if (text.indexOf('\n') >= 0) {
    let str = text.replace('\n', '')
    result = str.replace(/\n/g, '</br>')
  }
  return result
}

ex:
全部替换
let str = "\n债券代码:1680352.IB\n债券简称:16马经发债02\n发行量:17.5亿\n中标量:2.1";  
let newStr = str.replace(/\n/g, "</br>");  

//只替换第一个
let newStr = str .replace('\n', '')
相关推荐
专注前端30年30 分钟前
【JavaScript】reduce 方法的详解与实战
开发语言·前端·javascript
菜鸟una1 小时前
【瀑布流大全】分析原理及实现方式(微信小程序和网页都适用)
前端·css·vue.js·微信小程序·小程序·typescript
专注前端30年2 小时前
2025 最新 Vue2/Vue3 高频面试题(10月最新版)
前端·javascript·vue.js·面试
Highcharts.js2 小时前
选择合适的组合:如何打造数据可视化的“黄金组合”
javascript·信息可视化·highcharts·交互式图表开发
angelQ3 小时前
Vue 3 中 ref 获取 scrollHeight 属性为 undefined 问题定位
前端·javascript
我的div丢了肿么办3 小时前
js函数声明和函数表达式的理解
前端·javascript·vue.js
AAA阿giao3 小时前
JavaScript 对象字面量与代理模式:用“胡巴送花”讲透面向对象与设计思想
javascript
高台树色3 小时前
终于记住Javascript垃圾回收机制
javascript
武天3 小时前
一个项目有多个后端地址,每个后端地址的请求拦截器和响应拦截器都不一样,该怎么封装
vue.js
举个栗子dhy3 小时前
第二章、全局配置项目主题色(主题切换+跟随系统)
前端·javascript·react.js