test.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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>
  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.7)" />
  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 type="default" @click="handleLogin" class="phone-green-btn login-btn">登录</button>
  36. <button @click="handleChangeYijiandenglu" >
  37. 切换微信一键登录
  38. </button>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script setup>
  44. import cacheManager from '@/utils/cacheManager.js'
  45. import * as httpApi from "@/api/login.js"
  46. import {
  47. ref,
  48. onMounted
  49. } from "vue"
  50. import {
  51. toast
  52. } from "@/utils/common";
  53. import {
  54. useIsCanBack
  55. } from "@/store/isCanBack.js"
  56. import {
  57. onLoad
  58. } from "@dcloudio/uni-app";
  59. // 原有变量
  60. const userName = ref('')
  61. const password = ref('')
  62. const showPassword = ref(true)
  63. const clearTelIcon = ref(false)
  64. const clearPwIcon = ref(false)
  65. const isAgreed = ref(false)
  66. const id = ref('')
  67. const code = ref('')
  68. const fromPage = ref('');
  69. // 新增变量
  70. const fromAppShare = ref(false) // 是否来自APP分享
  71. const store = useIsCanBack();
  72. onLoad((options) => {
  73. fromPage.value = options.from;
  74. id.value = options.id
  75. getAllImg();
  76. })
  77. function handleChangeYijiandenglu() {
  78. let str = ``;
  79. if (id.value) {
  80. str = str+`id=${id.value}`
  81. }
  82. if ( id.value && fromPage.value ) {
  83. str = str +`&from=${fromPage.value}`
  84. } else if (!id.value && fromPage.value) {
  85. str = str + `from=${fromPage.value}`
  86. }
  87. if (str) {
  88. uni.redirectTo({
  89. url: `/pages/Login/clientIndex?${str}`
  90. })
  91. } else {
  92. uni.redirectTo({
  93. url: `/pages/Login/clientIndex`
  94. })
  95. }
  96. }
  97. // 你原有的所有方法都不变
  98. function handleChange() {
  99. isAgreed.value = !isAgreed.value
  100. }
  101. function agreeBtn(code) {
  102. if (code === 'yhxy') {
  103. uni.navigateTo({
  104. url: "/pages/client/my/xieyi"
  105. })
  106. } else {
  107. uni.navigateTo({
  108. url: "/pages/client/my/zhengce"
  109. })
  110. }
  111. }
  112. function userInputChange(event) {
  113. if (event.detail.value.length > 0) {
  114. clearTelIcon.value = true;
  115. } else {
  116. clearTelIcon.value = false;
  117. }
  118. }
  119. function passwordInputChange(event) {
  120. if (event.detail.value.length > 0) {
  121. clearPwIcon.value = true;
  122. } else {
  123. clearPwIcon.value = false;
  124. }
  125. }
  126. function clearTel() {
  127. userName.value = '';
  128. clearTelIcon.value = false;
  129. }
  130. function clearPw() {
  131. password.value = '';
  132. clearPwIcon.value = false;
  133. }
  134. function changePassword() {
  135. showPassword.value = !showPassword.value;
  136. }
  137. function handleLogin() {
  138. if (userName.value.length === 0) {
  139. toast('请输入手机号!')
  140. return
  141. }
  142. if (password.value.length === 0) {
  143. toast('请输入密码!')
  144. return
  145. }
  146. if (!isAgreed.value) {
  147. toast('请先阅读并同意用户协议和隐私政策')
  148. return // 直接返回,不执行后面的授权逻辑
  149. }
  150. const trimmedUserName = userName.value;
  151. const trimmedPassword = password.value;
  152. uni.showLoading({
  153. title: '登录中'
  154. })
  155. httpApi.appletLoginTel({
  156. tel: trimmedUserName,
  157. str: trimmedPassword,
  158. }).then(res => {
  159. if (res.data.type === 4) {
  160. cacheManager.set('auth', res.data)
  161. store.setIsCanBack(false)
  162. gotoPage();
  163. } else if (res.data.type === 6) {
  164. cacheManager.set('auth', res.data)
  165. store.setIsCanBack(false)
  166. gotoPage2();
  167. } else {
  168. toast('登录失败,您的身份有误,请联系管理员。')
  169. }
  170. }).catch(err => {
  171. store.setIsCanBack(true)
  172. }).finally(err => {
  173. uni.hideLoading()
  174. })
  175. }
  176. function gotoPage() {
  177. if (id.value) {
  178. uni.navigateTo({
  179. url: `/pages/client/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  180. })
  181. } else {
  182. uni.navigateTo({
  183. url: `/pages/client/ShouYe/shouye`
  184. })
  185. }
  186. }
  187. function gotoPage2() {
  188. if (id.value) {
  189. uni.navigateTo({
  190. url: `/pages/kehu/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  191. })
  192. } else {
  193. uni.navigateTo({
  194. url: `/pages/kehu/shouye/shouye`
  195. })
  196. }
  197. }
  198. function getAllImg() {
  199. httpApi.getAllImgList({}).then(res => {
  200. cacheManager.set('projectImg', res.data)
  201. });
  202. }
  203. </script>
  204. <style scoped>
  205. /* 新增样式 */
  206. .wechat-auth-box {
  207. text-align: center;
  208. padding: 40rpx 0;
  209. }
  210. .auth-tips {
  211. font-size: 32rpx;
  212. color: #333;
  213. margin-bottom: 60rpx;
  214. }
  215. .wechat-auth-btn {
  216. background-color: #07C160;
  217. color: white;
  218. border-radius: 50rpx;
  219. margin-bottom: 30rpx;
  220. }
  221. .switch-login {
  222. color: #007AFF;
  223. font-size: 28rpx;
  224. }
  225. /* 你原有的所有样式都保持不变 */
  226. </style>