Browse Source

登录

shibei_master
jiangyy 4 years ago
parent
commit
38995cc66a
  1. 155
      src/views/pages/login copy.vue
  2. 321
      src/views/pages/login.vue

155
src/views/pages/login copy.vue

@ -0,0 +1,155 @@
<template>
<div class="aui-wrapper aui-page__login">
<div class="aui-content__wrapper">
<main class="aui-content">
<div class="login-header">
<h2 class="login-brand">{{ $t('brand.lg') }}</h2>
</div>
<div class="login-body">
<h3 class="login-title">{{ $t('login.title') }}</h3>
<el-form :model="dataForm"
:rules="dataRule"
ref="dataForm"
@keyup.enter.native="dataFormSubmitHandle()"
status-icon>
<!-- <el-form-item>
<el-select v-model="$i18n.locale"
class="w-percent-100">
<el-option v-for="(val, key) in i18nMessages"
:key="key"
:label="val._lang"
:value="key"></el-option>
</el-select>
</el-form-item> -->
<el-form-item prop="phone">
<el-input v-model="dataForm.phone"
placeholder="手机号">
<span slot="prefix"
class="el-input__icon">
<svg class="icon-svg"
aria-hidden="true">
<use xlink:href="#icon-user"></use>
</svg>
</span>
</el-input>
</el-form-item>
<el-form-item prop="password">
<el-input v-model="dataForm.password"
type="password"
:placeholder="$t('login.password')">
<span slot="prefix"
class="el-input__icon">
<svg class="icon-svg"
aria-hidden="true">
<use xlink:href="#icon-lock"></use>
</svg>
</span>
</el-input>
</el-form-item>
<el-form-item prop="captcha">
<el-row :gutter="20">
<el-col :span="14">
<el-input v-model="dataForm.captcha"
:placeholder="$t('login.captcha')">
<span slot="prefix"
class="el-input__icon">
<svg class="icon-svg"
aria-hidden="true">
<use xlink:href="#icon-safetycertificate"></use>
</svg>
</span>
</el-input>
</el-col>
<el-col :span="10"
class="login-captcha">
<img :src="captchaPath"
@click="getCaptcha()">
</el-col>
</el-row>
</el-form-item>
<el-form-item>
<el-button type="primary"
@click="dataFormSubmitHandle()"
class="w-percent-100">{{ $t('login.title') }}</el-button>
</el-form-item>
</el-form>
</div>
<div class="login-footer">
<p>
<a href="https://demo.cloud.renren.io/renren-cloud"
target="_blank">{{ $t('login.demo') }}</a>
</p>
<!-- 2020 © renren.io -->
<p><a href="https://www.renren.io/"
target="_blank">{{ $t('login.copyright') }}</a></p>
</div>
</main>
</div>
</div>
</template>
<script>
import Cookies from 'js-cookie'
import debounce from 'lodash/debounce'
import { messages } from '@/i18n'
import { getUUID } from '@/utils'
export default {
data () {
return {
i18nMessages: messages,
captchaPath: '',
dataForm: {
app: 'oper',
client: 'web',
username: '',
phone: '',
password: '',
uuid: '',
captcha: ''
}
}
},
computed: {
dataRule () {
return {
phone: [
{ required: true, message: '手机号不能为空', trigger: 'blur' }
],
password: [
{ required: true, message: '密码不能为空', trigger: 'blur' }
],
captcha: [
{ required: true, message: '验证码不能为空', trigger: 'blur' }
]
}
}
},
created () {
this.getCaptcha()
},
methods: {
//
getCaptcha () {
this.dataForm.uuid = getUUID()
this.captchaPath = `${window.SITE_CONFIG['apiURL']}/auth/login/captcha?uuid=${this.dataForm.uuid}`
},
//
dataFormSubmitHandle: debounce(function () {
this.$refs['dataForm'].validate((valid, messageObj) => {
if (!valid) {
app.util.validateRule(messageObj)
}
this.$http.post('/auth/login/operweb/loginbypassword', this.dataForm).then(({ data: res }) => {
if (res.code !== 0) {
this.getCaptcha()
return this.$message.error(res.msg)
}
localStorage.setItem('userType', 'oper')
Cookies.set('token', res.data.token)
this.$router.replace({ name: 'home' }).catch(() => { })
}).catch(() => { })
})
}, 1000, { 'leading': true, 'trailing': false })
}
}
</script>

321
src/views/pages/login.vue

