account-login.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <!-- 账号密码登录 accountLogin -->
  2. <template>
  3. <view>
  4. <!-- 标题栏 -->
  5. <view class="head-box ss-flex-col">
  6. <view class="ss-flex ss-m-b-20">
  7. <view class="head-title ss-m-r-40 head-title-animation">账号登录</view>
  8. <view class="head-title-active head-title-line" @tap="showAuthModal('smsLogin')">
  9. 短信登录
  10. </view>
  11. </view>
  12. <!-- <view class="head-subtitle">如果未设置过密码,请点击忘记密码</view> -->
  13. </view>
  14. <!-- 用户协议的勾选 -->
  15. <view
  16. v-if="['accountLogin', 'smsLogin'].includes(authType)"
  17. class="agreement-box ss-flex ss-row-center"
  18. :class="{ shake: currentProtocol }"
  19. >
  20. <label class="radio ss-flex ss-col-center" @tap="onChange">
  21. <radio
  22. :checked="protocol"
  23. color="var(--ui-BG-Main)"
  24. style="transform: scale(0.8)"
  25. @tap.stop="onChange"
  26. />
  27. <view class="agreement-text ss-flex ss-col-center ss-m-l-8">
  28. 我已阅读并遵守
  29. <view class="tcp-text" @tap.stop="onProtocol('用户协议')">
  30. 《用户协议》
  31. </view>
  32. <view class="agreement-text">与</view>
  33. <view class="tcp-text" @tap.stop="onProtocol('隐私协议')">
  34. 《隐私协议》
  35. </view>
  36. </view>
  37. </label>
  38. </view>
  39. <!-- 表单项 -->
  40. <uni-forms
  41. ref="accountLoginRef"
  42. v-model="state.model"
  43. :rules="state.rules"
  44. validateTrigger="bind"
  45. labelWidth="140"
  46. labelAlign="center"
  47. class="loginUniForm"
  48. >
  49. <uni-forms-item name="mobile" label="账号" class="loginUniFormItem">
  50. <uni-easyinput placeholder="请输入账号" v-model="state.model.mobile" :inputBorder="false">
  51. <!-- <template v-slot:right>
  52. <button class="ss-reset-button forgot-btn" @tap="showAuthModal('resetPassword')">
  53. 忘记密码
  54. </button>
  55. </template> -->
  56. </uni-easyinput>
  57. </uni-forms-item>
  58. <uni-forms-item name="password" label="密码" class="loginUniFormItem">
  59. <uni-easyinput
  60. type="password"
  61. placeholder="请输入密码"
  62. v-model="state.model.password"
  63. :inputBorder="false"
  64. >
  65. <!-- <template v-slot:right>
  66. <button class="ss-reset-button login-btn-start" @tap="accountLoginSubmit">登录</button>
  67. </template> -->
  68. </uni-easyinput>
  69. </uni-forms-item>
  70. </uni-forms>
  71. <view style="display: flex;justify-content: space-between;margin-top: 20rpx;">
  72. <button class="ss-reset-button forgot-btn" @tap="showAuthModal('resetPassword')">
  73. 忘记密码
  74. </button>
  75. <button class="ss-reset-button login-btn-start" @tap="accountLoginSubmit">登录</button>
  76. </view>
  77. </view>
  78. </template>
  79. <script setup>
  80. import { ref, reactive, unref,computed } from 'vue';
  81. import sheep from '@/sheep';
  82. import { mobile, password } from '@/sheep/validate/form';
  83. import { showAuthModal, closeAuthModal } from '@/sheep/hooks/useModal';
  84. import AuthUtil from '@/sheep/api/member/auth';
  85. const accountLoginRef = ref(null);
  86. const emits = defineEmits(['onConfirm']);
  87. const props = defineProps({
  88. agreeStatus: {
  89. type: Boolean,
  90. default: false,
  91. },
  92. });
  93. // 数据
  94. const state = reactive({
  95. model: {
  96. mobile: '', // 账号
  97. password: '', // 密码
  98. },
  99. rules: {
  100. mobile,
  101. password,
  102. },
  103. });
  104. const currentProtocol = ref(false);
  105. const modalStore = sheep.$store('modal');
  106. const authType = computed(() => modalStore.auth);
  107. const protocol = ref(false)
  108. // 勾选协议
  109. function onChange() {
  110. protocol.value = !protocol.value;
  111. console.log(protocol.value)
  112. }
  113. // 查看协议
  114. function onProtocol(title) {
  115. closeAuthModal();
  116. sheep.$router.go('/pages/public/richtext', {
  117. title,
  118. });
  119. }
  120. // 点击登录 / 注册事件
  121. function onConfirm(e) {
  122. currentProtocol.value = e;
  123. setTimeout(() => {
  124. currentProtocol.value = false;
  125. }, 1000);
  126. }
  127. // 账号登录
  128. async function accountLoginSubmit() {
  129. // 表单验证
  130. const validate = await unref(accountLoginRef)
  131. .validate()
  132. .catch((error) => {
  133. console.log('error: ', error);
  134. });
  135. if (!validate) return;
  136. // 同意协议
  137. if (!protocol.value) {
  138. // emits('onConfirm', true)
  139. onConfirm(true)
  140. // console.log("没勾选",protocol)
  141. sheep.$helper.toast('请勾选同意');
  142. return;
  143. }
  144. // 提交数据
  145. const { code, data } = await AuthUtil.login(state.model);
  146. if (code === 0) {
  147. closeAuthModal();
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. @import '../index.scss';
  153. .shake {
  154. animation: shake 0.05s linear 4 alternate;
  155. }
  156. @keyframes shake {
  157. from {
  158. transform: translateX(-10rpx);
  159. }
  160. to {
  161. transform: translateX(10rpx);
  162. }
  163. }
  164. .agreement-box{
  165. margin: 20rpx 0;
  166. }
  167. .login-btn-start{
  168. background:rgb(14, 147, 46);
  169. width:60%
  170. }
  171. .loginUniForm{
  172. border: 1rpx solid #d6d6d6;
  173. padding:10rpx 15rpx;
  174. border-radius: 10rpx;
  175. }
  176. .loginUniFormItem:first-child{
  177. border-bottom: 1rpx solid #d6d6d6;
  178. padding-bottom:10rpx;
  179. }
  180. .loginUniFormItem:last-child{
  181. // border-bottom: 1rpx solid #d6d6d6;
  182. padding-top:10rpx;
  183. }
  184. ::v-deep .loginUniFormItem .uni-forms-item__inner{
  185. padding-bottom: 0;
  186. }
  187. ::v-deep .loginUniFormItem .uni-error-message{
  188. bottom: -20rpx;
  189. }
  190. </style>