自主项目,食堂系统,前端uniapp
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.

146 lines
3.2 KiB

  1. <template>
  2. <view>
  3. <view class="head"></view>
  4. <view class="content">
  5. <view>
  6. <!-- 账号 -->
  7. <view class="lf-flex lf-m-b-10">
  8. <u-icon name="account-fill"></u-icon>
  9. <text class="lf-m-l-10 lf-font-28 lf-color-333">登录账号</text>
  10. </view>
  11. <input class="input"
  12. maxlength="11"
  13. v-model="user_key"
  14. :adjust-position="false"
  15. :auto-blur="true"
  16. placeholder="请输入账号"
  17. @focus="inputFocus(170)"
  18. @blur="inputBlur" />
  19. <!-- 密码 -->
  20. <view class="lf-flex lf-m-b-10 lf-m-t-60">
  21. <u-icon name="lock-fill"></u-icon>
  22. <text class="lf-m-l-10 lf-font-28 lf-color-333">登录密码</text>
  23. </view>
  24. <input class="input"
  25. maxlength="20"
  26. v-model="user_pw"
  27. :adjust-position="false"
  28. :auto-blur="true"
  29. placeholder="请输入密码"
  30. :password="true"
  31. @focus="inputFocus(220)"
  32. @blur="inputBlur"
  33. @confirm="login" />
  34. </view>
  35. <view>
  36. <!-- 登录按钮 -->
  37. <button class="button" @click="login">登录</button>
  38. </view>
  39. </view>
  40. <view :style="is_focus ? 'height: 540rpx' : 'height: 40rpx'"></view>
  41. </view>
  42. </template>
  43. <script>
  44. let time = null;
  45. export default {
  46. data(){
  47. return {
  48. is_focus: false,
  49. user_key: '',
  50. user_pw: ''
  51. }
  52. },
  53. onLoad(options){
  54. // todo 优化:input输入后有clear按钮
  55. },
  56. onReady(){
  57. // #ifndef MP
  58. var a = document.getElementsByClassName('uni-page-head-hd')[0];
  59. a.style.display = 'none';
  60. // #endif
  61. },
  62. methods: {
  63. inputFocus(scrollTop){
  64. time = setTimeout(() => {
  65. this.is_focus = true;
  66. }, 0); // 给blur事件留出时间
  67. setTimeout(() => {
  68. uni.pageScrollTo({
  69. scrollTop: scrollTop,
  70. duration: 100
  71. })
  72. }, 200);
  73. },
  74. inputBlur(){
  75. time = setTimeout(() => {
  76. this.is_focus = false;
  77. }, 0); // 给click事件留出时间
  78. },
  79. login(){
  80. if(!this.user_key){
  81. this.$msg('账号不能为空');
  82. }else if(!this.user_pw){
  83. this.$msg('密码不能为空');
  84. }else{
  85. this.$http(this.API.API_CANTEEN_LOGIN, {
  86. username: this.user_key,
  87. password: this.user_pw
  88. }).then(res => {
  89. console.log("login", res);
  90. uni.setStorageSync('canteen_token', res.data.token);
  91. this.$url('/pages/canteen/index/index', {tyep: 'redirect'});
  92. })
  93. }
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped="scoped">
  99. .lf-m-t-60{
  100. margin-top: 60rpx;
  101. }
  102. .head{
  103. height: 604rpx;
  104. width: 750rpx;
  105. background-color: #11D189;
  106. }
  107. .content{
  108. width: 686rpx;
  109. height: 622rpx;
  110. background: #FFFFFF;
  111. box-shadow: 0rpx 2rpx 10rpx 5rpx rgba(17, 209, 137, 0.1);
  112. border-radius: 20rpx;
  113. margin: 0 auto;
  114. margin-top: -100rpx;
  115. padding: 60rpx 30rpx;
  116. box-sizing: border-box;
  117. display: flex;
  118. flex-direction: column;
  119. justify-content: space-between;
  120. .input{
  121. // padding: 20rpx 0;
  122. border-bottom: 1rpx solid #e5e5e5;
  123. font-size: 60rpx;
  124. /* #ifdef MP */
  125. height: 90rpx;
  126. line-height: 90rpx;
  127. /* #endif */
  128. }
  129. .button{
  130. background-color: #11D189;
  131. color: #FFFFFF;
  132. font-size: 32rpx;
  133. }
  134. }
  135. /deep/.input-placeholder{
  136. color: #999999;
  137. font-size: 28rpx;
  138. }
  139. /deep/.button-hover{
  140. opacity: .5;
  141. animation: all .3s;
  142. }
  143. </style>