Skip to content

Commit

Permalink
fix:收藏链接修改错误的问题(无id标识符)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanoqwq committed Nov 1, 2024
1 parent f740896 commit 82b6cfb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
9 changes: 5 additions & 4 deletions src/components/Favorites/AddLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ watch(
() => props.data,
() => {
if (props.data) {
link.id = props.data.id;
link.imgUrl = props.data.imgUrl;
link.href = props.data.href;
link.isBlank = props.data.isBlank;
Expand Down Expand Up @@ -135,10 +136,6 @@ const save = () => {
} else {
Configs.setFavLink(toRaw(link));
}
//清空并初始化
link.href = '';
link.imgUrl = '';
link.isBlank = true;
Toast({
value: props.showEdit ? '保存成功~' : '添加成功~',
color: 'green',
Expand All @@ -155,6 +152,10 @@ const save = () => {
} finally {
setTimeout(() => {
dialogisDisplay.value = false;
//清空并初始化
link.href = '';
link.imgUrl = '';
link.isBlank = true;
emit('onclose');
}, 300);
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/Favorites/Favorites.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:clickable="true"
:showOpt="false"
:href="item.href"
:id="item.id"
:imgUrl="item.imgUrl"
:isBlank="item.isBlank" />
</template>
Expand All @@ -20,6 +21,7 @@
:clickable="false"
:showOpt="true"
:href="item.href"
:id="item.id"
:imgUrl="item.imgUrl"
:isBlank="item.isBlank" />
</template>
Expand Down Expand Up @@ -48,6 +50,7 @@ defineProps({
});
const Configs = useStore.Configs();
const editData = ref({
id: -1,
imgUrl: '',
href: '',
isBlank: true,
Expand All @@ -58,9 +61,10 @@ const editLinkShow = ref(false);
const edit = (item: any) => {
editLinkShow.value = true;
editData.value = {
id: item.id,
imgUrl: item.imgUrl,
href: item.href,
isBlank: true,
isBlank: item.isBlank,
};
};
const onClose = () => {
Expand Down
5 changes: 3 additions & 2 deletions src/components/Favorites/LinkButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { ref } from 'vue';
import Modal from '@/components/Modal/index.vue';
const props = defineProps<{
id: number;
href: string;
imgUrl: string;
isBlank?: boolean;
Expand All @@ -67,10 +68,10 @@ let btnClass =
'rounded dark:dark-btn p-2 bg-stone-300 transition-all hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-600 focus:ring-opacity-50';
const close = () => {
if (props.href) {
if (props.id) {
isShowConfrim.value = false;
setTimeout(() => {
Configs.removeFavLinkByUrl(props.href);
Configs.removeFavLink(props.id);
}, 300);
Toast({
value: '删除成功~',
Expand Down
23 changes: 11 additions & 12 deletions src/store/Configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,15 @@ export const Configs = defineStore("Configs", {
},
//修改常用链接
updateFavLink(linkObj: LinkObj) {
let curLinksIndex: number = this.favLinks.findIndex(item => item.href.trim() == linkObj.href.trim())
//如在现有列表重找到url一致的标签,则进行替换
if (curLinksIndex !== -1) {
if (linkObj) {
this.favLinks[curLinksIndex] = {
href: linkObj.href.trim(),
imgUrl: linkObj.imgUrl.trim(),
isBlank: linkObj.isBlank
}
setItem("favLinks", this.favLinks)
if (linkObj.id) {
let curLinksIndex: number = this.favLinks.findIndex(item => item.id == linkObj.id)
this.favLinks[curLinksIndex] = {
id: this.favLinks[curLinksIndex].id,
href: linkObj.href.trim(),
imgUrl: linkObj.imgUrl.trim(),
isBlank: linkObj.isBlank
}
setItem("favLinks", this.favLinks)
}
},
// 设置常用链接
Expand All @@ -124,6 +122,7 @@ export const Configs = defineStore("Configs", {
} else {
if (linkObj) {
this.favLinks.push({
id: this.favLinks.length + 1,
href: linkObj.href.trim(),
imgUrl: linkObj.imgUrl.trim(),
isBlank: linkObj.isBlank
Expand All @@ -133,8 +132,8 @@ export const Configs = defineStore("Configs", {
}
},
//删除指定链接
removeFavLinkByUrl(href: string) {
const newFavLinks = this.favLinks.filter(item => item.href != href)
removeFavLink(id: number) {
const newFavLinks = this.favLinks.filter(item => item.id != id)
this.favLinks = newFavLinks
setItem("favLinks", newFavLinks)
},
Expand Down
1 change: 1 addition & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface SearchEngine {


interface LinkObj {
id?: number,
href: string,
imgUrl: string,
isBlank?: boolean,
Expand Down

0 comments on commit 82b6cfb

Please sign in to comment.