login.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="container">
  3. <view class="unp-header">
  4. <view class="unp-logo">
  5. <u-avatar size="80" icon="github-circle-fill" fontSize="80"></u-avatar>
  6. </view>
  7. </view>
  8. <view class="unp-box">
  9. <u--form class="unp-form" labelPosition="left" :model="formData" :rules="rules" ref="form">
  10. <u-form-item label="账号" prop="username" borderBottom ref="item-username">
  11. <u-input type="text" maxlength="20" v-model="formData.username" clearable placeholder="账号由数字和字母组成" border="none" @change="handleUsernameChange"></u-input>
  12. </u-form-item>
  13. <u-gap height="20"></u-gap>
  14. <u-form-item label="密码" prop="password" borderBottom ref="item-password">
  15. <u-input :type="inputType" maxlength="20" v-model="formData.password" placeholder="密码由数字、字母和符号组成" border="none" @change="handlePasswordChange">
  16. <template slot="suffix">
  17. <u-icon v-if="inputType === 'password'" size="20" color="#666666" name="eye-fill" @click="inputType = 'text'"></u-icon>
  18. <u-icon v-if="inputType === 'text'" size="20" color="#666666" name="eye-off" @click="inputType = 'password'"></u-icon>
  19. </template>
  20. </u-input>
  21. </u-form-item>
  22. <view class="lk-group">
  23. <navigator url="/pages/register/register" hover-class="none">
  24. <text class="register">注册账号</text>
  25. </navigator>
  26. <navigator url="/pages/forgot/forgot" hover-class="none">
  27. <text class="forgot">忘记密码</text>
  28. </navigator>
  29. </view>
  30. <u-button
  31. type="primary"
  32. text="登录"
  33. customStyle="margin-top: 50px"
  34. @click="handleSubmit"
  35. ></u-button>
  36. <u-gap height="20"></u-gap>
  37. <u-button type="info" text="返回" @click="navigateBack()"></u-button>
  38. </u--form>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. inputType: 'password',
  47. formData: {
  48. username: '',
  49. password: '',
  50. },
  51. rules: {
  52. 'username': {
  53. type: 'string',
  54. max: 20,
  55. required: true,
  56. message: '请输入您的账号',
  57. trigger: ['blur', 'change']
  58. },
  59. 'password': {
  60. type: 'string',
  61. max: 20,
  62. required: true,
  63. message: '请输入您的密码',
  64. trigger: ['blur', 'change']
  65. }
  66. }
  67. }
  68. },
  69. onLoad() {
  70. },
  71. methods: {
  72. handleUsernameChange(e){
  73. let str = uni.$u.trim(e, 'all');
  74. this.$nextTick(() => {
  75. this.formData.username = str
  76. })
  77. },
  78. handlePasswordChange(e){
  79. let str = uni.$u.trim(e, 'all');
  80. this.$nextTick(() => {
  81. this.formData.password = str
  82. })
  83. },
  84. handleSubmit() {
  85. this.$refs.form.validate().then(res => {
  86. uni.$u.toast('点击了登录')
  87. }).catch(err => {
  88. })
  89. },
  90. navigateBack() {
  91. uni.navigateBack()
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. .unp-header {
  98. height: 400rpx;
  99. display: flex;
  100. align-items: center;
  101. justify-content: center;
  102. .unp-logo {
  103. display: flex;
  104. flex-direction: column;
  105. align-items: center;
  106. justify-content: center;
  107. }
  108. }
  109. .unp-box {
  110. display: flex;
  111. flex-direction: column;
  112. align-items: center;
  113. justify-content: center;
  114. .unp-form{
  115. width: 560rpx;
  116. }
  117. }
  118. .lk-group {
  119. height: 40rpx;
  120. margin-top: 40rpx;
  121. display: flex;
  122. align-items: center;
  123. justify-content: space-between;
  124. font-size: 12rpx;
  125. color: #3c9cff;
  126. text-decoration: #3c9cff;
  127. }
  128. </style>