From 07b168509f9219c65c569c7a46a526299febce9b Mon Sep 17 00:00:00 2001 From: TriDiamond Date: Mon, 3 May 2021 23:02:06 +0800 Subject: [PATCH] Fixed Dropdown component test fail. - Fixed all eslint errors. --- src/App.vue | 14 +++++----- src/components/Dia.vue | 2 +- src/components/Dropdown/src/Dropdown.vue | 6 ++--- src/components/MobileMenu.vue | 2 +- src/components/Navigator.vue | 4 ++- src/components/PageContainer.vue | 10 ++++---- src/components/SearchModal.vue | 2 +- src/components/Sidebar/src/Profile.vue | 2 +- src/components/Sidebar/src/RecentComment.vue | 4 +-- src/components/Sidebar/src/Sidebar.vue | 6 ++--- src/locales/index.ts | 2 +- src/models/Search.class.ts | 4 +-- src/stores/app.ts | 17 +----------- src/stores/article.ts | 2 +- src/stores/author.ts | 2 +- src/stores/category.ts | 2 +- src/stores/common.ts | 27 ++++++++++++++++++++ src/stores/post.ts | 12 ++++----- src/stores/search.ts | 2 +- src/stores/tag.ts | 4 +-- src/utils/aurora-dia/index.ts | 18 ++++++------- src/utils/external-request.ts | 8 +++--- src/utils/github-api.ts | 24 ++++++++--------- src/utils/leancloud-api.ts | 2 +- src/utils/request.ts | 8 +++--- src/views/Archives.vue | 8 +++--- src/views/Post.vue | 8 +++--- src/views/Result.vue | 4 +-- src/views/Tag.vue | 8 +++--- 29 files changed, 115 insertions(+), 99 deletions(-) create mode 100644 src/stores/common.ts diff --git a/src/App.vue b/src/App.vue index ad15b509..6a4e6957 100644 --- a/src/App.vue +++ b/src/App.vue @@ -44,6 +44,7 @@ import { watch } from 'vue' import { useAppStore } from '@/stores/app' +import { useCommonStore } from '@/stores/common' import { useMetaStore } from '@/stores/meta' import { useSearchStore } from './stores/search' import HeaderMain from '@/components/Header/src/Header.vue' @@ -63,6 +64,7 @@ export default defineComponent({ }, setup() { const appStore = useAppStore() + const commonStore = useCommonStore() const metaStore = useMetaStore() const searchStore = useSearchStore() const MOBILE_WITH = 996 // Using the mobile width by Bootstrap design. @@ -128,14 +130,14 @@ export default defineComponent({ } const isMobile = computed(() => { - return appStore.isMobile + return commonStore.isMobile }) const resizeHanler = () => { const rect = document.body.getBoundingClientRect() const mobileState = rect.width - 1 < MOBILE_WITH if (isMobile.value !== mobileState) - appStore.changeMobileState(mobileState) + commonStore.changeMobileState(mobileState) } const initResizeEvent = () => { @@ -187,20 +189,20 @@ export default defineComponent({ headerImage: computed(() => { return { backgroundImage: `url(${ - appStore.headerImage + commonStore.headerImage }), url(${require('@/assets/default-cover.jpg')})`, - opacity: appStore.headerImage !== '' ? 1 : 0 + opacity: commonStore.headerImage !== '' ? 1 : 0 } }), headerBaseBackground: computed(() => { return { background: appStore.themeConfig.theme.header_gradient_css, - opacity: appStore.headerImage !== '' ? 0.91 : 0.99 + opacity: commonStore.headerImage !== '' ? 0.91 : 0.99 } }), wrapperStyle: computed(() => wrapperStyle.value), handleEscKey: appStore.handleEscKey, - isMobile: computed(() => appStore.isMobile), + isMobile: computed(() => commonStore.isMobile), configReady: computed(() => appStore.configReady), cssVariables: computed(() => { if (appStore.theme === 'theme-dark') { diff --git a/src/components/Dia.vue b/src/components/Dia.vue index 7ed00642..09d05bd6 100644 --- a/src/components/Dia.vue +++ b/src/components/Dia.vue @@ -42,7 +42,7 @@ export default defineComponent({ watch( () => appStore.configReady, - (value) => { + value => { if (value) { initializeBot() } diff --git a/src/components/Dropdown/src/Dropdown.vue b/src/components/Dropdown/src/Dropdown.vue index 368fee2e..c5f609e3 100644 --- a/src/components/Dropdown/src/Dropdown.vue +++ b/src/components/Dropdown/src/Dropdown.vue @@ -13,7 +13,7 @@ diff --git a/src/locales/index.ts b/src/locales/index.ts index af2f8ab4..9a93893b 100644 --- a/src/locales/index.ts +++ b/src/locales/index.ts @@ -11,7 +11,7 @@ function loadLocaleMessages(): { const messages: { [key: string]: { [key: string]: { [key: string]: string } } } = {} - locales.keys().forEach((key) => { + locales.keys().forEach(key => { const matched = key.match(/([A-Za-z0-9-_]+)\./i) if (matched && matched.length > 1) { const locale = matched[1] diff --git a/src/models/Search.class.ts b/src/models/Search.class.ts index fffb136b..e65255fc 100644 --- a/src/models/Search.class.ts +++ b/src/models/Search.class.ts @@ -53,7 +53,7 @@ export class RecentSearchResults { } initData(data: { [key: string]: string }[]): void { - data.forEach((value) => { + data.forEach(value => { this.add(value) }) } @@ -162,7 +162,7 @@ export class SearchIndexes { const matchedResult: SearchResultType[] = [] - this.indexes.forEach((data) => { + this.indexes.forEach(data => { if (!data.title || data.title.trim() === '') data.title = 'Untitled' const originalTitle = data.title.trim() diff --git a/src/stores/app.ts b/src/stores/app.ts index 0ad7fd7e..2faf3d3c 100644 --- a/src/stores/app.ts +++ b/src/stores/app.ts @@ -63,12 +63,8 @@ export const useAppStore = defineStore({ loadingTimeout: -1, /** Tracking if the blog config is ready */ configReady: false, - /** Header image url */ - headerImage: '', /** Is search modal opened */ - openSearchModal: false, - /** If current window with is for mobile */ - isMobile: false + openSearchModal: false }), getters: { getTheme(): string { @@ -150,14 +146,6 @@ export const useAppStore = defineStore({ this.appLoading = false }, 300) }, - /** Setting the image url for the header */ - setHeaderImage(imageUrl: string) { - this.headerImage = imageUrl - }, - /** Resetting the header image to null */ - resetHeaderImage() { - this.headerImage = '' - }, changeOpenModal(status: boolean) { this.openSearchModal = status }, @@ -166,9 +154,6 @@ export const useAppStore = defineStore({ }, handleSearchOpen() { if (!this.openSearchModal) this.openSearchModal = true - }, - changeMobileState(isMobile: boolean) { - this.isMobile = isMobile } } }) diff --git a/src/stores/article.ts b/src/stores/article.ts index 914a2482..116b07f4 100644 --- a/src/stores/article.ts +++ b/src/stores/article.ts @@ -11,7 +11,7 @@ export const useArticleStore = defineStore({ actions: { async fetchArticle(source: string): Promise { const { data } = await fetchImplicitPageBySource(source) - return new Promise((resolve) => + return new Promise(resolve => setTimeout(() => { resolve(new Page(data)) }, 200) diff --git a/src/stores/author.ts b/src/stores/author.ts index 3881ba8e..138e1897 100644 --- a/src/stores/author.ts +++ b/src/stores/author.ts @@ -12,7 +12,7 @@ export const useAuthorStore = defineStore({ /** Fetching author's info */ async fetchAuthorData(slug: string): Promise { const { data } = await fetchAuthorPost(slug) - return new Promise((resolve) => { + return new Promise(resolve => { resolve(new AuthorPosts(data)) }) } diff --git a/src/stores/category.ts b/src/stores/category.ts index 0098f2ac..4d3cc4f4 100644 --- a/src/stores/category.ts +++ b/src/stores/category.ts @@ -15,7 +15,7 @@ export const useCategoryStore = defineStore({ async fetchCategories() { this.isLoaded = false const { data } = await fetchAllCategories() - return new Promise((resolve) => { + return new Promise(resolve => { this.isLoaded = true this.categories = new Categories(data).data resolve(this.categories) diff --git a/src/stores/common.ts b/src/stores/common.ts new file mode 100644 index 00000000..be612f55 --- /dev/null +++ b/src/stores/common.ts @@ -0,0 +1,27 @@ +import { defineStore } from 'pinia' + +export const useCommonStore = defineStore({ + // id is the name of the store + // it is used in devtools and allows restoring state + id: 'commonStore', + state: () => ({ + /** If current window width is for mobile */ + isMobile: false, + /** Header image url */ + headerImage: '' + }), + getters: {}, + actions: { + /** Setting the image url for the header */ + setHeaderImage(imageUrl: string) { + this.headerImage = imageUrl + }, + /** Resetting the header image to null */ + resetHeaderImage() { + this.headerImage = '' + }, + changeMobileState(isMobile: boolean) { + this.isMobile = isMobile + } + } +}) diff --git a/src/stores/post.ts b/src/stores/post.ts index 195b2291..43ba72b6 100644 --- a/src/stores/post.ts +++ b/src/stores/post.ts @@ -32,7 +32,7 @@ export const usePostStore = defineStore({ actions: { async fetchFeaturePosts() { const { data } = await fetchFeature() - return new Promise((resolve) => + return new Promise(resolve => setTimeout(() => { this.featurePosts = new FeaturePosts(data) resolve(this.featurePosts) @@ -42,7 +42,7 @@ export const usePostStore = defineStore({ async fetchPostsList(page?: number): Promise { if (!page) page = 1 const { data } = await fetchPostsList(page) - return new Promise((resolve) => + return new Promise(resolve => setTimeout(() => { this.posts = new PostList(data) this.postTotal = this.posts.total @@ -53,7 +53,7 @@ export const usePostStore = defineStore({ async fetchArchives(page?: number): Promise { if (!page) page = 1 const { data } = await fetchPostsList(page) - return new Promise((resolve) => + return new Promise(resolve => setTimeout(() => { resolve(new Archives(data)) }, 200) @@ -61,7 +61,7 @@ export const usePostStore = defineStore({ }, async fetchPost(slug: string): Promise { const { data } = await fetchPostBySlug(slug) - return new Promise((resolve) => + return new Promise(resolve => setTimeout(() => { resolve(new Post(data)) }, 200) @@ -69,7 +69,7 @@ export const usePostStore = defineStore({ }, async fetchPostsByCategory(category: string): Promise { const { data } = await fetchPostsListByCategory(category) - return new Promise((resolve) => + return new Promise(resolve => setTimeout(() => { resolve(new SpecificPostsList(data)) }, 200) @@ -77,7 +77,7 @@ export const usePostStore = defineStore({ }, async fetchPostsByTag(slug: string): Promise { const { data } = await fetchPostsListByTag(slug) - return new Promise((resolve) => { + return new Promise(resolve => { setTimeout(() => { resolve(new SpecificPostsList(data)) }, 200) diff --git a/src/stores/search.ts b/src/stores/search.ts index 64fb9e1b..8eebe234 100644 --- a/src/stores/search.ts +++ b/src/stores/search.ts @@ -21,7 +21,7 @@ export const useSearchStore = defineStore({ async fetchSearchIndex(): Promise { const { data } = await fetchSearchIndexes() this.searchIndexes = new SearchIndexes(data) - return new Promise((resolve) => { + return new Promise(resolve => { resolve(this.searchIndexes) }) }, diff --git a/src/stores/tag.ts b/src/stores/tag.ts index 6cd06334..ec55aa96 100644 --- a/src/stores/tag.ts +++ b/src/stores/tag.ts @@ -14,7 +14,7 @@ export const useTagStore = defineStore({ actions: { async fetchAllTags() { const { data } = await fetchAllTags() - return new Promise((resolve) => { + return new Promise(resolve => { this.tags = new Tags(data).data resolve(this.tags) }) @@ -22,7 +22,7 @@ export const useTagStore = defineStore({ async fetchTagsByCount(count: number) { this.isLoaded = false const { data } = await fetchAllTags() - return new Promise((resolve) => { + return new Promise(resolve => { this.isLoaded = true const maxLength = data.length > count ? count : data.length this.tags = new Tags(data.splice(0, maxLength)).data diff --git a/src/utils/aurora-dia/index.ts b/src/utils/aurora-dia/index.ts index 01b62fde..c7000177 100644 --- a/src/utils/aurora-dia/index.ts +++ b/src/utils/aurora-dia/index.ts @@ -86,7 +86,7 @@ export class AuroraDia { rightEye instanceof HTMLElement && eyesEl instanceof HTMLElement ) { - document.addEventListener('mousemove', (evt) => { + document.addEventListener('mousemove', evt => { clearTimeout(this.eyesAnimationTimer) eyesEl.classList.add('moving') const x = -(eyesEl.getBoundingClientRect().left - evt.clientX) / 100 @@ -182,7 +182,7 @@ class AuroraBotSoftware { botScriptKeys = Object.keys(botScript) if (botScriptKeys.length > 0) { - botScriptKeys.forEach((key) => { + botScriptKeys.forEach(key => { this.botTips[key] = botScript[key] }) } @@ -206,7 +206,7 @@ class AuroraBotSoftware { }) // Mouseover tips if (this.botTips.mouseover && this.botTips.mouseover.length > 0) { - document.addEventListener('mouseover', (event) => { + document.addEventListener('mouseover', event => { for (const mouseoverEvents of this.botTips.mouseover) { const selector = mouseoverEvents.selector let text = mouseoverEvents.text @@ -234,7 +234,7 @@ class AuroraBotSoftware { } // onClick event if (this.botTips.click && this.botTips.click.length > 0) { - document.addEventListener('click', (event) => { + document.addEventListener('click', event => { if (event.target && event.target instanceof HTMLElement) for (const mouseoverEvents of this.botTips.click) { const selector = mouseoverEvents.selector @@ -330,7 +330,7 @@ class AuroraBotSoftware { [key: string]: { [key: string]: { [key: string]: string } } } = {} - locales.keys().forEach((key) => { + locales.keys().forEach(key => { const matched = key.match(/([A-Za-z0-9-_]+)\./i) if (matched && matched.length > 1) { const locale = matched[1] @@ -395,16 +395,16 @@ class AuroraBotSoftware { getHitokoto() { fetch('https://v1.hitokoto.cn') - .then((response) => response.json()) - .then((result) => { + .then(response => response.json()) + .then(result => { this.showMessage(result.hitokoto, 6000, 9) }) } getTheySaidSo() { fetch('https://quotes.rest/qod?language=en') - .then((response) => response.json()) - .then((result) => { + .then(response => response.json()) + .then(result => { this.showMessage(result.contents.quotes[0].quote, 6000, 9) }) } diff --git a/src/utils/external-request.ts b/src/utils/external-request.ts index e76664ea..077e5592 100644 --- a/src/utils/external-request.ts +++ b/src/utils/external-request.ts @@ -8,11 +8,11 @@ const service = axios.create({ // request interceptor service.interceptors.request.use( - (config) => { + config => { // do something before request is sent return config }, - (error) => { + error => { // do something with request error console.log(error) // for debug return Promise.reject(error) @@ -31,11 +31,11 @@ service.interceptors.response.use( * Here is just an example * You can also judge the status by HTTP Status Code */ - (response) => { + response => { // Login or other response handle place here. return response }, - (error) => { + error => { console.log('err' + error) // for debug console.error(error.message) return Promise.reject(error) diff --git a/src/utils/github-api.ts b/src/utils/github-api.ts index b7d76fef..b4a697a0 100644 --- a/src/utils/github-api.ts +++ b/src/utils/github-api.ts @@ -68,13 +68,13 @@ export class GithubComments implements GithubCommentsInterface { } async getComments(): Promise { - return new Promise((resolve) => { + return new Promise(resolve => { const cacheComments = this.getCache() if (cacheComments.isValid()) { this.comments = cacheComments.data resolve(this.comments) } else { - this.fetchCommentData().then((comments) => { + this.fetchCommentData().then(comments => { resolve(comments) }) } @@ -115,17 +115,15 @@ export class GithubComments implements GithubCommentsInterface { this.configs.repo + '/comments?sort=created&direction=desc&per_page=7&page=1' - return new Promise((resolve) => { - this.fetchGithub(url, this.configs.authorizationToken).then( - (response) => { - const { data } = response - this.comments = data.map((item: { [key: string]: any }) => { - return new GithubComment(item, this.configs) - }) - this.setCache(this.comments) - resolve(this.comments) - } - ) + return new Promise(resolve => { + this.fetchGithub(url, this.configs.authorizationToken).then(response => { + const { data } = response + this.comments = data.map((item: { [key: string]: any }) => { + return new GithubComment(item, this.configs) + }) + this.setCache(this.comments) + resolve(this.comments) + }) }) } diff --git a/src/utils/leancloud-api.ts b/src/utils/leancloud-api.ts index e15ca2cd..8818e778 100644 --- a/src/utils/leancloud-api.ts +++ b/src/utils/leancloud-api.ts @@ -245,7 +245,7 @@ export class LeanCloudComments implements LeanCloudCommentsInterface { * @param limit Amount of records needed. */ async getRecentComments(limit: number): Promise { - return await new Promise((resolve) => { + return await new Promise(resolve => { this.queryAll() .limit(limit) .find() diff --git a/src/utils/request.ts b/src/utils/request.ts index 4e62c78b..2f06d25b 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -9,11 +9,11 @@ const service = axios.create({ // request interceptor service.interceptors.request.use( - (config) => { + config => { // do something before request is sent return config }, - (error) => { + error => { // do something with request error console.log(error) // for debug return Promise.reject(error) @@ -32,11 +32,11 @@ service.interceptors.response.use( * Here is just an example * You can also judge the status by HTTP Status Code */ - (response) => { + response => { // Login or other response handle place here. return response }, - (error) => { + error => { console.log('err' + error) // for debug console.error(error.message) return Promise.reject(error) diff --git a/src/views/Archives.vue b/src/views/Archives.vue index 799237a4..f6a973cf 100644 --- a/src/views/Archives.vue +++ b/src/views/Archives.vue @@ -61,13 +61,13 @@ import { defineComponent, onBeforeMount, onUnmounted, ref } from 'vue' import { useI18n } from 'vue-i18n' import Breadcrumbs from '@/components/Breadcrumbs.vue' import Paginator from '@/components/Paginator.vue' -import { useAppStore } from '@/stores/app' +import { useCommonStore } from '@/stores/common' export default defineComponent({ name: 'Archives', components: { Breadcrumbs, Paginator }, setup() { - const appStore = useAppStore() + const commonStore = useCommonStore() const postStore = usePostStore() const { t } = useI18n() const archives = ref(new Archives().data) @@ -81,7 +81,7 @@ export default defineComponent({ pagination.value.pageTotal = data.total archives.value = data.data }) - appStore.setHeaderImage(`${require('@/assets/default-cover.jpg')}`) + commonStore.setHeaderImage(`${require('@/assets/default-cover.jpg')}`) } const pageChangeHanlder = (page: number) => { @@ -95,7 +95,7 @@ export default defineComponent({ onBeforeMount(fetchData) onUnmounted(() => { - appStore.resetHeaderImage() + commonStore.resetHeaderImage() }) return { pageChangeHanlder, pagination, archives, t } diff --git a/src/views/Post.vue b/src/views/Post.vue index b0101108..1d47d966 100644 --- a/src/views/Post.vue +++ b/src/views/Post.vue @@ -217,6 +217,7 @@ import { Article } from '@/components/ArticleCard' import '@/styles/prism-aurora-future.css' import { useMetaStore } from '@/stores/meta' import { useAppStore } from '@/stores/app' +import { useCommonStore } from '@/stores/common' declare const Prism: any @@ -227,6 +228,7 @@ export default defineComponent({ const metaStore = useMetaStore() const postStore = usePostStore() const appStore = useAppStore() + const commonStore = useCommonStore() const route = useRoute() const { t } = useI18n() const post = ref(new Post()) @@ -243,7 +245,7 @@ export default defineComponent({ await postStore.fetchPost(slug).then(response => { post.value = response metaStore.setTitle(post.value.title) - appStore.setHeaderImage(response.cover) + commonStore.setHeaderImage(response.cover) loading.value = false }) if (appStore.hexoConfig.writing.highlight.enable) { @@ -274,11 +276,11 @@ export default defineComponent({ onMounted(fetchData) onBeforeUnmount(() => { - appStore.resetHeaderImage() + commonStore.resetHeaderImage() }) return { - isMobile: computed(() => appStore.isMobile), + isMobile: computed(() => commonStore.isMobile), handleAuthorClick, loading, post, diff --git a/src/views/Result.vue b/src/views/Result.vue index 330bc754..894b4e2b 100644 --- a/src/views/Result.vue +++ b/src/views/Result.vue @@ -114,7 +114,7 @@ export default defineComponent({ const fetchPostByTag = () => { isFetched.value = false - postStore.fetchPostsByTag(querySlug.value).then((response) => { + postStore.fetchPostsByTag(querySlug.value).then(response => { isFetched.value = true posts.value = response }) @@ -133,7 +133,7 @@ export default defineComponent({ watch( () => route.query, - (toQuery) => { + toQuery => { pageChangeHanlder(toQuery) } ) diff --git a/src/views/Tag.vue b/src/views/Tag.vue index 4ef50170..8f7782ca 100644 --- a/src/views/Tag.vue +++ b/src/views/Tag.vue @@ -36,24 +36,24 @@ import Breadcrumbs from '@/components/Breadcrumbs.vue' import { useI18n } from 'vue-i18n' import { useTagStore } from '@/stores/tag' import { TagList, TagItem } from '@/components/Tag' -import { useAppStore } from '@/stores/app' +import { useCommonStore } from '@/stores/common' export default defineComponent({ name: 'Tag', components: { Breadcrumbs, TagList, TagItem }, setup() { - const appStore = useAppStore() + const commonStore = useCommonStore() const { t } = useI18n() const tagStore = useTagStore() const fetchData = async () => { tagStore.fetchAllTags() - appStore.setHeaderImage(`${require('@/assets/default-cover.jpg')}`) + commonStore.setHeaderImage(`${require('@/assets/default-cover.jpg')}`) } onBeforeMount(fetchData) onUnmounted(() => { - appStore.resetHeaderImage() + commonStore.resetHeaderImage() }) return {