init:初始化仓库

This commit is contained in:
2025-12-18 10:29:06 +08:00
commit c0b1f4d59b
184 changed files with 24119 additions and 0 deletions

3
.commitlintrc.cjs Normal file
View File

@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
}

View File

@@ -0,0 +1,51 @@
# API 和 HTTP 请求规范
## HTTP 请求封装
- 可以使用 `简单http` 或者 `alova` 或者 `@tanstack/vue-query` 进行请求管理
- HTTP 配置在 [src/http/](mdc:src/http/) 目录下
- `简单http` - [src/http/http.ts](mdc:src/http/http.ts)
- `alova` - [src/http/alova.ts](mdc:src/http/alova.ts)
- `vue-query` - [src/http/vue-query.ts](mdc:src/http/vue-query.ts)
- 请求拦截器在 [src/http/interceptor.ts](mdc:src/http/interceptor.ts)
- 支持请求重试、缓存、错误处理
## API 接口规范
- API 接口定义在 [src/api/](mdc:src/api/) 目录下
- 按功能模块组织 API 文件
- 使用 TypeScript 定义请求和响应类型
- 支持 `简单http`、`alova` 和 `vue-query` 三种请求方式
## 示例代码结构
```typescript
// API 接口定义
export interface LoginParams {
username: string
password: string
}
export interface LoginResponse {
token: string
userInfo: UserInfo
}
// alova 方式
export const login = (params: LoginParams) =>
http.Post<LoginResponse>('/api/login', params)
// vue-query 方式
export const useLogin = () => {
return useMutation({
mutationFn: (params: LoginParams) =>
http.post<LoginResponse>('/api/login', params)
})
}
```
## 错误处理
- 统一错误处理在拦截器中配置
- 支持网络错误、业务错误、认证错误等
- 自动处理 token 过期和刷新
---
globs: src/api/*.ts,src/http/*.ts
---

View File

@@ -0,0 +1,43 @@
# 开发工作流程
## 项目启动
1. 安装依赖:`pnpm install`
2. 开发环境:
- H5: `pnpm dev` 或 `pnpm dev:h5`
- 微信小程序: `pnpm dev:mp`
- 支付宝小程序: `pnpm dev:mp-alipay`
- APP: `pnpm dev:app`
## 代码规范
- 使用 ESLint 进行代码检查:`pnpm lint`
- 自动修复代码格式:`pnpm lint:fix`
- 使用 eslint 格式化代码
- 遵循 TypeScript 严格模式
## 构建和部署
- H5 构建:`pnpm build:h5`
- 微信小程序构建:`pnpm build:mp`
- 支付宝小程序构建:`pnpm build:mp-alipay`
- APP 构建:`pnpm build:app`
- 类型检查:`pnpm type-check`
## 开发工具
- 推荐使用 VSCode 编辑器
- 安装 Vue 和 TypeScript 相关插件
- 使用 uni-app 开发者工具调试小程序
- 使用 HBuilderX 调试 APP
## 调试技巧
- 使用 console.log 和 uni.showToast 调试
- 利用 Vue DevTools 调试组件状态
- 使用网络面板调试 API 请求
- 平台差异测试和兼容性检查
## 性能优化
- 使用懒加载和代码分割
- 优化图片和静态资源
- 减少不必要的重渲染
- 合理使用缓存策略
---
description: 开发工作流程和最佳实践指南
---

View File

@@ -0,0 +1,36 @@
---
alwaysApply: true
---
# unibest 项目概览
这是一个基于 uniapp + Vue3 + TypeScript + Vite5 + UnoCSS 的跨平台开发框架。
## 项目特点
- 支持 H5、小程序、APP 多平台开发
- 使用最新的前端技术栈
- 内置约定式路由、layout布局、请求封装、登录拦截、自定义tabbar等功能
- 无需依赖 HBuilderX支持命令行开发
## 核心配置文件
- [package.json](mdc:package.json) - 项目依赖和脚本配置
- [vite.config.ts](mdc:vite.config.ts) - Vite 构建配置
- [pages.config.ts](mdc:pages.config.ts) - 页面路由配置
- [manifest.config.ts](mdc:manifest.config.ts) - 应用清单配置
- [uno.config.ts](mdc:uno.config.ts) - UnoCSS 配置
## 主要目录结构
- `src/pages/` - 页面文件
- `src/components/` - 组件文件
- `src/layouts/` - 布局文件
- `src/api/` - API 接口
- `src/http/` - HTTP 请求封装
- `src/store/` - 状态管理
- `src/tabbar/` - 底部导航栏
- `src/App.ku.vue` - 全局根组件(类似 App.vue 里面的 template作用
## 开发命令
- `pnpm dev` - 开发 H5 版本
- `pnpm dev:mp` - 开发微信小程序
- `pnpm dev:mp-alipay` - 开发支付宝小程序(含钉钉)
- `pnpm dev:app` - 开发 APP 版本
- `pnpm build` - 构建生产版本

View File

@@ -0,0 +1,54 @@
# 样式和 CSS 开发规范
## UnoCSS 原子化 CSS
- 项目使用 UnoCSS 作为原子化 CSS 框架
- 配置在 [uno.config.ts](mdc:uno.config.ts)
- 支持预设和自定义规则
- 优先使用原子化类名,减少自定义 CSS
## SCSS 规范
- 使用 SCSS 预处理器
- 样式文件使用 `lang="scss"` 和 `scoped` 属性
- 遵循 BEM 命名规范
- 使用变量和混入提高复用性
## 样式组织
- 全局样式在 [src/style/](mdc:src/style/) 目录下
- 组件样式使用 scoped 作用域
- 图标字体在 [src/style/iconfont.css](mdc:src/style/iconfont.css)
- 主题变量在 [src/uni_modules/uni-scss/](mdc:src/uni_modules/uni-scss/) 目录下
## 示例代码结构
```vue
<template>
<view class="container flex flex-col items-center p-4">
<text class="title text-lg font-bold mb-2">标题</text>
<view class="content bg-gray-100 rounded-lg p-3">
<!-- 内容 -->
</view>
</view>
</template>
<style lang="scss" scoped>
.container {
min-height: 100vh;
.title {
color: var(--primary-color);
}
.content {
width: 100%;
max-width: 600rpx;
}
}
</style>
## 响应式设计
- 使用 rpx 单位适配不同屏幕
- 支持横屏和竖屏布局
- 使用 flexbox 和 grid 布局
- 考虑不同平台的样式差异
---
globs: *.vue,*.scss,*.css
---

View File

@@ -0,0 +1,62 @@
# uni-app 开发规范
## 页面开发
- 页面文件放在 [src/pages/](mdc:src/pages/) 目录下
- 使用约定式路由,文件名即路由路径
- 页面配置在仅需要在 宏`definePage` 中配置标题等内容即可,会自动生成到 `pages.json` 中
## 组件开发
- 组件文件放在 [src/components/](mdc:src/components/) 或者 [src/pages/xx/components/](mdc:src/pages/xx/components/) 目录下
- 使用 uni-app 内置组件和第三方组件库
- 支持 wot-ui\uview-pro\uv-ui\sard-ui\uview-plus 等多种第三方组件库 和 z-paging 组件
- 自定义组件遵循 uni-app 组件规范
## 平台适配
- 使用条件编译处理平台差异
- 支持 H5、小程序、APP 多平台
- 注意各平台的 API 差异
- 使用 uni.xxx API 替代原生 API
## 示例代码结构
```vue
<script setup lang="ts">
// #ifdef H5
import { h5Api } from '@/utils/h5'
// #endif
// #ifdef MP-WEIXIN
import { mpApi } from '@/utils/mp'
// #endif
const handleClick = () => {
// #ifdef H5
h5Api.showToast('H5 平台')
// #endif
// #ifdef MP-WEIXIN
mpApi.showToast('微信小程序')
// #endif
}
</script>
<template>
<view class="page">
<!-- uni-app 组件 -->
<button @click="handleClick">点击</button>
<!-- 条件渲染 -->
<!-- #ifdef H5 -->
<view>H5 特有内容</view>
<!-- #endif -->
</view>
</template>
```
## 生命周期
- 使用 uni-app 页面生命周期
- onLoad、onShow、onReady、onHide、onUnload
- 组件生命周期遵循 Vue3 规范
- 注意页面栈和导航管理
---
globs: src/pages/*.vue,src/components/*.vue
---

View File

@@ -0,0 +1,53 @@
# Vue3 + TypeScript 开发规范
## Vue 组件规范
- 使用 Composition API 和 `<script setup>` 语法
- 组件文件使用 PascalCase 命名
- 页面文件放在 `src/pages/` 目录下
- 全局组件文件放在 `src/components/` 目录下
- 局部组件文件放在页面的 `/components/` 目录下
## Vue SFC 组件规范
- `<script setup lang="ts">` 标签必须是第一个子元素
- `<template>` 标签必须是第二个子元素
- `<style scoped>` 标签必须是最后一个子元素(因为推荐使用原子化类名,所以很可能没有)
## TypeScript 规范
- 严格使用 TypeScript避免使用 `any` 类型
- 为 API 响应数据定义接口类型
- 使用 `interface` 定义对象类型,`type` 定义联合类型
- 导入类型时使用 `import type` 语法
## 状态管理
- 使用 Pinia 进行状态管理
- Store 文件放在 `src/store/` 目录下
- 使用 `defineStore` 定义 store
- 支持持久化存储
## 示例代码结构
```vue
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import type { UserInfo } from '@/types/user'
const userInfo = ref<UserInfo | null>(null)
onMounted(() => {
// 初始化逻辑
})
</script>
<template>
<view class="container">
<!-- 模板内容 -->
</view>
</template>
<style lang="scss" scoped>
.container {
// 样式
}
</style>
---
globs: *.vue,*.ts,*.tsx
---

13
.editorconfig Normal file
View File

@@ -0,0 +1,13 @@
root = true
[*] # 表示所有文件适用
charset = utf-8 # 设置文件字符集为 utf-8
indent_style = space # 缩进风格tab | space
indent_size = 2 # 缩进大小
end_of_line = lf # 控制换行类型(lf | cr | crlf)
trim_trailing_whitespace = true # 去除行首的任意空白字符
insert_final_newline = true # 始终在文件末尾插入一个新行
[*.md] # 表示仅 md 文件适用以下规则
max_line_length = off # 关闭最大行长度限制
trim_trailing_whitespace = false # 关闭末尾空格修剪

48
.gitignore vendored Normal file
View File

@@ -0,0 +1,48 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
.DS_Store
dist
*.local
# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
.hbuilderx
.stylelintcache
.eslintcache
docs/.vitepress/dist
docs/.vitepress/cache
src/types
# 单独把这个文件排除掉,用以解决部分电脑生成的 auto-import.d.ts 的API不完整导致类型提示报错问题
!src/types/auto-import.d.ts
src/manifest.json
src/pages.json
# 2025-10-15 by 菲鸽: lock 文件还是需要加入版本管理,今天又遇到版本不一致导致无法运行的问题了。
# pnpm-lock.yaml
# package-lock.json
# TIPS如果某些文件已经加入了版本管理现在重新加入 .gitignore 是不生效的,需要执行下面的操作
# `git rm -r --cached .` 然后提交 commit 即可。
# git rm -r --cached file1 file2 ## 针对某些文件
# git rm -r --cached dir1 dir2 ## 针对某些文件夹
# git rm -r --cached . ## 针对所有文件
# 更新 uni-app 官方版本
# npx @dcloudio/uvm@latest

1
.husky/commit-msg Normal file
View File

@@ -0,0 +1 @@
npx --no-install commitlint --edit "$1"

1
.husky/pre-commit Normal file
View File

@@ -0,0 +1 @@
npx lint-staged --allow-empty

9
.npmrc Normal file
View File

@@ -0,0 +1,9 @@
# registry = https://registry.npmjs.org
registry = https://registry.npmmirror.com
strict-peer-dependencies=false
auto-install-peers=true
shamefully-hoist=true
ignore-workspace-root-check=true
install-workspace-root=true
node-options=--max-old-space-size=8192

View File

@@ -0,0 +1,122 @@
# unibest 项目概览
这是一个基于 uniapp + Vue3 + TypeScript + Vite5 + UnoCSS 的跨平台开发框架。
## 项目特点
- 支持 H5、小程序、APP 多平台开发
- 使用最新的前端技术栈
- 内置约定式路由、layout布局、请求封装等功能
- 无需依赖 HBuilderX支持命令行开发
## 核心配置文件
- [package.json](mdc:package.json) - 项目依赖和脚本配置
- [vite.config.ts](mdc:vite.config.ts) - Vite 构建配置
- [pages.config.ts](mdc:pages.config.ts) - 页面路由配置
- [manifest.config.ts](mdc:manifest.config.ts) - 应用清单配置
- [uno.config.ts](mdc:uno.config.ts) - UnoCSS 配置
## 主要目录结构
- `src/pages/` - 页面文件
- `src/components/` - 组件文件
- `src/layouts/` - 布局文件
- `src/api/` - API 接口
- `src/http/` - HTTP 请求封装
- `src/store/` - 状态管理
- `src/tabbar/` - 底部导航栏
- `src/App.ku.vue` - 全局根组件(类似 App.vue 里面的 template作用
## 开发命令
- `pnpm dev` - 开发 H5 版本
- `pnpm dev:mp` - 开发微信小程序
- `pnpm dev:mp-alipay` - 开发支付宝小程序(含钉钉)
- `pnpm dev:app` - 开发 APP 版本
- `pnpm build` - 构建生产版本
## Vue 组件规范
- 使用 Composition API 和 `<script setup>` 语法
- 组件文件使用 PascalCase 命名
- 页面文件放在 `src/pages/` 目录下
- 全局组件文件放在 `src/components/` 目录下
- 局部组件文件放在页面的 `/components/` 目录下
## TypeScript 规范
- 严格使用 TypeScript避免使用 `any` 类型
- 为 API 响应数据定义接口类型
- 使用 `interface` 定义对象类型,`type` 定义联合类型
- 导入类型时使用 `import type` 语法
## 状态管理
- 使用 Pinia 进行状态管理
- Store 文件放在 `src/store/` 目录下
- 使用 `defineStore` 定义 store
- 支持持久化存储
## UnoCSS 原子化 CSS
- 项目使用 UnoCSS 作为原子化 CSS 框架
- 配置在 [uno.config.ts]
- 支持预设和自定义规则
- 优先使用原子化类名,减少自定义 CSS
## Vue SFC 组件规范
- `<script setup lang="ts">` 标签必须是第一个子元素
- `<template>` 标签必须是第二个子元素
- `<style scoped>` 标签必须是最后一个子元素(因为推荐使用原子化类名,所以很可能没有)
## 页面开发
- 页面文件放在 [src/pages/]目录下
- 使用约定式路由,文件名即路由路径
- 页面配置在仅需要在 宏`definePage` 中配置标题等内容即可,会自动生成到 `pages.json`
## 组件开发
- 全局组件文件放在 `src/components/` 目录下
- 局部组件文件放在页面的 `/components/` 目录下
- 使用 uni-app 内置组件和第三方组件库
- 支持 wot-ui\uview-pro\uv-ui\sard-ui\uview-plus 等多种第三方组件库 和 z-paging 组件
- 自定义组件遵循 uni-app 组件规范
## 平台适配
- 使用条件编译处理平台差异
- 支持 H5、小程序、APP 多平台
- 注意各平台的 API 差异
- 使用 uni.xxx API 替代原生 API
## 示例代码结构
```vue
<script setup lang="ts">
// #ifdef H5
import { h5Api } from '@/utils/h5'
// #endif
// #ifdef MP-WEIXIN
import { mpApi } from '@/utils/mp'
// #endif
const handleClick = () => {
// #ifdef H5
h5Api.showToast('H5 平台')
// #endif
// #ifdef MP-WEIXIN
mpApi.showToast('微信小程序')
// #endif
}
</script>
<template>
<view class="page">
<!-- uni-app 组件 -->
<button @click="handleClick">点击</button>
<!-- 条件渲染 -->
<!-- #ifdef H5 -->
<view>H5 特有内容</view>
<!-- #endif -->
</view>
</template>
```
## 生命周期
- 使用 uni-app 页面生命周期
- onLoad、onShow、onReady、onHide、onUnload
- 组件生命周期遵循 Vue3 规范
- 注意页面栈和导航管理

15
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,15 @@
{
"recommendations": [
"vue.volar",
"dbaeumer.vscode-eslint",
"antfu.unocss",
"antfu.iconify",
"evils.uniapp-vscode",
"uni-helper.uni-helper-vscode",
"uni-helper.uni-app-schemas-vscode",
"uni-helper.uni-highlight-vscode",
"uni-helper.uni-ui-snippets-vscode",
"uni-helper.uni-app-snippets-vscode",
"streetsidesoftware.code-spell-checker"
]
}

100
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,100 @@
{
// 配置语言的文件关联
"files.associations": {
"pages.json": "jsonc", // pages.json 可以写注释
"manifest.json": "jsonc" // manifest.json 可以写注释
},
"stylelint.enable": false, // 禁用 stylelint
"css.validate": false, // 禁用 CSS 内置验证
"scss.validate": false, // 禁用 SCSS 内置验证
"less.validate": false, // 禁用 LESS 内置验证
"typescript.tsdk": "node_modules\\typescript\\lib",
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.expand": false,
"explorer.fileNesting.patterns": {
"README.md": "index.html,favicon.ico,robots.txt,CHANGELOG.md",
"docker.md": "Dockerfile,docker*.md,nginx*,.dockerignore",
"pages.config.ts": "manifest.config.ts,openapi-ts-request.config.ts",
"package.json": "tsconfig.json,pnpm-lock.yaml,pnpm-workspace.yaml,LICENSE,.gitattributes,.gitignore,.gitpod.yml,CNAME,.npmrc,.browserslistrc",
"eslint.config.mjs": ".commitlintrc.*,.prettier*,.editorconfig,.commitlint.cjs,.eslint*"
},
// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,
// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},
// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off", "fixable": true },
{ "rule": "format/*", "severity": "off", "fixable": true },
{ "rule": "*-indent", "severity": "off", "fixable": true },
{ "rule": "*-spacing", "severity": "off", "fixable": true },
{ "rule": "*-spaces", "severity": "off", "fixable": true },
{ "rule": "*-order", "severity": "off", "fixable": true },
{ "rule": "*-dangle", "severity": "off", "fixable": true },
{ "rule": "*-newline", "severity": "off", "fixable": true },
{ "rule": "*quotes", "severity": "off", "fixable": true },
{ "rule": "*semi", "severity": "off", "fixable": true }
],
// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml",
"xml",
"gql",
"graphql",
"astro",
"svelte",
"css",
"less",
"scss",
"pcss",
"postcss"
],
"cSpell.words": [
"alova",
"Aplipay",
"attributify",
"chooseavatar",
"climblee",
"commitlint",
"dcloudio",
"iconfont",
"oxlint",
"qrcode",
"refresherrefresh",
"scrolltolower",
"tabbar",
"Toutiao",
"uniapp",
"unibest",
"unocss",
"uview",
"uvui",
"Wechat",
"WechatMiniprogram",
"Weixin"
],
"i18n-ally.localesPaths": [
"src/locale"
],
"i18n-ally.keystyle": "nested"
}

77
.vscode/vue3.code-snippets vendored Normal file
View File

@@ -0,0 +1,77 @@
{
// Place your unibest 工作区 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Print unibest Vue3 SFC": {
"scope": "vue",
"prefix": "v3",
"body": [
"<script lang=\"ts\" setup>",
"definePage({",
" style: {",
" navigationBarTitleText: '$1',",
" },",
"})",
"</script>\n",
"<template>",
" <view class=\"\">$3</view>",
"</template>\n",
"<style lang=\"scss\" scoped>",
"//$4",
"</style>\n",
],
},
"Print unibest style": {
"scope": "vue",
"prefix": "st",
"body": [
"<style lang=\"scss\" scoped>",
"//",
"</style>\n"
],
},
"Print unibest script": {
"scope": "vue",
"prefix": "sc",
"body": [
"<script lang=\"ts\" setup>",
"//$1",
"</script>\n"
],
},
"Print unibest script with definePage": {
"scope": "vue",
"prefix": "scdp",
"body": [
"<script lang=\"ts\" setup>",
"definePage({",
" style: {",
" navigationBarTitleText: '$1',",
" },",
"})",
"</script>\n"
],
},
"Print unibest template": {
"scope": "vue",
"prefix": "te",
"body": [
"<template>",
" <view class=\"\">$1</view>",
"</template>\n"
],
},
}

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 菲鸽
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

98
README.md Normal file
View File

@@ -0,0 +1,98 @@
<p align="center">
<a href="https://github.com/unibest-tech/unibest">
<img width="160" src="./src/static/logo.svg">
</a>
</p>
<h1 align="center">
<a href="https://github.com/unibest-tech/unibest" target="_blank">unibest - 最好的 uniapp 开发框架</a>
</h1>
<div align="center">
旧仓库 codercup 进不去了star 也拿不回来,这里也展示一下那个地址的 star.
[![GitHub Repo stars](https://img.shields.io/github/stars/codercup/unibest?style=flat&logo=github)](https://github.com/codercup/unibest)
[![GitHub forks](https://img.shields.io/github/forks/codercup/unibest?style=flat&logo=github)](https://github.com/codercup/unibest)
</div>
<div align="center">
[![GitHub Repo stars](https://img.shields.io/github/stars/feige996/unibest?style=flat&logo=github)](https://github.com/feige996/unibest)
[![GitHub forks](https://img.shields.io/github/forks/feige996/unibest?style=flat&logo=github)](https://github.com/feige996/unibest)
[![star](https://gitee.com/feige996/unibest/badge/star.svg?theme=dark)](https://gitee.com/feige996/unibest/stargazers)
[![fork](https://gitee.com/feige996/unibest/badge/fork.svg?theme=dark)](https://gitee.com/feige996/unibest/members)
![node version](https://img.shields.io/badge/node-%3E%3D18-green)
![pnpm version](https://img.shields.io/badge/pnpm-%3E%3D7.30-green)
![GitHub package.json version (subfolder of monorepo)](https://img.shields.io/github/package-json/v/feige996/unibest)
![GitHub License](https://img.shields.io/github/license/feige996/unibest)
</div>
`unibest` —— 最好的 `uniapp` 开发模板,由 `uniapp` + `Vue3` + `Ts` + `Vite5` + `UnoCss` + `wot-ui` + `z-paging` 构成,使用了最新的前端技术栈,无需依靠 `HBuilderX`,通过命令行方式运行 `web``小程序``App`(编辑器推荐 `VSCode`,可选 `webstorm`)。
`unibest` 内置了 `约定式路由``layout布局``请求封装``请求拦截``登录拦截``UnoCSS``i18n多语言` 等基础功能,提供了 `代码提示``自动格式化``统一配置``代码片段` 等辅助功能,让你编写 `uniapp` 拥有 `best` 体验 `unibest 的由来`)。
![](https://raw.githubusercontent.com/andreasbm/readme/master/screenshots/lines/rainbow.png)
<p align="center">
<a href="https://unibest.tech/" target="_blank">📖 文档地址(new)</a>
<span style="margin:0 10px;">|</span>
<a href="https://unibest-tech.github.io/hello-unibest" target="_blank">📱 DEMO 地址</a>
</p>
---
注意旧的地址 [codercup](https://github.com/codercup/unibest) 我进不去了,使用新的 [feige996](https://github.com/feige996/unibest)。PR和 issue 也请使用新地址,否则无法合并。
## 平台兼容性
| H5 | IOS | 安卓 | 微信小程序 | 字节小程序 | 快手小程序 | 支付宝小程序 | 钉钉小程序 | 百度小程序 |
| --- | --- | ---- | ---------- | ---------- | ---------- | ------------ | ---------- | ---------- |
| √ | √ | √ | √ | √ | √ | √ | √ | √ |
注意每种 `UI框架` 支持的平台有所不同,详情请看各 `UI框架` 的官网,也可以看 `unibest` 文档。
## ⚙️ 环境
- node>=18
- pnpm>=7.30
- Vue Official>=2.1.10
- TypeScript>=5.0
## 新版分支
- main == base
- base --> base-i18n
- base-login --> base-login-i18n
## &#x1F4C2; 快速开始
执行 `pnpm create unibest` 创建项目
执行 `pnpm i` 安装依赖
执行 `pnpm dev` 运行 `H5`
执行 `pnpm dev:mp` 运行 `微信小程序`
## 📦 运行(支持热更新)
- web平台 `pnpm dev:h5`, 然后打开 [http://localhost:9000/](http://localhost:9000/)。
- weixin平台`pnpm dev:mp` 然后打开微信开发者工具,导入本地文件夹,选择本项目的`dist/dev/mp-weixin` 文件。
- APP平台`pnpm dev:app`, 然后打开 `HBuilderX`,导入刚刚生成的`dist/dev/app` 文件夹,选择运行到模拟器(开发时优先使用),或者运行的安卓/ios基座。(如果是 `安卓``鸿蒙` 平台则不用这个方式可以把整个unibest项目导入到hbx通过hbx的菜单来运行到对应的平台。)
## 🔗 发布
- web平台 `pnpm build:h5`,打包后的文件在 `dist/build/h5`可以放到web服务器如nginx运行。如果最终不是放在根目录可以在 `manifest.config.ts` 文件的 `h5.router.base` 属性进行修改。
- weixin平台`pnpm build:mp`, 打包后的文件在 `dist/build/mp-weixin`,然后通过微信开发者工具导入,并点击右上角的“上传”按钮进行上传。
- APP平台`pnpm build:app`, 然后打开 `HBuilderX`,导入刚刚生成的`dist/build/app` 文件夹,选择发行 - APP云打包。(如果是 `安卓``鸿蒙` 平台则不用这个方式可以把整个unibest项目导入到hbx通过hbx的菜单来发行到对应的平台。)
## 📄 License
[MIT](https://opensource.org/license/mit/)
Copyright (c) 2025 菲鸽
## 捐赠
<p align='center'>
<img alt="special sponsor appwrite" src="https://oss.laf.run/ukw0y1-site/pay/wepay.png" height="330" style="display:inline-block; height:330px;">
<img alt="special sponsor appwrite" src="https://oss.laf.run/ukw0y1-site/pay/alipay.jpg" height="330" style="display:inline-block; height:330px; margin-left:10px;">
</p>

30
env/.env vendored Normal file
View File

@@ -0,0 +1,30 @@
VITE_APP_TITLE = 'FlyFishRC'
VITE_APP_PORT = 9000
VITE_UNI_APPID = '__UNI__CFC05C0'
VITE_WX_APPID = 'wxa2abb91f64032a2b'
# h5部署网站的base配置到 manifest.config.ts 里的 h5.router.base
# https://uniapp.dcloud.net.cn/collocation/manifest.html#h5-router
# 比如你要部署到 https://unibest.tech/doc/ ,则配置为 /doc/
VITE_APP_PUBLIC_BASE=/
# 后台请求地址
VITE_SERVER_BASEURL = 'https://ukw0y1.laf.run'
# 备注如果后台带统一前缀则也要加到后面eg: https://ukw0y1.laf.run/api
# 注意,如果是微信小程序,还有一套请求地址的配置,根据 develop、trial、release 分别设置上传地址,见 `src/utils/index.ts`。
# h5是否需要配置代理
VITE_APP_PROXY_ENABLE = false
# 下面的不用修改,只要不跟你后台的统一前缀冲突就行。如果修改了,记得修改 `nginx` 里面的配置
VITE_APP_PROXY_PREFIX = '/fg-api'
# 第二个请求地址 (目前alova中可以使用)
VITE_SERVER_BASEURL_SECONDARY = 'https://ukw0y1.laf.run'
# 认证模式,'single' | 'double' ==> 单token | 双token
VITE_AUTH_MODE = 'single'
# 原生插件资源复制开关,控制是否启用 copy-native-resources 插件
VITE_COPY_NATIVE_RES_ENABLE = false

9
env/.env.development vendored Normal file
View File

@@ -0,0 +1,9 @@
# 变量必须以 VITE_ 为前缀才能暴露给外部读取
NODE_ENV = 'development'
# 是否去除console 和 debugger
VITE_DELETE_CONSOLE = false
# 是否开启sourcemap
VITE_SHOW_SOURCEMAP = false
# 后台请求地址
# VITE_SERVER_BASEURL = 'https://dev.xxx.com'

9
env/.env.production vendored Normal file
View File

@@ -0,0 +1,9 @@
# 变量必须以 VITE_ 为前缀才能暴露给外部读取
NODE_ENV = 'production'
# 是否去除console 和 debugger
VITE_DELETE_CONSOLE = true
# 是否开启sourcemap
VITE_SHOW_SOURCEMAP = false
# 后台请求地址
# VITE_SERVER_BASEURL = 'https://prod.xxx.com'

9
env/.env.test vendored Normal file
View File

@@ -0,0 +1,9 @@
# 变量必须以 VITE_ 为前缀才能暴露给外部读取
NODE_ENV = 'development'
# 是否去除console 和 debugger
VITE_DELETE_CONSOLE = false
# 是否开启sourcemap
VITE_SHOW_SOURCEMAP = false
# 后台请求地址
# VITE_SERVER_BASEURL = 'https://test.xxx.com'

58
eslint.config.mjs Normal file
View File

@@ -0,0 +1,58 @@
import uniHelper from '@uni-helper/eslint-config'
export default uniHelper({
unocss: true,
vue: true,
markdown: false,
ignores: [
// 忽略uni_modules目录
'**/uni_modules/',
// 忽略原生插件目录
'**/nativeplugins/',
'dist',
// unplugin-auto-import 生成的类型文件,每次提交都改变,所以加入这里吧,与 .gitignore 配合使用
'auto-import.d.ts',
// vite-plugin-uni-pages 生成的类型文件,每次切换分支都一堆不同的,所以直接 .gitignore
'uni-pages.d.ts',
// 插件生成的文件
'src/pages.json',
'src/manifest.json',
// 忽略自动生成文件
'src/service/**',
],
// https://eslint-config.antfu.me/rules
rules: {
'no-useless-return': 'off',
'no-console': 'off',
'no-unused-vars': 'off',
'vue/no-unused-refs': 'off',
'unused-imports/no-unused-vars': 'off',
'eslint-comments/no-unlimited-disable': 'off',
'jsdoc/check-param-names': 'off',
'jsdoc/require-returns-description': 'off',
'ts/no-empty-object-type': 'off',
'no-extend-native': 'off',
'vue/singleline-html-element-content-newline': [
'error',
{
externalIgnores: ['text'],
},
],
// vue SFC 调换顺序改这里
'vue/block-order': ['error', {
order: [['script', 'template'], 'style'],
}],
},
formatters: {
/**
* Format CSS, LESS, SCSS files, also the `<style>` blocks in Vue
* By default uses Prettier
*/
css: true,
/**
* Format HTML files
* By default uses Prettier
*/
html: true,
},
})

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

