SourceItem.vue 1.4 KB

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