DictSelection.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <el-select
  3. v-model="selectVal"
  4. size="small"
  5. style="width: 100%"
  6. v-bind="$attrs"
  7. v-on="$listeners"
  8. >
  9. <el-option
  10. v-for="item in dictList"
  11. :key="item[valueName]"
  12. :value="item[valueName]"
  13. :label="item[labelName]"
  14. ></el-option>
  15. </el-select>
  16. </template>
  17. <script>
  18. import dictEnum from '@/enum/dict';
  19. import { mapActions, mapGetters } from 'vuex';
  20. export default {
  21. model: {
  22. prop: 'value',
  23. event: 'updateVal'
  24. },
  25. props: {
  26. value: {
  27. type: [String, Number],
  28. default: ''
  29. },
  30. dictName: {
  31. type: String,
  32. required: true
  33. },
  34. labelName: {
  35. type: String,
  36. default: 'dictValue'
  37. },
  38. valueName: {
  39. type: String,
  40. default: 'dictCode'
  41. }
  42. },
  43. data() {
  44. return {};
  45. },
  46. computed: {
  47. ...mapGetters(['dict', 'getDict']),
  48. dictList() {
  49. return this.dict[dictEnum[this.dictName]] || [];
  50. },
  51. selectVal: {
  52. set(val) {
  53. this.$emit('updateVal', val);
  54. // change获取选中项所有数据
  55. this.$emit('itemChange', this.getDict(this.dictName, val));
  56. },
  57. get() {
  58. return this.value;
  59. }
  60. }
  61. },
  62. created() {
  63. if (this.dictName) {
  64. this.requestDict(this.dictName);
  65. }
  66. },
  67. methods: {
  68. ...mapActions('dict', ['requestDict'])
  69. }
  70. };
  71. </script>