SourceItem.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <el-checkbox
  3. size="large"
  4. border
  5. :value="sourceUrl"
  6. :class="{
  7. error: isSaveError,
  8. edit: sourceUrl == currentSourceUrl,
  9. }"
  10. >
  11. {{ getSourceName(source) }}
  12. <el-button text :icon="Edit" @click="handleSourceClick(source)" />
  13. </el-checkbox>
  14. </template>
  15. <script setup lang="ts">
  16. import { Edit } from '@element-plus/icons-vue'
  17. import { getSourceUniqueKey, getSourceName } from '@/utils/souce'
  18. import type { Source } from '@/source'
  19. const props = defineProps<{
  20. source: Source
  21. }>()
  22. const store = useSourceStore()
  23. const currentSourceUrl = computed(() => store.currentSourceUrl)
  24. const sourceUrl = computed(() => getSourceUniqueKey(props.source))
  25. const handleSourceClick = (source: Source) => {
  26. store.changeCurrentSource(source)
  27. }
  28. const isSaveError = computed(() => {
  29. const map = store.savedSourcesMap
  30. if (map.size == 0) return false
  31. return !map.has(sourceUrl.value)
  32. })
  33. </script>
  34. <style lang="scss" scoped>
  35. :deep(.el-checkbox__label) {
  36. flex: 1;
  37. display: flex;
  38. justify-content: space-between;
  39. align-items: center;
  40. }
  41. .error {
  42. border-color: var(--el-color-error) !important;
  43. color: var(--el-color-error) !important;
  44. --el-checkbox-checked-text-color: var(--el-color-error);
  45. --el-checkbox-checked-bg-color: var(--el-color-error);
  46. --el-checkbox-checked-input-border-color: var(--el-color-error);
  47. }
  48. .edit {
  49. border-color: var(--el-color-dark) !important;
  50. }
  51. </style>