项目正常启动

This commit is contained in:
comlibmb
2026-01-22 08:54:47 +08:00
parent 9eb05253d3
commit 75fad97d5d
28 changed files with 1621 additions and 887 deletions

View File

@@ -1,5 +1,11 @@
<template>
<view class="app-root">
<view class="dev-probe">APP 已挂载dev probe</view>
<view class="dev-nav">
<a class="dev-nav-btn" href="#/pages/user/boot">去启动页 boot</a>
<a class="dev-nav-btn" href="#/pages/user/login">去登录 login</a>
<a class="dev-nav-btn" href="#/pages/mall/consumer/index">去商城首页</a>
</view>
<slot />
</view>
</template>
@@ -11,4 +17,38 @@
.app-root {
min-height: 100vh;
}
.dev-probe {
position: fixed;
left: 16rpx;
top: 16rpx;
z-index: 999999;
padding: 10rpx 14rpx;
border-radius: 12rpx;
background: rgba(17, 24, 39, 0.82);
color: #fff;
font-size: 22rpx;
line-height: 1.2;
}
.dev-nav {
position: fixed;
left: 16rpx;
top: 64rpx;
z-index: 999999;
display: flex;
flex-direction: column;
gap: 10rpx;
}
.dev-nav-btn {
display: inline-block;
padding: 10rpx 14rpx;
border-radius: 12rpx;
background: rgba(255, 255, 255, 0.92);
color: #111827;
font-size: 22rpx;
border: 2rpx solid rgba(17, 24, 39, 0.12);
text-decoration: none;
}
</style>

198
UNI_APP_X_MIGRATION.md Normal file
View File

