login.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div class="login dflex_c dflex_d_c">
  3. <el-image style="width: 81px;height: 54px;border-radius: 50%;" :src="require('static/img/logo.jpg')" fit="contain"></el-image>
  4. <div class="title">靖安人家乡村民宿特产商城</div>
  5. <el-form :model="form" :rules="rules" ref="ruleForm" class="login_form">
  6. <el-form-item prop="username" ref="username"><el-input v-model="form.username" placeholder="账号" @keyup.enter.native="enter"></el-input></el-form-item>
  7. <el-form-item prop="password" ref="password">
  8. <el-input v-model="form.password" placeholder="密码" show-password @keyup.enter.native="submitForm('ruleForm')"></el-input>
  9. </el-form-item>
  10. <div class="login_btn dflex_c margin_t_50 crpr" @click="submitForm('ruleForm')">登 录</div>
  11. </el-form>
  12. </div>
  13. </template>
  14. <script>
  15. import config from '@/admin.config.js';
  16. import bus from '@/common/bus';
  17. import {
  18. getLogin
  19. } from '@/util/loginJie.js'
  20. export default {
  21. data() {
  22. return {
  23. form: {
  24. username: '',
  25. password: ''
  26. },
  27. loading: false,
  28. rules: {
  29. username: [
  30. {
  31. required: true,
  32. message: '账号不可以为空',
  33. trigger: ['blur', 'keyup']
  34. }
  35. ],
  36. password: [
  37. {
  38. required: true,
  39. message: '密码不可以为空',
  40. trigger: 'change'
  41. }
  42. ]
  43. },
  44. business_data: {}
  45. };
  46. },
  47. methods: {
  48. enter() {
  49. if (this.form.username) {
  50. this.$refs.password.$el.querySelector('input').focus();
  51. }
  52. },
  53. submitForm(formName) {
  54. let data = {
  55. username: this.form.username,
  56. password: this.form.password
  57. }
  58. getLogin(data).then((res) => {
  59. if (res.success) {
  60. uni.setStorageSync("token",res.data.token)
  61. uni.setStorageSync("nickName",res.data.nickName)
  62. uni.setStorageSync("avatar",res.data.avatar)
  63. // uni.setStorage({
  64. // key: 'useadmin_user',
  65. // data: res.datas.userInfo
  66. // })
  67. // uni.setStorage({
  68. // key: 'uni_id_token',
  69. // data: res.datas.token
  70. // });
  71. // uni.setStorage({
  72. // key: 'uni_id_token_expired',
  73. // data: res.datas.tokenExpired
  74. // });
  75. // uni.redirectTo({
  76. // url: config.index.url
  77. // });
  78. this.$message.success('登录成功');
  79. uni.navigateTo({
  80. url:'/pages/shop/home/page'///pages/home
  81. })
  82. // bus.$emit('loginIn');
  83. return;
  84. } else {
  85. this.$message.warning('没有符合条件的数据!')
  86. }
  87. }).catch((err) => {
  88. this.$message.error(err.message)
  89. });
  90. // this.$refs[formName].validate((valid, obj) => {
  91. // this.$api.set_unvalidated_form_focus(this, obj);
  92. // if (valid) {
  93. // if (this.loading) {
  94. // return;
  95. // }
  96. // let data = this.form;
  97. // this.loading = true;
  98. // this.$func.useadmin
  99. // .call('user/login', data)
  100. // .then(res => {
  101. // if (res.code == 200) {
  102. // uni.setStorage({
  103. // key: 'useadmin_last_username',
  104. // data: data.username
  105. // });
  106. // uni.setStorage({
  107. // key: 'useadmin_user',
  108. // data: res.datas.userInfo
  109. // })
  110. // uni.setStorage({
  111. // key: 'uni_id_token',
  112. // data: res.datas.token
  113. // });
  114. // uni.setStorage({
  115. // key: 'uni_id_token_expired',
  116. // data: res.datas.tokenExpired
  117. // });
  118. // uni.redirectTo({
  119. // url: config.index.url
  120. // });
  121. // this.$message.success('登录成功');
  122. // bus.$emit('loginIn');
  123. // return;
  124. // }
  125. // this.$message.error(res.msg);
  126. // })
  127. // .finally(err => {
  128. // this.loading = false;
  129. // });
  130. // }
  131. // });
  132. }
  133. },
  134. mounted() {
  135. this.$refs.username.$el.querySelector('input').focus();
  136. uni.getStorage({
  137. key: 'useadmin_last_username',
  138. success: res => {
  139. this.form.username = res.data;
  140. this.$refs.password.$el.querySelector('input').focus();
  141. }
  142. });
  143. document.getElementsByTagName('html')[0].style.cssText =
  144. '--status-bar-height:0px; --top-window-height:0px; --window-left:0px; --window-right:0px; --window-margin:0px; --window-top:calc(var(--top-window-height) + 0px); --window-bottom:0px;';
  145. }
  146. };
  147. </script>
  148. <style>
  149. page {
  150. width: 100%;
  151. height: 100%;
  152. display: flex;
  153. align-items: center;
  154. justify-content: center;
  155. background: url('/static/img/login_bg.png');
  156. background-size: cover;
  157. padding: 0;
  158. margin-top: 0;
  159. }
  160. .login {
  161. width: 880px;
  162. height: 560px;
  163. background: #fff;
  164. box-shadow: 0 0 30px rgba(0, 0, 0, 0.16);
  165. border-radius: 20px;
  166. }
  167. .title {
  168. font-size: 22px;
  169. font-weight: 800;
  170. margin-bottom: 100px;
  171. }
  172. >>> .login_form .el-input__inner {
  173. border: none;
  174. border-bottom: 1px solid #d9d9d9;
  175. border-radius: 0;
  176. padding-left: 6px;
  177. font-size: 14px;
  178. width: 260px;
  179. color: #3492e9;
  180. }
  181. .login_btn {
  182. width: 260px;
  183. height: 40px;
  184. background-color: #3492e9;
  185. border-radius: 4px;
  186. font-size: 18px;
  187. font-weight: 800;
  188. color: #fff;
  189. }
  190. </style>