index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. validateGuestCode:0,
  52. form: {
  53. phone: '',
  54. code: '',
  55. },
  56. backUrl: "",
  57. message: "",
  58. codeTips: '',
  59. isSendMsgIng: false,
  60. sendMsgSecond: 60 * 2,
  61. customStyle: {
  62. background: '#1677ff'
  63. }
  64. }
  65. },
  66. onLoad(op) {
  67. this.message = op.message;
  68. this.backUrl = op.back;
  69. if (op.phone) {
  70. this.form.phone = op.phone;
  71. }
  72. },
  73. methods: {
  74. codeChange(text) {
  75. this.codeTips = text;
  76. },
  77. //倒计时
  78. end() {
  79. this.sendMsgSecond = 2 * 60;
  80. this.isSendMsgIng = false;
  81. },
  82. finish() {
  83. if (!this.carhelp.getOpenId()) {
  84. // uni.showToast({
  85. // title: "请使用“微信”访问本系统登录"
  86. // })
  87. // return
  88. }
  89. if (!this.form.phone) {
  90. uni.showToast({
  91. title: "请输入手机号"
  92. })
  93. return
  94. }
  95. if (!this.form.code) {
  96. uni.showToast({
  97. title: "请输入验证码"
  98. })
  99. return
  100. }
  101. uni.showLoading({
  102. title: "加载中",
  103. mask: true,
  104. })
  105. var headImg = "";
  106. var userInfo = this.carhelp.get("xpgj_wx_user_info")
  107. if (userInfo) {
  108. headImg = userInfo.headimgurl;
  109. }
  110. API.validateCode({
  111. validateGuestCode:this.validateGuestCode,
  112. verifyCode: this.form.code,
  113. telephone: this.form.phone,
  114. openId: this.carhelp.getOpenId(),
  115. headImg: headImg,
  116. source:1,
  117. }).then((response) => {
  118. var token = response ? response.data.token : '';
  119. this.carhelp.setToken(token);
  120. this.carhelp.setPersonInfo(response.data.regUser);
  121. this.carhelp.setPersonInfoPlus(response.data.data )
  122. //this.gotoUrl("pages/user/index")
  123. uni.redirectTo({
  124. url: '/pages/index/index'
  125. })
  126. }).catch(error => {
  127. uni.showToast({
  128. title: error,
  129. icon: "none"
  130. })
  131. })
  132. },
  133. start() {
  134. if (!this.isSendMsgIng) {
  135. uni.showLoading({
  136. title: "加载中",
  137. mask: true,
  138. })
  139. API.getVerifyCode(this.form.phone).then((response) => {
  140. uni.hideLoading();
  141. this.carhelp.set("getvcodetime", new Date().getTime());
  142. if (!"") {
  143. //倒计时
  144. uni.showToast({
  145. title: "发送成功"
  146. })
  147. } else {
  148. uni.showToast({
  149. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  150. })
  151. }
  152. }).catch(error => {
  153. uni.showToast({
  154. title: error,
  155. icon: "none"
  156. })
  157. })
  158. }
  159. },
  160. // 获取验证码
  161. getCode() {
  162. if (this.$refs.uCode.canGetCode) {
  163. } else {
  164. uni.showToast({
  165. title: '倒计时结束后再发送',
  166. icon: "none"
  167. })
  168. return
  169. }
  170. var checkPhoneResult = checkPhone(this.form.phone);
  171. if ( checkPhoneResult !== true) {
  172. uni.showToast({
  173. title: checkPhoneResult,
  174. })
  175. return;
  176. }
  177. this.$refs.uCode.start();
  178. },
  179. query(){
  180. uni.showLoading({
  181. title: "加载中",
  182. mask: true,
  183. })
  184. API.findByOpenId({
  185. openId: this.carhelp.getOpenId(),
  186. }).then((response) => {
  187. if(response.data.regUser.userType==1){
  188. this.validateGuestCode=1;
  189. throw 1
  190. }
  191. var token = response ? response.data.token : '';
  192. this.carhelp.setToken(token);
  193. this.carhelp.setPersonInfo(response.data.regUser);
  194. //this.gotoUrl("pages/user/index")
  195. this.carhelp.setPersonInfoPlus(response.data.data )
  196. uni.redirectTo({
  197. url: '/pages/index/index'
  198. })
  199. }).catch(error => {
  200. console.log(error)
  201. uni.hideLoading();
  202. if (!this.carhelp.getOpenId()) {
  203. // uni.showToast({
  204. // title: "请使用“微信”访问本系统登录"
  205. // })
  206. // return
  207. } else if (this.message) {
  208. uni.showToast({
  209. title: this.message.split(",")[0],
  210. icon: "none"
  211. })
  212. }
  213. var time = this.carhelp.get("getvcodetime");
  214. if (time) {
  215. //this.$refs.uCode.start();
  216. var nowtime = new Date().getTime()
  217. var differ = (nowtime - time) / 1000
  218. if (differ < 2 * 60) {
  219. this.sendMsgSecond = 2 * 60 - parseInt(differ)
  220. this.isSendMsgIng = true;
  221. this.$refs.uCode.start();
  222. }
  223. }
  224. })
  225. }
  226. },
  227. onReady() {
  228. this.query()
  229. }
  230. }
  231. </script>
  232. <style lang="scss" scoped>
  233. .login-title {
  234. text-align: center;
  235. align-items: center;
  236. margin: 25px 30px;
  237. h3 {
  238. font-size: 18px;
  239. margin-left: 10rpx;
  240. color: #1677ff;
  241. font-weight: normal;
  242. }
  243. }
  244. .login-main {
  245. margin: 0 30px;
  246. }
  247. .login-btn {
  248. margin: 30px;
  249. }
  250. .login-code {
  251. color: #1677ff;
  252. }
  253. </style>