若依框架----字典表

文章展示了在Vue2和Vue3中如何处理数据字典,用于下拉选择组件。在Vue2中,通过调用`getDicts`获取字典数据并赋值给选项。在Vue3中,使用`useDict`方法获取数据,并进行转换处理,然后在表格数据中应用这些字典值。同时,文章涉及到表单验证和数据提交时的数据转换操作。

vue2

   <el-form-item label="设备状态" prop="statustypeid">
        <el-select
          v-model="queryParams.statustypeid"
          placeholder="请选择设备状态"
          clearable
      
        >
          <el-option
            v-for="dict in Options.statustypeidOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="Number(dict.dictValue)"
          />
        </el-select>
      </el-form-item>
      
      
      
 mare_scoke 字典表名称
 created() {
    this.getList();
    // 满意度字典表转换
    this.getDicts("mare_scoke").then(response => {
      this.statForamt = response.data;
    });
    
      this.getDicts("deviceStatus").then(response => {
  this.Options.statustypeidOptions = response.data;
});
  },
  
  methods:{
      // 满意度字典表转换
satisFormat(row) {
  return this.selectDictLabel(this.statForamt, row.satisfied);
},

vue3

import { getDicts } from "@/api/system/dict/data";


const {  safe_level } = proxy.useDict("safe_level");
     
    let weaknessVal = {};
    let weaknessLab = {};
    ["safe_level"].map((item) => {
      getDicts(item)
        .then((res) => {
          res.data.map((itm) => {
            console.log("itm", itm);
            weaknessVal[item + itm.dictValue] = itm.dictLabel;
            weaknessLab[itm.dictLabel] = itm.dictValue;
          });
        })
        .then(() => {
          getList();
        });
    });
    
    /** 查询列表 */
    function getList() {
      loading.value = true;
      tableList.value = [{}];
      getDataAssetList(queryParams.value, currId.value).then((response) => {
        tableList.value = response.rows;
        tableList.value.map((item) => {
          item.confidentialType = weaknessVal["safe_level" + item.confidentialType];
        });
        total.value = response.total;
        loading.value = false;
        if (route.query.fileIden) {
          handleUpdate(tableList.value[0]);
        }
      });
    }
    
    
    function submitForm() {
      proxy.$refs["formRef"].validate((valid) => {
        if (valid) {
          form.value.confidentialType = weaknessLab[form.value.confidentialType];
          
          if (form.value.id != undefined) {
            // if (form.value.confidentialType == "敏感信息") {
            //   form.value.confidentialType = 1;
            // } else if (form.value.confidentialType == "核心商密") {
            //   form.value.confidentialType = 2;
            // } else if (form.value.confidentialType == "普通商密") {
            //   form.value.confidentialType = 3;
            // } else if (form.value.confidentialType == "内部") {
            //   form.value.confidentialType = 4;
            // } else if (form.value.confidentialType == "公开") {
            //   form.value.confidentialType = 5;
            // }
            updateDataAsset(form.value).then((response) => {
              if (response.code == 200) {
                proxy.$modal.msgSuccess("修改成功");
                open.value = false;
                getList();
              }
            });
          } else {

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

童小纯

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值