index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view>
  3. <div class="vongi-login-logo" style="
  4. text-align: center;
  5. margin-top: 40px;">
  6. <img src="@/assets/img/logo_xiaopengguanjia.png" style="
  7. width: 72px;
  8. height: 72px;
  9. border-radius: 15px;
  10. " />
  11. <div style="
  12. color: rgba(16, 16, 16, 100);
  13. font-size: 18px;
  14. text-align: center;
  15. font-family: PingFangSC-regular;
  16. ">小鹏管家</div>
  17. </div>
  18. <view class="login-title">
  19. <u-icon name="qichexiangguan-chongdianzhan" custom-prefix="custom-icon" color="#1677ff" size="56"></u-icon>
  20. <h2>电单车智能充电系统</h2>
  21. </view>
  22. <view class="login-main">
  23. <u-form :model="form" ref="uForm">
  24. <u-form-item label="手机号码" prop="phone" label-width="150" label-position="top">
  25. <u-input placeholder="请输入手机号" v-model="form.phone" type="number"></u-input>
  26. </u-form-item>
  27. <u-form-item label="验证码" prop="code" label-width="150" label-position="top">
  28. <u-input placeholder="请输入验证码" v-model="form.code" type="text"></u-input>
  29. <view class="login-code" @click="getCode">
  30. {{codeTips}}
  31. </view>
  32. </u-form-item>
  33. </u-form>
  34. </view>
  35. <view class="login-btn">
  36. <u-button type="primary" :custom-style="customStyle" @click="finish" shape="square">登录</u-button>
  37. </view>
  38. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start">
  39. </u-verification-code>
  40. </view>
  41. </template>
  42. <script>
  43. import * as API from '@/apis/login.js'
  44. import {
  45. checkPhone
  46. } from '@/utils'
  47. export default {
  48. data() {
  49. return {
  50. form: {
  51. phone: '',
  52. code: '',
  53. },
  54. backUrl: "",
  55. message: "",
  56. codeTips: '',
  57. isSendMsgIng: false,
  58. sendMsgSecond: 60 * 2,
  59. customStyle: {
  60. background: '#1677ff'
  61. }
  62. }
  63. },
  64. onLoad(op) {
  65. this.message = op.message;
  66. this.backUrl = op.back;
  67. if (op.phone) {
  68. this.form.phone = op.phone;
  69. }
  70. },
  71. methods: {
  72. codeChange(text) {
  73. this.codeTips = text;
  74. },
  75. //倒计时
  76. end() {
  77. this.sendMsgSecond = 2 * 60;
  78. this.isSendMsgIng = false;
  79. },
  80. finish() {
  81. if (!this.carhelp.getOpenId()) {
  82. uni.showToast({
  83. title: "请使用“微信”访问本系统登录"
  84. })
  85. return
  86. }
  87. if (!this.form.phone) {
  88. uni.showToast({
  89. title: "请输入手机号"
  90. })
  91. return
  92. }
  93. if (!this.form.code) {
  94. uni.showToast({
  95. title: "请输入验证码"
  96. })
  97. return
  98. }
  99. uni.showLoading({
  100. title: "加载中",
  101. mask: true,
  102. })
  103. var headImg = "";
  104. var userInfo = this.carhelp.get("xpgj_wx_user_info")
  105. if (userInfo) {
  106. headImg = userInfo.headimgurl;
  107. }
  108. API.validateCode({
  109. verifyCode: this.form.code,
  110. telephone: this.form.phone,
  111. openId: this.carhelp.getOpenId(),
  112. headImg: headImg
  113. }).then((response) => {
  114. var token = response ? response.data.token : '';
  115. this.carhelp.setToken(token);
  116. this.carhelp.setPersonInfo(response.data.regUser);
  117. this.carhelp.setPersonInfoPlus(response.data.data )
  118. //this.gotoUrl("pages/user/index")
  119. uni.redirectTo({
  120. url: '/pages/index/index'
  121. })
  122. }).catch(error => {
  123. uni.showToast({
  124. title: error,
  125. icon: "none"
  126. })
  127. })
  128. },
  129. start() {
  130. if (!this.isSendMsgIng) {
  131. uni.showLoading({
  132. title: "加载中",
  133. mask: true,
  134. })
  135. API.getVerifyCode(this.form.phone).then((response) => {
  136. uni.hideLoading();
  137. this.carhelp.set("getvcodetime", new Date().getTime());
  138. if (!"") {
  139. //倒计时
  140. uni.showToast({
  141. title: "发送成功"
  142. })
  143. } else {
  144. uni.showToast({
  145. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  146. })
  147. }
  148. }).catch(error => {
  149. uni.showToast({
  150. title: error,
  151. icon: "none"
  152. })
  153. })
  154. }
  155. },
  156. // 获取验证码
  157. getCode() {
  158. if (this.$refs.uCode.canGetCode) {
  159. } else {
  160. uni.showToast({
  161. title: '倒计时结束后再发送',
  162. icon: "none"
  163. })
  164. return
  165. }
  166. var checkPhoneResult = checkPhone(this.form.phone);
  167. if ( checkPhoneResult !== true) {
  168. uni.showToast({
  169. title: checkPhoneResult,
  170. })
  171. return;
  172. }
  173. this.$refs.uCode.start();
  174. },
  175. query(){
  176. uni.showLoading({
  177. title: "加载中",
  178. mask: true,
  179. })
  180. API.findByOpenId({
  181. openId: this.carhelp.getOpenId(),
  182. }).then((response) => {
  183. var token = response ? response.data.token : '';
  184. this.carhelp.setToken(token);
  185. this.carhelp.setPersonInfo(response.data.regUser);
  186. //this.gotoUrl("pages/user/index")
  187. this.carhelp.setPersonInfoPlus(response.data.data )
  188. uni.redirectTo({
  189. url: '/pages/index/index'
  190. })
  191. }).catch(error => {
  192. uni.hideLoading();
  193. if (!this.carhelp.getOpenId()) {
  194. uni.showToast({
  195. title: "请使用“微信”访问本系统登录"
  196. })
  197. return
  198. } else if (this.message) {
  199. uni.showToast({
  200. title: this.message.split(",")[0],
  201. icon: "none"
  202. })
  203. }
  204. var time = this.carhelp.get("getvcodetime");
  205. if (time) {
  206. //this.$refs.uCode.start();
  207. var nowtime = new Date().getTime()
  208. var differ = (nowtime - time) / 1000
  209. if (differ < 2 * 60) {
  210. this.sendMsgSecond = 2 * 60 - parseInt(differ)
  211. this.isSendMsgIng = true;
  212. this.$refs.uCode.start();
  213. }
  214. }
  215. })
  216. }
  217. },
  218. onReady() {
  219. this.query()
  220. }
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .login-title {
  225. display: flex;
  226. align-items: center;
  227. margin: 25px 30px;
  228. h3 {
  229. font-size: 20px;
  230. margin-left: 10rpx;
  231. color: #1677ff;
  232. font-weight: normal;
  233. }
  234. }
  235. .login-main {
  236. margin: 0 30px;
  237. }
  238. .login-btn {
  239. margin: 30px;
  240. }
  241. .login-code {
  242. color: #1677ff;
  243. }
  244. </style>