index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <div class="mianBox" >
  3. <el-form class="login-form" auto-complete="on" ref="loginForm" :model="loginForm" :rules="loginRules" v-if="login" :class="login?'opa1':'opa0'">
  4. <img src="../../assets/image/login/login.png" alt="" class="login">
  5. <el-form-item prop="username" width="460px">
  6. <el-input v-model="loginForm.username"
  7. ref="username"
  8. placeholder="请输入用户名"
  9. name="username"
  10. @keyup.enter.native="login_info()"
  11. type="text" auto-complete="off" >
  12. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon z" />
  13. </el-input>
  14. </el-form-item>
  15. <el-form-item prop="password" style="position: relative;width:100%">
  16. <el-input
  17. ref="password"
  18. placeholder="请输入密码"
  19. name="password"
  20. @keyup.enter.native="login_info()"
  21. :type="passwordtxt"
  22. v-model="loginForm.password"
  23. >
  24. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon z" />
  25. </el-input>
  26. <div class="eyeWrap ">
  27. <svg-icon slot="prefix" icon-class="eye" class="el-input__icon input-icon eye" @click="eyeTab" v-show="passwordtxt =='password'" />
  28. <svg-icon slot="prefix" icon-class="eye-open" class="el-input__icon input-icon eye" @click="eyeTab" v-show="passwordtxt =='text'" />
  29. </div>
  30. </el-form-item>
  31. <!-- <el-form-item prop="code">
  32. <el-input
  33. v-model="loginForm.code"
  34. auto-complete="off"
  35. placeholder="验证码"
  36. style="width: 63%"
  37. >
  38. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  39. </el-input>
  40. <div class="login-code">
  41. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  42. </div>
  43. </el-form-item> -->
  44. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  45. <el-button
  46. type="primary"
  47. @click.native.prevent="login_info()"
  48. @keyup.enter = "login_info()"
  49. >
  50. <span v-if="!loading" >登 录</span>
  51. <span v-else>登 录 中...</span></el-button
  52. >
  53. </el-form>
  54. <van-loading
  55. size="24px"
  56. v-if="loading"
  57. color="#fff"
  58. vertical
  59. style="z-index: 2; position: fixed; top: 40%; left: 0; right: 0"
  60. >登录中...</van-loading
  61. >
  62. <van-overlay :show="loading" style="z-index: 1; position: fixed;background-color: rgba(0,0,0,0.6);" />
  63. </div>
  64. </template>
  65. <script>
  66. import { Toast } from "vant";
  67. import axios from "axios";
  68. import Cookies from "js-cookie";
  69. import { encrypt, decrypt } from '../../utils/jsencrypt';
  70. export default {
  71. data() {
  72. return {
  73. login:false,
  74. loading:false,
  75. passwordtxt:"password",
  76. codeUrl: "",
  77. cookiePassword: "",
  78. show_num:[],
  79. // 验证码开关
  80. // captchaOnOff: true,
  81. loginForm: {
  82. username: "",
  83. password: "",
  84. rememberMe: false,
  85. code: "",
  86. uuid: ""
  87. },
  88. loginRules: {
  89. username: [
  90. { required: true, trigger: "blur", message: "请输入您的账号" }
  91. ],
  92. password: [
  93. { required: true, trigger: "blur", message: "请输入您的密码" }
  94. ],
  95. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  96. },
  97. appid:"wxd64360a4b8c50006",
  98. secret:"b7MTe45c89162542610509dafd9db7c3",
  99. code:undefined,
  100. };
  101. },
  102. mounted() {
  103. if(Cookies.get('rememberMeMT')){
  104. this.loginForm.rememberMe = Boolean(Cookies.get('rememberMeMT'))
  105. }
  106. if(Cookies.get("usernameMT")){
  107. this.loginForm.username = Cookies.get("usernameMT")
  108. }
  109. if(Cookies.get("passwordMT")){
  110. this.loginForm.password = decrypt(Cookies.get("passwordMT"))
  111. }
  112. if(Cookies.get("usernameMT") && Cookies.get("passwordMT")){
  113. this.loginForm.username = Cookies.get("usernameMT")
  114. this.loginForm.password = decrypt(Cookies.get("passwordMT"))
  115. this.login = false
  116. this.login_info()
  117. }else{
  118. this.login = true
  119. }
  120. },
  121. methods: {
  122. eyeTab(){//密码显示开关
  123. if(this.passwordtxt == "password"){
  124. this.passwordtxt = "text"
  125. }else{
  126. this.passwordtxt = "password"
  127. }
  128. },
  129. getCookie() {//缓存数据
  130. const username = Cookies.get("usernameMT");
  131. const password = Cookies.get("passwordMT");
  132. const rememberMe = Cookies.get('rememberMeMT')
  133. this.loginForm = {
  134. username: username === undefined ? this.loginForm.username : username,
  135. password: password === undefined ? this.loginForm.password : decrypt(password),
  136. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  137. };
  138. },
  139. login_info() {
  140. if(Cookies.get("usernameMT") && Cookies.get("passwordMT")){
  141. this.$router.push({ path: "/index"})
  142. }else{
  143. this.$refs.loginForm.validate(valid => {
  144. if (valid) {
  145. this.loading = true;
  146. axios.get(`${process.env.VUE_APP_CONTROL_BASE_API}/api/thirdparty/v1/user/appLogin?name=${this.loginForm.username}&pass=${this.loginForm.password}`).then(res => {
  147. if (res?.data?.data?.data?.cipher) {
  148. let data = res.data.data.data
  149. //人员种类(00-正式人员、01-外协单位、02-租户)
  150. if(data.user.dmUser.type == "00"){
  151. //Toast('请使用"中国东信APP查看功能"')
  152. Cookies.set("usernameMT", this.loginForm.username, { expires: 300 });
  153. Cookies.set("rememberMeMT", this.loginForm.rememberMe, { expires: 300 });
  154. Cookies.set("passwordMT", encrypt(this.loginForm.password), { expires: 300 });
  155. Cookies.set("userIdMT", data.user.id, { expires: 300 });
  156. Cookies.set("tokenMT", data.cipher, { expires: 300 });
  157. Cookies.set("nonceMT", data.nonce, { expires: 300 });
  158. Cookies.set("timestampMT", data.timestamp, { expires: 300 });
  159. this.$router.push({ path: "/index"})
  160. }else if(data.user.dmUser.type == "01"){
  161. if(data.user.dmUser.status == false){
  162. Toast("离职人员,暂无权限")
  163. return
  164. }else{
  165. Cookies.set("usernameMT", this.loginForm.username, { expires: 300 });
  166. Cookies.set("rememberMeMT", this.loginForm.rememberMe, { expires: 300 });
  167. Cookies.set("passwordMT", encrypt(this.loginForm.password), { expires: 300 });
  168. Cookies.set("userIdMT", data.user.id, { expires: 300 });
  169. Cookies.set("tokenMT", data.token, { expires: 300 });
  170. Cookies.set("nonceMT", data.nonce, { expires: 300 });
  171. Cookies.set("timestampMT", data.timestamp, { expires: 300 });
  172. this.$router.push({ path: "/index"})
  173. }
  174. }else if(data.user.dmUser.type == "02"){
  175. Toast("暂无权限")
  176. }else{
  177. }
  178. }
  179. }).catch(err =>{
  180. Toast(err.response.data.message)
  181. })
  182. setTimeout(()=>{
  183. this.loading = false
  184. },2000)
  185. }
  186. });
  187. }
  188. },
  189. },
  190. };
  191. </script>
  192. <style lang="scss" scoped>
  193. .mianBox{
  194. color: #000;
  195. position: fixed;
  196. top:0;
  197. left:0;
  198. width:100%;
  199. height:100%;
  200. overflow: hidden;
  201. display: flex;
  202. align-items: center;
  203. justify-content: center;
  204. background-color: #fff;
  205. }
  206. .opa1{
  207. opacity: 1;
  208. }
  209. .opa0{
  210. opacity: 0;
  211. }
  212. .login-form {
  213. border-radius: 6px;
  214. background: #ffffff;
  215. width: 90%;
  216. position: absolute;
  217. top:8%;
  218. left:5%;
  219. .login{
  220. width:60%;
  221. margin:10% 20%;
  222. }
  223. .el-form-item__content{
  224. height:40px;
  225. }
  226. .login-tip {
  227. font-size: 13px;
  228. text-align: center;
  229. color: #bfbfbf;
  230. }
  231. .login-code {
  232. width: 33%;
  233. height: 38px;
  234. float: right;
  235. margin-top:-2px;
  236. text-align: right;
  237. img {
  238. cursor: pointer;
  239. vertical-align: middle;
  240. }
  241. }
  242. .el-login-footer {
  243. height: 40px;
  244. line-height: 40px;
  245. position: fixed;
  246. bottom: 0;
  247. width: 100%;
  248. text-align: center;
  249. color: #fff;
  250. font-family: Arial;
  251. font-size: 12px;
  252. letter-spacing: 1px;
  253. }
  254. .login-code-img {
  255. height: 38px;
  256. }
  257. .el-button--primary{
  258. width:100%;
  259. margin-top:10px;
  260. color: #fff;
  261. background-color: rgba(242, 46, 60, 1);;
  262. border-color: rgba(242, 46, 60, 1);;
  263. border-radius: 4px;
  264. }
  265. .eyeWrap {
  266. position: relative;
  267. width:10%;
  268. right:0;
  269. height:2.5rem !important;
  270. margin:-2.5rem 0 0 90%;;
  271. }
  272. .z{
  273. position: absolute;
  274. top:0.8rem !important;
  275. }
  276. .eye {
  277. position: absolute;
  278. right: 0.5rem;
  279. top: 0.8rem;
  280. fill: #ccc;
  281. }
  282. .el-input__inner{
  283. padding-left:30px
  284. }
  285. .el-input__prefix{
  286. left:8px !important;
  287. }
  288. }
  289. </style>