26
index.html Normal file
View File

@@ -0,0 +1,26 @@
<!doctype html>
<html build-time="%BUILD_TIME%">
<head>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<script>
var coverSupport =
'CSS' in window &&
typeof CSS.supports === 'function' &&
(CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
document.write(
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
(coverSupport ? ', viewport-fit=cover' : '') +
'" />',
)
</script>
<title>%VITE_APP_TITLE%</title>
<!--preload-links-->
<!--app-context-->
</head>
<body>
<div id="app"><!--app-html--></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

172
manifest.config.ts Normal file
View File

@@ -0,0 +1,172 @@
import path from 'node:path'
import process from 'node:process'
// manifest.config.ts
import { defineManifestConfig } from '@uni-helper/vite-plugin-uni-manifest'
import { loadEnv } from 'vite'
// 手动解析命令行参数获取 mode
function getMode() {
const args = process.argv.slice(2)
const modeFlagIndex = args.findIndex(arg => arg === '--mode')
return modeFlagIndex !== -1 ? args[modeFlagIndex + 1] : args[0] === 'build' ? 'production' : 'development' // 默认 development
}
// 获取环境变量的范例
const env = loadEnv(getMode(), path.resolve(process.cwd(), 'env'))
const {
VITE_APP_TITLE,
VITE_UNI_APPID,
VITE_WX_APPID,
VITE_APP_PUBLIC_BASE,
VITE_FALLBACK_LOCALE,
} = env
// console.log('manifest.config.ts env:', env)
export default defineManifestConfig({
'name': VITE_APP_TITLE,
'appid': VITE_UNI_APPID,
'description': '',
'versionName': '1.0.0',
'versionCode': '100',
'transformPx': false,
'locale': VITE_FALLBACK_LOCALE, // 'zh-Hans'
'h5': {
router: {
base: VITE_APP_PUBLIC_BASE,
},
},
/* 5+App特有相关 */
'app-plus': {
usingComponents: true,
nvueStyleCompiler: 'uni-app',
compilerVersion: 3,
safearea: {
bottom: {
offset: 'none',
},
},
compatible: {
ignoreVersion: true,
},
pullToRefresh: {
support: true,
},
splashscreen: {
alwaysShowBeforeRender: true,
waiting: true,
autoclose: true,
delay: 0,
},
/* 模块配置 */
modules: {},
/* 应用发布信息 */
distribute: {
/* android打包配置 */
android: {
minSdkVersion: 21,
targetSdkVersion: 30,
abiFilters: ['armeabi-v7a', 'arm64-v8a'],
permissions: [
'<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>',
'<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>',
'<uses-permission android:name="android.permission.VIBRATE"/>',
'<uses-permission android:name="android.permission.READ_LOGS"/>',
'<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>',
'<uses-feature android:name="android.hardware.camera.autofocus"/>',
'<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>',
'<uses-permission android:name="android.permission.CAMERA"/>',
'<uses-permission android:name="android.permission.GET_ACCOUNTS"/>',
'<uses-permission android:name="android.permission.READ_PHONE_STATE"/>',
'<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>',
'<uses-permission android:name="android.permission.WAKE_LOCK"/>',
'<uses-permission android:name="android.permission.FLASHLIGHT"/>',
'<uses-feature android:name="android.hardware.camera"/>',
'<uses-permission android:name="android.permission.WRITE_SETTINGS"/>',
],
},
/* ios打包配置 */
ios: {},
/* SDK配置 */
sdkConfigs: {},
/* 图标配置 */
icons: {
android: {
hdpi: 'static/app/icons/72x72.png',
xhdpi: 'static/app/icons/96x96.png',
xxhdpi: 'static/app/icons/144x144.png',
xxxhdpi: 'static/app/icons/192x192.png',
},
ios: {
appstore: 'static/app/icons/1024x1024.png',
ipad: {
'app': 'static/app/icons/76x76.png',
'app@2x': 'static/app/icons/152x152.png',
'notification': 'static/app/icons/20x20.png',
'notification@2x': 'static/app/icons/40x40.png',
'proapp@2x': 'static/app/icons/167x167.png',
'settings': 'static/app/icons/29x29.png',
'settings@2x': 'static/app/icons/58x58.png',
'spotlight': 'static/app/icons/40x40.png',
'spotlight@2x': 'static/app/icons/80x80.png',
},
iphone: {
'app@2x': 'static/app/icons/120x120.png',
'app@3x': 'static/app/icons/180x180.png',
'notification@2x': 'static/app/icons/40x40.png',
'notification@3x': 'static/app/icons/60x60.png',
'settings@2x': 'static/app/icons/58x58.png',
'settings@3x': 'static/app/icons/87x87.png',
'spotlight@2x': 'static/app/icons/80x80.png',
'spotlight@3x': 'static/app/icons/120x120.png',
},
},
},
},
},
/* 快应用特有相关 */
'quickapp': {},
/* 小程序特有相关 */
'mp-weixin': {
appid: VITE_WX_APPID,
setting: {
urlCheck: false,
// 是否启用 ES6 转 ES5
es6: true,
minified: true,
},
optimization: {
subPackages: true,
},
// 是否合并组件虚拟节点外层属性uni-app 3.5.1+ 开始支持。目前仅支持 style、class 属性。
// 默认不开启undefined这里设置为开启。
mergeVirtualHostAttributes: true,
// styleIsolation: 'shared',
usingComponents: true,
// __usePrivacyCheck__: true,
},
'mp-alipay': {
usingComponents: true,
styleIsolation: 'shared',
optimization: {
subPackages: true,
},
// 解决支付宝小程序开发工具报错 【globalThis is not defined】
compileOptions: {
globalObjectMode: 'enable',
transpile: {
script: {
ignore: ['node_modules/**'],
},
},
},
},
'mp-baidu': {
usingComponents: true,
},
'mp-toutiao': {
usingComponents: true,
},
'uniStatistics': {
enable: false,
},
'vueVersion': '3',
})

View File

@@ -0,0 +1,14 @@
import { defineConfig } from 'openapi-ts-request'
export default defineConfig([
{
describe: 'unibest-openapi-test',
schemaPath: 'https://ukw0y1.laf.run/unibest-opapi-test.json',
serversPath: './src/service',
requestLibPath: `import request from '@/http/vue-query';\n import { CustomRequestOptions_ } from '@/http/types';`,
requestOptionsType: 'CustomRequestOptions_',
isGenReactQuery: false,
reactQueryMode: 'vue',
isGenJavaScript: false,
},
])

197
package.json Normal file
View File

@@ -0,0 +1,197 @@
{
"name": "flyfishrc",
"type": "module",
"version": "1.0.0",
"unibest-version": "4.1.0",
"unibest-update-time": "2025-11-07",
"packageManager": "pnpm@10.10.0",
"description": "unibest - 最好的 uniapp 开发模板",
"generate-time": "用户创建项目时生成",
"author": {
"name": "feige996",
"zhName": "菲鸽",
"email": "1020103647@qq.com",
"github": "https://github.com/feige996",
"gitee": "https://gitee.com/feige996"
},
"license": "MIT",
"homepage": "https://unibest.tech",
"repository": "https://github.com/feige996/unibest",
"bugs": {
"url": "https://github.com/feige996/unibest/issues",
"url-old": "https://github.com/codercup/unibest/issues"
},
"engines": {
"node": ">=20",
"pnpm": ">=9"
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"uvm": "npx @dcloudio/uvm@latest",
"uvm-rm": "node ./scripts/postupgrade.js",
"postuvm": "echo upgrade uni-app success!",
"dev:app": "uni -p app",
"dev:app:test": "uni -p app --mode test",
"dev:app:prod": "uni -p app --mode production",
"dev:app-android": "uni -p app-android",
"dev:app-ios": "uni -p app-ios",
"dev:custom": "uni -p",
"predev": "pnpm init-baseFiles",
"dev": "uni",
"dev:test": "uni --mode test",
"dev:prod": "uni --mode production",
"dev:h5": "uni",
"dev:h5:test": "uni --mode test",
"dev:h5:prod": "uni --mode production",
"dev:h5:ssr": "uni --ssr",
"dev:mp": "uni -p mp-weixin",
"dev:mp:test": "uni -p mp-weixin --mode test",
"dev:mp:prod": "uni -p mp-weixin --mode production",
"dev:mp-alipay": "uni -p mp-alipay",
"dev:mp-baidu": "uni -p mp-baidu",
"dev:mp-jd": "uni -p mp-jd",
"dev:mp-kuaishou": "uni -p mp-kuaishou",
"dev:mp-lark": "uni -p mp-lark",
"dev:mp-qq": "uni -p mp-qq",
"dev:mp-toutiao": "uni -p mp-toutiao",
"dev:mp-weixin": "uni -p mp-weixin",
"dev:mp-xhs": "uni -p mp-xhs",
"dev:quickapp-webview": "uni -p quickapp-webview",
"dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei",
"dev:quickapp-webview-union": "uni -p quickapp-webview-union",
"build:app": "uni build -p app",
"build:app:test": "uni build -p app --mode test",
"build:app:prod": "uni build -p app --mode production",
"build:app-android": "uni build -p app-android",
"build:app-ios": "uni build -p app-ios",
"build:custom": "uni build -p",
"build:h5": "uni build",
"build:h5:test": "uni build --mode test",
"build:h5:prod": "uni build --mode production",
"build": "uni build",
"build:test": "uni build --mode test",
"build:prod": "uni build --mode production",
"build:h5:ssr": "uni build --ssr",
"build:mp-alipay": "uni build -p mp-alipay",
"build:mp": "uni build -p mp-weixin",
"build:mp:test": "uni build -p mp-weixin --mode test",
"build:mp:prod": "uni build -p mp-weixin --mode production",
"build:mp-baidu": "uni build -p mp-baidu",
"build:mp-jd": "uni build -p mp-jd",
"build:mp-kuaishou": "uni build -p mp-kuaishou",
"build:mp-lark": "uni build -p mp-lark",
"build:mp-qq": "uni build -p mp-qq",
"build:mp-toutiao": "uni build -p mp-toutiao",
"build:mp-weixin": "uni build -p mp-weixin",
"build:mp-xhs": "uni build -p mp-xhs",
"build:quickapp-webview": "uni build -p quickapp-webview",
"build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
"build:quickapp-webview-union": "uni build -p quickapp-webview-union",
"type-check": "vue-tsc --noEmit",
"openapi": "openapi-ts",
"init-husky": "git init && husky",
"init-baseFiles": "node ./scripts/create-base-files.js",
"init-json": "pnpm init-baseFiles",
"prepare": "pnpm init-husky & pnpm init-baseFiles",
"lint": "eslint",
"lint:fix": "eslint --fix"
},
"dependencies": {
"@alova/adapter-uniapp": "^2.0.14",
"@alova/shared": "^1.3.1",
"@dcloudio/uni-app": "3.0.0-4070620250821001",
"@dcloudio/uni-app-harmony": "3.0.0-4070620250821001",
"@dcloudio/uni-app-plus": "3.0.0-4070620250821001",
"@dcloudio/uni-components": "3.0.0-4070620250821001",
"@dcloudio/uni-h5": "3.0.0-4070620250821001",
"@dcloudio/uni-mp-alipay": "3.0.0-4070620250821001",
"@dcloudio/uni-mp-baidu": "3.0.0-4070620250821001",
"@dcloudio/uni-mp-harmony": "3.0.0-4070620250821001",
"@dcloudio/uni-mp-jd": "3.0.0-4070620250821001",
"@dcloudio/uni-mp-kuaishou": "3.0.0-4070620250821001",
"@dcloudio/uni-mp-lark": "3.0.0-4070620250821001",
"@dcloudio/uni-mp-qq": "3.0.0-4070620250821001",
"@dcloudio/uni-mp-toutiao": "3.0.0-4070620250821001",
"@dcloudio/uni-mp-weixin": "3.0.0-4070620250821001",
"@dcloudio/uni-mp-xhs": "3.0.0-4070620250821001",
"@dcloudio/uni-quickapp-webview": "3.0.0-4070620250821001",
"abortcontroller-polyfill": "^1.7.8",
"alova": "^3.3.3",
"dayjs": "1.11.10",
"js-cookie": "^3.0.5",
"less": "^4.4.2",
"pinia": "2.0.36",
"pinia-plugin-persistedstate": "3.2.1",
"vue": "^3.4.21",
"vue-i18n": "9.1.9",
"vue-router": "4.5.1",
"wot-design-uni": "latest",
"z-paging": "2.8.7"
},
"devDependencies": {
"@commitlint/cli": "^19.8.1",
"@commitlint/config-conventional": "^19.8.1",
"@dcloudio/types": "^3.4.8",
"@dcloudio/uni-automator": "3.0.0-4070620250821001",
"@dcloudio/uni-cli-shared": "3.0.0-4070620250821001",
"@dcloudio/uni-stacktracey": "3.0.0-4070620250821001",
"@dcloudio/vite-plugin-uni": "3.0.0-4070620250821001",
"@esbuild/darwin-arm64": "0.20.2",
"@esbuild/darwin-x64": "0.20.2",
"@iconify-json/carbon": "^1.2.4",
"@iconify/utils": "^3.0.2",
"@rollup/rollup-darwin-x64": "^4.28.0",
"@types/node": "^20.17.9",
"@uni-helper/eslint-config": "0.5.0",
"@uni-helper/plugin-uni": "0.1.0",
"@uni-helper/uni-env": "0.1.8",
"@uni-helper/uni-types": "1.0.0-alpha.6",
"@uni-helper/unocss-preset-uni": "0.2.11",
"@uni-helper/vite-plugin-uni-components": "0.2.3",
"@uni-helper/vite-plugin-uni-layouts": "0.1.11",
"@uni-helper/vite-plugin-uni-manifest": "0.2.8",
"@uni-helper/vite-plugin-uni-pages": "0.3.19",
"@uni-helper/vite-plugin-uni-platform": "0.0.5",
"@uni-ku/bundle-optimizer": "v1.3.15-beta.2",
"@uni-ku/root": "1.4.1",
"@unocss/eslint-plugin": "^66.2.3",
"@unocss/preset-legacy-compat": "66.0.0",
"@vue/runtime-core": "^3.4.21",
"@vue/tsconfig": "^0.1.3",
"autoprefixer": "^10.4.20",
"cross-env": "^10.0.0",
"eslint": "^9.31.0",
"eslint-plugin-format": "^1.0.1",
"husky": "^9.1.7",
"lint-staged": "^15.2.10",
"miniprogram-api-typings": "^4.1.0",
"openapi-ts-request": "^1.10.0",
"postcss": "^8.4.49",
"postcss-html": "^1.8.0",
"postcss-scss": "^4.0.9",
"rollup-plugin-visualizer": "^6.0.3",
"sass": "1.77.8",
"std-env": "^3.9.0",
"typescript": "~5.8.0",
"unocss": "66.0.0",
"unplugin-auto-import": "^20.0.0",
"vite": "5.2.8",
"vite-plugin-restart": "^1.0.0",
"vue-tsc": "^3.0.6"
},
"pnpm": {
"overrides": {
"unconfig": "7.3.2"
}
},
"overrides": {
"unconfig": "7.3.2"
},
"resolutions": {
"bin-wrapper": "npm:bin-wrapper-china",
"unconfig": "7.3.2"
},
"lint-staged": {
"*": "eslint --fix"
}
}

23
pages.config.ts Normal file
View File

@@ -0,0 +1,23 @@
import { defineUniPages } from '@uni-helper/vite-plugin-uni-pages'
import { tabBar } from './src/tabbar/config'
export default defineUniPages({
globalStyle: {
navigationStyle: 'default',
navigationBarTitleText: 'unibest',
navigationBarBackgroundColor: '#f8f8f8',
navigationBarTextStyle: 'black',
backgroundColor: '#f8fafb',
},
easycom: {
autoscan: true,
custom: {
'^fg-(.*)': '@/components/fg-$1/fg-$1.vue',
'^(?!z-paging-refresh|z-paging-load-more)z-paging(.*)':
'z-paging/components/z-paging$1/z-paging$1.vue',
'^wd-(.*)': 'wot-design-uni/components/wd-$1/wd-$1.vue',
},
},
// tabbar 的配置统一在 “./src/tabbar/config.ts” 文件中
tabBar: tabBar as any,
})

14110
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,53 @@
// 基础配置文件生成脚本
// 此脚本用于生成 src/manifest.json 和 src/pages.json 基础文件
// 由于这两个配置文件会被添加到 .gitignore 中,因此需要通过此脚本确保项目能正常运行
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
// 获取当前文件的目录路径(替代 CommonJS 中的 __dirname
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// 最简可运行配置
const manifest = { }
const pages = {
pages: [
{
path: 'pages/index/index',
type: 'home',
style: {
navigationStyle: 'custom',
navigationBarTitleText: '首页',
},
},
{
path: 'pages/me/me',
type: 'page',
style: {
navigationBarTitleText: '我的',
},
},
],
subPackages: [],
}
// 使用修复后的 __dirname 来解析文件路径
const manifestPath = path.resolve(__dirname, '../src/manifest.json')
const pagesPath = path.resolve(__dirname, '../src/pages.json')
// 确保 src 目录存在
const srcDir = path.resolve(__dirname, '../src')
if (!fs.existsSync(srcDir)) {
fs.mkdirSync(srcDir, { recursive: true })
}
// 如果 src/manifest.json 不存在,就创建它;存在就不处理,以免覆盖
if (!fs.existsSync(manifestPath) || fs.statSync(manifestPath).size === 0) {
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2))
}
// 如果 src/pages.json 不存在,就创建它;存在就不处理,以免覆盖
if (!fs.existsSync(pagesPath) || fs.statSync(pagesPath).size === 0) {
fs.writeFileSync(pagesPath, JSON.stringify(pages, null, 2))
}

