test.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="phone-login-page">
  3. <view class="login-wrap-box">
  4. <view class="bjcx-head-box">
  5. <icon class="bjcx-logo-box"></icon>
  6. <view class="bjcx-logo-title">家政学</view>
  7. </view>
  8. <!-- 普通登录表单 -->
  9. <view class="login-input-body">
  10. <view class="login-input-box">
  11. <icon class="user-icon"></icon>
  12. <input class="login-input" type="text" v-model="userName" placeholder="请输入手机号"
  13. @input="userInputChange">
  14. <view class="close-btn" v-if="clearTelIcon" @click="clearTel"></view>
  15. </view>
  16. <view class="login-input-box">
  17. <icon class="tel-icon"></icon>
  18. <input class="login-input" placeholder="请输入证件号后六位" v-model="password" :password="showPassword"
  19. @input="passwordInputChange" />
  20. <text class="login-eye" :class="[!showPassword ? 'uni-eye-active' : '']"
  21. @click="changePassword"></text>
  22. <view class="close-btn" v-if="clearPwIcon" @click="clearPw"></view>
  23. </view>
  24. <!-- 协议勾选框和按钮 -->
  25. <view class="agreement-checkbox-box">
  26. <checkbox-group @change="handleChange">
  27. <checkbox class="agreement-checkbox-input" color="#3fd2a1" value="agree" :checked="isAgreed"
  28. style="transform:scale(0.8)" />
  29. </checkbox-group>
  30. <view class="agreement-text-box">
  31. 在使用当前小程序服务之前,请仔细阅读<view class="agreement-text" @click="agreeBtn('yhxy')">《诚祥学用户协议》</view>和<view
  32. @click="agreeBtn('ystk')" class="agreement-text">《诚祥学隐私政策》</view>,如您同意,请勾选后开始使用
  33. </view>
  34. </view>
  35. <button @click="handleLogin" class="phone-green-btn wechat-auth-btn" type="default" hover-class="none">登录</button>
  36. <view class="qtdl-btn"><text class="qtdl-text" @click="handleChangeYijiandenglu">手机号一键登录</text></view>
  37. </view>
  38. </view>
  39. <view style="position: absolute;bottom: 32px;width:100%;text-align: center;color:#999;font-size: 12px;">仅限家政学用户使用</view>
  40. </view>
  41. </template>
  42. <script setup>
  43. import cacheManager from '@/utils/cacheManager.js'
  44. import * as httpApi from "@/api/login.js"
  45. import {
  46. ref,
  47. onMounted
  48. } from "vue"
  49. import {
  50. toast
  51. } from "@/utils/common";
  52. import {
  53. useIsCanBack
  54. } from "@/store/isCanBack.js"
  55. import {
  56. onLoad
  57. } from "@dcloudio/uni-app";
  58. // 原有变量
  59. const userName = ref('')
  60. const password = ref('')
  61. const showPassword = ref(true)
  62. const clearTelIcon = ref(false)
  63. const clearPwIcon = ref(false)
  64. const isAgreed = ref(false)
  65. const id = ref('')
  66. const code = ref('')
  67. const fromPage = ref('');
  68. // 新增变量
  69. const fromAppShare = ref(false) // 是否来自APP分享
  70. const store = useIsCanBack();
  71. onLoad((options) => {
  72. fromPage.value = options.from;
  73. id.value = options.id
  74. getAllImg();
  75. })
  76. function handleChangeYijiandenglu() {
  77. let str = ``;
  78. if (id.value) {
  79. str = str+`id=${id.value}`
  80. }
  81. if ( id.value && fromPage.value ) {
  82. str = str +`&from=${fromPage.value}`
  83. } else if (!id.value && fromPage.value) {
  84. str = str + `from=${fromPage.value}`
  85. }
  86. if (str) {
  87. uni.redirectTo({
  88. url: `/pages/Login/clientIndex?${str}`
  89. })
  90. } else {
  91. uni.redirectTo({
  92. url: `/pages/Login/clientIndex`
  93. })
  94. }
  95. }
  96. // 你原有的所有方法都不变
  97. function handleChange() {
  98. isAgreed.value = !isAgreed.value
  99. }
  100. function agreeBtn(code) {
  101. if (code === 'yhxy') {
  102. uni.navigateTo({
  103. url: "/pages/client/my/xieyi"
  104. })
  105. } else {
  106. uni.navigateTo({
  107. url: "/pages/client/my/zhengce"
  108. })
  109. }
  110. }
  111. function userInputChange(event) {
  112. if (event.detail.value.length > 0) {
  113. clearTelIcon.value = true;
  114. } else {
  115. clearTelIcon.value = false;
  116. }
  117. }
  118. function passwordInputChange(event) {
  119. if (event.detail.value.length > 0) {
  120. clearPwIcon.value = true;
  121. } else {
  122. clearPwIcon.value = false;
  123. }
  124. }
  125. function clearTel() {
  126. userName.value = '';
  127. clearTelIcon.value = false;
  128. }
  129. function clearPw() {
  130. password.value = '';
  131. clearPwIcon.value = false;
  132. }
  133. function changePassword() {
  134. showPassword.value = !showPassword.value;
  135. }
  136. function handleLogin() {
  137. if (userName.value.length === 0) {
  138. toast('请输入手机号!')
  139. return
  140. }
  141. if (password.value.length === 0) {
  142. toast('请输入密码!')
  143. return
  144. }
  145. if (!isAgreed.value) {
  146. toast('请先阅读并同意用户协议和隐私政策')
  147. return // 直接返回,不执行后面的授权逻辑
  148. }
  149. const trimmedUserName = userName.value;
  150. const trimmedPassword = password.value;
  151. uni.showLoading({
  152. title: '登录中'
  153. })
  154. httpApi.appletLoginTel({
  155. tel: trimmedUserName,
  156. str: trimmedPassword,
  157. }).then(res => {
  158. if (res.data.type === 4) {
  159. cacheManager.set('auth', res.data)
  160. store.setIsCanBack(false)
  161. gotoPage();
  162. } else if (res.data.type === 6) {
  163. cacheManager.set('auth', res.data)
  164. store.setIsCanBack(false)
  165. gotoPage2();
  166. } else {
  167. toast('登录失败,您的身份有误,请联系管理员。')
  168. }
  169. uni.hideLoading()
  170. }).catch(err => {
  171. store.setIsCanBack(true)
  172. setTimeout(() => {
  173. uni.hideLoading()
  174. },4000)
  175. }).finally(err => {
  176. })
  177. }
  178. function gotoPage() {
  179. if (id.value) {
  180. uni.redirectTo({
  181. url: `/pages/client/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  182. })
  183. } else {
  184. uni.redirectTo({
  185. url: `/pages/client/ShouYe/shouye`
  186. })
  187. }
  188. }
  189. function gotoPage2() {
  190. if (id.value) {
  191. uni.redirectTo({
  192. url: `/pages/kehu/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  193. })
  194. } else {
  195. uni.redirectTo({
  196. url: `/pages/kehu/shouye/shouye`
  197. })
  198. }
  199. }
  200. function getAllImg() {
  201. httpApi.getAllImgList({}).then(res => {
  202. cacheManager.set('projectImg', res.data)
  203. });
  204. }
  205. </script>