login.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div class="login-layer">
  3. <!-- <div class="top-text">
  4. <img src="@/assets/image/top-text.png" alt="">
  5. </div> -->
  6. <div class="content">
  7. <div class="info">
  8. <h1>消防火调三维远程勘验平台</h1>
  9. <p>Three-dimensional remote prospecting platform of fire scene of Fire Rescue</p>
  10. </div>
  11. <el-form class="panel login" :model="form" @submit.stop>
  12. <h2>欢迎登录</h2>
  13. <el-form-item class="panel-form-item">
  14. <p class="err-info">{{verification.phone}}</p>
  15. <el-input v-model.trim="form.phone" placeholder="手机号" @keydown.enter="submitClick"></el-input>
  16. </el-form-item>
  17. <el-form-item class="panel-form-item">
  18. <p class="err-info">{{verification.psw}}</p>
  19. <el-input v-model="form.psw" placeholder="密码" maxlength="45" :type="flag?'password':'text'" @keydown.enter="submitClick">
  20. <template v-slot:suffix>
  21. <img v-if="flag" @click="flag = !flag" style="width:20px; margin: 15px;" src="@/assets/image/pasword.png" alt="">
  22. <i v-else class="icon-style el-icon-view" size="20" @click="flag = !flag"></i>
  23. </template>
  24. </el-input>
  25. </el-form-item>
  26. <el-form-item class="panel-form-item code-form-item">
  27. <p class="err-info">{{verification.code}}</p>
  28. <el-input v-model="form.code" placeholder="验证码" @keydown.enter="submitClick" class="code-input">
  29. <template v-slot:append>
  30. <img :src="codeImg" class="code-img" @click="refer">
  31. </template>
  32. </el-input>
  33. </el-form-item>
  34. <el-form-item class="panel-form-item">
  35. <el-button type="primary" class="fill" @click="submitClick">登录</el-button>
  36. </el-form-item>
  37. <div class="more">
  38. <a @click="$router.push({name: 'forget'})">忘记密码</a>
  39. <!-- <a @click="$router.push({name: 'register'})">账号注册</a>-->
  40. </div>
  41. </el-form>
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. import { reactive, watch,ref } from 'vue'
  47. import axios from 'axios'
  48. import { setToken, setPermission, setInfo, setRoleKey } from '@/state/user'
  49. import { userLogin, getCode } from '@/request/config'
  50. import {PHONE} from '@/constant/REG'
  51. import { openErrorMsg } from '@/request/errorMsg.js'
  52. import { encryption, guid } from '@/util'
  53. export default {
  54. name: 'login',
  55. setup() {
  56. const form = reactive({
  57. phone: localStorage.getItem('userName') || '',
  58. psw: localStorage.getItem('password') || '',
  59. code: '',
  60. remember: localStorage.getItem('remember') === '1'
  61. })
  62. const verification = reactive({ phone: '', psw: '', code: '' })
  63. const flag = ref(true)
  64. watch(form, () => {
  65. console.log('form',form)
  66. if (!form.phone) {
  67. verification.phone = '请输入手机号'
  68. } else if(form.phone == '88888888888'){
  69. verification.phone = ''
  70. }else{
  71. verification.phone = PHONE.REG.test(form.phone) ? '': PHONE.tip
  72. }
  73. if (!form.psw) {
  74. verification.psw = '请输入密码'
  75. } else {
  76. verification.psw = ''
  77. }
  78. if (!form.code.trim()) {
  79. verification.code = '请输入验证码'
  80. } else {
  81. verification.code = ''
  82. }
  83. }, {immediate: true})
  84. return {
  85. form,
  86. verification,
  87. flag
  88. }
  89. },
  90. methods: {
  91. async submitClick(ev) {
  92. ev.stopPropagation()
  93. if (this.verification.phone && this.verification.phone !== '88888888888') {
  94. console.log('return openErrorMsg(this.verification.phone, ',this.verification.phone)
  95. return openErrorMsg(this.verification.phone, '提示')
  96. }
  97. if (this.verification.psw) return openErrorMsg(this.verification.psw, '提示')
  98. if (this.verification.code) return openErrorMsg(this.verification.code, '提示')
  99. try {
  100. // await axios.get(checkCode, {params: { code: this.form.code, key: this.imgKey }})
  101. let res = await axios.post(userLogin, {
  102. userName: this.form.phone,
  103. key: this.imgKey,
  104. code: this.form.code,
  105. password: encryption(this.form.psw)
  106. })
  107. if (this.form.remember) {
  108. localStorage.setItem('userName', this.form.phone)
  109. localStorage.setItem('password', this.form.psw)
  110. localStorage.setItem('remember', '1')
  111. } else {
  112. localStorage.setItem('userName', '')
  113. localStorage.setItem('password', '')
  114. localStorage.setItem('remember', '0')
  115. }
  116. if (!res.data.roles.length) {
  117. setToken('')
  118. setRoleKey({})
  119. setPermission([])
  120. setInfo({})
  121. openErrorMsg('当前账号无权限,请联系总队管理员处理。', '提示')
  122. } else {
  123. res.data.user.department = res.data.department
  124. console.log('info', res.data.permissions)
  125. setInfo(res.data.user)
  126. setToken(res.data.token)
  127. setRoleKey(res.data.roles[0])
  128. setPermission(res.data.roles[0].roleKey,res.data.permissions)
  129. this.$router.replace({ name: 'home' })
  130. }
  131. } catch (e) {
  132. console.error(e)
  133. return this.refer()
  134. }
  135. },
  136. refer() {
  137. this.imgKey = guid()
  138. }
  139. },
  140. data() {
  141. let url = process.env.VUE_APP_PREFIX + getCode
  142. return {
  143. baseImg: url,
  144. imgKey: guid()
  145. }
  146. },
  147. computed: {
  148. codeImg() {
  149. return this.baseImg + '?key=' + this.imgKey
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang="sass">
  155. @import "./style.scss"
  156. </style>
  157. <style lang="scss" scoped>
  158. .login-layer {
  159. text-align: right;
  160. }
  161. .content{
  162. display: flex;
  163. justify-content: center;
  164. align-items: flex-start;
  165. }
  166. .info {
  167. color: #fff;
  168. margin-right: 143px;
  169. padding-top: 80px;
  170. padding-bottom: 80px;
  171. flex: none;
  172. text-align: left;
  173. img {
  174. width: 76px;
  175. height: 76px;
  176. }
  177. h1 {
  178. font-size: 2.8rem;
  179. line-height: 3.7rem;
  180. margin-bottom: 0.7rem;
  181. }
  182. p {
  183. font-size: 2rem;
  184. line-height: 2.2rem;
  185. }
  186. }
  187. .top-text {
  188. margin-bottom: 50px;
  189. pointer-events: none;
  190. height: 153px;
  191. min-width: 1200px;
  192. img {
  193. position: absolute;
  194. right: 0;
  195. }
  196. }
  197. .login {
  198. width: 320px;
  199. padding: 40px 40px 30px;
  200. position: relative;
  201. display: inline-block;
  202. h2 {
  203. padding-left: 0;
  204. padding-bottom: 0;
  205. border-bottom: none;
  206. margin-bottom: 2.14rem;
  207. span {
  208. color: #646566;
  209. font-size: 1.33rem;
  210. margin-top: 0.71rem;
  211. display: block;
  212. }
  213. }
  214. .panel-form-item {
  215. padding-left: 0;
  216. padding-right: 0;
  217. .icon-style{
  218. margin-right: 14px;
  219. font-size: 20px;
  220. line-height: 50px;
  221. }
  222. }
  223. .more a:first-child::after {
  224. content: '';
  225. position: absolute;
  226. right: -5px;
  227. width: 1px;
  228. height: 8px;
  229. background: #DCDEE0;
  230. top: 50%;
  231. transform: translateY(-50%);
  232. }
  233. }
  234. .code-img {
  235. width: 100%;
  236. height: 100%;
  237. // object-fit: cover;
  238. }
  239. </style>
  240. <style>
  241. .login .code-form-item .el-input {
  242. display: flex;
  243. }
  244. .login .code-form-item .el-input-group__append {
  245. flex: none;
  246. margin-left: 10px;
  247. width: 95px;
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. padding: 0;
  252. }
  253. .login .code-form-item .el-input__inner {
  254. flex: 1;
  255. }
  256. .login .code-form-item .el-input-group__append,
  257. .login .code-form-item .el-input__inner {
  258. border: 1px solid #DCDFE6;
  259. border-radius: 4px;
  260. }
  261. input[type='password']::-ms-reveal{
  262. display: none;
  263. }
  264. </style>