diff --git a/pages.config.ts b/pages.config.ts index 5a4bc68..25797ab 100644 --- a/pages.config.ts +++ b/pages.config.ts @@ -15,4 +15,34 @@ export default defineUniPages({ '^uv-(.*)': '@climblee/uv-ui/components/uv-$1/uv-$1.vue', }, }, + tabBar: { + color: '#999999', + selectedColor: '#018d71', + backgroundColor: '#F8F8F8', + borderStyle: 'black', + height: '50px', + fontSize: '10px', + iconWidth: '24px', + spacing: '3px', + list: [ + { + iconPath: 'static/tabbar/home.png', + selectedIconPath: 'static/tabbar/homeHL.png', + pagePath: 'pages/index/index', + text: '首页', + }, + { + iconPath: 'static/tabbar/example.png', + selectedIconPath: 'static/tabbar/exampleHL.png', + pagePath: 'pages/demo/index', + text: '示例', + }, + { + iconPath: 'static/tabbar/personal.png', + selectedIconPath: 'static/tabbar/personalHL.png', + pagePath: 'pages/my/index', + text: '我的', + }, + ], + }, }) diff --git a/src/components/fly-header/fly-header.vue b/src/components/fly-header/fly-header.vue new file mode 100644 index 0000000..9e34a4b --- /dev/null +++ b/src/components/fly-header/fly-header.vue @@ -0,0 +1,3 @@ + diff --git a/src/components/fly-login/README.md b/src/components/fly-login/README.md new file mode 100644 index 0000000..c931549 --- /dev/null +++ b/src/components/fly-login/README.md @@ -0,0 +1,7 @@ +# fly-login + +点击“点击显示微信头像”按钮后,出现的半屏登录弹窗,可以在任意页面引入。 + +仿“掘金小册”小程序。 + +![掘金小册登录](screenshot.png) diff --git a/src/components/fly-login/defaultAvatar.png b/src/components/fly-login/defaultAvatar.png new file mode 100644 index 0000000..e69596a Binary files /dev/null and b/src/components/fly-login/defaultAvatar.png differ diff --git a/src/components/fly-login/fly-login.vue b/src/components/fly-login/fly-login.vue new file mode 100644 index 0000000..8a6dc1f --- /dev/null +++ b/src/components/fly-login/fly-login.vue @@ -0,0 +1,120 @@ + + + + diff --git a/src/components/fly-login/screenshot.png b/src/components/fly-login/screenshot.png new file mode 100644 index 0000000..7ca7a26 Binary files /dev/null and b/src/components/fly-login/screenshot.png differ diff --git a/src/components/fly-navbar/README.md b/src/components/fly-navbar/README.md new file mode 100644 index 0000000..cd5cf97 --- /dev/null +++ b/src/components/fly-navbar/README.md @@ -0,0 +1,3 @@ +# fly-navbar + +建议本导航栏组件在设置 `"navigationStyle": "custom"` 的页面使用,目前支持微信小程序的页面滚动动画。 diff --git a/src/components/fly-navbar/fly-navbar.vue b/src/components/fly-navbar/fly-navbar.vue new file mode 100644 index 0000000..5636cb4 --- /dev/null +++ b/src/components/fly-navbar/fly-navbar.vue @@ -0,0 +1,71 @@ + + + + + diff --git a/src/hooks/useNavbarWeixin.ts b/src/hooks/useNavbarWeixin.ts new file mode 100644 index 0000000..e8f7aff --- /dev/null +++ b/src/hooks/useNavbarWeixin.ts @@ -0,0 +1,62 @@ +import { onReady } from '@dcloudio/uni-app' +import { getIsTabbar } from '@/utils/index' + +export default () => { + // 获取页面栈 + const pages = getCurrentPages() + const isTabbar = getIsTabbar() + + // 页面滚动到底部时的操作,通常用于加载更多数据 + const onScrollToLower = () => {} + // 获取屏幕边界到安全区域距离 + const { safeAreaInsets } = uni.getSystemInfoSync() + + // #ifdef MP-WEIXIN + // 基于小程序的 Page 类型扩展 uni-app 的 Page + type PageInstance = Page.PageInstance & WechatMiniprogram.Page.InstanceMethods + // 获取当前页面实例,数组最后一项 + const pageInstance = getCurrentPages().at(-1) as PageInstance + + // 页面渲染完毕,绑定动画效果 + onReady(() => { + // 动画效果,导航栏背景色 + pageInstance.animate( + '.fly-navbar', + [{ backgroundColor: 'transparent' }, { backgroundColor: '#f8f8f8' }], + 1000, + { + scrollSource: '#scroller', + timeRange: 1000, + startScrollOffset: 0, + endScrollOffset: 50, + }, + ) + // 动画效果,导航栏标题 + pageInstance.animate( + '.fly-navbar .title', + [{ color: 'transparent' }, { color: '#000' }], + 1000, + { + scrollSource: '#scroller', + timeRange: 1000, + startScrollOffset: 0, + endScrollOffset: 50, + }, + ) + // 动画效果,导航栏返回按钮 + pageInstance.animate('.fly-navbar .left-icon', [{ color: '#fff' }, { color: '#000' }], 1000, { + scrollSource: '#scroller', + timeRange: 1000, + startScrollOffset: 0, + endScrollOffset: 50, + }) + }) + // #endif + + return { + pages, + isTabbar, + onScrollToLower, + safeAreaInsets, + } +} diff --git a/src/hooks/useWeixinShare.ts b/src/hooks/useWeixinShare.ts new file mode 100644 index 0000000..47880c2 --- /dev/null +++ b/src/hooks/useWeixinShare.ts @@ -0,0 +1,25 @@ +import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app' + +export default () => { + return { + /** 激活“分享给好友” */ + onShareAppMessage: onShareAppMessage( + (options: Page.ShareAppMessageOption): Page.CustomShareContent => { + console.log('options:', options) + return { + title: '自定义分享标题', + path: '/pages/index/index?id=xxx', + imageUrl: + 'https://cip-shopping-page-0eysug01066a9e-1302818703.tcloudbaseapp.com/pretty-girl.png', + } + }, + ), + /** 激活“分享到朋友圈”, 注意:需要先激活“分享给好友” */ + onShareTimeline: onShareTimeline((): Page.ShareTimelineContent => { + return { + title: '自定义分享标题', + query: 'a=1&b=2', + } + }), + } +} diff --git a/src/pages/demo/base/mp-weixin-share.vue b/src/pages/demo/base/mp-weixin-share.vue new file mode 100644 index 0000000..9e499e4 --- /dev/null +++ b/src/pages/demo/base/mp-weixin-share.vue @@ -0,0 +1,42 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: '微信分享' }, +} + + + + + diff --git a/src/pages/demo/base/navbar.vue b/src/pages/demo/base/navbar.vue new file mode 100644 index 0000000..7985584 --- /dev/null +++ b/src/pages/demo/base/navbar.vue @@ -0,0 +1,19 @@ + +{ + style: { navigationBarTitleText: '自定义导航栏', navigationStyle: 'custom' }, +} + + + + + diff --git a/src/pages/demo/base/pinia.vue b/src/pages/demo/base/pinia.vue new file mode 100644 index 0000000..4ae0c52 --- /dev/null +++ b/src/pages/demo/base/pinia.vue @@ -0,0 +1,40 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: 'pinia+持久化' }, +} + + + + + diff --git a/src/pages/demo/base/request.vue b/src/pages/demo/base/request.vue new file mode 100644 index 0000000..2af78a9 --- /dev/null +++ b/src/pages/demo/base/request.vue @@ -0,0 +1,67 @@ + +{ + layout: 'demo', + style: { + navigationBarTitleText: '请求', + }, +} + + + + + diff --git a/src/pages/demo/base/throughout.vue b/src/pages/demo/base/throughout.vue new file mode 100644 index 0000000..10d8c7e --- /dev/null +++ b/src/pages/demo/base/throughout.vue @@ -0,0 +1,145 @@ + +{ + style: { + navigationBarTitleText: '通屏+下拉刷新+自定义导航栏', + enablePullDownRefresh: false, + backgroundColor: '#23c09c', // 这个背景色要与页面的.top-section的背景图差不多,这样下拉刷新看起来才比较协调 + 'app-plus': { + titleNView: { + type: 'transparent', + }, + }, + 'mp-weixin': { + navigationStyle: 'custom', + }, + }, +} + + + + + + + diff --git a/src/pages/demo/base/uni-ui-icons.vue b/src/pages/demo/base/uni-ui-icons.vue new file mode 100644 index 0000000..f513674 --- /dev/null +++ b/src/pages/demo/base/uni-ui-icons.vue @@ -0,0 +1,16 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: 'UniUI Icons 使用' }, +} + + + diff --git a/src/pages/demo/base/uni-ui.vue b/src/pages/demo/base/uni-ui.vue new file mode 100644 index 0000000..6fd423d --- /dev/null +++ b/src/pages/demo/base/uni-ui.vue @@ -0,0 +1,14 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: 'UniUI 使用' }, +} + + + diff --git a/src/pages/demo/base/unocss-icons.vue b/src/pages/demo/base/unocss-icons.vue new file mode 100644 index 0000000..18c583a --- /dev/null +++ b/src/pages/demo/base/unocss-icons.vue @@ -0,0 +1,20 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: 'UnoCss Icons 使用' }, +} + + + diff --git a/src/pages/demo/base/unocss.vue b/src/pages/demo/base/unocss.vue new file mode 100644 index 0000000..3fd903c --- /dev/null +++ b/src/pages/demo/base/unocss.vue @@ -0,0 +1,15 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: 'UnoCss 使用' }, +} + + + diff --git a/src/pages/demo/base/vconsole.vue b/src/pages/demo/base/vconsole.vue new file mode 100644 index 0000000..072f3e4 --- /dev/null +++ b/src/pages/demo/base/vconsole.vue @@ -0,0 +1,22 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: '开启 vConsole' }, +} + + + diff --git a/src/pages/demo/index.vue b/src/pages/demo/index.vue new file mode 100644 index 0000000..7a940ee --- /dev/null +++ b/src/pages/demo/index.vue @@ -0,0 +1,81 @@ + + + + + diff --git a/src/pages/demo/page/clock.vue b/src/pages/demo/page/clock.vue new file mode 100644 index 0000000..d507298 --- /dev/null +++ b/src/pages/demo/page/clock.vue @@ -0,0 +1,130 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: '动态时钟' }, +} + + + + + + + diff --git a/src/pages/demo/page/clock2.vue b/src/pages/demo/page/clock2.vue new file mode 100644 index 0000000..6fc30d8 --- /dev/null +++ b/src/pages/demo/page/clock2.vue @@ -0,0 +1,152 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: '动态时钟-抗锯齿' }, +} + + + + + + + diff --git a/src/pages/demo/page/floating-bubble.vue b/src/pages/demo/page/floating-bubble.vue new file mode 100644 index 0000000..3523408 --- /dev/null +++ b/src/pages/demo/page/floating-bubble.vue @@ -0,0 +1,88 @@ + +{ + layout: 'default', + style: { navigationBarTitleText: '页面悬浮球' }, +} + + + + + + + diff --git a/src/pages/demo/page/i18n.vue b/src/pages/demo/page/i18n.vue new file mode 100644 index 0000000..033cd8d --- /dev/null +++ b/src/pages/demo/page/i18n.vue @@ -0,0 +1,83 @@ + +{ + layout: 'demo', + style: { + navigationBarTitleText: '%app.name%', + }, +} + + + + + + + diff --git a/src/pages/demo/page/img-min/index.vue b/src/pages/demo/page/img-min/index.vue new file mode 100644 index 0000000..b4f4ee7 --- /dev/null +++ b/src/pages/demo/page/img-min/index.vue @@ -0,0 +1,29 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: '图片压缩' }, +} + + + diff --git a/src/pages/demo/page/lottery.vue b/src/pages/demo/page/lottery.vue new file mode 100644 index 0000000..048044d --- /dev/null +++ b/src/pages/demo/page/lottery.vue @@ -0,0 +1,127 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: '九宫格抽奖' }, +} + + + + + + + diff --git a/src/pages/demo/page/lottery/big-wheel.vue b/src/pages/demo/page/lottery/big-wheel.vue new file mode 100644 index 0000000..397f2af --- /dev/null +++ b/src/pages/demo/page/lottery/big-wheel.vue @@ -0,0 +1,216 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: '大转盘抽奖' }, +} + + + + + + + diff --git a/src/pages/demo/page/lottery/nine-grid.vue b/src/pages/demo/page/lottery/nine-grid.vue new file mode 100644 index 0000000..6374aa2 --- /dev/null +++ b/src/pages/demo/page/lottery/nine-grid.vue @@ -0,0 +1,196 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: '九宫格抽奖' }, +} + + + + + diff --git a/src/pages/demo/page/lottery2.vue b/src/pages/demo/page/lottery2.vue new file mode 100644 index 0000000..876a1bd --- /dev/null +++ b/src/pages/demo/page/lottery2.vue @@ -0,0 +1,181 @@ + +{ + layout: 'demo', + style: { navigationBarTitleText: '大转盘抽奖' }, +} + + + + + + + diff --git a/src/pages/demo/page/sign.vue b/src/pages/demo/page/sign.vue new file mode 100644 index 0000000..91cc02e --- /dev/null +++ b/src/pages/demo/page/sign.vue @@ -0,0 +1,266 @@ + +{ + layout: 'default', + style: { navigationBarTitleText: '签字板' }, +} + + + + + + + diff --git a/src/pages/my/components/wx-login.vue b/src/pages/my/components/wx-login.vue new file mode 100644 index 0000000..30e5ff9 --- /dev/null +++ b/src/pages/my/components/wx-login.vue @@ -0,0 +1,39 @@ + +{ + style: { navigationBarTitleText: '登录' }, +} + + + + + diff --git a/src/pages/my/index.vue b/src/pages/my/index.vue new file mode 100644 index 0000000..0d53bd8 --- /dev/null +++ b/src/pages/my/index.vue @@ -0,0 +1,35 @@ + +{ + style: { navigationBarTitleText: '我的' }, +} + + + + diff --git a/src/static/tabbar/example.png b/src/static/tabbar/example.png new file mode 100644 index 0000000..fd1e942 Binary files /dev/null and b/src/static/tabbar/example.png differ diff --git a/src/static/tabbar/exampleHL.png b/src/static/tabbar/exampleHL.png new file mode 100644 index 0000000..7501011 Binary files /dev/null and b/src/static/tabbar/exampleHL.png differ diff --git a/src/static/tabbar/home.png b/src/static/tabbar/home.png new file mode 100644 index 0000000..8f82e21 Binary files /dev/null and b/src/static/tabbar/home.png differ diff --git a/src/static/tabbar/homeHL.png b/src/static/tabbar/homeHL.png new file mode 100644 index 0000000..26d3761 Binary files /dev/null and b/src/static/tabbar/homeHL.png differ diff --git a/src/static/tabbar/personal.png b/src/static/tabbar/personal.png new file mode 100644 index 0000000..0a569a2 Binary files /dev/null and b/src/static/tabbar/personal.png differ diff --git a/src/static/tabbar/personalHL.png b/src/static/tabbar/personalHL.png new file mode 100644 index 0000000..8c3e66e Binary files /dev/null and b/src/static/tabbar/personalHL.png differ diff --git a/src/store/count.ts b/src/store/count.ts new file mode 100644 index 0000000..946ccd7 --- /dev/null +++ b/src/store/count.ts @@ -0,0 +1,28 @@ +// src/store/useCountStore.ts +import { defineStore } from 'pinia' +import { ref } from 'vue' + +export const useCountStore = defineStore( + 'count', + () => { + const count = ref(0) + const increment = () => { + count.value++ + } + const decrement = () => { + count.value-- + } + const reset = () => { + count.value = 0 + } + return { + count, + decrement, + increment, + reset, + } + }, + { + persist: true, + }, +) diff --git a/src/store/index.ts b/src/store/index.ts index e5f6675..74cb584 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -16,3 +16,4 @@ export default store // 模块统一导出 export * from './user' +export * from './count' diff --git a/src/store/user.ts b/src/store/user.ts index 7e08146..9118687 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -1,24 +1,30 @@ import { defineStore } from 'pinia' import { ref } from 'vue' -import { UserInfo } from '../typings' +import { IUserInfo } from '../typings' + +const initState = { nickname: '', avatar: '' } export const useUserStore = defineStore( 'user', () => { - const userInfo = ref({ nickname: '', avatar: '' }) + const userInfo = ref({ ...initState }) - const setUserInfo = (val: UserInfo) => { + const setUserInfo = (val: IUserInfo) => { userInfo.value = val } const clearUserInfo = () => { userInfo.value = undefined } + const reset = () => { + userInfo.value = { ...initState } + } return { userInfo, setUserInfo, clearUserInfo, + reset, } }, { diff --git a/src/typings.d.ts b/src/typings.d.ts index 9878916..3e860bb 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -6,15 +6,10 @@ export type IResData = { result: T } -export type UserInfo = { +export type IUserInfo = { nickname?: string avatar?: string /** 微信的 openid,非微信没有这个字段 */ openid?: string token?: string } - -export type UserItem = { - username: string - age: number -} diff --git a/src/utils/http.ts b/src/utils/http.ts index 79ace68..1a3d1a5 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -1,7 +1,7 @@ /* eslint-disable no-param-reassign */ import qs from 'qs' import { useUserStore } from '@/store' -import { IResData, UserInfo } from '@/typings' +import { IResData, IUserInfo } from '@/typings' type CustomRequestOptions = UniApp.RequestOptions & { query?: Record } @@ -36,7 +36,7 @@ const httpInterceptor = { } // 4. 添加 token 请求头标识 const userStore = useUserStore() - const { token } = userStore.userInfo as unknown as UserInfo + const { token } = userStore.userInfo as unknown as IUserInfo if (token) { options.header.Authorization = `Bearer ${token}` } diff --git a/src/utils/index.ts b/src/utils/index.ts index b46d00d..90d3637 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,5 +1,18 @@ +import pagesJson from '@/pages.json' import { translate as t } from '@/locale/index' +console.log(pagesJson) + +/** 判断当前页面是否是tabbar页 */ +export const getIsTabbar = () => { + if (!Object.keys(pagesJson).includes('tabBar')) { + return false + } + const pages = getCurrentPages() + const currPath = pages.at(-1).route + return !!pagesJson.tabBar.list.find((e) => e.pagePath === currPath) +} + /** * test i18n in not .vue file */