123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- <template>
-
- <view class="login-view">
- <image src="../../static/img/logo2.png" mode="widthFix"></image>
- <view class="login-text">测绘地理信息学院仪享云</view>
- <view class="login-text1">
-
- </view>
-
- </view>
- <view class="logo_sru">
- <view>
- <uni-forms ref="form" :modelValue="formData">
- <view class="denru">
- <uni-easyinput prefixIcon="person" v-model="formData.account" type="text" placeholder="请输入账号" />
- </view>
- <view class="denru">
- <uni-easyinput prefixIcon="locked" v-model="formData.password" type="password" placeholder="请输入密码" />
- </view>
- <button class="button" @click="submit" style="background-color:#2d8cf0 ; color: #fff; " >密码登录</button>
- </uni-forms>
- </view>
- <view class="" style="margin-top: 30rpx;">
- <button @click="login" type="primary">微信一键登录</button>
- </view>
- </view>
- <view class="student_login">
- <button v-if="studentData.errcode!=0" open-type="getPhoneNumber" @getphonenumber="studentLogin" size="mini" style="background-color:#2d8cf0 ; color: #fff;height: 70rpx; line-height: 70rpx;">学生登录</button>
- <button v-if="studentData.errcode==0" @click="studentLogin2" size="mini" style="background-color:#2d8cf0 ; color: #fff;height: 70rpx; line-height: 70rpx;">学生登录</button>
- </view>
-
- </template>
- <script setup lang="ts">
- import {requestApi } from '@/api/request.js'
- import { reactive, ref } from 'vue'
-
- import {onShow,onUnload} from '@dcloudio/uni-app'
- let studentData=ref(null)
- studentData.value = wx.getStorageSync('studentData')
- {
- // console.log(studentData)
- // }else if(studentData.value == null){
- // 进学生端,获取手机号
- async function studentLogin(e) {
- console.log(e)
- var detail = e.detail
- if (detail.errMsg == "getPhoneNumber:ok") {
- console.log("用户同意授权")
- var code = detail.code
- // console.log(code)
- const studentData= await requestApi(
- 'api/xmwechat.Miniprogram/getPhoneNumber?server=1',
- {
- code:code,
- },
- 'POST'
- )
- console.log(studentData)
- if(studentData.code==1){
- wx.showLoading({
- title: '加载中',
- })
-
- wx.setStorageSync('studentData',studentData.data)
- setTimeout(function () {
- wx.hideLoading()
- }, 1000)
- wx.reLaunch({
- url: '/pages/student/index'
- })
- }
-
- }
- }
- function studentLogin2() {
- wx.reLaunch({
- url: '/pages/student/index'
- })
- }
- onShow(async () => {
- //
- const logo =wx.getStorageSync('userInfos')
- if(logo.userInfo.group==1 || logo.userInfo.group==2 || logo.userInfo.group==3){
- wx.switchTab({
- url:'/pages/index/index'
- })
- }else if(logo.userInfo.group==4){
- wx.reLaunch({
- url: '/pages/teacher/navigation'
- })
- }
- })
- async function login(){
- wx.showLoading({title:'登录中'})
- wx.login({
- success:async(res)=>{
- console.log(res)
- // 使用await requestApi(...)调用封装好的API请求函数,向后端服务器发送POST请求到'/wxLogin'接口,
- // 并携带appid、secret(这两个参数是与微信小程序相关的应用ID和密钥)以及从微信登录接口获取到的code。
- // await requestApi(...)会等待后端接口返回数据,然后将结果赋值给userData。
- const userData= await requestApi(
- 'admin/Miniprogram/miniprogramLogin?server=1',
- {
- code:res.code,
- },
- 'POST'
- )
- const logo = userData.data
-
- {wx.setStorageSync('userInfo',userData)}
- {
- // console.log(userData)
- // }
- console.log('userData',userData)
- wx.setStorageSync('userInfos',userData.data)
- {title:'登录中'})
- wx.hideLoading()
- if(userData.data == null){
- wx.showModal({
- title: '提示',
- content: '您尚未绑定微信,请先账号密码登录',
- showCancel:false,
- success () {
-
- }
- })
-
- }else{
- wx.showLoading({title:'登录中'})
- if(logo.userInfo.group==1 || logo.userInfo.group==2 || logo.userInfo.group==3){
- wx.switchTab({
- url:'/pages/index/index'
- })
- }else if(logo.userInfo.group==4){
- wx.reLaunch({
- url: '/pages/teacher/navigation'
- })
- }
- }
- setTimeout(function () {
- wx.hideLoading()
- }, 2000)
- }
- })
- }
- const formData= ref({
- account:'',
- password:''
- })
- async function submit(){
- // console.log('success',formData)
- // console.log(formData.value.account)
- wx.showLoading({title:'登录中'})
- const denru= await requestApi(
- 'admin/Index/mplogin?server=1',
- {
- // 数据
- username:formData.value.account,
- password:formData.value.password
- },
- 'POST'
- )
- console.log(denru)
-
-
- wx.showLoading({title:denru.msg})
- {title:})
- setTimeout(function () {
- wx.hideLoading()
- }, 2000)
-
- const logo = denru.data
-
-
- if(logo.userInfo.wxbind != null){
- if(logo.userInfo.group==1 || logo.userInfo.group==2 || logo.userInfo.group==3){
- wx.switchTab({
- url:'/pages/index/index'
- })
- }else if(logo.userInfo.group==4){
- wx.reLaunch({
- url: '/pages/teacher/navigation'
- })
- }
-
- wx.setStorageSync('userInfos',denru.data)
- }
- else{
- wx.hideLoading()
- wx.showModal({
- title: '微信绑定',
- content: '请绑定您的微信账号,以便微信登录',
- showCancel:false,
- confirmText:'绑定',
- success () {
- wx.login({
- success:async(res)=>{
- console.log('用户点击确定')
- console.log(logo.userInfo.id)
- wx.showLoading({title:'绑定中'})
- const banden= await requestApi(
- 'admin/Miniprogram/miniprogramBind?server=1',
- {
- // 数据
- uid:logo.userInfo.id,
- code:res.code,
- },
- 'POST'
- )
- wx.hideLoading()
-
- wx.setStorageSync('userInfos',denru.data)
- if(logo.userInfo.group==1 || logo.userInfo.group==2 || logo.userInfo.group==3){
- wx.switchTab({
- url:'/pages/index/index'
- })
- }else if(logo.userInfo.group==4){
- wx.reLaunch({
- url: '/pages/teacher/navigation'
- })
- }
- }
- })}
- })
- }
- // console.log(logo.userInfo.group)
- }
- </script >
- <style scoped>
- .student_login{
- position: absolute;
- bottom: 30rpx;
- left: 30rpx;
- }
- .logo_bg{
- position: absolute;
- top: 0;
- width: 100%;
- height: 100%;
- z-index: -1;
- }
- .logo_bg image{
- width: 100%;
- height: 100%;
- }
- .login-text1{
- color: #808695;
- }
- .login-view{
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 0 80rpx;
- margin-top: 200rpx;
- font-size: 35rpx;
- }
- .login-view image{
- width: 200rpx;
-
- }
- .denru{
- margin-bottom: 30rpx;
- }
- .login-view button{
- width: 100%;
- margin-top: 600rpx;
- background-color:#2d8cf0;
- color: #fff;
- border:#2d8cf0;
- }
- .login-text{
- margin-top: 20rpx;
- font-size: 50rpx;
- }
- .logo_sru{
- width: 90%;
- margin: 0 auto;
- margin-top: 50rpx;
- }
-
- </style>
|