|
| 1 | +<template> |
| 2 | + <div class="tw-flex tw-relative tw-text-nowrap tw-whitespace-nowrap tw-p-3"> |
| 3 | + <div class="tw-overflow-hidden tw-text-ellipsis "> |
| 4 | + <span class="tw-text-gray-500"> |
| 5 | + {{ getValue() }} |
| 6 | + </span> |
| 7 | + </div> |
| 8 | + |
| 9 | + <AppPopover |
| 10 | + v-if="optionsModel.length > 1" |
| 11 | + v-model="show" |
| 12 | + :hover="false" |
| 13 | + position="bottom" |
| 14 | + class="!tw-absolute tw-right-0 tw-top-0 tw-h-full tw-flex tw-items-center" |
| 15 | + > |
| 16 | + <div |
| 17 | + class="tw-self-center tw-px-2 tw-rounded-md hover:tw-cursor-pointer hover:tw-bg-gray-200 tw-bg-white " |
| 18 | + @click.prevent="onClick" |
| 19 | + > |
| 20 | + <i class="fas fa-ellipsis-v" /> |
| 21 | + </div> |
| 22 | + |
| 23 | + <template #content> |
| 24 | + <ul |
| 25 | + class="tw-bg-white tw-list-none tw-text-gray-600 |
| 26 | + tw-overflow-hidden tw-rounded-lg tw-w-50 tw-text-sm tw-border tw-border-gray-300" |
| 27 | + > |
| 28 | + <template v-for="(option, index) in optionsModel"> |
| 29 | + <li |
| 30 | + v-if="index > 0" |
| 31 | + :key="index" |
| 32 | + class="hover:tw-bg-gray-100" |
| 33 | + > |
| 34 | + <span class="tw-flex tw-py-2 tw-px-4 transition duration-300"> |
| 35 | + {{ getValueOption(option, index) }} |
| 36 | + </span> |
| 37 | + </li> |
| 38 | + </template> |
| 39 | + </ul> |
| 40 | + </template> |
| 41 | + </AppPopover> |
| 42 | + </div> |
| 43 | +</template> |
| 44 | +<script> |
| 45 | +import { defineComponent, ref } from "vue"; |
| 46 | +import { isFunction } from "lodash"; |
| 47 | +import { AppPopover } from "../../../base/index"; |
| 48 | +
|
| 49 | +export default defineComponent({ |
| 50 | + components: { |
| 51 | + AppPopover, |
| 52 | + }, |
| 53 | + props: { |
| 54 | + columns: { |
| 55 | + type: Array, |
| 56 | + default: () => [], |
| 57 | + }, |
| 58 | + column: { |
| 59 | + type: Object, |
| 60 | + default: () => ({}), |
| 61 | + }, |
| 62 | + row: { |
| 63 | + type: Object, |
| 64 | + default: () => ({}), |
| 65 | + }, |
| 66 | + formatterOptions: { |
| 67 | + type: Function, |
| 68 | + default: new Function(), |
| 69 | + }, |
| 70 | + }, |
| 71 | + setup(props) { |
| 72 | + const show = ref(false); |
| 73 | + const optionsModel = ref(props.row[props.column.field]); |
| 74 | +
|
| 75 | + const getValue = () => { |
| 76 | + if (isFunction(props.column?.formatter)) { |
| 77 | + return props.column?.formatter(props.row, props.column, props.columns); |
| 78 | + } |
| 79 | + return props.row[props.column.field].length ? props.row[props.column.field][0].name : ""; |
| 80 | + }; |
| 81 | +
|
| 82 | + const getValueOption = (option) => { |
| 83 | + if (isFunction(props.formatterOptions)) { |
| 84 | + return props.formatterOptions(option, props.row, props.column, props.columns); |
| 85 | + } |
| 86 | + return ""; |
| 87 | + }; |
| 88 | +
|
| 89 | + const onClick = () => { |
| 90 | + show.value = !show.value; |
| 91 | + }; |
| 92 | +
|
| 93 | + const onClose = () => { |
| 94 | + show.value = false; |
| 95 | + }; |
| 96 | +
|
| 97 | + return { |
| 98 | + show, |
| 99 | + optionsModel, |
| 100 | + onClose, |
| 101 | + onClick, |
| 102 | + getValue, |
| 103 | + getValueOption, |
| 104 | + }; |
| 105 | + }, |
| 106 | +}); |
| 107 | +</script> |
0 commit comments