index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 name="account">
  9. <uni-easyinput type="text" v-model="form.account" placeholder="请输入登录账号" />
  10. </uni-forms-item>
  11. <uni-forms-item name="password">
  12. <uni-easyinput type="password" v-model="form.password" placeholder="请输入登录密码" />
  13. </uni-forms-item>
  14. </uni-forms>
  15. <view class="agree">
  16. <checkbox-group @change="changeAgree">
  17. <label>
  18. <checkbox :checked="agree" />
  19. <text @tap.stop="toAgree()">我已阅读并同意“用户协议”和“隐私政策”</text>
  20. </label>
  21. </checkbox-group>
  22. </view>
  23. <view class="btn">
  24. <button size="mini" @tap="toSubmit('form')">提交登录</button>
  25. </view>
  26. </view>
  27. <view class="thr">
  28. <button size="mini" @tap="toRegister()">账号注册</button>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. data() {
  35. return {
  36. // 基本信息
  37. basicInfo: {},
  38. form: {},
  39. rules: {
  40. account: {
  41. rules: [ //
  42. {
  43. required: true,
  44. errorMessage: '请输入登录账号',
  45. }
  46. ]
  47. },
  48. password: {
  49. rules: [ //
  50. {
  51. required: true,
  52. errorMessage: '请输入登录密码',
  53. }
  54. ]
  55. }
  56. },
  57. // 用戶协议
  58. agree: true,
  59. };
  60. },
  61. onLoad() {},
  62. onShow() {
  63. const that = this;
  64. that.searchBasic();
  65. },
  66. methods: {
  67. searchBasic() {
  68. const that = this;
  69. uni.getStorage({
  70. key: 'basicInfo',
  71. success: (res) => {
  72. let data = res.data
  73. that.$set(that, `basicInfo`, data);
  74. }
  75. })
  76. },
  77. // 提交登录
  78. toSubmit(ref) {
  79. const that = this;
  80. let agree = that.agree;
  81. that.$refs[ref].validate().then(async parmas => {
  82. if (agree) {
  83. let res = await that.$api('user/login', 'POST', parmas)
  84. if (res.errcode == '0') {
  85. uni.showToast({
  86. title: '账号登录成功',
  87. icon: 'none'
  88. })
  89. uni.setStorage({
  90. key: 'token',
  91. data: res.data,
  92. success: function() {
  93. uni.navigateBack()
  94. }
  95. });
  96. } else {
  97. uni.showToast({
  98. title: res.errmsg,
  99. icon: 'none'
  100. })
  101. }
  102. } else {
  103. uni.showToast({
  104. title: '请阅读并同意用户协议和隐私政策',
  105. icon: 'none'
  106. })
  107. }
  108. }).catch(err => {
  109. console.log('err', err);
  110. })
  111. },
  112. toRegister() {
  113. uni.navigateTo({
  114. url: '/pagesAccount/register/index'
  115. })
  116. },
  117. // 同意隐私协议
  118. changeAgree() {
  119. const that = this;
  120. let agree = true;
  121. if (that.agree) agree = false;
  122. that.$set(that, `agree`, agree);
  123. },
  124. // 查看隐私协议
  125. toAgree() {
  126. const that = this;
  127. uni.navigateTo({
  128. url: `/pagesAccount/other/agree`
  129. })
  130. },
  131. }
  132. }
  133. </script>
  134. <style lang="scss">
  135. .content {
  136. background-color: var(--rgb000);
  137. padding: 0 2vw;
  138. .one {
  139. text-align: center;
  140. font-size: 30px;
  141. font-family: monospace;
  142. color: var(--rgbfff);
  143. padding: 10vw 0 10vw 0;
  144. }
  145. .two {
  146. margin: 0 0 4vw 0;
  147. .btn {
  148. padding: 2vw 0 0 0;
  149. text-align: center;
  150. button {
  151. width: 80%;
  152. background-color: var(--rgbfa4);
  153. color: var(--rgbfff);
  154. padding: 1vw 0;
  155. }
  156. }
  157. }
  158. .thr {
  159. text-align: center;
  160. button {
  161. background-color: var(--rgbfa4);
  162. color: var(--rgbfff);
  163. }
  164. }
  165. }
  166. .agree {
  167. text-align: center;
  168. font-size: 12px;
  169. margin: 0 0 2vw 0;
  170. color: var(--rgbfff);
  171. }
  172. </style>