clientIndex.vue 6.5 KB

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