clientIndex.vue 6.3 KB

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