login.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <view class="wrap">
  3. <view class="login">
  4. <view class="login-title">
  5. <h3>手机号登录/注册</h3>
  6. <p>欢迎来到{{projectName}}</p>
  7. </view>
  8. <view class="login-form">
  9. <view class="login-form-item">
  10. <view class="title">手机号</view>
  11. <view class="input">
  12. <u-input v-model="form.telephone" type="number" placeholder="请输入手机号" placeholder-style="font-size:16px;color:#ccc;"/>
  13. </view>
  14. <view class="tips">未注册的手机号验证后将自动注册</view>
  15. </view>
  16. <view class="login-form-item">
  17. <view class="title">验证码</view>
  18. <view class="input">
  19. <u-input v-model="form.verifyCode" type="number" placeholder="请输入验证码" placeholder-style="font-size:16px;color:#ccc;"/>
  20. <view class="code" @click="getCode">{{codeTips}}</view>
  21. </view>
  22. <view style="width: 350px;">
  23. <u-checkbox-group>
  24. <u-checkbox class="tips" active-color="green" v-model="value" shape="circle" @change="checkboxChange()"></u-checkbox>
  25. </u-checkbox-group>
  26. <span>我已阅读并同意</span>
  27. <span @click="gotoUrl('pages/article/details?code=YHXY')" style="color: #3fbd70;">《会员协议》</span>和
  28. <span @click="gotoUrl('pages/article/details?code=YSZC')" style="color: #3fbd70;">《隐私协议》</span>
  29. </view>
  30. </view>
  31. </view>
  32. <u-button :style="[inputStyle]" class="login-btn" type="success" shape="circle" @click="login">登录</u-button>
  33. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start" change-text="已发送(Xs)">
  34. </u-verification-code>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import * as loginApi from '@/apis/login.js'
  40. import * as API from '@/apis/index.js'
  41. import {
  42. checkPhone
  43. } from '@/utils'
  44. export default {
  45. data() {
  46. return {
  47. form: {
  48. telephone: '',
  49. verifyCode: '',
  50. },
  51. isSendMsgIng: false,
  52. sendMsgSecond: 60,
  53. codeTips: '',
  54. value: false,
  55. code: '',
  56. codeId: '',
  57. projectName:'',
  58. }
  59. },
  60. computed: {
  61. inputStyle() {
  62. let style = {};
  63. if(this.form.telephone) {
  64. style.color = "#fff";
  65. style.backgroundColor = this.$u.color['success'];
  66. }
  67. return style;
  68. }
  69. },
  70. onLoad(op) {
  71. this.projectName=process.car.ProjectName;
  72. if(op.jpcode) {
  73. var str1 = op.jpcode.slice(0,19);
  74. var str2 = op.jpcode.slice(20,21);
  75. var str3 = op.jpcode.slice(22);
  76. if(str1 == 'jp_team51_charge_id') {
  77. if(str2 == 'A') {
  78. this.code = str2;
  79. this.codeId = str3;
  80. uni.showToast({
  81. title:"注册后享受充电服务"
  82. })
  83. }
  84. }
  85. }
  86. },
  87. methods: {
  88. codeChange(text) {
  89. this.codeTips = text;
  90. },
  91. start() {
  92. if (!this.isSendMsgIng) {
  93. uni.showLoading({
  94. title: "加载中",
  95. mask: true,
  96. })
  97. loginApi.getVerifyCode(this.form.telephone).then((response) => {
  98. uni.hideLoading();
  99. this.carhelp.set("getvcodetime", new Date().getTime());
  100. if (!"") {
  101. //倒计时
  102. uni.showToast({
  103. title: "发送成功"
  104. })
  105. } else {
  106. uni.showToast({
  107. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  108. })
  109. }
  110. }).catch(error => {
  111. uni.showToast({
  112. title: error,
  113. icon: "none"
  114. })
  115. })
  116. }
  117. },
  118. //倒计时
  119. end() {
  120. this.sendMsgSecond = 60;
  121. this.isSendMsgIng = false;
  122. },
  123. // 获取验证码
  124. getCode() {
  125. if (this.$refs.uCode.canGetCode) {} else {
  126. uni.showToast({
  127. title: '倒计时结束后再发送',
  128. icon: "none"
  129. })
  130. return
  131. }
  132. var checkPhoneResult = checkPhone(this.form.telephone);
  133. if (checkPhoneResult !== true) {
  134. uni.showToast({
  135. title: checkPhoneResult,
  136. })
  137. return;
  138. }
  139. this.$refs.uCode.start();
  140. },
  141. checkboxChange() {
  142. this.value = !this.value;
  143. },
  144. login() {
  145. var checkPhoneResult = checkPhone(this.form.telephone);
  146. if(!this.form.telephone || checkPhoneResult != true) {
  147. uni.showToast({
  148. title: checkPhoneResult,
  149. icon: "none"
  150. })
  151. return;
  152. }
  153. if(!this.form.verifyCode) {
  154. uni.showToast({
  155. title: "请输入验证码",
  156. icon: "none"
  157. })
  158. return
  159. }
  160. if(!this.value) {
  161. uni.showToast({
  162. title: "请勾选协议",
  163. icon: "none"
  164. })
  165. return
  166. }
  167. uni.showLoading({
  168. title: "加载中",
  169. mask: true,
  170. })
  171. loginApi.validateCode({
  172. verifyCode: this.form.verifyCode,
  173. telephone: this.form.telephone,
  174. nickName: this.carhelp.getUserInfo().nickname,
  175. openId: this.carhelp.getOpenId(),
  176. }).then((response) => {
  177. uni.hideLoading();
  178. var token = response ? response.data.token : '';
  179. this.carhelp.setToken(token);
  180. this.carhelp.setPersonInfo(response.data.regUser);
  181. if(this.code == 'A') {
  182. var k=API.codeOperation("jp_team51_charge_id:A_"+this.codeId);
  183. if(k){
  184. uni.redirectTo({
  185. url:k
  186. })
  187. }
  188. } else {
  189. uni.redirectTo({
  190. url: '/pages/index/index'
  191. })
  192. }
  193. }).catch(error => {
  194. uni.showToast({
  195. title: error,
  196. icon: "none"
  197. })
  198. })
  199. }
  200. }
  201. }
  202. </script>
  203. <style>
  204. page{
  205. background-color: #fff;
  206. }
  207. </style>
  208. <style lang="scss" scoped>
  209. .wrap {
  210. font-size: 28rpx;
  211. .login {
  212. width: 600rpx;
  213. padding-top: 80rpx;
  214. margin: 0 auto;
  215. .login-title {
  216. text-align: left;
  217. h3{
  218. font-size: 48rpx;
  219. font-weight: normal;
  220. }
  221. p{
  222. margin-top: 4px;
  223. color:#777
  224. }
  225. }
  226. .login-form-item{
  227. margin-top: 40px;
  228. .title{
  229. margin-bottom: 8px;
  230. }
  231. .input {
  232. border-bottom: 1px solid #f7f7f7;
  233. position: relative;
  234. }
  235. .code{
  236. position: absolute;
  237. right: 0;
  238. top:7px;
  239. color:#1677FF;
  240. }
  241. .tips {
  242. color: $u-type-info;
  243. margin-top: 12px;
  244. font-size: 12px;
  245. span{
  246. color:#3fbd70;
  247. }
  248. }
  249. }
  250. .login-btn {
  251. margin-top: 40px;
  252. background-color: #a7dbc2;
  253. }
  254. .alternative {
  255. color: $u-tips-color;
  256. display: flex;
  257. justify-content: space-between;
  258. margin-top: 30rpx;
  259. }
  260. }
  261. }
  262. </style>