|
| 1 | +<template lang="pug"> |
| 2 | +a-dropdown.tables(trigger="click" position="right") |
| 3 | + a-button.menu-button(type="text" @click="(event) => clickMenu(event, nodeData)") |
| 4 | + template(#icon) |
| 5 | + svg.icon-14.rotate-90 |
| 6 | + use(href="#extra") |
| 7 | + template(#content) |
| 8 | + a-doption( |
| 9 | + v-if="!isColumn" |
| 10 | + click.stop |
| 11 | + :class="nodeData.childrenType === 'columns' && expandedKeys?.includes(nodeData.key) ? 'selected' : ''" |
| 12 | + @click="(event) => expandChildren(event, nodeData, 'columns')" |
| 13 | + ) |
| 14 | + template(#icon) |
| 15 | + svg.icon |
| 16 | + use(href="#columns") |
| 17 | + | {{ $t('dashboard.columns') }} |
| 18 | + a-tooltip(position="right" :content="$t('dashboard.hints.details')") |
| 19 | + a-doption( |
| 20 | + v-if="!isColumn" |
| 21 | + :class="nodeData.childrenType === 'details' && expandedKeys?.includes(nodeData.key) ? 'selected' : ''" |
| 22 | + @click="(event) => expandChildren(event, nodeData, 'details')" |
| 23 | + ) |
| 24 | + template(#icon) |
| 25 | + svg.icon |
| 26 | + use(href="#details") |
| 27 | + | {{ $t('dashboard.details') }} |
| 28 | + a-doption(v-if="!isColumn" click.stop) |
| 29 | + a-space(v-for="item of SHORTCUT_MAP['TABLE']") |
| 30 | + ShortCut( |
| 31 | + icon |
| 32 | + :type="item.value" |
| 33 | + :node="nodeData" |
| 34 | + :parent="nodeData.iconType ? expandedTablesTree[nodeData.parentKey] : nodeData" |
| 35 | + :label="'Query table'" |
| 36 | + :database="database" |
| 37 | + ) |
| 38 | + a-doption(v-else) |
| 39 | + a-dropdown.quick-select(trigger="hover" position="right") |
| 40 | + a-space(:size="6") |
| 41 | + svg.icon.icon-color |
| 42 | + use(href="#query") |
| 43 | + | {{ $t('dashboard.quickSelect') }} |
| 44 | + template(#content) |
| 45 | + a-doption(v-for="item of SHORTCUT_MAP[nodeData.iconType]") |
| 46 | + ShortCut( |
| 47 | + :type="item.value" |
| 48 | + :node="nodeData" |
| 49 | + :parent="nodeData.iconType ? expandedTablesTree[nodeData.parentKey] : nodeData" |
| 50 | + :label="item.label" |
| 51 | + :database="database" |
| 52 | + ) |
| 53 | + a-tooltip(content="Copy to Clipboard" position="right") |
| 54 | + a-doption(@click="copy(nodeData.title)") |
| 55 | + template(#icon) |
| 56 | + svg.icon.icon-color(v-if="copied === false") |
| 57 | + use(href="#copy-new") |
| 58 | + svg.icon(v-else) |
| 59 | + icon-check.success-color |
| 60 | + | Copy name |
| 61 | +</template> |
| 62 | + |
| 63 | +<script lang="ts" setup name="TableMenu"> |
| 64 | + import type { TableTreeParent } from '@/store/modules/database/types' |
| 65 | + import type { OptionsType } from '@/types/global' |
| 66 | + import { useClipboard } from '@vueuse/core' |
| 67 | +
|
| 68 | + const props = defineProps<{ |
| 69 | + nodeData: TableTreeParent |
| 70 | + expandedKeys?: number[] |
| 71 | + expandedTablesTree?: TableTreeParent[] |
| 72 | + database: string |
| 73 | + isColumn?: boolean |
| 74 | + }>() |
| 75 | + const emits = defineEmits(['expandChildren']) |
| 76 | + const source = ref('') |
| 77 | + const { copy, copied } = useClipboard({ source }) |
| 78 | +
|
| 79 | + const expandChildren = (event: MouseEvent, nodeData: TableTreeParent, childrenType: string) => { |
| 80 | + event.stopPropagation() |
| 81 | + emits('expandChildren', event, nodeData, childrenType) |
| 82 | + } |
| 83 | +
|
| 84 | + const SHORTCUT_MAP: { [key: string]: OptionsType[] } = { |
| 85 | + TABLE: [{ value: 'select*100', label: 'Query table' }], |
| 86 | + FIELD: [ |
| 87 | + { value: 'select100', label: 'Query column' }, |
| 88 | + { |
| 89 | + value: 'max', |
| 90 | + label: 'Query max', |
| 91 | + }, |
| 92 | + { |
| 93 | + value: 'min', |
| 94 | + label: 'Query min', |
| 95 | + }, |
| 96 | + ], |
| 97 | + TAG: [ |
| 98 | + { value: 'count', label: 'Count by' }, |
| 99 | + { value: 'where=', label: 'Filter by' }, |
| 100 | + ], |
| 101 | + TIMESTAMP: [ |
| 102 | + { value: 'select*100', label: 'Query table' }, |
| 103 | + { |
| 104 | + value: 'where<', |
| 105 | + label: 'Filter by', |
| 106 | + }, |
| 107 | + ], |
| 108 | + } |
| 109 | +
|
| 110 | + const clickMenu = (event: MouseEvent, nodeData: TableTreeParent) => { |
| 111 | + if (props.expandedKeys.includes(nodeData.key)) { |
| 112 | + event.stopPropagation() |
| 113 | + } |
| 114 | + } |
| 115 | +</script> |
| 116 | + |
| 117 | +<style lang="less" scoped> |
| 118 | + :deep(.arco-btn-text[type='button']) { |
| 119 | + color: var(--main-font-color); |
| 120 | + border-radius: 0; |
| 121 | + width: 100%; |
| 122 | + justify-content: flex-start; |
| 123 | + } |
| 124 | +
|
| 125 | + .menu-button { |
| 126 | + display: none; |
| 127 | + } |
| 128 | +
|
| 129 | + .arco-btn.arco-dropdown-open { |
| 130 | + display: flex; |
| 131 | + background: var(--list-hover-color); |
| 132 | + } |
| 133 | +
|
| 134 | + .icon-14 { |
| 135 | + width: 14px; |
| 136 | + height: 14px; |
| 137 | + } |
| 138 | +
|
| 139 | + :deep(.query-icon) { |
| 140 | + width: 14px; |
| 141 | + height: 14px; |
| 142 | + } |
| 143 | +</style> |
| 144 | + |
| 145 | +<style lang="less"> |
| 146 | + .tables { |
| 147 | + .arco-dropdown { |
| 148 | + .arco-dropdown-option { |
| 149 | + &:not(.arco-dropdown-option-disabled, .arco-dropdown-option-has-suffix):hover { |
| 150 | + background-color: var(--list-hover-color); |
| 151 | + } |
| 152 | + .arco-dropdown-option-content { |
| 153 | + .arco-btn-text[type='button'] { |
| 154 | + padding: 0 16px 0 0; |
| 155 | + svg { |
| 156 | + color: var(--small-font-color); |
| 157 | + } |
| 158 | + &:hover { |
| 159 | + background: transparent; |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + &.arco-dropdown-option-has-suffix { |
| 164 | + padding: 0; |
| 165 | + &:hover { |
| 166 | + background: transparent; |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + .arco-dropdown-option.selected { |
| 171 | + color: var(--brand-color); |
| 172 | + svg { |
| 173 | + color: var(--brand-font-color); |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | +</style> |
0 commit comments