naf-policy.js 603 B

12345678910111213141516171819202122232425262728
  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.$policy = function(key) {
  11. assert(_.isString(key));
  12. const state = this.$store.state.naf.policy;
  13. if (!state) {
  14. throw new Error("can't find store for naf policy");
  15. }
  16. for (const i in state.items) {
  17. if (state.items[i].key == key) {
  18. return state.items[i].value;
  19. } else {
  20. return 0;
  21. }
  22. }
  23. };
  24. },
  25. };
  26. Vue.use(Plugin);