index.vue 7.9 KB

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