index.vue 15 KB

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