index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <view class="ss-p-30 head-box">
  3. <template v-if="changeType === 'login'">
  4. <view class="head-title ss-m-b-30">欢迎来到门墩儿</view>
  5. <view class="ss-m-t-30">
  6. <!-- 企业邮箱+密码登录 -->
  7. <uni-forms
  8. ref="accountLoginRef"
  9. v-model="state.account"
  10. :rules="state.rules"
  11. validateTrigger="bind"
  12. labelWidth="140"
  13. labelAlign="center"
  14. >
  15. <uni-forms-item name="phone" label="企业邮箱">
  16. <uni-easyinput placeholder="请输入企业邮箱" v-model="state.account.phone" :inputBorder="false"></uni-easyinput>
  17. </uni-forms-item>
  18. <uni-forms-item name="password" label="登录密码">
  19. <uni-easyinput type="password" placeholder="请输入密码" v-model="state.account.password" :inputBorder="false"></uni-easyinput>
  20. </uni-forms-item>
  21. </uni-forms>
  22. <view class="quickLogon">
  23. <view class="color-666" style="font-size: .85em; text-decoration: underline;" @tap.stop="handleForgotPassword">忘记密码</view>
  24. <view class="register" @tap="handleChangeRegister">还没有登录账户?去注册</view>
  25. </view>
  26. <button class="send-button" @tap="handleLogin"> 登 录 </button>
  27. <view class="agreement-box ss-flex ss-row-center" style="margin-bottom: 30px;">
  28. <uni-icons size="20" :type="protocol ? 'checkbox-filled' : 'circle'" :color="protocol ? '#00B760' : '#ccc'" @tap="protocol = !protocol"></uni-icons>
  29. <view class="color-999 ss-flex ss-col-center ss-m-l-8 font-size-13">
  30. 我已阅读并遵守
  31. <view class="color-primary" @tap.stop="handleToDetail('user')">
  32. 《用户协议》
  33. </view>
  34. <view class="agreement-text">和</view>
  35. <view class="color-primary" @tap.stop="handleToDetail('privacy')">
  36. 《隐私协议》
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <template v-if="changeType === 'register'">
  43. <view class="head-title pb-20">企业注册</view>
  44. <uni-forms
  45. ref="registerForm"
  46. v-model="state.register"
  47. :rules="state.smsRules"
  48. validateTrigger="bind"
  49. labelWidth="140"
  50. labelAlign="center"
  51. >
  52. <uni-forms-item name="phone" label="企业邮箱">
  53. <uni-easyinput placeholder="请输入企业邮箱" v-model="state.register.phone" :inputBorder="false"></uni-easyinput>
  54. </uni-forms-item>
  55. <uni-forms-item name="password" label="登录密码">
  56. <uni-easyinput type="password" placeholder="请输入密码" v-model="state.register.password" :inputBorder="false"></uni-easyinput>
  57. </uni-forms-item>
  58. </uni-forms>
  59. <view class="register login" style="text-align: end;" @tap="handleChangeLogin">已有账户?去登陆</view>
  60. <view>
  61. <button class="send-button" @tap="handleRegister"> 注 册 </button>
  62. </view>
  63. <view class="color-999 ss-flex ss-col-center ss-row-center ss-m-l-8 font-size-13" style="margin-bottom: 30px;">
  64. 点击注册即代表您同意
  65. <view class="color-primary" @tap.stop="handleToDetail('user')">
  66. 《用户协议》
  67. </view>
  68. <view class="agreement-text">和</view>
  69. <view class="color-primary" @tap.stop="handleToDetail('privacy')">
  70. 《隐私协议》
  71. </view>
  72. </view>
  73. </template>
  74. </view>
  75. </template>
  76. <script setup>
  77. import { ref, unref } from 'vue'
  78. import { password, emailRequired } from '@/utils/validate'
  79. import { userStore } from '@/store/user'
  80. import { closeAuthModal } from '@/hooks/useModal'
  81. import { getEnterpriseRegisterApply } from '@/api/enterprise'
  82. import { testEnvBool } from '@/utils/config'
  83. const useUserStore = userStore()
  84. const accountLoginRef = ref()
  85. const registerForm = ref()
  86. const protocol = ref(false)
  87. const state = ref({
  88. isMobileEnd: false, // 手机号输入完毕
  89. codeText: '获取验证码',
  90. sms: {
  91. phone: '',
  92. code: ''
  93. },
  94. register: {
  95. phone: '',
  96. password: ''
  97. },
  98. account: {
  99. phone: testEnvBool ? '1687284007@qq.com' : '', // 1687284007 18406571584
  100. password: testEnvBool ? 'Citu123456' : ''
  101. },
  102. rules: {
  103. phone: emailRequired,
  104. password
  105. },
  106. smsRules: {
  107. phone: emailRequired,
  108. password
  109. }
  110. })
  111. // 设置默认账号密码便于开发快捷登录
  112. if (window && window.location && window.location.hostname && window.location.hostname === 'localhost') {
  113. state.value.account.phone = '1687284007@qq.com'
  114. state.value.account.password = 'Citu123456'
  115. }
  116. // 忘记密码
  117. const handleForgotPassword = () => {
  118. uni.navigateTo({
  119. url: '/pagesA/forgotPassword/index'
  120. })
  121. }
  122. const changeType = ref('login')
  123. // 查看协议详情
  124. const handleToDetail = (type) => {
  125. const url = type === 'user' ? '/pagesB/agreement/user' : '/pagesB/agreement/privacy'
  126. uni.navigateTo({
  127. url
  128. })
  129. }
  130. // 注册
  131. function handleChangeRegister () {
  132. changeType.value = 'register'
  133. }
  134. // 登录
  135. function handleChangeLogin () {
  136. changeType.value = 'login'
  137. }
  138. async function handleRegister () {
  139. const validate = await unref(registerForm).validate()
  140. if (!validate) return
  141. closeAuthModal()
  142. const query = state.value.register
  143. uni.setStorageSync('isPersonalToken', true);
  144. uni.setStorageSync('registerAccount', JSON.stringify(query))
  145. uni.navigateTo({ url: '/pages/register/index' })
  146. }
  147. const handleCheckEnterprise = async () => {
  148. const { data } = await getEnterpriseRegisterApply(state.value.account.phone)
  149. if (data && Object.keys(data).length) {
  150. // 查看申请状态
  151. uni.setStorageSync('entRegisterData', JSON.stringify(data))
  152. uni.navigateTo({
  153. url: '/pages/register/review?hasData=true'
  154. })
  155. }
  156. closeAuthModal()
  157. }
  158. // 登录
  159. const handleLogin = async () => {
  160. if (!protocol.value) return uni.showToast({ title: '请先阅读并同意用户协议和隐私政策', icon: 'none' })
  161. const validate = await unref(accountLoginRef).validate()
  162. if (!validate) return
  163. const query = state.value.account
  164. Object.assign(query, {
  165. account: query.phone
  166. })
  167. console.log(query, '登录参数')
  168. try {
  169. await useUserStore.handleSmsLogin(query, 1)
  170. closeAuthModal()
  171. } catch (err) {
  172. console.log(err, '登录失败')
  173. if (!err.code || (err?.message && err.message.includes('timeout'))) return closeAuthModal()
  174. if (err.code === 1100017022) {
  175. // 密码不安全
  176. uni.showToast({ title: '您的密码不安全,请重置密码', icon: 'none', duration: 2000 })
  177. closeAuthModal()
  178. return
  179. }
  180. if (err.code === 1100021016) {
  181. // 企业注册申请中
  182. handleCheckEnterprise()
  183. return
  184. }
  185. if (err.code === 1100017019) {
  186. uni.showToast({ title: '您的邮箱还未注册过,请先注册', icon: 'none', duration: 2000 })
  187. changeType.value = 'register'
  188. }
  189. }
  190. }
  191. </script>
  192. <style scoped lang="scss">
  193. .login-code {
  194. width: 73px;
  195. min-width: 73px;
  196. color: #00B760;
  197. text-align: center;
  198. font-size: 12px;
  199. cursor: pointer;
  200. padding: 0;
  201. }
  202. .head-title {
  203. font-size: 40rpx;
  204. text-align: center;
  205. color: #00B760;
  206. margin-top: 30rpx;
  207. }
  208. .quickLogon {
  209. display: flex;
  210. justify-content: space-between;
  211. padding: 0 20rpx;
  212. align-items: center;
  213. }
  214. .register {
  215. widows: 100%;
  216. font-size: .85em;
  217. color: #00B760;
  218. text-decoration: underline;
  219. &.login {
  220. color: #00B760;
  221. }
  222. }
  223. .pb-20 {
  224. padding-bottom: 40rpx;
  225. }
  226. </style>