test.vue 5.5 KB

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