login.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <div>
  3. <form action>
  4. <div class="login">
  5. <div class="loginBg">
  6. <img src="@/assets/img/loginBg.png" />
  7. </div>
  8. <div class="loginBox">
  9. <div class="row center" style="height:48px;">
  10. <img :src="img_http + logo" alt style="width: 30px; height: 30px;" />
  11. </div>
  12. <div class="row center">
  13. <span style="font-size:16px;color:#666;">客服系统客服登录</span>
  14. </div>
  15. <div class="box row center">
  16. <div class="boxData" :class="0?'errBd':''">
  17. <input type="text" v-model="account" placeholder="账号" />
  18. <img src="@/assets/img/account.png" />
  19. <p v-if="0" style="color:#f60;font-size:14px;margin-top:5px;margin-left:3px;">账号不存在</p>
  20. </div>
  21. </div>
  22. <div class="box row center">
  23. <div class="boxData" :class="0?'errBd':''">
  24. <input type="password" v-model="password" placeholder="密码" />
  25. <img src="@/assets/img/password.png" />
  26. <p
  27. v-if="0"
  28. style="color:#f60;font-size:14px;margin-top:5px;margin-left:3px;"
  29. >密码错误,请重新输入</p>
  30. </div>
  31. </div>
  32. <div class="box row center" v-if="showSecurityCode">
  33. <div class="boxData" :class="0?'errBd':''">
  34. <input
  35. maxlength="6"
  36. @keyup.enter="loginBtn()"
  37. @blur="testCode()"
  38. type="text"
  39. v-model="securityCode"
  40. placeholder="验证码"
  41. />
  42. <img src="@/assets/img/password.png" />
  43. <p
  44. v-if="0"
  45. style="color:#f60;font-size:14px;margin-top:5px;margin-left:3px;"
  46. >验证码错误,请重新输入</p>
  47. </div>
  48. </div>
  49. <div class="box row center">
  50. <div class="btn row center" @click="loginBtn()">登录</div>
  51. </div>
  52. </div>
  53. </div>
  54. </form>
  55. </div>
  56. </template>
  57. <script>
  58. import "@/css/index.css";
  59. import Vue from "vue";
  60. export default {
  61. name: "login",
  62. data() {
  63. return {
  64. account: "", //账号
  65. password: "", //密码
  66. securityCode: "", // 验证码
  67. time: "",
  68. loading: false,
  69. showSecurityCode: false,
  70. logo: "",
  71. verifySystem: "",
  72. verifySystemId: "",
  73. img_http: "http://manage.281570.com" //图片路径域
  74. // img_http: 'http://192.168.2.187:8090',//图片路径域
  75. };
  76. },
  77. methods: {
  78. testCode() {
  79. if (this.showSecurityCode) {
  80. if (!/^[0-9]+$/.test(this.securityCode)) {
  81. this.$message.error("验证码错误!");
  82. this.securityCode = "";
  83. }
  84. }
  85. },
  86. loginBtn() {
  87. this.time = sessionStorage.getItem("time");
  88. if (this.$store.getters.get_socket_open) {
  89. let apiToken = this.$md5("customer-service" + window.location.origin);
  90. if (this.account && this.password) {
  91. //进程加载条
  92. const loading = this.$loading({
  93. lock: true,
  94. text: "Loading",
  95. spinner: "el-icon-loading",
  96. background: "rgba(0, 0, 0, 0.7)"
  97. });
  98. // console.log(this.verifySystemId)
  99. // console.log(this.verifySystem)
  100. // console.log(this.securityCode)
  101. let parmas;
  102. if (this.showSecurityCode) {
  103. parmas = {
  104. username: this.account,
  105. password: this.password,
  106. securityCode: this.securityCode
  107. };
  108. } else {
  109. parmas = {
  110. username: this.account,
  111. password: this.password,
  112. verifySystemId: this.verifySystemId,
  113. verifySystem: this.verifySystem
  114. };
  115. }
  116. this.$http.post(this.$ports.login, parmas).then(res => {
  117. if (res.data.code == 1) {
  118. this.$store.dispatch("SET_USER", res.data.data.user);
  119. this.$store.dispatch("SET_IS_INIT", true);
  120. this.$websocket.send(
  121. JSON.stringify({
  122. type: "init",
  123. data: {
  124. uid: "KF" + res.data.data.user.id,
  125. group: res.data.data.user.group_id,
  126. token: res.data.data.user.token,
  127. name: res.data.data.user.user_name,
  128. avatar: res.data.data.user.user_avatar
  129. }
  130. })
  131. );
  132. this.$router.push({
  133. path: "/",
  134. query: { pid: escape("这就是一个编码没有什么用啊") }
  135. });
  136. } else if (res.data.code == 100) {
  137. this.$message.success(res.data.msg);
  138. loading.close();
  139. } else {
  140. this.$notify({
  141. title: "错误",
  142. message: res.data.msg,
  143. type: "error",
  144. duration: 2000
  145. });
  146. }
  147. loading.close();
  148. });
  149. } else {
  150. this.$notify({
  151. title: "错误提示!",
  152. message: "请输入您的账号和密码",
  153. type: "error",
  154. duration: 2000
  155. });
  156. }
  157. } else {
  158. this.$notify({
  159. title: "错误提示!",
  160. message: "网路链接错误",
  161. type: "error",
  162. duration: 2000
  163. });
  164. }
  165. },
  166. /**************************************/
  167. //连接建立
  168. websocketonopen() {
  169. this.$websocket.onopen();
  170. //console.log('已经链接')
  171. }
  172. },
  173. mounted() {
  174. // 判断验证码参数
  175. let SystemId = this.$public.getQueryString("id");
  176. let System = this.$public.getQueryString("code");
  177. let checkVcode=true;
  178. if (!SystemId && !System) {
  179. this.showSecurityCode = true;
  180. } else {
  181. this.showSecurityCode = false;
  182. this.verifySystemId = SystemId;
  183. this.verifySystem = System;
  184. localStorage.clear();
  185. sessionStorage.clear();
  186. checkVcode=false;
  187. }
  188. this.$comm.checkValidCodeEnabled((data)=> {
  189. if (data == 0) {
  190. this.showSecurityCode = false;
  191. } else {
  192. this.showSecurityCode = true;
  193. if(!checkVcode){
  194. this.showSecurityCode = false;
  195. }
  196. }
  197. });
  198. this.$http.get(this.$ports.TIME).then(res => {
  199. if (res.data.code == 1) {
  200. let time = res.data.data.time.split(" ");
  201. time[0] = new Date(time[0].replace(/-/g, "/")).getTime() / 1000;
  202. sessionStorage.setItem("time", JSON.stringify(time));
  203. this.logo = res.data.data.logo;
  204. sessionStorage.setItem("logo", res.data.data.logo);
  205. }
  206. });
  207. }
  208. };
  209. </script>
  210. <style scoped>
  211. p {
  212. display: inline;
  213. margin-block-start: 0;
  214. margin-block-end: 0;
  215. margin-inline-start: 0;
  216. margin-inline-end: 0;
  217. }
  218. .login {
  219. width: 100%;
  220. height: 100%;
  221. }
  222. .loginBg {
  223. height: 50%;
  224. }
  225. .loginBg img {
  226. width: 100%;
  227. height: 100%;
  228. }
  229. .loginBox {
  230. position: fixed;
  231. top: 27%;
  232. left: 0px;
  233. right: 0px;
  234. margin: auto;
  235. width: 300px;
  236. height: 280px;
  237. background: #fff;
  238. border-radius: 2%;
  239. box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.1);
  240. }
  241. .box {
  242. /* margin-top: 40px; */
  243. height: 50px;
  244. }
  245. .boxData {
  246. width: 200px;
  247. /* height: 70px; */
  248. /*border: 1px solid #C6DCFF;*/
  249. background: #f6f8ff;
  250. position: relative;
  251. }
  252. .boxData img {
  253. position: absolute;
  254. left: 6px;
  255. top: 0;
  256. bottom: 0;
  257. margin: auto 0;
  258. height: 55%;
  259. }
  260. .boxData input {
  261. width: 100%;
  262. height: 30px;
  263. outline: none;
  264. padding-left: 30px;
  265. font-size: 14px;
  266. color: #999;
  267. }
  268. .boxData input:focus {
  269. color: #666;
  270. }
  271. .errBd {
  272. border: 1px solid #f60;
  273. }
  274. .btn {
  275. width: 240px;
  276. height: 40px;
  277. background: #5399f5;
  278. font-size: 18px;
  279. color: #fff;
  280. border: none;
  281. }
  282. .btn:hover {
  283. }
  284. .btn:active {
  285. background: #1d57dd;
  286. }
  287. </style>