83
scripts/open-dev-tools.js Normal file
View File

@@ -0,0 +1,83 @@
import { exec } from 'node:child_process'
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'
/**
* 打开开发者工具
*/
function _openDevTools() {
const platform = process.platform // darwin, win32, linux
const { UNI_PLATFORM } = process.env // mp-weixin, mp-alipay
const uniPlatformText = UNI_PLATFORM === 'mp-weixin' ? '微信小程序' : UNI_PLATFORM === 'mp-alipay' ? '支付宝小程序' : '小程序'
// 项目路径(构建输出目录)
const projectPath = path.resolve(process.cwd(), `dist/dev/${UNI_PLATFORM}`)
// 检查构建输出目录是否存在
if (!fs.existsSync(projectPath)) {
console.log(`${uniPlatformText}构建目录不存在:`, projectPath)
return
}
console.log(`🚀 正在打开${uniPlatformText}开发者工具...`)
// 根据不同操作系统执行不同命令
let command = ''
if (platform === 'darwin') {
// macOS
if (UNI_PLATFORM === 'mp-weixin') {
command = `/Applications/wechatwebdevtools.app/Contents/MacOS/cli -o "${projectPath}"`
}
else if (UNI_PLATFORM === 'mp-alipay') {
command = `/Applications/小程序开发者工具.app/Contents/MacOS/小程序开发者工具 --p "${projectPath}"`
}
}
else if (platform === 'win32' || platform === 'win64') {
// Windows
if (UNI_PLATFORM === 'mp-weixin') {
command = `"C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat" -o "${projectPath}"`
}
}
else {
// Linux 或其他系统
console.log('❌ 当前系统不支持自动打开微信开发者工具')
return
}
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(`❌ 打开${uniPlatformText}开发者工具失败:`, error.message)
console.log(`💡 请确保${uniPlatformText}开发者工具服务端口已启用`)
console.log(`💡 可以手动打开${uniPlatformText}开发者工具并导入项目:`, projectPath)
return
}
if (stderr) {
console.log('⚠️ 警告:', stderr)
}
console.log(`${uniPlatformText}开发者工具已打开`)
if (stdout) {
console.log(stdout)
}
})
}
export default function openDevTools() {
// 首次构建标记
let isFirstBuild = true
return {
name: 'uni-devtools',
writeBundle() {
if (isFirstBuild && process.env.UNI_PLATFORM?.includes('mp')) {
isFirstBuild = false
_openDevTools()
}
},
}
}

95
scripts/postupgrade.js Normal file
View File

@@ -0,0 +1,95 @@
// # 执行 `pnpm upgrade` 后会升级 `uniapp` 相关依赖
// # 在升级完后,会自动添加很多无用依赖,这需要删除以减小依赖包体积
// # 只需要执行下面的命令即可
import { exec } from 'node:child_process'
import { promisify } from 'node:util'
// 日志控制开关,设置为 true 可以启用所有日志输出
const FG_LOG_ENABLE = true
// 将 exec 转换为返回 Promise 的函数
const execPromise = promisify(exec)
// 定义要执行的命令
const dependencies = [
// TODO: 如果不需要某个平台的小程序,请手动删除或注释掉
'@dcloudio/uni-mp-baidu',
'@dcloudio/uni-mp-jd',
'@dcloudio/uni-mp-kuaishou',
'@dcloudio/uni-mp-qq',
'@dcloudio/uni-mp-xhs',
'@dcloudio/uni-quickapp-webview',
]
/**
* 带开关的日志输出函数
* @param {string} message 日志消息
* @param {string} type 日志类型 (log, error)
*/
function log(message, type = 'log') {
if (FG_LOG_ENABLE) {
if (type === 'error') {
console.error(message)
}
else {
console.log(message)
}
}
}
/**
* 卸载单个依赖包
* @param {string} dep 依赖包名
* @returns {Promise<boolean>} 是否成功卸载
*/
async function uninstallDependency(dep) {
try {
log(`开始卸载依赖: ${dep}`)
const { stdout, stderr } = await execPromise(`pnpm un ${dep}`)
if (stdout) {
log(`stdout [${dep}]: ${stdout}`)
}
if (stderr) {
log(`stderr [${dep}]: ${stderr}`, 'error')
}
log(`成功卸载依赖: ${dep}`)
return true
}
catch (error) {
// 单个依赖卸载失败不影响其他依赖
log(`卸载依赖 ${dep} 失败: ${error.message}`, 'error')
return false
}
}
/**
* 串行卸载所有依赖包
*/
async function uninstallAllDependencies() {
log(`开始串行卸载 ${dependencies.length} 个依赖包...`)
let successCount = 0
let failedCount = 0
// 串行执行所有卸载命令
for (const dep of dependencies) {
const success = await uninstallDependency(dep)
if (success) {
successCount++
}
else {
failedCount++
}
// 为了避免命令执行过快导致的问题,添加短暂延迟
await new Promise(resolve => setTimeout(resolve, 100))
}
log(`卸载操作完成: 成功 ${successCount} 个, 失败 ${failedCount}`)
}
// 执行串行卸载
uninstallAllDependencies().catch((err) => {
log(`串行卸载过程中出现未捕获的错误: ${err}`, 'error')
})

52
src/App.ku.vue Normal file
View File

@@ -0,0 +1,52 @@
<script setup lang="ts">
import { ref } from 'vue'
import FgTabbar from '@/tabbar/index.vue'
import { isPageTabbar } from './tabbar/store'
import { currRoute } from './utils'
const isCurrentPageTabbar = ref(true)
onShow(() => {
console.log('App.ku.vue onShow', currRoute())
const { path } = currRoute()
// “蜡笔小开心”提到本地是 '/pages/index/index',线上是 '/' 导致线上 tabbar 不见了
// 所以这里需要判断一下,如果是 '/' 就当做首页,也要显示 tabbar
if (path === '/') {
isCurrentPageTabbar.value = true
}
else {
isCurrentPageTabbar.value = isPageTabbar(path)
}
})
const helloKuRoot = ref('Hello AppKuVue')
const exposeRef = ref('this is form app.Ku.vue')
defineExpose({
exposeRef,
})
</script>
<template>
<view id="app-inner">
<!-- 这个先隐藏了知道这样用就行 -->
<view class="hidden text-center">
{{ helloKuRoot }}这里可以配置全局的东西
</view>
<KuRootView />
<FgTabbar v-if="isCurrentPageTabbar" />
</view>
</template>
<style lang="scss">
#app-inner {
height: 100%;
background-color: #f8fafb;
// height: calc(100vh - 105rpx - env(safe-area-inset-bottom) - env(safe-area-inset-top));
}
body {
background-color: #f8fafb;
}
</style>

34
src/App.vue Normal file
View File

@@ -0,0 +1,34 @@
<script setup lang="ts">
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
import { navigateToInterceptor } from '@/router/interceptor'
onLaunch((options) => {
console.log('App.vue onLaunch', options)
})
onShow((options) => {
console.log('App.vue onShow', options)
// 处理直接进入页面路由的情况如h5直接输入路由、微信小程序分享后进入等
// https://github.com/unibest-tech/unibest/issues/192
if (options?.path) {
navigateToInterceptor.invoke({ url: `/${options.path}`, query: options.query })
}
else {
navigateToInterceptor.invoke({ url: '/' })
}
})
onHide(() => {
console.log('App Hide')
})
</script>
<style lang="scss">
/* 隐藏所有标签的滚动条 */
* {
&::-webkit-scrollbar {
display: none;
width: 0;
height: 0;
color: transparent;
}
}
</style>

17
src/api/foo-alova.ts Normal file
View File

@@ -0,0 +1,17 @@
import { API_DOMAINS, http } from '@/http/alova'
export interface IFoo {
id: number
name: string
}
export function foo() {
return http.Get<IFoo>('/foo', {
params: {
name: '菲鸽',
page: 1,
pageSize: 10,
},
meta: { domain: API_DOMAINS.SECONDARY }, // 用于切换请求地址
})
}

43
src/api/foo.ts Normal file
View File

@@ -0,0 +1,43 @@
import { http } from '@/http/http'
export interface IFoo {
id: number
name: string
}
export function foo() {
return http.Get<IFoo>('/foo', {
params: {
name: '菲鸽',
page: 1,
pageSize: 10,
},
})
}
export interface IFooItem {
id: string
name: string
}
/** GET 请求 */
export async function getFooAPI(name: string) {
return await http.get<IFooItem>('/foo', { name })
}
/** GET 请求;支持 传递 header 的范例 */
export function getFooAPI2(name: string) {
return http.get<IFooItem>('/foo', { name }, { 'Content-Type-100': '100' })
}
/** POST 请求 */
export function postFooAPI(name: string) {
return http.post<IFooItem>('/foo', { name })
}
/** POST 请求;需要传递 query 参数的范例微信小程序经常有同时需要query参数和body参数的场景 */
export function postFooAPI2(name: string) {
return http.post<IFooItem>('/foo', { name }, { a: 1, b: 2 })
}
/** POST 请求;支持 传递 header 的范例 */
export function postFooAPI3(name: string) {
return http.post<IFooItem>('/foo', { name }, { a: 1, b: 2 }, { 'Content-Type-100': '100' })
}

85
src/api/login.ts Normal file
View File

@@ -0,0 +1,85 @@
import type { IAuthLoginRes, ICaptcha, IDoubleTokenRes, IUpdateInfo, IUpdatePassword, IUserInfoRes } from './types/login'
import { http } from '@/http/http'
/**
* 登录表单
*/
export interface ILoginForm {
username: string
password: string
}
/**
* 获取验证码
* @returns ICaptcha 验证码
*/
export function getCode() {
return http.get<ICaptcha>('/user/getCode')
}
/**
* 用户登录
* @param loginForm 登录表单
*/
export function login(loginForm: ILoginForm) {
return http.post<IAuthLoginRes>('/auth/login', loginForm)
}
/**
* 刷新token
* @param refreshToken 刷新token
*/
export function refreshToken(refreshToken: string) {
return http.post<IDoubleTokenRes>('/auth/refreshToken', { refreshToken })
}
/**
* 获取用户信息
*/
export function getUserInfo() {
return http.get<IUserInfoRes>('/user/info')
}
/**
* 退出登录
*/
export function logout() {
return http.get<void>('/auth/logout')
}
/**
* 修改用户信息
*/
export function updateInfo(data: IUpdateInfo) {
return http.post('/user/updateInfo', data)
}
/**
* 修改用户密码
*/
export function updateUserPassword(data: IUpdatePassword) {
return http.post('/user/updatePassword', data)
}
/**
* 获取微信登录凭证
* @returns Promise 包含微信登录凭证(code)
*/
export function getWxCode() {
return new Promise<UniApp.LoginRes>((resolve, reject) => {
uni.login({
provider: 'weixin',
success: res => resolve(res),
fail: err => reject(new Error(err)),
})
})
}
/**
* 微信登录
* @param params 微信登录参数包含code
* @returns Promise 包含登录结果
*/
export function wxLogin(data: { code: string }) {
return http.post<IAuthLoginRes>('/auth/wxLogin', data)
}

97
src/api/types/login.ts Normal file
View File

@@ -0,0 +1,97 @@
// 认证模式类型
export type AuthMode = 'single' | 'double'
// 单Token响应类型
export interface ISingleTokenRes {
token: string
expiresIn: number // 有效期(秒)
}
// 双Token响应类型
export interface IDoubleTokenRes {
accessToken: string
refreshToken: string
accessExpiresIn: number // 访问令牌有效期(秒)
refreshExpiresIn: number // 刷新令牌有效期(秒)
}
/**
* 登录返回的信息,其实就是 token 信息
*/
export type IAuthLoginRes = ISingleTokenRes | IDoubleTokenRes
/**
* 用户信息
*/
export interface IUserInfoRes {
userId: number
username: string
nickname: string
avatar?: string
[key: string]: any // 允许其他扩展字段
}
// 认证存储数据结构
export interface AuthStorage {
mode: AuthMode
tokens: ISingleTokenRes | IDoubleTokenRes
userInfo?: IUserInfoRes
loginTime: number // 登录时间戳
}
/**
* 获取验证码
*/
export interface ICaptcha {
captchaEnabled: boolean
uuid: string
image: string
}
/**
* 上传成功的信息
*/
export interface IUploadSuccessInfo {
fileId: number
originalName: string
fileName: string
storagePath: string
fileHash: string
fileType: string
fileBusinessType: string
fileSize: number
}
/**
* 更新用户信息
*/
export interface IUpdateInfo {
id: number
name: string
sex: string
}
/**
* 更新用户信息
*/
export interface IUpdatePassword {
id: number
oldPassword: string
newPassword: string
confirmPassword: string
}
/**
* 判断是否为单Token响应
* @param tokenRes 登录响应数据
* @returns 是否为单Token响应
*/
export function isSingleTokenRes(tokenRes: IAuthLoginRes): tokenRes is ISingleTokenRes {
return 'token' in tokenRes && !('refreshToken' in tokenRes)
}
/**
* 判断是否为双Token响应
* @param tokenRes 登录响应数据
* @returns 是否为双Token响应
*/
export function isDoubleTokenRes(tokenRes: IAuthLoginRes): tokenRes is IDoubleTokenRes {
return 'accessToken' in tokenRes && 'refreshToken' in tokenRes
}

0
src/components/.gitkeep Normal file
View File

View File

@@ -0,0 +1,31 @@
<script setup lang="ts">
const props = defineProps<{
disabled?: boolean
}>()
</script>
<template>
<view class="ff-btn" :class="{ disabled }">
<slot>按钮文本</slot>
</view>
</template>
<style lang="scss" scoped>
.ff-btn {
width: 100%;
height: 80rpx;
display: flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
text-align: center;
font-size: 32rpx;
color: #ffffff;
background-color: #0070d5;
border-radius: 80rpx;
&.disabled {
background-color: rgba(0, 112, 213, 0.65);
}
}
</style>

View File

