index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div class="l-con">
  3. <div class="l-top">
  4. <h1>场景转换列表登录</h1>
  5. </div>
  6. <div class="l_center">
  7. <vcenter>
  8. <div class="lc-l">
  9. <div class="text_01">大场景上传自动化</div>
  10. <div class="text_02">内部人员使用,便捷管理</div>
  11. <div class="text_02">请勿泄露</div>
  12. </div>
  13. <div class="lc-r">
  14. <div class="lc-title">
  15. <span>后台登录</span>
  16. </div>
  17. <div class="lc-form">
  18. <el-form
  19. label-position="top"
  20. :model="ruleForm2"
  21. status-icon
  22. :rules="rules2"
  23. ref="ruleForm2"
  24. label-width="100px"
  25. class="demo-ruleForm"
  26. >
  27. <el-form-item prop="phoneNum">
  28. <el-input
  29. type="phoneNum"
  30. placeholder="手机号码"
  31. v-model="ruleForm2.phoneNum"
  32. auto-complete="off"
  33. ></el-input>
  34. </el-form-item>
  35. <el-form-item prop="pass" id="no-bottom">
  36. <el-input
  37. type="password"
  38. placeholder="密码"
  39. @keyup.enter.native="submitForm('ruleForm2')"
  40. v-model="ruleForm2.pass"
  41. auto-complete="off"
  42. ></el-input>
  43. </el-form-item>
  44. <el-form-item>
  45. <el-checkbox v-model="checked">记住密码(在公共场所电脑请勿勾选)</el-checkbox>
  46. </el-form-item>
  47. </el-form>
  48. <div class="lc-btn">
  49. <el-button
  50. type="primary"
  51. v-loading.fullscreen.lock="fullscreenLoading"
  52. @click="submitForm('ruleForm2')"
  53. >登录</el-button>
  54. </div>
  55. </div>
  56. </div>
  57. </vcenter>
  58. </div>
  59. <div class="l_footer">
  60. <div>四维时代 Copyright © 2019 4DAGE Co., Ltd. All rights reserved.</div>
  61. <div class="sub">粤ICP备14078495号-2</div>
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. import vcenter from '@/components/vcenter'
  67. import {encodeStr} from '@/util'
  68. import { Base64 } from 'js-base64'
  69. export default {
  70. name: 'login',
  71. components: {
  72. vcenter
  73. },
  74. data () {
  75. var validateUser = (rule, value, callback) => {
  76. if (!value) {
  77. return callback(new Error('手机号码不能为空'))
  78. } else if (value.length < 3) {
  79. callback(new Error('手机号码不合法'))
  80. } else {
  81. callback()
  82. }
  83. }
  84. var validatePass = (rule, value, callback) => {
  85. if (value === '') {
  86. return callback(new Error('请输入密码'))
  87. } else if (value.length < 4) {
  88. callback(new Error('密码不能小于4位'))
  89. } else {
  90. callback()
  91. }
  92. }
  93. return {
  94. fullscreenLoading: false,
  95. checked: true,
  96. ruleForm2: {
  97. phoneNum: '',
  98. pass: ''
  99. },
  100. rules2: {
  101. phoneNum: [
  102. {
  103. validator: validateUser,
  104. trigger: 'blur'
  105. }
  106. ],
  107. pass: [
  108. {
  109. validator: validatePass,
  110. trigger: 'blur'
  111. }
  112. ]
  113. }
  114. }
  115. },
  116. mounted () {
  117. this.ruleForm2.phoneNum = window.localStorage.getItem('cjt_phoneNum') || ''
  118. this.ruleForm2.pass = window.localStorage.getItem('cjt_pass') || ''
  119. },
  120. methods: {
  121. async login () {
  122. let {phoneNum, pass} = this.ruleForm2
  123. this.fullscreenLoading = true
  124. let res = await this.$http.post('/api/sso/user/login', {
  125. phoneNum,
  126. password: encodeStr(Base64.encode(pass)),
  127. })
  128. this.fullscreenLoading = false
  129. if (res.code === 0) {
  130. let data = res.data
  131. window.localStorage.setItem('cjt_token', data.token)
  132. if (this.checked) {
  133. window.localStorage.setItem(
  134. 'cjt_phoneNum',
  135. phoneNum
  136. )
  137. window.localStorage.setItem('cjt_pass', pass)
  138. } else {
  139. window.localStorage.setItem('cjt_phoneNum', '')
  140. window.localStorage.setItem('cjt_pass', '')
  141. }
  142. this.$router.push('/')
  143. } else {
  144. this.$notify.error({
  145. title: '错误',
  146. message: res.msg
  147. })
  148. }
  149. },
  150. submitForm (formName) {
  151. this.$refs[formName].validate(valid => {
  152. if (valid) {
  153. this.login()
  154. } else {
  155. this.$alert('请填写正确信息', '提示', {
  156. confirmButtonText: '确定',
  157. callback: action => {}
  158. })
  159. return false
  160. }
  161. })
  162. }
  163. }
  164. }
  165. </script>
  166. <style scoped>
  167. .l-con {
  168. width: 100%;
  169. }
  170. .l-top {
  171. color: #333;
  172. text-align: center;
  173. padding: 50px 0;
  174. }
  175. .lc-l {
  176. display: inline-block;
  177. color: #fff;
  178. }
  179. .lc-l img {
  180. width: 150px;
  181. }
  182. .text_01 {
  183. font-size: 60px;
  184. font-weight: bold;
  185. margin-top: 70px;
  186. }
  187. .text_02 {
  188. font-size: 40px;
  189. margin: 30px 0;
  190. }
  191. .text_03 {
  192. font-size: 20px;
  193. }
  194. .lc-r {
  195. float: right;
  196. width: 345px;
  197. height: 370px;
  198. background-color: #fff;
  199. padding: 28px 30px;
  200. }
  201. .lc-title {
  202. text-align: center;
  203. border-bottom: 2px solid #0175dc;
  204. padding-bottom: 20px;
  205. }
  206. .lc-title span {
  207. color: #333;
  208. font-size: 16px;
  209. }
  210. .lc-form {
  211. margin-top: 40px;
  212. }
  213. .lc-btn {
  214. width: 100%;
  215. }
  216. .lc-btn .el-button--primary {
  217. width: 100%;
  218. }
  219. .l_center {
  220. height: 600px;
  221. width: 100%;
  222. padding: 0 10% 0 20%;
  223. background: url("~@/assets/images/img_login_banbg.jpg") center center
  224. no-repeat;
  225. box-sizing: border-box;
  226. }
  227. .l_footer {
  228. font-size: 14px;
  229. text-align: center;
  230. margin-top: 45px;
  231. line-height: 1.5;
  232. }
  233. .sub {
  234. font-size: 12px;
  235. color: #999;
  236. margin-top: 10px;
  237. }
  238. </style>