clientIndex.vue 5.3 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 v-if="fromAppShare" class="wechat-auth-box">
  10. <view class="auth-tips">欢迎使用小程序</view>
  11. <button class="wechat-auth-btn" open-type="getPhoneNumber" @getphonenumber="onWechatAuth">
  12. 微信一键登录
  13. </button>
  14. <view class="agreement-checkbox-box">
  15. <checkbox-group @change="handleChange">
  16. <checkbox class="agreement-checkbox-input" color="#3fd2a1" value="agree" :checked="isAgreed"
  17. style="transform:scale(0.7)" />
  18. </checkbox-group>
  19. <view class="agreement-text-box">
  20. 在使用当前小程序服务之前,请仔细阅读<view class="agreement-text" @click="agreeBtn('yhxy')">《诚祥学用户协议》</view>和<view
  21. @click="agreeBtn('ystk')" class="agreement-text">《诚祥学隐私政策》</view>,如您同意,请勾选后开始使用
  22. </view>
  23. </view>
  24. <button @click="handleChangeFangshi">
  25. 切换微信一键登录
  26. </button>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script setup>
  32. import cacheManager from '@/utils/cacheManager.js'
  33. import * as httpApi from "@/api/login.js"
  34. import {
  35. ref,
  36. onMounted
  37. } from "vue"
  38. import {
  39. toast
  40. } from "@/utils/common";
  41. import {
  42. useIsCanBack
  43. } from "@/store/isCanBack.js"
  44. import {
  45. onLoad
  46. } from "@dcloudio/uni-app";
  47. // 原有变量
  48. const userName = ref('')
  49. const password = ref('')
  50. const showPassword = ref(true)
  51. const clearTelIcon = ref(false)
  52. const clearPwIcon = ref(false)
  53. const isAgreed = ref(false)
  54. const id = ref('')
  55. const code = ref('')
  56. const fromPage = ref('');
  57. const openId = ref('');
  58. // 新增变量
  59. const fromAppShare = ref(true) // 是否来自APP分享
  60. const store = useIsCanBack();
  61. onLoad((options) => {
  62. getAllImg();
  63. })
  64. function handleChange() {
  65. isAgreed.value = !isAgreed.value
  66. }
  67. function agreeBtn(code) {
  68. if (code === 'yhxy') {
  69. uni.navigateTo({
  70. url: "/pages/client/my/xieyi"
  71. })
  72. } else {
  73. uni.navigateTo({
  74. url: "/pages/client/my/zhengce"
  75. })
  76. }
  77. }
  78. function handleChangeFangshi() {
  79. let str = ``;
  80. if (id.value) {
  81. str = str + `id=${id.value}`
  82. }
  83. if (id.value && fromPage.value) {
  84. str = str + `&from=${fromPage.value}`
  85. } else if (!id.value && fromPage.value) {
  86. str = str + `from=${fromPage.value}`
  87. }
  88. if (str) {
  89. uni.redirectTo({
  90. url: `/pages/Login/test?${str}`
  91. })
  92. } else {
  93. uni.redirectTo({
  94. url: `/pages/Login/test`
  95. })
  96. }
  97. }
  98. // 微信授权登录
  99. function onWechatAuth(e) {
  100. if (!isAgreed.value) {
  101. toast('请先阅读并同意用户协议和隐私政策')
  102. return // 直接返回,不执行后面的授权逻辑
  103. }
  104. if (e.detail.errMsg.includes('fail')) {
  105. toast('授权失败')
  106. return
  107. }
  108. uni.showLoading({
  109. title: '登录中'
  110. })
  111. try {
  112. uni.login().then(res1 => {
  113. console.log('res2222222', res1);
  114. code.value = res1.code
  115. httpApi.loginApplet({
  116. code: res1.code,
  117. }).then(result => {
  118. console.log('result2222', result);
  119. openId.value = result.data.openId
  120. if (result.data.bind) {
  121. // 保存用户信息
  122. if (result.data.loginVo.type == 4) {
  123. cacheManager.set('auth', result.data.loginVo)
  124. store.setIsCanBack(false)
  125. gotoPage();
  126. } else if (result.data.loginVo.type == 6) {
  127. cacheManager.set('auth', result.data.loginVo)
  128. store.setIsCanBack(false)
  129. gotoPage2();
  130. } else {
  131. toast('登录失败,您的身份有误,请联系管理员。')
  132. return
  133. }
  134. } else {
  135. console.log('1231');
  136. //.value = true
  137. httpApi.bindApplet({
  138. code: e.detail.code,
  139. openId: openId.value,
  140. }).then(result => {
  141. if (result.data.type == 4) {
  142. cacheManager.set('auth', result.data)
  143. store.setIsCanBack(false)
  144. gotoPage();
  145. } else if (result.data.type == 6) {
  146. cacheManager.set('auth', result.data)
  147. store.setIsCanBack(false)
  148. gotoPage2();
  149. } else {
  150. toast('登录失败,您的身份有误,请联系管理员。')
  151. }
  152. })
  153. }
  154. })
  155. })
  156. } catch (error) {
  157. toast('bindApplet失败')
  158. } finally {
  159. uni.hideLoading()
  160. }
  161. }
  162. function gotoPage() {
  163. console.log('ididid', id.value);
  164. if (id.value) {
  165. uni.navigateTo({
  166. url: `/pages/client/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  167. })
  168. } else {
  169. uni.navigateTo({
  170. url: `/pages/client/ShouYe/shouye`
  171. })
  172. }
  173. }
  174. function gotoPage2() {
  175. console.log('ididid222222', id.value);
  176. if (id.value) {
  177. uni.navigateTo({
  178. url: `/pages/kehu/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  179. })
  180. } else {
  181. uni.navigateTo({
  182. url: `/pages/kehu/shouYe/shouye`
  183. })
  184. }
  185. }
  186. function getAllImg() {
  187. httpApi.getAllImgList({}).then(res => {
  188. cacheManager.set('projectImg', res.data)
  189. });
  190. }
  191. </script>
  192. <style scoped>
  193. /* 新增样式 */
  194. .wechat-auth-box {
  195. text-align: center;
  196. padding: 40rpx 0;
  197. }
  198. .auth-tips {
  199. font-size: 32rpx;
  200. color: #333;
  201. margin-bottom: 60rpx;
  202. }
  203. .wechat-auth-btn {
  204. background-color: #07C160;
  205. color: white;
  206. border-radius: 50rpx;
  207. margin-bottom: 30rpx;
  208. }
  209. .switch-login {
  210. color: #007AFF;
  211. font-size: 28rpx;
  212. }
  213. /* 你原有的所有样式都保持不变 */
  214. </style>