Selaa lähdekoodia

Merge branch '长阳分支中职' of http://123.57.209.16:3000/bjquanjiang/DigitalScholl into 长阳分支中职

新疆警官学校中职
ndbs 2 vuotta sitten
vanhempi
commit
ed44aa79cd
1 muutettua tiedostoa jossa 341 lisäystä ja 281 poistoa
  1. +341
    -281
      Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/login.vue

+ 341
- 281
Learun.Framework.Ultimate V7/LearunApp-2.2.0/pages/login.vue Näytä tiedosto

@@ -1,308 +1,368 @@
<template>
<view class="page">
<image src="@/static/login-banner.png" mode="widthFix" style="width:100%;margin-bottom: 12px;position: absolute;top: 0;"></image>
<view class="content" style="padding-bottom:60px">
<view style="padding: 0 38px;">
<view class="head-banner">
<!-- 标题文字 -->
<view class="main-title">
数字化智慧校园
<!-- <text v-if="DEV" class="margin-left-sm text-red">(开发模式)</text> -->
<text class="text-gray margin-left-sm" style="font-size: 0.7em;">{{ APP_VERSION }}</text>
</view>
<!-- 首页 Logo -->
<view mode="aspectFit" class="logo">
<image src="~@/static/logo.dc7ee5a9.png" mode="widthFix" class="logoImg"></image>
</view>
<!-- 【仅生产环境】使用账号的原因,无此项则微信审核通不过 -->
<!-- <view v-if="!DEV" class="intro">
<view class="page">
<image src="@/static/login-banner.png" mode="widthFix" style="width:100%;margin-bottom: 12px;"></image>
<view class="content" style="padding-bottom:60px">
<view style="padding: 0 38px;">
<view class="head-banner">
<!-- 标题文字 -->
<view class="main-title">
数字化智慧校园
<!-- <text v-if="DEV" class="margin-left-sm text-red">(开发模式)</text> -->
<text class="text-gray margin-left-sm" style="font-size: 0.7em;">{{ APP_VERSION }}</text>
</view>
<!-- 首页 Logo -->
<view mode="aspectFit" class="logo">
<image src="~@/static/logo.dc7ee5a9.png" mode="widthFix" class="logoImg"></image>
</view>
<!-- 【仅生产环境】使用账号的原因,无此项则微信审核通不过 -->
<!-- <view v-if="!DEV" class="intro">
<view class="intro">注册登录智慧校园账号后,您将可以体验力软框架产品中的所有功能与业务</view>
<view class="intro">OA · 进销存 · 工作流审批 · 数据可视化</view>
<view class="intro text-gray" style="font-size: 0.9em;">
如果您之前已在智慧校园 PC 端中注册过体验账号,可以直接使用原账号登录,无需另行注册
</view>
</view> -->
</view>
<!-- 账户密码表单 -->
<l-input v-if="ready" v-model="username" placeholder="账号" left>
<l-icon slot="title" type="people" />
</l-input>
<l-input v-if="ready" v-model="password" placeholder="请输入密码" password left>
<l-icon slot="title" type="lock" />
</l-input>
<l-button @click="login(null)" size="lg" color="blue" class="margin-top-sm block" block>登 录</l-button>
<view class="otherLogin">
<navigator url="/pages/weixinLogin" class="textBtn">微信登录</text></navigator>
</view>
<!-- <l-button v-if="enableSignUp" @click="signUp" size="lg" line="blue" class="margin-top-sm block" block>
</view>
<!-- 账户密码表单 -->
<l-input v-if="ready" v-model="username" placeholder="账号" left>
<l-icon slot="title" type="people" />
</l-input>
<l-input v-if="ready" v-model="password" placeholder="请输入密码" password left>
<l-icon slot="title" type="lock" />
</l-input>
<l-button @click="login(null)" size="lg" color="blue" class="margin-top-sm block" block>登 录</l-button>
<view class="otherLogin">
<navigator url="/pages/weixinLogin" class="textBtn">微信登录</text></navigator>
</view>
<!-- <l-button v-if="enableSignUp" @click="signUp" size="lg" line="blue" class="margin-top-sm block" block>
教师注册
</l-button> -->