@@ -0,0 +1,85 @@
<script setup lang="ts">
const props = defineProps<{
noticeStyle?: 'white' | 'black'
}>()
function toSearchPage() {
uni.navigateTo({
url: '/pages/search/search',
})
}
onMounted(() => {
uni.getSystemInfo({
success: (res) => {
console.log('getSystemInfo success: ', res)
},
})
// #ifdef APP-IOS
console.log('searchBar mounted')
// #endif
})
</script>
<template>
<view class="search-bar">
<view class="search-input" @click="toSearchPage">
<image class="prefix-icon" src="/static/icons/Search.svg" alt="" mode="aspectFit" />
<text class="search-placeholder">搜索产品</text>
</view>
<!-- <view class="notices">
<image
class="notices-icon"
:src="noticeStyle === 'white' ? '/static/icons/Notice_white.svg' : '/static/icons/Notice.svg'" alt=""
mode="aspectFit"
/>
</view> -->
</view>
</template>
<style lang="less" scoped>
.search-bar {
padding: 0 28rpx;
display: flex;
align-items: center;
.search-input {
display: flex;
align-items: center;
background-color: rgba(#f9f9f9, 0.5);
border-radius: 10rpx;
padding: 14rpx;
flex: 1;
height: 68rpx;
box-sizing: border-box;
.prefix-icon {
height: 32rpx;
width: 32rpx;
margin-right: 8rpx;
}
.search-icon {
font-size: 64rpx;
margin-right: 20rpx;
color: #999;
}
.search-placeholder {
color: #999;
font-size: 28rpx;
}
}
.notices {
height: 48rpx;
width: 48rpx;
flex-shrink: 0;
margin-left: 36rpx;
> image {
max-width: 100%;
height: 48rpx;
}
}
}
</style>

View File

@@ -0,0 +1,201 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { useSearchStore } from '@/store/search'
const props = defineProps<{
hasFeature?: boolean
autoFocus: boolean
}>()
const emit = defineEmits<{
(e: 'onClickSearchInput'): boolean
}>()
const searchStore = useSearchStore()
const focus = ref(false)
function handleInput(e: any) {
searchStore.searchText = e.detail.value
}
function clearSearchAndFocus() {
searchStore.clearSearch()
focus.value = true
}
function back() {
searchStore.searchText = ''
uni.navigateBack()
}
function onClickSearchInput() {
searchStore.isSearching = false
emit('onClickSearchInput')
}
const showRelative = computed(() => props.hasFeature && searchStore.isSearching && searchStore.searchText)
function onFocus() {
searchStore.isSearching = true
searchStore.searched = false
}
onMounted(() => {
})
</script>
<template>
<view class="search-input-container">
<view class="search-input-area">
<view class="back-btn" @click="back">
<!-- <svg width="26" height="26" viewBox="0 0 32 32"><path d="M21.781 7.844l-9.063 8.594 9.063 8.594q0.25 0.25 0.25 0.609t-0.25 0.578q-0.25 0.25-0.578 0.25t-0.578-0.25l-9.625-9.125q-0.156-0.125-0.203-0.297t-0.047-0.359q0-0.156 0.047-0.328t0.203-0.297l9.625-9.125q0.25-0.25 0.578-0.25t0.578 0.25q0.25 0.219 0.25 0.578t-0.25 0.578z" fill="#000000" /></svg> -->
<image
src="/static/icons/back.svg"
mode="aspectFit"
/>
</view>
<view class="search-input-wrapper">
<image class="prefix-icon" src="/static/icons/Search.svg" alt="" mode="aspectFit" />
<input
v-model="searchStore.searchText"
:adjust-position="false"
class="search-input-text"
placeholder="Volador"
placeholder-class="input-placeholder"
:auto-focus="autoFocus"
:focus="focus"
@input="handleInput"
@focus="onFocus"
@blur="() => focus = false"
>
<image
v-if="searchStore.searchText"
class="suffix-icon"
src="/static/icons/input_close.svg"
mode="scaleToFill"
@click="clearSearchAndFocus"
/>
</view>
<view class="search-btn" @click="onClickSearchInput">
<text>搜索</text>
</view>
</view>
<!-- 搜索关联提示词列表 -->
<!-- <view v-if="showRelative" class="search-relative-result">
<view class="search-relative-list">
<view class="search-relative-item" @click="onClickRelative('搜索关联词')">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
</view>
</view> -->
</view>
</template>
<style lang="scss" scoped>
.search-input-container {
position: relative;
}
.search-input-area {
display: flex;
align-items: center;
padding: 10rpx 28rpx;
border-radius: 24rpx;
background-color: transparent;
.back-btn {
display: flex;
align-items: center;
justify-content: center;
image {
height: 52rpx;
width: 52rpx;
margin-right: 8rpx;
}
}
.search-input-wrapper {
background-color: rgba(#f5f5f5, 0.5);
display: flex;
padding: 0 17rpx;
align-items: center;
flex-grow: 1;
.prefix-icon {
width: 26rpx;
height: 26rpx;
margin-right: 12rpx;
}
.search-input-text {
flex: 1;
height: 1.4;
font-size: 28rpx;
padding: 15rpx 0;
color: #24272c;
background-color: transparent;
}
.suffix-icon {
width: 26rpx;
height: 26rpx;
margin-left: 12rpx;
}
}
.search-btn {
padding: 0 16rpx;
}
}
.search-relative-result {
background-color: #fff;
position: absolute;
z-index: 100;
top: 100%;
left: 0;
width: 100%;
height: calc(100vh - 120rpx - 122rpx);
overflow: auto;
.search-relative-list {
.search-relative-item {
border-bottom: 2rpx solid #e5e5e5;
padding: 44rpx 0;
margin-left: 32rpx;
border-radius: 12rpx;
font-size: 32rpx;
display: flex;
justify-content: space-between;
align-items: center;
color: rgba(0, 0, 0, 0.9);
&::after {
content: '';
display: inline-block;
width: 18rpx;
height: 18rpx;
border-top: 3rpx solid #999999;
border-right: 3rpx solid #999999;
position: relative;
right: 62rpx;
transform: rotate(45deg);
}
}
}
}
</style>

35
src/env.d.ts vendored Normal file
View File

@@ -0,0 +1,35 @@
/// <reference types="vite/client" />
/// <reference types="vite-svg-loader" />
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
interface ImportMetaEnv {
/** 网站标题,应用名称 */
readonly VITE_APP_TITLE: string
/** 服务端口号 */
readonly VITE_SERVER_PORT: string
/** 后台接口地址 */
readonly VITE_SERVER_BASEURL: string
/** H5是否需要代理 */
readonly VITE_APP_PROXY_ENABLE: 'true' | 'false'
/** H5是否需要代理需要的话有个前缀 */
readonly VITE_APP_PROXY_PREFIX: string
/** 后端是否有统一前缀 /api */
readonly VITE_SERVER_HAS_API_PREFIX: 'true' | 'false'
/** 认证模式,'single' | 'double' ==> 单token | 双token */
readonly VITE_AUTH_MODE: 'single' | 'double'
/** 是否清除console */
readonly VITE_DELETE_CONSOLE: string
// 更多环境变量...
}
interface ImportMeta {
readonly env: ImportMetaEnv
}
declare const __VITE_APP_PROXY__: 'true' | 'false'

54
src/hooks/useRequest.ts Normal file
View File

@@ -0,0 +1,54 @@
import type { Ref } from 'vue'
import { ref } from 'vue'
interface IUseRequestOptions<T> {
/** 是否立即执行 */
immediate?: boolean
/** 初始化数据 */
initialData?: T
}
interface IUseRequestReturn<T, P = undefined> {
loading: Ref<boolean>
error: Ref<boolean | Error>
data: Ref<T | undefined>
run: (args?: P) => Promise<T | undefined>
}
/**
* useRequest是一个定制化的请求钩子用于处理异步请求和响应。
* @param func 一个执行异步请求的函数返回一个包含响应数据的Promise。
* @param options 包含请求选项的对象 {immediate, initialData}。
* @param options.immediate 是否立即执行请求默认为false。
* @param options.initialData 初始化数据默认为undefined。
* @returns 返回一个对象{loading, error, data, run},包含请求的加载状态、错误信息、响应数据和手动触发请求的函数。
*/
export default function useRequest<T, P = undefined>(
func: (args?: P) => Promise<T>,
options: IUseRequestOptions<T> = { immediate: false },
): IUseRequestReturn<T, P> {
const loading = ref(false)
const error = ref(false)
const data = ref<T | undefined>(options.initialData) as Ref<T | undefined>
const run = async (args?: P) => {
loading.value = true
return func(args)
.then((res) => {
data.value = res
error.value = false
return data.value
})
.catch((err) => {
error.value = err
throw err
})
.finally(() => {
loading.value = false
})
}
if (options.immediate) {
(run as (args: P) => Promise<T | undefined>)({} as P)
}
return { loading, error, data, run }
}

116
src/hooks/useScroll.md Normal file
View File

@@ -0,0 +1,116 @@
# 上拉刷新和下拉加载更多
在 unibest 框架中,我们通过组合 `useScroll` Hook 可结合 `scroll-view` 组件来轻松实现上拉刷新和下拉加载更多的功能。
场景一 页面滚动
```
definePage({
style: {
navigationBarTitleText: '上拉刷新和下拉加载更多',
enablePullDownRefresh: true,
onReachBottomDistance: 100,
},
})
```
场景二 局部滚动 结合 `scroll-view`
## 关键文件
- `src/hooks/useScroll.ts`: 提供了核心的滚动逻辑处理 Hook。
- `src/pages-sub/demo/scroll.vue`: 一个具体的实现示例页面。
## `useScroll` Hook
`useScroll` 是一个 Vue Composition API Hook它封装了处理下拉刷新和上拉加载的通用逻辑。
### 主要功能
- **管理加载状态**: 自动处理 `loading`(加载中)、`finished`(已加载全部)和 `error`(加载失败)等状态。
- **分页逻辑**: 内部维护分页参数(页码 `page` 和每页数量 `pageSize`)。
- **事件处理**: 提供 `onScrollToLower`(滚动到底部)、`onRefresherRefresh`(下拉刷新)等方法,用于在视图层触发。
- **数据合并**: 自动将新加载的数据追加到现有列表 `list` 中。
### 使用方法
```typescript
import { useScroll } from '@/hooks/useScroll'
import { getList } from '@/service/list' // 你的数据请求API
const {
list, // 响应式的数据列表
loading, // 是否加载中
finished, // 是否已全部加载
error, // 是否加载失败
onScrollToLower, // 滚动到底部时触发的事件
onRefresherRefresh, // 下拉刷新时触发的事件
} = useScroll(getList) // 将获取数据的API函数传入
```
## `scroll-view` 组件
`scroll-view` 是 uni-app 提供的可滚动视图区域组件,它提供了一系列属性来支持下拉刷新和上拉加载。
### 关键属性
- `scroll-y`: 允许纵向滚动。
- `refresher-enabled`: 启用下拉刷新。
- `refresher-triggered`: 控制下拉刷新动画的显示与隐藏,通过 `loading` 状态绑定。
- `@scrolltolower`: 滚动到底部时触发的事件,绑定 `onScrollToLower` 方法。
- `@refresherrefresh`: 触发下拉刷新时触发的事件,绑定 `onRefresherRefresh` 方法。
## 示例代码
以下是 `src/pages-sub/demo/scroll.vue` 中的核心代码,展示了如何将 `useScroll``scroll-view` 结合使用。
```vue
<template>
<view class="scroll-page">
<scroll-view
class="scroll-view"
scroll-y
:refresher-enabled="true"
:refresher-triggered="loading"
@scrolltolower="onScrollToLower"
@refresherrefresh="onRefresherRefresh"
>
<view v-for="item in list" :key="item.id" class="scroll-item">
{{ item.name }}
</view>
<!-- 加载状态提示 -->
<view v-if="loading" class="loading-tip">加载中...</view>
<view v-if="finished" class="finished-tip">没有更多了</view>
<view v-if="error" class="error-tip">加载失败请重试</view>
</scroll-view>
</view>
</template>
<script setup lang="ts">
import { useScroll } from '@/hooks/useScroll'
import { getList } from '@/service/list'
const { list, loading, finished, error, onScrollToLower, onRefresherRefresh } = useScroll(getList)
</script>
<style scoped>
/* 样式省略 */
.scroll-page, .scroll-view {
height: 100%;
}
</style>
```
## 实现步骤总结
1. **创建API**: 确保你有一个返回分页数据的API请求函数例如 `getList`),它应该接受页码和页面大小作为参数。
2. **调用 `useScroll`**: 在你的页面脚本中,导入并调用 `useScroll` Hook将你的API函数作为参数传入。
3. **模板绑定**:
- 使用 `scroll-view` 组件作为滚动容器。
- 将其 `refresher-triggered` 属性绑定到 `useScroll` 返回的 `loading` 状态。
- 将其 `@scrolltolower` 事件绑定到 `onScrollToLower` 方法。
- 将其 `@refresherrefresh` 事件绑定到 `onRefresherRefresh` 方法。
4. **渲染列表**: 使用 `v-for` 指令渲染 `useScroll` 返回的 `list` 数组。
5. **添加加载提示**: 根据 `loading`, `finished`, `error` 状态,在列表底部显示不同的提示信息,提升用户体验。
通过以上步骤,你就可以在项目中快速集成一个功能完善、体验良好的上拉刷新和下拉加载列表。

74
src/hooks/useScroll.ts Normal file
View File

@@ -0,0 +1,74 @@
import type { Ref } from 'vue'
import { onMounted, ref } from 'vue'
interface UseScrollOptions<T> {
fetchData: (page: number, pageSize: number) => Promise<T[]>
pageSize?: number
}
interface UseScrollReturn<T> {
list: Ref<T[]>
loading: Ref<boolean>
finished: Ref<boolean>
error: Ref<any>
refresh: () => Promise<void>
loadMore: () => Promise<void>
}
export function useScroll<T>({
fetchData,
pageSize = 10,
}: UseScrollOptions<T>): UseScrollReturn<T> {
const list = ref<T[]>([]) as Ref<T[]>
const loading = ref(false)
const finished = ref(false)
const error = ref<any>(null)
const page = ref(1)
const loadData = async () => {
if (loading.value || finished.value)
return
loading.value = true
error.value = null
try {
const data = await fetchData(page.value, pageSize)
if (data.length < pageSize) {
finished.value = true
}
list.value.push(...data)
page.value++
}
catch (err) {
error.value = err
}
finally {
loading.value = false
}
}
const refresh = async () => {
page.value = 1
finished.value = false
list.value = []
await loadData()
}
const loadMore = async () => {
await loadData()
}
onMounted(() => {
refresh()
})
return {
list,
loading,
finished,
error,
refresh,
loadMore,
}
}

171
src/hooks/useUpload.ts Normal file
View File

@@ -0,0 +1,171 @@
import { ref } from 'vue'
import { getEnvBaseUrl } from '@/utils/index'
const VITE_UPLOAD_BASEURL = `${getEnvBaseUrl()}/upload`
type TfileType = 'image' | 'file'
type TImage = 'png' | 'jpg' | 'jpeg' | 'webp' | '*'
type TFile = 'doc' | 'docx' | 'ppt' | 'zip' | 'xls' | 'xlsx' | 'txt' | TImage
interface TOptions<T extends TfileType> {
formData?: Record<string, any>
maxSize?: number
accept?: T extends 'image' ? TImage[] : TFile[]
fileType?: T
success?: (params: any) => void
error?: (err: any) => void
}
export default function useUpload<T extends TfileType>(options: TOptions<T> = {} as TOptions<T>) {
const {
formData = {},
maxSize = 5 * 1024 * 1024,
accept = ['*'],
fileType = 'image',
success,
error: onError,
} = options
const loading = ref(false)
const error = ref<Error | null>(null)
const data = ref<any>(null)
const handleFileChoose = ({ tempFilePath, size }: { tempFilePath: string, size: number }) => {
if (size > maxSize) {
uni.showToast({
title: `文件大小不能超过 ${maxSize / 1024 / 1024}MB`,
icon: 'none',
})
return
}
// const fileExtension = file?.tempFiles?.name?.split('.').pop()?.toLowerCase()
// const isTypeValid = accept.some((type) => type === '*' || type.toLowerCase() === fileExtension)
// if (!isTypeValid) {
// uni.showToast({
// title: `仅支持 ${accept.join(', ')} 格式的文件`,
// icon: 'none',
// })
// return
// }
loading.value = true
uploadFile({
tempFilePath,
formData,
onSuccess: (res) => {
// 修改这里的解析逻辑,适应不同平台的返回格式
let parsedData = res
try {
// 尝试解析为JSON
const jsonData = JSON.parse(res)
// 检查是否包含data字段
parsedData = jsonData.data || jsonData
}
catch (e) {
// 如果解析失败,使用原始数据
console.log('Response is not JSON, using raw data:', res)
}
data.value = parsedData
// console.log('上传成功', res)
success?.(parsedData)
},
onError: (err) => {
error.value = err
onError?.(err)
},
onComplete: () => {
loading.value = false
},
})
}
const run = () => {
// 微信小程序从基础库 2.21.0 开始, wx.chooseImage 停止维护,请使用 uni.chooseMedia 代替。
// 微信小程序在2023年10月17日之后使用本API需要配置隐私协议
const chooseFileOptions = {
count: 1,
success: (res: any) => {
console.log('File selected successfully:', res)
// 小程序中res:{errMsg: "chooseImage:ok", tempFiles: [{fileType: "image", size: 48976, tempFilePath: "http://tmp/5iG1WpIxTaJf3ece38692a337dc06df7eb69ecb49c6b.jpeg"}]}
// h5中res:{errMsg: "chooseImage:ok", tempFilePaths: "blob:http://localhost:9000/f74ab6b8-a14d-4cb6-a10d-fcf4511a0de5", tempFiles: [File]}
// h5的File有以下字段{name: "girl.jpeg", size: 48976, type: "image/jpeg"}
// App中res:{errMsg: "chooseImage:ok", tempFilePaths: "file:///Users/feige/xxx/gallery/1522437259-compressed-IMG_0006.jpg", tempFiles: [File]}
// App的File有以下字段{path: "file:///Users/feige/xxx/gallery/1522437259-compressed-IMG_0006.jpg", size: 48976}
let tempFilePath = ''
let size = 0
// #ifdef MP-WEIXIN
tempFilePath = res.tempFiles[0].tempFilePath
size = res.tempFiles[0].size
// #endif
// #ifndef MP-WEIXIN
tempFilePath = res.tempFilePaths[0]
size = res.tempFiles[0].size
// #endif
handleFileChoose({ tempFilePath, size })
},
fail: (err: any) => {
console.error('File selection failed:', err)
error.value = err
onError?.(err)
},
}
if (fileType === 'image') {
// #ifdef MP-WEIXIN
uni.chooseMedia({
...chooseFileOptions,
mediaType: ['image'],
})
// #endif
// #ifndef MP-WEIXIN
uni.chooseImage(chooseFileOptions)
// #endif
}
else {
uni.chooseFile({
...chooseFileOptions,
type: 'all',
})
}
}
return { loading, error, data, run }
}
async function uploadFile({
tempFilePath,
formData,
onSuccess,
onError,
onComplete,
}: {
tempFilePath: string
formData: Record<string, any>
onSuccess: (data: any) => void
onError: (err: any) => void
onComplete: () => void
}) {
uni.uploadFile({
url: VITE_UPLOAD_BASEURL,
filePath: tempFilePath,
name: 'file',
formData,
success: (uploadFileRes) => {
try {
const data = uploadFileRes.data
onSuccess(data)
}
catch (err) {
onError(err)
}
},
fail: (err) => {
console.error('Upload failed:', err)
onError(err)
},
complete: onComplete,
})
}

13
src/http/README.md Normal file
View File

@@ -0,0 +1,13 @@
# 请求库
目前unibest支持3种请求库
- 菲鸽简单封装的 `简单版本http`路径src/http/http.ts对应的示例在 src/api/foo.ts
- `alova 的 http`路径src/http/alova.ts对应的示例在 src/api/foo-alova.ts
- `vue-query`, 路径src/http/vue-query.ts, 目前主要用在自动生成接口,详情看(https://unibest.tech/base/17-generate),示例在 src/service/app 文件夹
## 如何选择
如果您以前用过 alova 或者 vue-query可以优先使用您熟悉的。
如果您的项目简单简单版本的http 就够了也不会增加包体积。发版的时候可以去掉alova和vue-query如果没有超过包体积留着也无所谓 ^_^
## roadmap
菲鸽最近在优化脚手架后续可以选择是否使用第三方的请求库以及选择什么请求库。还在开发中大概月底出来8月31号

119
src/http/alova.ts Normal file
View File

@@ -0,0 +1,119 @@
import type { uniappRequestAdapter } from '@alova/adapter-uniapp'
import type { IResponse } from './types'
import AdapterUniapp from '@alova/adapter-uniapp'
import { createAlova } from 'alova'
import { createServerTokenAuthentication } from 'alova/client'
import VueHook from 'alova/vue'
import { toLoginPage } from '@/utils/toLoginPage'
import { ContentTypeEnum, ResultEnum, ShowMessage } from './tools/enum'
// 配置动态Tag
export const API_DOMAINS = {
DEFAULT: import.meta.env.VITE_SERVER_BASEURL,
SECONDARY: import.meta.env.VITE_SERVER_BASEURL_SECONDARY,
}
/**
* 创建请求实例
*/
const { onAuthRequired, onResponseRefreshToken } = createServerTokenAuthentication<
typeof VueHook,
typeof uniappRequestAdapter
>({
// 如果下面拦截不到,请使用 refreshTokenOnSuccess by 群友@琛
refreshTokenOnError: {
isExpired: (error) => {
return error.response?.status === ResultEnum.Unauthorized
},
handler: async () => {
try {
// await authLogin();
}
catch (error) {
// 切换到登录页
toLoginPage({ mode: 'reLaunch' })
throw error
}
},
},
})
/**
* alova 请求实例
*/
const alovaInstance = createAlova({
baseURL: API_DOMAINS.DEFAULT,
...AdapterUniapp(),
timeout: 5000,
statesHook: VueHook,
beforeRequest: onAuthRequired((method) => {
// 设置默认 Content-Type
method.config.headers = {
ContentType: ContentTypeEnum.JSON,
Accept: 'application/json, text/plain, */*',
...method.config.headers,
}
const { config } = method
const ignoreAuth = !config.meta?.ignoreAuth
console.log('ignoreAuth===>', ignoreAuth)
// 处理认证信息 自行处理认证问题
if (ignoreAuth) {
const token = 'getToken()'
if (!token) {
throw new Error('[请求错误]:未登录')
}
// method.config.headers.token = token;
}
// 处理动态域名
if (config.meta?.domain) {
method.baseURL = config.meta.domain
console.log('当前域名', method.baseURL)
}
}),
responded: onResponseRefreshToken((response, method) => {
const { config } = method
const { requestType } = config
const {
statusCode,
data: rawData,
errMsg,
} = response as UniNamespace.RequestSuccessCallbackResult
// 处理特殊请求类型(上传/下载)
if (requestType === 'upload' || requestType === 'download') {
return response
}
// 处理 HTTP 状态码错误
if (statusCode !== 200) {
const errorMessage = ShowMessage(statusCode) || `HTTP请求错误[${statusCode}]`
console.error('errorMessage===>', errorMessage)
uni.showToast({
title: errorMessage,
icon: 'error',
})
throw new Error(`${errorMessage}${errMsg}`)
}
// 处理业务逻辑错误
const { code, message, data } = rawData as IResponse
// 0和200当做成功都很普遍这里直接兼容两者见 ResultEnum
if (code !== ResultEnum.Success0 && code !== ResultEnum.Success200) {
if (config.meta?.toast !== false) {
uni.showToast({
title: message,
icon: 'none',
})
}
throw new Error(`请求错误[${code}]${message}`)
}
// 处理成功响应,返回业务数据
return data
}),
})
export const http = alovaInstance

199
src/http/http.ts Normal file
View File

@@ -0,0 +1,199 @@
import type { IDoubleTokenRes } from '@/api/types/login'
import type { CustomRequestOptions, IResponse } from '@/http/types'
import { nextTick } from 'vue'
import { useTokenStore } from '@/store/token'
import { isDoubleTokenMode } from '@/utils'
import { toLoginPage } from '@/utils/toLoginPage'
import { ResultEnum } from './tools/enum'
// 刷新 token 状态管理
let refreshing = false // 防止重复刷新 token 标识
let taskQueue: (() => void)[] = [] // 刷新 token 请求队列
export function http<T>(options: CustomRequestOptions) {
// 1. 返回 Promise 对象
return new Promise<T>((resolve, reject) => {
uni.request({
...options,
dataType: 'json',
// #ifndef MP-WEIXIN
responseType: 'json',
// #endif
// 响应成功
success: async (res) => {
const responseData = res.data as IResponse<T>
const { code } = responseData
// 检查是否是401错误包括HTTP状态码401或业务码401
const isTokenExpired = res.statusCode === 401 || code === 401
if (isTokenExpired) {
const tokenStore = useTokenStore()
if (!isDoubleTokenMode) {
// 未启用双token策略清理用户信息跳转到登录页
tokenStore.logout()
toLoginPage()
return reject(res)
}
/* -------- 无感刷新 token ----------- */
const { refreshToken } = tokenStore.tokenInfo as IDoubleTokenRes || {}
// token 失效的,且有刷新 token 的,才放到请求队列里
if (refreshToken) {
taskQueue.push(() => {
resolve(http<T>(options))
})
}
// 如果有 refreshToken 且未在刷新中,发起刷新 token 请求
if (refreshToken && !refreshing) {
refreshing = true
try {
// 发起刷新 token 请求(使用 store 的 refreshToken 方法)
await tokenStore.refreshToken()
// 刷新 token 成功
refreshing = false
nextTick(() => {
// 关闭其他弹窗
uni.hideToast()
uni.showToast({
title: 'token 刷新成功',
icon: 'none',
})
})
// 将任务队列的所有任务重新请求
taskQueue.forEach(task => task())
}
catch (refreshErr) {
console.error('刷新 token 失败:', refreshErr)
refreshing = false
// 刷新 token 失败,跳转到登录页
nextTick(() => {
// 关闭其他弹窗
uni.hideToast()
uni.showToast({
title: '登录已过期,请重新登录',
icon: 'none',
})
})
// 清除用户信息
await tokenStore.logout()
// 跳转到登录页
setTimeout(() => {
toLoginPage()
}, 2000)
}
finally {
// 不管刷新 token 成功与否,都清空任务队列
taskQueue = []
}
}
return reject(res)
}
// 处理其他成功状态HTTP状态码200-299
if (res.statusCode >= 200 && res.statusCode < 300) {
// 处理业务逻辑错误
if (code !== ResultEnum.Success0 && code !== ResultEnum.Success200) {
uni.showToast({
icon: 'none',
title: responseData.msg || responseData.message || '请求错误',
})
}
return resolve(responseData.data)
}
// 处理其他错误
!options.hideErrorToast
&& uni.showToast({
icon: 'none',
title: (res.data as any).msg || '请求错误',
})
reject(res)
},
// 响应失败
fail(err) {
uni.showToast({
icon: 'none',
title: '网络错误,换个网络试试',
})
reject(err)
},
})
})
}
/**
* GET 请求
* @param url 后台地址
* @param query 请求query参数
* @param header 请求头默认为json格式
* @returns
*/
export function httpGet<T>(url: string, query?: Record<string, any>, header?: Record<string, any>, options?: Partial<CustomRequestOptions>) {
return http<T>({
url,
query,
method: 'GET',
header,
...options,
})
}
/**
* POST 请求
* @param url 后台地址
* @param data 请求body参数
* @param query 请求query参数post请求也支持query很多微信接口都需要
* @param header 请求头默认为json格式
* @returns
*/
export function httpPost<T>(url: string, data?: Record<string, any>, query?: Record<string, any>, header?: Record<string, any>, options?: Partial<CustomRequestOptions>) {
return http<T>({
url,
query,
data,
method: 'POST',
header,
...options,
})
}
/**
* PUT 请求
*/
export function httpPut<T>(url: string, data?: Record<string, any>, query?: Record<string, any>, header?: Record<string, any>, options?: Partial<CustomRequestOptions>) {
return http<T>({
url,
data,
query,
method: 'PUT',
header,
...options,
})
}
/**
* DELETE 请求(无请求体,仅 query
*/
export function httpDelete<T>(url: string, query?: Record<string, any>, header?: Record<string, any>, options?: Partial<CustomRequestOptions>) {
return http<T>({
url,
query,
method: 'DELETE',
header,
...options,
})
}
// 支持与 axios 类似的API调用
http.get = httpGet
http.post = httpPost
http.put = httpPut
http.delete = httpDelete
// 支持与 alovaJS 类似的API调用
http.Get = httpGet
http.Post = httpPost
http.Put = httpPut
http.Delete = httpDelete

69
src/http/interceptor.ts Normal file
View File

@@ -0,0 +1,69 @@
import type { CustomRequestOptions } from '@/http/types'
import { useTokenStore } from '@/store'
import { getEnvBaseUrl } from '@/utils'
import { stringifyQuery } from './tools/queryString'
// 请求基准地址
const baseUrl = getEnvBaseUrl()
// 拦截器配置
const httpInterceptor = {
// 拦截前触发
invoke(options: CustomRequestOptions) {
// 如果您使用了alova则请把下面的代码放开注释
// alova 执行流程alova beforeRequest --> 本拦截器 --> alova responded
// return options
// 非 alova 请求,正常执行
// 接口请求支持通过 query 参数配置 queryString
if (options.query) {
const queryStr = stringifyQuery(options.query)
if (options.url.includes('?')) {
options.url += `&${queryStr}`
}
else {
options.url += `?${queryStr}`
}
}
// 非 http 开头需拼接地址
if (!options.url.startsWith('http')) {
// #ifdef H5
if (JSON.parse(import.meta.env.VITE_APP_PROXY_ENABLE)) {
// 自动拼接代理前缀
options.url = import.meta.env.VITE_APP_PROXY_PREFIX + options.url
}
else {
options.url = baseUrl + options.url
}
// #endif
// 非H5正常拼接
// #ifndef H5
options.url = baseUrl + options.url
// #endif
// TIPS: 如果需要对接多个后端服务,也可以在这里处理,拼接成所需要的地址
}
// 1. 请求超时
options.timeout = 60000 // 60s
// 2. (可选)添加小程序端请求头标识
options.header = {
...options.header,
}
// 3. 添加 token 请求头标识
const tokenStore = useTokenStore()
const token = tokenStore.validToken
if (token) {
options.header.Authorization = `Bearer ${token}`
}
return options
},
}
export const requestInterceptor = {
install() {
// 拦截 request 请求
uni.addInterceptor('request', httpInterceptor)
// 拦截 uploadFile 文件上传
uni.addInterceptor('uploadFile', httpInterceptor)
},
}

68
src/http/tools/enum.ts Normal file
View File

@@ -0,0 +1,68 @@
export enum ResultEnum {
// 0和200当做成功都很普遍这里直接兼容两者PS0和200通常都不会当做错误码但是有的接口会返回0有的接口会返回200
Success0 = 0, // 成功
Success200 = 200, // 成功
Error = 400, // 错误
Unauthorized = 401, // 未授权
Forbidden = 403, // 禁止访问原为forbidden
NotFound = 404, // 未找到原为notFound
MethodNotAllowed = 405, // 方法不允许原为methodNotAllowed
RequestTimeout = 408, // 请求超时原为requestTimeout
InternalServerError = 500, // 服务器错误原为internalServerError
NotImplemented = 501, // 未实现原为notImplemented
BadGateway = 502, // 网关错误原为badGateway
ServiceUnavailable = 503, // 服务不可用原为serviceUnavailable
GatewayTimeout = 504, // 网关超时原为gatewayTimeout
HttpVersionNotSupported = 505, // HTTP版本不支持原为httpVersionNotSupported
}
export enum ContentTypeEnum {
JSON = 'application/json;charset=UTF-8',
FORM_URLENCODED = 'application/x-www-form-urlencoded;charset=UTF-8',
FORM_DATA = 'multipart/form-data;charset=UTF-8',
}
/**
* 根据状态码,生成对应的错误信息
* @param {number|string} status 状态码
* @returns {string} 错误信息
*/
export function ShowMessage(status: number | string): string {
let message: string
switch (status) {
case 400:
message = '请求错误(400)'
break
case 401:
message = '未授权,请重新登录(401)'
break
case 403:
message = '拒绝访问(403)'
break
case 404:
message = '请求出错(404)'
break
case 408:
message = '请求超时(408)'
break
case 500:
message = '服务器错误(500)'
break
case 501:
message = '服务未实现(501)'
break
case 502:
message = '网络错误(502)'
break
case 503:
message = '服务不可用(503)'
break
case 504:
message = '网络超时(504)'
break
case 505:
message = 'HTTP版本不受支持(505)'
break
default:
message = `连接出错(${status})!`
}
return `${message},请检查网络或联系管理员!`
}

View File

@@ -0,0 +1,29 @@
/**
* 将对象序列化为URL查询字符串用于替代第三方的 qs 库,节省宝贵的体积
* 支持基本类型值和数组,不支持嵌套对象
* @param obj 要序列化的对象
* @returns 序列化后的查询字符串
*/
export function stringifyQuery(obj: Record<string, any>): string {
if (!obj || typeof obj !== 'object' || Array.isArray(obj))
return ''
return Object.entries(obj)
.filter(([_, value]) => value !== undefined && value !== null)
.map(([key, value]) => {
// 对键进行编码
const encodedKey = encodeURIComponent(key)
// 处理数组类型
if (Array.isArray(value)) {
return value
.filter(item => item !== undefined && item !== null)
.map(item => `${encodedKey}=${encodeURIComponent(item)}`)
.join('&')
}
// 处理基本类型
return `${encodedKey}=${encodeURIComponent(value)}`
})
.join('&')
}

44
src/http/types.ts Normal file
View File

@@ -0,0 +1,44 @@
/**
* 在 uniapp 的 RequestOptions 和 IUniUploadFileOptions 基础上,添加自定义参数
*/
export type CustomRequestOptions = UniApp.RequestOptions & {
query?: Record<string, any>
/** 出错时是否隐藏错误提示 */
hideErrorToast?: boolean
} & IUniUploadFileOptions // 添加uni.uploadFile参数类型
/** 主要提供给 openapi-ts-request 生成的代码使用 */
export type CustomRequestOptions_ = Omit<CustomRequestOptions, 'url'>
export interface HttpRequestResult<T> {
promise: Promise<T>
requestTask: UniApp.RequestTask
}
// 通用响应格式(兼容 msg + message 字段)
export type IResponse<T = any> = {
code: number
data: T
message: string
[key: string]: any // 允许额外属性
} | {
code: number
data: T
msg: string
[key: string]: any // 允许额外属性
}
// 分页请求参数
export interface PageParams {
page: number
pageSize: number
[key: string]: any
}
// 分页响应数据
export interface PageResult<T> {
list: T[]
total: number
page: number
pageSize: number
}

30
src/http/vue-query.ts Normal file
View File

@@ -0,0 +1,30 @@
import type { CustomRequestOptions } from '@/http/types'
import { http } from './http'
/*
* openapi-ts-request 工具的 request 跨客户端适配方法
*/
export default function request<T extends { data?: any }>(
url: string,
options: Omit<CustomRequestOptions, 'url'> & {
params?: Record<string, unknown>
headers?: Record<string, unknown>
},
) {
const requestOptions = {
url,
...options,
}
if (options.params) {
requestOptions.query = requestOptions.params
delete requestOptions.params
}
if (options.headers) {
requestOptions.header = options.headers
delete requestOptions.headers
}
return http<T['data']>(requestOptions)
}

15
src/layouts/default.vue Normal file
View File

@@ -0,0 +1,15 @@
<script lang="ts" setup>
import { getI18nText } from '@/tabbar/i18n'
import { getCurrentPageI18nKey } from '@/utils'
onShow(() => {
console.log('layout default - onShow')
uni.setNavigationBarTitle({
title: getI18nText(getCurrentPageI18nKey()),
})
})
</script>
<template>
<slot />
</template>

12
src/locale/README.md Normal file
View File

@@ -0,0 +1,12 @@
# 注意事项
> 文件夹名字必须为 `locale`, 这是 `uniapp` 官方约定的,如果改为别的,标题将不能正常切换多语言(其他内容还是正常)。
>
> `xxx.json` 的 `xxx` 多语言标识必须与 `uniapp` 官方约定的一致,否则也会出现 BUG。
>
> 查看截图 `screenshots/i18n.png`。
## 参考文档
[uniapp 国际化开发指南](https://uniapp.dcloud.net.cn/tutorial/i18n.html)
[uniapp 国际化-注意事项](https://uniapp.dcloud.net.cn/api/ui/locale.html#onlocalechange) 最下面的注意事项

36
src/locale/en.json Normal file
View File

@@ -0,0 +1,36 @@
{
"tabbar.home": "Home",
"tabbar.about": "About",
"tabbar.category": "Category",
"tabbar.explore": "Explore",
"tabbar.me": "Me",
"i18n.title": "En Title",
"alova.title": "Alova Request",
"weight": "{heavy}KG",
"detail": "{0}cm, {1}KG",
"introduction": "I am {name},height:{detail.height},weight:{detail.weight}",
"more.category": "More Category",
"agreeDesc1": "I have read and agree to the ",
"agreeDesc2": "and ",
"Terms of Service": "Terms of Service",
"Privacy Policy": "Privacy Policy",
"register.title": "Create an account",
"register.desc": "Create a new account",
"register.emailPH": "Email",
"register.phonePH": "Please enter your phone number",
"register.captchaPH": "Please enter the captcha",
"register.getCaptcha": "Get captcha",
"register.passwordPH": "Password",
"register.confirmPasswordPH": "Confirm Password",
"register.tips": "Already have an account?",
"register.toSign": "Sign in now",
"register.signUp": "Sign up",
"forgot.title": "Reset Password",
"forgot.desc": "Reset Password",
"forgot.phonePH": "Please enter your phone number",
"forgot.emailPH": "Email",
"forgot.captchaPH": "Please enter the captcha",
"forgot.getCaptcha": "Get captcha",
"forgot.passwordPH": "Password",
"forgot.submit": "Submit"
}

85
src/locale/index.ts Normal file
View File

@@ -0,0 +1,85 @@
import { createI18n } from 'vue-i18n'
import en from './en.json'
import zhHans from './zh-Hans.json' // 简体中文
const messages = {
en,
'zh-Hans': zhHans, // key 不能乱写,查看截图 screenshots/i18n.png
}
const i18n = createI18n({
locale: uni.getLocale(), // 获取已设置的语言fallback 语言需要再 manifest.config.ts 中设置
messages,
allowComposition: true,
})
console.log(uni.getLocale())
console.log(i18n.global.locale)
/**
* 可以拿到原始的语言模板,非 vue 文件使用这个方法,
* @param { string } key 多语言的keyeg: "app.name"
* @returns {string} 返回原始的多语言模板eg: "{heavy}KG"
*/
export function getTemplateByKey(key: string) {
if (!key) {
console.error(`[i18n] Function getTemplateByKey(), key param is required`)
return ''
}
const locale = uni.getLocale()
console.log('locale:', locale)
const message = messages[locale] // 拿到某个多语言的所有模板(是一个对象)
if (Object.keys(message).includes(key)) {
return message[key]
}
try {
const keyList = key.split('.')
return keyList.reduce((pre, cur) => {
return pre[cur]
}, message)
}
catch (error) {
console.error(`[i18n] Function getTemplateByKey(), key param ${key} is not existed.`)
return ''
}
}
/**
* formatI18n('我是{name},身高{detail.height},体重{detail.weight}',{name:'张三',detail:{height:178,weight:'75kg'}})
* 暂不支持数组
* @param template 多语言模板字符串eg: `我是{name}`
* @param {object | undefined} data 需要传递的数据对象里面的key与多语言字符串对应eg: `{name:'菲鸽'}`
* @returns
*/
function formatI18n(template: string, data?: any) {
if (!template) {
console.warn(`[i18n] Function formatI18n(), template param is required`)
return ''
}
return template.replace(/\{([^}]+)\}/g, (match, key: string) => {
// console.log( match, key) // => { detail.height } detail.height
const arr = key.trim().split('.')
let result = data
while (arr.length) {
const first = arr.shift()
result = result[first]
}
return result
})
}
/**
* t('introduction',{name:'张三',detail:{height:178,weight:'75kg'}})
* => formatI18n('我是{name},身高{detail.height},体重{detail.weight}',{name:'张三',detail:{height:178,weight:'75kg'}})
* 没有key的可以不传 data暂不支持数组
* @param template 多语言模板字符串eg: `我是{name}`
* @param {object | undefined} data 需要传递的数据对象里面的key与多语言字符串对应eg: `{name:'菲鸽'}`
* @returns
*/
export function t(key, data?) {
return formatI18n(getTemplateByKey(key), data)
}
export default i18n

13
src/locale/ru.json Normal file
View File

@@ -0,0 +1,13 @@
{
"tabbar.home": "Дом",
"tabbar.about": "О нас",
"tabbar.category": "Категории",
"tabbar.explore": "Исследовать",
"tabbar.me": "Мой",
"i18n.title": "Русский Заголовок",
"alova.title": "Alova Запрос",
"weight": "{heavy}KG",
"detail": "{0}cm, {1}KG",
"introduction": "Я {name}, рост:{detail.height}, вес:{detail.weight}",
"more.category": "Еще Категории"
}

37
src/locale/zh-Hans.json Normal file
View File

@@ -0,0 +1,37 @@
{
"tabbar.home": "首页",
"tabbar.about": "关于",
"tabbar.category": "分类",
"tabbar.explore": "发现",
"tabbar.me": "我的",
"i18n.title": "中文标题",
"me.feedback": "意见反馈",
"alova.title": "Alova 请求",
"weight": "{heavy}公斤",
"detail": "{0}cm, {1}公斤",
"introduction": "我是 {name},身高:{detail.height},体重:{detail.weight}",
"more.category": "更多分类",
"agreeDesc1": "我已阅读并同意",
"agreeDesc2": "和",
"Terms of Service": "《服务条款》",
"Privacy Policy": "《隐私政策》",
"register.title": "注册账号",
"register.desc": "注册新的手机号",
"register.emailPH": "邮箱",
"register.phonePH": "请输入手机号",
"register.captchaPH": "请输入验证码",
"register.getCaptcha": "获取验证码",
"register.passwordPH": "请输入密码",
"register.confirmPasswordPH": "请输入确认密码",
"register.tips": "已有账号?",
"register.toSign": "立即登录",
"register.signUp": "注册",
"forgot.title": "重置密码",
"forgot.desc": "重置/找回密码",
"forgot.phonePH": "请输入手机号",
"forgot.emailPH": "邮箱",
"forgot.captchaPH": "请输入验证码",
"forgot.getCaptcha": "获取验证码",
"forgot.passwordPH": "请输入6~12位密码",
"forgot.submit": "提交"
}

21
src/main.ts Normal file
View File

@@ -0,0 +1,21 @@
import { createSSRApp } from 'vue'
import App from './App.vue'
import { requestInterceptor } from './http/interceptor'
import i18n from './locale/index'
import { routeInterceptor } from './router/interceptor'
import store from './store'
import '@/style/index.scss'
import 'virtual:uno.css'
export function createApp() {
const app = createSSRApp(App)
app.use(store)
app.use(i18n)
app.use(routeInterceptor)
app.use(requestInterceptor)
return {
app,
}
}

View File

@@ -0,0 +1,362 @@
<script lang="ts" setup>
import SearchBar from '@/components/searchBar.vue'
definePage({
style: {
'navigationBarTitleText': '%tabbar.me%',
'navigationStyle': 'custom',
'backgroundColor': '#F8FAFB',
'app-plus': {
bounce: 'none',
},
},
})
interface Category {
name: string
label: string
key: number
}
interface ProductData {
[key: string]: Product[]
}
interface Product {
name: string
key: number
image: string
price: number
}
const categories: Category[] = [
// {
// name: 'recommend',
// label: '推荐✨️',
// key: 0,
// },
{
name: 'frame',
label: '机架',
key: 1,
},
{
name: 'antenna',
label: '天线',
key: 2,
},
{
name: 'motor',
label: '电机',
key: 3,
},
{
name: 'propeller',
label: '螺旋桨',
key: 4,
},
]
const productData: ProductData = {
// recommend: [
// {
// name: 'VD5',
// key: 1,
// image: '/static/images/frame_model.png',
// price: 100,
// },
// {
// name: 'VD6',
// key: 2,
// image: '/static/images/frame_model.png',
// price: 100,
// },
// {
// name: 'VD7',
// key: 3,
// image: '/static/images/frame_model.png',
// price: 100,
// },
// ],
frame: [
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD1',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
],
antenna: [
{
name: 'VD5',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD6',
key: 2,
image: '/static/images/frame_model.png',
price: 100,
},
],
motor: [
{
name: 'VD5',
key: 1,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD6',
key: 2,
image: '/static/images/frame_model.png',
price: 100,
},
{
name: 'VD7',
key: 3,
image: '/static/images/frame_model.png',
price: 100,
},
],
}
const activeCategory = ref<Category>(categories[0])
</script>
<template>
<view class="category-page">
<view class="top-content">
<SearchBar class="search-bar" />
</view>
<view class="main-content">
<view class="category-nav">
<view v-for="(item, index) in categories" :key="index" class="category-nav-item" :class="{ active: activeCategory.key === item.key }" @click="activeCategory = item">
<view class="category-nav-inner">
<text class="category-text">{{ item.label }}</text>
</view>
</view>
</view>
<view class="category-content">
<view class="category-title">
{{ activeCategory.label }}
</view>
<view class="product-list">
<view v-for="product in productData[activeCategory.name]" :key="product.key" class="product-item">
<image class="product-image" :src="product.image" mode="aspectFit" />
<view class="product-info">
<view class="product-name">
{{ product.name }}
</view>
<view class="product-price">
<text class="text-11px">$</text>{{ product.price.toFixed(2) }}
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</template>
<style lang="less" scoped>
.category-page {
background-color: #f8fafb;
padding-top: 195rpx;
height: 100%;
max-height: 100%;
box-sizing: border-box;
display: flex;
flex-direction: column;
// min-height: calc(100vh - 128rpx);
.top-content {
padding-top: 120rpx;
background-color: #fff;
padding-bottom: 10rpx;
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 100;
:deep(.search-bar) {
.search-input {
background-color: rgba(249, 249, 249, 1);
}
}
}
.main-content {
display: flex;
flex: 1;
.category-nav {
flex-basis: 206rpx;
flex-shrink: 0;
&-item {
height: 112rpx;
display: flex;
align-items: center;
font-size: 28rpx;
&.active {
color: #333333;
background-color: #fff;
.category-nav-inner {
color: #333333;
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 6rpx;
height: 100%;
background-color: #0070d5;
border-radius: 4rpx;
}
}
}
.category-nav-inner {
padding: 0 32rpx;
position: relative;
color: #666666;
}
}
}
.category-content {
flex: 1;
height: fit-content;
padding: 0 16rpx;
background-color: #fff;
display: flex;
flex-direction: column;
.category-title {
font-size: 28rpx;
height: 112rpx;
line-height: 112rpx;
color: #333333;
}
.product-list {
flex: 1;
display: flex;
flex-direction: column;
row-gap: 24rpx;
overflow-y: auto;
max-height: calc(100vh - 332rpx);
background-color: #ffffff;
padding-bottom: 20rpx;
.product-item {
display: flex;
align-items: center;
font-size: 28rpx;
color: #333333;
background-color: #f8fafb;
border-radius: 6rpx;
column-gap: 4rpx;
.product-image {
width: 162rpx;
height: 162rpx;
}
.product-info {
display: flex;
flex-direction: column;
align-items: flex-start;
row-gap: 26rpx;
.product-name {
color: #666666;
font-size: 28rpx;
}
.product-price {
color: #333333;
font-size: 28rpx;
}
}
}
}
}
}
}
</style>

View File

@@ -0,0 +1,560 @@
<script setup lang="ts">
import { useToast } from 'wot-design-uni'
definePage({
// 使用 type: "home" 属性设置首页其他页面不需要设置默认为page
style: {
// 'custom' 表示开启自定义导航栏,默认 'default'
'navigationStyle': 'custom',
'navigationBarTitleText': '%tabbar.explore%',
'backgroundColor': '#F8FAFB',
// 'enablePullDownRefresh': true,
// 'app-plus': {
// pullToRefresh: {
// style: 'circle',
// range: '30%',
// height: '10%',
// offset: '60px',
// },
// },
'app-plus': {
bounce: 'none',
},
},
})
const toast = useToast()
onPullDownRefresh(() => {
// uni.showToast({
// title: '刷新成功',
// })
uni.showToast({
icon: 'error',
title: '刷新成功111',
})
setTimeout(() => {
uni.stopPullDownRefresh()
}, 1000)
})
const productWikiList = ref([
{
name: '【教程】超详细教程手把手教你组装Fifty 5穿越机整机跟着视...',
imageUrl: '/static/images/fifty5@m.webp',
url: '/pages/product-wiki/product-wiki.vue',
},
{
name: '【教程】超详细教程手把手教你组装Fifty 5穿越机整机跟着视...',
imageUrl: '/static/images/fifty5@m.webp',
url: '/pages/product-wiki/product-wiki.vue',
},
])
const specialList = ref([
{
name: 'Volador II VX5 O4 Pro FPV Freesty',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
oriPrice: 488,
},
{
name: 'Volador II VX5 O4 Pro FPV Freesty',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
oriPrice: 488,
},
{
name: 'Volador II VX5 O4 Pro FPV Freesty',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
oriPrice: 488,
},
])
const productRecommendList = ref([
{
name: 'Fifty 5穿越机',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
},
{
name: 'Fifty 5穿越机',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
},
{
name: 'Fifty 5穿越机',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
},
{
name: 'Fifty 5穿越机',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
},
{
name: 'Fifty 5穿越机',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
},
])
const productNewList = ref([
{
name: 'Fifty 5穿越机',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
},
{
name: 'Fifty 5穿越机',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
},
{
name: 'Fifty 5穿越机',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
},
{
name: 'Fifty 5穿越机',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
},
])
const productPeripheryList = ref([
{
name: 'Fifty 5穿越机',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
},
{
name: 'Fifty 5穿越机',
imageUrl: '/static/images/fifty5@m.webp',
price: 388,
},
])
const paging = ref<ZPagingInstance>()
function onRefresh() {
// uni.showToast({
// icon: 'error',
// title: '刷新成功111111111111111111111111',
// })
toast.show({
msg: '刷新成功',
direction: 'vertical',
})
setTimeout(() => {
paging.value.complete()
}, 1000)
}
</script>
<template>
<wd-toast />
<view>
<z-paging ref="paging" refresher-only :refresher-end-bounce-enabled="false" @on-refresh="onRefresh">
<template #top>
<view class="top-bar" />
</template>
<!-- 自定义下拉刷新view -->
<template #refresher="{ refresherStatus }">
<view class="refresher">
<view v-if="refresherStatus === 'default'">
继续下拉
</view>
<view v-if="refresherStatus === 'release-to-refresh'">
释放刷新
</view>
<view v-if="refresherStatus === 'loading'">
刷新中...
</view>
<view v-if="refresherStatus === 'complete'">
刷新完成
</view>
</view>
</template>
<view class="explore">
<view class="explore-header">
<view class="title">
发现智能飞行日常
</view>
<image class="explore-header-image" src="/static/images/fifty5@m.webp" mode="aspectFill" />
</view>
<view class="explore-content">
<!-- 产品百科 -->
<view class="explore-content-section">
<view class="title">
<view class="main-title">
产品百科
</view>
<view class="all">
全部
</view>
</view>
<view class="product-wiki">
<view v-for="item in productWikiList" :key="item.name" class="product-wiki-item">
<image :src="item.imageUrl" mode="aspectFill" />
<view class="wiki-title">
{{ item.name }}
</view>
</view>
</view>
</view>
<!-- 特价商品 -->
<view class="explore-content-section">
<view class="title">
<view class="main-title">
特价商品
</view>
<view class="all">
全部
</view>
</view>
<view class="product-special">
<view v-for="item in specialList" :key="item.name" class="product-special-item">
<image :src="item.imageUrl" mode="aspectFill" />
<view class="product-name">
{{ item.name }}
</view>
<view class="product-price">
<view class="special-price">
{{ item.price }}
</view>
<view class="ori-price">
{{ item.oriPrice }}
</view>
</view>
</view>
</view>
</view>
<!-- 精选推荐 -->
<view class="explore-content-section not-padding">
<view class="title">
<view class="main-title">
精选推荐
</view>
<view class="all">
全部
</view>
</view>
<view class="product-recommend">
<view v-for="item in productRecommendList" :key="item.name" class="product-recommend-item">
<image :src="item.imageUrl" mode="aspectFill" />
<view class="product-name">
{{ item.name }}
</view>
<view class="product-price">
{{ item.price }}
</view>
</view>
</view>
</view>
<!-- 新品上市 -->
<view class="explore-content-section">
<view class="title">
<view class="main-title">
新品上市
</view>
<view class="all">
全部
</view>
</view>
<view class="product-new">
<view v-for="item in productNewList" :key="item.name" class="product-new-item">
<image :src="item.imageUrl" mode="aspectFill" />
<view class="product-name">
{{ item.name }}
</view>
<view class="product-price">
{{ item.price }}
</view>
</view>
</view>
</view>
<!-- 专属周边 -->
<view class="explore-content-section">
<view class="title">
<view class="main-title">
专属周边为热爱加冕
</view>
<view class="all">
全部
</view>
</view>
<view class="product-periphery">
<view v-for="item in productPeripheryList" :key="item.name" class="product-periphery-item">
<image :src="item.imageUrl" mode="aspectFill" />
</view>
</view>
</view>
</view>
</view>
</z-paging>
</view>
</template>
<style lang="scss" scoped>
.top-bar {
height: 120rpx;
background-color: #f8fafb;
}
.refresher {
padding: 20px 0;
height: 100rpx;
> view {
font-size: 32rpx;
line-height: 1.2;
text-align: center;
padding: 20rpx 0;
}
}
.explore {
// padding-top: 120rpx;
width: 100%;
box-sizing: border-box;
background-color: #f8fafb;
.explore-header {
display: flex;
flex-direction: column;
row-gap: 58rpx;
padding: 0 28rpx;
margin-bottom: 20rpx;
.title {
font-size: 36rpx;
color: #24272c;
font-weight: 500;
}
.explore-header-image {
width: 100%;
aspect-ratio: 16 / 9;
border-radius: 12px 12px 12px 12px;
}
}
.explore-content {
padding: 0;
.explore-content-section {
display: flex;
flex-direction: column;
margin-bottom: 28rpx;
&:last-child {
margin-bottom: 0;
}
.title {
padding: 32rpx 28rpx;
font-size: 32rpx;
color: #24272c;
display: flex;
justify-content: space-between;
align-items: center;
.main-title {
font-weight: 500;
}
.all {
font-size: 28rpx;
color: #999999;
&::after {
content: '';
display: inline-block;
height: 12rpx;
width: 12rpx;
border-top: 1px solid #aaaaaa;
border-right: 1px solid #aaaaaa;
transform: rotate(45deg) translateY(0rpx);
margin-left: auto;
}
}
}
.product-wiki {
display: flex;
flex-direction: column;
border-radius: 28rpx;
overflow: hidden;
margin: 0 28rpx;
&-item {
display: flex;
background-color: #ffffff;
column-gap: 16rpx;
padding: 24rpx;
align-items: center;
image {
flex-shrink: 0;
width: 112rpx;
height: 112rpx;
border-radius: 8rpx 8rpx 8rpx 8rpx;
}
.wiki-title {
font-size: 28rpx;
color: #333333;
}
}
}
.product-recommend {
overflow-x: auto;
display: flex;
column-gap: 16rpx;
padding: 0 28rpx;
&-item {
display: flex;
flex-direction: column;
row-gap: 17rpx;
background-color: #ffffff;
overflow: hidden;
border-radius: 8rpx;
align-items: flex-start;
width: 271rpx;
height: 324rpx;
flex-shrink: 0;
padding-bottom: 32rpx;
image {
width: 100%;
}
.product-name {
font-size: 28rpx;
padding: 0 12rpx;
color: #333333;
}
.product-price {
font-size: 28rpx;
padding: 0 12rpx;
color: #ea4141;
}
}
}
.product-new {
display: grid;
grid-template-columns: repeat(2, 1fr);
column-gap: 16rpx;
row-gap: 16rpx;
padding: 0 28rpx;
.product-new-item {
display: flex;
flex-direction: column;
row-gap: 17rpx;
border-radius: 8rpx;
align-items: flex-start;
flex-shrink: 0;
padding-bottom: 28rpx;
image {
// width: 100%;
max-width: 100%;
width: 100%;
height: 300rpx;
border-radius: 8rpx;
}
.product-name {
font-size: 28rpx;
padding: 0 12rpx;
color: #333333;
}
.product-price {
font-size: 32rpx;
padding: 0 12rpx;
color: #ea4141;
}
}
}
// 特价商品
.product-special {
display: flex;
column-gap: 16rpx;
overflow: auto;
padding: 0 28rpx;
.product-special-item {
display: flex;
flex-direction: column;
row-gap: 17rpx;
border-radius: 8rpx;
overflow: hidden;
align-items: flex-start;
flex-shrink: 0;
width: 300rpx;
background-color: #fff;
padding-bottom: 28rpx;
image {
width: 100%;
height: 300rpx;
}
.product-name {
font-size: 28rpx;
color: #333333;
width: 100%;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
text-overflow: ellipsis;
padding: 0 12rpx;
}
.product-price {
display: flex;
align-items: center;
padding: 0 12rpx;
.special-price {
font-size: 28rpx;
color: #ea4141;
}
.ori-price {
font-size: 24rpx;
color: #86909c;
text-decoration: line-through;
}
}
}
}
// 专属周边
.product-periphery {
display: grid;
grid-template-columns: repeat(2, 1fr);
column-gap: 16rpx;
padding: 0 28rpx;
&-item {
image {
border-radius: 8rpx;
width: 100%;
}
}
}
}
}
}
</style>

View File

@@ -0,0 +1,136 @@
<script setup lang="ts">
import type { Category } from './index.vue'
// 在unibest框架中使用definePage宏配置页面属性
definePage({
// 页面样式配置
style: {
// 导航栏标题文本 - 这就是设置头部导航栏标题的属性
navigationBarTitleText: '%more.category%',
// 导航栏样式default(默认)或custom(自定义)
navigationStyle: 'default',
backgroundColor: '#ffffff',
// 可以添加其他配置如背景色、文字颜色等
navigationBarBackgroundColor: '#ffffff', // 导航栏背景色
// navigationBarTextStyle: 'black', // 导航栏标题颜色仅支持black/white
},
})
const marketingCenter: Array<Category> = [
{ name: 'Special', icon: '/static/images/category/Special.png', label: '特价' },
{ name: 'TopPicks', icon: '/static/images/category/TopPicks.png', label: '精选' },
{ name: 'NewArrival', icon: '/static/images/category/NewArrival.png', label: '新品' },
{ name: 'Merchandise', icon: '/static/images/category/Merchandise.png', label: '周边' },
]
const productCategories: Array<Category> = [
{ name: 'Frame', icon: '/static/images/category/Frame.png', label: '机架' },
{ name: 'Antenna', icon: '/static/images/category/Antenna.png', label: '天线' },
{ name: 'Motor', icon: '/static/images/category/Motor.png', label: '电机' },
{ name: 'Propeller', icon: '/static/images/category/Propeller.png', label: '螺旋桨' },
{ name: 'Accessories', icon: '/static/images/category/Accessories.png', label: '配件' },
{ name: 'FPV', icon: '/static/images/category/FPV.png', label: 'FPV 设备' },
]
</script>
<template>
<view class="more-category">
<view class="marketing-center-container">
<view class="marketing-center-title">
<text>营销中心</text>
</view>
<view class="marketing-center">
<view v-for="category in marketingCenter" :key="category.name" class="marketing-center-item">
<image :src="category.icon" />
<text>{{ category.label }}</text>
</view>
</view>
</view>
<view class="product-categories-container">
<view class="product-categories-title">
<text>产品分类</text>
</view>
<view class="product-categories">
<view v-for="category in productCategories" :key="category.name" class="product-categories-item">
<image :src="category.icon" />
<text>{{ category.label }}</text>
</view>
</view>
</view>
</view>
</template>
<style lang="scss" scoped>
.more-category {
padding: 32rpx 28rpx 0;
background-color: #fff;
height: calc(100vh - 28rpx);
.marketing-center-container {
padding-bottom: 56rpx;
.marketing-center-title {
font-size: 32rpx;
line-height: 1.4;
color: #24272c;
font-weight: bolder;
margin-bottom: 32rpx;
}
.marketing-center {
display: grid;
grid-template-columns: repeat(4, 1fr);
&-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
image {
width: 96rpx;
height: 96rpx;
}
text {
font-size: 28rpx;
line-height: 1.4;
}
}
}
}
.product-categories-container {
border-top: 1px solid #e7e7e7;
.product-categories-title {
font-size: 32rpx;
line-height: 1.4;
color: #24272c;
font-weight: bolder;
padding: 32rpx 0;
}
.product-categories {
display: grid;
grid-template-columns: repeat(4, 1fr);
row-gap: 56rpx;
&-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
image {
width: 96rpx;
height: 96rpx;
}
text {
font-size: 28rpx;
line-height: 1.4;
}
}
}
}
}
</style>

