login.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <view class="login-content">
  3. <view class="login-header">
  4. <view class="text">云岩区发改委物资管理系统</view>
  5. <view class="text">(库管人员)</view>
  6. <svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  7. viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
  8. <defs>
  9. <path id="gentle-wave"
  10. d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
  11. </defs>
  12. <g class="parallax">
  13. <use xlink:href="#gentle-wave" x="48" y="0" fill="rgba(255,255,255,0.7" />
  14. <use xlink:href="#gentle-wave" x="48" y="3" fill="rgba(255,255,255,0.5)" />
  15. <use xlink:href="#gentle-wave" x="48" y="5" fill="rgba(255,255,255,0.3)" />
  16. <use xlink:href="#gentle-wave" x="48" y="7" fill="#fff" />
  17. </g>
  18. </svg>
  19. </view>
  20. <!-- 登录表单 -->
  21. <view class="from-box">
  22. <u-form labelPosition="left" :model="form" :rules="rules" ref="uForm">
  23. <u-form-item prop="username">
  24. <u-input v-model="form.username" placeholder="用户名" :border="false" clearable></u-input>
  25. </u-form-item>
  26. <u-form-item prop="password">
  27. <u-input v-model="form.password" type="password" placeholder="登录密码" :border="false"
  28. :password-icon="true" clearable></u-input>
  29. </u-form-item>
  30. </u-form>
  31. <view class="btn-box">
  32. <u-button class="main-color-btn" @click="submit" type="error">登录</u-button>
  33. </view>
  34. </view>
  35. <u-modal v-model="tipShow" title="登录提示" @confirm="confirm" :content="content"></u-modal>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. content: '登录错误',
  43. tipShow: false,
  44. form: {
  45. username: '',
  46. password: '',
  47. },
  48. password: true,
  49. rules: {
  50. username: {
  51. type: 'string',
  52. required: true,
  53. message: '请填写用户名',
  54. trigger: ['blur', 'change']
  55. },
  56. password: {
  57. type: 'string',
  58. required: true,
  59. message: '请填写登录密码',
  60. trigger: ['blur', 'change']
  61. },
  62. }
  63. };
  64. },
  65. created() {
  66. // this.getCaptchaImage();
  67. },
  68. onReady() {
  69. // 设置表单校验规则
  70. this.$refs.uForm.setRules(this.rules);
  71. if(process.env.NODE_ENV=='development'){
  72. this.form.username = 'zdd3';
  73. this.form.password = '123456'
  74. }
  75. },
  76. methods: {
  77. // 获取图片验证码
  78. async getCaptchaImage() {
  79. const {
  80. code,
  81. data,
  82. msg
  83. } = await this.$u.api.captchaImage();
  84. if (code === 200) {
  85. this.image = data.captchaImage;
  86. this.form.uuid = data.uuid;
  87. } else {
  88. console.log('1111');
  89. }
  90. },
  91. // 登录表单提交验证
  92. submit() {
  93. this.$refs.uForm
  94. .validate()
  95. .then((res) => {
  96. this.loginApi();
  97. })
  98. .catch((errors) => {
  99. uni.$u.toast('校验失败');
  100. });
  101. },
  102. confirm() {
  103. this.tipShow = false;
  104. },
  105. // 登录接口
  106. async loginApi() {
  107. let postMap = {
  108. username: this.form.username,
  109. password:this.form.password,
  110. };
  111. const {
  112. code,
  113. data,
  114. msg
  115. } = await this.$u.api.login(postMap);
  116. if (code === 200) {
  117. // 清空用户数据缓存
  118. this.$u.vuex('vuex_user', {});
  119. this.$u.vuex('user_info', {});
  120. this.$u.vuex('vuex_user', data);
  121. this.goToEven();
  122. // 获取用户数据
  123. // this.$store.dispatch('getUserInfo', (data) => {
  124. // this.$u.vuex('user_info', data);
  125. // this.goToEven();
  126. // });
  127. } else {
  128. this.content = msg;
  129. this.tipShow = true;
  130. }
  131. },
  132. // 登录成功进入首页
  133. goToEven() {
  134. this.$u.route({
  135. url: 'pages/index/index',
  136. })
  137. // 处理刷新时候 leader为403问题
  138. // if (window && window.location) {
  139. // window.location.href = window.location.protocol + '//' + window.location.host +
  140. // '/leader/pages/index/index'
  141. // } else {
  142. // uni.navigateTo({
  143. // url: '/pages/index/index'
  144. // });
  145. // }
  146. }
  147. }
  148. };
  149. </script>
  150. <style lang="scss">
  151. .from-box {
  152. width: 80vw;
  153. margin: 0 auto;
  154. ::v-deep .uni-input-input{
  155. font-size: 40rpx;
  156. }
  157. }
  158. .login-header {
  159. position: relative;
  160. box-sizing: border-box;
  161. height: 30vh;
  162. padding-top: 5vh;
  163. background-color: var(--main-color);
  164. .text {
  165. text-align: center;
  166. font-size: 36rpx;
  167. color: #fff;
  168. line-height: 1.5;
  169. }
  170. }
  171. .btn-box {
  172. margin-top: 24px;
  173. }
  174. .waves {
  175. position: absolute;
  176. left: 0;
  177. bottom: 0;
  178. width: 100%;
  179. height: 15vh;
  180. height: 40px;
  181. margin-bottom: -7px;
  182. /*Fix for safari gap*/
  183. min-height: 100px;
  184. max-height: 150px;
  185. }
  186. .parallax>use {
  187. animation: move-forever 25s cubic-bezier(.55, .5, .45, .5) infinite;
  188. }
  189. .parallax>use:nth-child(1) {
  190. animation-delay: -2s;
  191. animation-duration: 7s;
  192. }
  193. .parallax>use:nth-child(2) {
  194. animation-delay: -3s;
  195. animation-duration: 10s;
  196. }
  197. .parallax>use:nth-child(3) {
  198. animation-delay: -4s;
  199. animation-duration: 13s;
  200. }
  201. .parallax>use:nth-child(4) {
  202. animation-delay: -5s;
  203. animation-duration: 20s;
  204. }
  205. @keyframes move-forever {
  206. 0% {
  207. transform: translate3d(-90px, 0, 0);
  208. }
  209. 100% {
  210. transform: translate3d(85px, 0, 0);
  211. }
  212. }
  213. // waves end
  214. </style>