# HtDict 字典组件

HtDict 定义字典组件
Author yangmeng@expservice.com.cn

# 示例

<template>
  <div>
    <ht-form ref-form="dictForm" :form-list="dictFormList" divider="字典组件" :form-style="{width:'800px'}" />
  </div>
</template>
<script>
export default {
  data() {
    return {
      dictFormList: [
        {
          // type : 类型,dic为字典类型
          // format : 格式,允许输入的值
          // dicType:E#是本地实现的字典,多个字典用:分割 例如 KEY1=VALUE1:KEY2=VALUE2……
          // dicType:T#是调用后台的字典
          type: 'dic',
          format: [0, 'isDic', 10],
          dicType: 'E#100601=集团:10602=分公司',
          // dicType:  'T#FUNC-PROVINCE',
          label: '标准字典',
          field: 'dict01'
        },
        {
          type: 'dic',
          format: [0, 'isDic', 100],
          dicType: 'E#100601=集团:10602=分公司',
          label: '多选字典',
          field: 'dictMultiple',
          // multiple 是否允许多选,默认为false
          multiple: true
        },
        {
          type: 'dic',
          format: [0, 'isDic', 10],
          dicType: 'E#100601=集团:10602=分公司',
          label: '字典框禁用',
          field: 'dictDisabled',
          // disabled 是否禁用,默认为false
          disabled: true
        },
        {
          type: 'dic',
          format: [0, 'isDic', 10],
          dicType: 'E#100601=集团:10602=分公司',
          label: '枚举字典',
          field: 'dictEnums'
        },
        {
          type: 'dic',
          format: [0, 'isDic', 10],
          dicType: 'E#100601=集团:10602=分公司',
          label: '过滤字典',
          field: 'dictFilter',
          // filtercode: 过滤条件 可以是正则表达式
          filtercode: '100601|100605' 
        },
        {
          type: 'dic',
          format: [0, 'isDic', 10],
          dicType: 'E#100601=集团:10602=分公司',
          label: '带默认值',
          field: 'dictDefaultVal',
          // value 该对象实际的值
          value: '100601',
          // showLabel 显示的值 类似于select的key值
          showLabel: '集团公司'
        },
        {
          type: 'dic',
          format: [0, 'isDic', 30],
          label: '表选字典',
          field: 'dictTable',
          dicType: 'E#100601=集团:10602=分公司',
          // dicRemote  表选字典请求远程方法
          dicRemote: (dicType, query) => findDictFromTable(dicType, query),
          // cb 字典选中后回调方法
          cb: (row) => this.handleDicCallBack(row)
        }
      ]
    };
  },
  methods: {
    /**
     * @todo: 字典回调方法
     * @author: yangmeng@expservice.com.cn
     * @Date: 2023-05-30 16:35:04
     */
    handleDicCallBack(res) {
      this.$notify.message(res);
    },
  }
};
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Expand Copy

# 后端示例

  • TableDicConstant
/**
 * @Copyright: Copyright (c) 2023 scisoft
 * @remark: 字典通用类
 * @author:yangmeng
 * @date:2023/5/30 10:57
 * @version v1.0.1
 */
public class TableDicConstant
{
    /**
      * @remark:调用后台字典方法
      * @param user:
      * @param vparam:
      * @return: java.lang.String
      * @author: yangmeng
      * @date: 2023/5/30 10:56
      * @version: 1.0.1
      * Modification History:
      * Date       Author          Version            Description
      * ----------------------------------------------------------
      * 2023/5/30     yangmeng        v1.0.1             init
      */
    public static String getTableDic(Map<String, Object> user, String vparam)
    {
      String ret = "";
      String[] arr = {};
      String type;

      //存放参数
      String param = "";

      // 额外的参数,可以用多个逗号分开
      String[] paramsArr;
      if (vparam.contains(":"))
      {
        paramsArr = vparam.split(":");
        type = paramsArr[0];
      } else
        type = vparam;

      //新增截取参数
      if (vparam.indexOf(",") != -1)
      {
        int index = vparam.indexOf(",");
        String[] params = vparam.split(",");
        if (params.length >= 2)
        {
          type = params[0];
          param = vparam.substring(index + 1);
        }
      }

      switch (type)
      {
        //省份
        //调用字典的名称
        //字典查询的格式【每个都用:来分割】EP;
        //ret【json】的第一个冒号前表示 表名【多表可用逗号分隔并用别名】:
        //ret【json】的第二个冒号前表示 字典KEY值【表的列名】:
        //ret【json】的第三个冒号前表示 字典VALUE值【表的列名】{字典可选值}:
        //ret【json】的第三个冒号后表示 SQL查询条件
        case "FUNC-PROVINCE":
          ret = "sys_division:code:sname{code,dname,sname}:type = 20 and code = 130000 " + param;
          break;
      }
      return ret;
    }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

# 版本

  • v1.0.1