register.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. <!-- 占位 -->
  24. </view>
  25. <u-button
  26. type="success"
  27. text="注册账号"
  28. customStyle="margin-top: 50px"
  29. @click="handleSubmit"
  30. ></u-button>
  31. <u-gap height="20"></u-gap>
  32. <u-button type="info" text="返回" @click="navigateBack()"></u-button>
  33. </u--form>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. inputType: 'password',
  42. formData: {
  43. username: '',
  44. password: '',
  45. },
  46. rules: {
  47. 'username': {
  48. type: 'string',
  49. max: 20,
  50. required: true,
  51. message: '请输入您的账号',
  52. trigger: ['blur', 'change']
  53. },
  54. 'password': {
  55. type: 'string',
  56. max: 20,
  57. required: true,
  58. message: '请输入您的密码',
  59. trigger: ['blur', 'change']
  60. }
  61. }
  62. }
  63. },
  64. onLoad() {
  65. },
  66. methods: {
  67. handleUsernameChange(e){
  68. let str = uni.$u.trim(e, 'all');
  69. this.$nextTick(() => {
  70. this.formData.username = str
  71. })
  72. },
  73. handlePasswordChange(e){
  74. let str = uni.$u.trim(e, 'all');
  75. this.$nextTick(() => {
  76. this.formData.password = str
  77. })
  78. },
  79. handleSubmit() {
  80. this.$refs.form.validate().then(res => {
  81. uni.$u.toast('点击了注册账号')
  82. }).catch(err => {
  83. })
  84. },
  85. navigateBack() {
  86. uni.navigateBack()
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .unp-header {
  93. height: 400rpx;
  94. display: flex;
  95. align-items: center;
  96. justify-content: center;
  97. .unp-logo {
  98. display: flex;
  99. flex-direction: column;
  100. align-items: center;
  101. justify-content: center;
  102. }
  103. }
  104. .unp-box {
  105. display: flex;
  106. flex-direction: column;
  107. align-items: center;
  108. justify-content: center;
  109. .unp-form{
  110. width: 560rpx;
  111. }
  112. }
  113. .lk-group {
  114. height: 40rpx;
  115. margin-top: 40rpx;
  116. display: flex;
  117. align-items: center;
  118. justify-content: space-between;
  119. font-size: 12rpx;
  120. color: #3c9cff;
  121. text-decoration: #3c9cff;
  122. }
  123. </style>