推拿小程序前端代码仓库
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.

236 lines
4.9 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. <template>
  2. <view class="login">
  3. <view class="logo">
  4. <image :src="configList.config_app_logo" mode=""></image>
  5. <view class="text">
  6. {{ configList.config_app_name }}
  7. </view>
  8. </view>
  9. <button class="btn btn-login mt" @click="wxLogin">
  10. <view class="icon">
  11. <uv-icon name="weixin-fill" color="#ffffff" size="36rpx"></uv-icon>
  12. </view>
  13. <view class="">
  14. 授权登录
  15. </view>
  16. </button>
  17. <button class="btn btn-cancel" :plain="true" :hairline="false" @click="onCancel">
  18. 暂不登录
  19. </button>
  20. <view class="config mt">
  21. <view style="flex: 1;">
  22. <uv-checkbox-group v-model="checkboxValue" shape="circle">
  23. <view class="content">
  24. <uv-checkbox size="28rpx" icon-size="28rpx" activeColor="#07C261" :name="1"></uv-checkbox>
  25. 已同意
  26. <text @click="openModal">注册协议隐私协议</text>
  27. </view>
  28. </uv-checkbox-group>
  29. </view>
  30. <view class="flex">
  31. <uv-icon name="info-circle" color="#07C261" size="28rpx"></uv-icon>
  32. </view>
  33. </view>
  34. <agreementModal ref="modal" @confirm="onConfirmAggrement"></agreementModal>
  35. </view>
  36. </template>
  37. <script>
  38. import agreementModal from './agreementModal.vue'
  39. import Vue from 'vue'
  40. export default {
  41. name: 'Login',
  42. data() {
  43. return {
  44. checkboxValue: []
  45. }
  46. },
  47. components: {
  48. agreementModal
  49. },
  50. onShow() {
  51. if (this.GetQueryString('code')) { //路径上面有code说明微信已授权
  52. this.agreement = true; //勾选协议
  53. //直接去登录发起请求
  54. this.toWxLogin(this.GetQueryString('code'))
  55. }
  56. },
  57. methods: {
  58. wxLogin() {
  59. if (!this.checkboxValue.length) {
  60. return uni.showToast({
  61. title: '请先同意隐私协议',
  62. icon: 'none'
  63. })
  64. }
  65. // #ifdef MP-WEIXIN
  66. this.$store.commit('login')
  67. // #endif
  68. // #ifdef H5
  69. this.getwx_authorize();
  70. // #endif
  71. },
  72. openModal() {
  73. this.$refs.modal.open()
  74. },
  75. onConfirmAggrement(confirm) {
  76. if (confirm) {
  77. this.checkboxValue = [1]
  78. } else {
  79. this.checkboxValue = []
  80. }
  81. },
  82. onCancel() {
  83. console.log('--onCancel')
  84. uni.reLaunch({
  85. url: '/pages/index/index'
  86. })
  87. },
  88. getwx_authorize() {
  89. console.log(Vue.prototype.$config.redirect);
  90. let redirect_uri = encodeURIComponent(Vue.prototype.$config.redirect + '/#/pages_order/auth/wxLogin');
  91. let appid = Vue.prototype.$config.appId;
  92. window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid +
  93. '&redirect_uri=' + redirect_uri +
  94. '&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect' + '&t=' + new Date().getTime();
  95. },
  96. //获取url中参数的方法
  97. GetQueryString(name) {
  98. var url = window.location.href;
  99. try {
  100. var cs = url.split('?')[1]; //获取?之后的参数字符串
  101. var cs_arr = cs.split('&'); //参数字符串分割为数组
  102. for (var i = 0; i < cs_arr.length; i++) { //遍历数组,拿到json对象
  103. if (cs_arr[i].split('=')[0] == name) {
  104. return cs_arr[i].split('=')[1];
  105. }
  106. }
  107. return "";
  108. } catch {
  109. return "";
  110. }
  111. },
  112. //微信登录
  113. toWxLogin(code) {
  114. let vid = sessionStorage.getItem('vid');
  115. this.$api('wxLogin', {
  116. code,
  117. vid
  118. }, res => {
  119. if (res.code == 200) {
  120. this.$store.commit('h5Login', res.result)
  121. } else {
  122. location.href = Vue.prototype.$config.redirect + '/#/pages_order/auth/wxLogin'
  123. }
  124. sessionStorage.removeItem('vid')
  125. })
  126. },
  127. }
  128. }
  129. </script>
  130. <style scoped lang="scss">
  131. .login {
  132. display: flex;
  133. justify-content: flex-start;
  134. align-items: center;
  135. height: 100vh;
  136. flex-direction: column;
  137. position: relative;
  138. background: $uni-fg-color;
  139. .logo {
  140. margin-top: 334rpx;
  141. width: 320rpx;
  142. image {
  143. height: 150rpx;
  144. width: 320rpx;
  145. }
  146. .text {
  147. margin-top: 90rpx;
  148. font-size: 38rpx;
  149. font-family: PingFang SC, PingFang SC-Bold;
  150. font-weight: 700;
  151. text-align: center;
  152. color: #000000;
  153. }
  154. }
  155. .btn {
  156. width: 80%;
  157. height: 100rpx;
  158. font-size: 15px;
  159. font-family: PingFang SC, PingFang SC-Regular;
  160. font-weight: 400;
  161. display: flex;
  162. justify-content: center;
  163. align-items: center;
  164. border-radius: 50rpx;
  165. &-login {
  166. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  167. color: #fff;
  168. border: none;
  169. .icon {
  170. margin-right: 10rpx;
  171. image {
  172. width: 40rpx;
  173. height: 35rpx;
  174. }
  175. }
  176. }
  177. &-cancel {
  178. height: calc(100rpx - 1rpx * 2);
  179. color: #c7c7c7;
  180. background-color: transparent;
  181. border: 1rpx solid #c7c7c7;
  182. margin-top: 60rpx;
  183. }
  184. }
  185. .mt {
  186. margin-top: 200rpx;
  187. }
  188. .config {
  189. width: 80%;
  190. line-height: 40rpx;
  191. // margin-top: 27rpx;
  192. color: #C7C7C7;
  193. text-align: left;
  194. display: flex;
  195. .content {
  196. font-size: 22rpx;
  197. display: flex;
  198. align-items: center;
  199. }
  200. text {
  201. color: #07C261;
  202. }
  203. }
  204. }
  205. .flex {
  206. display: flex;
  207. align-items: center;
  208. }
  209. </style>