indexs.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view>
  3. <view class="logo">
  4. <view class="logo_top">
  5. <image style="width: 100%;height: 100%" src="@/static/login/logo.png" mode=""></image>
  6. </view>
  7. <view class="logo_bottom">
  8. 家盛茂-回收平台
  9. </view>
  10. </view>
  11. <view class="loginForm">
  12. <!-- #ifdef H5 -->
  13. <u--form labelPosition="left" :model="model" :rules="rules" ref='model'>
  14. <u-form-item label="" prop="mobile">
  15. <u--input clearable shape='circle' placeholder="请输入手机号" v-model="model.mobile">
  16. <view class="" style="" slot='prefix'>
  17. <image class="icon" src="@/static/login/icon_login_account.png" mode=""></image>
  18. </view>
  19. </u--input>
  20. </u-form-item>
  21. <u-form-item label="" prop="code">
  22. <u--input clearable shape='circle' placeholder="请输入验证码" v-model="model.code">
  23. <view class="" style="" slot='prefix'>
  24. <image class="icon" src="@/static/login/icon_003.png" mode=""></image>
  25. </view>
  26. <view class="" slot='suffix' @click="getImgV">
  27. {{countDown?countDown+'S':'获取验证码'}}
  28. </view>
  29. </u--input>
  30. </u-form-item>
  31. </u--form>
  32. <u-button @click='loginFn' class='loginBtn' type="primary" shape="circle" size="" text="登录"></u-button>
  33. <!-- #endif -->
  34. <!-- #ifdef MP-WEIXIN -->
  35. <u-button type="primary" size="large" shape="circle" text="手机号快捷登录" open-type="getPhoneNumber"
  36. @getphonenumber="getPhoneNumber">
  37. </u-button>
  38. <!-- #endif -->
  39. </view>
  40. <!-- #ifdef H5 -->
  41. <zjDialogVerification ref="verification" :isShow="isShowCodeDialog" :top="codeObj.yHeight" :bgImg="codeObj.bigImage"
  42. :maskImg="codeObj.smallImage" :isSuccess="codeObj.isSuccess" :isFail="codeObj.isFail"
  43. @close="isShowCodeDialog = false" @refresh="refresh" @finish="finish">
  44. </zjDialogVerification>
  45. <!-- #endif -->
  46. </view>
  47. </template>
  48. <script>
  49. import zjDialogVerification from "@/components/zj-dialog-verification.vue";
  50. import api from '@/common/http/'
  51. export default {
  52. components: {
  53. zjDialogVerification
  54. },
  55. data() {
  56. return {
  57. isShowCodeDialog: false,
  58. codeObj: {
  59. bigImage: '',
  60. smallImage: '',
  61. key: '',
  62. yHeight: '',
  63. isSuccess: false,
  64. isFail: false,
  65. },
  66. model: {
  67. mobile: '',
  68. code: '',
  69. },
  70. rules: {
  71. mobile: {
  72. type: 'string',
  73. required: true,
  74. message: '手机号不能为空',
  75. trigger: ['blur', 'change']
  76. },
  77. code: {
  78. type: 'string',
  79. required: true,
  80. message: '验证码不能为空',
  81. trigger: ['blur', 'change']
  82. },
  83. },
  84. countDown: 0,
  85. }
  86. },
  87. watch: {
  88. countDown() {
  89. if (this.countDown > 0) {
  90. setTimeout(() => {
  91. this.countDown--
  92. }, 1000)
  93. }
  94. }
  95. },
  96. methods: {
  97. // 获取手机号
  98. getPhoneNumber(e) {
  99. if (!e.detail.iv) {
  100. return this.$toast('获取手机号失败');
  101. }
  102. uni.login({
  103. provider: 'weixin',
  104. success: (loginRes) => {
  105. api.get('/wechat/user/auth', {
  106. code: loginRes.code,
  107. phoneCode: e.detail.code,
  108. }).then(res => {
  109. this.$store.commit("user/set_token", res.data.token)
  110. this.$store.commit("user/set_openId", res.data.openId)
  111. this.$store.commit("user/set_name", res.data.name)
  112. this.$store.commit("user/set_avatar", res.data.avatar)
  113. this.$store.commit("user/set_userId", res.data.baseUserId)
  114. this.$navToPage({
  115. url: "/pages/index/index"
  116. }, "switchTab")
  117. })
  118. }
  119. });
  120. },
  121. async getImgV() {
  122. try {
  123. if (this.countDown == 0) {
  124. this.$refs.model.validateField("mobile", (res) => {
  125. if (!res.length) {
  126. api.get('/admin/user/getVerifi').then(res => {
  127. this.codeObj = res.data;
  128. this.isShowCodeDialog = true
  129. })
  130. }
  131. })
  132. }
  133. } catch (e) {}
  134. },
  135. refresh() {
  136. this.getImgV()
  137. },
  138. finish(val) {
  139. api.postJson('/admin/user/smsCode', {
  140. mobile: this.model.mobile,
  141. code: this.codeObj.key,
  142. codeValue: parseInt(val),
  143. }).then(res => {
  144. this.isShowCodeDialog = false
  145. this.codeObj = {
  146. bigImage: '',
  147. smallImage: '',
  148. key: '',
  149. yHeight: '',
  150. isSuccess: false,
  151. isFail: false,
  152. }
  153. this.countDown = 60
  154. })
  155. },
  156. //登录
  157. async loginFn() {
  158. try {
  159. await this.$refs.model.validate()
  160. let params = {
  161. "mobile": this.model.mobile,
  162. "code": this.model.code,
  163. }
  164. await this.$store.dispatch('user/login', params)
  165. await this.$store.dispatch('user/getInfo')
  166. await this.$Prompt.toast({
  167. title: '登陆成功',
  168. icon: 'success'
  169. })
  170. this.$Router.push({
  171. name: 'learn'
  172. })
  173. } catch (e) {}
  174. },
  175. }
  176. }
  177. </script>
  178. <style lang="scss" scoped>
  179. page {
  180. background-color: #fff;
  181. }
  182. .icon {
  183. width: 36rpx;
  184. height: 36rpx;
  185. padding: 10rpx 20rpx 0
  186. }
  187. .logo {
  188. width: 100vw;
  189. height: 500rpx;
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. flex-direction: column;
  194. .logo_top {
  195. width: 240rpx;
  196. height: 240rpx;
  197. }
  198. .logo_bottom {
  199. font-size: 40rpx;
  200. font-weight: 700;
  201. color: #333;
  202. padding-top: 38rpx;
  203. }
  204. }
  205. .loginForm {
  206. padding: 0 60rpx;
  207. }
  208. .loginBtn {
  209. margin-top: 44rpx;
  210. background: linear-gradient(135deg, #7fdaff 0%, #6da7ff 100%);
  211. border-radius: 50rpx;
  212. }
  213. </style>