InspectionCleaning/pages/login/login.vue

147 lines
4.6 KiB
Vue
Raw Normal View History

2025-04-14 14:29:21 +08:00
<template>
<view class="content">
2025-04-24 15:03:07 +08:00
<view style="margin-top: 50rpx; display: flex; align-items: center; padding-right: 50rpx">
2025-04-14 14:29:21 +08:00
<view style="margin-right: 50rpx">账号</view>
<u-input v-model="phone" border placeholder="账号"></u-input>
</view>
2025-04-24 15:03:07 +08:00
<view style="margin-top: 50rpx; display: flex; align-items: center; padding-right: 50rpx">
2025-04-14 14:29:21 +08:00
<view style="margin-right: 50rpx">账号</view>
<u-input v-model="pwd" border placeholder="密码"></u-input>
</view>
2025-04-24 15:03:07 +08:00
<u-button type="primary" @click="loginFn('admin')" style="margin-top: 50rpx">登陆-管理员</u-button>
2025-04-29 11:45:17 +08:00
<u-button type="primary" @click="loginFn('user')" style="margin-top: 50rpx">登陆-清洁工</u-button>
2025-04-29 14:12:55 +08:00
<u-button type="primary" @click="login1Fn" style="margin-top: 50rpx">登陆13800456666-清洁工</u-button>
2025-04-29 11:45:17 +08:00
<u-button type="primary" v-if="false" @click="login2Fn" style="margin-top: 50rpx">登陆18174010562-管理员</u-button>
<u-button type="primary" v-if="false" @click="login4Fn" style="margin-top: 50rpx">登陆18174010562-清洁工</u-button>
<u-button type="primary" v-if="false" @click="login3Fn" style="margin-top: 50rpx">登陆18174010561-清洁工</u-button>
<u-button type="primary" v-if="false" @click="login5Fn" style="margin-top: 50rpx">登陆18174010561-管理员</u-button>
2025-04-14 14:29:21 +08:00
</view>
</template>
<script>
2025-04-29 11:45:17 +08:00
import bcrypt from 'bcryptjs'
import { jwtDecode } from 'jwt-decode'
import { loginApi } from '@/api/apiList'
2025-04-14 14:29:21 +08:00
export default {
data() {
return {
2025-04-29 11:45:17 +08:00
phone: '18174010566',
pwd: '123456'
}
2025-04-14 14:29:21 +08:00
},
mounted() {
// console.log("%c%s", "color:red", "mounted--");
2025-04-29 11:45:17 +08:00
uni.hideLoading() // 关闭 Loading
2025-04-14 14:29:21 +08:00
},
2025-04-29 11:45:17 +08:00
onLoad() {},
2025-04-14 14:29:21 +08:00
methods: {
login1Fn() {
2025-04-29 14:12:55 +08:00
this.phone = '13800456666'
2025-04-18 11:55:50 +08:00
// this.phone = "18174010561";
2025-04-29 11:45:17 +08:00
this.pwd = '123456'
this.loginFn('user')
2025-04-14 14:29:21 +08:00
},
login2Fn() {
2025-04-29 11:45:17 +08:00
this.phone = '18174010562'
this.pwd = '123456'
this.loginFn('admin')
2025-04-14 14:29:21 +08:00
},
2025-04-24 15:03:07 +08:00
login3Fn() {
2025-04-29 11:45:17 +08:00
this.phone = '18174010561'
this.pwd = '123456'
this.loginFn('user')
2025-04-24 15:03:07 +08:00
},
2025-04-18 11:55:50 +08:00
login4Fn() {
2025-04-29 11:45:17 +08:00
this.phone = '18174010562'
this.pwd = '123456'
this.loginFn('user')
2025-04-18 11:55:50 +08:00
},
2025-04-24 15:03:07 +08:00
login5Fn() {
2025-04-29 11:45:17 +08:00
this.phone = '18174010561'
this.pwd = '123456'
this.loginFn('admin')
2025-04-18 11:55:50 +08:00
},
2025-04-15 10:07:11 +08:00
async loginFn(type) {
2025-04-29 11:45:17 +08:00
let salt = bcrypt.genSaltSync(12)
2025-04-14 14:29:21 +08:00
let req = {
phone: this.phone,
2025-04-29 11:45:17 +08:00
password: bcrypt.hashSync(this.pwd, salt)
}
const res = await loginApi(req)
2025-04-14 14:29:21 +08:00
if (!res.succeed) {
uni.showToast({
2025-04-29 11:45:17 +08:00
title: res.error || '登录失败',
icon: 'none'
})
return
2025-04-14 14:29:21 +08:00
}
2025-04-29 11:45:17 +08:00
let token = res.data
uni.setStorageSync('token', 'Bearer ' + token)
console.log(jwtDecode(token), '解析的token信息')
2025-04-28 15:31:01 +08:00
// return
2025-04-29 11:45:17 +08:00
console.log(type, 'type--')
if (type === 'user') {
2025-04-24 15:03:07 +08:00
const normalTabBar = [
{
2025-04-29 11:45:17 +08:00
pagePath: '/pages/index/planList',
iconPath: '/static/tab/planList.png',
selectedIconPath: '/static/tab/planList-active.png',
text: '计划'
2025-04-24 15:03:07 +08:00
},
{
2025-04-29 11:45:17 +08:00
pagePath: '/pages/index/index',
iconPath: '/static/tab/admin-home.png',
selectedIconPath: '/static/tab/admin-home-acitve.png',
text: '首页'
2025-04-24 15:03:07 +08:00
},
{
2025-04-29 11:45:17 +08:00
pagePath: '/pages/user/index',
iconPath: '/static/tab/admin-my.png',
selectedIconPath: '/static/tab/admin-my-active.png',
text: '设置'
}
]
this.$u.vuex('vuex_tabbar', normalTabBar)
2025-04-24 15:03:07 +08:00
2025-04-15 10:07:11 +08:00
uni.switchTab({
2025-04-29 11:45:17 +08:00
url: `/pages/index/planList`
})
2025-04-15 11:22:20 +08:00
}
2025-04-29 11:45:17 +08:00
if (type === 'admin') {
2025-04-24 15:03:07 +08:00
const adminTabBar = [
{
2025-04-29 11:45:17 +08:00
pagePath: '/pages/adminHome/index',
iconPath: '/static/tab/admin-home.png',
selectedIconPath: '/static/tab/admin-home-acitve.png',
text: '首页'
2025-04-24 15:03:07 +08:00
},
{
2025-04-29 11:45:17 +08:00
pagePath: '/pages/adminNfc/index',
iconPath: '/static/tab/nfc.png',
selectedIconPath: '/static/tab/nfc-active.png',
text: 'nfc写入'
2025-04-24 15:03:07 +08:00
},
{
2025-04-29 11:45:17 +08:00
pagePath: '/pages/adminMy/index',
iconPath: '/static/tab/admin-my.png',
selectedIconPath: '/static/tab/admin-my-active.png',
text: '我的'
}
]
this.$u.vuex('vuex_tabbar', adminTabBar)
2025-04-15 10:07:11 +08:00
uni.switchTab({
2025-04-29 11:45:17 +08:00
url: `/pages/adminHome/index`
})
2025-04-15 10:07:11 +08:00
}
2025-04-29 11:45:17 +08:00
}
}
}
2025-04-14 14:29:21 +08:00
</script>
<style lang="scss" scoped>
.content {
height: 100vh; // 确保容器有明确高度
// background-color: skyblue;
overflow: hidden;
padding-bottom: 100rpx;
}
</style>