访客页面

This commit is contained in:
zjf committed 2025-04-18 17:02:21 +08:00
1 parent 0a952f01c1
commit 4d6a5d5e0a
4 files changed
+469 -493

No files matched your search

+223 -259
View File
@@ -1,259 +1,223 @@
<script lang="ts">
import isDevEnv from "./sheep/utils/isDevEnv"
// import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"
// onLaunch(() => {})
// onShow(() => {})
// onHide(() => {})
interface TabbarItem {
pagePath: string
text: string
iconPath: string
selectedIconPath: string
launchParam: string[]
auth: string[]
}
const tabbar: TabbarItem[] = [
// {
// pagePath: "pages/tabbar/canteen",
// text: "食堂",
// iconPath: "/static/tabbar/canteen.png",
// selectedIconPath: "/static/tabbar/canteen-select.png",
// launchParam: ["canteen"],
// auth: [],
// },
// {
// pagePath: "pages/tabbar/selfMerchant",
// text: "自营商家",
// iconPath: "/static/tabbar/selfMerchant.png",
// selectedIconPath: "/static/tabbar/selfMerchant-select.png",
// launchParam: ["selfMerchant"],
// auth: [],
// },
// {
// pagePath: "pages/tabbar/coopMerchant",
// text: "合作商家",
// iconPath: "/static/tabbar/coopMerchant.png",
// selectedIconPath: "/static/tabbar/coopMerchant-select.png",
// launchParam: ["selfMerchant"],
// auth: ["user"],
// },
// {
// pagePath: "pages/tabbar/order",
// text: "订单",
// iconPath: "/static/tabbar/order.png",
// selectedIconPath: "/static/tabbar/order-select.png",
// launchParam: ["canteen", "selfMerchant"],
// auth: ["user"],
// },
// {
// pagePath: "pages/tabbar/flowStatistics",
// text: "流水统计",
// iconPath: "/static/tabbar/order.png",
// selectedIconPath: "/static/tabbar/order-select.png",
// launchParam: [],
// auth: ["merchant"],
// },
// {
// pagePath: "pages/tabbar/individualOrder",
// text: "订单",
// iconPath: "/static/tabbar/order.png",
// selectedIconPath: "/static/tabbar/order-select.png",
// launchParam: [],
// auth: ["merchant"],
// },
{
pagePath: "pages/integrated/visitor/index",
text: "访客申请",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user",],
},
{
pagePath: "pages/integrated/visitor/myvisitor",
text: "申请记录",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user",],
},
{
pagePath: "pages/integrated/visitor/myyyvisitor",
text: "主动邀约",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user",],
},
{
pagePath: "pages/integrated/visitor/myyyvisitorlist",
text: "邀约记录",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user",],
},
{
pagePath: "pages/integrated/visitor/verify",
text: "访客核销",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user",],
},
{
pagePath: "pages/tabbar/my",
text: "我的",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user", "merchant"],
},
]
// 获取启动参数
const getLaunchParam = () => {
return new URL(window.location.href).searchParams.get("launchParam")
}
// 设置tabbar项目
const setTabbarItem = (index: number, item: TabbarItem, visible: boolean) => {
uni.setTabBarItem({
index,
pagePath: item.pagePath,
text: item.text,
iconPath: item.iconPath,
selectedIconPath: item.selectedIconPath,
visible,
})
}
// 根据启动参数设置tabbar项目
const setTabbarByLaunchParam = (launchParam: string) => {
tabbar.forEach((item, index) => {
const visible = item.launchParam.includes(launchParam)
setTabbarItem(index, item, visible)
})
}
// 根据用户角色设置tabbar项目
const setTabbarByUserRole = (role: string) => {
tabbar.forEach((item, index) => {
const visible = item.auth.includes(role)
setTabbarItem(index, item, visible)
})
}
export default {
async onLaunch() {
if (isDevEnv()) return
uni.setNavigationBarTitle({ title: "" })
// 环境判断
const res = await (window as any).CP2.getAppInfo()
if (res.code == 0) {
// 不是诗画环境
const launchParam = getLaunchParam()
console.log("app launch 启动路径参数", launchParam)
switch (launchParam) {
case "canteen":
uni.switchTab({ url: "/pages/tabbar/canteen" })
break
case "selfMerchant":
uni.switchTab({ url: "/pages/tabbar/selfMerchant" })
break
default:
break
}
} else {
// 是诗画环境
const userRole = uni.getStorageSync("userRole")
if (!userRole) return uni.redirectTo({ url: "/pages/user/userRole" })
if (userRole === "user") return uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
if (userRole === "merchant") return uni.switchTab({ url: "/pages/tabbar/individualOrder" })
}
},
onShow() {},
onHide() {},
methods: {
async _initTabbar() {
if (isDevEnv()) {
tabbar.forEach((item, index) => {
setTabbarItem(index, item, true)
})
return
}
const launchParam = getLaunchParam()
console.log("tabbar launch 启动路径参数", launchParam)
const res = await (window as any).CP2.getAppInfo()
if (res.code == 0) {
// 不是诗画环境
if (launchParam) {
setTabbarByLaunchParam(launchParam)
} else {
uni.hideTabBar()
uni.showToast({ title: "启动参数不合法", icon: "none" })
}
} else {
// 是诗画环境
const userRole = uni.getStorageSync("userRole")
switch (userRole) {
case "user":
setTabbarByUserRole("user")
break
case "merchant":
setTabbarByUserRole("merchant")
break
default:
uni.hideTabBar()
uni.showToast({ title: "用户身份未确认", icon: "none" })
break
}
}
},
},
}
</script>
<style lang="scss">
@import "@/sheep/scss/global.scss";
@import url(@/uni_modules/tm-ui/css/remixicon.min.css);
$theme-green: #06be36;
$theme-blue: #0094ff;
$theme-gray: #999;
.botder_btn {
border: 1px solid #999;
color: #999;
font-weight: 500;
font-size: 28rpx;
border-radius: 10rpx;
padding: 8rpx 15rpx;
}
.prefix_title {
font-size: 32rpx;
font-weight: 500;
color: #333;
&::before {
content: "";
display: inline-block;
width: 8rpx;
height: 24rpx;
background: $theme-blue;
border-radius: 4rpx;
margin-right: 10rpx;
}
}
</style>
<script lang="ts">
import isDevEnv from "./sheep/utils/isDevEnv"
// import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"
// onLaunch(() => {})
// onShow(() => {})
// onHide(() => {})
interface TabbarItem {
pagePath: string
text: string
iconPath: string
selectedIconPath: string
launchParam: string[]
auth: string[]
}
const tabbar: TabbarItem[] = [
// {
// pagePath: "pages/tabbar/canteen",
// text: "食堂",
// iconPath: "/static/tabbar/canteen.png",
// selectedIconPath: "/static/tabbar/canteen-select.png",
// launchParam: ["canteen"],
// auth: [],
// },
// {
// pagePath: "pages/tabbar/selfMerchant",
// text: "自营商家",
// iconPath: "/static/tabbar/selfMerchant.png",
// selectedIconPath: "/static/tabbar/selfMerchant-select.png",
// launchParam: ["selfMerchant"],
// auth: [],
// },
// {
// pagePath: "pages/tabbar/coopMerchant",
// text: "合作商家",
// iconPath: "/static/tabbar/coopMerchant.png",
// selectedIconPath: "/static/tabbar/coopMerchant-select.png",
// launchParam: ["selfMerchant"],
// auth: ["user"],
// },
// {
// pagePath: "pages/tabbar/order",
// text: "订单",
// iconPath: "/static/tabbar/order.png",
// selectedIconPath: "/static/tabbar/order-select.png",
// launchParam: ["canteen", "selfMerchant"],
// auth: ["user"],
// },
// {
// pagePath: "pages/tabbar/flowStatistics",
// text: "流水统计",
// iconPath: "/static/tabbar/order.png",
// selectedIconPath: "/static/tabbar/order-select.png",
// launchParam: [],
// auth: ["merchant"],
// },
// {
// pagePath: "pages/tabbar/individualOrder",
// text: "订单",
// iconPath: "/static/tabbar/order.png",
// selectedIconPath: "/static/tabbar/order-select.png",
// launchParam: [],
// auth: ["merchant"],
// },
{
pagePath: "pages/integrated/visitor/index",
text: "访客申请",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user",],
},
{
pagePath: "pages/integrated/visitor/myvisitor",
text: "申请记录",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user",],
},
{
pagePath: "pages/integrated/visitor/myyyvisitor",
text: "主动邀约",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user",],
},
{
pagePath: "pages/integrated/visitor/myyyvisitorlist",
text: "邀约记录",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user",],
},
{
pagePath: "pages/integrated/visitor/verify",
text: "访客核销",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user",],
},
{
pagePath: "pages/tabbar/my",
text: "我的",
iconPath: "/static/tabbar/my.png",
selectedIconPath: "/static/tabbar/my-select.png",
launchParam: ["canteen", "selfMerchant"],
auth: ["user", "merchant"],
},
]
// 获取启动参数
const getLaunchParam = () => {
return new URL(window.location.href).searchParams.get("launchParam")
}
// 设置tabbar项目
const setTabbarItem = (index: number, item: TabbarItem, visible: boolean) => {
uni.setTabBarItem({
index,
pagePath: item.pagePath,
text: item.text,
iconPath: item.iconPath,
selectedIconPath: item.selectedIconPath,
visible,
})
}
// 根据启动参数设置tabbar项目
const setTabbarByLaunchParam = (launchParam: string) => {
tabbar.forEach((item, index) => {
const visible = item.launchParam.includes(launchParam)
setTabbarItem(index, item, visible)
})
}
// 根据用户角色设置tabbar项目
const setTabbarByUserRole = (role: string) => {
tabbar.forEach((item, index) => {
const visible = item.auth.includes(role)
setTabbarItem(index, item, visible)
})
}
export default {
async onLaunch() {
if (isDevEnv()) return
uni.setNavigationBarTitle({ title: "" })
// 检查是否已登录
const token = uni.getStorageSync("token")
if (!token) {
uni.navigateTo({ url: "/pages/user/login" })
return
}
// 设置tabbar
await this._initTabbar()
},
onShow() {},
onHide() {},
methods: {
async _initTabbar() {
if (isDevEnv()) {
tabbar.forEach((item, index) => {
setTabbarItem(index, item, true)
})
return
}
// 根据用户角色设置tabbar
const userInfo = uni.getStorageSync("userInfo")
if (userInfo) {
const role = userInfo.role || "user"
setTabbarByUserRole(role)
} else {
uni.hideTabBar()
}
},
},
}
</script>
<style lang="scss">
@import "@/sheep/scss/global.scss";
@import url(@/uni_modules/tm-ui/css/remixicon.min.css);
$theme-green: #06be36;
$theme-blue: #0094ff;
$theme-gray: #999;
.botder_btn {
border: 1px solid #999;
color: #999;
font-weight: 500;
font-size: 28rpx;
border-radius: 10rpx;
padding: 8rpx 15rpx;
}
.prefix_title {
font-size: 32rpx;
font-weight: 500;
color: #333;
&::before {
content: "";
display: inline-block;
width: 8rpx;
height: 24rpx;
background: $theme-blue;
border-radius: 4rpx;
margin-right: 10rpx;
}
}
</style>
+152 -53
View File
@@ -9,47 +9,67 @@
}
},
"pages": [
{
"path": "pages/integrated/visitor/index",
"style": {
"navigationBarTitleText": "访客申请",
"navigationStyle": "custom"
}
},
{
"path": "pages/integrated/visitor/myvisitor",
"style": {
"navigationBarTitleText": "申请记录",
"navigationStyle": "custom"
}
},
{
"path": "pages/integrated/visitor/myyyvisitor",
"style": {
"navigationBarTitleText": "访客邀约",
"navigationStyle": "custom"
}
},
{
"path": "pages/integrated/visitor/myyyvisitorlist",
"style": {
"navigationBarTitleText": "邀约记录",
"navigationStyle": "custom"
}
},
{
"path": "pages/integrated/visitor/verify",
"style": {
"navigationBarTitleText": "访客核销",
"navigationStyle": "custom"
}
},
// {
// "path": "pages/tabbar/canteen",
// "style": {
// "navigationBarTitleText": "食堂",
// "disableScroll": true
// }
// },
// {
// "path": "pages/tabbar/selfMerchant",
// "style": {
// "navigationBarTitleText": "自营商家",
// "disableScroll": true
// }
// },
// {
// "path": "pages/tabbar/coopMerchant",
// "style": {
// "navigationBarTitleText": "合作商家",
// "disableScroll": true
// }
// },
// {
// "path": "pages/tabbar/order",
// "style": {
// "navigationBarTitleText": "订单",
// "disableScroll": true
// }
// },
// {
// "path": "pages/tabbar/flowStatistics",
// "style": {
// "navigationBarTitleText": "流水统计",
// "disableScroll": true
// }
// },
// {
// "path": "pages/tabbar/individualOrder",
// "style": {
// "navigationBarTitleText": "订单",
// "disableScroll": true
// }
// },
// {
// "path": "pages/integrated/visitor/myvisitor",
// "style": {
// "navigationBarTitleText": "访客",
// "disableScroll": true
// }
// },
{
"path": "pages/tabbar/my",
"style": {
"navigationBarTitleText": "我的",
"disableScroll": true
}
},
{
"path": "pages/integrated/visitor/verify",
"style": {
"navigationStyle": "custom"
}
}
],
"subPackages": [
@@ -351,7 +371,7 @@
{
"path": "visitor/myyyvisitor",
"style": {
"navigationBarTitleText": "访客邀约"
"navigationBarTitleText": "邀约访客"
}
}
]
@@ -392,39 +412,118 @@
{
"pagePath": "pages/integrated/visitor/index",
"text": "访客申请",
"iconPath": "static/tabbar/visitor-apply.png",
"selectedIconPath": "static/tabbar/visitor-apply-select.png"
"iconPath": "",
"selectedIconPath": ""
},
{
"pagePath": "pages/integrated/visitor/myvisitor",
"text": "申请记录",
"iconPath": "static/tabbar/visitor-record.png",
"selectedIconPath": "static/tabbar/visitor-record-select.png"
"iconPath": "",
"selectedIconPath": ""
},
{
"pagePath": "pages/integrated/visitor/myyyvisitor",
"text": "访客邀约",
"iconPath": "static/tabbar/visitor-invite.png",
"selectedIconPath": "static/tabbar/visitor-invite-select.png"
"iconPath": "",
"selectedIconPath": ""
},
{
"pagePath": "pages/integrated/visitor/myyyvisitorlist",
"text": "邀约记录",
"iconPath": "static/tabbar/visitor-invited.png",
"selectedIconPath": "static/tabbar/visitor-invited-select.png"
"iconPath": "",
"selectedIconPath": ""
},
{
"pagePath": "pages/integrated/visitor/verify",
"text": "访客核销",
"iconPath": "static/tabbar/visitor-verify.png",
"selectedIconPath": "static/tabbar/visitor-verify-select.png"
"text": "核销",
"iconPath": "",
"selectedIconPath": ""
},
{
"pagePath": "pages/tabbar/my",
"text": "我的",
"iconPath": "static/tabbar/my.png",
"selectedIconPath": "static/tabbar/my-select.png"
}
// {
// "pagePath": "pages/tabbar/canteen",
// "text": "",
// "iconPath": "",
// "selectedIconPath": ""
// },
// {
// "pagePath": "pages/tabbar/selfMerchant",
// "text": "",
// "iconPath": "",
// "selectedIconPath": ""
// },
// {
// "pagePath": "pages/tabbar/coopMerchant",
// "text": "",
// "iconPath": "",
// "selectedIconPath": ""
// },
// {
// "pagePath": "pages/tabbar/order",
// "text": "",
// "iconPath": "",
// "selectedIconPath": ""
// },
// {
// "pagePath": "pages/tabbar/flowStatistics",
// "text": "",
// "iconPath": "",
// "selectedIconPath": ""
// },
// {
// "pagePath": "pages/tabbar/individualOrder",
// "text": "",
// "iconPath": "",
// "selectedIconPath": ""
// },
// {
// "pagePath": "pages/tabbar/my",
// "text": "",
// "iconPath": "",
// "selectedIconPath": ""
// }
// {
// "pagePath": "pages/tabbar/canteen",
// "text": "食堂",
// "iconPath": "static/tabbar/canteen.png",
// "selectedIconPath": "static/tabbar/canteen-select.png"
// },
// {
// "pagePath": "pages/tabbar/selfMerchant",
// "text": "自营商家",
// "iconPath": "static/tabbar/selfMerchant.png",
// "selectedIconPath": "static/tabbar/selfMerchant-select.png"
// },
// {
// pagePath: "pages/tabbar/coopMerchant",
// text: "合作商家",
// iconPath: "static/tabbar/coopMerchant.png",
// selectedIconPath: "static/tabbar/coopMerchant-select.png",
// },
// {
// "pagePath": "pages/tabbar/order",
// "text": "订单",
// "iconPath": "static/tabbar/order.png",
// "selectedIconPath": "static/tabbar/order-select.png"
// },
// {
// "pagePath": "pages/tabbar/flowStatistics",
// "text": "流水统计",
// "iconPath": "static/tabbar/order.png",
// "selectedIconPath": "static/tabbar/order-select.png"
// },
// {
// "pagePath": "pages/tabbar/individualOrder",
// "text": "订单",
// "iconPath": "static/tabbar/order.png",
// "selectedIconPath": "static/tabbar/order-select.png"
// },
{
"pagePath": "pages/tabbar/my",
"text": "我的",
"iconPath": "static/tabbar/my.png",
"selectedIconPath": "static/tabbar/my-select.png"
}
]
}
}
@@ -69,6 +69,30 @@
<view class="empty" v-if="!loading && visitorList.length === 0">
<text>暂无数据</text>
</view>
<!-- 底部固定导航 -->
<view class="bottom-nav">
<view class="nav-item">
<image src="/static/images/visitor/visitor-apply.png" mode="aspectFit" class="nav-icon"></image>
<text class="nav-text active">访客申请</text>
</view>
<view class="nav-item">
<image src="/static/images/visitor/visitor-record.png" mode="aspectFit" class="nav-icon"></image>
<text class="nav-text">申请记录</text>
</view>
<view class="nav-item">
<image src="/static/images/visitor/visitor-invite.png" mode="aspectFit" class="nav-icon"></image>
<text class="nav-text">主动邀约</text>
</view>
<view class="nav-item">
<image src="/static/images/visitor/visitor-invited.png" mode="aspectFit" class="nav-icon"></image>
<text class="nav-text">邀约记录</text>
</view>
<view class="nav-item">
<image src="/static/images/visitor/visitor-my.png" mode="aspectFit" class="nav-icon"></image>
<text class="nav-text">我的</text>
</view>
</view>
</view>
</template>
@@ -338,7 +362,7 @@ defineExpose({
.page-container {
min-height: 100vh;
background-color: #f5f5f5;
padding-bottom: 20rpx; // 修改底部间距
padding-bottom: 120rpx; // 为底部导航留出空间
}
.status-tabs {
@@ -482,4 +506,40 @@ defineExpose({
color: #999;
font-size: 26rpx;
}
.bottom-nav {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 100rpx;
background-color: #fff;
display: flex;
justify-content: space-around;
align-items: center;
border-top: 1rpx solid #eee;
padding-bottom: env(safe-area-inset-bottom); // 适配iPhone底部安全区
.nav-item {
display: flex;
flex-direction: column;
align-items: center;
padding: 10rpx 0;
.nav-icon {
width: 44rpx;
height: 44rpx;
margin-bottom: 4rpx;
}
.nav-text {
font-size: 20rpx;
color: #999;
&.active {
color: #1777FF;
}
}
}
}
</style>
+33 -180
View File
@@ -16,7 +16,7 @@
</view>
<text class="sub-text-26">ID {{ state.userInfo?.sysUser?.userId }}</text>
</view>
<view v-else class="flex-row items-center m-l-30rpx" @tap="showLoginPopup">
<view v-else class="flex-row items-center m-l-30rpx" @tap="onTabLogin">
<text class="sub-text-32">请先登录</text>
<text class="iconfont icon-youjiantou" />
</view>
@@ -42,40 +42,6 @@
切换角色
</view>
</view>
<!-- 登录弹窗 -->
<view class="login-popup" v-if="showLogin">
<view class="popup-mask" @tap="closeLoginPopup"></view>
<view class="popup-content">
<view class="popup-header">
<text class="popup-title">账号密码登录</text>
<text class="popup-close" @tap="closeLoginPopup">×</text>
</view>
<view class="popup-body">
<view class="input-item">
<input
type="text"
v-model="loginForm.username"
placeholder="请输入账号"
placeholder-class="placeholder"
class="input"
/>
</view>
<view class="input-item">
<input
type="password"
v-model="loginForm.password"
placeholder="请输入密码"
placeholder-class="placeholder"
class="input"
/>
</view>
</view>
<view class="popup-footer">
<button class="login-btn" @tap="handleLogin">登录</button>
</view>
</view>
</view>
</crud-layout>
</template>
@@ -114,7 +80,7 @@ const state = reactive<{
// { text: "访客记录", icon: "/static/icon/service_5.png", router: "/pages/integrated/visitor/myvisitor" },
// { text: "访客邀约", icon: "/static/icon/service_5.png", router: "/pages/integrated/visitor/myyyvisitor" },
// { text: "邀约记录", icon: "/static/icon/service_5.png", router: "/pages/integrated/visitor/myyyvisitorlist" },
{ text: "访客核销", icon: "/static/icon/service_5.png", router: "/pages/integrated/visitor/verify" },
// { text: "访客核销", icon: "/static/icon/service_5.png", router: "/pages/integrated/visitor/verify" },
// { text: "意见反馈", icon: "/static/icon/service_5.png", router: "/pages/integrated/feedback/index" }
],
@@ -159,59 +125,6 @@ const storage = {
},
}
// 添加登录相关的状态
const showLogin = ref(false)
const loginForm = reactive({
username: '',
password: ''
})
// 显示登录弹窗
const showLoginPopup = () => {
showLogin.value = true
}
// 关闭登录弹窗
const closeLoginPopup = () => {
showLogin.value = false
loginForm.username = ''
loginForm.password = ''
}
// 处理账号密码登录
const handleLogin = async () => {
if (!loginForm.username || !loginForm.password) {
uni.showToast({
title: '请输入账号和密码',
icon: 'none'
})
return
}
try {
uni.showLoading({ title: '登录中...', mask: true })
const response = await userApi.login({
username: loginForm.username,
password: loginForm.password
})
if (response.code === 0) {
storage.saveToken({ accessToken: response.data.accessToken })
const { data: userData } = await userApi.userInfo()
storage.saveUserInfo(userData)
closeLoginPopup()
uni.showToast({ title: '登录成功', icon: 'none' })
} else {
uni.showToast({ title: response.msg || '登录失败', icon: 'none' })
}
} catch (error) {
console.error('登录失败:', error)
uni.showToast({ title: '登录失败', icon: 'none' })
} finally {
uni.hideLoading()
}
}
const login = {
// 检查应用环境并登录
checkAppInfo: async () => {
@@ -224,8 +137,10 @@ const login = {
const zhengdingResult = login.zhengdingLogin()
if (zhengdingResult) return
// 如果都不是,显示账号密码登录弹窗
showLoginPopup()
// 显示账号密码登录界面
uni.navigateTo({
url: '/pages/user/login'
})
} catch (error) {
console.error("登录失败:", error)
uni.showToast({ title: "登录失败", icon: "none" })
@@ -335,6 +250,33 @@ const login = {
changeRole: () => {
router.jump("/pages/user/userRole")
},
// 账号密码登录
accountLogin: async (username: string, password: string) => {
try {
uni.showLoading({ title: "登录中...", mask: true })
const response = await userApi.login({ username, password })
if (response.code == 0) {
storage.saveToken({ accessToken: response.data.accessToken })
uni.hideLoading()
uni.showToast({ title: "登录成功", icon: "none" })
const { data: userData } = await userApi.userInfo()
storage.saveUserInfo(userData)
return true
} else {
uni.hideLoading()
storage.clearUserStorage()
uni.showToast({ title: response.msg || "登录失败", icon: "none" })
return false
}
} catch (error) {
uni.hideLoading()
uni.showToast({ title: "登录失败", icon: "none" })
return false
}
},
}
const scanCode = {
@@ -481,93 +423,4 @@ onShow(() => {
border-bottom: 1px solid #fafafa;
margin-bottom: 40rpx;
}
// 添加登录弹窗样式
.login-popup {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 100;
.popup-mask {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.4);
}
.popup-content {
position: absolute;
left: 0;
right: 0;
bottom: 0;
background: #fff;
border-radius: 24rpx 24rpx 0 0;
}
.popup-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 32rpx;
border-bottom: 1rpx solid #f5f5f5;
.popup-title {
font-size: 32rpx;
color: #323233;
font-weight: 500;
}
.popup-close {
font-size: 40rpx;
color: #969799;
padding: 10rpx;
}
}
.popup-body {
padding: 32rpx;
}
.input-item {
margin-bottom: 24rpx;
.input {
width: 100%;
height: 88rpx;
background: #F7F8FA;
border-radius: 8rpx;
padding: 0 24rpx;
font-size: 30rpx;
color: #323233;
}
.placeholder {
color: #969799;
}
}
.popup-footer {
padding: 24rpx 32rpx;
background: #fff;
border-top: 1rpx solid #f5f5f5;
.login-btn {
width: 100%;
height: 88rpx;
background: #1989FA;
border-radius: 44rpx;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-size: 32rpx;
font-weight: 500;
}
}
}
</style>