<!-- 【仅小程序】一键登录按钮 -->
<!-- #ifdef MP -->
<l-button v-if="MPLogin" @click="login(PLATFORM)" size="lg" line="green" class="margin-top-sm block" block>
{{ PLATFORM_TEXT }}一键登录
</l-button>
<!-- #endif -->
<!-- 【仅小程序】一键登录按钮 -->
<!-- #ifdef MP -->
<l-button v-if="MPLogin" @click="login(PLATFORM)" size="lg" line="green" class="margin-top-sm block"
block>
{{ PLATFORM_TEXT }}一键登录
</l-button>
<!-- #endif -->

<!-- 【仅开发模式】显示,后台地址切换 -->
<!-- <view v-if="DEV" class="more">
<!-- 【仅开发模式】显示,后台地址切换 -->
<!-- <view v-if="DEV" class="more">
<view @click="showApiRootSelector = true" class="morebtn">后台地址(点击切换):</view>
<view class="morebtn">{{ currentApiRoot }}</view>
</view> -->

<!-- 【仅开发模式】选择 API 地址的弹层 -->
<l-modal
v-if="DEV && ready"
v-model="showApiRootSelector"
@radioIndex="changeApiRoot"
:radio="currentApiRoot"
:range="apiRootList"
type="radio"
/>
</view>
</view>
<!-- 页面底部版权文字 -->
<view class="footer">{{ copyRightDisplay }}</view>
</view>
<!-- 【仅开发模式】选择 API 地址的弹层 -->
<l-modal v-if="DEV && ready" v-model="showApiRootSelector" @radioIndex="changeApiRoot"
:radio="currentApiRoot" :range="apiRootList" type="radio" />

</view>
</view>
<!-- 页面底部版权文字 -->
<view class="footer" v-show="hideshow">{{ copyRightDisplay }}</view>
</view>
</template>

