indexs.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. uni.$emit("getSendMsg")
  115. this.$navToPage({
  116. url: "/pages/index/index"
  117. }, "switchTab")
  118. })
  119. }
  120. });
  121. },
  122. async getImgV() {
  123. try {
  124. if (this.countDown == 0) {
  125. this.$refs.model.validateField("mobile", (res) => {
  126. if (!res.length) {
  127. api.get('/admin/user/getVerifi').then(res => {
  128. this.codeObj = res.data;
  129. this.isShowCodeDialog = true
  130. })
  131. }
  132. })
  133. }
  134. } catch (e) {}
  135. },
  136. refresh() {
  137. this.getImgV()
  138. },
  139. finish(val) {
  140. api.postJson('/admin/user/smsCode', {
  141. mobile: this.model.mobile,
  142. code: this.codeObj.key,
  143. codeValue: parseInt(val),
  144. }).then(res => {
  145. this.isShowCodeDialog = false
  146. this.codeObj = {
  147. bigImage: '',
  148. smallImage: '',
  149. key: '',
  150. yHeight: '',
  151. isSuccess: false,
  152. isFail: false,
  153. }
  154. this.countDown = 60
  155. })
  156. },
  157. //登录
  158. async loginFn() {
  159. try {
  160. await this.$refs.model.validate()
  161. let params = {
  162. "mobile": this.model.mobile,
  163. "code": this.model.code,
  164. }
  165. await this.$store.dispatch('user/login', params)
  166. await this.$store.dispatch('user/getInfo')
  167. await this.$Prompt.toast({
  168. title: '登陆成功',
  169. icon: 'success'
  170. })
  171. this.$Router.push({
  172. name: 'learn'
  173. })
  174. } catch (e) {}
  175. },
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. page {
  181. background-color: #fff;
  182. }
  183. .icon {
  184. width: 36rpx;
  185. height: 36rpx;
  186. padding: 10rpx 20rpx 0
  187. }
  188. .logo {
  189. width: 100vw;
  190. height: 500rpx;
  191. display: flex;
  192. justify-content: center;
  193. align-items: center;
  194. flex-direction: column;
  195. .logo_top {
  196. width: 240rpx;
  197. height: 240rpx;
  198. }
  199. .logo_bottom {
  200. font-size: 40rpx;
  201. font-weight: 700;
  202. color: #333;
  203. padding-top: 38rpx;
  204. }
  205. }
  206. .loginForm {
  207. padding: 0 60rpx;
  208. }
  209. .loginBtn {
  210. margin-top: 44rpx;
  211. background: linear-gradient(135deg, #7fdaff 0%, #6da7ff 100%);
  212. border-radius: 50rpx;
  213. }
  214. </style>