common.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { computed, PropType, ref } from 'vue';
  2. import { createComponent } from '@/packages/utils/create';
  3. const { componentName, translate } = createComponent('fixed-nav');
  4. export const component = (components: any) => {
  5. return {
  6. components,
  7. props: {
  8. visible: {
  9. type: Boolean,
  10. default: false
  11. },
  12. overlay: {
  13. type: Boolean,
  14. default: true
  15. },
  16. navList: {
  17. default: () => [],
  18. type: Array as PropType<any[]>
  19. },
  20. activeColor: {
  21. default: '',
  22. type: String
  23. },
  24. activeText: {
  25. default: '',
  26. type: String
  27. },
  28. unActiveText: {
  29. default: '',
  30. type: String
  31. },
  32. position: {
  33. default: () => {
  34. return {
  35. top: 'auto',
  36. bottom: 'auto'
  37. };
  38. },
  39. type: Object
  40. },
  41. type: {
  42. default: 'right',
  43. type: String
  44. }
  45. },
  46. emits: ['update:visible', 'selected'],
  47. setup(props: any, { emit }: any) {
  48. const classes = computed(() => {
  49. const prefixCls = componentName;
  50. return {
  51. [prefixCls]: true,
  52. active: props.visible,
  53. [props.type]: true
  54. };
  55. });
  56. const current = ref(-1);
  57. const updateValue = (value: boolean = !props.visible) => {
  58. emit('update:visible', value);
  59. };
  60. const selected = (item: any, event: Event) => {
  61. emit('selected', {
  62. item,
  63. event
  64. });
  65. current.value = item.id;
  66. };
  67. return { classes, updateValue, selected, translate, current };
  68. }
  69. };
  70. };