<script>
export default {
data() {
return {
username: '',
password: '',

ready: false,
showApiRootSelector: false,

currentApiRoot: '',
apiRootList: [],
devAccountList: []
}
},

async onLoad() {
await this.init()
},

methods: {
// 页面初始化
async init() {
const index = this.DEV ? this.CONFIG('devApiHostIndex') : this.CONFIG('prodApiHostIndex')
this.apiRootList = this.CONFIG('apiHost')
this.currentApiRoot = this.apiRootList[index]

// 如果是开发模式,填入测试账号密码
if (this.DEV) {
this.devAccountList = this.CONFIG('devAccount')
const account = this.devAccountList[index] || { username: '', password: '' }
this.username = account.username
this.password = account.password
}
this.ready = true
},

// 点击新用户注册
signUp() {
this.NAV_TO('/pages/signup')
},

// 切换后台地址
changeApiRoot(newIndex) {
const newApiRoot = this.apiRootList[newIndex]
this.currentApiRoot = newApiRoot
this.SET_GLOBAL('apiRoot', newApiRoot)

// 如果是开发模式,填入测试账号密码
if (this.DEV && this.devAccountList && this.devAccountList[newIndex]) {
const account = this.devAccountList[newIndex] || { username: '', password: '' }
this.username = account.username
this.password = account.password
}
},

// 发起登录
// type=null 时表示使用账号密码登录
// type='weixin'/'alipay'/'dingtalk' 时表示使用小程序一键登录
async login(type) {
const { username, password, check } = this

// 账号密码登录时,验证输入,输入有误则返回
if (!type && !check()) {
return
}
this.LOADING('登录中…')

// 根据不同的登录方式,调用 API
let loginResult = null

// 不是小程序,则提交用户名、密码登录
// 是小程序,则申请授权码登录
if (!type) {
let postResult = await this.POST('learun/adms/user/login', { username, password: this.MD5(password) })
if(postResult[1].data.code=='200'){
loginResult=postResult[1].data.data;
}else{
this.TOAST(postResult[1].data.info);
}
} else {
const [codeErr, { code } = {}] = await uni.login({ provider: type })
if (codeErr || !code) {
this.HIDE_LOADING()
this.CONFIRM('登录失败', '无法获取小程序登录授权码')
return
}

loginResult = await this.HTTP_POST('learun/adms/user/openid_login', { code, type }, '登录时发生错误')
}

if (!loginResult) {
return
}

// loginUser 中合并 role、post 两个字段
const { baseinfo, mpinfo, post, role } = loginResult
const user = { ...baseinfo, post, role }
const token = baseinfo.token

// 返回的用户信息中,有 mpinfo 字段表示是否是小程序
if (mpinfo && Array.isArray(mpinfo) && mpinfo.includes(type)) {
user.miniProgram = true
}

this.SET_GLOBAL('token', token)
this.SET_GLOBAL('loginUser', user)

this.SET_STORAGE('token', token)

this.HIDE_LOADING()
this.TAB_TO('/pages/home')
},

// 验证用户输入
check() {
const { username, password } = this
if (username.length <= 0 || password.length <= 0) {
this.CONFIRM('输入错误', '账号或密码不能为空,请重新输入')
return false
}

return true
}
},

computed: {
// 页面底部公司名、版权信息
copyRightDisplay() {
const year = new Date().getFullYear()
const company = this.CONFIG('company')

return `Copyright © ${year} ${company}`
},

// 是否显示小程序登录按键
MPLogin() {
return this.CONFIG(`miniProgramAccount.${this.PLATFORM}`).includes('login')
},

// 是否展示注册按钮
enableSignUp() {
return this.CONFIG('enableSignUp')
}
}
}
export default {
data() {
return {
username: '',
password: '',
ready: false,
showApiRootSelector: false,
currentApiRoot: '',
apiRootList: [],
devAccountList: [],

docmHeight: document.documentElement.clientHeight || document.body.clientHeight,
showHeight: document.documentElement.clientHeight || document.body.clientHeight,
hideshow: true
}
},

async onLoad() {
await this.init()
},
watch: {
//监听显示高度
showHeight:function() {
if(this.docmHeight > this.showHeight){
//隐藏
this.hideshow=false
}else{
//显示
this.hideshow=true
}
}
},
mounted() {
//监听事件
window.onresize = ()=>{
return(()=>{
this.showHeight = document.documentElement.clientHeight || document.body.clientHeight;
})()
}
},
methods: {
// 页面初始化
async init() {
const index = this.DEV ? this.CONFIG('devApiHostIndex') : this.CONFIG('prodApiHostIndex')
this.apiRootList = this.CONFIG('apiHost')
this.currentApiRoot = this.apiRootList[index]

// 如果是开发模式,填入测试账号密码
if (this.DEV) {
this.devAccountList = this.CONFIG('devAccount')
const account = this.devAccountList[index] || {
username: '',
password: ''
}
this.username = account.username
this.password = account.password
}
this.ready = true
},

// 点击新用户注册
signUp() {
this.NAV_TO('/pages/signup')
},

// 切换后台地址
changeApiRoot(newIndex) {
const newApiRoot = this.apiRootList[newIndex]
this.currentApiRoot = newApiRoot
this.SET_GLOBAL('apiRoot', newApiRoot)

// 如果是开发模式,填入测试账号密码
if (this.DEV && this.devAccountList && this.devAccountList[newIndex]) {
const account = this.devAccountList[newIndex] || {
username: '',
password: ''
}
this.username = account.username
this.password = account.password
}
},

// 发起登录
// type=null 时表示使用账号密码登录
// type='weixin'/'alipay'/'dingtalk' 时表示使用小程序一键登录
async login(type) {
const {
username,
password,
check
} = this

// 账号密码登录时,验证输入,输入有误则返回
if (!type && !check()) {
return
}
this.LOADING('登录中…')

// 根据不同的登录方式,调用 API
let loginResult = null

// 不是小程序,则提交用户名、密码登录
// 是小程序,则申请授权码登录
if (!type) {
let postResult = await this.POST('learun/adms/user/login', {
username,
password: this.MD5(password)
})
if (postResult[1].data.code == '200') {
loginResult = postResult[1].data.data;
} else {
this.TOAST(postResult[1].data.info);
}
} else {
const [codeErr, {
code
} = {}] = await uni.login({
provider: type
})
if (codeErr || !code) {
this.HIDE_LOADING()
this.CONFIRM('登录失败', '无法获取小程序登录授权码')
return
}

loginResult = await this.HTTP_POST('learun/adms/user/openid_login', {
code,
type
}, '登录时发生错误')
}

if (!loginResult) {
return
}

// loginUser 中合并 role、post 两个字段
const {
baseinfo,
mpinfo,
post,
role
} = loginResult
const user = {
...baseinfo,
post,
role
}
const token = baseinfo.token

// 返回的用户信息中,有 mpinfo 字段表示是否是小程序
if (mpinfo && Array.isArray(mpinfo) && mpinfo.includes(type)) {
user.miniProgram = true
}

this.SET_GLOBAL('token', token)
this.SET_GLOBAL('loginUser', user)

this.SET_STORAGE('token', token)

this.HIDE_LOADING()
this.TAB_TO('/pages/home')
},

// 验证用户输入
check() {
const {
username,
password
} = this
if (username.length <= 0 || password.length <= 0) {
this.CONFIRM('输入错误', '账号或密码不能为空,请重新输入')
return false
}

return true
}
},

computed: {
// 页面底部公司名、版权信息
copyRightDisplay() {
const year = new Date().getFullYear()
const company = this.CONFIG('company')

return `Copyright © ${year} ${company}`
},

// 是否显示小程序登录按键
MPLogin() {
return this.CONFIG(`miniProgramAccount.${this.PLATFORM}`).includes('login')
},

// 是否展示注册按钮
enableSignUp() {
return this.CONFIG('enableSignUp')
}
}
}
</script>

