index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <template>
  2. <div class="wrapper-box">
  3. <div class="page-account kf">
  4. <div class="content">
  5. <img :src="copyrightImg" alt="" />
  6. <div class="desc">
  7. <p class="tit">让客户服务如此简单</p>
  8. <p class="kefu">专业客服系统<br />助力企业打造一流的服务体验</p>
  9. </div>
  10. </div>
  11. <div class="container" :class="[fullWidth > 768 ? 'containerSamll' : 'containerBig']">
  12. <div class="index_from page-account-container">
  13. <div :style="{ display: !loginType ? 'block' : 'none' }">
  14. <div class="page-account-top">
  15. <div class="page-account-top-logo">客服登录</div>
  16. </div>
  17. <el-form ref="formInline" :model="formInline" :rules="ruleInline" @keyup.enter="handleSubmit('formInline')">
  18. <el-form-item prop="username">
  19. <el-input type="text" v-model="formInline.username" placeholder="请输入用户名" size="large" />
  20. </el-form-item>
  21. <el-form-item prop="password">
  22. <el-input type="password" v-model="formInline.password" placeholder="请输入密码" size="large" />
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button type="primary" long size="large" @click="handleSubmit('formInline')" class="btn">登录 </el-button>
  26. </el-form-item>
  27. </el-form>
  28. <div class="qh_box" v-if="!isMobile" @click="bindScan"><span class="iconfont iconerweima2"></span></div>
  29. </div>
  30. <div :style="{ display: loginType ? 'block' : 'none' }">
  31. <div class="page-account-top">
  32. <div class="page-account-top-logo">微信扫码登录</div>
  33. </div>
  34. <div class="code-box">
  35. <div class="qrcode" ref="qrCodeUrl"></div>
  36. <div class="rxpired-box" v-show="rxpired">
  37. <p>已过期</p>
  38. <el-button type="primary" @click="bindRefresh">点击刷新</el-button>
  39. </div>
  40. </div>
  41. <div class="qh_box" @click="loginType = 0"><span class="iconfont iconzhanghaomima"></span></div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="foot-box" v-if="copyright">{{ copyright }}</div>
  47. <div class="foot-box" v-else>
  48. Copyright © 2014-2023 <a href="https://www.crmeb.com" target="_blank">{{ version }}</a>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. import { AccountLogin, loginInfoApi, getSanCodeKey, scanStatus, kefuConfig } from '@/api/kefu';
  54. import mixins from '../account/mixins';
  55. import Setting from '@/setting';
  56. import util from '@/libs/util';
  57. import QRCode from 'qrcodejs2';
  58. import { getCookies, removeCookies, setCookies } from '@/libs/util';
  59. export default {
  60. mixins: [mixins],
  61. data() {
  62. return {
  63. fullWidth: document.documentElement.clientWidth,
  64. swiperOption: {
  65. pagination: '.swiper-pagination',
  66. autoplay: true,
  67. },
  68. modals: false,
  69. autoLogin: true,
  70. imgcode: '',
  71. formInline: {
  72. username: '',
  73. password: '',
  74. code: '',
  75. },
  76. ruleInline: {
  77. username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  78. password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
  79. code: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
  80. },
  81. errorNum: 0,
  82. jigsaw: null,
  83. login_logo: '',
  84. swiperList: [],
  85. defaultSwiperList: require('@/assets/images/sw.jpg'),
  86. loginType: 0, // 0 账号 1 扫码
  87. codeKey: '',
  88. scanTime: '',
  89. rxpired: false, // 扫码是否过期
  90. isMobile: false,
  91. version: '', //版本号
  92. isScan: false,
  93. timeNum: 0,
  94. copyright: '',
  95. copyrightImg: require('@/assets/images/logo-dark.png'),
  96. };
  97. },
  98. created() {
  99. kefuConfig().then((res) => {
  100. this.version = res.data.version;
  101. this.copyright = res.data.copyright;
  102. if (res.data.site_name) {
  103. document.title = res.data.site_name;
  104. }
  105. if (res.data.copyrightImg) {
  106. this.copyrightImg = res.data.copyrightImg;
  107. }
  108. });
  109. this.isMobile = this.$store.state.media.isMobile;
  110. var _this = this;
  111. top != window && (top.location.href = location.href);
  112. document.onkeydown = function (e) {
  113. if (_this.$route.name === 'login') {
  114. let key = window.event.keyCode;
  115. if (key === 13) {
  116. _this.handleSubmit('formInline');
  117. }
  118. }
  119. };
  120. window.addEventListener('resize', this.handleResize);
  121. },
  122. watch: {
  123. fullWidth(val) {
  124. // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
  125. if (!this.timer) {
  126. // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
  127. this.screenWidth = val;
  128. this.timer = true;
  129. let that = this;
  130. setTimeout(function () {
  131. // 打印screenWidth变化的值
  132. that.timer = false;
  133. }, 400);
  134. }
  135. },
  136. $route(n) {
  137. this.captchas();
  138. },
  139. },
  140. mounted: function () {
  141. this.$nextTick(() => {});
  142. this.captchas();
  143. },
  144. methods: {
  145. // 切换扫码
  146. bindScan() {
  147. if (!this.isScan) {
  148. this.isScan = true;
  149. this.getSanCodeKey();
  150. }
  151. this.loginType = 1;
  152. },
  153. // 生成二维码
  154. creatQrCode() {
  155. let url = `${window.location.protocol}//${window.location.host}/pages/users/scan_login/index?key=${this.codeKey}`;
  156. var qrcode = new QRCode(this.$refs.qrCodeUrl, {
  157. text: url, // 需要转换为二维码的内容
  158. width: 160,
  159. height: 160,
  160. colorDark: '#000000',
  161. colorLight: '#ffffff',
  162. correctLevel: QRCode.CorrectLevel.H,
  163. });
  164. },
  165. // 关闭模态框
  166. closeModel() {
  167. AccountLogin({
  168. account: this.formInline.username,
  169. password: this.formInline.password,
  170. imgcode: this.formInline.code,
  171. })
  172. .then(async (res) => {
  173. let expires = this.getExpiresTime(res.data.exp_time);
  174. // 记录用户登陆信息
  175. setCookies('kefu_uuid', res.data.kefuInfo.uid, expires);
  176. setCookies('kefu_token', res.data.token, expires);
  177. setCookies('kefu_expires_time', res.data.exp_time, expires);
  178. setCookies('kefuInfo', res.data.kefuInfo, expires);
  179. // 记录用户信息
  180. this.$store.commit('kefu/setInfo', res.data.kefuInfo);
  181. if (this.$store.state.media.isMobile) {
  182. //手机页面
  183. return this.$router.replace({ path: this.$route.query.redirect || '/kefu/mobile_list' });
  184. } else {
  185. // pc页面
  186. return this.$router.replace({ path: this.$route.query.redirect || '/kefu/pc_list' });
  187. }
  188. })
  189. .catch((res) => {
  190. let data = res === undefined ? {} : res;
  191. this.errorNum++;
  192. this.captchas();
  193. this.$message.error(data.msg || '登录失败');
  194. if (this.jigsaw) this.jigsaw.reset();
  195. });
  196. },
  197. getExpiresTime(expiresTime) {
  198. let nowTimeNum = Math.round(new Date() / 1000);
  199. let expiresTimeNum = expiresTime - nowTimeNum;
  200. return parseFloat(parseFloat(parseFloat(expiresTimeNum / 60) / 60) / 24);
  201. },
  202. closefail() {
  203. if (this.jigsaw) this.jigsaw.reset();
  204. this.$message.error('校验错误');
  205. },
  206. handleResize(event) {
  207. this.fullWidth = document.documentElement.clientWidth;
  208. },
  209. captchas: function () {
  210. this.imgcode = Setting.apiBaseURL + '/captcha_pro?' + Date.parse(new Date());
  211. },
  212. handleSubmit(name) {
  213. this.$refs[name].validate((valid) => {
  214. if (valid) {
  215. this.closeModel();
  216. }
  217. });
  218. },
  219. // 获取客服扫码key
  220. getSanCodeKey() {
  221. getSanCodeKey()
  222. .then((res) => {
  223. this.codeKey = res.data.key;
  224. this.creatQrCode();
  225. this.scanTime = setInterval(() => {
  226. this.timeNum++;
  227. if (this.timeNum >= 60) {
  228. this.timeNum = 0;
  229. window.clearInterval(this.scanTime);
  230. this.rxpired = true;
  231. } else {
  232. this.getScanStatus();
  233. }
  234. }, 1000);
  235. })
  236. .catch((error) => {
  237. this.timeNum = 0;
  238. window.clearInterval(this.scanTime);
  239. this.rxpired = true;
  240. this.$message.error(error.msg);
  241. });
  242. },
  243. // 扫码登录情况
  244. getScanStatus() {
  245. scanStatus(this.codeKey)
  246. .then(async (res) => {
  247. // 0 = 二维码过期需要重新获取授权凭证
  248. if (res.data.status == 0) {
  249. this.timeNum = 0;
  250. window.clearInterval(this.scanTime);
  251. this.rxpired = true;
  252. }
  253. // 1=正在扫描
  254. if (res.data.status == 1) {
  255. }
  256. // 3 扫描成功正在登录
  257. if (res.data.status == 3) {
  258. window.clearInterval(this.scanTime);
  259. let expires = this.getExpiresTime(res.data.exp_time);
  260. // 记录用户登陆信息
  261. setCookies('kefu_uuid', res.data.kefuInfo.uid, expires);
  262. setCookies('kefu_token', res.data.token, expires);
  263. setCookies('kefu_expires_time', res.data.exp_time, expires);
  264. setCookies('kefuInfo', res.data.kefuInfo, expires);
  265. // 记录用户信息
  266. this.$store.commit('kefu/setInfo', res.data.kefuInfo);
  267. if (this.$store.state.media.isMobile) {
  268. //手机页面
  269. return this.$router.replace({ path: this.$route.query.redirect || '/kefu/mobile_list' });
  270. } else {
  271. // pc页面
  272. return this.$router.replace({ path: this.$route.query.redirect || '/kefu/pc_list' });
  273. }
  274. }
  275. })
  276. .catch((error) => {
  277. this.$Modal.error({
  278. title: '提示',
  279. content: error.msg,
  280. });
  281. this.timeNum = 0;
  282. window.clearInterval(this.scanTime);
  283. this.rxpired = true;
  284. });
  285. },
  286. // 刷新二维码
  287. bindRefresh() {
  288. this.$refs.qrCodeUrl.innerHTML = '';
  289. this.rxpired = false;
  290. this.getSanCodeKey();
  291. },
  292. },
  293. beforeCreate() {},
  294. beforeDestroy: function () {
  295. this.timeNum = 0;
  296. this.$refs.qrCodeUrl.innerHTML = '';
  297. window.clearInterval(this.scanTime);
  298. window.removeEventListener('resize', this.handleResize);
  299. // document.getElementsByTagName('canvas')[0].removeAttribute('class', 'index_bg');
  300. },
  301. };
  302. </script>
  303. <style scoped lang="stylus">
  304. .page-account {
  305. display: flex;
  306. width: 100%;
  307. background-image: url('~@/assets/images/kfbg_2.jpg');
  308. background-size: cover;
  309. background-position: center;
  310. justify-content: center;
  311. align-items: center;
  312. height: 100vh;
  313. overflow: auto;
  314. .content {
  315. height: 400px;
  316. margin-right: 100px;
  317. .desc {
  318. color: #fff;
  319. .tit {
  320. font-size: 40px;
  321. font-weight: 600;
  322. }
  323. .kefu {
  324. margin-top: 30px;
  325. font-weight: 500;
  326. font-size: 20px;
  327. }
  328. }
  329. img {
  330. width: 360px;
  331. margin-left: -100px;
  332. }
  333. }
  334. }
  335. .code-box {
  336. position: relative;
  337. display: flex;
  338. align-items: center;
  339. justify-content: center;
  340. .qrcode {
  341. display: flex;
  342. align-items: center;
  343. justify-content: center;
  344. width: 180px;
  345. height: 180px;
  346. border: 1px solid #E5E5E6;
  347. }
  348. .rxpired-box {
  349. display: flex;
  350. flex-direction: column;
  351. align-items: center;
  352. justify-content: center;
  353. position: absolute;
  354. left: 50%;
  355. top: 50%;
  356. transform: translate(-50%, -50%);
  357. width: 160px;
  358. height: 160px;
  359. background: rgba(0, 0, 0, 0.6);
  360. p {
  361. margin-bottom: 10px;
  362. font-size: 15px;
  363. color: #fff;
  364. }
  365. }
  366. }
  367. .page-account-top-logo {
  368. color: #000000;
  369. font-size: 21px;
  370. }
  371. .wrapper-box {
  372. display: flex;
  373. flex-direction: column;
  374. height: 100vh;
  375. .foot-box {
  376. padding: 20px 20px;
  377. font-size: 14px;
  378. color: #666666;
  379. text-align: right;
  380. box-sizing: border-box;
  381. a {
  382. margin-left: 0;
  383. color: #666666;
  384. }
  385. }
  386. }
  387. .page-account {
  388. display: flex;
  389. flex: 1;
  390. }
  391. .page-account .code {
  392. display: flex;
  393. align-items: center;
  394. justify-content: center;
  395. }
  396. .page-account .code .pictrue {
  397. height: 40px;
  398. }
  399. .swiperPross {
  400. border-radius: 6px 0px 0px 6px;
  401. }
  402. .swiperPross, .swiperPic, .swiperPic img {
  403. width: 510px;
  404. height: 100%;
  405. }
  406. .swiperPic img {
  407. width: 100%;
  408. height: 100%;
  409. }
  410. .container {
  411. height: 400px !important;
  412. padding: 0 !important;
  413. /* overflow: hidden; */
  414. border-radius: 6px;
  415. z-index: 1;
  416. display: flex;
  417. }
  418. .containerSamll {
  419. width: 384px !important;
  420. // margin-left: 30%;
  421. background: #fff !important;
  422. }
  423. .containerBig {
  424. width: 90%;
  425. padding-bottom: 20px;
  426. margin-top: 84px;
  427. background: #f7f7f7 !important;
  428. height: auto !important;
  429. box-shadow: 0px 3px 20px rgba(0, 20, 41, 0.06);
  430. }
  431. .index_from {
  432. position: relative;
  433. padding: 40px 40px 32px 40px;
  434. height: 400px;
  435. width: 100%;
  436. box-sizing: border-box;
  437. }
  438. .containerBig .index_from {
  439. padding: 20px;
  440. height: auto !important;
  441. }
  442. .index_from .qh_box {
  443. position: absolute;
  444. right: 12px;
  445. top: 0;
  446. cursor: pointer;
  447. .iconfont {
  448. color: #265BED;
  449. font-size: 36px;
  450. }
  451. }
  452. .page-account-top {
  453. padding: 20px 0 50px !important;
  454. box-sizing: border-box !important;
  455. display: flex;
  456. justify-content: center;
  457. }
  458. .page-account-container {
  459. border-radius: 0px 6px 6px 0px;
  460. }
  461. .btn {
  462. background: #265BED;
  463. }
  464. .captchaBox {
  465. width: 310px;
  466. }
  467. input {
  468. display: block;
  469. width: 290px;
  470. line-height: 40px;
  471. margin: 10px 0;
  472. padding: 0 10px;
  473. outline: none;
  474. border: 1px solid #c8cccf;
  475. border-radius: 4px;
  476. color: #6a6f77;
  477. }
  478. #msg {
  479. width: 100%;
  480. line-height: 40px;
  481. font-size: 14px;
  482. text-align: center;
  483. }
  484. a:link, a:visited, a:hover, a:active {
  485. margin-left: 100px;
  486. color: #0366D6;
  487. }
  488. .index_from >>> .ivu-input-large {
  489. font-size: 14px !important;
  490. }
  491. </style>
  492. <style>
  493. @media screen and (min-width: 320px) and (max-width: 960px) {
  494. .page-account {
  495. background-image: url('~@/assets/images/m_bg.png') !important;
  496. background-size: 100% auto !important;
  497. background-repeat: no-repeat;
  498. background-position: left top !important;
  499. display: flex;
  500. }
  501. .wrapper-box .foot-box {
  502. text-align: center !important;
  503. }
  504. .content {
  505. display: none;
  506. }
  507. .index_from {
  508. box-shadow: 0px 3px 20px rgba(0, 20, 41, 0.06);
  509. background: #fff;
  510. }
  511. .wrapper-box .foot-box {
  512. padding: 20px 66px !important;
  513. color: #adadad !important;
  514. font-size: 0.22rem !important;
  515. }
  516. .containerBig {
  517. width: 86% !important;
  518. border-radius: 0.2rem !important;
  519. overflow: hidden;
  520. }
  521. .btn {
  522. background: linear-gradient(90deg, #3875ea 0%, #1890fc 100%) !important;
  523. border-radius: 0.41rem;
  524. }
  525. .ivu-input {
  526. border: 1px solid #dcdee2;
  527. -webkit-appearance: none; /*去除阴影边框*/
  528. outline: none;
  529. -webkit-tap-highlight-color: rgba(0, 0, 0, 0); /*点击高亮的颜色*/
  530. }
  531. }
  532. </style>