index.vue 6.1 KB

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