InspectionCleaning/pages/login/login.vue

194 lines
5.5 KiB
Vue
Raw Normal View History

2025-04-14 14:29:21 +08:00
<template>
<view class="content">
<view
2025-04-18 11:55:50 +08:00
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>
<view
2025-04-18 11:55:50 +08:00
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-18 11:55:50 +08:00
<u-button type="primary" @click="loginFn" style="margin-top: 50rpx">登陆</u-button>
2025-04-14 14:29:21 +08:00
<u-button type="primary" @click="login1Fn" style="margin-top: 50rpx"
2025-04-18 13:51:49 +08:00
>登陆13800451500-清洁工</u-button
2025-04-14 14:29:21 +08:00
>
<u-button type="primary" @click="login2Fn" style="margin-top: 50rpx"
2025-04-18 13:51:49 +08:00
>登陆18174010562-管理员</u-button
2025-04-14 14:29:21 +08:00
>
2025-04-18 11:55:50 +08:00
<u-button type="primary" @click="login4Fn" style="margin-top: 50rpx"
2025-04-18 13:51:49 +08:00
>登陆18174010562-清洁工</u-button
2025-04-18 11:55:50 +08:00
>
<u-button type="primary" @click="login3Fn" style="margin-top: 50rpx"
2025-04-18 13:51:49 +08:00
>登陆18174010561-清洁工</u-button
2025-04-18 11:55:50 +08:00
>
2025-04-14 14:29:21 +08:00
</view>
</template>
<script>
import bcrypt from "bcryptjs";
import { loginApi } from "@/api/apiList";
export default {
data() {
return {
phone: "13800451500",
pwd: "123456",
};
},
mounted() {
// console.log("%c%s", "color:red", "mounted--");
uni.hideLoading(); // 关闭 Loading
},
onLoad() {},
methods: {
login1Fn() {
2025-04-18 11:55:50 +08:00
this.phone = "13800451500";
// this.phone = "18174010561";
2025-04-14 14:29:21 +08:00
this.pwd = "123456";
2025-04-15 10:07:11 +08:00
const normalTabBar = [
{
pagePath: "/pages/index/planList",
2025-04-15 16:08:33 +08:00
iconPath: "/static/tab/planList.png",
selectedIconPath: "/static/tab/planList-active.png",
2025-04-15 10:07:11 +08:00
text: "计划",
},
{
pagePath: "/pages/index/index",
2025-04-15 16:08:33 +08:00
iconPath: "/static/tab/admin-home.png",
selectedIconPath: "/static/tab/admin-home-acitve.png",
2025-04-15 10:07:11 +08:00
text: "首页",
},
{
pagePath: "/pages/user/index",
2025-04-15 16:08:33 +08:00
iconPath: "/static/tab/admin-my.png",
selectedIconPath: "/static/tab/admin-my-active.png",
2025-04-15 10:07:11 +08:00
text: "设置",
},
];
this.$u.vuex("vuex_tabbar", normalTabBar);
2025-04-15 11:22:20 +08:00
this.loginFn("user");
2025-04-14 14:29:21 +08:00
},
login2Fn() {
this.phone = "18174010562";
this.pwd = "123456";
2025-04-15 10:07:11 +08:00
const adminTabBar = [
{
pagePath: "/pages/adminHome/index",
2025-04-15 15:40:25 +08:00
iconPath: "/static/tab/admin-home.png",
selectedIconPath: "/static/tab/admin-home-acitve.png",
2025-04-15 10:07:11 +08:00
text: "首页",
},
{
pagePath: "/pages/adminNfc/index",
2025-04-15 14:37:47 +08:00
iconPath: "/static/tab/nfc.png",
selectedIconPath: "/static/tab/nfc-active.png",
2025-04-15 10:07:11 +08:00
text: "nfc写入",
},
{
pagePath: "/pages/adminMy/index",
2025-04-15 15:40:25 +08:00
iconPath: "/static/tab/admin-my.png",
selectedIconPath: "/static/tab/admin-my-active.png",
2025-04-15 10:07:11 +08:00
text: "我的",
},
];
this.$u.vuex("vuex_tabbar", adminTabBar);
2025-04-15 11:22:20 +08:00
this.loginFn("admin");
2025-04-14 14:29:21 +08:00
},
2025-04-18 11:55:50 +08:00
login4Fn() {
this.phone = "18174010562";
this.pwd = "123456";
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);
this.loginFn("user");
},
login3Fn() {
this.phone = "18174010561";
this.pwd = "123456";
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);
this.loginFn("user");
},
2025-04-15 10:07:11 +08:00
async loginFn(type) {
2025-04-14 14:29:21 +08:00
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);
2025-04-15 11:22:20 +08:00
console.log(type, "type--");
if (type === "user") {
2025-04-15 10:07:11 +08:00
uni.switchTab({
url: `/pages/index/planList`,
});
2025-04-15 11:22:20 +08:00
}
if (type === "admin") {
2025-04-15 10:07:11 +08:00
uni.switchTab({
url: `/pages/adminHome/index`,
});
}
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>