新增登录页、首页

This commit is contained in:
zm2000 2026-05-14 18:22:45 +08:00
parent faa195ad07
commit 705c6f3854
3 changed files with 559 additions and 59 deletions

4
env.js
View File

@ -1,3 +1,3 @@
export const BASE_URL = 'https://ye4s.wms.gztbyc.com/' //后台根域名 https://demo.shopro.top
export const API_URL = `${BASE_URL}/api/` //后台接口域名
export const BASE_URL = 'http://192.168.11.56:6060' //后台根域名 https://demo.shopro.top
export const API_URL = `${BASE_URL}/system` //后台接口域名
export const IMG_URL = 'https://ye4s.file.gzxunren.com' //全局网络图片地址变量,css背景图片地址变量在uni.scss

View File

@ -1,48 +1,181 @@
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{ title }}</text>
<view class="page" @click="closeMinePopup">
<view class="top-nav" @click.stop>
<image class="top-nav-logo" src="http://192.168.11.56:5174/public/logo/1.png" mode="heightFix"></image>
<view class="top-nav-right">
<text class="top-nav-mine" @click="openMinePopup">我的</text>
<view v-if="showMinePopup" class="popup-card" @click.stop>
<button class="logout-btn" type="warn" @click="handleLogout">退出登录</button>
<button class="close-btn" @click="closeMinePopup">关闭</button>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello',
onLoad() {
const token = uni.getStorageSync('token')
if (!token) {
uni.reLaunch({
url: '/pages/login/login',
})
}
},
onLoad() {},
methods: {},
data() {
return {
showMinePopup: false,
}
},
methods: {
openMinePopup() {
this.showMinePopup = true
},
closeMinePopup() {
this.showMinePopup = false
},
finishLogout() {
uni.removeStorageSync('token')
uni.showToast({
title: '已退出登录',
icon: 'none',
})
setTimeout(() => {
uni.reLaunch({
url: '/pages/login/login',
})
}, 200)
},
handleLogout() {
const token = uni.getStorageSync('token')
if (!token) {
this.finishLogout()
return
}
uni.request({
url: `http://192.168.11.56:6060/system?method=user.logout&v=1.0&timestamp=${Date.now()}`,
method: 'POST',
header: {
accept: 'application/json, text/plain, */*',
platform: 'workerstation',
project: 'warehouse',
token,
Authorization: `Bearer ${token}`,
},
data: {},
complete: () => {
this.finishLogout()
},
})
},
},
}
</script>
<style>
.content {
.page {
min-height: 100vh;
min-width: 960px;
box-sizing: border-box;
padding: 56rpx;
background-color: #2fbf71;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
justify-content: flex-start;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
.top-nav {
width: 100%;
align-self: stretch;
margin: 0 0 24rpx;
padding: 18rpx 28rpx;
box-sizing: border-box;
border-radius: 16rpx;
background-color: #2f7dff;
display: flex;
justify-content: center;
align-items: center;
justify-content: space-between;
position: relative;
}
.title {
font-size: 36rpx;
color: #8f8f94;
.top-nav-right {
position: relative;
}
.top-nav-logo {
height: 90rpx;
}
.top-nav-mine {
font-size: 30rpx;
font-weight: 600;
color: #fff;
}
.popup-card {
position: absolute;
right: 0;
top: calc(100% + 14rpx);
width: 420rpx;
background-color: #fff;
border-radius: 16rpx;
padding: 32rpx;
box-sizing: border-box;
z-index: 1000;
box-shadow: 0 12rpx 30rpx rgba(0, 0, 0, 0.14);
}
.logout-btn,
.close-btn {
width: 100%;
height: 64rpx;
line-height: 64rpx;
font-size: 26rpx;
padding: 0;
border-radius: 10rpx;
}
.logout-btn {
margin-top: 8rpx;
}
.close-btn {
margin-top: 10rpx;
background-color: #f5f7fb;
color: #333;
}
@media screen and (max-width: 1024px) {
.page {
min-width: 760px;
padding: 36rpx;
}
.top-nav {
margin-bottom: 18rpx;
padding: 16rpx 20rpx;
}
.top-nav-logo {
height: 78rpx;
}
.popup-card {
width: 360rpx;
padding: 24rpx;
top: calc(100% + 12rpx);
}
.logout-btn,
.close-btn {
height: 58rpx;
line-height: 58rpx;
font-size: 24rpx;
}
}
</style>

View File

@ -1,30 +1,71 @@
<template>
<view class="page">
<view class="header">
<text class="title">登录</text>
<text class="subtitle">请选择登录方式</text>
</view>
<view class="switch-tabs">
<view :class="['tab-item', loginMode === 'scan' ? 'tab-item--active' : '']" @click="switchMode('scan')">
扫码登录2
<view class="login-card">
<view class="visual-side">
<image class="visual-logo" src="http://192.168.11.56:5174/public/logo/1.png" mode="widthFix"></image>
<text class="visual-desc">仓库管理系统工作台</text>
</view>
<view :class="['tab-item', loginMode === 'account' ? 'tab-item--active' : '']" @click="switchMode('account')">
账号登录
</view>
</view>
<view v-if="loginMode === 'scan'" class="panel">
<view class="scan-box">
<text class="scan-placeholder">二维码区域</text>
</view>
<button class="primary-btn" type="primary" @click="handleScanLogin">开始扫码</button>
</view>
<view class="form-side">
<view class="header">
<text class="title">登录</text>
<text class="subtitle">欢迎回来,请登录您的账户</text>
</view>
<view v-else class="panel">
<input class="input" v-model="form.username" placeholder="请输入账号" />
<input class="input" v-model="form.password" placeholder="请输入密码" password />
<button class="primary-btn" type="primary" @click="handleAccountLogin">登录</button>
<view class="switch-tabs">
<view :class="['tab-item', loginMode === 'account' ? 'tab-item--active' : '']" @click="switchMode('account')">
账号登录
</view>
<view :class="['tab-item', loginMode === 'scan' ? 'tab-item--active' : '']" @click="switchMode('scan')">
扫码登录
</view>
</view>
<view v-if="loginMode === 'scan'" class="panel">
<text class="scan-tip-top">打开微信,扫描二维码登录</text>
<view class="scan-box">
<image v-if="scanQrImage" class="scan-image" :src="scanQrImage" mode="aspectFit"></image>
<text v-else class="scan-placeholder">{{ scanCode || '二维码区域' }}</text>
</view>
<text class="scan-tip-bottom">{{ scanStatus }}</text>
<button class="primary-btn scan-login-btn" @click="handleScanLogin">扫描枪扫描工牌登录</button>
</view>
<view v-else class="panel">
<view :class="['input-wrap', focusedField === 'username' ? 'input-wrap--focused' : '']">
<input
class="input input--with-clear"
v-model="form.username"
placeholder="请输入账号"
@focus="handleFocus('username')"
@blur="handleBlur"
/>
<view v-if="form.username" class="clear-trigger" @click="clearField('username')">
<text class="clear-trigger__icon">×</text>
</view>
</view>
<view :class="['password-wrap', focusedField === 'password' ? 'input-wrap--focused' : '']">
<input
class="input password-input"
v-model="form.password"
placeholder="请输入密码"
:password="!showPassword"
@focus="handleFocus('password')"
@blur="handleBlur"
/>
<view v-if="form.password" class="clear-trigger clear-trigger--password" @click="clearField('password')">
<text class="clear-trigger__icon">×</text>
</view>
<view class="toggle-password" @click="togglePassword">
<view class="eye-icon" :class="showPassword ? 'eye-icon--open' : 'eye-icon--closed'">
<view class="eye-pupil"></view>
<view class="eye-lid"></view>
</view>
</view>
</view>
<button class="primary-btn" type="primary" @click="handleAccountLogin">登录</button>
</view>
</view>
</view>
</view>
</template>
@ -33,7 +74,14 @@
export default {
data() {
return {
loginMode: 'scan',
loginMode: 'account',
showPassword: false,
focusedField: '',
scanLoading: false,
scanClientCode: '',
scanCode: '',
scanQrImage: '',
scanStatus: '等待扫码...',
form: {
username: '',
password: '',
@ -43,11 +91,71 @@ export default {
methods: {
switchMode(mode) {
this.loginMode = mode
if (mode === 'scan' && !this.scanCode && !this.scanQrImage) {
this.handleScanLogin()
}
},
togglePassword() {
this.showPassword = !this.showPassword
},
clearField(field) {
this.form[field] = ''
this.focusedField = field
},
handleFocus(field) {
this.focusedField = field
},
handleBlur() {
this.focusedField = ''
},
handleScanLogin() {
uni.showToast({
title: '请接入扫码能力',
icon: 'none',
if (this.scanLoading) {
return
}
this.scanLoading = true
this.scanStatus = '正在获取二维码...'
const query = [`method=user.getLoginWechatCode`, `v=1.0`, `timestamp=${Date.now()}`]
if (this.scanClientCode) {
query.push(`clientCode=${encodeURIComponent(this.scanClientCode)}`)
}
uni.request({
url: `http://192.168.11.56:6060/system?${query.join('&')}`,
method: 'POST',
header: {
platform: 'workerstation',
project: 'warehouse',
},
data: this.scanClientCode ? { clientCode: this.scanClientCode } : {},
success: (res) => {
const body = res?.data || {}
const payload = body?.data || body?.result || body
const clientCode = payload?.clientCode || body?.clientCode || ''
const qrImage = payload?.qrCodeUrl || payload?.qrcodeUrl || payload?.codeUrl || payload?.wechatCodeUrl || payload?.image || ''
const loginCode = payload?.loginWechatCode || payload?.wechatCode || payload?.qrCode || payload?.code || ''
if (clientCode) {
this.scanClientCode = clientCode
}
this.scanQrImage = qrImage || ''
this.scanCode = loginCode || ''
if (this.scanQrImage || this.scanCode) {
this.scanStatus = '等待扫码...'
} else {
this.scanStatus = body?.message || body?.msg || '二维码获取失败'
}
},
fail: () => {
this.scanStatus = '网络异常,请稍后重试'
},
complete: () => {
this.scanLoading = false
},
})
},
handleAccountLogin() {
@ -59,9 +167,47 @@ export default {
return
}
uni.showToast({
title: '登录请求已发起',
icon: 'none',
uni.request({
url: `http://192.168.11.56:6060/system?method=user.login&v=1.0&timestamp=${Date.now()}`,
method: 'POST',
header: {
accept: 'application/json, text/plain, */*',
platform: 'workerstation',
project: 'warehouse'
},
data: {
username: this.form.username,
password: this.form.password,
},
success: (res) => {
const body = res?.data || {}
const token = body?.token || body?.data?.token || body?.result?.token
if (token) {
uni.setStorageSync('token', token)
uni.showToast({
title: '登录成功',
icon: 'success',
})
setTimeout(() => {
uni.reLaunch({
url: '/pages/index/index',
})
}, 300)
return
}
uni.showToast({
title: body?.msg || body?.message || '登录失败',
icon: 'none',
})
},
fail: () => {
uni.showToast({
title: '网络异常,请稍后重试',
icon: 'none',
})
},
})
},
},
@ -71,11 +217,59 @@ export default {
<style>
.page {
min-height: 100vh;
min-width: 960px;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
padding: 64rpx 40rpx;
padding: 48rpx;
background-color: #f8f8f8;
}
.login-card {
width: 100%;
max-width: 1200rpx;
min-width: 920px;
background-color: #fff;
border-radius: 20rpx;
display: flex;
overflow: hidden;
}
.visual-side {
width: 45%;
min-height: 720rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
box-sizing: border-box;
padding: 80rpx 56rpx;
background: linear-gradient(135deg, #2f7dff, #4d97ff);
text-align: center;
}
.visual-logo {
display: block;
width: 320rpx;
max-width: 100%;
margin: 0 auto 24rpx;
}
.visual-desc {
font-size: 44rpx;
font-weight: 800;
line-height: 1.3;
letter-spacing: 2rpx;
color: #fff;
}
.form-side {
width: 55%;
box-sizing: border-box;
padding: 64rpx 56rpx;
}
.header {
margin-bottom: 40rpx;
}
@ -95,7 +289,7 @@ export default {
.switch-tabs {
display: flex;
background-color: #fff;
background-color: #f5f7fb;
border-radius: 12rpx;
margin-bottom: 32rpx;
overflow: hidden;
@ -116,7 +310,8 @@ export default {
}
.panel {
background-color: #fff;
background-color: #fdfdfd;
border: 1rpx solid #f0f0f0;
border-radius: 12rpx;
padding: 28rpx;
}
@ -131,6 +326,27 @@ export default {
margin-bottom: 24rpx;
}
.scan-image {
width: 280rpx;
height: 280rpx;
}
.scan-tip-top {
display: block;
text-align: center;
font-size: 28rpx;
color: #666;
margin-bottom: 16rpx;
}
.scan-tip-bottom {
display: block;
text-align: center;
font-size: 26rpx;
color: #999;
margin-bottom: 16rpx;
}
.scan-placeholder {
color: #999;
font-size: 28rpx;
@ -145,7 +361,158 @@ export default {
font-size: 30rpx;
}
.input:focus {
border-color: #007aff;
}
.input-wrap,
.password-wrap {
position: relative;
border: 1rpx solid #e5e5e5;
border-radius: 8rpx;
background-color: #fff;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
margin-bottom: 20rpx;
}
.input-wrap--focused {
border-color: #007aff;
box-shadow: 0 0 0 4rpx rgba(0, 122, 255, 0.08);
}
.password-input {
margin-bottom: 0;
padding-right: 156rpx;
}
.input--with-clear {
padding-right: 84rpx;
}
.input-wrap .input,
.password-wrap .input {
border: none;
margin-bottom: 0;
background-color: transparent;
}
.clear-trigger {
position: absolute;
right: 22rpx;
top: 50%;
transform: translateY(-50%);
width: 40rpx;
height: 40rpx;
border-radius: 50%;
border: 1rpx solid #cfd6e4;
background-color: transparent;
display: flex;
align-items: center;
justify-content: center;
}
.clear-trigger--password {
right: 88rpx;
}
.clear-trigger__icon {
font-size: 24rpx;
line-height: 1;
color: #a9b4c6;
}
.toggle-password {
position: absolute;
right: 22rpx;
top: 50%;
transform: translateY(-50%);
width: 56rpx;
height: 56rpx;
display: flex;
align-items: center;
justify-content: center;
}
.eye-icon {
width: 36rpx;
height: 24rpx;
border: 2rpx solid #007aff;
border-radius: 20rpx;
position: relative;
box-sizing: border-box;
}
.eye-pupil {
width: 10rpx;
height: 10rpx;
border-radius: 50%;
background-color: #007aff;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.eye-lid {
position: absolute;
width: 28rpx;
height: 2rpx;
background-color: #007aff;
left: 4rpx;
top: 11rpx;
border-radius: 2rpx;
display: none;
}
.eye-icon--closed {
height: 18rpx;
border-top: 2rpx solid #007aff;
border-right: none;
border-bottom: none;
border-left: none;
border-radius: 20rpx 20rpx 0 0;
}
.eye-icon--closed .eye-pupil {
display: none;
}
.eye-icon--closed .eye-lid {
display: block;
}
.primary-btn {
margin-top: 12rpx;
}
.scan-login-btn {
background-color: #2fbf71;
color: #fff;
}
.scan-login-btn::after {
border: none;
}
@media screen and (max-width: 1024px) {
.page {
min-width: 760px;
}
.login-card {
max-width: 980rpx;
min-width: 720px;
}
.visual-side {
width: 45%;
min-height: 660rpx;
padding: 64rpx 40rpx;
}
.form-side {
width: 55%;
padding: 56rpx 40rpx;
}
}
</style>