diff --git a/.eslintrc-auto-import.json b/.eslintrc-auto-import.json index 27df73d..f86a319 100644 --- a/.eslintrc-auto-import.json +++ b/.eslintrc-auto-import.json @@ -96,6 +96,8 @@ "onWatcherCleanup": true, "useId": true, "useModel": true, - "useTemplateRef": true + "useTemplateRef": true, + "useCaptcha": true, + "useListPageRequest": true } } diff --git a/env/.env b/env/.env index d520ddc..3634bc2 100644 --- a/env/.env +++ b/env/.env @@ -7,9 +7,9 @@ VITE_WX_APPID = 'wxa2abb91f64032a2b' # h5部署网站的base,配置到 manifest.config.ts 里的 h5.router.base VITE_APP_PUBLIC_BASE=/ -VITE_SERVER_BASEURL = 'https://ukw0y1.laf.run' -VITE_UPLOAD_BASEURL = 'https://ukw0y1.laf.run/upload' +VITE_SERVER_BASEURL = 'http://api.divine913.com' +VITE_UPLOAD_BASEURL = 'http://api.divine913.com/api/v1/UploadFile' # h5是否需要配置代理 -VITE_APP_PROXY=false +VITE_APP_PROXY=true VITE_APP_PROXY_PREFIX = '/api' diff --git a/package.json b/package.json index b0e6256..ed77ee5 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,7 @@ "@dcloudio/uni-mp-xhs": "3.0.0-4020920240930001", "@dcloudio/uni-quickapp-webview": "3.0.0-4020920240930001", "dayjs": "1.11.10", + "nprogress": "^0.2.0", "pinia": "2.0.36", "pinia-plugin-persistedstate": "3.2.1", "qs": "6.5.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 23c2296..93f88b3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -62,6 +62,9 @@ importers: dayjs: specifier: 1.11.10 version: 1.11.10 + nprogress: + specifier: ^0.2.0 + version: 0.2.0 pinia: specifier: 2.0.36 version: 2.0.36(typescript@5.7.2)(vue@3.4.21(typescript@5.7.2)) @@ -4224,6 +4227,9 @@ packages: resolution: {integrity: sha512-ppwTtiJZq0O/ai0z7yfudtBpWIoxM8yE6nHi1X47eFR2EWORqfbu6CnPlNsjeN683eT0qG6H/Pyf9fCcvjnnnQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + nprogress@0.2.0: + resolution: {integrity: sha512-I19aIingLgR1fmhftnbWWO3dXc0hSxqHQHQb3H8m+K3TnEn/iSeTZZOyvKXWqQESMwuUVnatlCnZdLBZZt2VSA==} + nth-check@2.1.1: resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==} @@ -10958,6 +10964,8 @@ snapshots: dependencies: path-key: 4.0.0 + nprogress@0.2.0: {} + nth-check@2.1.1: dependencies: boolbase: 1.0.0 diff --git a/src/App.vue b/src/App.vue index f91e826..dca4b1d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -11,6 +11,8 @@ onLaunch((options) => { // redirect: options.path, // }, }) + } else { + userStore.loadUserInfo() } }) @@ -100,15 +102,15 @@ uni-modal { } .uni-modal__title { - @apply p-16 text-left text-16 font-600; + @apply p-15 text-left text-16 font-600; } .uni-modal__bd { - @apply mb-16 px-16 pt-0 text-left text-14 font-medium text-#666; + @apply px-15 pt-0 text-left text-14 font-medium text-#666; } .uni-modal__btn { - @apply px-16 py-8 flex-none rounded-full shadow-none text-14; + @apply px-15 py-6 flex-none rounded-full shadow-none text-14; &::after { content: none; @@ -120,7 +122,7 @@ uni-modal { } .uni-modal__ft { - @apply justify-end p-16 leading-normal; + @apply justify-end px-15 pb-10 leading-normal; &::after { content: none; diff --git a/src/hooks/useCaptcha.ts b/src/hooks/useCaptcha.ts new file mode 100644 index 0000000..910fe6d --- /dev/null +++ b/src/hooks/useCaptcha.ts @@ -0,0 +1,11 @@ +export const useCaptcha = () => { + const codeUrl = ref('') + const refreshCode = () => { + const baseUrl = import.meta.env.VITE_SERVER_BASEURL + codeUrl.value = baseUrl + '/api/v1/getCaptcha?t=' + Date.now() + } + onMounted(() => { + refreshCode() + }) + return { codeUrl, refreshCode } +} diff --git a/src/hooks/useListPageRequest.ts b/src/hooks/useListPageRequest.ts new file mode 100644 index 0000000..325801e --- /dev/null +++ b/src/hooks/useListPageRequest.ts @@ -0,0 +1,105 @@ +import { onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app' +import { computed, onMounted, ref } from 'vue' + +interface PaginationRequest { + pageIndex?: number + pageSize?: number + [key: string]: any +} + +function useListPageRequest( + request: (params: PaginationRequest) => Promise, + options: { + autoBind?: boolean + autoRequest?: boolean + } = {}, +) { + const { autoBind = true, autoRequest = true } = options + const list = ref([]) + // 加载中 + const loading = ref(false) + // 加载更多中 + const moreLoading = ref(false) + // 全部数据加载完成 + const totalPage = ref(0) + const finished = computed(() => totalPage.value <= pagingParams.value.pageIndex) + const pagingParams = ref({ + pageIndex: 1, + pageSize: 10, + }) + const getPagingParams = computed(() => { + return { + ...pagingParams.value, + } + }) + let customParams: PaginationRequest = {} + + const statusLoading = computed(() => { + if (moreLoading.value || loading.value) { + return 'loading' + } + if (finished.value) { + return 'noMore' + } + return 'more' + }) + + const loadData = async () => { + const { data } = await request({ + ...getPagingParams.value, + ...customParams, + }) + totalPage.value = data.count ? Math.ceil(data.count / pagingParams.value.pageSize!) : 0 + list.value.push(...data.list) + } + + const onReload = async (params?: AnyObject) => { + loading.value = true + pagingParams.value.pageIndex = 1 + if (params) { + customParams = params + } + try { + await loadData() + } finally { + loading.value = false + } + } + const onMore = async () => { + if (finished.value) { + return + } + pagingParams.value.pageIndex = pagingParams.value.pageIndex! + 1 + moreLoading.value = true + try { + await loadData() + } finally { + moreLoading.value = false + } + } + + if (autoRequest) { + onMounted(onReload) + } + if (autoBind) { + onPullDownRefresh(async () => { + await onReload() + uni.stopPullDownRefresh() + }) + onReachBottom(onMore) + } + + return { + list, + loading, + moreLoading, + finished, + statusLoading, + totalPage, + + onReload, + onMore, + } +} + +export { useListPageRequest } diff --git a/src/hooks/useRequest.ts b/src/hooks/useRequest.ts index 9a0c8e5..f95e788 100644 --- a/src/hooks/useRequest.ts +++ b/src/hooks/useRequest.ts @@ -17,7 +17,7 @@ type IUseRequestOptions = { */ export default function useRequest( func: () => Promise>, - options: IUseRequestOptions = { immediate: false }, + options: IUseRequestOptions = { immediate: true }, ) { const loading = ref(false) const error = ref(false) diff --git a/src/interceptors/request.ts b/src/interceptors/request.ts index 1f84b31..e4b8009 100644 --- a/src/interceptors/request.ts +++ b/src/interceptors/request.ts @@ -51,9 +51,9 @@ const httpInterceptor = { } // 3. 添加 token 请求头标识 const userStore = useUserStore() - const { token } = userStore.userInfo as unknown as IUserInfo + const token = userStore.token if (token) { - options.header.Authorization = `Bearer ${token}` + options.header.Authorization = token } }, } diff --git a/src/interceptors/route.ts b/src/interceptors/route.ts index 32ea1a0..f25e512 100644 --- a/src/interceptors/route.ts +++ b/src/interceptors/route.ts @@ -4,6 +4,7 @@ * 可以设置路由白名单,或者黑名单,看业务需要选哪一个 * 我这里应为大部分都可以随便进入,所以使用黑名单 */ +import { getUserInfoAPI } from '@/service' import { useUserStore } from '@/store' import { getNotNeedLoginPages as _getNotNeedLoginPages, @@ -11,6 +12,10 @@ import { } from '@/utils' import type { Router } from 'vue-router' +import NProgress from 'nprogress' +import 'nprogress/nprogress.css' +NProgress.configure({ showSpinner: true, parent: '#app' }) + export const loginRoute = '/pages/login/index' export const isLogged = () => { @@ -68,7 +73,6 @@ export const getNotNeedLoginPages = () => { export const checkLoginUrl = (url: string) => { const path = url.split('?')[0] const isNotNeedLogin = getNotNeedLoginPages().includes(path.replace(/^pages/, '/pages')) - console.log(path) return isNotNeedLogin } @@ -89,15 +93,21 @@ export const checkNotFound = (url: string) => { } export const routerBeforeEachConfig = (router: Router) => { - router.beforeEach((to, from, next) => { + router.beforeEach(async (to, from, next) => { + NProgress.start() if (checkWithRedirectLogin(to.path)) { return next({ path: loginRoute, - // query: { - // redirect: to.fullPath, - // }, }) } + const userStore = useUserStore() + if (!userStore.userInfo && userStore.isLogged) { + await userStore.loadUserInfo() + } return next() }) + + router.afterEach(() => { + NProgress.done() + }) } diff --git a/src/pages-sub/asset/index.vue b/src/pages-sub/asset/index.vue index ee6e529..c4284a9 100644 --- a/src/pages-sub/asset/index.vue +++ b/src/pages-sub/asset/index.vue @@ -1,4 +1,4 @@ - + { style: { navigationBarTitleText: '我的资产', @@ -14,41 +14,51 @@ class="mt-15 mx-15 text-white btn-gradient p-15 rounded-10 shadow-[0_5px_30px_rgba(55,230,236,0.4)]" > 总投资金 - 10000.00 + {{ userStore.userInfo?.member_investment }} 我的分红 - 10000.00 + {{ userStore.userInfo?.member_dividend }} 数字人民币 - 10000.00 + {{ userStore.userInfo?.member_dividend }} 认购点 - 10000.00 + {{ userStore.userInfo?.member_point }} 资产记录 - 邀请好友奖励 + {{ item.title }} 奖励 - 2024-12-27 10:00:00 + {{ item.create_time }} - +1000 RMB - +2000 RMB - +30 点 - 已到账 + {{ item.money }} + + + + 已到账 + + + diff --git a/src/pages-sub/introduction/index.vue b/src/pages-sub/introduction/index.vue index 1c95af0..c4a14ff 100644 --- a/src/pages-sub/introduction/index.vue +++ b/src/pages-sub/introduction/index.vue @@ -1,4 +1,4 @@ - + { style: { navigationBarTitleText: '公司简介', @@ -6,17 +6,22 @@ } + + diff --git a/src/pages-sub/invest-detail/index.vue b/src/pages-sub/invest-detail/index.vue index c49b6e4..f1a6d12 100644 --- a/src/pages-sub/invest-detail/index.vue +++ b/src/pages-sub/invest-detail/index.vue @@ -1,4 +1,4 @@ - + { style: { navigationBarTitleText: '投资记录', @@ -6,24 +6,41 @@ }, } + diff --git a/src/pages-sub/invest-immediately/index.vue b/src/pages-sub/invest-immediately/index.vue index 7df416b..9a22364 100644 --- a/src/pages-sub/invest-immediately/index.vue +++ b/src/pages-sub/invest-immediately/index.vue @@ -1,4 +1,4 @@ - + { style: { navigationStyle: 'custom', diff --git a/src/pages-sub/invest-result/index.vue b/src/pages-sub/invest-result/index.vue index a194df8..11e5e12 100644 --- a/src/pages-sub/invest-result/index.vue +++ b/src/pages-sub/invest-result/index.vue @@ -1,7 +1,7 @@ - + { style: { - navigationBarTitleText: '投资成功', + navigationBarTitleText: '充值成功', navigationBarBackgroundColor: '#fff', }, } @@ -9,7 +9,7 @@