You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

227 lines
6.4 KiB

  1. <template>
  2. <view class="login">
  3. <view class="login-logo">
  4. <image class="logo" src="https://img.teyizhao.com/2025-08-07/f5cd742f-fef4-4d9b-84d9-131f0cba716f.png" mode="aspectFill"></image>
  5. </view>
  6. <view class="login-submit">
  7. <up-button class="mt24" type="primary" text="手机号登录"
  8. v-if="checkboxValue.length == 0"
  9. @click="loginWx"
  10. shape="circle" color="#FFBF60" style="margin-top: 20rpx;"></up-button>
  11. <up-button class="mt24" type="primary" text="手机号登录"
  12. v-else
  13. open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber"
  14. shape="circle" color="#FFBF60" style="margin-top: 20rpx;"></up-button>
  15. </view>
  16. <view class="flex-rowc">
  17. <view>
  18. <up-checkbox-group v-model="checkboxValue">
  19. <up-checkbox v-model="isAgree" size="29rpx" icon-size="29rpx" name="agree"
  20. shape="circle" activeColor="#FFBF60">
  21. </up-checkbox>
  22. </up-checkbox-group>
  23. </view>
  24. <view class="size-26 agreement">
  25. <text>我已阅读并同意猫爸狗妈</text>
  26. <text @click="privacyPolicy('login_xy')" class="main-color">注册协议</text>
  27. <text></text>
  28. <text @click="privacyPolicy('login_ys')" class="main-color">隐私政策</text>
  29. </view>
  30. </view>
  31. <view class="login-footer flex-rowc">
  32. <button @click="cancelLogin" class="btn-cancel" plain>暂不登录</button>
  33. </view>
  34. <up-popup :show="show" @close="close" :round="10">
  35. <view style="padding: 10rpx 20rpx;height: 50vh;overflow-y: scroll;" v-html="content"></view>
  36. </up-popup>
  37. </view>
  38. </template>
  39. <script>
  40. import {
  41. getOpenIdKey,
  42. getToken,
  43. setOpenIdKey,
  44. setStorage,
  45. setToken
  46. } from "../../utils/auth";
  47. import {
  48. getOpenId,
  49. getPersonalInfo,
  50. getPhoneNumber
  51. } from "../../api/system/user";
  52. import { mapGetters } from 'vuex';
  53. export default {
  54. name: 'AuthIndex',
  55. data() {
  56. return {
  57. value: false,
  58. show: false,
  59. content: '',
  60. checkboxValue: [],
  61. url : '',
  62. }
  63. },
  64. computed: {
  65. ...mapGetters(['configList'])
  66. },
  67. onLoad(options) {
  68. this.url = options.url || ''
  69. },
  70. methods: {
  71. // 微信授权登陆
  72. loginWx() {
  73. if (this.checkboxValue.length == 0) {
  74. return uni.showToast({
  75. title: '请先同意隐私协议',
  76. icon: 'none'
  77. })
  78. }
  79. },
  80. login() {
  81. uni.login({
  82. provider: 'weixin',
  83. success: (loginRes) => {
  84. this.getOpenId(loginRes.code)
  85. },
  86. fail: function(error) {
  87. // 授权失败处理
  88. uni.showToast('授权失败,请授权后再试')
  89. }
  90. });
  91. },
  92. getOpenId(code) {
  93. getOpenId(code).then(res => {
  94. if (res.code == 200 && res.data) {
  95. let resData = JSON.parse(res.data)
  96. let token = resData.token;
  97. let openId = resData.openId;
  98. setOpenIdKey(openId)
  99. if(token){
  100. setToken(token)
  101. this.$store.commit('getUserInfo')
  102. }else{
  103. // 如果没有token,可能需要获取手机号
  104. uni.showToast({
  105. title: '请授权手机号登录',
  106. icon: 'none'
  107. })
  108. }
  109. }
  110. })
  111. },
  112. // 获取token
  113. onGetPhoneNumber(e) {
  114. if(e.detail.errMsg=="getPhoneNumber:fail user deny"){ //用户拒绝授权
  115. //拒绝授权后弹出一些提示
  116. }else{ //允许授权
  117. if(getOpenIdKey()){
  118. this.getPhoneNumber({"openId":getOpenIdKey(),"code":e.detail.code})
  119. }
  120. }
  121. },
  122. getPhoneNumber(data){
  123. getPhoneNumber(data).then(res=>{
  124. if(res&&res.code==200){
  125. let token = res.data.token
  126. setToken(token)
  127. this.$store.commit('getUserInfo')
  128. if(this.url){
  129. uni.redirectTo({
  130. url: this.url
  131. })
  132. }
  133. } else{
  134. uni.showToast({
  135. icon:'error',
  136. title:'获取手机号失败'
  137. })
  138. }
  139. })
  140. },
  141. cancelLogin() {
  142. uni.switchTab({
  143. url: "/pages/workbenchManage/index"
  144. })
  145. },
  146. close() {
  147. this.show = false
  148. },
  149. privacyPolicy(key) {
  150. this.content = this.configList && this.configList[key] ? this.configList[key].paramValueArea || "" : "";
  151. this.show = true;
  152. }
  153. }
  154. }
  155. </script>
  156. <style scoped lang="scss">
  157. .login {
  158. height: 100vh;
  159. background: #ffffff;
  160. &-logo {
  161. display: flex;
  162. flex-direction: column;
  163. justify-content: center;
  164. align-items: center;
  165. height: 504rpx;
  166. background: linear-gradient(360deg, #FFFFFF 0%, #FFBF60 99%);
  167. .logo {
  168. width: 220rpx;
  169. height: 220rpx;
  170. }
  171. .d {
  172. width: 200rpx;
  173. height: 80rpx;
  174. margin-top: 20rpx;
  175. }
  176. }
  177. &-submit {
  178. padding: 0 76rpx;
  179. margin: 150rpx 0 40rpx 0;
  180. }
  181. }
  182. .flex-rowc{
  183. display: flex;
  184. justify-content: center;
  185. align-items: center;
  186. }
  187. .agreement {
  188. color: #C7C7C7;
  189. font-size: 22rpx;
  190. line-height: 29rpx;
  191. }
  192. .login-footer {
  193. width: 100vw;
  194. position: fixed;
  195. bottom: 127rpx;
  196. text-align: center;
  197. .btn-cancel {
  198. color: #C7C7C7;
  199. font-size: 30rpx;
  200. line-height: 40rpx;
  201. border: none;
  202. display: inline-block;
  203. padding: 0;
  204. }
  205. }
  206. </style>