@ -1,120 +1,132 @@
<template> <template>
<div class="aui-wrapper aui-page__login"> <div class="g-app">
<div class="aui-content__wrapper"> <div class="g-bd"
<main class="aui-content"> v-if="isShowLogin || true">
<div class="login-header"> <div class="m-fm">
<h2 class="login-brand">{{ $t('brand.lg') }}</h2> <div class="wrap">
</div> <h2 class="title">{{ $t('brand.work') }}</h2>
<div class="login-body"> <div class="fm">
<h3 class="login-title">{{ $t('login.title') }}</h3> <el-form :model="dataForm"
<el-form :model="dataForm" :rules="dataRule"
:rules="dataRule" ref="dataForm"
ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()"
@keyup.enter.native="dataFormSubmitHandle()" status-icon>
status-icon> <div class="fm-item">
<!-- <el-form-item> <div class="ico">
<el-select v-model="$i18n.locale" <img src="@/assets/img/login/zhanghao.png"
class="w-percent-100"> alt="" />
<el-option v-for="(val, key) in i18nMessages" </div>
:key="key" <div class="input">
:label="val._lang" <input type="text"
:value="key"></el-option> v-model="dataForm.phone"
</el-select> placeholder="账号" />
</el-form-item> --> </div>
<el-form-item prop="phone"> </div>
<el-input v-model="dataForm.phone" <div class="fm-item">
placeholder="手机号"> <div class="ico">
<span slot="prefix" <img src="@/assets/img/login/mima.png"
class="el-input__icon"> alt="" />
<svg class="icon-svg" </div>
aria-hidden="true"> <div class="input">
<use xlink:href="#icon-user"></use> <input type="password"
</svg> v-model="dataForm.password"
</span> :placeholder="$t('login.password')" />
</el-input> </div>
</el-form-item> </div>
<el-form-item prop="password"> <div class="fm-captcha">
<el-input v-model="dataForm.password" <div class="fm-item">
type="password" <div class="input">
:placeholder="$t('login.password')"> <input type="text"
<span slot="prefix" v-model="dataForm.captcha"
class="el-input__icon"> placeholder="验证码" />
<svg class="icon-svg" </div>
aria-hidden="true"> </div>
<use xlink:href="#icon-lock"></use> <div class="captcha">
</svg>
</span>
</el-input>
</el-form-item>
<el-form-item prop="captcha">
<el-row :gutter="20">
<el-col :span="14">
<el-input v-model="dataForm.captcha"
:placeholder="$t('login.captcha')">
<span slot="prefix"
class="el-input__icon">
<svg class="icon-svg"
aria-hidden="true">
<use xlink:href="#icon-safetycertificate"></use>
</svg>
</span>
</el-input>
</el-col>
<el-col :span="10"
class="login-captcha">
<img :src="captchaPath" <img :src="captchaPath"
@click="getCaptcha()"> @click="getCaptcha()" />
</el-col> </div>
</el-row> </div>
</el-form-item>
<el-form-item> <div class="fm-btn"
<el-button type="primary" @click="dataFormSubmitHandle()">
@click="dataFormSubmitHandle()" {{ $t('login.title') }}
class="w-percent-100">{{ $t('login.title') }}</el-button> </div>
</el-form-item> <div class="hint">请使用小程序端的账号密码登录</div>
</el-form> </el-form>
</div>
</div> </div>
</div>
<div class="m-footer">
<div class="login-footer"> <div class="login-footer">
<p> <p>
<a href="https://demo.cloud.renren.io/renren-cloud" <a href=""
target="_blank">{{ $t('login.demo') }}</a> target="_blank">{{ $t('login.copyright') }}</a>
</p> </p>
<!-- 2020 © renren.io -->
<p><a href="https://www.renren.io/"
target="_blank">{{ $t('login.copyright') }}</a></p>
</div> </div>
</main> </div>
</div> </div>
<c-dialog :showFooter="false"
:title="'选择客户'"
:isNest="false"
:visible="diaVisible"
:dialogHeight="0.8"
:width="30"
:top="'120px'"
@cancel="diaCancel">
<!-- <div class="div_total"> -->
<div v-for="(item, index) in tableData"
:key="index"
class="div_row">
<span @click="selectCustomer(item)"
class="span_name">{{
item.customerName
}}</span>
</div>
</c-dialog>
</div> </div>
</template> </template>
<script> <script>
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
import CDialog from '@c/CDialog'
import debounce from 'lodash/debounce' import debounce from 'lodash/debounce'
import { messages } from '@/i18n' import { messages } from '@/i18n'
import { getUUID } from '@/utils' import { getUUID } from '@/utils'
import { Loading } from 'element-ui' // Loading
import JSEncrypt from 'jsencrypt' //
let loading //
export default { export default {
data () { data () {
return { return {
pubKey: null, //
isShowLogin: true,
i18nMessages: messages, i18nMessages: messages,
captchaPath: '', captchaPath: '',
dataForm: { dataForm: {
app: 'oper', customerId: '',
app: 'gov',
client: 'web', client: 'web',
username: '', username: '',
phone: '', phone: '',
password: '', password: '',
uuid: '', uuid: '',
captcha: '' captcha: ''
} },
//
diaVisible: false,
tableLoading: false,
tableData: []
} }
}, },
components: {
CDialog
},
computed: { computed: {
dataRule () { dataRule () {
return { return {
phone: [ phone: [{ required: true, message: '手机号不能为空', trigger: 'blur' }],
{ required: true, message: '手机号不能为空', trigger: 'blur' }
],
password: [ password: [
{ required: true, message: '密码不能为空', trigger: 'blur' } { required: true, message: '密码不能为空', trigger: 'blur' }
], ],
@ -125,31 +137,156 @@ export default {
} }
}, },
created () { created () {
this.getCaptcha() //
if (this.$route.query.platformToken) {
this.isShowLogin = false
this.getAutoLogin(this.$route.query.platformToken)
} else {
this.getCaptcha()
//
this.getPubKey()
}
},
mounted () {
localStorage.removeItem('showHeader')
}, },
methods: { methods: {
//
getPubKey () {
this.$http
.post('/auth/govweb/getKey')
.then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.pubKey = res.data // ;
})
.catch(() => { })
},
// //
getCaptcha () { getCaptcha () {
this.dataForm.uuid = getUUID() this.dataForm.uuid = getUUID()
this.captchaPath = `${window.SITE_CONFIG['apiURL']}/auth/login/captcha?uuid=${this.dataForm.uuid}` this.captchaPath = `${window.SITE_CONFIG['apiURL']}/auth/login/captcha?uuid=${this.dataForm.uuid}`
}, },
// //
dataFormSubmitHandle: debounce(function () { dataFormSubmitHandle () {
this.$refs['dataForm'].validate((valid, messageObj) => { this.$refs['dataForm'].validate((valid, messageObj) => {
if (!valid) { if (!valid) {
app.util.validateRule(messageObj) app.util.validateRule(messageObj)
} }
this.$http.post('/auth/login/operweb/loginbypassword', this.dataForm).then(({ data: res }) => { this.startLoading()
// const url = 'https://nei.netease.com/api/apimock-v2/e3b1d0eb88e905f6c7ee559b2d6bb7ad/epmetuser/customerstaff/customerlist'
const url = '/epmetuser/customerstaff/customerlist'
const params = {
phone: this.dataForm.phone
}
window.app.ajax.post(
url,
params,
(data, rspMsg) => {
if (data.length === 0) {
//
this.$message.error('账号不存在')
this.endLoading()
} else if (data.length === 1) {
this.selectCustomer(data[0])
} else {
this.endLoading()
this.diaVisible = true
this.$nextTick(() => {
this.tableData = data
})
}
},
(rspMsg, data) => {
this.endLoading()
this.$message.error(rspMsg)
}
)
})
},
//
getAutoLogin (platformToken) {
this.dataForm.thirdToken = platformToken
this.dataForm.platform = 'pyld'
this.$http
.post(`/auth/sso/oper/third/login`, this.dataForm)
.then(({ data: res }) => {
if (res.code !== 0) {
if (res.code == 8302) {
return this.$message.error(res.msg)
}
return this.$message.error(res.msg)
}
localStorage.setItem('customerId', res.data.customerId)
localStorage.setItem('userType', 'work')
localStorage.setItem('showHeader', '0')
Cookies.set('token', res.data.token)
this.$router.replace({ name: 'home' })
})
.catch(() => { })
// epmet-ext9.elinkservice.cn/platform-admin
},
//
selectCustomer (row) {
localStorage.setItem('customerId', row.customerId)
localStorage.setItem('customerName', row.customerName)
this.startLoading()
// const url = 'https://nei.netease.com/api/apimock-v2/e3b1d0eb88e905f6c7ee559b2d6bb7ad/auth/govweb/login'
const url = '/auth/govweb/login'
this.dataForm.customerId = row.customerId
let param = {}
Object.assign(param, this.dataForm)
param.password = this.encryptedData(this.pubKey, this.dataForm.password)
this.$http
.post(url, param)
.then(({ data: res }) => {
if (res.code !== 0) { if (res.code !== 0) {
this.getCaptcha() this.getCaptcha()
return this.$message.error(res.msg) return this.$message.error(res.msg)
} }
localStorage.setItem('userType', 'oper') this.diaVisible = false
localStorage.setItem('userType', 'work')
Cookies.set('token', res.data.token) Cookies.set('token', res.data.token)
this.$router.replace({ name: 'home' }).catch(() => { }) this.$router.replace({ name: 'indexWork' }).catch(() => { })
}).catch(() => { }) })
.catch(() => { })
this.endLoading()
},
//
diaCancel () {
this.diaVisible = false
},
//
startLoading () {
loading = Loading.service({
lock: true, //
text: '正在加载……', //
background: 'rgba(0,0,0,.7)' //
}) })
}, 1000, { 'leading': true, 'trailing': false }) },
//
endLoading () {
// clearTimeout(timer);
if (loading) {
loading.close()
}
},
//
encryptedData (key, data) {
// JSEncrypt
let encryptor = new JSEncrypt()
//
encryptor.setPublicKey(key)
//
return encryptor.encrypt(data)
}
} }
} }
</script> </script>
<style lang="scss" src="@/assets/scss/pages/loginWork.scss"></style>

Loading…
Cancel
Save