Showing
3 changed files
with
28 additions
and
0 deletions
| @@ -6,6 +6,7 @@ import { CardMediaInfo } from '../cardCommon/CardMediaInfo'; | @@ -6,6 +6,7 @@ import { CardMediaInfo } from '../cardCommon/CardMediaInfo'; | ||
| 6 | import { CardSourceInfo } from '../cardCommon/CardSourceInfo'; | 6 | import { CardSourceInfo } from '../cardCommon/CardSourceInfo'; |
| 7 | import { Notes } from './notes'; | 7 | import { Notes } from './notes'; |
| 8 | import { onlyWifiLoadImg } from '../../utils/lazyloadImg'; | 8 | import { onlyWifiLoadImg } from '../../utils/lazyloadImg'; |
| 9 | +import { persistentStorage, hasClicked } from '../../utils/persistentStorage'; | ||
| 9 | 10 | ||
| 10 | const TAG: string = 'Card2Component'; | 11 | const TAG: string = 'Card2Component'; |
| 11 | 12 | ||
| @@ -24,6 +25,7 @@ export struct Card2Component { | @@ -24,6 +25,7 @@ export struct Card2Component { | ||
| 24 | 25 | ||
| 25 | async aboutToAppear(): Promise<void> { | 26 | async aboutToAppear(): Promise<void> { |
| 26 | this.loadImg = await onlyWifiLoadImg(); | 27 | this.loadImg = await onlyWifiLoadImg(); |
| 28 | + this.clicked = hasClicked(this.contentDTO.objectId) | ||
| 27 | } | 29 | } |
| 28 | 30 | ||
| 29 | build() { | 31 | build() { |
| @@ -75,6 +77,7 @@ export struct Card2Component { | @@ -75,6 +77,7 @@ export struct Card2Component { | ||
| 75 | }) | 77 | }) |
| 76 | .onClick((event: ClickEvent) => { | 78 | .onClick((event: ClickEvent) => { |
| 77 | this.clicked = true; | 79 | this.clicked = true; |
| 80 | + persistentStorage(this.contentDTO.objectId); | ||
| 78 | ProcessUtils.processPage(this.contentDTO) | 81 | ProcessUtils.processPage(this.contentDTO) |
| 79 | }) | 82 | }) |
| 80 | } | 83 | } |
| @@ -5,6 +5,7 @@ import { CardSourceInfo } from '../cardCommon/CardSourceInfo'; | @@ -5,6 +5,7 @@ import { CardSourceInfo } from '../cardCommon/CardSourceInfo'; | ||
| 5 | import { CardMediaInfo } from '../cardCommon/CardMediaInfo'; | 5 | import { CardMediaInfo } from '../cardCommon/CardMediaInfo'; |
| 6 | import { Notes } from './notes'; | 6 | import { Notes } from './notes'; |
| 7 | import { onlyWifiLoadImg } from '../../utils/lazyloadImg'; | 7 | import { onlyWifiLoadImg } from '../../utils/lazyloadImg'; |
| 8 | +import { persistentStorage, hasClicked } from '../../utils/persistentStorage'; | ||
| 8 | 9 | ||
| 9 | const TAG: string = 'Card6Component-Card13Component'; | 10 | const TAG: string = 'Card6Component-Card13Component'; |
| 10 | 11 | ||
| @@ -19,6 +20,7 @@ export struct Card6Component { | @@ -19,6 +20,7 @@ export struct Card6Component { | ||
| 19 | 20 | ||
| 20 | async aboutToAppear(): Promise<void> { | 21 | async aboutToAppear(): Promise<void> { |
| 21 | this.loadImg = await onlyWifiLoadImg(); | 22 | this.loadImg = await onlyWifiLoadImg(); |
| 23 | + this.clicked = hasClicked(this.contentDTO.objectId) | ||
| 22 | } | 24 | } |
| 23 | 25 | ||
| 24 | build() { | 26 | build() { |
| @@ -78,6 +80,7 @@ export struct Card6Component { | @@ -78,6 +80,7 @@ export struct Card6Component { | ||
| 78 | } | 80 | } |
| 79 | .onClick((event: ClickEvent) => { | 81 | .onClick((event: ClickEvent) => { |
| 80 | this.clicked = true; | 82 | this.clicked = true; |
| 83 | + persistentStorage(this.contentDTO.objectId); | ||
| 81 | ProcessUtils.processPage(this.contentDTO) | 84 | ProcessUtils.processPage(this.contentDTO) |
| 82 | }) | 85 | }) |
| 83 | .padding({ | 86 | .padding({ |
| 1 | +PersistentStorage.persistProp('clickedIds', []); | ||
| 2 | + | ||
| 3 | +function persistentStorage(id: string | number, type: 'add' | 'remove' | undefined = 'add') { | ||
| 4 | + let clickedIds = AppStorage.get<string>('clickedIds')?.split(',') || []; | ||
| 5 | + let index = clickedIds.indexOf(id.toString()) | ||
| 6 | + if (type === 'add') { | ||
| 7 | + if (index >= 0) return; | ||
| 8 | + clickedIds.push(id.toString()); | ||
| 9 | + } else if (type === 'remove') { | ||
| 10 | + clickedIds.splice(index, 1); | ||
| 11 | + } | ||
| 12 | + AppStorage.set('clickedIds', clickedIds.join(',')); | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +function hasClicked(id: string | number) { | ||
| 16 | + let clickedIds = AppStorage.get<string>('clickedIds')?.split(',') || []; | ||
| 17 | + let index = clickedIds.indexOf(id.toString()) | ||
| 18 | + if (index >= 0) return true; | ||
| 19 | + return false; | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +export { persistentStorage, hasClicked } |
-
Please register or login to post a comment