login.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view class="container">
  3. <!--顶部返回按钮-->
  4. <!-- <text class="back-btn iconfont iconzuojiantou-up" @tap="navBack"></text> -->
  5. <view class="login-title">
  6. <image
  7. class="logo"
  8. mode="widthFix"
  9. src="@/static/img/logo-xd.png"></image>
  10. <view class="title">商家端管理后台登录</view>
  11. </view>
  12. <!-- 设置白色背景防止软键盘把下部绝对定位元素顶上来盖住输入框等 -->
  13. <view class="wrapper">
  14. <view class="input-content">
  15. <view class="input-item">
  16. <input
  17. type="text"
  18. name="username"
  19. v-model="loginParams.username"
  20. placeholder="请输入账户名"
  21. />
  22. </view>
  23. <view class="input-item" v-if="loginByPass">
  24. <input
  25. name="password"
  26. type="password"
  27. v-model="loginParams.password"
  28. placeholder="请输入密码"
  29. />
  30. </view>
  31. <view class="input-item relative" v-if="loginByPass">
  32. <input class="codenum"
  33. name="code"
  34. type="text"
  35. v-model="loginParams.code"
  36. placeholder="请输入验证码"
  37. />
  38. <image
  39. @tap="getCaptchaImage"
  40. class="codeImage"
  41. mode="widthFix"
  42. :src="codeImage"
  43. ></image>
  44. </view>
  45. <button
  46. class="confirm-btn"
  47. :disabled="btnLoading"
  48. :loading="btnLoading"
  49. @tap="toLogin"
  50. >
  51. 登录
  52. </button>
  53. </view>
  54. <view class="forget-section" @tap="navTo()">
  55. 忘记密码?
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import { authLogin, loginByPass, loginBySmsCode, smsCode } from '@/api/login';
  62. import moment from '@/common/moment';
  63. export default {
  64. data() {
  65. return {
  66. loginParams: {
  67. username: 'xiudo',
  68. code: '',
  69. password: '123456',
  70. uuid: null,
  71. },
  72. codeImage: null,
  73. btnLoading: false,
  74. reqBody: {},
  75. codeSeconds: 0, // 验证码发送时间间隔
  76. loginByPass: true,
  77. smsCodeBtnDisabled: true,
  78. userInfo: null
  79. };
  80. },
  81. onShow() {
  82. if (this.$mStore.getters.hasLogin) {
  83. this.$mRouter.reLaunch({ route: '/pages/index/index' });
  84. }
  85. },
  86. // 页面生命周期 监听页面加载是否加载完成
  87. onLoad() {
  88. this.getCaptchaImage();
  89. // #ifdef MP-WEIXIN
  90. uni.hideHomeButton() // 会话过期更改页面跳转到登录页的跳转方式,并隐藏小房子
  91. // #endif
  92. },
  93. methods: {
  94. // 统一跳转路由
  95. navTo() {
  96. this.$mRouter.redirectTo({ route: '/pages/public/resetpassword' });
  97. },
  98. // 获取验证码
  99. async getCaptchaImage() {
  100. await this.$http
  101. .get('/captchaImage', {})
  102. .then(async (r) => {
  103. this.codeImage = 'data:image/gif;base64,' + r.data.img;
  104. this.loginParams.uuid = r.data.uuid;
  105. })
  106. .catch(() => {
  107. this.loading = false;
  108. });
  109. },
  110. // 提交表单
  111. async toLogin() {
  112. let cheRes, loginApi;
  113. if (this.loginByPass) {
  114. loginApi = loginByPass;
  115. cheRes = this.$mGraceChecker.check(
  116. this.loginParams,
  117. this.$mFormRule.loginByPassRule
  118. );
  119. }
  120. //表单验证规则是否通过,否,终止登陆提示错误信息
  121. if (!cheRes) {
  122. this.$mHelper.toast(this.$mGraceChecker.error);
  123. return;
  124. }
  125. this.handleLogin(this.loginParams, loginApi);
  126. },
  127. // 登录
  128. async handleLogin(params, loginApi) {
  129. this.btnLoading = true;
  130. await this.$http
  131. .post(loginApi, params)
  132. .then( async r => {
  133. console.log(r);
  134. let rolelist = r.data.pages
  135. this.$mStore.commit('login', r.data);
  136. // 商家信息
  137. await this.$http.get('/getUserInfo').then(async (res) => {
  138. if (res.data) {
  139. console.log(res);
  140. this.$mStore.commit('setScenic',res.data)
  141. }
  142. });
  143. this.$mHelper.toast('恭喜您,登录成功!');
  144. this.$mRouter.reLaunch({ route: `/pages/${rolelist[0].code}/${rolelist[0].code}`});
  145. this.btnLoading = false;
  146. })
  147. .catch(() => {
  148. this.btnLoading = false;
  149. });
  150. }
  151. },
  152. };
  153. </script>
  154. <style lang="scss" scoped>
  155. .container {
  156. padding-top: 65px;
  157. position: relative;
  158. width: 100vw;
  159. height: 100vh;
  160. overflow: hidden;
  161. background: #fff;
  162. }
  163. .wrapper {
  164. position: relative;
  165. z-index: 90;
  166. background: #fff;
  167. padding-bottom: 40upx;
  168. }
  169. .back-btn {
  170. position: absolute;
  171. left: 40upx;
  172. z-index: 9999;
  173. padding-top: var(--status-bar-height);
  174. top: 40upx;
  175. font-size: 40upx;
  176. color: $font-color-dark;
  177. }
  178. .login-title {
  179. padding-left: 32upx;
  180. margin-bottom: 40upx;
  181. .logo {
  182. width: 156upx;
  183. }
  184. .title {
  185. font-size: 48upx;
  186. color: #2f2f2f;
  187. }
  188. }
  189. .left-top-sign {
  190. font-size: 120upx;
  191. color: $page-color-base;
  192. position: relative;
  193. left: -16upx;
  194. }
  195. .right-top-sign {
  196. position: absolute;
  197. top: 80upx;
  198. right: -30upx;
  199. z-index: 95;
  200. &:before,
  201. &:after {
  202. display: block;
  203. content: '';
  204. width: 400upx;
  205. height: 80upx;
  206. background: #b4f3e2;
  207. }
  208. &:before {
  209. transform: rotate(50deg);
  210. border-radius: 0 50px 0 0;
  211. }
  212. &:after {
  213. position: absolute;
  214. right: -198upx;
  215. top: 0;
  216. transform: rotate(-50deg);
  217. border-radius: 50px 0 0 0;
  218. }
  219. }
  220. .left-bottom-sign {
  221. position: absolute;
  222. left: -270upx;
  223. bottom: -320upx;
  224. border: 100upx solid #d0d1fd;
  225. border-radius: 50%;
  226. padding: 180upx;
  227. }
  228. .welcome {
  229. position: relative;
  230. left: 50upx;
  231. top: -90upx;
  232. font-size: 46upx;
  233. color: #555;
  234. text-shadow: 1px 0px 1px rgba(0, 0, 0, 0.3);
  235. }
  236. .input-content {
  237. padding: 0 32upx;
  238. }
  239. .input-item {
  240. display: flex;
  241. flex-direction: column;
  242. align-items: flex-start;
  243. justify-content: center;
  244. padding: 0 30upx;
  245. background: $page-color-light;
  246. height: 80upx;
  247. border-radius: 4px;
  248. margin-bottom: 30upx;
  249. background-color: #fff;
  250. border-bottom: 1px solid #e7e7e7;
  251. .tit {
  252. height: 50upx;
  253. line-height: 56upx;
  254. font-size: $font-sm + 2upx;
  255. color: $font-color-base;
  256. }
  257. input {
  258. height: 60upx;
  259. font-size: $font-base + 2upx;
  260. color: $font-color-dark;
  261. background-color: #fff;
  262. width: 100%;
  263. }
  264. .codenum {
  265. width: 65%;
  266. }
  267. }
  268. .input-item-sms-code {
  269. position: relative;
  270. width: 100%;
  271. .sms-code-btn {
  272. position: absolute;
  273. color: #111;
  274. right: 20upx;
  275. bottom: 20upx;
  276. font-size: 28upx;
  277. }
  278. .sms-code-resend {
  279. color: #999;
  280. }
  281. .sms-code-btn:after {
  282. border: none;
  283. background-color: transparent;
  284. }
  285. }
  286. .forget-section {
  287. font-size: $font-sm + 2upx;
  288. color: $font-color-spec;
  289. text-align: center;
  290. margin-top: 40upx;
  291. }
  292. .register-section {
  293. margin: 30upx 0 50upx 0;
  294. width: 100%;
  295. font-size: $font-sm + 2upx;
  296. color: $font-color-base;
  297. text-align: center;
  298. text {
  299. color: $font-color-spec;
  300. margin-left: 10upx;
  301. }
  302. text:first-child {
  303. margin-right: 10upx;
  304. }
  305. }
  306. .btn-group {
  307. display: flex;
  308. margin-bottom: 20upx;
  309. }
  310. .codeImage {
  311. width: 220upx;
  312. position: absolute;
  313. top: 0;
  314. right: 0;
  315. }
  316. .confirm-btn {
  317. background-color: rgb(255, 205, 0);
  318. color: rgb(35, 40, 40);
  319. font-weight: bold;
  320. border-radius: 40upx;
  321. }
  322. </style>