login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="aui-wrapper aui-page__login">
  3. <div class="aui-content__wrapper">
  4. <el-row>
  5. <el-col class="aui-content" :span="24" :offset="5">
  6. <!--<div class="login-header">-->
  7. <!--<h2 class="login-brand">{{ $t('brand.lg') }}</h2>-->
  8. <!--</div>-->
  9. <div class="login-body">
  10. <!--<h3 class="login-title">{{ $t('login.title') }}</h3>-->
  11. <img src="~@/assets/img/logo.png" style="width:50%;margin-bottom: 40px;">
  12. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" status-icon>
  13. <el-form-item v-if="showUsername" prop="username">
  14. <el-input v-model="dataForm.username" :placeholder="$t('login.username')">
  15. <span slot="prefix" class="el-input__icon">
  16. <svg class="icon-svg" aria-hidden="true"><use xlink:href="#icon-user"></use></svg>
  17. </span>
  18. </el-input>
  19. </el-form-item>
  20. <el-form-item v-if="showOnPhone" prop="phoneNumber">
  21. <el-input v-model="dataForm.phoneNumber" placeholder="请输入手机号">
  22. </el-input>
  23. </el-form-item>
  24. <el-form-item v-if="showUsername" prop="password">
  25. <el-input v-model="dataForm.password" type="password" show-password :placeholder="$t('login.password')">
  26. <span slot="prefix" class="el-input__icon">
  27. <svg class="icon-svg" aria-hidden="true"><use xlink:href="#icon-lock"></use></svg>
  28. </span>
  29. </el-input>
  30. </el-form-item>
  31. <el-form-item prop="validCode">
  32. <el-row :gutter="20">
  33. <el-col :span="14">
  34. <el-input v-model="dataForm.validCode" :placeholder="$t('login.captcha')">
  35. <span slot="prefix" class="el-input__icon">
  36. <svg class="icon-svg" aria-hidden="true"><use xlink:href="#icon-safetycertificate"></use></svg>
  37. </span>
  38. </el-input>
  39. </el-col>
  40. <el-col :span="10" class="login-captcha">
  41. <img :src="captchaPath" @click="getCaptcha()">
  42. </el-col>
  43. </el-row>
  44. </el-form-item>
  45. <el-form-item v-if="showOnPhone" prop="validsmsCode" >
  46. <el-input v-model="dataForm.validsmsCode" placeholder="请输入验证码">
  47. <template #append> <div class="verView" @click="verCodeClick()">{{codeTitle}}</div></template>
  48. </el-input>
  49. </el-form-item>
  50. <el-form-item>
  51. <el-button type="primary" @click="dataFormSubmitHandle()" class="w-percent-100">{{ $t('login.title') }}</el-button>
  52. </el-form-item>
  53. <div class="do">
  54. <div v-if="showOnPhone" class="phone" @click="onUserName()">用户名登录</div>
  55. <div v-if="showUsername" class="phone" @click="onPone()">手机号登录</div>
  56. <!-- <a href="../../../onenettest.html" class="phone" > 证书登录</a> -->
  57. <div class="phone" @click="CertLogin()">证书登录</div>
  58. </div>
  59. </el-form>
  60. </div>
  61. </el-col>
  62. </el-row>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import Cookies from 'js-cookie'
  68. import debounce from 'lodash/debounce'
  69. import { messages } from '@/i18n'
  70. import { getUUID } from '@/utils'
  71. import {
  72. IsAddonAvailable,
  73. GetSignAndToken,
  74. GetSignAndTokenCb,
  75. } from './onenethelper'
  76. export default {
  77. data () {
  78. return {
  79. i18nMessages: messages,
  80. showOnPhone: false,
  81. showUsername: true,
  82. show:false,
  83. codeTitle:"获取验证码",
  84. time_count:60,
  85. timer:null,
  86. captchaPath: '',
  87. dataForm: {
  88. username: '',
  89. password: '',
  90. deviceId: '',
  91. validCode: '',
  92. phoneNumber:'',
  93. validsmsCode:'',
  94. }
  95. }
  96. },
  97. computed: {
  98. dataRule () {
  99. return {
  100. username: [
  101. { required: true, message: this.$t('validate.required'), trigger: 'blur' }
  102. ],
  103. password: [
  104. { required: true, message: this.$t('validate.required'), trigger: 'blur' }
  105. ],
  106. validCode: [
  107. { required: true, message: '请输入验证码', trigger: 'blur' }
  108. ],
  109. validsmsCode: [
  110. { required: true, message: '请输入验证码', trigger: 'blur' }
  111. ],
  112. phoneNumber: [
  113. { required: true, message: '请输入手机号码', trigger: 'blur' }
  114. ],
  115. }
  116. }
  117. },
  118. created () {
  119. this.getCaptcha()
  120. },
  121. methods: {
  122. // 获取验证码
  123. getCaptcha () {
  124. this.dataForm.deviceId = getUUID()
  125. this.captchaPath = `${window.SITE_CONFIG['apiURL']}/validata/code/${this.dataForm.deviceId}`
  126. },
  127. // 获取手机验证码
  128. verCodeClick () {
  129. if(!this.show){
  130. this.$http.post('/idaas/sso/smsvalidate',{
  131. phoneNumber:this.dataForm.phoneNumber,
  132. deviceId:this.dataForm.deviceId,
  133. validCode:this.dataForm.validCode,
  134. }).then(({ data: res }) => {
  135. // this.show = true
  136. if (res.code !== 0) {
  137. return this.$message.error(res.msg)
  138. }
  139. if(res.code==0) {
  140. if(!this.timer) {
  141. this.timer = setInterval ( () => {
  142. if(this.time_count>0) {
  143. this.time_count--
  144. this.codeTitle = this.time_count +'秒后重新获取'
  145. }
  146. else {
  147. this.codeTitle = '获取验证码'
  148. clearInterval(this.timer)
  149. this.timer = null
  150. this.time_count = 60
  151. this.show = false
  152. }
  153. },1000)
  154. }
  155. }
  156. }).catch(() => {})
  157. }
  158. },
  159. onUserName () {
  160. this.showUsername = true
  161. this.showOnPhone = false
  162. },
  163. // 手机号登录
  164. onPone () {
  165. this.showOnPhone = true
  166. this.showUsername = false
  167. },
  168. CertLogin () {
  169. if(IsAddonAvailable()) {
  170. this.$http.post('/webservice/generatorchallenge', {}).then(({ data: res }) => {
  171. if (res.data.code ==0) {
  172. GetSignAndToken(res.data.msg)
  173. if(GetSignAndTokenCb()) {
  174. this.$http.post('/webservice/verifyIdentityTicket', {
  175. challenge: res.data.msg,//随机挑战数
  176. identityTicket:GetSignAndTokenCb(),//组合令牌数据
  177. appServerID:'0'//服务器ID
  178. }).then(({ data: res }) => {
  179. if (res.expiresIn==7200) {
  180. // 发送用户登录成功MQ消息
  181. this.$http.get('/mq/user/login').then(({ data: res }) => {
  182. if (res.code !== 0) {
  183. return this.$message.error(res.msg)
  184. }
  185. }).catch(() => {})
  186. Cookies.set('token', res.sessionToken)
  187. this.$router.replace({ name: 'home' })
  188. }
  189. })
  190. }
  191. // form1.T8.value = res.data.msg//获取随机挑战数
  192. }
  193. })
  194. }
  195. },
  196. // 表单提交
  197. dataFormSubmitHandle: debounce(function () {
  198. this.$refs['dataForm'].validate((valid) => {
  199. if (!valid) {
  200. return false
  201. }
  202. if(this.showOnPhone) {
  203. this.$http.post('idaas/sso/smslogin', {
  204. deviceId:this.dataForm.deviceId,
  205. phoneNumber:this.dataForm.phoneNumber,
  206. validCode:this.dataForm.validCode,
  207. validsmsCode:this.dataForm.validsmsCode,
  208. })
  209. .then(({ data: res }) => {
  210. if (res.code !== 0) {
  211. this.getCaptcha()
  212. return this.$message.error(res.msg)
  213. }
  214. Cookies.set('token', res.sessionToken)
  215. // 发送用户登录成功MQ消息
  216. this.$http.get('/mq/user/login').then(({ data: res }) => {
  217. if (res.code !== 0) {
  218. return this.$message.error(res.msg)
  219. }
  220. }).catch(() => {})
  221. if(localStorage.getItem('pathCopyshow') && localStorage.getItem('pathCopy')) {
  222. this.$router.push(localStorage.getItem('pathCopy'))
  223. }
  224. else{
  225. this.$router.replace({ name: 'home' })
  226. }
  227. }).catch(() => {})
  228. }else {
  229. this.$http.post('/idaas/sso/login', this.dataForm).then(({ data: res }) => {
  230. if (res.code !== 0) {
  231. this.getCaptcha()
  232. return this.$message.error(res.msg)
  233. }
  234. Cookies.set('token', res.sessionToken)
  235. // 发送用户登录成功MQ消息
  236. this.$http.get('/mq/user/login').then(({ data: res }) => {
  237. if (res.code !== 0) {
  238. return this.$message.error(res.msg)
  239. }
  240. }).catch(() => {})
  241. if(localStorage.getItem('pathCopyshow') && localStorage.getItem('pathCopy')) {
  242. this.$router.push(localStorage.getItem('pathCopy'))
  243. }
  244. else{
  245. this.$router.replace({ name: 'home' })
  246. }
  247. }).catch(() => {})
  248. }
  249. })
  250. }, 1000, { 'leading': true, 'trailing': false })
  251. }
  252. }
  253. </script>
  254. <style scoped>
  255. .aui-page__login .aui-content{
  256. padding: 0!important;
  257. }
  258. .do {
  259. margin-top: 24px;
  260. display: flex;
  261. align-items: center;
  262. justify-content: space-between;
  263. }
  264. .cert {
  265. cursor: pointer;
  266. display: flex;
  267. align-items: center;
  268. font-size: 16px;
  269. color: #3E8EF7;
  270. margin-right: 24px;
  271. }
  272. .phone {
  273. font-family: MicrosoftYaHei;
  274. font-size: 16px;
  275. font-weight: normal;
  276. font-stretch: normal;
  277. letter-spacing: 0px;
  278. color: #3E8EF7;
  279. cursor: pointer;
  280. margin-left: 24px;
  281. }
  282. .verView {
  283. color: #3E8EF7;
  284. cursor: pointer;
  285. }
  286. </style>