This commit is contained in:
weiwei committed 2025-04-25 16:22:32 +08:00
1 parent 4f480a9927
commit 498914d8ad
1 file changed
+30 -15
+30 -15
View File
@@ -1,18 +1,25 @@
<template>
<view v-if="!isDevEnv()" class="card p-x-30rpx p-y-40rpx my-5 m-4">
<tm-form ref="applyFormRef" v-model="applyForm" :rules="applyFormRules" direction="vertical">
<tm-form-item name="username" label="用户名" :showBottom="false">
<tm-input v-model="applyForm.username" placeholder="请输入用户名..." />
</tm-form-item>
<view class="h-10rpx" />
<tm-form-item name="password" label="密码" :showBottom="false">
<tm-input password showEye v-model="applyForm.password" placeholder="请输入用户密码..." />
</tm-form-item>
</tm-form>
<tm-button block @tap="doSubmit">登录</tm-button>
</view>
<view class="bg-#F8F8F8 w-full h-screen overflow-hidden">
<view class="card p-30rpx m-4">
<view class="text-lg text-center my-1">员工登录</view>
<tm-form ref="applyFormRef" v-model="applyForm" :rules="applyFormRules" direction="vertical">
<tm-form-item name="username" label="用户名" :showBottom="false">
<tm-input v-model="applyForm.username" placeholder="请输入用户名..." />
</tm-form-item>
<view class="h-10rpx" />
<tm-form-item name="password" label="密码" :showBottom="false">
<tm-input password showEye v-model="applyForm.password" placeholder="请输入用户密码..." />
</tm-form-item>
</tm-form>
<button class="bg-#0779fd rounded-2 c-white text-lg py-2 mx-4 my-1/2" open-type="getUserInfo" @click="getUserInfo">微信登录</button>
<tm-button block @tap="doSubmit">登录</tm-button>
</view>
<view class="card p-30rpx m-4">
<view class="text-lg text-center my-1">访客登录</view>
<button class="bg-#0779fd rounded-3 c-white text-lg py-2" open-type="getUserInfo" @click="getUserInfo">微信登录</button>
</view>
</view>
</template>
<script setup lang="ts">
@@ -60,6 +67,7 @@ const doSubmit = async () => {
// 获取用户信息
const getUserInfo = () => {
uni.showLoading({ title: "登录中...", mask: true })
uni.getUserInfo({
success: (res) => {
// 存储用户信息
@@ -71,11 +79,15 @@ const getUserInfo = () => {
fail: (res) => {
return uni.showToast({ title: "获取用户信息失败", icon: "error" })
},
complete: () => {
uni.hideLoading()
},
})
}
// 登录
const login = async () => {
uni.showLoading({ title: "登录中...", mask: true })
const result = await uni.login({ provider: "weixin" }).catch((error) => error)
if (result.errMsg === "login:ok") {
console.log("code", result.code)
@@ -83,12 +95,15 @@ const login = async () => {
const res: any = await userApi.mnpLogin(result.code)
if (res.code == 0) {
uni.setStorageSync(tokenKey, res.data)
uni.hideLoading()
uni.showToast({ title: "登录成功", icon: "none" })
router.back()
return uni.showToast({ title: "登录成功", icon: "none" })
} else {
return uni.showToast({ title: "获取token失败", icon: "error" })
uni.hideLoading()
uni.showToast({ title: "获取token失败", icon: "error" })
}
} else {
uni.hideLoading()
uni.showToast({ title: "获取登录code失败", icon: "error" })
}
}