Signed-off-by: 吴文峰 <kevin@lmve.net>

This commit is contained in:
2026-04-16 15:57:44 +08:00
parent 118277d37d
commit aedab4b0ee
24 changed files with 0 additions and 1970 deletions
-208
View File
@@ -1,208 +0,0 @@
<template>
<view class="min-h-screen" :style="{ paddingTop: statusBarHeight + 'px' }">
<!-- 未登录状态 -->
<view v-if="!isLoggedIn" class="flex flex-col items-center justify-center px-6" style="min-height: 80vh">
<text class="text-6xl mb-6">🔐</text>
<text class="block text-xl font-semibold text-center mb-8" style="color: #1f2937">{{ t('index.pleaseLogin') }}</text>
<button
class="w-full max-w-xs h-12 rounded-full flex items-center justify-center font-semibold text-base"
:style="{ background: 'linear-gradient(to right, #667eea, #764ba2)', color: '#fff' }"
@click="goToLogin"
>
{{ t('index.login') }}
</button>
</view>
<!-- 已登录状态 -->
<template v-else>
<!-- 顶部标题 -->
<view class="header mx-4 mt-4 rounded-3xl p-8 mb-6" :style="{ background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)' }">
<text class="block text-3xl font-bold text-white">{{ t('index.welcome') }}</text>
<text class="block text-base text-white/80 mt-2">{{ t('index.subtitle') }}</text>
</view>
<!-- 订单统计卡片 -->
<view class="grid grid-cols-4 gap-3 mx-4 mb-6">
<view class="stat-card rounded-2xl p-4 text-center shadow-sm" @click="goToOrders('pending')">
<text class="block text-3xl font-bold" style="color: #667eea">{{ stats.pending }}</text>
<text class="block text-sm mt-2" style="color: #6b7280">{{ t('index.pending') }}</text>
</view>
<view class="stat-card rounded-2xl p-4 text-center shadow-sm" @click="goToOrders('ordered')">
<text class="block text-3xl font-bold" style="color: #667eea">{{ stats.ordered }}</text>
<text class="block text-sm mt-2" style="color: #6b7280">{{ t('index.ordered') }}</text>
</view>
<view class="stat-card rounded-2xl p-4 text-center shadow-sm" @click="goToOrders('arrived')">
<text class="block text-3xl font-bold" style="color: #667eea">{{ stats.arrived }}</text>
<text class="block text-sm mt-2" style="color: #6b7280">{{ t('index.arrived') }}</text>
</view>
<view class="stat-card rounded-2xl p-4 text-center shadow-sm" @click="goToOrders('received')">
<text class="block text-3xl font-bold" style="color: #667eea">{{ stats.received }}</text>
<text class="block text-sm mt-2" style="color: #6b7280">{{ t('index.received') }}</text>
</view>
</view>
<!-- 快捷操作 -->
<view class="mx-4 mb-6">
<text class="block text-xl font-semibold mb-4" style="color: #1f2937">{{ t('index.quickActions') }}</text>
<view class="bg-white rounded-2xl overflow-hidden shadow-sm">
<view class="action-item flex items-center p-6 border-b border-gray-100" @click="goToOrders('all')">
<text class="text-2xl mr-4">📋</text>
<text class="flex-1 text-base" style="color: #1f2937">{{ t('index.allOrders') }}</text>
<text class="text-base" style="color: #d1d5db"></text>
</view>
<view class="action-item flex items-center p-6 border-b border-gray-100" @click="goToAddOrder">
<text class="text-2xl mr-4"></text>
<text class="flex-1 text-base" style="color: #1f2937">{{ t('index.addOrder') }}</text>
<text class="text-base" style="color: #d1d5db"></text>
</view>
<view class="action-item flex items-center p-6" @click="goToSchedule">
<text class="text-2xl mr-4">📅</text>
<text class="flex-1 text-base" style="color: #1f2937">{{ t('index.schedule') }}</text>
<text class="text-base" style="color: #d1d5db"></text>
</view>
</view>
</view>
<!-- 语言切换入口 -->
<view class="mx-4 mb-6">
<view class="bg-white rounded-2xl p-6 flex items-center shadow-sm" @click="switchLang">
<text class="text-2xl mr-4">🌐</text>
<view class="flex-1">
<text class="block text-base" style="color: #1f2937">{{ t('index.language') }}</text>
<text class="block text-sm mt-1" style="color: #6b7280">{{ locale === 'zh' ? '中文' : 'English' }}</text>
</view>
<text class="text-base" style="color: #d1d5db"></text>
</view>
</view>
<!-- 退出登录 -->
<view class="mx-4 pb-8">
<button class="w-full h-11 rounded-full text-center text-lg"
style="background: #fff; color: #e53935" @click="handleLogout">
{{ t('index.logout') }}
</button>
</view>
</template>
</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 statusBarHeight = ref(20)
const isLoggedIn = ref(false)
// API 请求封装,解决路径拼接问题
const request = (path, method = 'GET', data = {}) => {
return new Promise((resolve, reject) => {
// 确保 BASE_URL 不以 / 结尾
const baseUrl = (getApp().globalData.BASE_URL || '').replace(/\/$/, '')
// 确保 path 以 / 开头
const fullPath = path.startsWith('/') ? path : '/' + path
uni.request({
url: baseUrl + fullPath,
method,
data,
header: {
'Content-Type': 'application/json',
'Cookie': uni.getStorageSync('sessionCookie') || ''
},
success: (res) => resolve(res),
fail: (err) => reject(err)
})
})
}
const stats = reactive({
pending: 0,
ordered: 0,
arrived: 0,
received: 0
})
const fetchStats = () => {
request('/purchase/getordercount', 'POST').then((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
}
}).catch(console.error)
}
const goToLogin = () => {
uni.navigateTo({
url: '/pages/login/login'
})
}
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')
isLoggedIn.value = false
}
}
})
}
onMounted(() => {
const systemInfo = uni.getSystemInfoSync()
statusBarHeight.value = systemInfo.statusBarHeight || 20
locale.value = getCurrentLocale()
// 检查登录状态
const sessionCookie = uni.getStorageSync('sessionCookie')
isLoggedIn.value = !!sessionCookie
// 已登录才获取数据
if (isLoggedIn.value) {
fetchStats()
}
})
onUnmounted(() => {
uni.$off('localeChanged')
})
</script>
<style scoped>
.min-h-screen {
min-height: 100vh;
background-color: #f5f5f5;
}
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
</style>
-227
View File
@@ -1,227 +0,0 @@
<template>
<view class="min-h-screen bg-gradient-to-br from-purple-500 to-purple-800 px-6" :style="{ paddingTop: statusBarHeight + 'px' }">
<!-- 语言切换 -->
<view class="flex justify-center items-center py-4">
<text
class="text-sm px-2"
:class="locale === 'zh' ? 'text-white font-semibold' : 'text-white/60'"
@click="switchLang('zh')"
>中文</text>
<text class="text-white/40 mx-1">|</text>
<text
class="text-sm px-2"
:class="locale === 'en' ? 'text-white font-semibold' : 'text-white/60'"
@click="switchLang('en')"
>EN</text>
</view>
<!-- Logo 区域 -->
<view class="flex flex-col items-center mb-16">
<image class="w-20 h-20 rounded-2xl bg-white shadow-lg" src="/static/logo.png" mode="aspectFit"></image>
<text class="text-4xl font-bold text-white mt-4 tracking-wider">OPS</text>
<text class="text-sm text-white/80 mt-2">{{ t('login.title') }}</text>
</view>
<!-- 登录表单 -->
<view class="bg-white rounded-3xl p-8 shadow-xl">
<view class="mb-6">
<text class="block text-sm font-medium mb-3" style="color: #1f2937">{{ t('login.username') }}</text>
<input
class="w-full h-11 rounded-xl px-4 text-base"
style="background: #f3f4f6; color: #1f2937"
type="text"
v-model="form.username"
:placeholder="t('login.usernamePlaceholder')"
placeholder-class="placeholder-gray"
@confirm="handleLogin"
/>
</view>
<view class="mb-6 relative">
<text class="block text-sm font-medium mb-3" style="color: #1f2937">{{ t('login.password') }}</text>
<input
class="w-full h-11 rounded-xl px-4 text-base pr-10"
style="background: #f3f4f6; color: #1f2937"
:type="showPassword ? 'text' : 'password'"
v-model="form.password"
:placeholder="t('login.passwordPlaceholder')"
placeholder-class="placeholder-gray"
@confirm="handleLogin"
/>
<view class="absolute right-3 bottom-2.5 text-xl" @click="showPassword = !showPassword">
<text>{{ showPassword ? '👁️' : '👁️‍🗨️' }}</text>
</view>
</view>
<view class="mb-8 flex items-center">
<checkbox-group @change="onRememberChange">
<label class="flex items-center text-sm" style="color: #6b7280">
<checkbox value="1" :checked="form.remember" color="#667eea" />
<text class="ml-2">{{ t('login.rememberMe') }}</text>
</label>
</checkbox-group>
</view>
<button
class="w-full h-12 rounded-full flex items-center justify-center font-semibold text-lg"
:style="{ background: 'linear-gradient(to right, #667eea, #764ba2)', color: '#fff' }"
:loading="loading"
:disabled="loading"
@click="handleLogin"
>
{{ loading ? t('login.logging') : t('login.loginBtn') }}
</button>
<view class="mt-4 p-4 rounded-xl text-center" style="background: #fef2f2" v-if="errorMsg">
<text class="text-sm" style="color: #ef4444">{{ errorMsg }}</text>
</view>
</view>
<!-- 底部信息 -->
<view class="flex justify-center items-end pb-8 mt-8">
<text class="text-sm text-white/80">{{ t('login.registerLink') }}</text>
<navigator url="/pages/register/register" class="text-sm text-white font-semibold ml-1">{{ t('register.title') }}</navigator>
</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 statusBarHeight = ref(20)
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: {
userCookieValue: '',
data: {
username: form.username,
password: form.password,
remember: form.remember
}
},
header: {
'Content-Type': 'application/json'
},
success: (res) => {
if (res.data.err_code === 0 && res.data.return && res.data.return.cookie) {
const cookieData = res.data.return.cookie
// 存储 cookie Value 作为 session 标识
uni.setStorageSync('sessionCookie', cookieData.Value)
uni.setStorageSync('cookieExpires', cookieData.ExpiresAt)
uni.setStorageSync('userInfo', {
userId: cookieData.ID,
username: form.username
})
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 {
// 根据 err_code 显示错误信息
const errCode = res.data.err_code
const msgMap = {
'-41': t('login.usernameNotFound'),
'-42': t('login.passwordIncorrect'),
'-3': t('login.paramError'),
'-2': t('login.requestFailed')
}
errorMsg.value = msgMap[errCode] || res.data.err_msg || t('login.loginFailed')
}
},
fail: (err) => {
errorMsg.value = t('login.networkError')
console.error('Login error:', err)
},
complete: () => {
loading.value = false
}
})
}
onMounted(() => {
const systemInfo = uni.getSystemInfoSync()
statusBarHeight.value = systemInfo.statusBarHeight || 20
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>
.placeholder-gray {
color: #9ca3af;
}
</style>
@@ -1,226 +0,0 @@
<template>
<view class="min-h-screen bg-gradient-to-br from-purple-500 to-purple-800 px-6" :style="{ paddingTop: statusBarHeight + 'px' }">
<!-- 语言切换 -->
<view class="flex justify-center items-center py-4">
<text
class="text-sm px-2"
:class="locale === 'zh' ? 'text-white font-semibold' : 'text-white/60'"
@click="switchLang('zh')"
>中文</text>
<text class="text-white/40 mx-1">|</text>
<text
class="text-sm px-2"
:class="locale === 'en' ? 'text-white font-semibold' : 'text-white/60'"
@click="switchLang('en')"
>EN</text>
</view>
<!-- 返回按钮 -->
<view class="mb-8 py-3" @click="goBack">
<text class="text-lg text-white"> {{ t('common.back') }}</text>
</view>
<!-- 注册表单 -->
<view class="bg-white rounded-3xl p-8 shadow-xl">
<text class="block text-3xl font-bold text-center mb-8" style="color: #1f2937">{{ t('register.title') }}</text>
<view class="mb-5">
<text class="block text-sm font-medium mb-3" style="color: #1f2937">{{ t('register.username') }}</text>
<input
class="w-full h-11 rounded-xl px-4 text-base"
style="background: #f3f4f6; color: #1f2937"
type="text"
v-model="form.username"
:placeholder="t('register.usernamePlaceholder')"
placeholder-class="placeholder-gray"
/>
</view>
<view class="mb-5">
<text class="block text-sm font-medium mb-3" style="color: #1f2937">{{ t('register.email') }}</text>
<input
class="w-full h-11 rounded-xl px-4 text-base"
style="background: #f3f4f6; color: #1f2937"
type="email"
v-model="form.email"
:placeholder="t('register.emailPlaceholder')"
placeholder-class="placeholder-gray"
/>
</view>
<view class="mb-5">
<text class="block text-sm font-medium mb-3" style="color: #1f2937">{{ t('register.password') }}</text>
<input
class="w-full h-11 rounded-xl px-4 text-base"
style="background: #f3f4f6; color: #1f2937"
:type="showPassword ? 'text' : 'password'"
v-model="form.password"
:placeholder="t('register.passwordPlaceholder')"
placeholder-class="placeholder-gray"
/>
</view>
<view class="mb-5">
<text class="block text-sm font-medium mb-3" style="color: #1f2937">{{ t('register.confirmPassword') }}</text>
<input
class="w-full h-11 rounded-xl px-4 text-base"
style="background: #f3f4f6; color: #1f2937"
:type="showPassword ? 'text' : 'password'"
v-model="form.confirmPassword"
:placeholder="t('register.confirmPlaceholder')"
placeholder-class="placeholder-gray"
/>
</view>
<view class="mb-6" @click="showPassword = !showPassword">
<text class="text-sm" style="color: #6b7280">{{ showPassword ? '👁️ ' : '👁️‍🗨️ ' }}{{ showPassword ? t('register.showPassword') : t('register.hidePassword') }}</text>
</view>
<button
class="w-full h-12 rounded-full flex items-center justify-center font-semibold text-lg"
:style="{ background: 'linear-gradient(to right, #667eea, #764ba2)', color: '#fff' }"
:loading="loading"
:disabled="loading"
@click="handleRegister"
>
{{ loading ? t('register.registering') : t('register.registerBtn') }}
</button>
<view class="mt-4 p-4 rounded-xl text-center" style="background: #fef2f2" v-if="errorMsg">
<text class="text-sm" style="color: #ef4444">{{ 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 statusBarHeight = ref(20)
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: {
userCookieValue: '',
data: {
username: form.username,
useremail: form.email,
userpass: form.password
}
},
header: {
'Content-Type': 'application/json'
},
success: (res) => {
if (res.data.err_code === 0) {
uni.showToast({
title: t('register.registerSuccess'),
icon: 'success',
duration: 1500
})
setTimeout(() => {
uni.navigateBack()
}, 1500)
} else {
// 根据 err_code 显示错误信息
const errCode = res.data.err_code
const msgMap = {
'-4': t('register.usernameExists'),
'-43': t('register.emailInvalid'),
'-3': t('register.paramError'),
'-2': t('register.requestFailed')
}
errorMsg.value = msgMap[errCode] || res.data.err_msg || t('register.registerFailed')
}
},
fail: (err) => {
errorMsg.value = t('common.networkError')
console.error('Register error:', err)
},
complete: () => {
loading.value = false
}
})
}
onMounted(() => {
const systemInfo = uni.getSystemInfoSync()
statusBarHeight.value = systemInfo.statusBarHeight || 20
locale.value = getCurrentLocale()
uni.$on('localeChanged', (lang) => {
locale.value = lang
})
})
onUnmounted(() => {
uni.$off('localeChanged')
})
</script>
<style>
.placeholder-gray {
color: #9ca3af;
}
</style>
@@ -1,200 +0,0 @@
<template>
<view class="min-h-screen" :style="{ paddingTop: statusBarHeight + 'px' }">
<!-- 页面标题 -->
<view class="mx-4 mt-4 mb-6">
<text class="block text-2xl font-bold" style="color: #1f2937">{{ t('apiConfig.title') }}</text>
</view>
<!-- #ifndef H5 -->
<!-- API 地址配置 - 非H5端显示 -->
<view class="mx-4 mb-4 bg-white rounded-2xl p-6 shadow-sm">
<text class="block text-base font-semibold mb-4" style="color: #1f2937">{{ t('apiConfig.apiUrl') }}</text>
<view class="mb-4">
<input
class="w-full h-11 rounded-xl px-4 text-base"
style="background: #f3f4f6; color: #1f2937"
type="text"
v-model="apiUrl"
:placeholder="t('apiConfig.apiUrlPlaceholder')"
placeholder-class="placeholder-gray"
/>
</view>
<view class="mb-3">
<text class="block text-sm" style="color: #9ca3af">{{ t('apiConfig.format') }}: http://192.168.1.100/api/</text>
</view>
<view class="mb-4">
<text class="block text-sm" style="color: #9ca3af">{{ t('apiConfig.current') }}: {{ currentApiUrl }}</text>
</view>
<button
class="w-full h-11 rounded-full flex items-center justify-center font-semibold text-base"
:style="{ background: 'linear-gradient(to right, #667eea, #764ba2)', color: '#fff' }"
:loading="saving"
@click="saveApiUrl"
>
{{ t('apiConfig.save') }}
</button>
</view>
<!-- #endif -->
<view class="mx-4 mb-4 bg-white rounded-2xl p-6 shadow-sm">
<text class="block text-base font-semibold mb-4" style="color: #1f2937">{{ t('apiConfig.testConnection') }}</text>
<button
class="w-full h-10 rounded-full flex items-center justify-center text-base"
:style="{ background: testResult === true ? '#dcfce7' : testResult === false ? '#fef2f2' : '#f3f4f6', color: testResult === true ? '#22c55e' : testResult === false ? '#ef4444' : '#1f2937' }"
:loading="testing"
:disabled="!apiUrl"
@click="testConnection"
>
{{ testing ? t('apiConfig.testing') : t('apiConfig.testBtn') }}
</button>
<view class="mt-4 text-center" v-if="testResult !== null">
<text class="text-base font-medium" :style="{ color: testResult ? '#22c55e' : '#ef4444' }">
{{ testResult ? t('apiConfig.connectionSuccess') : t('apiConfig.connectionFailed') }}
</text>
</view>
</view>
<!-- 语言切换 -->
<view class="mx-4 mb-8 bg-white rounded-2xl p-6 shadow-sm">
<text class="block text-base font-semibold mb-4" style="color: #1f2937">{{ t('apiConfig.language') }}</text>
<view class="flex gap-4">
<view
class="flex-1 h-11 rounded-xl flex items-center justify-center border-2"
:style="currentLang === 'zh' ? { borderColor: '#667eea', backgroundColor: '#f0f5ff' } : { borderColor: 'transparent', backgroundColor: '#f3f4f6' }"
@click="switchLang('zh')"
>
<text class="text-base" :style="{ color: currentLang === 'zh' ? '#667eea' : '#1f2937' }">🇨🇳 中文</text>
</view>
<view
class="flex-1 h-11 rounded-xl flex items-center justify-center border-2"
:style="currentLang === 'en' ? { borderColor: '#667eea', backgroundColor: '#f0f5ff' } : { borderColor: 'transparent', backgroundColor: '#f3f4f6' }"
@click="switchLang('en')"
>
<text class="text-base" :style="{ color: currentLang === 'en' ? '#667eea' : '#1f2937' }">🇺🇸 English</text>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
const { t, locale } = useI18n()
const statusBarHeight = ref(20)
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)
}
const saveApiUrl = () => {
if (!apiUrl.value) {
uni.showToast({
title: t('apiConfig.pleaseInput'),
icon: 'none'
})
return
}
let url = apiUrl.value.trim()
if (!url.startsWith('http://') && !url.startsWith('https://')) {
url = 'http://' + url
}
if (!url.endsWith('/')) {
url = url + '/'
}
saving.value = true
// 保存原始 URL 到本地存储
uni.setStorageSync('apiUrl', url)
// H5 端使用相对路径走代理,其他端使用完整 URL
// #ifdef H5
getApp().globalData.BASE_URL = '/api/'
// #endif
// #ifndef H5
getApp().globalData.BASE_URL = url
// #endif
setTimeout(() => {
saving.value = false
uni.showToast({
title: t('apiConfig.saveSuccess'),
icon: 'success'
})
}, 500)
}
const testConnection = () => {
testing.value = true
testResult.value = null
uni.request({
url: getApp().globalData.BASE_URL,
method: 'GET',
timeout: 5000,
success: (res) => {
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 systemInfo = uni.getSystemInfoSync()
statusBarHeight.value = systemInfo.statusBarHeight || 20
const savedApiUrl = uni.getStorageSync('apiUrl')
if (savedApiUrl) {
apiUrl.value = savedApiUrl
} else {
apiUrl.value = getApp().globalData.BASE_URL || ''
}
currentLang.value = locale.value || 'zh'
})
</script>
<style scoped>
.min-h-screen {
min-height: 100vh;
background-color: #f5f5f5;
}
.placeholder-gray {
color: #9ca3af;
}
</style>
-319
View File
@@ -1,319 +0,0 @@
<template>
<view class="container">
<!-- 未登录状态 -->
<view v-if="!isLoggedIn" class="login-prompt">
<view class="prompt-icon">👤</view>
<text class="prompt-text">{{ t('index.pleaseLogin') }}</text>
<button class="login-btn" @click="goLogin">{{ t('index.login') }}</button>
</view>
<!-- 已登录状态 -->
<view v-else class="user-info">
<!-- 用户卡片 -->
<view class="user-card">
<view class="avatar-box">
<view class="avatar-placeholder">👤</view>
</view>
<view class="user-details">
<text class="username">{{ userInfo.username || userInfo.Name || 'User' }}</text>
<text class="email">{{ userInfo.email || userInfo.Email || '' }}</text>
</view>
</view>
<!-- 加载状态 -->
<view v-if="loading" class="loading-box">
<text>{{ t('common.loading') }}</text>
</view>
<!-- 用户详细信息 -->
<view v-else-if="userDetail" class="detail-section">
<view class="section-title">{{ t('user.profile') }}</view>
<view class="info-list">
<view class="info-item">
<text class="info-label">{{ t('user.username') }}</text>
<text class="info-value">{{ userDetail.userInfo.Username || '-' }}</text>
</view>
<view class="info-item">
<text class="info-label">{{ t('user.firstName') }}</text>
<text class="info-value">{{ userDetail.userInfo.FirstName || '-' }}</text>
</view>
<view class="info-item">
<text class="info-label">{{ t('user.birthday') }}</text>
<text class="info-value">{{ userDetail.userInfo.Birthdate || '-' }}</text>
</view>
<view class="info-item">
<text class="info-label">{{ t('user.gender') }}</text>
<text class="info-value">{{ genderText }}</text>
</view>
<view class="info-item">
<text class="info-label">{{ t('user.region') }}</text>
<text class="info-value">{{ userDetail.userInfo.Region || '-' }}</text>
</view>
</view>
</view>
<!-- 操作按钮 -->
<view class="action-section">
<button class="action-btn logout" @click="handleLogout">
{{ t('index.logout') }}
</button>
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { onShow } from '@dcloudio/uni-app'
const { t, locale } = useI18n()
const isLoggedIn = ref(false)
const loading = ref(false)
const userInfo = ref({})
const userDetail = ref(null)
// 性别显示文本
const genderText = computed(() => {
if (!userDetail.value?.userInfo?.Gender) return '-'
const map = { M: t('user.male'), F: t('user.female'), U: t('user.unknown') }
return map[userDetail.value.userInfo.Gender] || '-'
})
// 检查登录状态
const checkLogin = () => {
const cookie = uni.getStorageSync('sessionCookie')
const info = uni.getStorageSync('userInfo')
isLoggedIn.value = !!cookie && !!info
if (info) userInfo.value = info
}
// 获取用户详细信息
const fetchUserDetail = () => {
if (!isLoggedIn.value) return
loading.value = true
const cookie = uni.getStorageSync('sessionCookie')
uni.request({
url: getApp().globalData.BASE_URL + '/users/getinfo',
method: 'POST',
data: {
userCookieValue: cookie,
data: {}
},
header: {
'Content-Type': 'application/json'
},
success: (res) => {
if (res.data.err_code === 0 && res.data.return) {
userDetail.value = res.data.return
// 更新本地存储的用户信息
const newInfo = {
userId: res.data.return.user?.ID,
username: res.data.return.user?.Name,
email: res.data.return.user?.Email,
...res.data.return.userInfo
}
uni.setStorageSync('userInfo', newInfo)
userInfo.value = newInfo
} else if (res.data.err_code === -44) {
// Cookie 过期,清除登录状态
handleLogout()
}
},
fail: (err) => {
console.error('Get user info error:', err)
},
complete: () => {
loading.value = false
}
})
}
// 跳转到登录页
const goLogin = () => {
uni.navigateTo({
url: '/pages/login/login'
})
}
// 退出登录
const handleLogout = () => {
uni.showModal({
title: t('index.logoutConfirm'),
content: t('index.logoutMessage'),
success: (res) => {
if (res.confirm) {
uni.removeStorageSync('sessionCookie')
uni.removeStorageSync('cookieExpires')
uni.removeStorageSync('userInfo')
isLoggedIn.value = false
userInfo.value = {}
userDetail.value = null
uni.showToast({
title: t('index.logout'),
icon: 'success'
})
}
}
})
}
// 页面显示时刷新数据
onShow(() => {
checkLogin()
if (isLoggedIn.value) {
fetchUserDetail()
}
})
</script>
<style>
.container {
min-height: 100vh;
background-color: #f5f5f5;
padding: 20rpx;
}
.login-prompt {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding-top: 200rpx;
}
.prompt-icon {
font-size: 120rpx;
margin-bottom: 30rpx;
}
.prompt-text {
font-size: 32rpx;
color: #666;
margin-bottom: 40rpx;
}
.login-btn {
width: 300rpx;
height: 88rpx;
line-height: 88rpx;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
border-radius: 44rpx;
font-size: 32rpx;
border: none;
}
.user-card {
display: flex;
align-items: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 20rpx;
padding: 40rpx;
margin-bottom: 30rpx;
}
.avatar-box {
width: 120rpx;
height: 120rpx;
border-radius: 60rpx;
background: rgba(255, 255, 255, 0.3);
display: flex;
align-items: center;
justify-content: center;
margin-right: 30rpx;
}
.avatar-placeholder {
font-size: 60rpx;
}
.user-details {
flex: 1;
}
.username {
display: block;
font-size: 36rpx;
font-weight: bold;
color: #fff;
margin-bottom: 10rpx;
}
.email {
display: block;
font-size: 26rpx;
color: rgba(255, 255, 255, 0.8);
}
.loading-box {
text-align: center;
padding: 60rpx;
color: #999;
}
.detail-section {
background: #fff;
border-radius: 16rpx;
padding: 30rpx;
margin-bottom: 30rpx;
}
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
margin-bottom: 20rpx;
padding-bottom: 20rpx;
border-bottom: 1rpx solid #eee;
}
.info-list {
display: flex;
flex-direction: column;
}
.info-item {
display: flex;
justify-content: space-between;
padding: 24rpx 0;
border-bottom: 1rpx solid #f5f5f5;
}
.info-item:last-child {
border-bottom: none;
}
.info-label {
font-size: 28rpx;
color: #666;
}
.info-value {
font-size: 28rpx;
color: #333;
}
.action-section {
margin-top: 40rpx;
}
.action-btn {
width: 100%;
height: 88rpx;
line-height: 88rpx;
border-radius: 44rpx;
font-size: 32rpx;
border: none;
margin-bottom: 20rpx;
}
.action-btn.logout {
background: #fff;
color: #ff4d4f;
border: 2rpx solid #ff4d4f;
}
</style>