243
src/pages/index/index.vue Normal file
View File

@@ -0,0 +1,243 @@
<script lang="ts" setup>
import SearchBar from '@/components/searchBar.vue'
defineOptions({
name: 'Home',
})
definePage({
// 使用 type: "home" 属性设置首页其他页面不需要设置默认为page
type: 'home',
style: {
// 'custom' 表示开启自定义导航栏,默认 'default'
'navigationStyle': 'custom',
'navigationBarTitleText': '%tabbar.home%',
'backgroundColor': '#F8FAFB',
'app-plus': {
bounce: 'none',
},
},
})
export interface Category {
name: string
icon: string
label: string
}
interface Video {
coverImage: string
videoSrc?: string
color?: string
title: string
desc: string
}
const categories: Category[] = [
{ name: 'Special', icon: '/static/images/category/Special.png', label: '特价' },
{ name: 'TopPicks', icon: '/static/images/category/TopPicks.png', label: '精选' },
{ name: 'NewArrival', icon: '/static/images/category/NewArrival.png', label: '新品' },
{ name: 'Merchandise', icon: '/static/images/category/Merchandise.png', label: '周边' },
{ name: 'Frame', icon: '/static/images/category/Frame.png', label: '机架' },
{ name: 'Antenna', icon: '/static/images/category/Antenna.png', label: '天线' },
{ name: 'Motor', icon: '/static/images/category/Motor.png', label: '电机' },
{ name: 'More', icon: '/static/images/category/More.png', label: '更多分类' },
// { name: 'Propeller', icon: '/static/images/category/Propeller.png', label: '螺旋桨' },
// { name: 'Accessories', icon: '/static/images/category/Accessories.png', label: '配件' },
// { name: 'FPV', icon: '/static/images/category/FPV.png', label: 'FPV设备' },
]
const videoList: Array<Video> = [
{ coverImage: '/static/logo.png', videoSrc: '/static/logo.mp4', color: '#333333', title: 'Volador ll vx5', desc: '捕捉每一刻·畅享飞行乐趣' },
{ coverImage: '/static/logo.png', videoSrc: '/static/logo.mp4', color: '#215484', title: 'Volador ll vx5', desc: '捕捉每一刻·畅享飞行乐趣' },
{ coverImage: '/static/logo.png', videoSrc: '/static/logo.mp4', color: '#368941', title: '标题3', desc: '描述3' },
{ coverImage: '/static/logo.png', videoSrc: '/static/logo.mp4', color: '#885468', title: '标题4', desc: '描述4' },
]
function toCategoryPage(item: Category) {
uni.navigateTo({
url: `/pages/index/category`,
})
}
onLoad(() => {
console.log('测试 uni API 自动引入: onLoad')
})
</script>
<template>
<view class="home-page">
<!-- 搜索框 -->
<view class="top-container">
<SearchBar class="home-search-bar" notice-style="white" />
<!-- 主要产品展示 -->
<view class="main-product">
<image class="slider-image" src="/static/images/fifty5@m.webp" mode="aspectFill" />
</view>
</view>
<!-- 分类导航 -->
<view class="category-nav">
<view v-for="(item, index) in categories" :key="index" class="category-item" @click="toCategoryPage(item)">
<image class="category-icon" :src="item.icon" mode="aspectFit" />
<text class="category-text">{{ item.label }}</text>
</view>
</view>
<!-- 飞行场景 -->
<view class="section">
<view class="section-header">
<text class="section-title">飞行场景</text>
<text class="section-more">全部 ></text>
</view>
<swiper class="video-list" next-margin="60rpx">
<swiper-item v-for="(item, index) in videoList" :key="index" class="video">
<view class="video-container">
<view class="video-core" :style="{ backgroundColor: item.color }" />
<view class="video-info">
<view class="video-title">
{{ item.title }}
</view>
<view class="video-desc">
{{ item.desc }}
</view>
</view>
</view>
</swiper-item>
</swiper>
</view>
</view>
</template>
<style lang="less" scoped>
.home-page {
// padding-bottom: 100rpx;
/* 为底部导航栏留出空间 */
background-color: #f8fafb;
min-height: calc(100vh - 128rpx);
height: 100%;
.top-container {
background-color: #fff;
position: relative;
.home-search-bar {
position: absolute;
left: 0;
right: 0;
z-index: 100;
top: 120rpx;
}
// 主要产品展示
.main-product {
background-color: #fff;
height: 563rpx;
width: 100%;
.slider-image {
width: 100%;
height: 100%;
background-size: cover;
}
}
}
// 分类导航
.category-nav {
padding: 16rpx 0rpx 36rpx;
display: grid;
grid-template-columns: repeat(4, 1fr);
overflow-x: auto;
&::-webkit-scrollbar {
display: none; /* Chrome Safari */
}
.category-item {
display: flex;
flex-direction: column;
align-items: center;
row-gap: 8rpx;
padding: 24rpx 12rpx;
.category-icon {
width: 64rpx;
height: 64rpx;
border-radius: 6rpx;
}
.category-text {
font-size: 24rpx;
line-height: 1.2;
color: #333333;
}
}
}
// 通用区块样式
.section {
margin-bottom: 40rpx;
padding: 0 0 0 14px;
&:last-child {
margin-bottom: 0;
}
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
margin-left: 16rpx;
}
.section-more {
font-size: 28rpx;
color: #999;
margin-right: 44rpx;
}
}
.video-list {
height: 490rpx; // 设置明确的高度
.video {
.video-container {
width: calc(100% - 16rpx); // 减去next-margin的值确保内容不被裁剪
// width: 400rpx;
.video-core {
width: 100%;
aspect-ratio: 16 / 9; // 视频的宽高比
position: relative;
}
.video-info {
margin-top: 24rpx;
display: flex;
flex-direction: column;
row-gap: 16rpx;
.video-title {
font-size: 32rpx;
font-weight: 500;
line-height: 1.2;
color: #333;
}
.video-desc {
font-size: 24rpx;
line-height: 1;
color: #666666;
}
}
}
}
}
}
}
</style>

