index.vue 848 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <!-- 按钮组 -->
  2. <template>
  3. <ul class="app-button-group" v-if="dataList.length">
  4. <li class="app-button-group__item" v-for="(item, index) in dataList" :key="index">
  5. <el-button :type="getButtonType(item.code)" @click="onClick(item.code)">{{ item.label }}</el-button>
  6. </li>
  7. </ul>
  8. </template>
  9. <script lang="ts" setup>
  10. const emit = defineEmits(['click'])
  11. defineProps({
  12. dataList: {
  13. type: Array,
  14. default: () => ([])
  15. }
  16. })
  17. const getButtonType = (code: string) => {
  18. const codes: { [key: string]: string[] } = {
  19. primary: ['trade', 'add', 'modify'],
  20. danger: ['delete'],
  21. };
  22. for (const key in codes) {
  23. if (codes[key].includes(code)) {
  24. return key;
  25. }
  26. }
  27. return 'info';
  28. }
  29. const onClick = (code: string) => {
  30. emit('click', code);
  31. }
  32. </script>
  33. <style lang="less">
  34. @import './index.less';
  35. </style>