index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. <h3>电动自行车智能充电系统</h3>
  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.gotoUrl("pages/user/index")
  118. uni.redirectTo({
  119. url: '/pages/index/index'
  120. })
  121. }).catch(error => {
  122. uni.showToast({
  123. title: error,
  124. icon: "none"
  125. })
  126. })
  127. },
  128. start() {
  129. if (!this.isSendMsgIng) {
  130. uni.showLoading({
  131. title: "加载中",
  132. mask: true,
  133. })
  134. API.getVerifyCode(this.form.phone).then((response) => {
  135. uni.hideLoading();
  136. this.carhelp.set("getvcodetime", new Date().getTime());
  137. if (!"") {
  138. //倒计时
  139. uni.showToast({
  140. title: "发送成功"
  141. })
  142. } else {
  143. uni.showToast({
  144. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  145. })
  146. }
  147. }).catch(error => {
  148. uni.showToast({
  149. title: error,
  150. icon: "none"
  151. })
  152. })
  153. }
  154. },
  155. // 获取验证码
  156. getCode() {
  157. if (this.$refs.uCode.canGetCode) {
  158. } else {
  159. uni.showToast({
  160. title: '倒计时结束后再发送',
  161. icon: "none"
  162. })
  163. return
  164. }
  165. var checkPhoneResult = checkPhone(this.form.phone);
  166. if (false && checkPhoneResult !== true) {
  167. uni.showToast({
  168. title: checkPhoneResult,
  169. })
  170. return;
  171. }
  172. this.$refs.uCode.start();
  173. },
  174. query(){
  175. uni.showLoading({
  176. title: "加载中",
  177. mask: true,
  178. })
  179. API.findByOpenId({
  180. openId: this.carhelp.getOpenId(),
  181. }).then((response) => {
  182. var token = response ? response.data.token : '';
  183. this.carhelp.setToken(token);
  184. this.carhelp.setPersonInfo(response.data.regUser);
  185. //this.gotoUrl("pages/user/index")
  186. uni.redirectTo({
  187. url: '/pages/index/index'
  188. })
  189. }).catch(error => {
  190. uni.hideLoading();
  191. if (!this.carhelp.getOpenId()) {
  192. uni.showToast({
  193. title: "请使用“微信”访问本系统登录"
  194. })
  195. return
  196. } else if (this.message) {
  197. uni.showToast({
  198. title: this.message.split(",")[0],
  199. icon: "none"
  200. })
  201. }
  202. var time = this.carhelp.get("getvcodetime");
  203. if (time) {
  204. //this.$refs.uCode.start();
  205. var nowtime = new Date().getTime()
  206. var differ = (nowtime - time) / 1000
  207. if (differ < 2 * 60) {
  208. this.sendMsgSecond = 2 * 60 - parseInt(differ)
  209. this.isSendMsgIng = true;
  210. this.$refs.uCode.start();
  211. }
  212. }
  213. })
  214. }
  215. },
  216. onReady() {
  217. this.query()
  218. }
  219. }
  220. </script>
  221. <style lang="scss" scoped>
  222. .login-title {
  223. display: flex;
  224. align-items: center;
  225. margin: 25px 30px;
  226. h3 {
  227. font-size: 20px;
  228. margin-left: 10rpx;
  229. color: #1677ff;
  230. font-weight: normal;
  231. }
  232. }
  233. .login-main {
  234. margin: 0 30px;
  235. }
  236. .login-btn {
  237. margin: 30px;
  238. }
  239. .login-code {
  240. color: #1677ff;
  241. }
  242. </style>