js将对象数组中的某个属性值,批量替换成另一个数值

前提:对接口数据进行替换。把对应的数值或者字符串替换成中文。。。

核心代码:

const toStr = {
  sh: "沪",
  sz: "深",
};

myArr.map((item) => {
  const placeCode = item.placeCode;
  item.placeCode = toStr[placeCode] ? toStr[placeCode] : placeCode;
  return item;
});

写到这儿,基础的功能已经实现。

下面是一些pms的扩展使用:

//js
// 操作状态
export const materialReqState = {
  0: { text: "待审核", class: "reviewed" },
  1: { text: "审核不通过", class: "cancel" },
  2: { text: "待审批", class: "approval" },
  3: { text: "审批不通过", class: "stay" },
  4: { text: "采购中", class: "pass" },
  5: { text: "已取消", class: "cancel" },
  6: { text: "下发中", class: "cancel" },
  7: { text: "已完成", class: "pass" },
};

export const materialReqType={
  1:{text: "正常申请", class: "pass"},
  2:{text: "采购申请", class: "approval"},
}
export const materialWarnState = {
  0: { text: "待审核", class: "reviewed" },
  1: { text: "审核不通过", class: "cancel" },
  2: { text: "待审批", class: "approval" },
  3: { text: "审批不通过", class: "cancel" },
  4: { text: "审批通过", class: "pass" },
};
export const pmsCrawColorSatae = {
  1: { class: "work" },
  2: { class: "offDuty" },
  3: { class: "daysOff" },
  4: { class: "UnplanDays" },
};
export const materialAccountType = {
  1: { text: "入库", class: "reviewed" },
  2: { text: "出库", class: "pass" },
};

export const selectMaterialReqair={
  0: { text: "采购中", class: "reviewed" },
  1: { text: "待下发", class: "stay" },
  2: { text: "待收货", class: "approval" },
  3: { text: "已完成", class: "pass" },
}

el-table的使用:

const titleList = [
  {
    prop: "shipName",
    label: "船舶名称",
  },
  {
    prop: "orderNumber",
    label: "申请单号",
  },
  {
    prop: "createTime",
    label: "申请时间",
  },
  {
    prop: "type",
    label: "申请类型",
    formatter: materialReqType,
  },
]

//TableColumn
//列表的封装组件
<template>
  <template v-for="item in props.columnData">
    <el-table-column
      :prop="item.prop"
      :label="item.label"
      :width="item.width"
      :min-width="item['min-width']"
      v-if="!item.formatter && !item.transform"
      :show-overflow-tooltip="props.showOverflow"
    >
      <template #default="scope" v-if="item.type == 'date'">
        <span>{{ handleDate(scope.row[item.prop]) }}</span>
      </template>
    </el-table-column>
    <el-table-column
      :prop="item.prop"
      :label="item.label"
      :width="item.width"
      :min-width="item['min-width']"
      v-else-if="item.formatter && !item.transform"
      :show-overflow-tooltip="props.showOverflow"
    >
      <template #default="scope">
        <span
          v-if="!item.type"
          :class="
            (item.formatter[scope.row[item.prop]] &&
              item.formatter[scope.row[item.prop]].class) ||
            ''
          "
        >
          {{
            (item.formatter[scope.row[item.prop]] &&
              item.formatter[scope.row[item.prop]].text) ||
            ""
          }}
        </span>
        <div
          v-else
          :class="
            (item.formatter[scope.row[item.prop]] &&
              item.formatter[scope.row[item.prop]].class) ||
            ''
          "
        >
          {{ "" }}
        </div>
      </template>
    </el-table-column>
    <el-table-column
      :prop="item.prop"
      :label="item.label"
      :width="item.width"
      :min-width="item['min-width']"
      v-if="!item.formatter && item.transform"
      :show-overflow-tooltip="props.showOverflow"
    >
      <template #default="scope">
        <span>{{ item.transform(scope.row[item.prop], scope.row) }}</span>
      </template>
    </el-table-column>
  </template>
</template>

<script setup>
import { handleDate } from "@/utils";
let props = defineProps({
  columnData: Array,
  isShowIndex: Boolean,
  showOverflow: { type: Boolean, default: true },
});
</script>
<style scoped lang='less'></style>

 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值