clientIndex.vue 4.2 KB

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