clientIndex.vue 5.4 KB

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