clientIndex.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. <view v-if="fromAppShare" class="wechat-auth-box">
  9. <view class="auth-tips">欢迎使用小程序</view>
  10. <button class="wechat-auth-btn" open-type="getPhoneNumber" @getphonenumber="onWechatAuth">
  11. 微信一键登录
  12. </button>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script setup>
  18. import cacheManager from '@/utils/cacheManager.js'
  19. import * as httpApi from "@/api/login.js"
  20. import {
  21. ref,
  22. onMounted
  23. } from "vue"
  24. import {
  25. toast
  26. } from "@/utils/common";
  27. import {
  28. useIsCanBack
  29. } from "@/store/isCanBack.js"
  30. import {
  31. onLoad
  32. } from "@dcloudio/uni-app";
  33. // 原有变量
  34. const userName = ref('')
  35. const password = ref('')
  36. const showPassword = ref(true)
  37. const clearTelIcon = ref(false)
  38. const clearPwIcon = ref(false)
  39. const isAgreed = ref(false)
  40. const id = ref('')
  41. const code = ref('')
  42. const fromPage = ref('');
  43. const openId = ref('');
  44. // 新增变量
  45. const fromAppShare = ref(false) // 是否来自APP分享
  46. const store = useIsCanBack();
  47. onLoad((options) => {
  48. if (options.from === 'appcx') {
  49. id.value = options.id
  50. fromPage.value = options.from;
  51. }
  52. uni.login().then(res1 => {
  53. console.log('res1', res1);
  54. code.value = res1.code
  55. httpApi.loginApplet({
  56. code: res1.code,
  57. }).then(result => {
  58. console.log('result', result);
  59. openId.value = result.data.openId
  60. if (result.data.bind) {
  61. // 保存用户信息
  62. if (result.data.loginVo.type == 4) {
  63. cacheManager.set('auth', result.data.loginVo)
  64. store.setIsCanBack(false)
  65. gotoPage();
  66. } else if (result.data.loginVo.type == 6) {
  67. cacheManager.set('auth', result.data.loginVo)
  68. store.setIsCanBack(false)
  69. gotoPage2();
  70. } else {
  71. toast('登录失败,您的身份有误,请联系管理员。')
  72. return
  73. }
  74. } else {
  75. fromAppShare.value = true
  76. }
  77. })
  78. })
  79. getAllImg();
  80. })
  81. // 微信授权登录
  82. function onWechatAuth(e) {
  83. if (e.detail.errMsg.includes('fail')) {
  84. toast('授权失败')
  85. return
  86. }
  87. uni.showLoading({
  88. title: '登录中'
  89. })
  90. console.log('e123123123', e);
  91. try {
  92. httpApi.bindApplet({
  93. code: e.detail.code,
  94. openId: openId.value,
  95. }).then(result=>{
  96. if (result.data.type == 4) {
  97. cacheManager.set('auth', result.data)
  98. store.setIsCanBack(false)
  99. gotoPage();
  100. } else if (result.data.type == 6) {
  101. cacheManager.set('auth', result.data)
  102. store.setIsCanBack(false)
  103. gotoPage2();
  104. } else {
  105. toast('登录失败,您的身份有误,请联系管理员。')
  106. }
  107. })
  108. } catch (error) {
  109. toast('bindApplet失败')
  110. } finally {
  111. uni.hideLoading()
  112. }
  113. }
  114. function gotoPage() {
  115. console.log('ididid', id.value);
  116. if (id.value) {
  117. uni.navigateTo({
  118. url: `/pages/client/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  119. })
  120. } else {
  121. uni.navigateTo({
  122. url: `/pages/client/ShouYe/shouye`
  123. })
  124. }
  125. }
  126. function gotoPage2() {
  127. console.log('ididid222222', id.value);
  128. if (id.value) {
  129. uni.navigateTo({
  130. url: `/pages/kehu/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  131. })
  132. } else {
  133. uni.navigateTo({
  134. url: `/pages/kehu/shouYe/shouye`
  135. })
  136. }
  137. }
  138. function getAllImg() {
  139. httpApi.getAllImgList({}).then(res => {
  140. cacheManager.set('projectImg', res.data)
  141. });
  142. }
  143. </script>
  144. <style scoped>
  145. /* 新增样式 */
  146. .wechat-auth-box {
  147. text-align: center;
  148. padding: 40rpx 0;
  149. }
  150. .auth-tips {
  151. font-size: 32rpx;
  152. color: #333;
  153. margin-bottom: 60rpx;
  154. }
  155. .wechat-auth-btn {
  156. background-color: #07C160;
  157. color: white;
  158. border-radius: 50rpx;
  159. margin-bottom: 30rpx;
  160. }
  161. .switch-login {
  162. color: #007AFF;
  163. font-size: 28rpx;
  164. }
  165. /* 你原有的所有样式都保持不变 */
  166. </style>