From 86ed732ca818fd74f19c05f8a1f8b774d0bd320d Mon Sep 17 00:00:00 2001 From: Li Kui <90845831+likui628@users.noreply.github.com> Date: Sun, 8 Sep 2024 19:39:19 +0800 Subject: [PATCH] feat: tanstack query demos (#4276) * chore(@vben/request): add axios-retry * feat: error retry * feat: paginated queries * feat: infinite queries * chore: update * chore: update * fix: ci error * chore: update * chore: remove axios-retry * chore: update deps * chore: update deps * chore: update deps * chore: update pnpm.lock --------- Co-authored-by: vince --- playground/package.json | 1 + playground/src/bootstrap.ts | 5 ++ playground/src/router/routes/modules/demos.ts | 9 +++ .../views/demos/features/vue-query/index.vue | 25 ++++++++ .../features/vue-query/infinite-queries.vue | 58 +++++++++++++++++++ .../features/vue-query/paginated-queries.vue | 51 ++++++++++++++++ .../features/vue-query/query-retries.vue | 34 +++++++++++ .../views/demos/features/vue-query/typing.ts | 18 ++++++ pnpm-lock.yaml | 38 ++++++++++++ 9 files changed, 239 insertions(+) create mode 100644 playground/src/views/demos/features/vue-query/index.vue create mode 100644 playground/src/views/demos/features/vue-query/infinite-queries.vue create mode 100644 playground/src/views/demos/features/vue-query/paginated-queries.vue create mode 100644 playground/src/views/demos/features/vue-query/query-retries.vue create mode 100644 playground/src/views/demos/features/vue-query/typing.ts diff --git a/playground/package.json b/playground/package.json index e565bf0b..89182b3d 100644 --- a/playground/package.json +++ b/playground/package.json @@ -26,6 +26,7 @@ "#/*": "./src/*" }, "dependencies": { + "@tanstack/vue-query": "^5.53.1", "@vben/access": "workspace:*", "@vben/common-ui": "workspace:*", "@vben/constants": "workspace:*", diff --git a/playground/src/bootstrap.ts b/playground/src/bootstrap.ts index 1be9bbe0..6dac2709 100644 --- a/playground/src/bootstrap.ts +++ b/playground/src/bootstrap.ts @@ -5,6 +5,8 @@ import { initStores } from '@vben/stores'; import '@vben/styles'; import '@vben/styles/antd'; +import { VueQueryPlugin } from '@tanstack/vue-query'; + import { setupI18n } from '#/locales'; import App from './app.vue'; @@ -25,6 +27,9 @@ async function bootstrap(namespace: string) { // 配置路由及路由守卫 app.use(router); + // 配置@tanstack/vue-query + app.use(VueQueryPlugin); + app.mount('#app'); } diff --git a/playground/src/router/routes/modules/demos.ts b/playground/src/router/routes/modules/demos.ts index ee1a6345..d7918513 100644 --- a/playground/src/router/routes/modules/demos.ts +++ b/playground/src/router/routes/modules/demos.ts @@ -183,6 +183,15 @@ const routes: RouteRecordRaw[] = [ title: $t('page.demos.features.clipboard'), }, }, + { + name: 'VueQueryDemo', + path: '/demos/features/vue-query', + component: () => + import('#/views/demos/features/vue-query/index.vue'), + meta: { + title: 'Tanstack Query', + }, + }, ], }, // 面包屑导航 diff --git a/playground/src/views/demos/features/vue-query/index.vue b/playground/src/views/demos/features/vue-query/index.vue new file mode 100644 index 00000000..d57cf812 --- /dev/null +++ b/playground/src/views/demos/features/vue-query/index.vue @@ -0,0 +1,25 @@ + + + diff --git a/playground/src/views/demos/features/vue-query/infinite-queries.vue b/playground/src/views/demos/features/vue-query/infinite-queries.vue new file mode 100644 index 00000000..2add4c15 --- /dev/null +++ b/playground/src/views/demos/features/vue-query/infinite-queries.vue @@ -0,0 +1,58 @@ + + + diff --git a/playground/src/views/demos/features/vue-query/paginated-queries.vue b/playground/src/views/demos/features/vue-query/paginated-queries.vue new file mode 100644 index 00000000..b2e3c26d --- /dev/null +++ b/playground/src/views/demos/features/vue-query/paginated-queries.vue @@ -0,0 +1,51 @@ + + + diff --git a/playground/src/views/demos/features/vue-query/query-retries.vue b/playground/src/views/demos/features/vue-query/query-retries.vue new file mode 100644 index 00000000..0080386f --- /dev/null +++ b/playground/src/views/demos/features/vue-query/query-retries.vue @@ -0,0 +1,34 @@ + + + diff --git a/playground/src/views/demos/features/vue-query/typing.ts b/playground/src/views/demos/features/vue-query/typing.ts new file mode 100644 index 00000000..95558dd8 --- /dev/null +++ b/playground/src/views/demos/features/vue-query/typing.ts @@ -0,0 +1,18 @@ +export interface IProducts { + limit: number; + products: { + brand: string; + category: string; + description: string; + discountPercentage: string; + id: string; + images: string[]; + price: string; + rating: string; + stock: string; + thumbnail: string; + title: string; + }[]; + skip: number; + total: number; +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 98c3f30d..2293ba3e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1156,6 +1156,9 @@ importers: playground: dependencies: + '@tanstack/vue-query': + specifier: ^5.53.1 + version: 5.54.2(vue@3.5.3(typescript@5.5.4)) '@vben/access': specifier: workspace:* version: link:../packages/effects/access @@ -3976,12 +3979,28 @@ packages: peerDependencies: tailwindcss: '>=3.0.0 || insiders || >=4.0.0-alpha.20' + '@tanstack/match-sorter-utils@8.19.4': + resolution: {integrity: sha512-Wo1iKt2b9OT7d+YGhvEPD3DXvPv2etTusIMhMUoG7fbhmxcXCtIjJDEygy91Y2JFlwGyjqiBPRozme7UD8hoqg==} + engines: {node: '>=12'} + + '@tanstack/query-core@5.54.1': + resolution: {integrity: sha512-hKS+WRpT5zBFip21pB6Jx1C0hranWQrbv5EJ7qPoiV5MYI3C8rTCqWC9DdBseiPT1JgQWh8Y55YthuYZNiw3Xw==} + '@tanstack/store@0.5.5': resolution: {integrity: sha512-EOSrgdDAJExbvRZEQ/Xhh9iZchXpMN+ga1Bnk8Nmygzs8TfiE6hbzThF+Pr2G19uHL6+DTDTHhJ8VQiOd7l4tA==} '@tanstack/virtual-core@3.9.0': resolution: {integrity: sha512-Saga7/QRGej/IDCVP5BgJ1oDqlDT2d9rQyoflS3fgMS8ntJ8JGw/LBqK2GorHa06+VrNFc0tGz65XQHJQJetFQ==} + '@tanstack/vue-query@5.54.2': + resolution: {integrity: sha512-GYIYee9WkUbPDD28t1kdNNtLCioiIva0MhKCvODGWoEML5MNONCX4/i4y2GGFi8i9nSbcA8MpvD+nt/tdZ+yJw==} + peerDependencies: + '@vue/composition-api': ^1.1.2 + vue: 3.5.3 + peerDependenciesMeta: + '@vue/composition-api': + optional: true + '@tanstack/vue-store@0.5.5': resolution: {integrity: sha512-j+CDrxVhtQQNOjWzLmCqJeDwmmTAQGvEaNbLr1uPJ9rxJITodJtFNdBFj7l+Nd5o34v2ayEv64Ugh6+1BtuGNg==} peerDependencies: @@ -8442,6 +8461,9 @@ packages: resolution: {integrity: sha512-G08Dxvm4iDN3MLM0EsP62EDV9IuhXPR6blNz6Utcp7zyV3tr4HVNINt6MpaRWbxoOHT3Q7YN2P+jaHX8vUbgog==} engines: {node: '>= 0.10'} + remove-accents@0.5.0: + resolution: {integrity: sha512-8g3/Otx1eJaVD12e31UbJj1YzdtVvzH85HV7t+9MJYk/u3XmkOUJ5Ys9wQrf9PCPK8+xn4ymzqYCiZl6QWKn+A==} + repeat-string@1.6.1: resolution: {integrity: sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==} engines: {node: '>=0.10'} @@ -12909,10 +12931,24 @@ snapshots: postcss-selector-parser: 6.0.10 tailwindcss: 3.4.10 + '@tanstack/match-sorter-utils@8.19.4': + dependencies: + remove-accents: 0.5.0 + + '@tanstack/query-core@5.54.1': {} + '@tanstack/store@0.5.5': {} '@tanstack/virtual-core@3.9.0': {} + '@tanstack/vue-query@5.54.2(vue@3.5.3(typescript@5.5.4))': + dependencies: + '@tanstack/match-sorter-utils': 8.19.4 + '@tanstack/query-core': 5.54.1 + '@vue/devtools-api': 6.6.3 + vue: 3.5.3(typescript@5.5.4) + vue-demi: 0.14.10(vue@3.5.3(typescript@5.5.4)) + '@tanstack/vue-store@0.5.5(vue@3.5.3(typescript@5.5.4))': dependencies: '@tanstack/store': 0.5.5 @@ -17933,6 +17969,8 @@ snapshots: relateurl@0.2.7: {} + remove-accents@0.5.0: {} + repeat-string@1.6.1: {} require-directory@2.1.1: {}