index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. {{basicInfo.name}}
  5. </view>
  6. <view class="two">
  7. <uni-forms ref="form" :model="form" :rules="rules" label-width="auto">
  8. <uni-forms-item label="登录账号" name="account">
  9. <uni-easyinput type="text" v-model="form.account" placeholder="请输入登录账号" />
  10. </uni-forms-item>
  11. <uni-forms-item label="登录密码" name="password">
  12. <uni-easyinput type="text" v-model="form.password" placeholder="请输入登录密码" />
  13. </uni-forms-item>
  14. </uni-forms>
  15. <view class="btn">
  16. <button size="mini" @tap="toSubmit('form')">提交登录</button>
  17. </view>
  18. </view>
  19. <view class="thr">
  20. <button size="mini" @tap="toRegister()">账号注册</button>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. // 基本信息
  29. basicInfo: {},
  30. form: {},
  31. rules: {
  32. account: {
  33. rules: [ //
  34. {
  35. required: true,
  36. errorMessage: '请输入登录账号',
  37. }
  38. ]
  39. },
  40. passowrd: {
  41. rules: [ //
  42. {
  43. required: true,
  44. errorMessage: '请输入登录密码',
  45. }
  46. ]
  47. }
  48. },
  49. // 协议
  50. agree: true
  51. };
  52. },
  53. onLoad() {
  54. },
  55. onShow() {
  56. const that = this;
  57. that.searchBasic();
  58. },
  59. methods: {
  60. searchBasic() {
  61. const that = this;
  62. uni.getStorage({
  63. key: 'basicInfo',
  64. success: (res) => {
  65. let data = res.data
  66. that.$set(that, `basicInfo`, data);
  67. }
  68. })
  69. },
  70. // 提交登录
  71. async toSubmit(ref) {
  72. const that = this;
  73. let agree = that.agree;
  74. let form = that.form;
  75. if (agree) {
  76. let res = await that.$api('user/login', 'POST', form)
  77. if (res.errcode == '0') {
  78. console.log(res.data);
  79. } else {
  80. uni.showToast({
  81. title: res.errmsg,
  82. icon: 'none'
  83. })
  84. }
  85. } else {
  86. uni.showToast({
  87. title: '请阅读并同意用户协议和隐私政策',
  88. icon: 'none'
  89. })
  90. }
  91. },
  92. toRegister() {
  93. uni.navigateTo({
  94. url: '/pagesAccount/register/index'
  95. })
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss">
  101. .content {
  102. background-color: var(--rgb000);
  103. padding: 0 2vw;
  104. .one {
  105. text-align: center;
  106. font-size: 30px;
  107. font-family: monospace;
  108. color: var(--rgbfff);
  109. padding: 10vw 0 10vw 0;
  110. }
  111. .two {
  112. margin: 0 0 4vw 0;
  113. .uni-easyinput {
  114. margin: 0 0 15px 0;
  115. }
  116. .btn {
  117. padding: 2vw 0 0 0;
  118. text-align: center;
  119. button {
  120. width: 80%;
  121. background-color: var(--rgbfa4);
  122. color: var(--rgbfff);
  123. padding: 1vw 0;
  124. }
  125. }
  126. }
  127. .thr {
  128. text-align: center;
  129. button {
  130. background-color: var(--rgbfa4);
  131. color: var(--rgbfff);
  132. }
  133. }
  134. }
  135. </style>