<style lang="less">
page {
height: 100%;
}

/* #ifdef MP-ALIPAY */
.page {
height: 100%;
position: absolute;
}
/* #endif */
page {
height: 100%;
}

/* #ifdef MP-ALIPAY */
.page {
height: 100%;
position: absolute;
}

/* #endif */
</style>

<style lang="less" scoped>
.page {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;

.content {
text-align: center;
width: 100%;
// padding: 0 38rpx;
}

.head-banner {
margin-bottom: 40rpx;

.logo {
// background-image: url('~@/static/logo.png');
background-size: contain;
height: 120rpx;
width: 120rpx;
text-align: center;
display: inline-block;
border-radius: 5px;
}
.logoImg {
body {
width: 100%;
height: 100%;
position: ;
}

.page {
height: 100%;
width: 100%;
// display: flex;
// justify-content: center;
// align-items: center;

.content {
text-align: center;
width: 100%;
// padding: 0 38rpx;
}

.head-banner {
margin-bottom: 40rpx;

.logo {
// background-image: url('~@/static/logo.png');
background-size: contain;
height: 120rpx;
width: 120rpx;
text-align: center;
display: inline-block;
border-radius: 5px;
}

.logoImg {
width: 100%;
}

.main-title {
display: block;
margin: 20rpx 0;
color: #555;
font-size: 1.4em;
margin-bottom: 30rpx;
}

.intro {
margin-top: 20rpx;
}
}

.more {
margin-top: 30rpx;

.morebtn {
color: #555;
}
}

.otherLogin {
display: flex;
justify-content: flex-end;

.textBtn {
width: 100px;
color: #606266;
}
}

.footer {
position: absolute;
left: 0;
right: 0;
bottom: 10px;
bottom: calc(10px + env(safe-area-inset-bottom));
text-align: center;
font-size: 14px;
color: #555;

/* #ifdef MP-ALIPAY */
bottom: 10px;
/* #endif */
}
}
.main-title {
display: block;
margin: 20rpx 0;
color: #555;
font-size: 1.4em;
margin-bottom: 30rpx;
}

.intro {
margin-top: 20rpx;
}
}

.more {
margin-top: 30rpx;

.morebtn {
color: #555;
}
}
.otherLogin{
display: flex;
justify-content: flex-end;
.textBtn{
width: 100px;
color: #606266;
}
}

.footer {
position: absolute;
left: 0;
right: 0;
bottom: 10px;
bottom: calc(10px + env(safe-area-inset-bottom));
text-align: center;
font-size: 14px;
color: #555;

/* #ifdef MP-ALIPAY */
bottom: 10px;
/* #endif */
}
}
</style>

Ladataan…
Peruuta
Tallenna