index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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" />
  13. </el-input>
  14. </el-form-item>
  15. <el-form-item prop="password" style="position: relative;width:100%">
  16. <el-input
  17. class="inputs"
  18. ref="password"
  19. placeholder="请输入密码"
  20. name="password"
  21. @keyup.enter.native="login_info()"
  22. :type="passwordtxt"
  23. v-model="loginForm.password"
  24. >
  25. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  26. <svg-icon slot="prefix" icon-class="eye" class="el-input__icon input-icon eye" @click="eyeTab" v-show="passwordtxt =='password'" />
  27. <svg-icon slot="prefix" icon-class="eye-open" class="el-input__icon input-icon eye" @click="eyeTab" v-show="passwordtxt =='text'" />
  28. </el-input>
  29. </el-form-item>
  30. <!-- <el-form-item prop="code">
  31. <el-input
  32. v-model="loginForm.code"
  33. auto-complete="off"
  34. placeholder="验证码"
  35. style="width: 63%"
  36. >
  37. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  38. </el-input>
  39. <div class="login-code">
  40. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  41. </div>
  42. </el-form-item> -->
  43. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  44. <el-button
  45. type="primary"
  46. @click.native.prevent="login_info()"
  47. @keyup.enter = "login_info()"
  48. >
  49. <span v-if="!loading" >登 录</span>
  50. <span v-else>登 录 中...</span></el-button
  51. >
  52. </el-form>
  53. <van-loading
  54. size="24px"
  55. v-if="loading"
  56. color="#fff"
  57. vertical
  58. style="z-index: 2; position: fixed; top: 40%; left: 0; right: 0"
  59. >登录中...</van-loading
  60. >
  61. <van-overlay :show="loading" style="z-index: 1; position: fixed;background-color: rgba(0,0,0,0.6);" />
  62. </div>
  63. </template>
  64. <script>
  65. import { Toast } from "vant";
  66. import axios from "axios";
  67. import Cookies from "js-cookie";
  68. import { encrypt, decrypt } from '../../utils/jsencrypt';
  69. export default {
  70. data() {
  71. return {
  72. login:false,
  73. loading:false,
  74. passwordtxt:"password",
  75. codeUrl: "",
  76. cookiePassword: "",
  77. show_num:[],
  78. // 验证码开关
  79. // captchaOnOff: true,
  80. loginForm: {
  81. username: "",
  82. password: "",
  83. rememberMe: false,
  84. code: "",
  85. uuid: ""
  86. },
  87. loginRules: {
  88. username: [
  89. { required: true, trigger: "blur", message: "请输入您的账号" }
  90. ],
  91. password: [
  92. { required: true, trigger: "blur", message: "请输入您的密码" }
  93. ],
  94. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  95. },
  96. appid:"wxd64360a4b8c50006",
  97. secret:"b758e45c89162542610509dafd9db7c3",
  98. code:undefined,
  99. };
  100. },
  101. mounted() {
  102. document.title = '中国东信智慧园区'
  103. Cookies.set("openid57",'o5P6I5tLj-TjrK7leWUT8EFmTCa4')
  104. if(Cookies.get('rememberMe57')){
  105. this.loginForm.rememberMe = Boolean(Cookies.get('rememberMe57'))
  106. }
  107. if(Cookies.get("username57")){
  108. this.loginForm.username = Cookies.get("username57")
  109. }
  110. if(Cookies.get("password57")){
  111. this.loginForm.password = decrypt(Cookies.get("password57"))
  112. }
  113. if(Cookies.get("openid57")){
  114. if(Cookies.get("username57") && Cookies.get("password57")){
  115. this.login_info()
  116. this.login = false
  117. }else{
  118. this.login = true
  119. }
  120. }else{
  121. this.login = true
  122. let url = window.location.href
  123. if(url.indexOf("?code")>0){
  124. let code = this.getRequest("code")
  125. this.wx_openid(code)
  126. }else{
  127. this.wx_login()
  128. }
  129. }
  130. },
  131. methods: {
  132. //获取url指定参数
  133. getRequest(parName){
  134. var str=parName.toLowerCase()+"=";
  135. var gvalue="";
  136. var HREF=location.href;
  137. var upperHREF=location.href.toLowerCase();
  138. if(upperHREF.indexOf(str)>0) {
  139. gvalue=HREF.substring(upperHREF.indexOf(str)+str.length,upperHREF.length);
  140. if(gvalue.indexOf('&')>0)gvalue=gvalue.substring(0,gvalue.indexOf('&'));
  141. if(gvalue.indexOf("#")>0)gvalue=gvalue.split("#")[0];
  142. gvalue = decodeURIComponent(gvalue)
  143. }
  144. return gvalue;
  145. },
  146. wx_login(){//微信拉起授权获取code
  147. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd64360a4b8c50006&redirect_uri=https://smartpark.caih.com/vuepay&response_type=code&scope=snsapi_base&state=123`
  148. //获取openid
  149. //https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxd64360a4b8c50006&secret=b758e45c89162542610509dafd9db7c3&code=021Ye8Ha1jvNXC0ckiJa1JtKPF2Ye8Hp&grant_type=authorization_code
  150. },
  151. wx_openid(code){//获取openid
  152. axios.get('/offOpenId' + '?code=' + code, {
  153. code:code
  154. }).then(res => {
  155. if(res.data.data){
  156. Cookies.set("openid57",res.data.data)
  157. }
  158. })
  159. },
  160. eyeTab(){//密码显示开关
  161. if(this.passwordtxt == "password"){
  162. this.passwordtxt = "text"
  163. }else{
  164. this.passwordtxt = "password"
  165. }
  166. },
  167. // getCode() {//获取验证码
  168. // getCodeImg().then(res => {
  169. // this.codeUrl = "data:image/gif;base64," + res.data.img;
  170. // this.loginForm.uuid = res.data.uuid;
  171. // });
  172. // },
  173. getCookie() {//缓存数据
  174. const username = Cookies.get("username57");
  175. const password = Cookies.get("password57");
  176. const rememberMe = Cookies.get('rememberMe57')
  177. this.loginForm = {
  178. username: username === undefined ? this.loginForm.username : username,
  179. password: password === undefined ? this.loginForm.password : decrypt(password),
  180. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  181. };
  182. },
  183. login_info() {
  184. if(Cookies.get("openid57") && Cookies.get("username57") && Cookies.get("password57")){
  185. this.$router.push({ path: "/home"})
  186. }else{
  187. this.$refs.loginForm.validate(valid => {
  188. if (valid) {
  189. this.loading = true;
  190. axios.get(`https://smartpark.caih.com/zkxt/api/thirdparty/v1/user/appLogin?name=${this.loginForm.username}&pass=${this.loginForm.password}`).then(res => {
  191. if (res?.data?.data?.data?.cipher) {
  192. let data = res.data.data.data
  193. //人员种类(00-正式人员、01-外协单位、02-租户)
  194. if(data.user.dmUser.type == "00"){
  195. //Toast('请使用"中国东信APP查看功能"')
  196. localStorage.setItem("cipher57",data.cipher)
  197. localStorage.setItem("classify","1")
  198. Cookies.set("username57", this.loginForm.username, { expires: 300 });
  199. Cookies.set("rememberMe57", this.loginForm.rememberMe, { expires: 300 });
  200. Cookies.set("password57", encrypt(this.loginForm.password), { expires: 300 });
  201. Cookies.set("portrait57", data.user.dmUser.faceid, { expires: 300 });
  202. Cookies.set("userId57", data.userId, { expires: 300 });
  203. Cookies.set("token57", data.token, { expires: 300 });
  204. Cookies.set("nonce57", data.nonce, { expires: 300 });
  205. Cookies.set("timestamp57", data.timestamp, { expires: 300 });
  206. Cookies.set("nickName57", data.user.nickName, { expires: 300 });
  207. Cookies.set("dept57", data.user.dept.name, { expires: 300 });
  208. Cookies.set("phone57", data.user.dmUser.contacts, { expires: 300 });
  209. Cookies.set("people57", 0, { expires: 300 });
  210. axios.put('/dxtop/staff', {
  211. id:data.userId,
  212. openId:Cookies.get("openid57")
  213. })
  214. this.$router.push({ path: "/home"})
  215. }else if(data.user.dmUser.type == "01"){
  216. if(data.user.dmUser.status == false){
  217. Toast("离职人员,暂无权限")
  218. return
  219. }else{
  220. localStorage.setItem("cipher57",data.cipher)
  221. localStorage.setItem("classify","1")
  222. Cookies.set("username57", this.loginForm.username, { expires: 300 });
  223. Cookies.set("rememberMe57", this.loginForm.rememberMe, { expires: 300 });
  224. Cookies.set("password57", encrypt(this.loginForm.password), { expires: 300 });
  225. Cookies.set("portrait57", data.user.dmUser.faceid, { expires: 300 });
  226. Cookies.set("userId57", data.userId, { expires: 300 });
  227. Cookies.set("token57", data.token, { expires: 300 });
  228. Cookies.set("nonce57", data.nonce, { expires: 300 });
  229. Cookies.set("timestamp57", data.timestamp, { expires: 300 });
  230. Cookies.set("nickName57", data.user.nickName, { expires: 300 });
  231. Cookies.set("dept57", data.user.dept.name, { expires: 300 });
  232. Cookies.set("phone57", data.user.dmUser.contacts, { expires: 300 });
  233. Cookies.set("people57", 1, { expires: 300 });
  234. axios.put('/dxtop/staff', {
  235. id:data.userId,
  236. openId:Cookies.get("openid57")
  237. })
  238. this.$router.push({ path: "/home"})
  239. }
  240. }else if(data.user.dmUser.type == "02"){
  241. Toast("暂无权限")
  242. }else{
  243. }
  244. }
  245. }).catch(err =>{
  246. Toast(err.response.data.message)
  247. })
  248. setTimeout(()=>{
  249. this.loading = false
  250. },2000)
  251. }
  252. });
  253. }
  254. },
  255. },
  256. };
  257. </script>
  258. <style lang="scss" scoped>
  259. .mianBox{
  260. color: #000;
  261. position: fixed;
  262. top:0;
  263. left:0;
  264. width:100%;
  265. height:100%;
  266. overflow: hidden;
  267. display: flex;
  268. align-items: center;
  269. justify-content: center;
  270. background-color: #fff;
  271. }
  272. .opa1{
  273. opacity: 1;
  274. }
  275. .opa0{
  276. opacity: 0;
  277. }
  278. .login-form {
  279. border-radius: 6px;
  280. background: #ffffff;
  281. width: 90%;
  282. position: absolute;
  283. top:8%;
  284. left:5%;
  285. .login{
  286. width:60%;
  287. margin:10% 20%;
  288. }
  289. .el-form-item__content{
  290. height:40px;
  291. }
  292. .login-tip {
  293. font-size: 13px;
  294. text-align: center;
  295. color: #bfbfbf;
  296. }
  297. .login-code {
  298. width: 33%;
  299. height: 38px;
  300. float: right;
  301. margin-top:-2px;
  302. text-align: right;
  303. img {
  304. cursor: pointer;
  305. vertical-align: middle;
  306. }
  307. }
  308. .el-login-footer {
  309. height: 40px;
  310. line-height: 40px;
  311. position: fixed;
  312. bottom: 0;
  313. width: 100%;
  314. text-align: center;
  315. color: #fff;
  316. font-family: Arial;
  317. font-size: 12px;
  318. letter-spacing: 1px;
  319. }
  320. .login-code-img {
  321. height: 38px;
  322. }
  323. .el-button--primary{
  324. width:100%;
  325. margin-top:10px;
  326. color: #fff;
  327. background-color: rgba(242, 46, 60, 1);;
  328. border-color: rgba(242, 46, 60, 1);;
  329. border-radius: 4px;
  330. }
  331. .eye{
  332. position: absolute;
  333. top:12px;
  334. }
  335. @media screen and (min-width: 300px) and (max-width: 330px){
  336. .eye{
  337. left:250px;
  338. }
  339. }
  340. @media screen and (min-width: 340px) and (max-width: 365px){
  341. .eye{
  342. left:290px;
  343. }
  344. }
  345. @media screen and (min-width: 365px) and (max-width: 380px){
  346. .eye{
  347. left:300px;
  348. }
  349. }
  350. @media screen and (min-width: 381px) and (max-width: 400px){
  351. .eye{
  352. left:320px;
  353. }
  354. }
  355. @media screen and (min-width: 401px) and (max-width: 420px){
  356. .eye{
  357. left:330px;
  358. }
  359. }
  360. @media screen and (min-width: 421px) and (max-width: 440px){
  361. .eye{
  362. left:350px;
  363. }
  364. }
  365. .el-input__inner{
  366. padding-left:30px
  367. }
  368. .el-input__prefix{
  369. left:8px !important;
  370. }
  371. }
  372. </style>