index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <template>
  2. <div class="page-account">
  3. <div class="container" :class="[fullWidth > 768 ? 'containerSamll' : 'containerBig']">
  4. <swiper :options="swiperOption" class="swiperPross" v-if="fullWidth > 768">
  5. <swiper-slide class="swiperPic" v-for="(item, index) in swiperList" :key="index">
  6. <img :src="item.slide" alt="" />
  7. </swiper-slide>
  8. <div class="swiper-pagination" slot="pagination"></div>
  9. </swiper>
  10. <div class="index_from page-account-container from-wh">
  11. <div class="page-account-top">
  12. <div class="page-account-top-logo">
  13. <img :src="login_logo" alt="logo" style="width: 100%; height: 74px" />
  14. </div>
  15. </div>
  16. <Form ref="formInline" :model="formInline" :rules="ruleInline" @keyup.enter="handleSubmit('formInline')">
  17. <FormItem prop="username">
  18. <Input
  19. type="text"
  20. v-model="formInline.username"
  21. prefix="ios-contact-outline"
  22. placeholder="请输入用户名"
  23. size="large"
  24. />
  25. </FormItem>
  26. <FormItem prop="password">
  27. <Input
  28. type="password"
  29. v-model="formInline.password"
  30. prefix="ios-lock-outline"
  31. placeholder="请输入密码"
  32. size="large"
  33. />
  34. </FormItem>
  35. <!-- <FormItem prop="code">
  36. <div class="code">
  37. <Input
  38. type="text"
  39. v-model="formInline.code"
  40. prefix="ios-keypad-outline"
  41. placeholder="请输入验证码"
  42. size="large"
  43. />
  44. <img :src="imgcode" class="pictrue" @click="captchas" />
  45. </div>
  46. </FormItem> -->
  47. <FormItem class="pt10">
  48. <Button type="primary" long :loading="loading" size="large" @click="handleSubmit('formInline')" class="btn"
  49. >登录</Button
  50. >
  51. </FormItem>
  52. </Form>
  53. </div>
  54. </div>
  55. <Verify
  56. @success="success"
  57. captchaType="blockPuzzle"
  58. :imgSize="{ width: '330px', height: '155px' }"
  59. ref="verify"
  60. ></Verify>
  61. <div class="footer">
  62. <div class="pull-right" v-if="copyright">{{ copyright }}</div>
  63. <div class="pull-right" v-else>
  64. Copyright © 2014-2023 <a href="https://www.crmeb.com" target="_blank">{{ version }}</a>
  65. </div>
  66. </div>
  67. </div>
  68. </template>
  69. <script>
  70. import { AccountLogin, loginInfoApi } from '@/api/account';
  71. import { getWorkermanUrl } from '@/api/kefu';
  72. import { setCookies } from '@/libs/util';
  73. import '@/assets/js/canvas-nest.min';
  74. import Verify from '@/components/verifition/Verify';
  75. import { PrevLoading } from '@/utils/loading.js';
  76. import { formatFlatteningRoutes, findFirstNonNullChildren } from '@/libs/system';
  77. export default {
  78. components: {
  79. Verify,
  80. },
  81. data() {
  82. return {
  83. fullWidth: document.documentElement.clientWidth,
  84. swiperOption: {
  85. pagination: '.swiper-pagination',
  86. autoplay: true,
  87. },
  88. loading: false,
  89. isShow: false,
  90. autoLogin: true,
  91. imgcode: '',
  92. formInline: {
  93. username: '',
  94. password: '',
  95. },
  96. ruleInline: {
  97. username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  98. password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
  99. },
  100. login_captcha: 0,
  101. // jigsaw: null,
  102. login_logo: '',
  103. swiperList: [],
  104. defaultSwiperList: require('@/assets/images/sw.jpg'),
  105. key: '',
  106. copyright: '',
  107. version: '',
  108. };
  109. },
  110. created() {
  111. const _this = this;
  112. document.onkeydown = function () {
  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. },
  138. mounted: function () {
  139. this.$nextTick(() => {
  140. // /* eslint-disable */
  141. let that = this;
  142. // this.jigsaw = jigsaw.init({
  143. // el: this.$refs.captcha,
  144. // onSuccess() {
  145. // that.modals = false;
  146. // that.closeModel();
  147. // },
  148. // onFail: this.closefail,
  149. // onRefresh() {},
  150. // });
  151. if (this.screenWidth < 768) {
  152. document.getElementsByTagName('canvas')[0].removeAttribute('class', 'index_bg');
  153. } else {
  154. document.getElementsByTagName('canvas')[0].className = 'index_bg';
  155. }
  156. this.swiperData();
  157. });
  158. },
  159. methods: {
  160. swiperData() {
  161. loginInfoApi()
  162. .then((res) => {
  163. window.document.title = `${res.data.site_name} - 登录`;
  164. localStorage.setItem('ADMIN_TITLE', res.data.site_name || '');
  165. this.$store.commit('setAdminTitle', res.data.site_name);
  166. let data = res.data || {};
  167. this.login_logo = data.login_logo ? data.login_logo : require('@/assets/images/logo.png');
  168. this.swiperList = data.slide.length ? data.slide : [{ slide: this.defaultSwiperList }];
  169. this.key = data.key;
  170. this.copyright = data.copyright;
  171. this.version = data.version;
  172. this.login_captcha = data.login_captcha;
  173. })
  174. .catch((err) => {
  175. this.$Message.error(err);
  176. this.login_logo = require('@/assets/images/logo.png');
  177. this.swiperList = [{ slide: this.defaultSwiperList }];
  178. });
  179. },
  180. success(params) {
  181. this.closeModel(params);
  182. },
  183. // 关闭模态框
  184. closeModel(params) {
  185. this.isShow = false;
  186. // noinspection JSVoidFunctionReturnValueUsed
  187. let msg = this.$Message.loading({
  188. content: '登录中...',
  189. duration: 0,
  190. });
  191. this.loading = true;
  192. AccountLogin({
  193. account: this.formInline.username,
  194. pwd: this.formInline.password,
  195. key: this.key,
  196. captchaType: 'blockPuzzle',
  197. captchaVerification: params ? params.captchaVerification : '',
  198. })
  199. .then(async (res) => {
  200. msg();
  201. let data = res.data;
  202. let expires = this.getExpiresTime(data.expires_time);
  203. // 记录用户登陆信息
  204. setCookies('uuid', data.user_info.id, expires);
  205. setCookies('token', data.token, expires);
  206. setCookies('expires_time', data.expires_time, expires);
  207. this.$store.commit('userInfo/uniqueAuth', data.unique_auth);
  208. this.$store.commit('userInfo/userInfo', data.user_info);
  209. // 保存菜单信息
  210. this.$store.commit('menus/setopenMenus', []);
  211. this.$store.commit('menus/getmenusNav', data.menus);
  212. this.$store.dispatch('routesList/setRoutesList', data.menus);
  213. let arr = formatFlatteningRoutes(this.$router.options.routes);
  214. this.formatTwoStageRoutes(arr);
  215. this.$store.commit('menus/setOneLvMenus', arr);
  216. let routes = formatFlatteningRoutes(data.menus);
  217. this.$store.commit('menus/setOneLvRoute', routes);
  218. // 记录用户信息
  219. this.$store.commit('userInfo/name', data.user_info.account);
  220. this.$store.commit('userInfo/avatar', data.user_info.head_pic);
  221. this.$store.commit('userInfo/access', data.unique_auth);
  222. this.$store.commit('userInfo/logo', data.logo);
  223. this.$store.commit('userInfo/logoSmall', data.logo_square);
  224. this.$store.commit('userInfo/version', data.version);
  225. this.$store.commit('userInfo/newOrderAudioLink', data.newOrderAudioLink);
  226. this.login_captcha = 0;
  227. try {
  228. if (data.queue === false) {
  229. this.$Notice.warning({
  230. title: '温馨提示',
  231. desc: '您的【消息队列】未开启,没有开启会导致异步任务无法执行。请尽快执行命令开启!!<a href="https://doc.crmeb.com/single/crmeb_v4/7217" target="_blank">点击查看开启方法</a>',
  232. duration: 30,
  233. });
  234. }
  235. if (data.timer === false) {
  236. this.$Notice.warning({
  237. title: '温馨提示',
  238. desc: '您的【定时任务】未开启,没有开启会导致自动收货、未支付自动取消订单、订单自动好评、拼团到期退款等任务无法正常执行。请尽快执行命令开启!!<a href="https://doc.crmeb.com/single/crmeb_v4/7211" target="_blank">点击查看开启方法</a>',
  239. duration: 30,
  240. });
  241. }
  242. this.checkSocket();
  243. } catch (e) {}
  244. PrevLoading.start();
  245. return this.$router.push({
  246. path: findFirstNonNullChildren(res.data.menus).path || this.$routeProStr + '/',
  247. });
  248. })
  249. .catch((res) => {
  250. msg();
  251. let data = res === undefined ? {} : res;
  252. this.$Message.error(data.msg || '登录失败');
  253. this.login_captcha = res.data.login_captcha;
  254. });
  255. setTimeout((e) => {
  256. this.loading = false;
  257. }, 1000);
  258. },
  259. formatTwoStageRoutes(arr) {
  260. if (arr.length <= 0) return false;
  261. const newArr = [];
  262. const cacheList = [];
  263. arr.forEach((v) => {
  264. if (v && v.meta && v.meta.keepAlive) {
  265. newArr.push({ ...v });
  266. cacheList.push(v.name);
  267. this.$store.dispatch('keepAliveNames/setCacheKeepAlive', cacheList);
  268. }
  269. });
  270. return newArr;
  271. },
  272. checkSocket() {
  273. getWorkermanUrl().then((res) => {
  274. let url = res.data.admin;
  275. let isNotice = false;
  276. let socket = new WebSocket(url);
  277. socket.onopen = () => {
  278. isNotice = true;
  279. socket.close();
  280. };
  281. socket.onerror = (err) => {
  282. if (!isNotice) {
  283. isNotice = true;
  284. this.$Notice.warning({
  285. title: '温馨提示',
  286. desc: '您的【长连接】未开启,没有开启会导致系统默认客服无法使用,后台订单通知无法收到。请尽快执行命令开启!!<a href="https://doc.crmeb.com/single/crmeb_v4/7219" target="_blank">点击查看开启方法</a>',
  287. duration: 30,
  288. });
  289. }
  290. };
  291. socket.onclose = (err) => {
  292. if (!isNotice) {
  293. isNotice = true;
  294. this.$Notice.warning({
  295. title: '温馨提示',
  296. desc: '您的【长连接】未开启,没有开启会导致系统默认客服无法使用,后台订单通知无法收到。请尽快执行命令开启!!<a href="https://doc.crmeb.com/single/crmeb_v4/7219" target="_blank">点击查看开启方法</a>',
  297. duration: 30,
  298. });
  299. }
  300. };
  301. });
  302. },
  303. getExpiresTime(expiresTime) {
  304. let nowTimeNum = Math.round(new Date() / 1000);
  305. let expiresTimeNum = expiresTime - nowTimeNum;
  306. return parseFloat(parseFloat(parseFloat(expiresTimeNum / 60) / 60) / 24);
  307. },
  308. closefail() {
  309. // if (this.jigsaw) this.jigsaw.reset();
  310. this.$Message.error('校验错误');
  311. },
  312. handleResize(event) {
  313. this.fullWidth = document.documentElement.clientWidth;
  314. if (this.fullWidth < 768) {
  315. document.getElementsByTagName('canvas')[0].removeAttribute('class', 'index_bg');
  316. } else {
  317. document.getElementsByTagName('canvas')[0].className = 'index_bg';
  318. }
  319. },
  320. handleSubmit(name) {
  321. this.$refs[name].validate((valid) => {
  322. if (valid) {
  323. if (this.login_captcha == 1) {
  324. this.$refs.verify.show();
  325. } else {
  326. this.closeModel();
  327. }
  328. }
  329. });
  330. },
  331. },
  332. beforeCreate() {
  333. if (this.fullWidth < 768) {
  334. document.getElementsByTagName('canvas')[0].removeAttribute('class', 'index_bg');
  335. } else {
  336. document.getElementsByTagName('canvas')[0].className = 'index_bg';
  337. }
  338. },
  339. beforeDestroy: function () {
  340. window.removeEventListener('resize', this.handleResize);
  341. document.getElementsByTagName('canvas')[0].removeAttribute('class', 'index_bg');
  342. },
  343. };
  344. </script>
  345. <style scoped lang="stylus">
  346. .page-account {
  347. display: flex;
  348. width: 100%;
  349. background-image: url('../../../assets/images/bg.jpg');
  350. background-size: cover;
  351. background-position: center;
  352. flex-direction: column;
  353. justify-content: center;
  354. align-items: center;
  355. height: 100vh;
  356. overflow: auto;
  357. }
  358. .page-account .code {
  359. display: flex;
  360. align-items: center;
  361. justify-content: center;
  362. }
  363. .page-account .code .pictrue {
  364. height: 40px;
  365. }
  366. .swiperPross {
  367. border-radius: 12px 0px 0px 12px;
  368. }
  369. .swiperPross, .swiperPic, .swiperPic img {
  370. width: 510px;
  371. height: 100%;
  372. }
  373. .swiperPic img {
  374. width: 100%;
  375. height: 100%;
  376. }
  377. .container {
  378. height: 400px !important;
  379. padding: 0 !important;
  380. border-radius: 12px;
  381. z-index: 1;
  382. display: flex;
  383. }
  384. .containerSamll {
  385. /* width: 56% !important; */
  386. background: #fff !important;
  387. }
  388. .containerBig {
  389. width: auto !important;
  390. background: #f7f7f7 !important;
  391. }
  392. .index_from {
  393. padding: 32px 40px 32px 40px;
  394. height: 400px;
  395. box-sizing: border-box;
  396. }
  397. .page-account-top {
  398. padding: 20px 0 24px 0!important;
  399. box-sizing: border-box !important;
  400. display: flex;
  401. justify-content: center;
  402. }
  403. .page-account-container {
  404. border-radius: 0px 6px 6px 0px;
  405. }
  406. .btn {
  407. background: linear-gradient(90deg, rgba(25, 180, 241, 1) 0%, rgba(14, 115, 232, 1) 100%) !important;
  408. }
  409. .captchaBox {
  410. width: 310px;
  411. }
  412. input {
  413. display: block;
  414. width: 290px;
  415. line-height: 40px;
  416. margin: 10px 0;
  417. padding: 0 10px;
  418. outline: none;
  419. border: 1px solid #c8cccf;
  420. border-radius: 4px;
  421. color: #6a6f77;
  422. }
  423. #msg {
  424. width: 100%;
  425. line-height: 40px;
  426. font-size: 14px;
  427. text-align: center;
  428. }
  429. a:link, a:visited, a:hover, a:active {
  430. margin-left: 100px;
  431. color: #0366D6;
  432. }
  433. .index_from >>> .ivu-input-large {
  434. font-size: 14px !important;
  435. }
  436. .from-wh {
  437. width: 400px;
  438. }
  439. .pull-right {
  440. float: right!important;
  441. }
  442. .footer{
  443. position: fixed;
  444. bottom: 0;
  445. width: 100%;
  446. left: 0;
  447. margin: 0;
  448. background: rgba(255,255,255,.8);
  449. border-top: 1px solid #e7eaec;
  450. overflow: hidden;
  451. padding: 10px 20px;
  452. height: 36px;
  453. z-index: 999;
  454. }
  455. .pull-right {
  456. float: right!important;
  457. color: #666;
  458. }
  459. .pull-right a {
  460. margin-left: 0;
  461. color: #666;
  462. }
  463. .footer{
  464. position: fixed;
  465. bottom: 0;
  466. width: 100%;
  467. left: 0;
  468. margin: 0;
  469. background: rgba(255,255,255,.8);
  470. border-top: 1px solid #e7eaec;
  471. overflow: hidden;
  472. padding: 10px 20px;
  473. height: 36px;
  474. }
  475. </style>