clientIndex.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. <!-- 协议勾选框和按钮 -->
  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.7)" />
  15. </checkbox-group>
  16. <view class="agreement-text-box">
  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-if="!isAgreed">微信一键登录</button>
  22. <button v-else class="wechat-auth-btn" open-type="getPhoneNumber" @getphonenumber="onWechatAuth">
  23. 微信一键登录
  24. </button>
  25. <button @click="handleChangeFangshi">
  26. 切换微信一键登录
  27. </button>
  28. </view>
  29. <!-- <view @click="ceshi" class="auth-tips">欢迎使用小程序12312312312312</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 id = ref('')
  57. const code = ref('')
  58. const fromPage = ref('');
  59. const openId = ref('');
  60. // 新增变量
  61. const fromAppShare = ref(false) // 是否来自APP分享
  62. const store = useIsCanBack();
  63. onLoad((options) => {
  64. if (options.from === 'appcx') {
  65. id.value = options.id
  66. fromPage.value = options.from;
  67. }
  68. uni.login().then(res1 => {
  69. console.log('res1', res1);
  70. code.value = res1.code
  71. httpApi.loginApplet({
  72. code: res1.code,
  73. }).then(result => {
  74. console.log('result', result);
  75. openId.value = result.data.openId
  76. if (result.data.bind) {
  77. // 保存用户信息
  78. if (result.data.loginVo.type == 4) {
  79. cacheManager.set('auth', result.data.loginVo)
  80. store.setIsCanBack(false)
  81. gotoPage();
  82. } else if (result.data.loginVo.type == 6) {
  83. cacheManager.set('auth', result.data.loginVo)
  84. store.setIsCanBack(false)
  85. gotoPage2();
  86. } else {
  87. toast('登录失败,您的身份有误,请联系管理员。')
  88. return
  89. }
  90. } else {
  91. fromAppShare.value = true
  92. }
  93. })
  94. })
  95. getAllImg();
  96. })
  97. // 你原有的所有方法都不变
  98. function handleChange() {
  99. isAgreed.value = !isAgreed.value
  100. }
  101. function agreeBtn(code) {
  102. if (code === 'yhxy') {
  103. uni.navigateTo({
  104. url: "/pages/client/my/xieyi"
  105. })
  106. } else {
  107. uni.navigateTo({
  108. url: "/pages/client/my/zhengce"
  109. })
  110. }
  111. }
  112. // 微信授权登录
  113. function onWechatAuth(e) {
  114. if (e.detail.errMsg.includes('fail')) {
  115. toast('授权失败')
  116. return
  117. }
  118. uni.showLoading({
  119. title: '登录中'
  120. })
  121. console.log('e123123123', e);
  122. try {
  123. httpApi.bindApplet({
  124. code: e.detail.code,
  125. openId: openId.value,
  126. }).then(result => {
  127. if (result.data.type == 4) {
  128. cacheManager.set('auth', result.data)
  129. store.setIsCanBack(false)
  130. gotoPage();
  131. } else if (result.data.type == 6) {
  132. cacheManager.set('auth', result.data)
  133. store.setIsCanBack(false)
  134. gotoPage2();
  135. } else {
  136. toast('登录失败,您的身份有误,请联系管理员。')
  137. }
  138. })
  139. } catch (error) {
  140. toast('bindApplet失败')
  141. } finally {
  142. uni.hideLoading()
  143. }
  144. }
  145. function gotoPage() {
  146. console.log('ididid', id.value);
  147. if (id.value) {
  148. uni.redirectTo({
  149. url: `/pages/client/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  150. })
  151. } else {
  152. uni.redirectTo({
  153. url: `/pages/client/ShouYe/shouye`
  154. })
  155. }
  156. }
  157. function gotoPage2() {
  158. console.log('ididid222222', id.value);
  159. if (id.value) {
  160. uni.redirectTo({
  161. url: `/pages/kehu/hetong/hetongInfo?id=` + id.value + `&from=${fromPage.value}`
  162. })
  163. } else {
  164. uni.redirectTo({
  165. url: `/pages/kehu/shouye/shouye`
  166. })
  167. }
  168. }
  169. function getAllImg() {
  170. httpApi.getAllImgList({}).then(res => {
  171. cacheManager.set('projectImg', res.data)
  172. });
  173. }
  174. function handleChangeFangshi() {
  175. let str = ``;
  176. if (id.value) {
  177. str = str+`id=${id.value}`
  178. }
  179. if ( id.value && fromPage.value ) {
  180. str = str +`&from=${fromPage.value}`
  181. } else if (!id.value && fromPage.value) {
  182. str = str + `from=${fromPage.value}`
  183. }
  184. if (str) {
  185. uni.redirectTo({
  186. url: `/pages/Login/test?${str}`
  187. })
  188. } else {
  189. uni.redirectTo({
  190. url: `/pages/Login/test`
  191. })
  192. }
  193. }
  194. </script>
  195. <style scoped>
  196. /* 新增样式 */
  197. .wechat-auth-box {
  198. text-align: center;
  199. padding: 40rpx 0;
  200. }
  201. .auth-tips {
  202. font-size: 32rpx;
  203. color: #333;
  204. margin-bottom: 60rpx;
  205. }
  206. .wechat-auth-btn {
  207. background-color: #07C160;
  208. color: white;
  209. border-radius: 50rpx;
  210. margin-bottom: 30rpx;
  211. }
  212. .switch-login {
  213. color: #007AFF;
  214. font-size: 28rpx;
  215. }
  216. /* 你原有的所有样式都保持不变 */
  217. </style>