clientIndex.vue 5.4 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 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. if (options.from === 'appcx') {
  63. id.value = options.id
  64. fromPage.value = options.from;
  65. }
  66. getAllImg();
  67. })
  68. function handleChange() {
  69. isAgreed.value = !isAgreed.value
  70. }
  71. function agreeBtn(code) {
  72. if (code === 'yhxy') {
  73. uni.navigateTo({
  74. url: "/pages/client/my/xieyi"
  75. })
  76. } else {
  77. uni.navigateTo({
  78. url: "/pages/client/my/zhengce"
  79. })
  80. }
  81. }
  82. function handleChangeFangshi() {
  83. let str = ``;
  84. if (id.value) {
  85. str = str + `id=${id.value}`
  86. }
  87. if (id.value && fromPage.value) {
  88. str = str + `&from=${fromPage.value}`
  89. } else if (!id.value && fromPage.value) {
  90. str = str + `from=${fromPage.value}`
  91. }
  92. if (str) {
  93. uni.redirectTo({
  94. url: `/pages/Login/test?${str}`
  95. })
  96. } else {
  97. uni.redirectTo({
  98. url: `/pages/Login/test`
  99. })
  100. }
  101. }
  102. // 微信授权登录
  103. function onWechatAuth(e) {
  104. if (!isAgreed.value) {
  105. toast('请先阅读并同意用户协议和隐私政策')
  106. return // 直接返回,不执行后面的授权逻辑
  107. }
  108. if (e.detail.errMsg.includes('fail')) {
  109. toast('授权失败')
  110. return
  111. }
  112. uni.showLoading({
  113. title: '登录中'
  114. })
  115. try {
  116. uni.login().then(res1 => {
  117. console.log('res2222222', res1);
  118. code.value = res1.code
  119. httpApi.loginApplet({
  120. code: res1.code,
  121. }).then(result => {
  122. console.log('result2222', result);
  123. openId.value = result.data.openId
  124. if (result.data.bind) {
  125. // 保存用户信息
  126. if (result.data.loginVo.type == 4) {
  127. cacheManager.set('auth', result.data.loginVo)
  128. store.setIsCanBack(false)
  129. gotoPage();
  130. } else if (result.data.loginVo.type == 6) {
  131. cacheManager.set('auth', result.data.loginVo)
  132. store.setIsCanBack(false)
  133. gotoPage2();
  134. } else {
  135. toast('登录失败,您的身份有误,请联系管理员。')
  136. return
  137. }
  138. } else {
  139. console.log('1231');
  140. //.value = true
  141. httpApi.bindApplet({
  142. code: e.detail.code,
  143. openId: openId.value,
  144. }).then(result => {
  145. if (result.data.type == 4) {
  146. cacheManager.set('auth', result.data)
  147. store.setIsCanBack(false)
  148. gotoPage();
  149. } else if (result.data.type == 6) {
  150. cacheManager.set('auth', result.data)
  151. store.setIsCanBack(false)
  152. gotoPage2();
  153. } else {
  154. toast('登录失败,您的身份有误,请联系管理员。')
  155. }
  156. })
  157. }
  158. })
  159. })
  160. } catch (error) {
  161. toast('bindApplet失败')
  162. } finally {
  163. uni.hideLoading()
  164. }
  165. }
  166. function gotoPage() {
  167. console.log('ididid', id.value);
  168. if (id.value) {
  169. uni.navigateTo({
  170. url: `/pages/client/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  171. })
  172. } else {
  173. uni.navigateTo({
  174. url: `/pages/client/ShouYe/shouye`
  175. })
  176. }
  177. }
  178. function gotoPage2() {
  179. console.log('ididid222222', id.value);
  180. if (id.value) {
  181. uni.navigateTo({
  182. url: `/pages/kehu/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  183. })
  184. } else {
  185. uni.navigateTo({
  186. url: `/pages/kehu/shouYe/shouye`
  187. })
  188. }
  189. }
  190. function getAllImg() {
  191. httpApi.getAllImgList({}).then(res => {
  192. cacheManager.set('projectImg', res.data)
  193. });
  194. }
  195. </script>
  196. <style scoped>
  197. /* 新增样式 */
  198. .wechat-auth-box {
  199. text-align: center;
  200. padding: 40rpx 0;
  201. }
  202. .auth-tips {
  203. font-size: 32rpx;
  204. color: #333;
  205. margin-bottom: 60rpx;
  206. }
  207. .wechat-auth-btn {
  208. background-color: #07C160;
  209. color: white;
  210. border-radius: 50rpx;
  211. margin-bottom: 30rpx;
  212. }
  213. .switch-login {
  214. color: #007AFF;
  215. font-size: 28rpx;
  216. }
  217. /* 你原有的所有样式都保持不变 */
  218. </style>