View File

@@ -0,0 +1,198 @@
<script setup lang="ts">
definePage({
style: {
'navigationBarTitleText': '%%',
'navigationStyle': 'default',
'backgroundColor': '#ffffff',
'navigationBarBackgroundColor': '#ffffff',
'app-plus': {
bounce: 'none',
},
},
})
const showPwd = ref(false)
const showCPwd = ref(false)
const isAgreed = ref(false)
const locale = uni.getLocale()
const isCh = computed(() => locale === 'zh-Hans')
function toSignIn() {
uni.navigateBack({ delta: 1 })
}
onMounted(() => {
console.log(locale)
})
</script>
<template>
<view class="forgot-container">
<view class="forgot-title">
<view>{{ $t('forgot.title') }}</view>
<view>{{ $t('forgot.desc') }}</view>
</view>
<view class="forgot-input-container">
<view v-if="isCh" class="forgot-input">
<input :placeholder="$t('forgot.phonePH')">
</view>
<view v-if="isCh" class="forgot-input">
<input :placeholder="$t('forgot.captchaPH')">
<view class="get-code">
{{ $t('forgot.getCaptcha') }}
</view>
</view>
<view v-if="!isCh" class="forgot-input">
<input :placeholder="$t('forgot.emailPH')">
</view>
<view class="forgot-input">
<input :placeholder="$t('forgot.passwordPH')" :password="!showPwd">
<image
class="suffix"
:src="showPwd ? '/static/icons/visible.svg' : '/static/icons/invisible.svg'"
mode="scaleToFill"
@click="showPwd = !showPwd"
/>
</view>
<view v-if="!isCh" class="forgot-input">
<input :placeholder="$t('register.confirmPasswordPH')" :password="!showCPwd">
<image
class="suffix"
:src="showCPwd ? '/static/icons/visible.svg' : '/static/icons/invisible.svg'"
mode="scaleToFill"
@click="showCPwd = !showCPwd"
/>
</view>
<view class="btn-wrapper">
<view class="forgot-btn" :class="{ ch: isCh }" :disabled="!isAgreed">
{{ $t('forgot.submit') }}
</view>
</view>
</view>
</view>
</template>
<style lang="scss" scoped>
.forgot-container {
background-color: #fff;
padding-top: 62rpx;
height: 100%;
box-sizing: border-box;
display: flex;
flex-direction: column;
.forgot-title {
display: flex;
flex-direction: column;
row-gap: 16rpx;
padding: 0 64rpx;
& > view {
&:nth-child(1) {
font-size: 48rpx;
font-weight: 500;
color: #24272c;
}
&:nth-child(2) {
font-size: 28rpx;
color: #aaaaaa;
}
}
}
.forgot-input-container {
display: flex;
flex-direction: column;
padding: 0 64rpx;
margin-top: 116rpx;
// margin-top: 58rpx;
.forgot-input {
padding: 40rpx 32rpx 40rpx 0;
border-bottom: 1rpx solid #e7e7e7;
display: flex;
.suffix {
width: 48rpx;
height: 48rpx;
margin-right: 32rpx;
}
input {
flex: 1;
font-size: 32rpx;
color: #24272c;
}
.get-code {
font-size: 28rpx;
color: #0070d5;
padding-left: 30rpx;
border-left: 1rpx solid #dcdfe6;
}
}
.register-tips {
display: flex;
justify-content: flex-end;
font-size: 28rpx;
padding: 16rpx;
margin-top: 12rpx;
color: #999999;
view {
color: #0070d5;
margin-left: 12rpx;
}
}
.btn-wrapper {
margin-top: 80rpx;
.forgot-btn {
width: 100%;
height: 80rpx;
display: flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
text-align: center;
font-size: 32rpx;
letter-spacing: 4rpx;
color: #ffffff;
background-color: #0070d5;
border-radius: 80rpx;
&.ch {
letter-spacing: 8rpx;
}
}
}
.user-agreement {
display: inline-flex;
column-gap: 16rpx;
justify-content: center;
align-items: center;
margin-top: 32rpx;
word-break: break-word;
.selection-box {
width: 40rpx;
height: 40rpx;
flex-shrink: 0;
flex-grow: 0;
image {
width: 40rpx;
height: 40rpx;
}
}
.agreement-text {
font-size: 24rpx;
color: #666666;
display: inline;
}
.agreement-link {
display: inline;
color: #0070d5;
}
}
}
}
</style>

