123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- <template>
- <div class="login-container">
- <div class="company-name">
- {{ title }}
-
- </div>
- <div class="fill-container" v-show="isMydesk">
- <div class="left">
- <img src="./images/background3.png" />
- </div>
- <div class="right">
- <div class="top">
- <span>用户登录</span>
-
- </div>
- <el-form
- ref="loginForm"
- :model="loginForm"
- :rules="loginRules"
- class="login-form middle"
- auto-complete="on"
- label-position="left"
- style="position: relative; left: calc((100% - 320px) / 2); top: 100px"
- >
- <el-input
- ref="username"
- v-model.trim="loginForm.username"
- prefix-icon="el-icon-user"
- placeholder="请输入账号"
- name="username"
- type="text"
- class="form-input"
- tabindex="1"
- auto-complete="on"
- />
- <el-input
- :key="passwordType"
- ref="password"
- v-model.trim="loginForm.password"
- :type="passwordType"
- placeholder="请输入密码"
- name="password"
- tabindex="2"
- class="form-input"
- auto-complete="on"
- prefix-icon="el-icon-lock"
- @keyup.enter.native="handleLogin"
- show-password
- />
- <el-input
- ref="msg"
- tabindex="3"
- prefix-icon="el-icon-tickets"
- placeholder="请输入短信验证码"
- v-model.trim="loginForm.msg"
- type="text"
- class="form-input"
- >
- <el-button @click="sendMsg()" type="primary" slot="append" :disabled="btnDisabled">{{
- btnTitle
- }}</el-button>
- </el-input>
- </el-form>
- <el-button type="button" class="login-btn" :loading="loading" @click.native.prevent="handleLogin"
- >登录</el-button
- >
- <el-button type="text" class="forgetpsw-btn" style="left: 38%" @click="resetPsw()">忘记密码?</el-button>
- <el-button type="text" class="forgetpsw-btn" style="left: 60%" @click="modifyPsw()"
- >修改密码<i class="el-icon-edit"></i
- ></el-button>
- </div>
- </div>
- <el-dialog
- title="密码修改"
- :visible.sync="passwordDialog"
- append-to-body
- width="520px"
- top="25vh"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- :show-close="false"
- >
- <el-form ref="changePwdForm" :model="changePwd" :rules="pwdRules" label-width="100px" label-position="right">
- <el-form-item label="密码:" prop="pass" style="margin-bottom: 25px">
- <el-input
- v-model="changePwd.pass"
- autocomplete="off"
- type="password"
- placeholder="请输入密码"
- prefix-icon="el-icon-lock"
- show-password
- />
- </el-form-item>
- <el-form-item label="确认密码:" prop="checkPass">
- <el-input
- v-model="changePwd.checkPass"
- autocomplete="off"
- type="password"
- placeholder="请输入密码"
- prefix-icon="el-icon-lock"
- show-password
- />
- </el-form-item>
- </el-form>
- <template slot="footer">
- <el-button @click="handleDialogBtnClick('cancel')">取消</el-button>
- <el-button type="primary" @click="handleDialogBtnClick('confirm')">确定</el-button>
- </template>
- </el-dialog>
- <ResetPsw
- :title="isReset ? '重置密码' : '修改密码'"
- :visible="resetPswDialog"
- :username="loginForm.username"
- :isReset="isReset"
- @add="setContent"
- @cancel="resetPswDialog = false"
- />
- </div>
- </template>
- <script lang="ts">
- import { Vue, Component, Watch } from 'vue-property-decorator'
- import { userFirstLogin, getMsgCode } from '@/api/user'
- import { changePassword } from '@/api/base'
- import { regNewPassword } from '@/utils/reg'
- import { ElForm } from 'element-ui/types/form'
- import { sysTitle } from '@/settings'
- import ResetPsw from './resetPsw.vue'
- import { encryption } from '@/utils/encryption'
- const defaultPwd = '000000'
- @Component({ components: { ResetPsw } })
- export default class Login extends Vue {
- name = 'Login'
- url = '@/assets/images/login/logo.png'
- title = sysTitle
- loginForm = {
- username: '',
- password: '',
- msg: ''
- }
- btnTitle = '发送验证码'
- btnDisabled = false
- time = 60
- loginRules = {
- username: [{ required: true, trigger: 'blur', message: '请输入账号' }],
- password: [{ required: true, trigger: 'blur', message: '请输入密码' }],
- msg: [{ required: true, trigger: 'blur', message: '请输入短信验证码' }]
- }
- loading = false
- passwordType = 'password'
- redirect = undefined
- error = 1
-
- msg = ''
- passwordDialog = false
- changePwd = {
- pass: '',
- checkPass: ''
- }
- pwdRules = {}
- userId = ''
-
- isMydesk = true
- mydeskUrl = 'https://uac.ctg.com.cn/sso/login'
- get sysTitle() {
- return this.$store.state.settings.sysTitle
- }
-
- resetPswDialog = false
- isReset = true
-
- beforeMount() {
- const search = window.location.hash.split('?')[1]
- const SYS_ADDR = location.href.replace(/\#\/login.*$/, '')
- if (search) {
- const typeIndex = search.indexOf('type')
- const tokenIndex = search.indexOf('token')
- const rtype = this.getSearchString('type', search)
- if (typeIndex > -1 && rtype === 'mydesk') {
- this.isMydesk = false
- }
- if (typeIndex > -1 && tokenIndex === -1) {
- if (rtype === 'mydesk') {
- const url = SYS_ADDR + '#/login?type=mydesk'
- window.location.href = this.mydeskUrl + '?url=' + encodeURIComponent(url)
- }
- } else if (typeIndex > -1 && tokenIndex > -1) {
- const token = this.getSearchString('token', search)
- this.loginWithTokenCheck(token)
- return
- }
- }
- }
- mounted() {
- this.pwdRules = {
- pass: [{ required: true, validator: this.validatePwd1st, trigger: 'blur' }],
- checkPass: [{ required: true, validator: this.validatePwd2nd, trigger: 'blur' }]
- }
- }
- getSearchString(key, Url) {
- var str = Url
-
-
- var arr = str.split('&')
- var obj = new Object()
-
- for (var i = 0; i < arr.length; i++) {
- var tmp_arr = arr[i].split('=')
- obj[decodeURIComponent(tmp_arr[0])] = decodeURIComponent(tmp_arr[1])
- }
- return obj[key]
- }
-
- loginWithTokenCheck(token) {
- this.$store.dispatch('user/mydeskLogin', { token: token }).then((result) => {
- setTimeout(() => {
-
- this.$router.push({ path: '/' })
- }, 0)
- })
- }
- validatePwd1st(rule, value, callback) {
- if (value === '') {
- callback(new Error('请输入密码!'))
- } else {
- if (this.changePwd.pass !== '') {
- if (!regNewPassword().test(value)) {
- callback(new Error('密码位数至少12位,必须包含大小写字母和数字,不可包含非法字符!'))
- return
- }
- }
- callback()
- }
- }
- validatePwd2nd(rule, value, callback) {
- if (value === '') {
- callback(new Error('请再次输入密码'))
- } else if (value !== this.changePwd.pass && value !== '') {
- callback(new Error('两次输入密码不一致!'))
- } else {
- callback()
- }
- }
- @Watch('$route', { immediate: true })
- changeValue(route, oldvalue) {
- this.redirect = route.query && route.query.redirect
- }
-
- showPwd() {
- if (this.passwordType === 'password') {
- this.passwordType = 'text'
- } else {
- this.passwordType = 'password'
- }
- this.$nextTick(() => {
- ;(this.$refs.password as HTMLElement).focus()
- })
- }
-
- handleLogin() {
- ;(this.$refs.loginForm as ElForm).validate((valid) => {
- if (valid) {
- this.loading = true
-
-
-
-
- this.$store
- .dispatch('user/login', this.loginForm)
- .then((res) => {
- const { id } = res.result
-
- userFirstLogin(id)
- .then((res) => {
-
- const { auditstatus, enableFlag } = res.result
- if (enableFlag === '0') {
- this.$message({
- message: '用户已被禁用,请先启用!',
- type: 'error'
- })
- this.loading = false
- sessionStorage.clear()
- return
- }
- if (auditstatus !== '2' && auditstatus !== null) {
- this.$message({
- message: auditstatus === 1 ? '账户还未审核通过!' : '账户审核未被通过!',
- type: 'error'
- })
- this.loading = false
- sessionStorage.clear()
- return
- }
-
- if (res.result.firstlog === '1' && this.loginForm.password === defaultPwd) {
- this.userId = id
- this.passwordDialog = true
-
- sessionStorage.removeItem('userId')
- this.$store.state.user.userId = undefined
- } else {
- this.loading = false
- setTimeout(() => {
-
- this.$router.push({ path: '/' })
- }, 0)
- }
- })
- .catch(() => {
- sessionStorage.clear()
- this.loading = false
- })
-
- })
- .catch((err) => {
- this.$message.error(err.message)
- this.loading = false
- })
- } else {
- console.log('error submit!!')
- return false
- }
-
- })
- }
-
- sendMsg() {
- if (this.loginForm.username === '' && this.loginForm.password === '') {
- this.$message.error('请输入账号')
- return
- }
- let timer = setInterval(() => {
- this.time--
- this.btnDisabled = true
- this.btnTitle = `${this.time}s后重新发送`
- if (this.time === 0) {
- this.time = 60
- this.btnDisabled = false
- this.btnTitle = '发送验证码'
- clearInterval(timer)
- }
- }, 1000)
- getMsgCode({ username: this.loginForm.username })
- .then((result) => {
- this.$message.success(result.result)
- })
- .catch((error) => {
- console.log(error)
- })
- }
-
- handleDialogBtnClick(type) {
- if (type === 'cancel') {
- this.$nextTick(() => {
- ;(this.$refs.changePwdForm as ElForm).resetFields()
- })
- this.passwordDialog = false
- this.changePwd.pass = ''
- this.changePwd.checkPass = ''
- sessionStorage.clear()
- this.loading = false
- } else {
- ;(this.$refs.changePwdForm as ElForm).validate((valid) => {
- if (valid) {
- const data = {
- originalPassword: encryption(defaultPwd),
- id: this.userId,
- firstlog: 0,
- password: encryption(this.changePwd.checkPass)
- }
- changePassword(data).then((res) => {
- if (res.code !== -1) {
- this.$message({
- message: '密码修改成功,请您重新登录!',
- type: 'success'
- })
- this.passwordDialog = false
- this.loading = false
- this.changePwd.pass = ''
- this.changePwd.checkPass = ''
- this.loginForm.password = ''
- sessionStorage.clear()
- } else {
- this.$nextTick(() => {
- ;(this.$refs.changePwdForm as ElForm).resetFields()
- })
- this.passwordDialog = false
- this.loading = false
- this.changePwd.pass = ''
- this.changePwd.checkPass = ''
- sessionStorage.clear()
- this.$message({
- message: res.message,
- type: 'error'
- })
- }
- })
- } else return false
- })
- }
- }
-
- resetPsw() {
- this.resetPswDialog = true
- this.isReset = true
- }
- setContent(val) {
- const { password, code } = val
- this.loginForm.password = password
- this.loginForm.msg = code
- }
-
- modifyPsw() {
- this.resetPswDialog = true
- this.isReset = false
- }
- }
- </script>
- <style lang="scss" scoped>
- .login-container {
- width: 100%;
- height: 100%;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- background: url('./images/background.png') no-repeat fixed center/100%;
- background-size: cover;
- .company-name {
- position: absolute;
- font-size: 40px;
- color: white;
- font-weight: 500;
- letter-spacing: 4px;
- width: 100%;
- text-align: center;
- top: calc((100% - 534px) / 2);
- -webkit-box-reflect: below 1px -webkit-gradient(linear, 0 0, 0 50%, from(transparent), color-stop(0.2, transparent), to(rgba(3, 3, 3, 0.1)));
- }
- img {
- user-select: none;
- height: 100%;
- }
- .fill-container {
- position: relative;
- width: 926px;
- height: 434px;
- border-radius: 10px;
- background-color: rgb(228, 242, 255);
- left: calc((100% - 926px) / 2);
- top: calc((100% - 334px) / 2);
- .left {
- position: relative;
- float: left;
- width: 538px;
- overflow: hidden;
- }
- .right {
- width: 388px;
- height: 100%;
- position: relative;
- float: left;
- .top {
- font-size: 25px;
- font-weight: 700;
- color: rgb(45, 116, 231);
- text-align: center;
- width: 100%;
- top: 50px;
- position: relative;
- float: left;
- > span {
- line-height: 30px;
- &:nth-of-type(2) {
- margin-top: 16px;
- }
- }
- }
- /deep/ input.el-input__inner {
- padding-left: 40px !important;
- }
- /deep/ i.el-input__icon.el-icon-user,
- /deep/ i.el-input__icon.el-icon-lock,
- /deep/ i.el-input__icon.el-icon-tickets {
- font-size: 20px;
- color: #2d74e7;
- top: -2.25px;
- position: relative;
- }
- .middle {
- width: 320px;
- height: 106px;
- margin-bottom: 80px;
- > .form-input {
- height: 36px;
- line-height: 36px;
- /deep/ input {
- height: 36px;
- }
- &:nth-of-type(2) {
- margin-top: 15px;
- }
- &:nth-of-type(3) {
- margin-top: 15px;
- }
- }
- }
- .login-btn {
- width: 320px;
- height: 44px;
- border-radius: 22px;
- position: relative;
- float: left;
- left: calc((100% - 320px) / 2);
- top: 120px;
- overflow: hidden;
- font-size: 16px;
- background: #2d74e7;
- transition: background 0.3s linear;
- color: #ffffff;
- &:hover {
- background: #2467d3;
- }
- }
- .forgetpsw-btn {
- position: absolute;
- // bottom: 45px;
- bottom: 7px;
- left: 50%;
- margin-left: -28px;
- }
- .forgetpsw-btn:last-child::before {
- content: '';
- position: absolute;
- height: 12px;
- width: 1px;
- background: #01a2ff;
- margin: 0 auto;
- left: -10px;
- bottom: 12px;
- }
- }
- }
- }
- </style>
|