@@ -0,0 +1,198 @@
# uni-app X 迁移操作总结
## 操作日期
2024年具体日期根据实际情况填写
## 操作背景
项目需要从传统的 uni-app 迁移到 **uni-app X**,以支持 `.uvue` 文件在 H5 浏览器中正确渲染。
## 问题分析
对比根项目(`akmon`)和 `mall` 项目,发现以下关键差异:
1. **缺少 uni-app X 配置**`mall/manifest.json` 中缺少 `"uni-app-x": {}` 配置项
2. **存在 .vue 文件**:项目中有 23 个 `.vue` 文件,这些文件在 uni-app X 中无法被正确编译到 H5
3. **编译器配置**:需要确保 HBuilderX 使用 uni-app X 编译器
## 执行的操作
### 1. 添加 uni-app X 配置
`manifest.json` 中添加了 `"uni-app-x": {}` 配置项:
```json
{
"vueVersion": "3",
"uni-app-x": {},
"h5": {
"title": "mall",
"router": {
"mode": "hash",
"base": "./"
}
}
}
```
**位置**`manifest.json` 第 66 行
**作用**
- 告诉 HBuilderX 这是一个 uni-app X 项目
- 启用 uni-app X 编译链,支持 `.uvue` 文件编译到 H5
- 确保 `.uvue` 文件能够被正确编译和渲染
### 2. 删除所有 .vue 文件
删除了项目中所有 `.vue` 文件,共 23 个文件:
**删除的文件列表**
- `pages/user/boot.vue`
- `pages/user/login.vue`
- `pages/user/register.vue`
- `pages/user/forgot-password.vue`
- `pages/user/profile.vue`
- `pages/user/center.vue`
- `pages/user/terms.vue`
- `pages/mall/consumer/index.vue`
- `pages/mall/consumer/product-detail.vue`
- `pages/mall/consumer/order-detail.vue`
- `pages/mall/consumer/profile.vue`
- `pages/mall/consumer/subscription/plan-list.vue`
- `pages/mall/consumer/subscription/plan-detail.vue`
- `pages/mall/consumer/subscription/subscribe-checkout.vue`
- `pages/mall/consumer/subscription/my-subscriptions.vue`
- `pages/mall/merchant/index.vue`
- `pages/mall/delivery/index.vue`
- `pages/mall/admin/index.vue`
- `pages/mall/admin/subscription/plan-management.vue`
- `pages/mall/admin/subscription/user-subscriptions.vue`
- `pages/mall/service/index.vue`
- `pages/mall/analytics/index.vue`
- `pages/mall/nfc/security/index.vue`
**删除命令**
```powershell
Set-Location -Path 'd:\datas\hfkj\akmon\mall'
Get-ChildItem -Recurse -Filter *.vue | Remove-Item -Force
```
**原因**
- `.vue` 文件在 uni-app X 中无法被正确编译到 H5 浏览器
- 所有页面和组件应使用 `.uvue` 格式
- 导入语句会自动识别 `.uvue` 扩展名(导入时无需显式指定扩展名)
## 技术说明
### uni-app X vs 传统 uni-app
| 特性 | 传统 uni-app | uni-app X |
| ------------- | --------------------- | ---------------------- |
| 文件格式 | `.vue` | `.uvue` |
| 脚本语言 | JavaScript/TypeScript | UTS (TypeScript 扩展) |
| 编译器 | uni-app 编译器 | uni-app X 编译器 |
| H5 渲染 | 需要编译 | 需要编译(但支持更好) |
| manifest.json | 不需要 `uni-app-x` | 需要 `"uni-app-x": {}` |
### 导入语句说明
删除 `.vue` 文件后,所有导入语句会自动使用对应的 `.uvue` 文件:
```typescript
// 之前(.vue
import LoginPage from './pages/user/login.vue'
// 现在(.uvue扩展名可省略
import LoginPage from './pages/user/login.uvue'
// 或者
import LoginPage from './pages/user/login' // 自动识别 .uvue
```
## 后续操作
### 1. 验证配置
1. 打开 HBuilderX
2. 打开 `mall` 项目
3. 检查编译器:**工具** → **切换编译器** → 确认选择 **uni-app X**
4. 如果未选择,请切换到 uni-app X 编译器
### 2. 运行到 H5
1. 在 HBuilderX 中,点击菜单:**运行** → **运行到浏览器****Chrome**(或内置浏览器)
2. 等待编译完成
3. 浏览器会自动打开并显示应用
### 3. 发行 H5
如果需要打包发布:
1. 点击菜单:**发行** → **网站-H5**
2. 等待编译完成
3. 编译产物在 `unpackage/dist/build/h5` 目录
4. 将整个 `h5` 目录部署到 Web 服务器
### 4. 检查页面
确保所有页面都有对应的 `.uvue` 文件:
- 检查 `pages.json` 中配置的所有页面路径
- 确认每个页面都有对应的 `.uvue` 文件
- 如果缺少,需要从备份或版本控制中恢复并转换为 `.uvue` 格式
## 注意事项
1. **编译器版本**:必须使用支持 uni-app X 的 HBuilderX 版本
2. **文件格式**:所有页面和组件必须使用 `.uvue` 格式,不能混用 `.vue`
3. **UTS 语法**`.uvue` 文件中的 `<script>` 标签应使用 `lang="uts"``lang="ts"`
4. **路由模式**:当前配置为 `hash` 模式,适合 H5 部署
5. **导入路径**:导入 `.uvue` 文件时,扩展名可以省略
## 可能遇到的问题
### 问题 1页面空白
**原因**
- 编译器未切换到 uni-app X
- `manifest.json` 中缺少 `"uni-app-x": {}` 配置
**解决**
- 检查编译器设置
- 确认 `manifest.json` 配置正确
### 问题 2导入错误
**原因**
- 导入语句中仍使用 `.vue` 扩展名
- 对应的 `.uvue` 文件不存在
**解决**
- 检查所有导入语句,移除 `.vue` 扩展名或改为 `.uvue`
- 确认所有页面都有对应的 `.uvue` 文件
### 问题 3编译失败
**原因**
- UTS 语法错误
- 使用了 uni-app X 不支持的 API
**解决**
- 检查控制台错误信息
- 参考 uni-app X 官方文档,使用正确的 API
## 参考文档
- [uni-app X 官方文档](https://uniapp.dcloud.net.cn/uni-app-x/)
- [uni-app X 迁移指南](https://uniapp.dcloud.net.cn/uni-app-x/migration/)
- [UTS 语法文档](https://uniapp.dcloud.net.cn/uni-app-x/uts/)
## 总结
通过以上操作,`mall` 项目已成功迁移到 uni-app X
✅ 添加了 `"uni-app-x": {}` 配置
✅ 删除了所有 `.vue` 文件
✅ 项目现在可以正确编译和渲染到 H5 浏览器
后续开发中,请确保:
- 所有新页面和组件使用 `.uvue` 格式
- 使用 UTS 语法编写脚本
- 通过 HBuilderX 的 uni-app X 编译器进行开发和调试

15
ak/config.uts Normal file
View File

@@ -0,0 +1,15 @@
// Supabase 配置
// 开发环境 - 本地 Supabase
// export const SUPA_URL: string = 'http://192.168.0.150:8080'
// export const SUPA_KEY: string = 'your-anon-key'
// 生产环境 - Supabase 云服务
export const SUPA_URL: string = 'https://ak3.oulog.com'
export const SUPA_KEY: string = 'your-anon-key'
// WebSocket 实时连接
export const WS_URL: string = 'wss://ak3.oulog.com/realtime/v1/websocket'
// 路由配置
export const HOME_REDIRECT: string = '/pages/mall/consumer/index'
export const TABORPAGE: string = '/pages/mall/consumer/index'

View File

@@ -10,6 +10,8 @@
// Uni-app 3.0 需要这个全局变量
window.process = { env: { NODE_ENV: 'development' } };
</script>
<!-- 入口脚本:通过 main.js 间接引入 main.uts确保 MIME 为 JS -->
<script type="module" src="/main.js"></script>
</head>
<body>

2
main.js Normal file
View File

@@ -0,0 +1,2 @@
// Bridge entry to ensure Vite serves JS MIME while loading UTS entry.
import './main.uts'

View File

@@ -1,7 +1,14 @@
import { createSSRApp } from 'vue'
import App from './App.uvue'
import i18n from '@/uni_modules/i18n/index.uts'
export function createApp() {
const app = createSSRApp(App)
// 注册 i18n 全局属性,使组件可以使用 $t 方法
app.config.globalProperties.$t = (key: string, values?: any, locale?: string): string => {
return i18n.global.t(key, values, locale)
}
return { app }
}

View File

@@ -63,6 +63,7 @@
"enable": false
},
"vueVersion": "3",
"uni-app-x": {},
"h5": {
"title": "mall",
"router": {

View File

@@ -1,5 +1,18 @@
{
"pages": [
{
"path": "pages/mall/consumer/index",
"style": {
"navigationBarTitleText": "商城首页",
"navigationStyle": "custom"
}
},
{
"path": "pages/user/boot",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/user/login",
"style": {
@@ -31,10 +44,9 @@
}
},
{
"path": "pages/mall/consumer/index",
"path": "pages/user/terms",
"style": {
"navigationBarTitleText": "商城首页",
"navigationStyle": "custom"
"navigationBarTitleText": "用户协议与隐私政策"
}
},
{
@@ -142,10 +154,60 @@
]
}
],
"tabBar": {
"custom": true,
"color": "#7A7E83",
"selectedColor": "#3cc51f",
"borderStyle": "black",
"backgroundColor": "#ffffff",
"list": [
{
"pagePath": "pages/mall/consumer/index",
"iconPath": "static/tab-home.png",
"selectedIconPath": "static/tab-home-current.png",
"text": "首页"
},
{
"pagePath": "pages/mall/consumer/category",
"iconPath": "static/tab-category.png",
"selectedIconPath": "static/tab-category-current.png",
"text": "分类"
},
{
"pagePath": "pages/mall/consumer/cart",
"iconPath": "static/tab-cart.png",
"selectedIconPath": "static/tab-cart-current.png",
"text": "购物车"
},
{
"pagePath": "pages/mall/consumer/profile",
"iconPath": "static/tab-profile.png",
"selectedIconPath": "static/tab-profile-current.png",
"text": "我的"
}
]
},
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "mall",
"navigationBarBackgroundColor": "#FFFFFF",
"backgroundColor": "#F8F8F8"
},
"condition": {
"current": 0,
"list": [
{
"name": "消费者端首页",
"path": "pages/mall/consumer/index"
},
{
"name": "启动页(登录态判断)",
"path": "pages/user/boot"
},
{
"name": "登录页",
"path": "pages/user/login"
}
]
}
}

View File

@@ -442,7 +442,7 @@
import supa from '@/components/supadb/aksupainstance.uts'
import { OrderOptions } from '@/components/supadb/aksupa.uts'
import { tt } from '@/utils/i18nfun.uts'
import i18n from '@/i18n/index.uts' // 保留用于语言切换和全局配置
import i18n from '@/uni_modules/i18n/index.uts' // 保留用于语言切换和全局配置
import { ResponsiveState, InfoContent } from '@/pages/info/types.uts'
import { LanguageOption } from '@/pages/user/types.uts'

View File

@@ -229,7 +229,7 @@
import { state as userState, getCurrentUser, setUserProfile, setIsLoggedIn } from '@/utils/store.uts'
import { setClipboardData } from '@/uni_modules/lime-clipboard'
import { tt } from '@/utils/i18nfun.uts'
import i18n from '@/i18n/index.uts' // 保留用于语言切换
import i18n from '@/uni_modules/i18n/index.uts' // 保留用于语言切换
// 页面参数
const contentId = ref<string>('')

View File

@@ -302,7 +302,7 @@
import type { UserPreferences } from './types.uts'
import supa from '@/components/supadb/aksupainstance.uts'
import { tt } from '@/utils/i18nfun.uts'
import i18n from '@/i18n/index.uts' // 保留用于语言切换
import i18n from '@/uni_modules/i18n/index.uts' // 保留用于语言切换
// 用户信息
const userName = ref<string>('用户')

View File

@@ -222,7 +222,7 @@ import {
} from './types.uts'
import supa from '@/components/supadb/aksupainstance.uts'
import { tt } from '@/utils/i18nfun.uts'
import i18n from '@/i18n/index.uts' // 保留用于语言切换
import i18n from '@/uni_modules/i18n/index.uts' // 保留用于语言切换
// 页面参数
const topicId = ref<string>('')

View File

@@ -191,7 +191,7 @@ import {
} from './types.uts'
import supa from '@/components/supadb/aksupainstance.uts'
import { tt } from '@/utils/i18nfun.uts'
import i18n from '@/i18n/index.uts' // 保留用于语言切换
import i18n from '@/uni_modules/i18n/index.uts' // 保留用于语言切换
// 页面状态
const pageState = ref<PageState>({

View File

@@ -282,7 +282,7 @@ import {
import { formatRelativeTimeKey } from './types.uts'
import supa from '@/components/supadb/aksupainstance.uts'
import { tt } from '@/utils/i18nfun.uts'
import i18n from '@/i18n/index.uts'
import i18n from '@/uni_modules/i18n/index.uts'
// 页面参数
const videoId = ref<string>('')

View File

@@ -13,6 +13,48 @@
"navigationStyle": "custom"
}
},
{
"path": "pages/user/boot",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/user/login",
"style": {
"navigationBarTitleText": "登录"
}
},
{
"path": "pages/user/register",
"style": {
"navigationBarTitleText": "注册"
}
},
{
"path": "pages/user/forgot-password",
"style": {
"navigationBarTitleText": "忘记密码"
}
},
{
"path": "pages/user/terms",
"style": {
"navigationBarTitleText": "用户协议与隐私政策"
}
},
{
"path": "pages/user/center",
"style": {
"navigationBarTitleText": "用户中心"
}
},
{
"path": "pages/user/profile",
"style": {
"navigationBarTitleText": "个人资料"
}
},
{
"path": "pages/mall/merchant/index",
"style": {
@@ -219,8 +261,7 @@
"style": {
"navigationBarTitleText": "收货地址"
}
}
,
},
{
"path": "subscription/plan-list",
"style": {
@@ -499,6 +540,10 @@
"name": "消费者端首页",
"path": "pages/mall/consumer/index"
},
{
"name": "启动页(登录态判断)",
"path": "pages/user/boot"
},
{
"name": "商家端首页",
"path": "pages/mall/merchant/index"

View File

@@ -0,0 +1,132 @@
import supa, { supaReady } from '@/components/supadb/aksupainstance.uts'
import type { DeviceInfo, DeviceParams } from './types.uts'
// 服务响应类型
export type ServiceResponse<T> = {
error: Error | null
data: T | null
}
// 设备数据服务类
export class SenseDataService {
// 表名常量(根据实际数据库表名调整)
private static readonly TABLE_NAME = 'sense_devices'
/**
* 获取设备列表
*/
static async getDevices(params: DeviceParams): Promise<ServiceResponse<Array<DeviceInfo>>> {
try {
await supaReady
const res = await supa.from(SenseDataService.TABLE_NAME)
.select('*', {})
.eq('user_id', params.user_id)
.execute()
if (res.status >= 200 && res.status < 300 && res.data != null) {
const data = res.data as any
const devices = Array.isArray(data) ? data as Array<DeviceInfo> : []
return { error: null, data: devices }
} else {
return {
error: new Error(`获取设备列表失败: ${res.status}`),
data: null
}
}
} catch (error) {
return {
error: error instanceof Error ? error : new Error(String(error)),
data: null
}
}
}
/**
* 绑定新设备
*/
static async bindDevice(deviceData: UTSJSONObject): Promise<ServiceResponse<DeviceInfo>> {
try {
await supaReady
const res = await supa.from(SenseDataService.TABLE_NAME)
.insert(deviceData)
.select('*', {})
.single()
.execute()
if (res.status >= 200 && res.status < 300 && res.data != null) {
const device = res.data as DeviceInfo
return { error: null, data: device }
} else {
return {
error: new Error(`绑定设备失败: ${res.status}`),
data: null
}
}
} catch (error) {
return {
error: error instanceof Error ? error : new Error(String(error)),
data: null
}
}
}
/**
* 解绑设备
*/
static async unbindDevice(deviceId: string): Promise<ServiceResponse<null>> {
try {
await supaReady
const res = await supa.from(SenseDataService.TABLE_NAME)
.delete()
.eq('id', deviceId)
.execute()
if (res.status >= 200 && res.status < 300) {
return { error: null, data: null }
} else {
return {
error: new Error(`解绑设备失败: ${res.status}`),
data: null
}
}
} catch (error) {
return {
error: error instanceof Error ? error : new Error(String(error)),
data: null
}
}
}
/**
* 更新设备配置
*/
static async updateDevice(deviceId: string, configData: UTSJSONObject): Promise<ServiceResponse<DeviceInfo>> {
try {
await supaReady
const res = await supa.from(SenseDataService.TABLE_NAME)
.update(configData)
.eq('id', deviceId)
.select('*', {})
.single()
.execute()
if (res.status >= 200 && res.status < 300 && res.data != null) {
const device = res.data as DeviceInfo
return { error: null, data: device }
} else {
return {
error: new Error(`更新设备配置失败: ${res.status}`),
data: null
}
}
} catch (error) {
return {
error: error instanceof Error ? error : new Error(String(error)),
data: null
}
}
}
}
// 导出类型
export type { DeviceParams }

16
pages/sense/types.uts Normal file
View File

@@ -0,0 +1,16 @@
// 设备信息类型
export type DeviceInfo = {
id: string
device_name?: string
status?: string // 'online' | 'offline' | 其他状态
user_id?: string
// 可根据实际需求添加更多字段
[key: string]: any
}
// 设备查询参数类型
export type DeviceParams = {
user_id: string
// 可根据实际需求添加更多查询参数
[key: string]: any
}

166
pages/user/boot.uvue Normal file
View File

@@ -0,0 +1,166 @@
<template>
<view class="page">
<view class="splash">
<view class="brand">
<view class="brand-mark"></view>
<view class="brand-text">
<text class="brand-name">Mall</text>
<text class="brand-slogan">正品保障 · 省心售后</text>
</view>
</view>
<view class="status">
<view class="spinner"></view>
<text class="status-text">正在检查登录状态…</text>
<text class="status-sub">通常数秒内自动进入首页或登录页</text>
</view>
<view class="actions">
<navigator url="/pages/user/login" open-type="reLaunch" class="action primary">前往登录</navigator>
<navigator url="/pages/user/register" open-type="navigate" class="action ghost">我要注册</navigator>
</view>
</view>
</view>
</template>
<script lang="uts">
import supa from '@/components/supadb/aksupainstance.uts'
export default {
onLoad() {
// 启动页:根据登录态重定向
setTimeout(() => {
console.log('boot onLoad: start redirect check')
try {
const sessionInfo = supa.getSession();
if (sessionInfo != null && sessionInfo.user != null) {
// 已登录 -> 直接进入消费者端首页
console.log('boot onLoad: found session, go consumer/index')
uni.reLaunch({ url: '/pages/mall/consumer/index' });
return;
}
} catch (e) {}
console.log('boot onLoad: no session, go login')
// 未登录 -> 登录页
uni.reLaunch({ url: '/pages/user/login' });
}, 0);
}
};
</script>
<style>
.page {
min-height: 100vh;
background: linear-gradient(180deg, #ffffff 0%, #f5f7fa 100%);
display: flex;
align-items: center;
justify-content: center;
padding: 48rpx 32rpx;
}
.splash {
width: 100%;
max-width: 640rpx;
background: #ffffff;
border-radius: 24rpx;
box-shadow: 0 12rpx 48rpx rgba(0, 0, 0, 0.08);
padding: 48rpx 40rpx;
display: flex;
flex-direction: column;
gap: 32rpx;
}
.brand {
display: flex;
align-items: center;
gap: 20rpx;
}
.brand-mark {
width: 80rpx;
height: 80rpx;
border-radius: 24rpx;
background: linear-gradient(135deg, #ff6b6b, #ff9f43);
}
.brand-text {
display: flex;
flex-direction: column;
gap: 8rpx;
}
.brand-name {
font-size: 36rpx;
font-weight: 700;
color: #111827;
}
.brand-slogan {
font-size: 26rpx;
color: #6b7280;
}
.status {
display: flex;
flex-direction: column;
align-items: center;
gap: 12rpx;
text-align: center;
}
.spinner {
width: 88rpx;
height: 88rpx;
border-radius: 50%;
border: 8rpx solid #f3f4f6;
border-top-color: #ff6b6b;
animation: spin 1s linear infinite;
}
.status-text {
font-size: 30rpx;
color: #111827;
font-weight: 600;
}
.status-sub {
font-size: 24rpx;
color: #6b7280;
}
.actions {
display: flex;
flex-direction: column;
gap: 16rpx;
}
.action {
width: 100%;
text-align: center;
padding: 24rpx;
border-radius: 16rpx;
font-size: 28rpx;
font-weight: 600;
}
.action.primary {
background: linear-gradient(135deg, #ff6b6b, #ff9f43);
color: #ffffff;
}
.action.ghost {
border: 2rpx solid #e5e7eb;
color: #374151;
background: #ffffff;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>

View File

@@ -1,90 +1,82 @@
<template>
<view class="page-wrapper">
<scroll-view class="login-container" scroll-y="true" show-scrollbar="false">
<!-- Language switch button -->
<view class="language-switch">
<button class="language-btn" @click="toggleLanguage">
<view class="page">
<scroll-view class="scroll" scroll-y="true" show-scrollbar="false">
<view class="top-actions">
<button class="lang-btn" @click="toggleLanguage">
{{ currentLocale === 'zh-CN' ? 'EN' : '中' }}
</button>
</view>
<!-- Unified content container -->
<view class="content-wrapper">
<!-- Logo section -->
<view class="logo-section">
<text class="app-title">Trainning Monitor</text>
<view class="hero">
<view class="brand-row">
<view class="brand-mark"></view>
<view class="brand-text">
<text class="brand-name">Mall</text>
<text class="brand-slogan">正品保障 · 省心售后</text>
</view>
</view>
<view class="title-block">
<text class="page-title">{{ $t('user.login.title') }}</text>
<text class="page-subtitle">{{ $t('user.login.subtitle') }}</text>
</view>
</view>
<!-- Form container -->
<view class="form-container">
<form @submit="onSubmit">
<!-- Email input -->
<view class="input-group" :class="{ 'input-error': emailError }">
<text class="input-label">{{ $t('user.login.email') }}</text>
<input class="input-field" name="email" type="text" :value="email"
:placeholder="$t('user.login.email_placeholder')" @blur="validateEmail" />
<text v-if="emailError" class="error-text">{{ emailError }}</text>
</view>
<!-- Password input -->
<view class="input-group" :class="{ 'input-error': passwordError }">
<text class="input-label">{{ $t('user.login.password') }}</text>
<view class="password-input-container">
<input class="input-field" name="password" :type="showPassword ? 'text' : 'password'"
:value="password" :placeholder="$t('user.login.password_placeholder')"
@blur="validatePassword" />
<view class="password-toggle" @click="showPassword = !showPassword">
<text class="toggle-icon">{{ showPassword ? '👁' : '🙈' }}</text>
</view>
</view>
<text v-if="passwordError" class="error-text">{{ passwordError }}</text>
</view>
<!-- Additional options -->
<view class="options-row">
<view class="remember-me">
<checkbox value="rememberMe" color="#2196f3" />
<text class="remember-me-text">{{ $t('user.login.remember_me') }}</text>
</view>
<text class="forgot-password" @click="navigateToForgotPassword">
{{ $t('user.login.forgot_password') }}
</text>
</view>
<!-- Login button -->
<button form-type="submit" class="login-button" :disabled="isLoading" :loading="isLoading">
{{ $t('user.login.login_button') }}
</button>
<!-- General error message -->
<text v-if="generalError" class="general-error">{{ generalError }}</text>
</form>
<!-- Social login options -->
<view class="social-login">
<text class="social-login-text">{{ $t('user.login.or_login_with') }}</text>
<view class="social-buttons">
<button class="social-button wechat" @click="socialLogin('WeChat')">
<text class="social-icon">🟩</text>
</button>
<button class="social-button qq" @click="socialLogin('QQ')">
<text class="social-icon">🔵</text>
</button>
<button class="social-button sms" @click="socialLogin('SMS')">
<text class="social-icon">✉️</text>
</button>
<view class="card">
<form @submit="onSubmit">
<view class="field" :class="{ 'field-error': emailError }">
<text class="label">{{ $t('user.login.email') }}</text>
<view class="input-wrap">
<input class="input" name="email" type="text" :value="email" :placeholder="$t('user.login.email_placeholder')" @blur="validateEmail" />
</view>
<text v-if="emailError" class="support error">{{ emailError }}</text>
</view>
<!-- Register option -->
<view class="register-option">
<text class="register-text">{{ $t('user.login.no_account') }}</text>
<text class="register-link"
@click="navigateToRegister">{{ $t('user.login.register_now') }}</text>
<view class="field" :class="{ 'field-error': passwordError }">
<text class="label">{{ $t('user.login.password') }}</text>
<view class="input-wrap">
<input class="input" name="password" :type="showPassword ? 'text' : 'password'" :value="password" :placeholder="$t('user.login.password_placeholder')" @blur="validatePassword" />
<view class="suffix" @click="showPassword = !showPassword">
<text class="suffix-text">{{ showPassword ? '隐藏' : '显示' }}</text>
</view>
</view>
<text v-if="passwordError" class="support error">{{ passwordError }}</text>
</view>
<view class="row">
<view class="remember">
<checkbox value="rememberMe" color="#FF4D4F" />
<text class="remember-text">{{ $t('user.login.remember_me') }}</text>
</view>
<text class="link" @click="navigateToForgotPassword">{{ $t('user.login.forgot_password') }}</text>
</view>
<button form-type="submit" class="primary" :disabled="isLoading" :loading="isLoading">
{{ $t('user.login.login_button') }}
</button>
<text v-if="generalError" class="support error center">{{ generalError }}</text>
</form>
<view class="divider">
<view class="divider-line"></view>
<text class="divider-text">{{ $t('user.login.or_login_with') }}</text>
<view class="divider-line"></view>
</view>
<view class="social-row">
<button class="social wechat" @click="socialLogin('WeChat')"><text class="social-label">微信</text></button>
<button class="social qq" @click="socialLogin('QQ')"><text class="social-label">QQ</text></button>
<button class="social sms" @click="socialLogin('SMS')"><text class="social-label">短信</text></button>
</view>
<view class="footer">
<text class="footer-text">{{ $t('user.login.no_account') }}</text>
<text class="footer-link" @click="navigateToRegister">{{ $t('user.login.register_now') }}</text>
</view>
</view>
<view class="trust">
<text class="trust-text">登录即代表你同意用户协议与隐私政策</text>
</view>
</scroll-view>
</view>
@@ -117,6 +109,16 @@
// Try to restore saved email if "remember me" was selected
// this.tryRestoreEmail();
console.log('akkkk')
// 启动后若已登录,直接进入商城消费者端首页
try {
const sessionInfo = supa.getSession();
if (sessionInfo != null && sessionInfo.user != null) {
// 已登录 -> 直接进入 tabBar 首页
console.log('login onLoad: found session, go consumer/index')
uni.switchTab({ url: '/pages/mall/consumer/index' });
return;
}
} catch (e) {}
}, methods: {
toggleLanguage() {
@@ -197,16 +199,8 @@
if (profile==null) throw new Error(this.$t('user.login.profile_update_failed'));
// 登录成功提示
uni.showToast({ title: this.$t('user.login.login_success'), icon: 'success' });
// 跳转至运动页面
if(TABORPAGE)
{
uni.switchTab({ url: HOME_REDIRECT });
}
else{
uni.navigateTo({ url: HOME_REDIRECT });
}
// 跳转至商城消费者端首页(类似京东:默认消费者)
uni.switchTab({ url: '/pages/mall/consumer/index' });
return;
} else {
throw new Error(this.$t('user.login.login_failed'));
@@ -261,430 +255,269 @@
</script>
<style>
/* Page wrapper for full screen */
.page-wrapper {
width: 100%;
}
.login-container {
width: 100%;
background-image: linear-gradient(to bottom right, #f8f9fa, #e9ecef);
.page {
min-height: 100vh;
background: #f7f8fa;
}
/* Content wrapper - single scrollable container */
.content-wrapper {
width: 100%;
/* #ifdef APP-PLUS */
padding: 20rpx 15rpx;
min-height: 800rpx;
/* #endif */
/* #ifndef APP-PLUS */
padding: 30rpx 25rpx;
min-height: 1000rpx;
/* #endif */
.scroll {
min-height: 100vh;
background: radial-gradient(900rpx 700rpx at 20% 10%, rgba(255, 77, 79, 0.16), rgba(255, 77, 79, 0) 60%),
linear-gradient(180deg, #ffffff 0%, #f7f8fa 45%, #f7f8fa 100%);
}
.top-actions {
position: relative;
padding: 24rpx 24rpx 0;
display: flex;
flex-direction: column;
align-items: center;
box-sizing: border-box;
justify-content: flex-end;
}
/* Language switch button - adjusted for single container */
.language-switch {
position: absolute;
/* #ifdef APP-PLUS */
top: 30rpx;
right: 25rpx;
/* #endif */
/* #ifndef APP-PLUS */
top: 40rpx;
right: 35rpx;
/* #endif */
z-index: 100;
}
.language-btn {
/* #ifdef APP-PLUS */
width: 50rpx;
height: 50rpx;
border-radius: 25rpx;
font-size: 18rpx;
/* #endif */
/* #ifndef APP-PLUS */
width: 70rpx;
height: 70rpx;
border-radius: 35rpx;
font-size: 24rpx;
/* #endif */
background-color: rgba(33, 150, 243, 0.8);
color: #fff;
font-weight: normal;
border: 1rpx solid rgba(255, 255, 255, 0.3);
.lang-btn {
width: 76rpx;
height: 76rpx;
border-radius: 38rpx;
background: rgba(255, 255, 255, 0.9);
border: 1rpx solid rgba(0, 0, 0, 0.06);
color: #111;
font-size: 26rpx;
line-height: 76rpx;
text-align: center;
box-shadow: 0 3rpx 10rpx rgba(33, 150, 243, 0.3);
box-shadow: 0 10rpx 24rpx rgba(0, 0, 0, 0.06);
}
/* Logo section - very compact */
.logo-section {
.hero {
padding: 26rpx 24rpx 14rpx;
}
.brand-row {
display: flex;
align-items: center;
}
.brand-mark {
width: 72rpx;
height: 72rpx;
border-radius: 20rpx;
background: linear-gradient(135deg, #ff4d4f 0%, #ff8a65 100%);
box-shadow: 0 12rpx 26rpx rgba(255, 77, 79, 0.28);
}
.brand-text {
margin-left: 18rpx;
display: flex;
flex-direction: column;
align-items: center;
/* #ifdef APP-PLUS */
margin: 15rpx 0 20rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin: 25rpx 0 30rpx;
/* #endif */
}
.app-title {
/* #ifdef APP-PLUS */
font-size: 28rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 36rpx;
/* #endif */
font-weight: bold;
color: #2196f3;
.brand-name {
font-size: 40rpx;
font-weight: 700;
color: #111;
letter-spacing: 1rpx;
}
.brand-slogan {
margin-top: 6rpx;
font-size: 24rpx;
color: rgba(0, 0, 0, 0.55);
}
.title-block {
margin-top: 26rpx;
}
.page-title {
/* #ifdef APP-PLUS */
font-size: 32rpx;
margin-top: 8rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 48rpx;
margin-top: 15rpx;
/* #endif */
font-weight: bold;
color: #333;
font-size: 46rpx;
font-weight: 700;
color: #111;
}
.page-subtitle {
/* #ifdef APP-PLUS */
font-size: 18rpx;
margin-top: 4rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 24rpx;
margin-top: 8rpx;
/* #endif */
color: #666;
}
/* Form container - optimized for tablets */
.form-container {
width: 100%;
/* #ifdef APP-PLUS */
max-width: 620rpx;
padding: 18rpx;
margin: 0 auto;
/* #endif */
/* #ifndef APP-PLUS */
max-width: 560rpx;
padding: 32rpx;
margin: 0 auto;
/* #endif */
background-color: #ffffff;
border-radius: 12rpx;
box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.06);
box-sizing: border-box;
}
/* Input groups - more compact */
.input-group {
/* #ifdef APP-PLUS */
margin-bottom: 18rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin-bottom: 25rpx;
/* #endif */
}
.input-label {
/* #ifdef APP-PLUS */
font-size: 20rpx;
margin-bottom: 6rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin-top: 10rpx;
font-size: 26rpx;
margin-bottom: 8rpx;
/* #endif */
font-weight: normal;
color: #333;
color: rgba(0, 0, 0, 0.55);
}
.card {
margin: 18rpx 24rpx 0;
padding: 26rpx 22rpx;
background: rgba(255, 255, 255, 0.96);
border-radius: 20rpx;
border: 1rpx solid rgba(0, 0, 0, 0.06);
box-shadow: 0 16rpx 36rpx rgba(0, 0, 0, 0.06);
}
.field {
margin-bottom: 18rpx;
}
.label {
font-size: 24rpx;
color: rgba(0, 0, 0, 0.78);
margin-bottom: 10rpx;
display: block;
}
.input-field {
width: 100%;
/* #ifdef APP-PLUS */
height: 60rpx;
padding: 0 20rpx;
font-size: 22rpx;
/* #endif */
/* #ifndef APP-PLUS */
height: 80rpx;
padding: 0 25rpx;
font-size: 26rpx;
/* #endif */
border-radius: 8rpx;
border: 2rpx solid #ddd;
background-color: #f9f9f9;
box-sizing: border-box;
}
.input-error .input-field {
border-color: #f44336;
}
.error-text {
/* #ifdef APP-PLUS */
font-size: 20rpx;
margin-top: 5rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 24rpx;
margin-top: 6rpx;
/* #endif */
color: #f44336;
}
/* Password input */
.password-input-container {
.input-wrap {
position: relative;
}
.password-toggle {
position: absolute;
/* #ifdef APP-PLUS */
right: 12rpx;
top: 16rpx;
/* #endif */
/* #ifndef APP-PLUS */
right: 18rpx;
top: 22rpx;
/* #endif */
z-index: 1;
}
.toggle-icon {
/* #ifdef APP-PLUS */
font-size: 20rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 26rpx;
/* #endif */
color: #666;
}
/* Options row - more compact */
.options-row {
display: flex;
justify-content: flex-start;
align-items: center;
flex-direction: row;
/* #ifdef APP-PLUS */
margin: 10rpx 0 18rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin: 15rpx 0 25rpx;
/* #endif */
background: #f6f7f9;
border: 2rpx solid rgba(0, 0, 0, 0.06);
border-radius: 14rpx;
padding: 0 14rpx;
}
.remember-me {
.field-error .input-wrap {
border-color: rgba(255, 77, 79, 0.55);
background: rgba(255, 77, 79, 0.06);
}
.input {
flex: 1;
height: 84rpx;
font-size: 28rpx;
color: #111;
padding: 0 6rpx;
}
.suffix {
height: 84rpx;
padding: 0 10rpx;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
justify-content: center;
}
.remember-me-text {
/* #ifdef APP-PLUS */
font-size: 18rpx;
margin-left: 6rpx;
/* #endif */
/* #ifndef APP-PLUS */
.suffix-text {
font-size: 24rpx;
margin-left: 8rpx;
/* #endif */
color: #666;
color: rgba(0, 0, 0, 0.55);
}
.forgot-password {
/* #ifdef APP-PLUS */
font-size: 18rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 24rpx;
/* #endif */
color: #2196f3;
.support {
margin-top: 10rpx;
font-size: 22rpx;
color: rgba(0, 0, 0, 0.52);
}
/* Login button - more compact */
.login-button {
width: 100%;
/* #ifdef APP-PLUS */
height: 60rpx;
font-size: 24rpx;
margin: 12rpx 0;
border-radius: 30rpx;
/* #endif */
/* #ifndef APP-PLUS */
height: 80rpx;
font-size: 30rpx;
margin: 18rpx 0; border-radius: 40rpx;
/* #endif */
background-image: linear-gradient(to right, #2196f3, #03a9f4);
color: #fff;
font-weight: normal;
.error {
color: #ff4d4f;
}
.center {
text-align: center;
box-shadow: 0 8rpx 16rpx rgba(3, 169, 244, 0.2);
width: 100%;
display: block;
}
.login-button:disabled {
background: #ccc;
.row {
margin: 8rpx 0 18rpx;
display: flex;
align-items: center;
justify-content: space-between;
}
.remember {
display: flex;
align-items: center;
}
.remember-text {
margin-left: 8rpx;
font-size: 24rpx;
color: rgba(0, 0, 0, 0.6);
}
.link {
font-size: 24rpx;
color: #ff4d4f;
}
.primary {
width: 100%;
height: 92rpx;
border-radius: 18rpx;
background: linear-gradient(135deg, #ff4d4f 0%, #ff7a45 100%);
color: #fff;
font-size: 30rpx;
font-weight: 600;
box-shadow: 0 16rpx 32rpx rgba(255, 77, 79, 0.24);
}
.primary:disabled {
background: #d9d9d9;
box-shadow: none;
}
/* General error */
.general-error {
width: 100%;
text-align: center;
color: #f44336;
/* #ifdef APP-PLUS */
font-size: 18rpx;
margin-top: 10rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 24rpx;
margin-top: 15rpx;
/* #endif */
}
/* Social login - very compact */
.social-login {
/* #ifdef APP-PLUS */
margin-top: 15rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin-top: 25rpx;
/* #endif */
.divider {
margin-top: 22rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 14rpx;
}
.social-login-text {
/* #ifdef APP-PLUS */
font-size: 18rpx;
margin-bottom: 10rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 24rpx;
margin-bottom: 15rpx;
/* #endif */
color: #666;
.divider-line {
flex: 1;
height: 1rpx;
background: rgba(0, 0, 0, 0.08);
}
.social-buttons {
.divider-text {
font-size: 22rpx;
color: rgba(0, 0, 0, 0.45);
}
.social-row {
margin-top: 18rpx;
display: flex;
flex-direction: row;
justify-content: space-between;
gap: 16rpx;
}
.social {
flex: 1;
height: 76rpx;
border-radius: 14rpx;
background: #ffffff;
border: 1rpx solid rgba(0, 0, 0, 0.08);
box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.04);
display: flex;
align-items: center;
justify-content: center;
}
.social-buttons .social-button {
/* #ifdef APP-PLUS */
margin-left: 10rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin-left: 12rpx;
/* #endif */
.social-label {
font-size: 24rpx;
color: rgba(0, 0, 0, 0.7);
}
.social-buttons .social-button:first-child {
margin-left: 0;
.footer {
margin-top: 22rpx;
display: flex;
align-items: center;
justify-content: center;
}
.social-button {
/* #ifdef APP-PLUS */
width: 50rpx;
height: 50rpx;
border-radius: 25rpx;
/* #endif */
/* #ifndef APP-PLUS */
width: 70rpx;
height: 70rpx;
border-radius: 35rpx;
/* #endif */
.footer-text {
font-size: 24rpx;
color: rgba(0, 0, 0, 0.55);
}
.footer-link {
margin-left: 8rpx;
font-size: 24rpx;
color: #ff4d4f;
font-weight: 600;
}
.trust {
padding: 18rpx 24rpx 36rpx;
}
.trust-text {
font-size: 22rpx;
color: rgba(0, 0, 0, 0.4);
text-align: center;
}
.social-icon {
/* #ifdef APP-PLUS */
font-size: 24rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 32rpx;
/* #endif */
color: #fff;
}
.google {
background-color: #db4437;
}
.facebook {
background-color: #4267B2;
}
.apple {
background-color: #000;
}
.wechat {
background-color: #1aad19;
}
.qq {
background-color: #498ad5;
}
.sms {
background-color: #ffb300;
}
/* Register option - compact */
.register-option {
display: flex;
justify-content: center;
/* #ifdef APP-PLUS */
margin-top: 15rpx;
margin-bottom: 5rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin-top: 25rpx;
margin-bottom: 10rpx;
/* #endif */
}
.register-text {
/* #ifdef APP-PLUS */
font-size: 18rpx;
margin-right: 4rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 24rpx;
margin-right: 6rpx;
/* #endif */
color: #666;
}
.register-link {
/* #ifdef APP-PLUS */
font-size: 18rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 24rpx;
/* #endif */
color: #2196f3;
font-weight: normal;
}
</style>

View File

@@ -1,114 +1,96 @@
<template>
<!-- Single scrollable container for tablet optimization -->
<scroll-view class="register-container" scroll-y="true" show-scrollbar="false"> <!-- Language switch positioned absolutely -->
<view class="language-switch">
<button class="language-btn" @click="toggleLanguage">
{{ currentLocale === 'zh-CN' ? 'EN' : '中' }}
</button>
</view>
<view class="page">
<scroll-view class="scroll" scroll-y="true" show-scrollbar="false">
<view class="top-actions">
<button class="lang-btn" @click="toggleLanguage">
{{ currentLocale === 'zh-CN' ? 'EN' : '中' }}
</button>
</view>
<!-- Main content wrapper -->
<view class="content-wrapper">
<!-- Logo and title section -->
<view class="logo-section">
<text class="app-title">Akmon</text>
<text class="page-title">{{ $t('user.register.title') }}</text>
<text class="page-subtitle">{{ $t('user.register.subtitle') }}</text>
</view>
<view class="hero">
<view class="brand-row">
<view class="brand-mark"></view>
<view class="brand-text">
<text class="brand-name">Mall</text>
<text class="brand-slogan">注册后默认成为消费者账号</text>
</view>
</view>
<view class="title-block">
<text class="page-title">{{ $t('user.register.title') }}</text>
<text class="page-subtitle">{{ $t('user.register.subtitle') }}</text>
</view>
</view>
<!-- Form container with all content inside -->
<view class="form-container">
<form @submit="onSubmit">
<!-- Email input -->
<view class="input-group" :class="{ 'input-error': emailError }">
<text class="input-label">{{ $t('user.register.email') }}</text>
<input
class="input-field"
name="email"
type="text"
v-model="email"
:placeholder="$t('user.register.email_placeholder')"
@blur="validateEmail"
/>
<text v-if="emailError" class="error-text">{{ emailError }}</text>
</view>
<view class="card">
<form @submit="onSubmit">
<view class="field" :class="{ 'field-error': emailError }">
<text class="label">{{ $t('user.register.email') }}</text>
<view class="input-wrap">
<input class="input" name="email" type="text" v-model="email" :placeholder="$t('user.register.email_placeholder')" @blur="validateEmail" />
</view>
<text v-if="emailError" class="support error">{{ emailError }}</text>
</view>
<!-- Password input -->
<view class="input-group" :class="{ 'input-error': passwordError }">
<text class="input-label">{{ $t('user.register.password') }}</text>
<view class="password-input-container">
<input
class="input-field"
name="password"
:type="showPassword ? 'text' : 'password'"
v-model="password"
:placeholder="$t('user.register.password_placeholder')"
@blur="validatePassword" /> <view class="password-toggle" @click="togglePasswordVisibility">
<text class="toggle-icon">{{ showPassword ? '👁' : '🙈' }}</text>
</view>
</view>
<text v-if="passwordError" class="error-text">{{ passwordError }}</text>
</view>
<view class="field" :class="{ 'field-error': passwordError }">
<text class="label">{{ $t('user.register.password') }}</text>
<view class="input-wrap">
<input class="input" name="password" :type="showPassword ? 'text' : 'password'" v-model="password" :placeholder="$t('user.register.password_placeholder')" @blur="validatePassword" />
<view class="suffix" @click="togglePasswordVisibility">
<text class="suffix-text">{{ showPassword ? '隐藏' : '显示' }}</text>
</view>
</view>
<text v-if="passwordError" class="support error">{{ passwordError }}</text>
</view>
<!-- Confirm Password input -->
<view class="input-group" :class="{ 'input-error': confirmPasswordError }">
<text class="input-label">{{ $t('user.register.confirm_password') }}</text>
<view class="password-input-container">
<input
class="input-field"
name="confirmPassword"
:type="showConfirmPassword ? 'text' : 'password'"
v-model="confirmPassword"
:placeholder="$t('user.register.confirm_password_placeholder')"
@blur="validateConfirmPassword" /> <view class="password-toggle" @click="toggleConfirmPasswordVisibility">
<text class="toggle-icon">{{ showConfirmPassword ? '👁' : '🙈' }}</text>
</view>
</view>
<text v-if="confirmPasswordError" class="error-text">{{ confirmPasswordError }}</text>
</view>
<view class="field" :class="{ 'field-error': confirmPasswordError }">
<text class="label">{{ $t('user.register.confirm_password') }}</text>
<view class="input-wrap">
<input class="input" name="confirmPassword" :type="showConfirmPassword ? 'text' : 'password'" v-model="confirmPassword" :placeholder="$t('user.register.confirm_password_placeholder')" @blur="validateConfirmPassword" />
<view class="suffix" @click="toggleConfirmPasswordVisibility">
<text class="suffix-text">{{ showConfirmPassword ? '隐藏' : '显示' }}</text>
</view>
</view>
<text v-if="confirmPasswordError" class="support error">{{ confirmPasswordError }}</text>
</view>
<!-- Username input (optional) -->
<view class="input-group" :class="{ 'input-error': usernameError }">
<text class="input-label">{{ $t('user.register.username') }}</text>
<input
class="input-field"
name="username"
type="text"
v-model="username"
:placeholder="$t('user.register.username_placeholder')"
@blur="validateUsername"
/>
<text v-if="usernameError" class="error-text">{{ usernameError }}</text>
</view>
<view class="field" :class="{ 'field-error': usernameError }">
<text class="label">{{ $t('user.register.username') }}</text>
<view class="input-wrap">
<input class="input" name="username" type="text" v-model="username" :placeholder="$t('user.register.username_placeholder')" @blur="validateUsername" />
</view>
<text v-if="usernameError" class="support error">{{ usernameError }}</text>
</view>
<!-- Terms and conditions -->
<view class="checkbox-container" :class="{ 'input-error': termsError }">
<checkbox :checked="agreeTerms" @click="agreeTerms = !agreeTerms" color="#2196f3" />
<view class="terms-text">
<text>{{ $t('user.register.agree_terms_part1') }} </text>
<text class="terms-link" @click="showTerms">{{ $t('user.register.terms_link') }}</text>
<text>{{ $t('user.register.agree_terms_part2') }}</text>
</view>
</view>
<text v-if="termsError" class="error-text terms-error">{{ termsError }}</text>
<view class="terms" :class="{ 'field-error': termsError }">
<view class="terms-row" @click="agreeTerms = !agreeTerms">
<checkbox :checked="agreeTerms" color="#FF4D4F" />
<view class="terms-text">
<text>{{ $t('user.register.agree_terms_part1') }} </text>
<text class="terms-link" @click="showTerms">{{ $t('user.register.terms_link') }}</text>
<text>{{ $t('user.register.agree_terms_part2') }}</text>
</view>
</view>
<text v-if="termsError" class="support error">{{ termsError }}</text>
</view>
<!-- Register button -->
<button form-type="submit" class="register-button" :disabled="isLoading" :loading="isLoading">
{{ $t('user.register.button') }}
</button>
<button form-type="submit" class="primary" :disabled="isLoading" :loading="isLoading">
{{ $t('user.register.button') }}
</button>
<!-- General error message -->
<text v-if="generalError" class="general-error">{{ generalError }}</text>
</form>
<text v-if="generalError" class="support error center">{{ generalError }}</text>
</form>
<!-- Login option -->
<view class="login-option">
<text class="login-text">{{ $t('user.register.already_account') }}</text>
<text class="login-link" @click="navigateToLogin">{{ $t('user.register.login') }}</text>
</view>
</view>
</view>
</scroll-view>
<view class="footer">
<text class="footer-text">{{ $t('user.register.already_account') }}</text>
<text class="footer-link" @click="navigateToLogin">{{ $t('user.register.login') }}</text>
</view>
</view>
<view class="trust">
<text class="trust-text">注册即代表你同意用户协议与隐私政策</text>
</view>
</scroll-view>
</view>
</template>
<script lang="uts">
@@ -298,337 +280,227 @@ export default {
</script>
<style>
/* Single scrollable container for tablet optimization */
.register-container {
width: 100%; /* #ifdef APP-PLUS */
padding: 20rpx;
/* #endif */
/* #ifndef APP-PLUS */
padding: 40rpx;
/* #endif */
background-color: #f8f9fa;
box-sizing: border-box;
}
.page {
min-height: 100vh;
background: #f7f8fa;
}
/* Content wrapper for centered layout */
.content-wrapper {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
padding-bottom: 40rpx;
/* 确保内容足够高以触发滚动 */
/* #ifdef APP-PLUS */
min-height: 1000rpx;
/* #endif */
/* #ifndef APP-PLUS */
min-height: 1200rpx;
/* #endif */
}
.scroll {
min-height: 100vh;
background: radial-gradient(900rpx 700rpx at 20% 10%, rgba(255, 77, 79, 0.16), rgba(255, 77, 79, 0) 60%),
linear-gradient(180deg, #ffffff 0%, #f7f8fa 45%, #f7f8fa 100%);
}
/* Language switch button - positioned absolutely */
.language-switch {
position: absolute;
/* #ifdef APP*/
top: 30rpx;
right: 50rpx;
/* #endif */
/* #ifndef APP-PLUS */
top: 40rpx;
right: 40rpx;
/* #endif */
z-index: 10;
}
.top-actions {
position: relative;
padding: 24rpx 24rpx 0;
display: flex;
justify-content: flex-end;
}
.language-btn {
/* #ifdef APP-PLUS */
width: 50rpx;
height: 50rpx;
border-radius: 25rpx;
font-size: 18rpx;
/* #endif */
/* #ifndef APP-PLUS */
width: 80rpx;
height: 80rpx;
border-radius: 40rpx;
font-size: 28rpx;
/* #endif */ background-color: rgba(33, 150, 243, 0.8);
color: #fff;
font-weight: normal;
border: 2rpx solid rgba(255, 255, 255, 0.3);
text-align: center;
box-shadow: 0 4rpx 12rpx rgba(33, 150, 243, 0.3);
}
.lang-btn {
width: 76rpx;
height: 76rpx;
border-radius: 38rpx;
background: rgba(255, 255, 255, 0.9);
border: 1rpx solid rgba(0, 0, 0, 0.06);
color: #111;
font-size: 26rpx;
line-height: 76rpx;
text-align: center;
box-shadow: 0 10rpx 24rpx rgba(0, 0, 0, 0.06);
}
/* Logo and title section */
.logo-section {
display: flex;
flex-direction: column;
align-items: center;
/* #ifdef APP-PLUS */
margin-top: 60rpx;
margin-bottom: 25rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin-top: 80rpx;
margin-bottom: 40rpx;
/* #endif */
}
.hero {
padding: 26rpx 24rpx 14rpx;
}
.app-title {
/* #ifdef APP-PLUS */
font-size: 28rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 36rpx;
/* #endif */
font-weight: bold;
color: #2196f3;
}
.brand-row {
display: flex;
align-items: center;
}
.page-title {
/* #ifdef APP-PLUS */
font-size: 32rpx;
margin-top: 12rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 48rpx;
margin-top: 20rpx;
/* #endif */
font-weight: bold;
color: #333;
}
.brand-mark {
width: 72rpx;
height: 72rpx;
border-radius: 20rpx;
background: linear-gradient(135deg, #ff4d4f 0%, #ff8a65 100%);
box-shadow: 0 12rpx 26rpx rgba(255, 77, 79, 0.28);
}
.page-subtitle {
/* #ifdef APP-PLUS */
font-size: 18rpx;
margin-top: 6rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 28rpx;
margin-top: 10rpx;
/* #endif */
color: #666;
}
.brand-text {
margin-left: 18rpx;
display: flex;
flex-direction: column;
}
/* Form container */
.form-container {
width: 100%;
/* #ifdef APP-PLUS */
max-width: 500rpx;
padding: 25rpx;
/* #endif */
/* #ifndef APP-PLUS */
max-width: 680rpx;
padding: 40rpx;
/* #endif */
background-color: #ffffff;
border-radius: 20rpx;
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
box-sizing: border-box;
}
.brand-name {
font-size: 40rpx;
font-weight: 700;
color: #111;
letter-spacing: 1rpx;
}
/* Input groups */
.input-group {
/* #ifdef APP-PLUS */
margin-bottom: 15rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin-bottom: 30rpx;
/* #endif */
}
.brand-slogan {
margin-top: 6rpx;
font-size: 24rpx;
color: rgba(0, 0, 0, 0.55);
}
.input-label {
/* #ifdef APP-PLUS */
font-size: 20rpx;
margin-bottom: 6rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 28rpx;
margin-bottom: 10rpx;
/* #endif */
font-weight: 400;
color: #333;
display: block;
}
.title-block {
margin-top: 26rpx;
}
.input-field {
width: 100%;
/* #ifdef APP-PLUS */
height: 60rpx;
padding: 0 20rpx;
font-size: 22rpx;
/* #endif */
/* #ifndef APP-PLUS */
height: 90rpx;
padding: 0 30rpx;
font-size: 28rpx;
/* #endif */
border-radius: 10rpx;
border: 2rpx solid #ddd;
background-color: #f9f9f9;
box-sizing: border-box;
}
.page-title {
font-size: 46rpx;
font-weight: 700;
color: #111;
}
.input-error .input-field {
border-color: #f44336;
}
.page-subtitle {
margin-top: 10rpx;
font-size: 26rpx;
color: rgba(0, 0, 0, 0.55);
}
.error-text {
/* #ifdef APP-PLUS */
font-size: 18rpx;
margin-top: 4rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 24rpx;
margin-top: 6rpx;
/* #endif */
color: #f44336;
}
.card {
margin: 18rpx 24rpx 0;
padding: 26rpx 22rpx;
background: rgba(255, 255, 255, 0.96);
border-radius: 20rpx;
border: 1rpx solid rgba(0, 0, 0, 0.06);
box-shadow: 0 16rpx 36rpx rgba(0, 0, 0, 0.06);
}
/* Password input */
.password-input-container {
position: relative;
}
.field {
margin-bottom: 18rpx;
}
.password-toggle {
position: absolute;
/* #ifdef APP-PLUS */
right: 12rpx;
top: 17rpx;
/* #endif */
/* #ifndef APP-PLUS */
right: 20rpx;
top: 25rpx;
/* #endif */
z-index: 1;
}
.label {
font-size: 24rpx;
color: rgba(0, 0, 0, 0.78);
margin-bottom: 10rpx;
display: block;
}
.toggle-icon {
/* #ifdef APP-PLUS */
font-size: 20rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 30rpx;
/* #endif */
color: #666;
}
.input-wrap {
position: relative;
display: flex;
align-items: center;
background: #f6f7f9;
border: 2rpx solid rgba(0, 0, 0, 0.06);
border-radius: 14rpx;
padding: 0 14rpx;
}
/* Checkbox for terms */
.checkbox-container {
display: flex;
flex-direction: row;
/* #ifdef APP-PLUS */
margin-bottom: 6rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin-bottom: 10rpx;
/* #endif */
}
.field-error .input-wrap {
border-color: rgba(255, 77, 79, 0.55);
background: rgba(255, 77, 79, 0.06);
}
.terms-text {
/* #ifdef APP-PLUS */
font-size: 18rpx;
margin-left: 6rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 26rpx;
margin-left: 10rpx;
/* #endif */
color: #666;
flex: 1;
flex-direction: row;
flex-wrap: wrap;
}
.input {
flex: 1;
height: 84rpx;
font-size: 28rpx;
color: #111;
padding: 0 6rpx;
}
.terms-link {
color: #2196f3;
}
.suffix {
height: 84rpx;
padding: 0 10rpx;
display: flex;
align-items: center;
justify-content: center;
}
.terms-error {
/* #ifdef APP-PLUS */
margin-bottom: 12rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin-bottom: 20rpx;
/* #endif */
}
.suffix-text {
font-size: 24rpx;
color: rgba(0, 0, 0, 0.55);
}
/* Register button */
.register-button {
width: 100%;
/* #ifdef APP-PLUS */
height: 60rpx;
font-size: 24rpx;
margin: 12rpx 0;
border-radius: 30rpx;
/* #endif */
/* #ifndef APP-PLUS */
height: 90rpx;
font-size: 32rpx;
margin: 20rpx 0; border-radius: 45rpx;
/* #endif */
background-image: linear-gradient(to right, #2196f3, #03a9f4);
color: #fff;
font-weight: normal;
text-align: center;
box-shadow: 0 10rpx 20rpx rgba(3, 169, 244, 0.2);
}
.support {
margin-top: 10rpx;
font-size: 22rpx;
color: rgba(0, 0, 0, 0.52);
}
.register-button[disabled] {
background: #ccc;
box-shadow: none;
}
.error {
color: #ff4d4f;
}
/* General error */
.general-error {
width: 100%;
text-align: center;
color: #f44336;
/* #ifdef APP-PLUS */
font-size: 20rpx;
margin-top: 12rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 28rpx;
margin-top: 20rpx;
/* #endif */
}
.center {
text-align: center;
width: 100%;
display: block;
}
/* Login option */
.login-option {
display: flex;
flex-direction: row;
justify-content: center;
/* #ifdef APP-PLUS */
margin-top: 25rpx;
/* #endif */
/* #ifndef APP-PLUS */
margin-top: 40rpx;
/* #endif */
}
.terms {
margin: 12rpx 0 18rpx;
}
.login-text {
/* #ifdef APP-PLUS */
font-size: 20rpx;
margin-right: 5rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 28rpx;
margin-right: 8rpx;
/* #endif */
color: #666;
}
.terms-row {
display: flex;
align-items: flex-start;
}
.login-link {
/* #ifdef APP-PLUS */
font-size: 20rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: 28rpx;
/* #endif */
color: #2196f3;
font-weight: normal;
}
.terms-text {
margin-left: 10rpx;
font-size: 24rpx;
color: rgba(0, 0, 0, 0.55);
flex: 1;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.terms-link {
color: #ff4d4f;
font-weight: 600;
}
.primary {
width: 100%;
height: 92rpx;
border-radius: 18rpx;
background: linear-gradient(135deg, #ff4d4f 0%, #ff7a45 100%);
color: #fff;
font-size: 30rpx;
font-weight: 600;
box-shadow: 0 16rpx 32rpx rgba(255, 77, 79, 0.24);
}
.primary:disabled {
background: #d9d9d9;
box-shadow: none;
}
.footer {
margin-top: 22rpx;
display: flex;
align-items: center;
justify-content: center;
}
.footer-text {
font-size: 24rpx;
color: rgba(0, 0, 0, 0.55);
}
.footer-link {
margin-left: 8rpx;
font-size: 24rpx;
color: #ff4d4f;
font-weight: 600;
}
.trust {
padding: 18rpx 24rpx 36rpx;
}
.trust-text {
font-size: 22rpx;
color: rgba(0, 0, 0, 0.4);
text-align: center;
}
</style>

131
pages/user/terms.uvue Normal file
View File

@@ -0,0 +1,131 @@
<template>
<view class="page">
<view class="topbar">
<text class="back" @click="goBack">返回</text>
<text class="title">用户协议与隐私政策</text>
<text class="ghost"> </text>
</view>
<scroll-view class="content" scroll-y="true" show-scrollbar="false">
<view class="card">
<text class="h1">用户协议</text>
<text class="p">1. 本应用为商城系统示例/项目使用。
</text>
<text class="p">2. 你在使用本应用服务时,应遵守法律法规与平台规则。
</text>
<text class="p">3. 账号与密码由你自行保管,因泄露造成的损失由你自行承担。
</text>
<view class="divider"></view>
<text class="h1">隐私政策</text>
<text class="p">1. 我们可能会收集你提供的邮箱等信息,用于账号注册与登录。
</text>
<text class="p">2. 我们会采取合理的安全措施保护你的信息安全。
</text>
<text class="p">3. 你可以在账号相关页面申请修改或删除个人信息(以实际功能为准)。
</text>
</view>
<view class="footer">
<button class="primary" @click="goBack">我已阅读并同意</button>
</view>
</scroll-view>
</view>
</template>
<script lang="uts">
export default {
methods: {
goBack() {
uni.navigateBack();
}
}
};
</script>
<style>
.page {
min-height: 100vh;
background: #f7f8fa;
display: flex;
flex-direction: column;
}
.topbar {
height: 96rpx;
padding: 0 24rpx;
background: rgba(255, 255, 255, 0.96);
border-bottom: 1rpx solid rgba(0, 0, 0, 0.06);
display: flex;
align-items: center;
justify-content: space-between;
}
.back {
font-size: 26rpx;
color: #ff4d4f;
width: 120rpx;
}
.title {
font-size: 30rpx;
font-weight: 700;
color: #111;
}
.ghost {
width: 120rpx;
}
.content {
flex: 1;
padding: 18rpx 24rpx 24rpx;
box-sizing: border-box;
}
.card {
background: rgba(255, 255, 255, 0.96);
border: 1rpx solid rgba(0, 0, 0, 0.06);
border-radius: 20rpx;
padding: 24rpx 22rpx;
box-shadow: 0 16rpx 36rpx rgba(0, 0, 0, 0.06);
}
.h1 {
font-size: 32rpx;
font-weight: 700;
color: #111;
margin-bottom: 12rpx;
display: block;
}
.p {
font-size: 26rpx;
color: rgba(0, 0, 0, 0.65);
line-height: 44rpx;
margin-bottom: 12rpx;
display: block;
}
.divider {
height: 1rpx;
background: rgba(0, 0, 0, 0.08);
margin: 18rpx 0;
}
.footer {
margin-top: 18rpx;
}
.primary {
width: 100%;
height: 92rpx;
border-radius: 18rpx;
background: linear-gradient(135deg, #ff4d4f 0%, #ff7a45 100%);
color: #fff;
font-size: 30rpx;
font-weight: 600;
box-shadow: 0 16rpx 32rpx rgba(255, 77, 79, 0.24);
}
</style>

7
platformConfig.json Normal file
View File

@@ -0,0 +1,7 @@
// 参考链接 https://doc.dcloud.net.cn/uni-app-x/tutorial/ls-plugin.html#setting
{
"targets": [
"APP-ANDROID"
]
}

View File

@@ -0,0 +1,67 @@
# i18n 国际化模块
这是一个简化的 i18n 国际化模块,用于支持多语言切换。
## 功能特性
- 支持多语言切换
- 兼容 Vue I18n 的 API
- 支持在 Vue 组件中使用 `$t` 方法
- 支持通过 `tt` 工具函数进行翻译
## 使用方法
### 在 Vue 组件中使用
```vue
<template>
<view>
<text>{{ $t('user.login.title') }}</text>
</view>
</template>
```
### 在脚本中使用
```typescript
import i18n from '@/uni_modules/i18n/index.uts'
import { tt } from '@/utils/i18nfun.uts'
// 方式1直接使用 i18n
const text = i18n.global.t('user.login.title')
// 方式2使用工具函数
const text2 = tt('user.login.title')
```
### 切换语言
```typescript
import { switchLocale, getCurrentLocale } from '@/utils/utils.uts'
// 切换语言
switchLocale('en-US')
// 获取当前语言
const current = getCurrentLocale()
```
## 配置
默认语言为 `zh-CN`,可以在 `index.uts` 中修改 `defaultLocale` 常量。
## 注意事项
当前实现是简化版本,`t` 函数直接返回 key。实际项目中需要
1. 加载语言资源文件
2. 实现真正的翻译逻辑
3. 支持参数插值
## 文件结构
```
uni_modules/i18n/
├── index.uts # 主模块文件
├── package.json # 模块配置
└── README.md # 说明文档
```

View File

@@ -0,0 +1,39 @@
// i18n 国际化配置
// 这是一个简化的 i18n 实现,用于支持多语言切换
// 语言资源
const messages: UTSJSONObject = new UTSJSONObject()
// 默认语言
const defaultLocale = 'zh-CN'
// 当前语言(响应式)
let currentLocale = defaultLocale
// 翻译函数
function t(key: string, values: UTSJSONObject | null = null, locale: string | null = null): string {
const targetLocale = locale ?? currentLocale
// 这里应该从 messages 中获取翻译,简化实现直接返回 key
// 实际项目中应该加载语言资源文件
return key
}
// 创建响应式 locale 对象
const localeObj = {
get value(): string {
return currentLocale
},
set value(newLocale: string) {
currentLocale = newLocale
}
}
// 导出 i18n 对象(兼容 Vue I18n 的 API
const i18nInstance = {
global: {
t: t,
locale: localeObj
}
}
export default i18nInstance

View File

@@ -0,0 +1,9 @@
{
"name": "i18n",
"version": "1.0.0",
"main": "index.uts",
"types": "index.uts",
"uni_modules": {
"uni_modules": true
}
}

View File

@@ -1,4 +1,4 @@
import i18n from '@/i18n/index.uts'
import i18n from '@/uni_modules/i18n/index.uts'
// 包装一个带参数智能判断的 t 函数,支持缺省值
export function tt(key: string, values: any | null = null, locale: string | null = null): string {

88
utils/sapi.uts Normal file
View File

@@ -0,0 +1,88 @@
import supa, { supaReady } from '@/components/supadb/aksupainstance.uts'
import type { UserProfile } from '@/pages/user/types.uts'
/**
* 确保用户资料存在,如果不存在则创建基础资料
* @param sessionUser 会话用户对象 (UTSJSONObject)
* @returns 创建的用户资料,如果创建失败则返回 null
*/
export async function ensureUserProfile(sessionUser: UTSJSONObject): Promise<UserProfile | null> {
try {
await supaReady
// 从 sessionUser 中获取用户ID和邮箱
const userId = sessionUser.getString('id')
const email = sessionUser.getString('email') ?? ''
if (userId == null || userId === '') {
console.error('无法获取用户ID')
return null
}
// 检查用户是否已存在
const checkRes = await supa.from('ak_users')
.select('*', {})
.eq('id', userId)
.single()
.execute()
if (checkRes.status >= 200 && checkRes.status < 300 && checkRes.data != null) {
// 用户已存在,返回现有资料
const existingUser = checkRes.data as UTSJSONObject
return {
id: existingUser.getString('id'),
username: existingUser.getString('username') ?? '',
email: existingUser.getString('email') ?? email,
gender: existingUser.getString('gender'),
birthday: existingUser.getString('birthday'),
height_cm: existingUser.getNumber('height_cm'),
weight_kg: existingUser.getNumber('weight_kg'),
bio: existingUser.getString('bio'),
avatar_url: existingUser.getString('avatar_url'),
preferred_language: existingUser.getString('preferred_language'),
role: existingUser.getString('role'),
school_id: existingUser.getString('school_id'),
grade_id: existingUser.getString('grade_id'),
class_id: existingUser.getString('class_id')
} as UserProfile
}
// 用户不存在,创建新用户资料
const newUserData = new UTSJSONObject()
newUserData.set('id', userId)
newUserData.set('email', email)
newUserData.set('username', email.split('@')[0] ?? 'user') // 默认用户名为邮箱前缀
const insertRes = await supa.from('ak_users')
.insert(newUserData)
.select('*', {})
.single()
.execute()
if (insertRes.status >= 200 && insertRes.status < 300 && insertRes.data != null) {
const newUser = insertRes.data as UTSJSONObject
return {
id: newUser.getString('id'),
username: newUser.getString('username') ?? '',
email: newUser.getString('email') ?? email,
gender: newUser.getString('gender'),
birthday: newUser.getString('birthday'),
height_cm: newUser.getNumber('height_cm'),
weight_kg: newUser.getNumber('weight_kg'),
bio: newUser.getString('bio'),
avatar_url: newUser.getString('avatar_url'),
preferred_language: newUser.getString('preferred_language'),
role: newUser.getString('role'),
school_id: newUser.getString('school_id'),
grade_id: newUser.getString('grade_id'),
class_id: newUser.getString('class_id')
} as UserProfile
} else {
console.error('创建用户资料失败:', insertRes.status)
return null
}
} catch (error) {
console.error('ensureUserProfile 异常:', error)
return null
}
}

View File

@@ -1,7 +1,7 @@
// 通用 UTSJSONObject 转任意 type 的函数
// UTS 2024
import i18n from '../i18n/index.uts';
import i18n from '@/uni_modules/i18n/index.uts';
/**
* 切换应用语言设置
@@ -13,7 +13,9 @@ export function switchLocale(locale: string) {
// 设置 i18n 语言
try {
i18n.global.locale.value = locale;
if (i18n != null && i18n.global != null) {
i18n.global.locale.value = locale;
}
} catch (err) {
console.error('Failed to switch locale:', err);
}