241
src/pages/me/auth/login.vue Normal file
View File

@@ -0,0 +1,241 @@
<script setup lang="ts">
import FfButton from '@/components/ffButton.vue'
definePage({
style: {
'navigationBarTitleText': '',
'navigationStyle': 'default',
'backgroundColor': '#ffffff',
'navigationBarBackgroundColor': '#ffffff',
'app-plus': {
bounce: 'none',
},
},
})
const phone = ref('')
const pwd = ref('')
const captcha = ref('')
const showPwd = ref(false)
// 是否使用短信验证码登录
const isCaptcha = ref(false)
const isAgreed = ref(false)
const locale = uni.getLocale()
const isCh = computed(() => locale === 'zh-Hans')
const loginDisable = computed(() => {
if (!isAgreed.value) {
return true
}
if (isCaptcha.value) {
if (captcha.value && phone.value) {
return false
}
return true
}
else {
if (phone.value && pwd.value) {
return false
}
return true
}
})
function toRegister() {
uni.navigateTo({
url: '/pages/me/auth/register',
})
}
function toForgot() {
uni.navigateTo({
url: '/pages/me/auth/forgot',
})
}
onMounted(() => {
console.log(locale)
})
</script>
<template>
<view class="login-container">
<view class="login-title">
<view>账号密码登录</view>
<view>使用已经注册过的手机号登录</view>
</view>
<view class="login-content">
<view class="login-input">
<input v-model="phone" placeholder="请输入手机号">
</view>
<view v-if="isCaptcha && isCh" class="login-input">
<input v-model="captcha" :placeholder="$t('forgot.captchaPH')">
<view class="get-code">
{{ $t('forgot.getCaptcha') }}
</view>
</view>
<view v-else class="login-input">
<input v-model="pwd" placeholder="请输入密码" :password="!showPwd">
<image
class="suffix"
:src="showPwd ? '/static/icons/visible.svg' : '/static/icons/invisible.svg'"
mode="scaleToFill"
@click="showPwd = !showPwd"
/>
</view>
<view class="login-forgot" @click="toForgot">
忘记密码?
</view>
<view class="btn-wrapper">
<ff-button class="login-btn" :disabled="loginDisable">
登录
</ff-button>
<view class="addition">
<view @click="toRegister">
立即注册
</view>
<view @click="isCaptcha = !isCaptcha">
{{ isCaptcha ? '密码登录' : '短信登录' }}
</view>
</view>
</view>
<view class="user-agreement">
<view class="selection-box">
<image
:src="isAgreed ? '/static/images/me/selected.png' : '/static/images/me/unselected.png'"
mode="scaleToFill"
@click="isAgreed = !isAgreed"
/>
</view>
<view class="agreement-text">
我已阅读并同意
<view class="agreement-link">
用户服务协议
</view>
<view class="agreement-link">
隐私政策
</view>
</view>
</view>
</view>
</view>
</template>
<style lang="scss" scoped>
.login-container {
background-color: #fff;
padding-top: 62rpx;
height: 100%;
box-sizing: border-box;
display: flex;
flex-direction: column;
.login-title {
display: flex;
flex-direction: column;
row-gap: 16rpx;
padding: 0 64rpx;
& > view {
&:nth-child(1) {
font-size: 48rpx;
font-weight: 500;
color: #24272c;
}
&:nth-child(2) {
font-size: 28rpx;
color: #aaaaaa;
}
}
}
.login-content {
display: flex;
flex-direction: column;
padding: 0 64rpx;
flex: 1;
margin-top: 116rpx;
.login-input {
padding: 40rpx 32rpx 40rpx 0;
border-bottom: 1rpx solid #e7e7e7;
display: flex;
.suffix {
width: 48rpx;
height: 48rpx;
margin-right: 32rpx;
}
input {
flex: 1;
font-size: 32rpx;
color: #24272c;
}
.get-code {
font-size: 28rpx;
color: #0070d5;
padding-left: 30rpx;
border-left: 1rpx solid #dcdfe6;
}
}
.login-forgot {
display: flex;
justify-content: flex-end;
font-size: 28rpx;
color: #0070d5;
padding: 16rpx;
margin-top: 12rpx;
}
.btn-wrapper {
margin-top: 80rpx;
.addition {
display: flex;
font-size: 28rpx;
color: #666666;
text-align: center;
margin-top: 34rpx;
> view {
flex: 1;
&:first-child {
color: #0070d5;
border-right: 1rpx solid #dcdfe6;
}
}
}
}
.user-agreement {
display: flex;
column-gap: 16rpx;
justify-content: center;
align-items: center;
margin-top: auto;
// margin-bottom: 100rpx;
position: absolute;
bottom: 100rpx;
.selection-box {
width: 40rpx;
height: 40rpx;
flex-shrink: 0;
flex-grow: 0;
image {
width: 40rpx;
height: 40rpx;
}
}
.agreement-text {
font-size: 24rpx;
color: #666666;
display: flex;
}
.agreement-link {
color: #0070d5;
}
}
}
}
</style>

View File

@@ -0,0 +1,223 @@
<script setup lang="ts">
definePage({
style: {
'navigationBarTitleText': '',
'navigationStyle': 'default',
'backgroundColor': '#ffffff',
'navigationBarBackgroundColor': '#ffffff',
'app-plus': {
bounce: 'none',
},
},
})
const showPwd = ref(false)
const showCPwd = ref(false)
const isAgreed = ref(false)
const locale = uni.getLocale()
const isCh = computed(() => locale === 'zh-Hans')
function toSignIn() {
uni.navigateBack({ delta: 1 })
}
onMounted(() => {
console.log(locale)
})
</script>
<template>
<view class="register-container">
<view class="register-title">
<view>{{ $t('register.title') }}</view>
<view>{{ $t('register.desc') }}</view>
</view>
<view class="register-content">
<view v-if="isCh" class="register-input">
<input :placeholder="$t('register.phonePH')">
</view>
<view v-if="isCh" class="register-input">
<input :placeholder="$t('register.captchaPH')">
<view class="get-code">
{{ $t('register.getCaptcha') }}
</view>
</view>
<view v-if="!isCh" class="register-input">
<input :placeholder="$t('register.emailPH')">
</view>
<view class="register-input">
<input :placeholder="$t('register.passwordPH')" :password="!showPwd">
<image
class="suffix"
:src="showPwd ? '/static/icons/visible.svg' : '/static/icons/invisible.svg'"
mode="scaleToFill"
@click="showPwd = !showPwd"
/>
</view>
<view v-if="!isCh" class="register-input">
<input :placeholder="$t('register.confirmPasswordPH')" :password="!showCPwd">
<image
class="suffix"
:src="showCPwd ? '/static/icons/visible.svg' : '/static/icons/invisible.svg'"
mode="scaleToFill"
@click="showCPwd = !showCPwd"
/>
</view>
<view class="register-tips">
{{ $t('register.tips') }}
<view @click="toSignIn">
{{ $t('register.toSign') }}
</view>
</view>
<view class="btn-wrapper">
<view class="register-btn" :class="{ ch: isCh }" :disabled="!isAgreed">
{{ $t('register.signUp') }}
</view>
</view>
<view class="user-agreement">
<view class="selection-box">
<image
:src="isAgreed ? '/static/images/me/selected.png' : '/static/images/me/unselected.png'"
mode="scaleToFill"
@click="isAgreed = !isAgreed"
/>
</view>
<text class="agreement-text">
{{ $t('agreeDesc1') }}
<text class="agreement-link">
{{ $t('Terms of Service') }}
</text>
{{ $t('agreeDesc2') }}
<text class="agreement-link">
{{ $t('Privacy Policy') }}
</text>
</text>
</view>
</view>
</view>
</template>
<style lang="scss" scoped>
.register-container {
background-color: #fff;
padding-top: 62rpx;
height: 100%;
box-sizing: border-box;
display: flex;
flex-direction: column;
.register-title {
display: flex;
flex-direction: column;
row-gap: 16rpx;
padding: 0 64rpx;
& > view {
&:nth-child(1) {
font-size: 48rpx;
font-weight: 500;
color: #24272c;
}
&:nth-child(2) {
font-size: 28rpx;
color: #aaaaaa;
}
}
}
.register-content {
display: flex;
flex-direction: column;
padding: 0 64rpx;
flex: 1;
margin-top: 116rpx;
.register-input {
padding: 40rpx 32rpx 40rpx 0;
border-bottom: 1rpx solid #e7e7e7;
display: flex;
.suffix {
width: 48rpx;
height: 48rpx;
margin-right: 32rpx;
}
input {
flex: 1;
font-size: 32rpx;
color: #24272c;
}
.get-code {
font-size: 28rpx;
color: #0070d5;
padding-left: 30rpx;
border-left: 1rpx solid #dcdfe6;
}
}
.register-tips {
display: flex;
justify-content: flex-end;
font-size: 28rpx;
padding: 16rpx;
margin-top: 12rpx;
color: #999999;
view {
color: #0070d5;
margin-left: 12rpx;
}
}
.btn-wrapper {
margin-top: 80rpx;
.register-btn {
width: 100%;
height: 80rpx;
display: flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
text-align: center;
font-size: 32rpx;
letter-spacing: 4rpx;
color: #ffffff;
background-color: #0070d5;
border-radius: 80rpx;
&.ch {
letter-spacing: 8rpx;
}
}
}
.user-agreement {
display: inline-flex;
column-gap: 16rpx;
justify-content: center;
align-items: center;
margin-top: 32rpx;
word-break: break-word;
.selection-box {
width: 40rpx;
height: 40rpx;
flex-shrink: 0;
flex-grow: 0;
image {
width: 40rpx;
height: 40rpx;
}
}
.agreement-text {
font-size: 24rpx;
color: #666666;
display: inline;
}
.agreement-link {
display: inline;
color: #0070d5;
}
}
}
}
</style>

421
src/pages/me/me.vue Normal file
View File

@@ -0,0 +1,421 @@
<script lang="ts" setup>
definePage({
style: {
'navigationBarTitleText': '我的',
'navigationStyle': 'custom',
'backgroundColor': '#F8FAFB',
'app-plus': {
bounce: 'none',
},
},
})
interface MenuItem {
name: string
icon: string
label: string
url?: string
}
const msgCount = ref(99)
const orderConfig: Array<MenuItem> = [
{
name: '待付款',
icon: '/static/images/me/pending_payment.png',
label: '待付款',
},
{
name: '待发货',
icon: '/static/images/me/pending_delivery.png',
label: '待发货',
},
{
name: '待收货',
icon: '/static/images/me/pending_receipt.png',
label: '待收货',
},
{
name: '待评价',
icon: '/static/images/me/pending_comment.png',
label: '待评价',
},
{
name: '退款/售后',
icon: '/static/images/me/refunds.png',
label: '退款/售后',
},
]
const featureMenu: Array<MenuItem> = [
{
name: '购物车',
icon: '/static/images/me/cart.png',
label: '购物车',
},
{
name: '收藏列表',
icon: '/static/images/me/collection.png',
label: '收藏列表',
},
{
name: '收货地址',
icon: '/static/images/me/address.png',
label: '收货地址',
},
{
name: '客服中心',
icon: '/static/images/me/customer_service.png',
label: '客服中心',
},
{
name: '意见反馈',
icon: '/static/images/me/feedback.png',
label: '意见反馈',
url: '/pages/me/menu/feedback',
},
]
function clickUser() {
uni.navigateTo({
url: '/pages/me/auth/login',
})
}
function clickFeature(item: MenuItem) {
if (item.url) {
uni.navigateTo({
url: item.url,
})
}
}
</script>
<template>
<view class="me">
<view class="me-header">
<view class="user-info" @click="clickUser">
<view class="user-avatar">
<image src="/static/images/me/user.png" mode="scaleToFill" />
</view>
<view>
<view class="user-name">
登录/注册
</view>
</view>
</view>
<view class="me-buttons">
<view class="me-button">
<image src="/static/images/me/notice.png" mode="scaleToFill" />
<view class="badge">
{{ msgCount }}
</view>
</view>
<view class="me-button">
<image src="/static/images/me/setting.png" mode="scaleToFill" />
</view>
</view>
</view>
<view class="me-content">
<view class="account-data">
<view class="account-data-item">
<view class="value balance">
0
</view>
<view class="label">
我的余额
</view>
</view>
<view class="account-data-item">
<view class="value points">
0
</view>
<view class="label">
我的积分
</view>
</view>
</view>
<view class="order-data">
<view class="order-data-title">
<view>
我的订单
</view>
<view class="all-order">
全部
</view>
</view>
<view class="order-menu">
<view v-for="item in orderConfig" :key="item.name" class="order-menu-item">
<view class="icon">
<image :src="item.icon" mode="scaleToFill" />
</view>
<view class="label">
{{ item.label }}
</view>
</view>
</view>
</view>
<view class="more-feature">
<view class="more-feature-title">
更多功能
</view>
<view class="feature-list">
<view v-for="item in featureMenu" :key="item.name" class="feature-item" @click="clickFeature(item)">
<view class="icon">
<image :src="item.icon" mode="scaleToFill" />
</view>
<view class="label">
{{ item.label }}
</view>
</view>
</view>
</view>
</view>
</view>
</template>
<style lang="scss" scoped>
.badge {
position: absolute;
top: 0;
left: 60%;
height: 24rpx;
padding: 0 7rpx;
line-height: 24rpx;
text-align: center;
font-size: 18rpx;
color: #fff;
background-color: #ea4141;
border-radius: 50rpx;
}
.me {
padding-top: 120rpx;
background-image: url('/static/images/me/background.png');
background-size: cover;
background-size: contain;
background-repeat: no-repeat;
width: 100%;
height: 100%;
box-sizing: border-box;
background-color: #f8fafb;
min-height: calc(100vh - 128rpx);
.me-header {
display: flex;
justify-content: space-between;
padding: 0 28rpx;
.user-info {
display: flex;
align-items: center;
.user-avatar {
height: 96rpx;
width: 96rpx;
display: flex;
align-items: center;
justify-content: center;
background-color: #fff;
border-radius: 50%;
margin-right: 24rpx;
image {
height: 48rpx;
width: 48rpx;
}
}
.user-name {
font-size: 32rpx;
color: #24272c;
&::after {
content: '';
display: inline-block;
height: 12rpx;
width: 12rpx;
border-top: 1px solid #24272c;
border-right: 1px solid #24272c;
transform: rotate(45deg) translateY(-4rpx);
}
}
}
.me-buttons {
display: flex;
align-items: center;
column-gap: 32rpx;
.me-button {
height: 48rpx;
width: 48rpx;
position: relative;
image {
height: 100%;
width: 100%;
}
}
}
}
.me-content {
padding: 0 28rpx;
.account-data {
display: flex;
justify-content: space-around;
margin: 40rpx 0;
.account-data-item {
display: flex;
flex-direction: column;
row-gap: 12rpx;
align-items: center;
width: fit-content;
.value {
font-size: 36rpx;
color: #24272c;
&.balance {
color: #0070d5;
}
&.points {
color: #ff782c;
}
}
.label {
font-size: 24rpx;
line-height: 1.2;
color: #666666;
}
}
}
.order-data {
margin-bottom: 16rpx;
background-color: #fff;
padding: 0 32rpx;
border-radius: 16rpx;
.order-data-title {
font-size: 28rpx;
line-height: 1.2;
font-weight: 500;
color: #24272c;
padding: 32rpx 0;
border-bottom: 1px solid #e7e7e7;
display: flex;
justify-content: space-between;
align-items: center;
.all-order {
font-size: 24rpx;
line-height: 1;
color: #aaaaaa;
&::after {
content: '';
display: inline-block;
height: 12rpx;
width: 12rpx;
border-top: 1px solid #aaaaaa;
border-right: 1px solid #aaaaaa;
transform: rotate(45deg) translateY(-4rpx);
}
}
}
.order-menu {
display: flex;
justify-content: space-around;
padding: 28rpx 0 32rpx;
.order-menu-item {
display: flex;
flex-direction: column;
align-items: center;
width: fit-content;
.icon {
image {
height: 48rpx;
width: 48rpx;
}
}
.label {
font-size: 24rpx;
line-height: 1.2;
color: #666666;
font-weight: 400;
}
}
}
}
.more-feature {
background-color: #fff;
padding: 0 32rpx;
border-radius: 8rpx;
.more-feature-title {
font-size: 28rpx;
line-height: 1.2;
font-weight: 500;
color: #24272c;
padding: 32rpx 0;
border-bottom: 1px solid #e7e7e7;
display: flex;
justify-content: space-between;
align-items: center;
}
.feature-list {
display: flex;
flex-direction: column;
padding: 28rpx 0 32rpx;
.feature-item {
display: flex;
align-items: center;
column-gap: 16rpx;
width: 100%;
padding: 8px 0;
.icon {
height: 44rpx;
width: 44rpx;
image {
height: 44rpx;
width: 44rpx;
}
}
.label {
font-size: 28rpx;
line-height: 1;
color: #333333;
font-weight: 400;
}
&:after {
content: '';
display: inline-block;
height: 12rpx;
width: 12rpx;
border-top: 1px solid #aaaaaa;
border-right: 1px solid #aaaaaa;
transform: rotate(45deg) translateY(0rpx);
margin-left: auto;
}
}
}
}
}
}
</style>

View File

@@ -0,0 +1,197 @@
<script setup lang="ts">
import { ref } from 'vue'
// 在unibest框架中使用definePage宏配置页面属性
definePage({
// 页面样式配置
style: {
// 导航栏标题文本 - 这就是设置头部导航栏标题的属性
navigationBarTitleText: '%me.feedback%',
// 导航栏样式default(默认)或custom(自定义)
navigationStyle: 'default',
backgroundColor: '#ffffff',
// 可以添加其他配置如背景色、文字颜色等
navigationBarBackgroundColor: '#ffffff', // 导航栏背景色
// navigationBarTextStyle: 'black', // 导航栏标题颜色仅支持black/white
},
})
const feedbackContent = ref('')
const phoneOrEmail = ref('')
const feedbackImages = ref([])
function uploadImage() {
if (feedbackImages.value.length >= 6) {
uni.showToast({
title: '最多上传6张照片',
icon: 'none',
})
return
}
uni.chooseImage({
count: 6 - feedbackImages.value.length,
sourceType: ['album'],
success: (res) => {
feedbackImages.value = [...feedbackImages.value, ...(res.tempFilePaths as string[])]
},
})
}
function previewImage(index: number) {
uni.previewImage({
urls: feedbackImages.value,
current: feedbackImages.value[index],
})
}
function removeImage(index: number) {
feedbackImages.value.splice(index, 1)
}
</script>
<template>
<view class="feedback">
<view class="feedback-section">
<view class="section-title required">
意见或建议
</view>
<wd-textarea v-model="feedbackContent" class="feedback-text" clear-trigger="focus" :maxlength="200" clearable show-word-limit />
</view>
<view class="feedback-section">
<view class="section-title">
上传照片({{ feedbackImages.length }}/6)
</view>
<div class="upload-area">
<view v-for="(item, index) in feedbackImages" :key="index" class="upload-box uploaded">
<image class="upload-image" :src="item" mode="scaleToFill" @click="previewImage(index)" />
<image
class="remove-icon"
src="/static/images/me/remove.png"
mode="scaleToFill"
@click="removeImage(index)"
/>
</view>
<view v-if="feedbackImages.length < 6" class="upload-box" @click="uploadImage">
<image class="upload-icon" src="/static/images/me/upload.png" mode="scaleToFill" />
</view>
</div>
</view>
<view class="feedback-section">
<view class="section-title">
邮箱/电话
</view>
<div class="phone-area">
<input
v-model="phoneOrEmail"
placeholder="请留下您的电话或邮箱,方便我们联系您"
placeholder-class="input-placeholder"
>
</div>
</view>
<view class="feedback-btn">
<ff-button :disabled="feedbackContent.length === 0">
提交
</ff-button>
</view>
</view>
</template>
<style lang="scss" scoped>
.feedback {
height: 100%;
background-color: #fff;
.feedback-section {
padding: 0 28rpx 32rpx 28rpx;
.section-title {
font-size: 32rpx;
color: #24272c;
padding: 32rpx 0;
&.required {
&::after {
content: '*';
font-size: 32rpx;
line-height: 32rpx;
color: #ff4d4f;
}
}
}
.upload-area {
display: grid;
grid-template-columns: repeat(4, 1fr);
column-gap: 24rpx;
row-gap: 38rpx;
padding: 23rpx;
background-color: #f8fafb;
border-radius: 12rpx;
.upload-box {
&.uploaded {
border: none;
}
width: 100%;
aspect-ratio: 1/1;
background-color: #f8fafb;
border-radius: 15rpx;
border: 1px dashed #b6c3cc;
display: flex;
align-items: center;
justify-content: center;
position: relative;
.upload-icon {
width: 45rpx;
height: 45rpx;
}
.upload-image {
border-radius: 15rpx;
width: 100%;
height: 100%;
}
.remove-icon {
width: 40rpx;
height: 40rpx;
right: 0;
top: 0;
transform: translate(50%, -50%);
position: absolute;
}
}
}
.phone-area {
background-color: #f8fafb;
border-radius: 12rpx;
padding: 19rpx 16rpx;
input {
font-size: 28rpx;
line-height: 1.2;
}
.input-placeholder {
color: #999999;
font-size: 28rpx;
line-height: 1.2;
}
}
:deep(.feedback-text) {
background-color: #f8fafb;
border-radius: 12rpx;
.wd-textarea__value {
background-color: #f8fafb;
}
.wd-textarea__count {
background-color: #f8fafb;
}
}
}
.feedback-btn {
position: absolute;
bottom: calc(32rpx + env(safe-area-inset-bottom));
padding: 0 32rpx;
width: 100%;
box-sizing: border-box;
}
}
</style>

412
src/pages/search/search.vue Normal file
View File

