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