| | |
| | | <view class="container"> |
| | | <view class="content"> |
| | | <view class="top"> |
| | | <image class="top-bg" :src="BASE_URL + '/upload' + '/qingYuan/images/20241126/2f56a2a7ecfd2544dec5978d2687383e.png'" mode="widthFix"></image> |
| | | <image class="top-bg" src="../../static/images/login/top_bg.png" mode="widthFix"></image> |
| | | <view class="top--title"> |
| | | <image class="logo" src="../../static/images/login/logo.png "></image> |
| | | <view class="text">慧物通直饮水</view> |
| | |
| | | </view> |
| | | </view> |
| | | </view> |
| | | <view class="switch-btn" @click="changeLoginType"> |
| | | <!-- <view class="switch-btn" @click="changeLoginType"> |
| | | <text v-if="loginType == 0">切换微信登录</text> |
| | | <text v-if="loginType == 1">切换管理员登录</text> |
| | | <image class="switch-to" src="../../static/images/login/switchto.svg"></image> |
| | | </view> |
| | | </view> --> |
| | | </view> |
| | | </view> |
| | | </template> |
| | |
| | | <script setup> |
| | | import {ref, onMounted} from 'vue' |
| | | import { BASE_URL } from '../../config/index.js'; |
| | | import { wxLoginApi } from '../../api/index.js' |
| | | |
| | | const loginType = ref(1) |
| | | const form = ref({userName:'',password:''}) |
| | |
| | | if(res.code == 200){ |
| | | uni.setStorageSync('maintainId',JSON.stringify(res.data.id)) |
| | | uni.setStorageSync('token',res.data.token) |
| | | uni.redirectTo({ |
| | | uni.switchTab({ |
| | | url:'/pages/index/index' |
| | | }) |
| | | } |
| | |
| | | } |
| | | |
| | | //用户点击微信登录默认授权 |
| | | function wxLogin(){ |
| | | const wxLogin = () => { |
| | | wx.login({ |
| | | success:async (res1)=>{ |
| | | success:(res1)=>{ |
| | | //存储微信登录的code,调用后端接口传递code参数,返回openid(也就是userId)存储到本地,通过判断本地是否存在openId,存在表示已登录 |
| | | uni.setStorageSync('code',res1.code) |
| | | await wxLoginApi({code:res1.code}).then((res2) =>{ |
| | | wxLoginApi({code:res1.code}).then((res2) =>{ |
| | | if(res2.code == 200){ |
| | | uni.redirectTo({ |
| | | url:'/pages/index/index' |
| | | }) |
| | | uni.setStorageSync('openId',res2.data.userId) |
| | | uni.setStorageSync('token',res2.data.token) |
| | | uni.switchTab({ |
| | | url:'/pages/index/index' |
| | | }) |
| | | }else{ |
| | | uni.showToast({ |
| | | title:'登录失败', |
| | | icon:'none', |
| | | |
| | | }) |
| | | } |
| | | }) |
| | |
| | | |
| | | onMounted(() => { |
| | | if(uni.getStorageSync('openId') && uni.getStorageSync('token')){ |
| | | uni.redirectTo({ |
| | | uni.switchTab({ |
| | | url:'/pages/index/index' |
| | | }) |
| | | } |