clientIndex.vue 5.1 KB

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