fix(web): 源修改后列表多选异常 添加编辑按钮

close #3051
This commit is contained in:
Xwite
2023-05-04 13:31:17 +08:00
parent d70b685f47
commit ddfe95e7fd
2 changed files with 41 additions and 12 deletions
+20 -5
View File
@@ -2,23 +2,35 @@
<el-checkbox <el-checkbox
size="large" size="large"
border border
:label="source" :label="sourceUrl"
:class="{ error: errorPushSources.includes(source) }" :class="{
@change="handleSourceClick(source)" error: errorPushSources.includes(source),
edit: sourceUrl == currentSourceUrl,
}"
> >
{{ source.bookSourceName || source.sourceName }} {{ source.bookSourceName || source.sourceName }}
<el-button text :icon="Edit" @click="handleSourceClick(source)" />
</el-checkbox> </el-checkbox>
</template> </template>
<script setup> <script setup>
defineProps(["source"]); import { Edit } from "@element-plus/icons-vue";
const props = defineProps(["source"]);
const sourceUrl = props.source.bookSourceUrl || props.source.sourceUrl;
const store = useSourceStore(); const store = useSourceStore();
const { errorPushSources } = storeToRefs(store); const { errorPushSources, currentSourceUrl } = storeToRefs(store);
const handleSourceClick = (source) => { const handleSourceClick = (source) => {
store.changeCurrentSource(source); store.changeCurrentSource(source);
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
:deep(.el-checkbox__label) {
flex: 1;
display: flex;
justify-content: space-between;
align-items: center;
}
.error { .error {
border-color: var(--el-color-error) !important; border-color: var(--el-color-error) !important;
color: var(--el-color-error) !important; color: var(--el-color-error) !important;
@@ -26,4 +38,7 @@ const handleSourceClick = (source) => {
--el-checkbox-checked-bg-color: var(--el-color-error); --el-checkbox-checked-bg-color: var(--el-color-error);
--el-checkbox-checked-input-border-color: var(--el-color-error); --el-checkbox-checked-input-border-color: var(--el-color-error);
} }
.edit {
border-color: var(--el-color-dark) !important;
}
</style> </style>
+21 -7
View File
@@ -18,7 +18,7 @@
type="danger" type="danger"
:icon="Delete" :icon="Delete"
@click="deleteSelectSources" @click="deleteSelectSources"
:disabled="sourceSelect.length === 0" :disabled="sourceUrlSelect.length === 0"
>删除</el-button >删除</el-button
> >
<el-button <el-button
@@ -29,7 +29,7 @@
>清空</el-button >清空</el-button
> >
</div> </div>
<el-checkbox-group id="source-list" v-model="sourceSelect"> <el-checkbox-group id="source-list" v-model="sourceUrlSelect">
<virtual-list <virtual-list
style="height: 100%; overflow-y: auto; overflow-x: hidden" style="height: 100%; overflow-y: auto; overflow-x: hidden"
:data-key="(source) => source.bookSourceUrl || source.sourceUrl" :data-key="(source) => source.bookSourceUrl || source.sourceUrl"
@@ -48,22 +48,37 @@ import VirtualList from "vue3-virtual-scroll-list";
import SourceItem from "./SourceItem.vue"; import SourceItem from "./SourceItem.vue";
const store = useSourceStore(); const store = useSourceStore();
const sourceSelect = ref([]); const sourceUrlSelect = ref([]);
const searchKey = ref(""); const searchKey = ref("");
const { sources } = storeToRefs(store); const { sources } = storeToRefs(store);
const isBookSource = computed(() => { const isBookSource = computed(() => {
return /bookSource/.test(window.location.href); return /bookSource/.test(window.location.href);
}); });
const sourceSelect = computed(() => {
let temp = sourceUrlSelect.value,
selectUrlsLength = temp.length;
if (selectUrlsLength == 0) return [];
let searchKey = "sourceUrl";
if (isBookSource.value) searchKey = "bookSourceUrl";
return sources.value.filter((source) => {
let searchIndex = temp.indexOf(source[searchKey]);
if (searchIndex > -1) {
temp.splice(searchIndex, 1);
return true;
}
return false;
});
});
const deleteSelectSources = () => { const deleteSelectSources = () => {
API.deleteSource(sourceSelect.value).then(({ data }) => { API.deleteSource(sourceSelect.value).then(({ data }) => {
if (!data.isSuccess) return ElMessage.error(data.errorMsg); if (!data.isSuccess) return ElMessage.error(data.errorMsg);
store.deleteSources(sourceSelect.value); store.deleteSources(sourceSelect.value);
sourceSelect.value = []; sourceUrlSelect.value = [];
}); });
}; };
const clearAllSources = () => { const clearAllSources = () => {
store.clearAllSource(); store.clearAllSource();
sourceSelect.value = []; sourceUrlSelect.value = [];
}; };
//筛选源 //筛选源
const sourcesFiltered = computed(() => { const sourcesFiltered = computed(() => {
@@ -104,7 +119,7 @@ const importSourceFile = () => {
const outExport = () => { const outExport = () => {
const exportFile = document.createElement("a"); const exportFile = document.createElement("a");
let sources = let sources =
sourceSelect.value.length === 0 sourceUrlSelect.value.length === 0
? sourcesFiltered.value ? sourcesFiltered.value
: sourceSelect.value, : sourceSelect.value,
sourceType = isBookSource.value ? "BookSource" : "RssSource"; sourceType = isBookSource.value ? "BookSource" : "RssSource";
@@ -131,7 +146,6 @@ const outExport = () => {
#source-list { #source-list {
margin-top: 6px; margin-top: 6px;
height: calc(100vh - 112px - 7px); height: calc(100vh - 112px - 7px);
:deep(.el-checkbox) { :deep(.el-checkbox) {
margin-bottom: 4px; margin-bottom: 4px;
width: 100%; width: 100%;