naf-dict.js 611 B

1234567891011121314151617181920212223242526
  1. /**
  2. * 字典数据处理插件
  3. */
  4. import Vue from 'vue';
  5. import _ from 'lodash';
  6. import assert from 'assert';
  7. const Plugin = {
  8. install(vue, options) {
  9. // 4. 添加实例方法
  10. vue.prototype.$dict = function(codeType, code) {
  11. assert(_.isString(codeType));
  12. const state = this.$store.state.naf.dict;
  13. if (!state) {
  14. throw new Error("can't find store for naf dict");
  15. }
  16. if (_.isString(code)) {
  17. return (state.codes[codeType] && state.codes[codeType][code]) || code;
  18. } else {
  19. return state.items[codeType];
  20. }
  21. };
  22. },
  23. };
  24. Vue.use(Plugin);