src\api\system\dict\data.js

// 根据字典类型查询字典数据信息
export function getDicts(dictType) {return request({url: '/system/dict/data/type/' + dictType,method: 'get'})
}

main.js

import { getDicts } from "@/api/system/dict/data";
// 全局方法挂载
Vue.prototype.getDicts = getDicts

src\components\DictData\index.js

import Vue from 'vue'
import DataDict from '@/utils/dict'
import { getDicts as getDicts } from '@/api/system/dict/data'function install() {Vue.use(DataDict, {metas: {'*': {labelField: 'dictLabel',valueField: 'dictValue',request(dictMeta) {return getDicts(dictMeta.type).then(res => res.data)},},},})
}export default {install,
}

src\utils\dict\Dict.js

import Vue from 'vue'
import { mergeRecursive } from "@/utils/common";
import DictMeta from './DictMeta'
import DictData from './DictData'const DEFAULT_DICT_OPTIONS = {types: [],
}/*** @classdesc 字典* @property {Object} label 标签对象,内部属性名为字典类型名称* @property {Object} dict 字段数组,内部属性名为字典类型名称* @property {Array.<DictMeta>} _dictMetas 字典元数据数组*/
export default class Dict {constructor() {this.owner = nullthis.label = {}this.type = {}}init(options) {if (options instanceof Array) {options = { types: options }}const opts = mergeRecursive(DEFAULT_DICT_OPTIONS, options)if (opts.types === undefined) {throw new Error('need dict types')}const ps = []this._dictMetas = opts.types.map(t => DictMeta.parse(t))this._dictMetas.forEach(dictMeta => {const type = dictMeta.typeVue.set(this.label, type, {})Vue.set(this.type, type, [])if (dictMeta.lazy) {return}ps.push(loadDict(this, dictMeta))})return Promise.all(ps)}/*** 重新加载字典* @param {String} type 字典类型*/reloadDict(type) {const dictMeta = this._dictMetas.find(e => e.type === type)if (dictMeta === undefined) {return Promise.reject(`the dict meta of ${type} was not found`)}return loadDict(this, dictMeta)}
}/*** 加载字典* @param {Dict} dict 字典* @param {DictMeta} dictMeta 字典元数据* @returns {Promise}*/
function loadDict(dict, dictMeta) {return dictMeta.request(dictMeta).then(response => {const type = dictMeta.typelet dicts = dictMeta.responseConverter(response, dictMeta)if (!(dicts instanceof Array)) {console.error('the return of responseConverter must be Array.<DictData>')dicts = []} else if (dicts.filter(d => d instanceof DictData).length !== dicts.length) {console.error('the type of elements in dicts must be DictData')dicts = []}dict.type[type].splice(0, Number.MAX_SAFE_INTEGER, ...dicts)dicts.forEach(d => {Vue.set(dict.label[type], d.value, d.label)})return dicts})
}

若可框架,关于dicts字典的用法相关推荐

  1. [vue 进阶] 关于dicts字典的用法

    前言 在使用若依框架开发小项目的时候,发现在项目中频繁使用到字典,原本代码中的dicts没有深入研究,故自己写了一个混入来实现想要的字典获取功能.但是觉得每次切换页面都需要调用一下,而且每个系统都有一 ...

  2. php中条件查询语句,thinkphp3.2框架中where条件查询用法总结

    本文实例讲述了thinkphp3.2框架中where条件查询用法.分享给大家供大家参考,具体如下: thinkphp3.2 where 条件查询 在连贯操作中条件where的操作有时候自己很晕,所以整 ...

  3. python字典的用法_Python字典的用法详解(附示例)

    本篇文章给大家带来的内容是关于Python字典的用法详解(附示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 字典的表现形式为:{key:value},键和值之间用冒号分隔,每个 ...

  4. python编程字典100例_python中字典(Dictionary)用法实例详解

    本文实例讲述了python中字典(Dictionary)用法.分享给大家供大家参考.具体分析如下: 字典(Dictionary)是一种映射结构的数据类型,由无序的"键-值对"组成. ...

  5. python 字典定义日志用法_python中字典(Dictionary)用法实例详解

    本文实例讲述了python中字典(Dictionary)用法.分享给大家供大家参考.具体分析如下: 字典(Dictionary)是一种映射结构的数据类型,由无序的"键-值对"组成. ...

  6. Android Glide图片加载框架(一)基本用法

    文章目录 一.前言 二.简介 三.基本用法 第一步:调用 Glide.with() 方法创建加载图片的实例 第二步:调用 load() 方法指定待加载的图片资源 第三步:调用 into() 方法绑定显 ...

  7. [转载] python里字典的用法_python中字典(Dictionary)用法实例详解

    参考链接: Python字典dictionary copy方法 本文实例讲述了python中字典(Dictionary)用法.分享给大家供大家参考.具体分析如下: 字典(Dictionary)是一种映 ...

  8. jQuery框架的介绍以及基本用法--操作dom

    jQuery框架的介绍以及基本用法–操作dom 概念 jQuery是一个优秀的javascript轻量级框架之一,兼容css3和各大浏览器,提供了dom,events,animate,ajax等简易操 ...

  9. php ci captcha使用,CodeIgniter框架验证码类库文件与用法示例

    本文实例讲述了CodeIgniter框架验证码类库文件与用法.分享给大家供大家参考,具体如下: 折腾了我四五个小时,终于,ci的验证码类库成功的整出来了. 下面请看源码: 在application/l ...

最新文章

  1. RISV-V未来将面临怎样的挑战?
  2. C#中操作XML (节点添加,修改,删除完整版)
  3. Kotlin 性能优化利器 —— Sqeuence 原理浅析
  4. 【SD】自定义销售订单审批状态
  5. AliExpress:在检索式问答系统中应用迁移学习 | PaperDaily #24
  6. [Python人工智能] 二十六.基于BiLSTM-CRF的医学命名实体识别研究(上)数据预处理
  7. python基础——使用__slots__
  8. css两列布局之基于BFC规则实现
  9. python用缩进来标明代码的层次关系_8-1-Python设计案例.pptx
  10. c语言多线程的建立视频,如何用C语言实现多线程
  11. nginx中root和alias的区别
  12. android操作XML的几种方式(转)
  13. 华为交换机关闭网口_关闭端口的命令 怎么开启华为交换机关闭端口,命令谁知道啊。...
  14. Windows8 RP版亲手体验全过程
  15. Java项目:基于SSM的婚纱影楼管理系统(计算机毕业设计)
  16. SATA Link Power Management的partial和slumber power state区别
  17. TortoiseSVN-1.6.5.16974(开源文件版本管理软件) 安装图解教程及下载文件
  18. c语言实验植物与颜色,植物的光合作用曲线比较.doc
  19. C++中内存数据库SQLite的使用
  20. 递推算法题:王小二刀工之王小二切大饼

热门文章

  1. Clementine Application Templates(CATs)介绍
  2. Java递归求斐波那契数求猴子吃桃
  3. matlab:Lagrange插值函数构造
  4. 用C语言制作Fly bird飞鸟游戏
  5. idea 激活码获取教程及常用命令
  6. cmakelist.txt 编写教程
  7. 基于51单片机电池的电压电流温度电量监控系统设计
  8. 感知机perceptron
  9. 设计模式学习总结(18) 命令模式
  10. buu Reverse学习记录(19) [GWCTF 2019]pyre