兼兼街租房小程序
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.

247 lines
5.2 KiB

  1. <template>
  2. <view v-else class="login">
  3. <view class="login-img flex align-center justify-center">
  4. <view class="login_img">
  5. <image src="@/static/image/logo.jpg" mode=""></image>
  6. </view>
  7. </view>
  8. <view class="login-title">找房租房尽在兼兼街</view>
  9. <view>
  10. <view class="btn">
  11. <button class="btn_class" type="primary" @click="login">授权登录</button>
  12. </view>
  13. </view>
  14. <view class="tips flex align-center justify-between" @click="xieyiChoose = !xieyiChoose">
  15. <view>
  16. 注册/登录即代表同意
  17. <text class="xieyi">用户协议与隐私政策</text>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. xieyiChoose: true,
  27. code: '',
  28. did: '',
  29. vid: '',
  30. baomingStyle: {
  31. fontSize: "30rpx",
  32. fontWeight: "700",
  33. height: "100rpx",
  34. width: "480rpx"
  35. },
  36. baomingStyleQuxiao: {
  37. fontSize: "30rpx",
  38. fontWeight: "700",
  39. height: "100rpx",
  40. width: "480rpx",
  41. marginTop: "40rpx"
  42. }
  43. }
  44. },
  45. onLoad(err) {
  46. },
  47. methods: {
  48. //微信授权
  49. login() {
  50. uni.showLoading()
  51. uni.getProvider({
  52. service: 'oauth',
  53. success: res => {
  54. uni.hideLoading()
  55. if (~res.provider.indexOf('weixin')) {
  56. uni.login({
  57. provider: 'weixin',
  58. success: res => {
  59. console.log("授权登录信息")
  60. console.log(res)
  61. this.code = res.code
  62. uni.getUserInfo({
  63. provider: 'weixin',
  64. withCredentials: true,
  65. success: info => {
  66. this.getUserProfile(info, res.code)
  67. },
  68. fail: (err) => {
  69. console.log(err)
  70. uni.showToast({
  71. title: '拒绝授权将无法使用',
  72. icon: 'none'
  73. })
  74. }
  75. })
  76. },
  77. fail: () => {
  78. uni.hideLoading()
  79. uni.showToast({
  80. title: '微信登录授权失败',
  81. icon: 'none'
  82. })
  83. }
  84. })
  85. } else {
  86. uni.showToast({
  87. title: '请先安装微信或升级版本',
  88. icon: 'none'
  89. })
  90. }
  91. },
  92. fail: () => {
  93. uni.hideLoading()
  94. uni.showToast({
  95. title: '拉取授权失败',
  96. icon: 'none'
  97. })
  98. }
  99. })
  100. },
  101. getUserProfile(user, code) {
  102. uni.showModal({
  103. title: '温馨提示',
  104. content: '亲,请授权后获取您的',
  105. success: res => {
  106. if (res.confirm) {
  107. uni.getUserProfile({
  108. // desc: '显示用户昵称',
  109. desc: '获取你的昵称、头像、地区及性别',
  110. lang: 'zh_CN',
  111. success: val => {
  112. // uni.showLoading()
  113. let params = {
  114. iv: user.iv,
  115. code: code,
  116. encryptedData: user.encryptedData,
  117. signature: user.signature,
  118. rawData: user.rawData,
  119. nickName: val.userInfo.nickName
  120. }
  121. this.userInfo = val.userInfo
  122. this.toLogin(params)
  123. },
  124. fail: error => {
  125. console.log('getUserProfile error =>', error)
  126. uni.hideLoading()
  127. uni.showToast({
  128. title: '微信登录授权失败',
  129. icon: 'none'
  130. })
  131. }
  132. })
  133. }
  134. }
  135. })
  136. },
  137. // 登录
  138. toLogin(data) {
  139. this.$functions.showLoading("登录中...")
  140. this.$api.wxLogin(data).then(res => {
  141. console.log("等是否",res)
  142. // 保存token 跳转页面
  143. uni.setStorageSync("token",res.result.token);
  144. this.$functions.hideLoading();
  145. uni.switchTab({
  146. url: "/pages/index/index"
  147. })
  148. }).catch( err => {
  149. this.$functions.showToast(err.message)
  150. })
  151. // this.$request('/job-dev/house/applet/login', data, 'GET', (res) => {
  152. // console.log("登录成功")
  153. // // console.log(res)
  154. // // uni.hideLoading()
  155. // // let {
  156. // // result,
  157. // // code,
  158. // // message
  159. // // } = res
  160. // // result?.token && this.$store.commit('set_userToken', result.token)
  161. // if (res.code === 200) {
  162. // console.log("登录成功");
  163. // console.log(res,"登录成功后的信息")
  164. // uni.showToast({
  165. // title: "登录成功",
  166. // icon: 'none'
  167. // });
  168. // }else{
  169. // uni.showToast({
  170. // title: res.message,
  171. // icon: 'none'
  172. // })
  173. // }
  174. // })
  175. // .catch(err => {
  176. // uni.hideLoading()
  177. // uni.showToast({
  178. // title: err.message,
  179. // icon: 'none'
  180. // })
  181. // console.log(err)
  182. // })
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. .login {
  189. background-size: 100% 100%;
  190. height: 70vh;
  191. padding-top: 154rpx;
  192. .login-title {
  193. margin-top: 40rpx;
  194. font-size: 34rpx;
  195. font-weight: 700;
  196. text-align: center;
  197. padding-bottom: 30rpx;
  198. }
  199. .login-img {
  200. image {
  201. border-radius: 50%;
  202. width: 248rpx;
  203. height: 248rpx;
  204. }
  205. .login_img{
  206. display: flex;
  207. justify-content: center;
  208. }
  209. }
  210. .btn-box {
  211. margin-top: 136rpx;
  212. }
  213. .btn{
  214. display: flex;
  215. justify-content: center;
  216. .btn_class{
  217. width: 720rpx;
  218. border-radius: 20rpx;
  219. }
  220. }
  221. .tips {
  222. width: 500rpx;
  223. position: fixed;
  224. bottom: 52rpx;
  225. left: 51%;
  226. transform: translate(-50%, 0);
  227. font-size: 24rpx;
  228. color: #707070;
  229. .xieyi {
  230. color: #00CCFF;
  231. }
  232. }
  233. }
  234. </style>