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.

239 lines
5.3 KiB

8 months ago
8 months ago
  1. <template>
  2. <view class="content">
  3. <view style="height: 166rpx; width: 100%;"></view>
  4. <view class="a1">手机号快捷登录</view>
  5. <view class="a2">美好服务即刻享受</view>
  6. <view class="a3" @click="clickStaff">
  7. <image :src="configList.logo_image" mode="aspectFit"></image>
  8. </view>
  9. <view class="a4">上门服务服务平台</view>
  10. <button class="a5" @click.once="clickLogin()">微信一键注册登录</button>
  11. <view class="a6">
  12. <view class="a7" :class="{ a8 : agreement}" @click="agreement = !agreement">
  13. <span v-if="agreement">&check;</span>
  14. </view>
  15. 已同意<span @click="keyValue = 'policy'; configPopupShow = true" class="agreement">隐私政策</span>
  16. <span @click="keyValue = 'server';configPopupShow = true" class="agreement">服务条款</span>
  17. </view>
  18. <configPopup :keyValue="keyValue" :show="configPopupShow" :list="config" @close="configPopupShow = false" />
  19. </view>
  20. </template>
  21. <script>
  22. import configPopup from '@/components/configPopup'
  23. export default {
  24. components: {
  25. configPopup
  26. },
  27. data() {
  28. return {
  29. step: 2,
  30. openid: '',
  31. code: undefined,
  32. configPopupShow: false,
  33. keyValue: '',
  34. config: [],
  35. agreement: false,
  36. }
  37. },
  38. onShow() {
  39. this.getConfig()
  40. if (this.GetQueryString('code')) { //路径上面有code说明微信已授权
  41. this.agreement = true; //勾选协议
  42. //直接去登录发起请求
  43. this.toWxLogin(this.GetQueryString('code'))
  44. }
  45. },
  46. methods: {
  47. clickCancel() {
  48. uni.navigateTo({
  49. url: '/pages/login/mobile'
  50. })
  51. },
  52. clickStaff() {
  53. uni.navigateTo({
  54. url: '/pages/staff/center'
  55. })
  56. },
  57. clickLogin() {
  58. if (!this.agreement) {
  59. return uni.showToast({
  60. title: '请勾选协议',
  61. icon: 'none'
  62. })
  63. }
  64. this.getwx_authorize();
  65. },
  66. loginOrRegister(encryptData) {
  67. uni.setStorageSync("userid", "1")
  68. uni.switchTab({
  69. url: '/pages/index/index'
  70. })
  71. this.$httpGet("/wxma/getMobile", {
  72. encryptedData: encryptData
  73. }, (res) => {
  74. uni.setStorageSync("userid", "1")
  75. })
  76. },
  77. getwx_authorize() {
  78. let redirect_uri = encodeURIComponent(import.meta.env.VITE_REDIRECT_URI + '/#/pages/login/login');
  79. let appid = import.meta.env.VITE_APPID;
  80. window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid +
  81. '&redirect_uri=' + redirect_uri +
  82. '&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect' + '&t=' + new Date().getTime();
  83. },
  84. //获取url中参数的方法
  85. GetQueryString(name) {
  86. var url = window.location.href;
  87. try {
  88. var cs = url.split('?')[1]; //获取?之后的参数字符串
  89. var cs_arr = cs.split('&'); //参数字符串分割为数组
  90. for (var i = 0; i < cs_arr.length; i++) { //遍历数组,拿到json对象
  91. if (cs_arr[i].split('=')[0] == name) {
  92. return cs_arr[i].split('=')[1];
  93. }
  94. }
  95. return "";
  96. } catch {
  97. return "";
  98. }
  99. },
  100. //微信登录
  101. toWxLogin(code) {
  102. let vid = sessionStorage.getItem('vid');
  103. this.$api('wxLogin', {
  104. code,
  105. vid
  106. }, res => {
  107. if (res.code == 200) {
  108. localStorage.setItem("token", res.result.token)
  109. localStorage.setItem("userInfo", JSON.stringify(res.result.userInfo))
  110. if (!res.result.userInfo.phone) {
  111. uni.reLaunch({
  112. url: '/pages/mine/phoneDetail'
  113. })
  114. } else {
  115. location.href = import.meta.env.VITE_REDIRECT_URI + '/#/pages/index/index'
  116. }
  117. } else {
  118. location.href = import.meta.env.VITE_REDIRECT_URI + '/#/pages/login/login'
  119. }
  120. sessionStorage.removeItem('vid')
  121. })
  122. },
  123. getConfig() {
  124. this.$api('getConfig', {}, res => {
  125. if (res.code == 200) {
  126. this.config = res.result
  127. }
  128. })
  129. }
  130. }
  131. }
  132. </script>
  133. <style>
  134. .a1 {
  135. width: 336rpx;
  136. height: 66rpx;
  137. line-height: 66rpx;
  138. font-size: 48rpx;
  139. font-family: PingFang SC, PingFang SC-Heavy;
  140. font-weight: 800;
  141. text-align: center;
  142. color: #333333;
  143. width: 100%;
  144. margin-bottom: 20rpx;
  145. }
  146. .a2 {
  147. width: 100%;
  148. height: 40rpx;
  149. line-height: 40rpx;
  150. font-size: 28rpx;
  151. font-family: PingFang SC, PingFang SC-Regular;
  152. font-weight: 400;
  153. text-align: center;
  154. color: #333333;
  155. margin-bottom: 100rpx;
  156. }
  157. .a3 {
  158. width: 170rpx;
  159. height: 170rpx;
  160. border-radius: 16px;
  161. margin: 0 auto;
  162. overflow: hidden;
  163. }
  164. .a3 image {
  165. width: 100%;
  166. height: 100%;
  167. }
  168. .a4 {
  169. height: 40rpx;
  170. font-size: 28rpx;
  171. font-family: PingFang SC, PingFang SC-Regular;
  172. font-weight: 400;
  173. text-align: center;
  174. color: #333333;
  175. margin-top: 20rpx;
  176. margin-bottom: 80rpx;
  177. }
  178. .a5 {
  179. width: 568rpx;
  180. height: 90rpx;
  181. background: #51d0b4;
  182. border-radius: 16rpx;
  183. margin: 0 auto;
  184. line-height: 90rpx;
  185. font-size: 28rpx;
  186. font-family: PingFang SC, PingFang SC-Regular;
  187. font-weight: 400;
  188. text-align: center;
  189. color: #ffffff;
  190. }
  191. .a6 {
  192. display: flex;
  193. align-items: center;
  194. justify-content: center;
  195. height: 34rpx;
  196. font-size: 24rpx;
  197. font-family: PingFang SC, PingFang SC-Medium;
  198. font-weight: 500;
  199. text-align: center;
  200. color: #333333;
  201. margin-top: 40rpx;
  202. }
  203. .a6 .agreement {
  204. color: #6FDFBE;
  205. }
  206. .a7 {
  207. box-sizing: border-box;
  208. border-radius: 50%;
  209. width: 34rpx;
  210. height: 34rpx;
  211. display: inline-block;
  212. border: 1px solid #ccc;
  213. margin-right: 4rpx;
  214. }
  215. .a8 {
  216. background-color: #6FDFBE;
  217. border: none;
  218. color: #fff;
  219. }
  220. </style>