clientIndex.vue 6.3 KB

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