up
This commit is contained in:
@@ -1,52 +1,308 @@
|
||||
<template>
|
||||
<view class="content">
|
||||
<image class="logo" src="/static/logo.png"></image>
|
||||
<view class="text-area">
|
||||
<text class="title">{{title}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="index-container">
|
||||
<!-- 顶部标题 -->
|
||||
<view class="header">
|
||||
<text class="title">{{ t('index.welcome') }}</text>
|
||||
<text class="subtitle">{{ t('index.subtitle') }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 订单统计卡片 -->
|
||||
<view class="stats-grid">
|
||||
<view class="stat-card" @click="goToOrders('pending')">
|
||||
<text class="stat-num">{{ stats.pending }}</text>
|
||||
<text class="stat-label">{{ t('index.pending') }}</text>
|
||||
</view>
|
||||
<view class="stat-card" @click="goToOrders('ordered')">
|
||||
<text class="stat-num">{{ stats.ordered }}</text>
|
||||
<text class="stat-label">{{ t('index.ordered') }}</text>
|
||||
</view>
|
||||
<view class="stat-card" @click="goToOrders('arrived')">
|
||||
<text class="stat-num">{{ stats.arrived }}</text>
|
||||
<text class="stat-label">{{ t('index.arrived') }}</text>
|
||||
</view>
|
||||
<view class="stat-card" @click="goToOrders('received')">
|
||||
<text class="stat-num">{{ stats.received }}</text>
|
||||
<text class="stat-label">{{ t('index.received') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 快捷操作 -->
|
||||
<view class="section">
|
||||
<text class="section-title">{{ t('index.quickActions') }}</text>
|
||||
<view class="action-list">
|
||||
<view class="action-item" @click="goToOrders('all')">
|
||||
<text class="action-icon">📋</text>
|
||||
<text class="action-text">{{ t('index.allOrders') }}</text>
|
||||
<text class="action-arrow">→</text>
|
||||
</view>
|
||||
<view class="action-item" @click="goToAddOrder">
|
||||
<text class="action-icon">➕</text>
|
||||
<text class="action-text">{{ t('index.addOrder') }}</text>
|
||||
<text class="action-arrow">→</text>
|
||||
</view>
|
||||
<view class="action-item" @click="goToSchedule">
|
||||
<text class="action-icon">📅</text>
|
||||
<text class="action-text">{{ t('index.schedule') }}</text>
|
||||
<text class="action-arrow">→</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 语言切换入口 -->
|
||||
<view class="section">
|
||||
<view class="lang-card" @click="switchLang">
|
||||
<text class="lang-icon">🌐</text>
|
||||
<view class="lang-info">
|
||||
<text class="lang-title">{{ t('index.language') }}</text>
|
||||
<text class="lang-value">{{ locale === 'zh' ? '中文' : 'English' }}</text>
|
||||
</view>
|
||||
<text class="action-arrow">→</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 退出登录 -->
|
||||
<view class="logout-section">
|
||||
<button class="logout-btn" @click="handleLogout">
|
||||
{{ t('index.logout') }}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
title: 'Hello'
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { setLocale, getCurrentLocale } from '../../locales/index.js'
|
||||
|
||||
},
|
||||
methods: {
|
||||
const { t, locale } = useI18n()
|
||||
|
||||
}
|
||||
}
|
||||
// 统计数据
|
||||
const stats = reactive({
|
||||
pending: 0,
|
||||
ordered: 0,
|
||||
arrived: 0,
|
||||
received: 0
|
||||
})
|
||||
|
||||
// 获取订单统计
|
||||
const fetchStats = () => {
|
||||
uni.request({
|
||||
url: getApp().globalData.BASE_URL + '/purchase/getordercount',
|
||||
method: 'POST',
|
||||
header: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cookie': uni.getStorageSync('sessionCookie') || ''
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
stats.pending = res.data.data.pending || 0
|
||||
stats.ordered = res.data.data.ordered || 0
|
||||
stats.arrived = res.data.data.arrived || 0
|
||||
stats.received = res.data.data.received || 0
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 跳转订单列表
|
||||
const goToOrders = (status) => {
|
||||
const url = status === 'all' ? '/pages/order/list' : `/pages/order/list?status=${status}`
|
||||
uni.navigateTo({ url })
|
||||
}
|
||||
|
||||
// 跳转新增订单
|
||||
const goToAddOrder = () => {
|
||||
uni.navigateTo({ url: '/pages/order/add' })
|
||||
}
|
||||
|
||||
// 跳转日程
|
||||
const goToSchedule = () => {
|
||||
uni.navigateTo({ url: '/pages/schedule/schedule' })
|
||||
}
|
||||
|
||||
// 切换语言
|
||||
const switchLang = () => {
|
||||
const newLang = locale.value === 'zh' ? 'en' : 'zh'
|
||||
setLocale(newLang)
|
||||
locale.value = newLang
|
||||
}
|
||||
|
||||
// 退出登录
|
||||
const handleLogout = () => {
|
||||
uni.showModal({
|
||||
title: t('index.logoutConfirm'),
|
||||
content: t('index.logoutMessage'),
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.removeStorageSync('sessionCookie')
|
||||
uni.removeStorageSync('userInfo')
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
locale.value = getCurrentLocale()
|
||||
fetchStats()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
<style lang="scss" scoped>
|
||||
.index-container {
|
||||
min-height: 100vh;
|
||||
background-color: #f5f5f5;
|
||||
padding: 20rpx 30rpx;
|
||||
padding-bottom: 140rpx;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 200rpx;
|
||||
width: 200rpx;
|
||||
margin-top: 200rpx;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
margin-bottom: 50rpx;
|
||||
}
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 24rpx;
|
||||
padding: 40rpx 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.text-area {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.title {
|
||||
display: block;
|
||||
font-size: 44rpx;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 36rpx;
|
||||
color: #8f8f94;
|
||||
}
|
||||
.subtitle {
|
||||
display: block;
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 20rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 24rpx 16rpx;
|
||||
text-align: center;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.stat-num {
|
||||
display: block;
|
||||
font-size: 40rpx;
|
||||
font-weight: 700;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
display: block;
|
||||
font-size: 22rpx;
|
||||
color: #999;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: block;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.action-list {
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.action-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 32rpx 30rpx;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
font-size: 40rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.action-text {
|
||||
flex: 1;
|
||||
font-size: 30rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.action-arrow {
|
||||
font-size: 28rpx;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.lang-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 32rpx 30rpx;
|
||||
}
|
||||
|
||||
.lang-icon {
|
||||
font-size: 40rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.lang-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.lang-title {
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.lang-value {
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
|
||||
.logout-section {
|
||||
margin-top: 40rpx;
|
||||
padding-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background-color: #fff;
|
||||
color: #e53935;
|
||||
font-size: 32rpx;
|
||||
border-radius: 44rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,394 @@
|
||||
<template>
|
||||
<view class="login-container">
|
||||
<!-- 语言切换 -->
|
||||
<view class="lang-switch">
|
||||
<text
|
||||
class="lang-btn"
|
||||
:class="{ active: locale === 'zh' }"
|
||||
@click="switchLang('zh')"
|
||||
>中文</text>
|
||||
<text class="lang-divider">|</text>
|
||||
<text
|
||||
class="lang-btn"
|
||||
:class="{ active: locale === 'en' }"
|
||||
@click="switchLang('en')"
|
||||
>EN</text>
|
||||
</view>
|
||||
|
||||
<!-- Logo 区域 -->
|
||||
<view class="logo-section">
|
||||
<image class="logo" src="/static/logo.png" mode="aspectFit"></image>
|
||||
<text class="app-name">OPS</text>
|
||||
<text class="app-desc">{{ t('login.title') }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 登录表单 -->
|
||||
<view class="form-section">
|
||||
<view class="input-group">
|
||||
<text class="input-label">{{ t('login.username') }}</text>
|
||||
<input
|
||||
class="input-field"
|
||||
type="text"
|
||||
v-model="form.username"
|
||||
:placeholder="t('login.usernamePlaceholder')"
|
||||
placeholder-class="placeholder"
|
||||
@confirm="handleLogin"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="input-group">
|
||||
<text class="input-label">{{ t('login.password') }}</text>
|
||||
<input
|
||||
class="input-field"
|
||||
:type="showPassword ? 'text' : 'password'"
|
||||
v-model="form.password"
|
||||
:placeholder="t('login.passwordPlaceholder')"
|
||||
placeholder-class="placeholder"
|
||||
@confirm="handleLogin"
|
||||
/>
|
||||
<view class="password-toggle" @click="showPassword = !showPassword">
|
||||
<text>{{ showPassword ? '👁️' : '👁️🗨️' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="remember-row">
|
||||
<checkbox-group @change="onRememberChange">
|
||||
<label class="remember-label">
|
||||
<checkbox value="1" :checked="form.remember" color="#007AFF" />
|
||||
<text>{{ t('login.rememberMe') }}</text>
|
||||
</label>
|
||||
</checkbox-group>
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="login-btn"
|
||||
:loading="loading"
|
||||
:disabled="loading"
|
||||
@click="handleLogin"
|
||||
>
|
||||
{{ loading ? t('login.logging') : t('login.loginBtn') }}
|
||||
</button>
|
||||
|
||||
<view class="error-tip" v-if="errorMsg">
|
||||
<text>{{ errorMsg }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 底部信息 -->
|
||||
<view class="footer-section">
|
||||
<text class="footer-text">{{ t('login.registerLink') }}</text>
|
||||
<navigator url="/pages/register/register" class="link">{{ t('register.title') }}</navigator>
|
||||
</view>
|
||||
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted, onUnmounted, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { setLocale, getCurrentLocale } from '../../locales/index.js'
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
|
||||
// 响应式数据
|
||||
const form = reactive({
|
||||
username: '',
|
||||
password: '',
|
||||
remember: false
|
||||
})
|
||||
|
||||
const showPassword = ref(false)
|
||||
const loading = ref(false)
|
||||
const errorMsg = ref('')
|
||||
|
||||
// 切换语言
|
||||
const switchLang = (lang) => {
|
||||
setLocale(lang)
|
||||
locale.value = lang
|
||||
}
|
||||
|
||||
// 记住密码勾选
|
||||
const onRememberChange = (e) => {
|
||||
form.remember = e.detail.value.length > 0
|
||||
}
|
||||
|
||||
// 表单验证
|
||||
const validate = () => {
|
||||
if (!form.username.trim()) {
|
||||
errorMsg.value = t('login.usernameRequired')
|
||||
return false
|
||||
}
|
||||
if (!form.password) {
|
||||
errorMsg.value = t('login.passwordRequired')
|
||||
return false
|
||||
}
|
||||
errorMsg.value = ''
|
||||
return true
|
||||
}
|
||||
|
||||
// 登录处理
|
||||
const handleLogin = () => {
|
||||
if (!validate()) return
|
||||
|
||||
loading.value = true
|
||||
errorMsg.value = ''
|
||||
|
||||
uni.request({
|
||||
url: getApp().globalData.BASE_URL + '/users/login',
|
||||
method: 'POST',
|
||||
data: {
|
||||
username: form.username,
|
||||
password: form.password,
|
||||
remember: form.remember
|
||||
},
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.data.code === 0 && res.data.data && res.data.data.cookie) {
|
||||
// 登录成功
|
||||
const cookie = res.data.data.cookie
|
||||
|
||||
// 保存 cookie 到本地
|
||||
uni.setStorageSync('sessionCookie', cookie.Value)
|
||||
uni.setStorageSync('userInfo', res.data.data)
|
||||
|
||||
// 处理记住密码
|
||||
if (form.remember) {
|
||||
uni.setStorageSync('savedUsername', form.username)
|
||||
uni.setStorageSync('savedRemember', true)
|
||||
} else {
|
||||
uni.removeStorageSync('savedUsername')
|
||||
uni.removeStorageSync('savedRemember')
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: t('login.loginSuccess'),
|
||||
icon: 'success',
|
||||
duration: 1500
|
||||
})
|
||||
|
||||
// 跳转到首页
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}, 1500)
|
||||
} else {
|
||||
// 登录失败
|
||||
const msgMap = {
|
||||
userNameNoFund: t('login.usernameNotFound'),
|
||||
userPassIncorrect: t('login.passwordIncorrect'),
|
||||
jsonErr: t('login.paramError'),
|
||||
postErr: t('login.requestFailed')
|
||||
}
|
||||
errorMsg.value = msgMap[res.data.code] || t('login.loginFailed')
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
errorMsg.value = t('login.networkError')
|
||||
console.error('Login error:', err)
|
||||
},
|
||||
complete: () => {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
// 同步当前语言
|
||||
locale.value = getCurrentLocale()
|
||||
|
||||
// 从本地存储读取记住的登录状态
|
||||
const savedUsername = uni.getStorageSync('savedUsername')
|
||||
const savedRemember = uni.getStorageSync('savedRemember')
|
||||
if (savedUsername && savedRemember) {
|
||||
form.username = savedUsername
|
||||
form.remember = true
|
||||
}
|
||||
|
||||
// 监听语言切换
|
||||
uni.$on('localeChanged', (lang) => {
|
||||
locale.value = lang
|
||||
})
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
uni.$off('localeChanged')
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.login-container {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 80rpx 60rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.lang-switch {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.lang-btn {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
padding: 8rpx 16rpx;
|
||||
|
||||
&.active {
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.lang-divider {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
margin: 0 8rpx;
|
||||
}
|
||||
|
||||
.logo-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-bottom: 80rpx;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
border-radius: 32rpx;
|
||||
background-color: #fff;
|
||||
box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.app-name {
|
||||
font-size: 56rpx;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
margin-top: 24rpx;
|
||||
letter-spacing: 4rpx;
|
||||
}
|
||||
|
||||
.app-desc {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.form-section {
|
||||
background-color: #fff;
|
||||
border-radius: 24rpx;
|
||||
padding: 48rpx 40rpx;
|
||||
box-shadow: 0 16rpx 48rpx rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 32rpx;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.input-label {
|
||||
display: block;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 16rpx;
|
||||
padding: 0 32rpx;
|
||||
font-size: 30rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.password-toggle {
|
||||
position: absolute;
|
||||
right: 24rpx;
|
||||
bottom: 24rpx;
|
||||
font-size: 36rpx;
|
||||
}
|
||||
|
||||
.remember-row {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.remember-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
height: 96rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
border-radius: 48rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
&:active {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
&[disabled] {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
.error-tip {
|
||||
margin-top: 24rpx;
|
||||
padding: 20rpx;
|
||||
background-color: #fff5f5;
|
||||
border-radius: 12rpx;
|
||||
text-align: center;
|
||||
|
||||
text {
|
||||
color: #e53935;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.footer-section {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: flex-end;
|
||||
padding-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.footer-text {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.link {
|
||||
font-size: 28rpx;
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,343 @@
|
||||
<template>
|
||||
<view class="register-container">
|
||||
<!-- 语言切换 -->
|
||||
<view class="lang-switch">
|
||||
<text
|
||||
class="lang-btn"
|
||||
:class="{ active: locale === 'zh' }"
|
||||
@click="switchLang('zh')"
|
||||
>中文</text>
|
||||
<text class="lang-divider">|</text>
|
||||
<text
|
||||
class="lang-btn"
|
||||
:class="{ active: locale === 'en' }"
|
||||
@click="switchLang('en')"
|
||||
>EN</text>
|
||||
</view>
|
||||
|
||||
<!-- 返回按钮 -->
|
||||
<view class="back-btn" @click="goBack">
|
||||
<text>← {{ t('common.back') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="form-section">
|
||||
<text class="title">{{ t('register.title') }}</text>
|
||||
|
||||
<view class="input-group">
|
||||
<text class="input-label">{{ t('register.username') }}</text>
|
||||
<input
|
||||
class="input-field"
|
||||
type="text"
|
||||
v-model="form.username"
|
||||
:placeholder="t('register.usernamePlaceholder')"
|
||||
placeholder-class="placeholder"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="input-group">
|
||||
<text class="input-label">{{ t('register.email') }}</text>
|
||||
<input
|
||||
class="input-field"
|
||||
type="email"
|
||||
v-model="form.email"
|
||||
:placeholder="t('register.emailPlaceholder')"
|
||||
placeholder-class="placeholder"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="input-group">
|
||||
<text class="input-label">{{ t('register.password') }}</text>
|
||||
<input
|
||||
class="input-field"
|
||||
:type="showPassword ? 'text' : 'password'"
|
||||
v-model="form.password"
|
||||
:placeholder="t('register.passwordPlaceholder')"
|
||||
placeholder-class="placeholder"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="input-group">
|
||||
<text class="input-label">{{ t('register.confirmPassword') }}</text>
|
||||
<input
|
||||
class="input-field"
|
||||
:type="showPassword ? 'text' : 'password'"
|
||||
v-model="form.confirmPassword"
|
||||
:placeholder="t('register.confirmPlaceholder')"
|
||||
placeholder-class="placeholder"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="password-toggle" @click="showPassword = !showPassword">
|
||||
<text>{{ showPassword ? '👁️ ' : '👁️🗨️ ' }}{{ showPassword ? t('register.showPassword') : t('register.hidePassword') }}</text>
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="register-btn"
|
||||
:loading="loading"
|
||||
:disabled="loading"
|
||||
@click="handleRegister"
|
||||
>
|
||||
{{ loading ? t('register.registering') : t('register.registerBtn') }}
|
||||
</button>
|
||||
|
||||
<view class="error-tip" v-if="errorMsg">
|
||||
<text>{{ errorMsg }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted, onUnmounted } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { setLocale, getCurrentLocale } from '../../locales/index.js'
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
|
||||
// 响应式数据
|
||||
const form = reactive({
|
||||
username: '',
|
||||
email: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
const showPassword = ref(false)
|
||||
const loading = ref(false)
|
||||
const errorMsg = ref('')
|
||||
|
||||
// 切换语言
|
||||
const switchLang = (lang) => {
|
||||
setLocale(lang)
|
||||
locale.value = lang
|
||||
}
|
||||
|
||||
// 返回上一页
|
||||
const goBack = () => {
|
||||
uni.navigateBack()
|
||||
}
|
||||
|
||||
// 表单验证
|
||||
const validate = () => {
|
||||
if (!form.username.trim()) {
|
||||
errorMsg.value = t('register.usernameRequired')
|
||||
return false
|
||||
}
|
||||
if (!form.email.trim()) {
|
||||
errorMsg.value = t('register.emailRequired')
|
||||
return false
|
||||
}
|
||||
// 简单邮箱验证
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||
if (!emailRegex.test(form.email)) {
|
||||
errorMsg.value = t('register.emailInvalid')
|
||||
return false
|
||||
}
|
||||
if (!form.password) {
|
||||
errorMsg.value = t('register.passwordRequired')
|
||||
return false
|
||||
}
|
||||
if (form.password.length < 6) {
|
||||
errorMsg.value = t('register.passwordLength')
|
||||
return false
|
||||
}
|
||||
if (form.password !== form.confirmPassword) {
|
||||
errorMsg.value = t('register.passwordMismatch')
|
||||
return false
|
||||
}
|
||||
errorMsg.value = ''
|
||||
return true
|
||||
}
|
||||
|
||||
// 注册处理
|
||||
const handleRegister = () => {
|
||||
if (!validate()) return
|
||||
|
||||
loading.value = true
|
||||
errorMsg.value = ''
|
||||
|
||||
uni.request({
|
||||
url: getApp().globalData.BASE_URL + '/users/register',
|
||||
method: 'POST',
|
||||
data: {
|
||||
username: form.username,
|
||||
useremail: form.email,
|
||||
userpass: form.password
|
||||
},
|
||||
header: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.data.code === 0) {
|
||||
uni.showToast({
|
||||
title: t('register.registerSuccess'),
|
||||
icon: 'success',
|
||||
duration: 1500
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
} else {
|
||||
const msgMap = {
|
||||
userNameDup: t('register.usernameExists'),
|
||||
userEmailDup: t('register.emailUsed'),
|
||||
jsonErr: t('register.paramError'),
|
||||
postErr: t('register.requestFailed')
|
||||
}
|
||||
errorMsg.value = msgMap[res.data.code] || t('register.registerFailed')
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
errorMsg.value = t('common.networkError')
|
||||
console.error('Register error:', err)
|
||||
},
|
||||
complete: () => {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
locale.value = getCurrentLocale()
|
||||
|
||||
uni.$on('localeChanged', (lang) => {
|
||||
locale.value = lang
|
||||
})
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
uni.$off('localeChanged')
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.register-container {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 40rpx 60rpx;
|
||||
}
|
||||
|
||||
.lang-switch {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.lang-btn {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
padding: 8rpx 16rpx;
|
||||
|
||||
&.active {
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.lang-divider {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
margin: 0 8rpx;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
margin-bottom: 40rpx;
|
||||
padding: 16rpx 0;
|
||||
|
||||
text {
|
||||
color: #fff;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.form-section {
|
||||
background-color: #fff;
|
||||
border-radius: 24rpx;
|
||||
padding: 48rpx 40rpx;
|
||||
box-shadow: 0 16rpx 48rpx rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.title {
|
||||
display: block;
|
||||
font-size: 44rpx;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
margin-bottom: 48rpx;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 28rpx;
|
||||
}
|
||||
|
||||
.input-label {
|
||||
display: block;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 16rpx;
|
||||
padding: 0 32rpx;
|
||||
font-size: 30rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.password-toggle {
|
||||
margin-bottom: 32rpx;
|
||||
|
||||
text {
|
||||
color: #666;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.register-btn {
|
||||
width: 100%;
|
||||
height: 96rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
border-radius: 48rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
&:active {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
&[disabled] {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
.error-tip {
|
||||
margin-top: 24rpx;
|
||||
padding: 20rpx;
|
||||
background-color: #fff5f5;
|
||||
border-radius: 12rpx;
|
||||
text-align: center;
|
||||
|
||||
text {
|
||||
color: #e53935;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,344 @@
|
||||
<template>
|
||||
<view class="settings-container">
|
||||
<!-- 页面标题 -->
|
||||
<view class="page-header">
|
||||
<text class="page-title">{{ t('apiConfig.title') }}</text>
|
||||
</view>
|
||||
|
||||
<!-- API 地址配置 -->
|
||||
<view class="config-section">
|
||||
<text class="section-title">{{ t('apiConfig.apiUrl') }}</text>
|
||||
|
||||
<view class="input-group">
|
||||
<input
|
||||
class="input-field"
|
||||
type="text"
|
||||
v-model="apiUrl"
|
||||
:placeholder="t('apiConfig.apiUrlPlaceholder')"
|
||||
placeholder-class="placeholder"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="info-text">
|
||||
<text>{{ t('apiConfig.format') }}: http://192.168.1.100/api/</text>
|
||||
</view>
|
||||
|
||||
<view class="info-text">
|
||||
<text>{{ t('apiConfig.current') }}: {{ currentApiUrl }}</text>
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="save-btn"
|
||||
:loading="saving"
|
||||
@click="saveApiUrl"
|
||||
>
|
||||
{{ t('apiConfig.save') }}
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- 测试连接 -->
|
||||
<view class="config-section">
|
||||
<text class="section-title">{{ t('apiConfig.testConnection') }}</text>
|
||||
|
||||
<button
|
||||
class="test-btn"
|
||||
:loading="testing"
|
||||
:disabled="!apiUrl"
|
||||
@click="testConnection"
|
||||
>
|
||||
{{ testing ? t('apiConfig.testing') : t('apiConfig.testBtn') }}
|
||||
</button>
|
||||
|
||||
<view class="test-result" v-if="testResult !== null">
|
||||
<text
|
||||
class="result-text"
|
||||
:class="testResult ? 'success' : 'failed'"
|
||||
>
|
||||
{{ testResult ? t('apiConfig.connectionSuccess') : t('apiConfig.connectionFailed') }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 语言切换 -->
|
||||
<view class="config-section">
|
||||
<text class="section-title">{{ t('apiConfig.language') }}</text>
|
||||
|
||||
<view class="lang-options">
|
||||
<view
|
||||
class="lang-item"
|
||||
:class="{ active: currentLang === 'zh' }"
|
||||
@click="switchLang('zh')"
|
||||
>
|
||||
<text>🇨🇳 {{ t('apiConfig.zh') }}</text>
|
||||
</view>
|
||||
<view
|
||||
class="lang-item"
|
||||
:class="{ active: currentLang === 'en' }"
|
||||
@click="switchLang('en')"
|
||||
>
|
||||
<text>🇺🇸 {{ t('apiConfig.en') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
|
||||
// 响应式数据
|
||||
const apiUrl = ref('')
|
||||
const saving = ref(false)
|
||||
const testing = ref(false)
|
||||
const testResult = ref(null)
|
||||
const currentLang = ref('zh')
|
||||
|
||||
// 计算属性
|
||||
const currentApiUrl = computed(() => {
|
||||
return getApp().globalData.BASE_URL || t('apiConfig.notSet')
|
||||
})
|
||||
|
||||
// 切换语言
|
||||
const switchLang = (lang) => {
|
||||
locale.value = lang
|
||||
currentLang.value = lang
|
||||
uni.setStorageSync('locale', lang)
|
||||
uni.$emit('localeChanged', lang)
|
||||
}
|
||||
|
||||
// 保存 API 地址
|
||||
const saveApiUrl = () => {
|
||||
if (!apiUrl.value) {
|
||||
uni.showToast({
|
||||
title: t('apiConfig.pleaseInput'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 验证 URL 格式
|
||||
let url = apiUrl.value.trim()
|
||||
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
||||
url = 'http://' + url
|
||||
}
|
||||
if (!url.endsWith('/')) {
|
||||
url = url + '/'
|
||||
}
|
||||
|
||||
saving.value = true
|
||||
|
||||
// 保存到本地
|
||||
uni.setStorageSync('apiUrl', url)
|
||||
|
||||
// 更新全局配置
|
||||
getApp().globalData.BASE_URL = url
|
||||
|
||||
setTimeout(() => {
|
||||
saving.value = false
|
||||
uni.showToast({
|
||||
title: t('apiConfig.saveSuccess'),
|
||||
icon: 'success'
|
||||
})
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// 测试连接
|
||||
const testConnection = () => {
|
||||
testing.value = true
|
||||
testResult.value = null
|
||||
|
||||
// 使用相对路径,走代理
|
||||
uni.request({
|
||||
url: '/api/',
|
||||
method: 'GET',
|
||||
timeout: 5000,
|
||||
success: (res) => {
|
||||
// 成功返回 {"err_code":0,"err_msg":"apiOK"}
|
||||
if (res.data && res.data.err_code === 0) {
|
||||
testResult.value = true
|
||||
} else {
|
||||
testResult.value = false
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
testResult.value = false
|
||||
},
|
||||
complete: () => {
|
||||
testing.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
// 读取当前配置
|
||||
const savedApiUrl = uni.getStorageSync('apiUrl')
|
||||
if (savedApiUrl) {
|
||||
apiUrl.value = savedApiUrl
|
||||
} else {
|
||||
apiUrl.value = getApp().globalData.BASE_URL || ''
|
||||
}
|
||||
|
||||
currentLang.value = locale.value || 'zh'
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.settings-container {
|
||||
min-height: 100vh;
|
||||
background-color: #f5f5f5;
|
||||
padding: 40rpx 30rpx;
|
||||
padding-bottom: 140rpx;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 40rpx;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.config-section {
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 32rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: block;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 12rpx;
|
||||
padding: 0 24rpx;
|
||||
font-size: 30rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.info-text {
|
||||
margin-top: 16rpx;
|
||||
|
||||
text {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
||||
.save-btn {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
border-radius: 44rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 30rpx;
|
||||
border: none;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
&:active {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
&[disabled] {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
.test-btn {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
background-color: #f0f0f0;
|
||||
color: #333;
|
||||
font-size: 30rpx;
|
||||
border-radius: 40rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
&:active {
|
||||
background-color: #e0e0e0;
|
||||
}
|
||||
|
||||
&[disabled] {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
.test-result {
|
||||
margin-top: 24rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.result-text {
|
||||
font-size: 28rpx;
|
||||
font-weight: 500;
|
||||
|
||||
&.success {
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
&.failed {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
}
|
||||
|
||||
.lang-options {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.lang-item {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 12rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 2rpx solid transparent;
|
||||
|
||||
&.active {
|
||||
background-color: #f0f5ff;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
text {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user