index.vue 6.5 KB

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