login-code.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="container login">
  3. <view class="login-main"> <image class="logo" :src="staticUrl + 'logo@2x.png'" mode=""></image> </view>
  4. <view class="login-input">
  5. <keyInput
  6. borderValueColor="#E1E1E1"
  7. borderActiveColor="#E1E1E1"
  8. ref="vcodeInputRef"
  9. @vcodeInput="keyInput"
  10. @vcodeChange="keyInputChangeHandle"
  11. sum="6"
  12. >
  13. </keyInput>
  14. </view>
  15. <button class="login-btn" @click.stop="goLogin" :class="isDisabled ? 'disabled' : ''" :disabled="isDisabled">
  16. 邀请码登录
  17. </button>
  18. <view class="login-tips">
  19. <text class="h1">注意事项:</text>
  20. <text class="p"
  21. >邀请码是为了方便机构内成员互相邀请并快速注册【丽格集采联盟】小程序而推出的一项邀请机制。</text
  22. >
  23. <text class="p"
  24. >机构已注册了账号的成员,可在其个人中心添加其他机构成员,系统会自动为添加的每一个成员生成邀请码。其他成员使用邀请码可直接登录【丽格集采联盟】小程序。</text
  25. >
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import authorize from '@/common/config/authorize.js'
  31. import wxLogin from '@/common/config/wxLogin.js'
  32. import { mapState, mapMutations } from 'vuex'
  33. import keyInput from '@/components/uni-keyinput/uni-keyinput'
  34. import shareMixin from '@/mixins/shareMixin.js'
  35. export default {
  36. mixins: [ shareMixin ],
  37. components: {
  38. keyInput
  39. },
  40. data() {
  41. return {
  42. staticUrl: this.global.staticUrl,
  43. params: {
  44. invitationCode: '', //获取用户登录的邀请码
  45. unionId: 0,
  46. nickName: '',
  47. avatarUrl: '',
  48. organizeId: 4
  49. }
  50. }
  51. },
  52. onLoad(option) {},
  53. computed: {
  54. ...mapState(['isWxAuthorize', 'isLoginType', 'isLoginProductId', 'isLoginOrderId']),
  55. isDisabled() {
  56. // 邀请码长度是否符合要求
  57. return this.params.invitationCode.trim().length < 6
  58. }
  59. },
  60. methods: {
  61. ...mapMutations(['login', 'wxLogin']),
  62. goLogin() {
  63. if (this.params.invitationCode == '') {
  64. this.$util.msg('请输入邀请码', 2000)
  65. return
  66. }
  67. this.params.unionId = uni.getStorageSync('unionId')
  68. this.bindingWechat(this.params)
  69. },
  70. async bindingWechat(params) {
  71. //邀请码登录并绑定微信
  72. try{
  73. const res = await this.UserService.usrInvitationLogin(params)
  74. const data = res.data
  75. uni.setStorageSync('token', data.token)
  76. this.$store.commit('updateStatus', data)
  77. this.login(data)
  78. // 登录成功处理
  79. const url = uni.getStorageSync('LOGIN_REDIRECT_URL')
  80. if (url) {
  81. if (url.indexOf('tabBar') > -1) {
  82. uni.switchTabTo(url)
  83. } else {
  84. this.$api.redirectTo(url)
  85. }
  86. } else {
  87. this.$api.switchTabTo('/pages/tabBar/user/user')
  88. }
  89. uni.removeStorageSync('LOGIN_REDIRECT_URL')
  90. }catch(error){
  91. this.$util.msg(error.msg, 2000)
  92. }
  93. },
  94. keyInput(val) {
  95. // 输入框输入介绍
  96. // this.params.invitationCode = val
  97. console.log(val)
  98. },
  99. keyInputChangeHandle(val) {
  100. // 输入框输入事件
  101. this.params.invitationCode = val
  102. // console.log(val)
  103. },
  104. setFocus() {
  105. // 控制组件获取焦点
  106. this.$refs.VcodeInput.setFocus()
  107. },
  108. setBlur() {
  109. // 控制组件失去焦点
  110. this.$refs.VcodeInput.setBlur()
  111. },
  112. clearValue() {
  113. // 清除已输入
  114. this.$refs.VcodeInput.clearValue()
  115. },
  116. InitAuthorize() {
  117. //是否已授权 0:为取消授权 1:为已授权 2:为未操作
  118. wxLogin.wxLoginQuick()
  119. }
  120. },
  121. onShow() {
  122. this.InitAuthorize()
  123. }
  124. }
  125. </script>
  126. <style lang="scss">
  127. .login {
  128. width: 100%;
  129. height: auto;
  130. .model-warp.none {
  131. display: none;
  132. }
  133. .model-warp.show {
  134. display: block;
  135. }
  136. .login-main {
  137. width: 100%;
  138. display: flex;
  139. flex-direction: column;
  140. align-items: center;
  141. height: 206rpx;
  142. padding: 60rpx 0 40rpx 0;
  143. margin: 70rpx 0;
  144. .logo {
  145. width: 358rpx;
  146. height: 206rpx;
  147. display: block;
  148. }
  149. }
  150. .login-input {
  151. width: 600rpx;
  152. height: 88rpx;
  153. padding: 24rpx 0;
  154. margin: 30rpx auto;
  155. margin-bottom: 30rpx;
  156. background: #ffffff;
  157. position: relative;
  158. }
  159. .login-row {
  160. padding: 0 75rpx;
  161. font-size: $font-size-28;
  162. line-height: 40rpx;
  163. color: #ff5b00;
  164. margin-bottom: 48rpx;
  165. text-align: right;
  166. }
  167. .login-btn {
  168. width: 600rpx;
  169. height: 88rpx;
  170. border-radius: 44rpx;
  171. font-size: $font-size-28;
  172. line-height: 88rpx;
  173. color: #ffffff;
  174. margin: 0 auto;
  175. text-align: center;
  176. background: $btn-confirm;
  177. &.disabled {
  178. background: #e1e1e1;
  179. }
  180. }
  181. .login-btn-last {
  182. width: 600rpx;
  183. height: 86rpx;
  184. border-radius: 44rpx;
  185. font-size: $font-size-28;
  186. line-height: 88rpx;
  187. color: $color-system;
  188. margin: 0 auto;
  189. text-align: center;
  190. border: 1px solid $color-system;
  191. margin-top: 20rpx;
  192. }
  193. .login-tips {
  194. width: 100%;
  195. height: auto;
  196. margin-top: 80rpx;
  197. box-sizing: border-box;
  198. padding: 0 75rpx;
  199. .h1 {
  200. line-height: 44rpx;
  201. font-size: $font-size-24;
  202. color: #666666;
  203. text-align: justify;
  204. display: inline-block;
  205. }
  206. .p {
  207. line-height: 44rpx;
  208. font-size: $font-size-24;
  209. color: #999999;
  210. text-align: justify;
  211. margin-bottom: 20rpx;
  212. display: inline-block;
  213. }
  214. }
  215. .model-authorization {
  216. width: 100%;
  217. height: 100%;
  218. position: fixed;
  219. top: 0;
  220. left: 0;
  221. z-index: 999;
  222. .authorization {
  223. width: 518rpx;
  224. height: 320rpx;
  225. position: absolute;
  226. background: rgba(255, 255, 255, 0.7);
  227. left: 0;
  228. right: 0;
  229. bottom: 0;
  230. top: 0;
  231. margin: auto;
  232. .to-btn {
  233. position: absolute;
  234. top: 0;
  235. left: 0;
  236. right: 0;
  237. bottom: 0;
  238. margin: auto;
  239. width: 70%;
  240. height: 88rpx;
  241. font-size: $font-size-28;
  242. line-height: 88rpx;
  243. color: #ffffff;
  244. text-align: center;
  245. border-radius: 44rpx;
  246. }
  247. }
  248. }
  249. }
  250. </style>