多租户商城-客户PC端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

421 lines
10 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="showTheLogin">
  3. <div class="loginCent">
  4. <nav>
  5. <div class="hiddenLoginBtn">
  6. <a class="el-icon-close" @click="hiddenLoginBtn" />
  7. </div>
  8. </nav>
  9. <div class="loginForm">
  10. <!-- <div class="loginTit" v-text="isRegistered == '1' ? '注册' : '登录'"></div> -->
  11. <div class="loginTitle">
  12. <div class="title" v-text="isRegistered !== '1' ? vm.$t('page.login') : '用户注册'"></div>
  13. <div class="content">
  14. <span v-text="isRegistered === '1' ? '已有账户?' : '第一次使用Thee商城?'"></span>
  15. <u @click="registered" v-text="isRegistered === '1' ? '立即登录' : '用户注册'"></u>
  16. </div>
  17. </div>
  18. <div class="loginFormBox">
  19. <div class="inputBox">
  20. <el-input v-model="userName" placeholder="$t('common.entermobilephone')">
  21. <template slot="prepend"><span class="icon iconfont">&#xe62f;</span></template>
  22. </el-input>
  23. </div>
  24. <div>
  25. <div class="inputBox">
  26. <el-input v-model="verificationCode" :placeholder="vm.$t('common.enterverificationcode')" @keyup.enter.native="login">
  27. <template slot="prepend">
  28. <span class="icon iconfont">&#xe62e;</span>
  29. </template>
  30. </el-input>
  31. <div>
  32. </div>
  33. <span v-show="codeShow" class="codeBtn" @click="getCode">{{vm.$t('common.verificationcodetip')}}</span>
  34. <span v-show="!codeShow" class="codeBtn codeCount">{{ vm.$t('common.verificationcodetip3') }}({{ codeCountNum }}s)</span>
  35. </div>
  36. </div>
  37. <div class="noLogin" :class="{ registered: isRegistered === '1' }">
  38. <el-checkbox v-show="isRegistered === '2'" v-model="isNoLogin">七天免登录</el-checkbox>
  39. <span></span>
  40. </div>
  41. <el-button class="loginBtn" @click="login"
  42. :loading="loadingLogin">{{isRegistered === '1' ? vm.$t('page.register') : vm.$t('page.login')}}</el-button>
  43. </div>
  44. <div class="loginProtocol" v-if="isRegistered === '1'">
  45. <el-checkbox v-model="haveRead"></el-checkbox>
  46. <span>阅读并同意</span>
  47. <span @click="readAgreement">Thee 服务协议</span>
  48. </div>
  49. </div>
  50. </div>
  51. <el-dialog title="服务协议" :visible.sync="dialogAgreement" width="50%">
  52. 这是服务协议
  53. </el-dialog>
  54. </div>
  55. </template>
  56. <script>
  57. import Cookie from 'js-cookie'
  58. import store from '@/store/index.js'
  59. import {
  60. getTheCode,
  61. login
  62. } from '@/api/login.js'
  63. import {
  64. getUserInfo
  65. } from '@/api/user/user.js'
  66. export default {
  67. name: 'login',
  68. data() {
  69. const vm =window.vm;
  70. return {
  71. vm:vm,
  72. userName: '',
  73. verificationCode: '',
  74. isNoLogin: false,
  75. haveRead: false,
  76. codeShow: true,
  77. codeCountNum: '',
  78. dialogAgreement: false,
  79. isRegistered: '2',
  80. loadingLogin: false
  81. }
  82. },
  83. methods: {
  84. async getUserInfoData() {
  85. const response = await getUserInfo()
  86. const res = response.data
  87. if (res.code === '200') {
  88. store.commit('SET_USERINFO', res.data)
  89. this.userInfoData = res.data
  90. }
  91. },
  92. async getCode() {
  93. const TIME_COUNT = 120
  94. let reg = /^1[13456789]\d{9}$/
  95. if (!reg.test(this.userName)) {
  96. this.$message({
  97. message: '手机号格式错误',
  98. type: 'error',
  99. customClass: 'messageZindex',
  100. })
  101. return
  102. }
  103. const response = await getTheCode({ phone: this.userName })
  104. const res = response.data
  105. if (res.code === '200') {
  106. if (!this.timer) {
  107. this.codeCountNum = TIME_COUNT
  108. this.codeShow = false
  109. this.timer = setInterval(() => {
  110. if (this.codeCountNum > 0 && this.codeCountNum <= TIME_COUNT) {
  111. this.codeCountNum--
  112. } else {
  113. this.codeShow = true
  114. clearInterval(this.timer)
  115. this.timer = null
  116. }
  117. }, 1000)
  118. }
  119. this.$message({
  120. message: '验证码获取成功',
  121. type: 'success',
  122. customClass: 'messageZindex'
  123. })
  124. } else {
  125. this.$message({
  126. message: res.message,
  127. type: 'warning',
  128. customClass: 'messageZindex'
  129. })
  130. }
  131. },
  132. // 阅读协议
  133. readAgreement() {
  134. this.dialogAgreement = true
  135. },
  136. login() {
  137. let that = this
  138. let reg = /^1[13456789]\d{9}$/
  139. if (!reg.test(this.userName)) {
  140. this.$message({
  141. message: '手机号码格式错误',
  142. type: 'error',
  143. customClass: 'messageZindex'
  144. })
  145. return
  146. }
  147. if (this.verificationCode === '') {
  148. this.$message({
  149. message: that.$t('common.enterverificationcode'),
  150. type: 'warning',
  151. customClass: 'messageZindex'
  152. })
  153. return
  154. }
  155. if (this.isRegistered === '2') {
  156. this.getLogin()
  157. } else if (this.haveRead) {
  158. this.getLogin()
  159. } else {
  160. this.$message({
  161. message: '请阅读并同意服务协议',
  162. type: 'warning',
  163. customClass: 'messageZindex'
  164. })
  165. }
  166. },
  167. async getLogin() {
  168. this.loadingLogin = true
  169. const response = await login({
  170. phone: this.userName,
  171. verificationCode: this.verificationCode,
  172. type: this.isRegistered,
  173. terminal: 5
  174. })
  175. const res = response.data
  176. if (res.code === '200') {
  177. if (this.isNoLogin) {
  178. Cookie.set('token', res.data.token, { expires: 7 })
  179. } else {
  180. Cookie.set('token', res.data.token, { expires: 1 })
  181. }
  182. this.getUserInfoData()
  183. this.$message({
  184. message: '登录成功',
  185. type: 'success',
  186. customClass: 'messageZindex'
  187. })
  188. store.commit('SHOW_LOGIN')
  189. store.commit('IS_LOGIN', true)
  190. location.reload()
  191. } else {
  192. this.$message({
  193. message: res.message,
  194. type: 'warning',
  195. customClass: 'messageZindex'
  196. })
  197. }
  198. this.loadingLogin = false
  199. },
  200. registered() {
  201. this.codeShow = true
  202. clearInterval(this.timer)
  203. this.timer = null
  204. this.userName = ''
  205. this.verificationCode = ''
  206. if (this.isRegistered === '1') {
  207. this.isRegistered = '2'
  208. } else {
  209. this.isRegistered = '1'
  210. }
  211. },
  212. // 关闭登录
  213. hiddenLoginBtn() {
  214. store.commit('SHOW_LOGIN')
  215. }
  216. }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. .showTheLogin {
  221. // height: 100vh;
  222. // min-height: 768px;
  223. position: fixed;
  224. z-index: 9999;
  225. width: 100%;
  226. height: 100%;
  227. background-color: rgba(0, 0, 0, 0.5);
  228. .loginCent {
  229. // background: url('../../assets/images/beijing.png') no-repeat;
  230. // flex-grow: 1;
  231. // background-size: cover;
  232. width: 500px;
  233. height: 100%;
  234. min-height: 768px;
  235. padding: 20px 50px;
  236. float: right;
  237. background-color: #ffffff;
  238. animation: showRight .5s;
  239. animation-fill-mode: forwards;
  240. -webkit-animation-fill-mode: forwards;
  241. nav {
  242. margin-bottom: 85px;
  243. .hiddenLoginBtn {
  244. a {
  245. float: right;
  246. }
  247. }
  248. }
  249. .loginForm {
  250. width: 500px;
  251. height: 100%;
  252. background: #ffffff;
  253. .loginTitle {
  254. font-family: Microsoft YaHei;
  255. color: #333333;
  256. .title {
  257. font-size: 36px;
  258. }
  259. .content {
  260. margin: 10px 0;
  261. font-size: 14px;
  262. u {
  263. color: $mainColor;
  264. cursor: pointer;
  265. }
  266. }
  267. }
  268. .loginFormBox {
  269. .inputBox {
  270. position: relative;
  271. .el-input {
  272. .iconfont {
  273. font-size: 32px;
  274. padding: 0 10px;
  275. }
  276. }
  277. >>>.el-input__inner {
  278. height: 70px;
  279. border-radius: 0px;
  280. font-size: 20px;
  281. padding-left: 5px;
  282. }
  283. &:nth-child(2) {
  284. margin: 60px 0 20px 0;
  285. }
  286. .codeBtn {
  287. width: 120px;
  288. height: 50px;
  289. background: #EEEEEE;
  290. border: #999999;
  291. border-radius: 0;
  292. display: block;
  293. line-height: 54px;
  294. text-align: center;
  295. position: absolute;
  296. right: 5px;
  297. color: #333333;
  298. bottom: 10px;
  299. cursor: pointer;
  300. }
  301. .codeCount {
  302. color: #999999;
  303. }
  304. }
  305. .noLogin {
  306. color: #333333;
  307. font-size: 18px;
  308. margin: 20px 0 60px 0;
  309. height: 30px;
  310. align-items: center;
  311. display: flex;
  312. justify-content: space-between;
  313. >>>.el-checkbox__label {
  314. font-size: 16px;
  315. color: #333333;
  316. font-weight: 400;
  317. }
  318. span {
  319. cursor: pointer;
  320. font-size: 16px;
  321. text-decoration: underline;
  322. color: #666666;
  323. }
  324. }
  325. .registered {
  326. justify-content: flex-end;
  327. }
  328. .loginBtn {
  329. width: 100%;
  330. height: 70px;
  331. background: $mainColor;
  332. border-radius: 0;
  333. border: 1px solid $mainColor;
  334. text-align: center;
  335. font-size: 20px;
  336. color: $mainBtnFontColor;
  337. cursor: pointer;
  338. &:hover {
  339. border: 1px solid $mainColor;
  340. }
  341. }
  342. }
  343. .loginProtocol {
  344. padding: 0 60px;
  345. display: flex;
  346. align-items: center;
  347. height: 80px;
  348. line-height: 80px;
  349. border-top: 1px solid #EEEEEE;
  350. span {
  351. margin-left: 10px;
  352. }
  353. span:nth-child(3) {
  354. color: #426BEA;
  355. cursor: pointer;
  356. }
  357. }
  358. >>>.el-checkbox__inner {
  359. width: 20px;
  360. height: 20px;
  361. &:after {
  362. height: 10px;
  363. left: 7px;
  364. width: 4px;
  365. }
  366. }
  367. }
  368. }
  369. >>>.el-dialog__body {
  370. max-height: 500px;
  371. min-height: 300px;
  372. overflow: auto;
  373. }
  374. }
  375. .hiddenLogin {
  376. display: none;
  377. }
  378. @keyframes showRight {
  379. from {
  380. width: 560px;
  381. opacity: 0;
  382. }
  383. to {
  384. width: 600px;
  385. opacity: 1;
  386. display: block;
  387. }
  388. }</style>