| 1 | <template> |
| 2 | <div> |
| 3 | <n-tooltip v-if="feedback === 'tooltip'" to="body" :disabled="!showFeedback"> |
| 4 | <template #trigger> |
| 5 | <slot v-if="$slots.default" /> |
| 6 | <template v-else> |
| 7 | <Icon v-if="showFeedback" :name="LockIcon" :size="18" /> |
| 8 | <span v-else></span> |
| 9 | </template> |
| 10 | </template> |
| 11 | <div class="flex w-[90vw] max-w-lg! flex-col gap-3"> |
| 12 | <div> |
| 13 | It seems that the feature you are looking for is currently unavailable. To unlock and use it, you |
| 14 | need to enable this feature. You can manage your features from the License page. |
| 15 | </div> |
| 16 | <div class="flex justify-end"> |
| 17 | <n-button @click="routeLicense().navigate()"> |
| 18 | <template #icon> |
| 19 | <Icon :name="LicenseIcon" /> |
| 20 | </template> |
| 21 | View license |
| 22 | </n-button> |
| 23 | </div> |
| 24 | </div> |
| 25 | </n-tooltip> |
| 26 | |
| 27 | <div v-if="showFeedback && feedback === 'overlay'" class="over-layer animate-fade"> |
| 28 | <n-card class="w-[90vw] max-w-lg!"> |
| 29 | <template #header> |
| 30 | <div class="flex items-center gap-3"> |
| 31 | <Icon :name="AlertIcon" :size="18" /> |
| 32 | <span>Feature required</span> |
| 33 | </div> |
| 34 | </template> |
| 35 | <div> |
| 36 | It seems that the feature you are looking for is currently unavailable. To unlock and use it, you |
| 37 | need to enable this feature. You can manage your features from the License page. |
| 38 | </div> |
| 39 | <template #footer> |
| 40 | <div class="flex justify-end"> |
| 41 | <n-button @click="routeLicense().navigate()"> |
| 42 | <template #icon> |
| 43 | <Icon :name="LicenseIcon" /> |
| 44 | </template> |
| 45 | View license |
| 46 | </n-button> |
| 47 | </div> |
| 48 | </template> |
| 49 | </n-card> |
| 50 | </div> |
| 51 | |
| 52 | <n-modal v-model:show="showModal" class="w-[90vw] max-w-lg!" preset="card"> |
| 53 | <template #header> |
| 54 | <div class="flex items-center gap-3"> |
| 55 | <Icon :name="AlertIcon" :size="18" /> |
| 56 | <span>Feature required</span> |
| 57 | </div> |
| 58 | </template> |
| 59 | <div> |
| 60 | It seems that the feature you are looking for is currently unavailable. To unlock and use it, you need |
| 61 | to enable this feature. You can manage your features from the License page. |
| 62 | </div> |
| 63 | <template #footer> |
| 64 | <div class="flex justify-end"> |
| 65 | <n-button @click="routeLicense().navigate()"> |
| 66 | <template #icon> |
| 67 | <Icon :name="LicenseIcon" /> |
| 68 | </template> |
| 69 | View license |
| 70 | </n-button> |
| 71 | </div> |
| 72 | </template> |
| 73 | </n-modal> |
| 74 | </div> |
| 75 | </template> |
| 76 | |
| 77 | <script setup lang="ts"> |
| 78 | import type { LicenseFeatures } from "@/types/license.d" |
| 79 | import { NButton, NCard, NModal, NTooltip } from "naive-ui" |
| 80 | import { ref, watch, watchEffect } from "vue" |
| 81 | import Api from "@/api" |
| 82 | import Icon from "@/components/common/Icon.vue" |
| 83 | import { useNavigation } from "@/composables/useNavigation" |
| 84 | |
| 85 | const { feature, feedback, disabled, forceShowFeedback } = defineProps<{ |
| 86 | feature: LicenseFeatures |
| 87 | feedback?: "overlay" | "alert" | "tooltip" |
| 88 | disabled?: boolean |
| 89 | forceShowFeedback?: boolean |
| 90 | }>() |
| 91 | |
| 92 | const emit = defineEmits<{ |
| 93 | (e: "response", value: boolean): void |
| 94 | (e: "startLoading"): void |
| 95 | (e: "stopLoading"): void |
| 96 | }>() |
| 97 | |
| 98 | const LockIcon = "carbon:locked" |
| 99 | const LicenseIcon = "carbon:license" |
| 100 | const AlertIcon = "mdi:alert-outline" |
| 101 | const loading = ref(false) |
| 102 | const { routeLicense } = useNavigation() |
| 103 | const showFeedback = ref(forceShowFeedback ?? false) |
| 104 | const showModal = ref(false) |
| 105 | |
| 106 | function checkFeature(feature: LicenseFeatures) { |
| 107 | loading.value = true |
| 108 | |
| 109 | Api.license |
| 110 | .isFeatureEnabled(feature) |
| 111 | .then(res => { |
| 112 | if (!res.data.success) { |
| 113 | showFeedback.value = true |
| 114 | emit("response", false) |
| 115 | } else { |
| 116 | emit("response", true) |
| 117 | } |
| 118 | }) |
| 119 | .catch(() => { |
| 120 | showFeedback.value = true |
| 121 | emit("response", false) |
| 122 | }) |
| 123 | .finally(() => { |
| 124 | loading.value = false |
| 125 | }) |
| 126 | } |
| 127 | |
| 128 | watch(showFeedback, val => { |
| 129 | if (val && feedback === "alert") { |
| 130 | showModal.value = true |
| 131 | } |
| 132 | }) |
| 133 | |
| 134 | watch(loading, val => { |
| 135 | if (val) { |
| 136 | emit("startLoading") |
| 137 | } else { |
| 138 | emit("stopLoading") |
| 139 | } |
| 140 | }) |
| 141 | |
| 142 | watch( |
| 143 | [() => disabled, () => feature], |
| 144 | values => { |
| 145 | if (!values[0]) { |
| 146 | checkFeature(values[1]) |
| 147 | } |
| 148 | }, |
| 149 | { immediate: true } |
| 150 | ) |
| 151 | |
| 152 | watchEffect(() => { |
| 153 | showFeedback.value = forceShowFeedback ?? false |
| 154 | }) |
| 155 | </script> |