@@ -0,0 +1,412 @@
<script setup lang="ts">
import SearchInput from '@/components/searchInput.vue'
import { useSearchStore } from '@/store/search'
// 在unibest框架中使用definePage宏配置页面属性
definePage({
// 页面样式配置
style: {
// 导航栏标题文本 - 这就是设置头部导航栏标题的属性
// navigationBarTitleText: '%more.category%',
// 导航栏样式default(默认)或custom(自定义)
'navigationStyle': 'custom',
'backgroundColor': '#ffffff',
// 可以添加其他配置如背景色、文字颜色等
'navigationBarBackgroundColor': '#ffffff', // 导航栏背景色
// navigationBarTextStyle: 'black', // 导航栏标题颜色仅支持black/white
'app-plus': {
bounce: 'none',
},
},
})
const searchStore = useSearchStore()
const recommendList = ref([
'Volador II VD5',
'Volador II VX5',
'Atlas 4 的替换零件',
'SMA 天线- RHCP',
'FPV 电机',
'替换转子',
])
const currentSort = ref('综合')
const sortType = ref([
{
name: '综合',
value: '综合',
},
{
name: '销量',
value: '销量',
},
{
name: '新品',
value: '新品',
},
{
name: '价格',
value: '价格',
},
])
const productList = ref([
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 100,
originalPrice: 150,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
])
const showRelative = computed(() => searchStore.isSearching && searchStore.searchText)
function onClickSearchInput() {
// uni.navigateTo({
// url: `/pages/search/searchResult?searchText=${searchStore.searchText}`,
// })
searchStore.searched = true
}
function clickSort(sort: string) {
currentSort.value = sort
}
</script>
<template>
<view class="search-page">
<SearchInput :auto-focus="true" :has-feature="true" @on-click-search-input="onClickSearchInput" />
<view v-if="searchStore.searched" class="search-sort-type">
<view
v-for="item in sortType" :key="item.value" class="sort-item"
:class="{ active: item.value === currentSort }" @click="clickSort(item.value)"
>
{{ item.name }}
<view v-if="item.name === '价格'" class="sort-arrow" />
</view>
</view>
<view v-if="showRelative" class="search-relative-result">
<view class="search-relative-list">
<view class="search-relative-item" @click="searchStore.searchProduct('搜索关联词')">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
<view class="search-relative-item">
搜索关联词
</view>
</view>
</view>
<view v-else-if="!searchStore.searched" class="search-recommend">
<view class="search-recommend-title">
<text>猜你想搜</text>
<image src="/static/icons/refresh.svg" mode="scaleToFill" />
</view>
<view class="search-recommend-content">
<view
v-for="item in recommendList" :key="item" class="search-recommend-item"
@click="searchStore.searchProduct(item)"
>
{{ item }}
</view>
</view>
</view>
<view v-else class="product-list">
<view v-for="item in productList" :key="item.name" class="product-item">
<image src="/static/images/fifty5@m.webp" mode="scaleToFill" />
<view class="product-info">
<view class="product-name">
{{ item.name }}
</view>
<view class="product-price">
<view class="price">
<view class="unit">
</view>{{ item.price }}
</view>
<view class="original-price">
{{ item.originalPrice }}
</view>
</view>
</view>
</view>
</view>
</view>
</template>
<style lang="scss" scoped>
.search-page {
height: 100vh;
background-color: #fff;
padding-top: 120rpx;
box-sizing: border-box;
.search-sort-type {
display: flex;
align-items: center;
.sort-item {
font-size: 24rpx;
line-height: 1.2;
color: #666666;
padding: 12rpx 24rpx;
border-radius: 32rpx;
margin-right: 24rpx;
display: flex;
align-items: center;
column-gap: 6rpx;
&.active {
color: #0070d5;
}
.sort-arrow {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
row-gap: 6rpx;
&::before {
content: '';
display: inline-block;
border-top: 8rpx solid transparent;
border-left: 8rpx solid transparent;
border-right: 8rpx solid transparent;
border-bottom: 8rpx solid #999999;
}
&::after {
content: '';
display: inline-block;
border-top: 8rpx solid #999999;
border-left: 8rpx solid transparent;
border-right: 8rpx solid transparent;
border-bottom: 8rpx solid transparent;
}
}
}
}
.search-relative-result {
background-color: #fff;
width: 100%;
height: calc(100vh - 120rpx - 122rpx);
overflow: auto;
.search-relative-list {
.search-relative-item {
border-bottom: 2rpx solid #e5e5e5;
padding: 29rpx 0;
margin-left: 32rpx;
font-size: 28rpx;
display: flex;
justify-content: space-between;
align-items: center;
color: rgba(0, 0, 0, 0.9);
&::after {
content: '';
display: inline-block;
width: 18rpx;
height: 18rpx;
border-top: 3rpx solid #999999;
border-right: 3rpx solid #999999;
position: relative;
right: 62rpx;
transform: rotate(45deg);
}
}
}
}
.search-recommend {
margin-top: 48rpx;
padding: 0 28rpx;
.search-recommend-title {
display: flex;
justify-content: space-between;
align-items: center;
color: #24272c;
font-weight: 500;
margin-bottom: 32rpx;
image {
width: 36rpx;
height: 36rpx;
}
}
.search-recommend-content {
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: wrap;
column-gap: 24rpx;
row-gap: 24rpx;
.search-recommend-item {
white-space: nowrap;
background-color: #f7f7f7;
padding: 8rpx 32rpx;
font-size: 28rpx;
color: #999999;
border-radius: 4rpx;
}
}
}
.product-list {
padding: 16rpx 28rpx;
display: flex;
flex-direction: column;
row-gap: 16rpx;
height: calc(100vh - 120rpx - 142rpx);
box-sizing: border-box;
overflow: auto;
background-color: #f8fafb;
.product-item {
overflow: hidden;
background-color: #fff;
border-radius: 16rpx;
padding: 28rpx;
flex-shrink: 0;
display: flex;
align-items: center;
image {
flex-shrink: 0;
width: 160rpx;
height: 160rpx;
margin-right: 16rpx;
}
.product-info {
display: flex;
flex-direction: column;
row-gap: 24rpx;
.product-name {
font-size: 28rpx;
line-height: 1.4;
color: #24272c;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
text-overflow: ellipsis;
}
.product-price {
display: flex;
align-items: center;
.price {
font-size: 32rpx;
line-height: 1.2;
color: #ea4141;
.unit {
display: inline-block;
font-size: 24rpx;
line-height: 1.2;
color: #ea4141;
}
}
.original-price {
font-size: 24rpx;
line-height: 1.2;
text-decoration: line-through;
color: #cccccc;
margin-left: 8rpx;
}
}
}
}
}
}
</style>

View File

@@ -0,0 +1,234 @@
<script setup lang="ts">
import SearchInput from '@/components/searchInput.vue'
import { useSearchStore } from '@/store/search'
// 在unibest框架中使用definePage宏配置页面属性
definePage({
// 页面样式配置
style: {
// 导航栏标题文本 - 这就是设置头部导航栏标题的属性
// navigationBarTitleText: '%more.category%',
// 导航栏样式default(默认)或custom(自定义)
'navigationStyle': 'custom',
'backgroundColor': '#f8fafb',
// 可以添加其他配置如背景色、文字颜色等
'navigationBarBackgroundColor': '#ffffff', // 导航栏背景色
// navigationBarTextStyle: 'black', // 导航栏标题颜色仅支持black/white
'app-plus': {
bounce: 'none',
},
},
})
const searchStore = useSearchStore()
const currentSort = ref('综合')
const sortType = ref([
{
name: '综合',
value: '综合',
},
{
name: '销量',
value: '销量',
},
{
name: '新品',
value: '新品',
},
{
name: '价格',
value: '价格',
},
])
const productList = ref([
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 100,
originalPrice: 150,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
{
name: 'Volador lI VD5 O4 Deadcat FPV T7O0 机架套件-颜色:黄色',
price: 200,
originalPrice: 250,
},
])
function onClickSearchInput() {
}
function clickSort(sort: string) {
currentSort.value = sort
}
onMounted(() => {
console.log(searchStore.isSearching)
console.log(searchStore.searchText)
})
</script>
<template>
<view class="search-result-page">
<SearchInput :auto-focus="false" :has-feature="true" @on-click-search-input="onClickSearchInput" />
<view class="search-sort-type">
<view v-for="item in sortType" :key="item.value" class="sort-item" :class="{ active: item.value === currentSort }" @click="clickSort(item.value)">
{{ item.name }}
<view v-if="item.name === '价格'" class="sort-arrow" />
</view>
</view>
<view class="product-list">
<view v-for="item in productList" :key="item.name" class="product-item">
<image
src="/static/images/fifty5@m.webp"
mode="scaleToFill"
/>
<view class="product-info">
<view class="product-name">
{{ item.name }}
</view>
<view class="product-price">
<view class="price">
<view class="unit">
</view>{{ item.price }}
</view>
<view class="original-price">
{{ item.originalPrice }}
</view>
</view>
</view>
</view>
</view>
</view>
</template>
<style lang="scss" scoped>
.search-result-page {
height: 100vh;
background-color: #f8fafb;
padding-top: 120rpx;
box-sizing: border-box;
.search-sort-type {
display: flex;
align-items: center;
.sort-item {
font-size: 24rpx;
line-height: 1.2;
color: #666666;
padding: 12rpx 24rpx;
border-radius: 32rpx;
margin-right: 24rpx;
&.active {
color: #0070d5;
}
}
.sort-arrow {
display: flex;
flex-direction: column;
&::before {
display: inline-block;
width: 12rpx;
height: 12rpx;
border-top: 32rpx solid transparent;
border-left: 32rpx solid transparent;
border-right: 32rpx solid transparent;
border-bottom: 32rpx solid #999999;
transform: rotate(-45deg);
}
&::after {
display: inline-block;
width: 12rpx;
height: 12rpx;
}
}
}
.product-list {
padding: 16rpx 28rpx;
display: flex;
flex-direction: column;
row-gap: 16rpx;
.product-item {
overflow: hidden;
background-color: #fff;
border-radius: 16rpx;
padding: 28rpx;
display: flex;
align-items: center;
image {
flex-shrink: 0;
width: 160rpx;
height: 160rpx;
margin-right: 16rpx;
}
.product-info {
display: flex;
flex-direction: column;
row-gap: 24rpx;
.product-name {
font-size: 28rpx;
line-height: 1.4;
color: #24272c;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
text-overflow: ellipsis;
}
.product-price {
display: flex;
align-items: center;
.price {
font-size: 32rpx;
line-height: 1.2;
color: #ea4141;
.unit {
display: inline-block;
font-size: 24rpx;
line-height: 1.2;
color: #ea4141;
}
}
.original-price {
font-size: 24rpx;
line-height: 1.2;
text-decoration: line-through;
color: #cccccc;
margin-left: 8rpx;
}
}
}
}
}
}
</style>

55
src/router/README.md Normal file
View File

@@ -0,0 +1,55 @@
# 登录 说明
## 登录 2种策略
- 默认无需登录策略: DEFAULT_NO_NEED_LOGIN
- 默认需要登录策略: DEFAULT_NEED_LOGIN
### 默认无需登录策略: DEFAULT_NO_NEED_LOGIN
进入任何页面都不需要登录,只有进入到黑名单中的页面/或者页面中某些动作需要登录,才需要登录。
比如大部分2C的应用美团、今日头条、抖音等都可以直接浏览只有点赞、评论、分享等操作或者去特殊页面比如个人中心才需要登录。
### 默认需要登录策略: DEFAULT_NEED_LOGIN
进入任何页面都需要登录,只有进入到白名单中的页面,才不需要登录。默认进入应用需要先去登录页。
比如大部分2B和后台管理类的应用比如企业微信、钉钉、飞书、内部报表系统、CMS系统等都需要登录只有登录后才能使用。
### EXCLUDE_LOGIN_PATH_LIST
`EXCLUDE_LOGIN_PATH_LIST` 表示排除的路由列表。
`默认无需登录策略: DEFAULT_NO_NEED_LOGIN` 中,只有路由在 `EXCLUDE_LOGIN_PATH_LIST` 中,才需要登录,相当于黑名单。
`默认需要登录策略: DEFAULT_NEED_LOGIN` 中,只有路由在 `EXCLUDE_LOGIN_PATH_LIST` 中,才不需要登录,相当于白名单。
### excludeLoginPath
definePage 中可以通过 `excludeLoginPath` 来配置路由是否需要登录。(类似过去的 needLogin 的功能)
```ts
definePage({
style: {
navigationBarTitleText: '关于',
},
// 登录授权(可选):跟以前的 needLogin 类似功能,但是同时支持黑白名单,详情请见 src/router 文件夹
excludeLoginPath: true,
// 角色授权(可选):如果需要根据角色授权,就配置这个
roleAuth: {
field: 'role',
value: 'admin',
redirect: '/pages/auth/403',
},
})
```
## 登录注册页路由
登录页 `login.vue` 对应路由是 `/pages/login/login`.
注册页 `register.vue` 对应路由是 `/pages/login/register`.
## 登录注册页适用性
登录注册页主要适用于 `h5``App`,默认不适用于 `小程序`,因为 `小程序` 通常会使用平台提供的快捷登录。
特殊情况例外,如业务需要跨平台复用登录注册页时,也可以用在 `小程序` 上,所以主要还是看业务需求。
通过一个参数 `LOGIN_PAGE_ENABLE_IN_MP` 来控制是否在 `小程序` 中使用 `H5登录页` 的登录逻辑。

53
src/router/interceptor.ts Normal file
View File

@@ -0,0 +1,53 @@
/**
* by 菲鸽 on 2025-08-19
* 路由拦截,通常也是登录拦截
* 黑、白名单的配置,请看 config.ts 文件, EXCLUDE_LOGIN_PATH_LIST
*/
import { tabbarStore } from '@/tabbar/store'
import { getAllPages, getLastPage, parseUrlToObj } from '@/utils/index'
export const FG_LOG_ENABLE = false
export const navigateToInterceptor = {
// 注意这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同
// 增加对相对路径的处理BY 网友 @ideal
invoke({ url, query }: { url: string, query?: Record<string, string> }) {
if (url === undefined) {
return
}
let { path, query: _query } = parseUrlToObj(url)
FG_LOG_ENABLE && console.log('\n\n路由拦截器:-------------------------------------')
FG_LOG_ENABLE && console.log('路由拦截器 1: url->', url, ', query ->', query)
const myQuery = { ..._query, ...query }
// /pages/route-interceptor/index?name=feige&age=30
FG_LOG_ENABLE && console.log('路由拦截器 2: path->', path, ', _query ->', _query)
FG_LOG_ENABLE && console.log('路由拦截器 3: myQuery ->', myQuery)
// 处理相对路径
if (!path.startsWith('/')) {
const currentPath = getLastPage()?.route || ''
const normalizedCurrentPath = currentPath.startsWith('/') ? currentPath : `/${currentPath}`
const baseDir = normalizedCurrentPath.substring(0, normalizedCurrentPath.lastIndexOf('/'))
path = `${baseDir}/${path}`
}
// 处理路由不存在的情况
if (path !== '/' && !getAllPages().some(page => page.path !== path)) {
console.warn('路由不存在:', path)
return false // 明确表示阻止原路由继续执行
}
// 处理直接进入路由非首页时tabbarIndex 不正确的问题
tabbarStore.setAutoCurIdx(path)
},
}
export const routeInterceptor = {
install() {
uni.addInterceptor('navigateTo', navigateToInterceptor)
uni.addInterceptor('reLaunch', navigateToInterceptor)
uni.addInterceptor('redirectTo', navigateToInterceptor)
uni.addInterceptor('switchTab', navigateToInterceptor)
},
}

6
src/service/index.ts Normal file
View File

@@ -0,0 +1,6 @@
/* eslint-disable */
// @ts-ignore
export * from './types';
export * from './listAll';
export * from './info';

14
src/service/info.ts Normal file
View File

@@ -0,0 +1,14 @@
/* eslint-disable */
// @ts-ignore
import request from '@/http/vue-query';
import { CustomRequestOptions_ } from '@/http/types';
import * as API from './types';
/** 用户信息 GET /user/info */
export function infoUsingGet({ options }: { options?: CustomRequestOptions_ }) {
return request<API.InfoUsingGetResponse>('/user/info', {
method: 'GET',
...(options || {}),
});
}

18
src/service/listAll.ts Normal file
View File

@@ -0,0 +1,18 @@
/* eslint-disable */
// @ts-ignore
import request from '@/http/vue-query';
import { CustomRequestOptions_ } from '@/http/types';
import * as API from './types';
/** 用户列表 GET /user/listAll */
export function listAllUsingGet({
options,
}: {
options?: CustomRequestOptions_;
}) {
return request<API.ListAllUsingGetResponse>('/user/listAll', {
method: 'GET',
...(options || {}),
});
}

29
src/service/types.ts Normal file
View File

@@ -0,0 +1,29 @@
/* eslint-disable */
// @ts-ignore
export type InfoUsingGetResponse = {
code: number;
msg: string;
data: UserItem;
};
export type InfoUsingGetResponses = {
200: InfoUsingGetResponse;
};
export type ListAllUsingGetResponse = {
code: number;
msg: string;
data: UserItem[];
};
export type ListAllUsingGetResponses = {
200: ListAllUsingGetResponse;
};
export type UserItem = {
userId: number;
username: string;
nickname: string;
avatar: string;
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 985 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,12 @@
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="&#228;&#191;&#161;&#230;&#129;&#175;" clip-path="url(#clip0_56_1847)">
<path id="Union" d="M41 40V41.5C41.5532 41.5 42.0615 41.1955 42.3225 40.7078C42.5835 40.2201 42.5549 39.6282 42.2481 39.1679L41 40ZM7 40L5.75192 39.1679C5.44507 39.6282 5.41646 40.2201 5.67749 40.7078C5.93852 41.1955 6.44681 41.5 7 41.5V40ZM11 34L12.2481 34.8321C12.4123 34.5856 12.5 34.2961 12.5 34H11ZM37 34H35.5C35.5 34.2961 35.5877 34.5856 35.7519 34.8321L37 34ZM41 40V38.5H7V40V41.5H41V40ZM7 40L8.24808 40.8321L12.2481 34.8321L11 34L9.75192 33.1679L5.75192 39.1679L7 40ZM11 34H12.5V21H11H9.5V34H11ZM11 21H12.5C12.5 14.6487 17.6487 9.5 24 9.5V8V6.5C15.9919 6.5 9.5 12.9919 9.5 21H11ZM24 8V9.5C30.3513 9.5 35.5 14.6487 35.5 21H37H38.5C38.5 12.9919 32.0081 6.5 24 6.5V8ZM37 21H35.5V34H37H38.5V21H37ZM37 34L35.7519 34.8321L39.7519 40.8321L41 40L42.2481 39.1679L38.2481 33.1679L37 34Z" fill="#333333"/>
<path id="Ellipse 44" d="M20.1851 7.98769C20.0649 7.607 20 7.2017 20 6.78125C20 4.57211 21.7909 2.78125 24 2.78125C26.2091 2.78125 28 4.57211 28 6.78125C28 7.2017 27.9351 7.607 27.8149 7.98769" stroke="#333333" stroke-width="3"/>
<path id="Ellipse 45" d="M16.376 39.9377C17.4047 43.1677 20.4292 45.5074 24.0001 45.5074C27.5711 45.5074 30.5956 43.1677 31.6243 39.9377" stroke="#333333" stroke-width="3"/>
</g>
<defs>
<clipPath id="clip0_56_1847">
<rect width="48" height="48" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,12 @@
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="&#228;&#191;&#161;&#230;&#129;&#175;&#231;&#153;&#189;" clip-path="url(#clip0_68_1432)">
<path id="Union" d="M41 40V41.5C41.5532 41.5 42.0615 41.1955 42.3225 40.7078C42.5835 40.2201 42.5549 39.6282 42.2481 39.1679L41 40ZM7 40L5.75192 39.1679C5.44507 39.6282 5.41646 40.2201 5.67749 40.7078C5.93852 41.1955 6.44681 41.5 7 41.5V40ZM11 34L12.2481 34.8321C12.4123 34.5856 12.5 34.2961 12.5 34H11ZM37 34H35.5C35.5 34.2961 35.5877 34.5856 35.7519 34.8321L37 34ZM41 40V38.5H7V40V41.5H41V40ZM7 40L8.24808 40.8321L12.2481 34.8321L11 34L9.75192 33.1679L5.75192 39.1679L7 40ZM11 34H12.5V21H11H9.5V34H11ZM11 21H12.5C12.5 14.6487 17.6487 9.5 24 9.5V8V6.5C15.9919 6.5 9.5 12.9919 9.5 21H11ZM24 8V9.5C30.3513 9.5 35.5 14.6487 35.5 21H37H38.5C38.5 12.9919 32.0081 6.5 24 6.5V8ZM37 21H35.5V34H37H38.5V21H37ZM37 34L35.7519 34.8321L39.7519 40.8321L41 40L42.2481 39.1679L38.2481 33.1679L37 34Z" fill="white"/>
<path id="Ellipse 44" d="M20.1851 7.98769C20.0649 7.607 20 7.2017 20 6.78125C20 4.57211 21.7909 2.78125 24 2.78125C26.2091 2.78125 28 4.57211 28 6.78125C28 7.2017 27.9351 7.607 27.8149 7.98769" stroke="white" stroke-width="3"/>
<path id="Ellipse 45" d="M16.376 39.9375C17.4047 43.1675 20.4292 45.5071 24.0001 45.5071C27.5711 45.5071 30.5956 43.1675 31.6243 39.9375" stroke="white" stroke-width="3"/>
</g>
<defs>
<clipPath id="clip0_68_1432">
<rect width="48" height="48" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,12 @@
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="Search" clip-path="url(#clip0_67_1429)">
<g id="Search_2">
<path id="vector" d="M6.82886 6.76703C11.4897 2.18878 19.0463 2.18878 23.7072 6.76703C28.2105 11.1907 28.3626 18.2699 24.1635 22.8729L29.1396 27.7615C29.2447 27.8647 29.2462 28.0335 29.143 28.1386C29.1418 28.1397 29.1407 28.1408 29.1396 28.142L28.1136 29.1498C28.0099 29.2517 27.8436 29.2517 27.7399 29.1498L22.7183 24.2166C18.0323 27.9035 11.1728 27.6134 6.82886 23.3464C2.16805 18.7681 2.16805 11.3453 6.82886 6.76703ZM8.23538 8.14864C4.35137 11.9639 4.35137 18.1495 8.23538 21.9647C12.1194 25.78 18.4166 25.78 22.3006 21.9647C26.1846 18.1495 26.1846 11.9639 22.3006 8.14864C18.4166 4.33343 12.1194 4.33343 8.23538 8.14864Z" fill="#CCCCCC"/>
</g>
</g>
<defs>
<clipPath id="clip0_67_1429">
<rect width="32" height="32" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 924 B

Some files were not shown because too many files have changed in this diff Show More